couchbase_core/memdx/
request.rs

1/*
2 *
3 *  * Copyright (c) 2025 Couchbase, Inc.
4 *  *
5 *  * Licensed under the Apache License, Version 2.0 (the "License");
6 *  * you may not use this file except in compliance with the License.
7 *  * You may obtain a copy of the License at
8 *  *
9 *  *    http://www.apache.org/licenses/LICENSE-2.0
10 *  *
11 *  * Unless required by applicable law or agreed to in writing, software
12 *  * distributed under the License is distributed on an "AS IS" BASIS,
13 *  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 *  * See the License for the specific language governing permissions and
15 *  * limitations under the License.
16 *
17 */
18
19use std::time::Duration;
20
21use crate::memdx::auth_mechanism::AuthMechanism;
22use crate::memdx::durability_level::DurabilityLevel;
23use crate::memdx::hello_feature::HelloFeature;
24use crate::memdx::subdoc::{LookupInOp, MutateInOp, SubdocDocFlag};
25
26#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
27pub struct HelloRequest {
28    pub(crate) client_name: Vec<u8>,
29    pub(crate) requested_features: Vec<HelloFeature>,
30}
31
32impl HelloRequest {
33    pub fn new(client_name: Vec<u8>, requested_features: Vec<HelloFeature>) -> Self {
34        Self {
35            client_name,
36            requested_features,
37        }
38    }
39}
40
41#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
42pub struct GetErrorMapRequest {
43    pub(crate) version: u16,
44}
45
46impl GetErrorMapRequest {
47    pub fn new(version: u16) -> Self {
48        Self { version }
49    }
50}
51
52#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
53pub struct SelectBucketRequest {
54    pub(crate) bucket_name: String,
55}
56
57impl SelectBucketRequest {
58    pub fn new(bucket_name: String) -> Self {
59        Self { bucket_name }
60    }
61}
62
63#[derive(Clone, Default, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
64pub struct GetClusterConfigKnownVersion {
65    pub rev_epoch: i64,
66    pub rev_id: i64,
67}
68
69#[derive(Clone, Default, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
70pub struct GetClusterConfigRequest {
71    pub known_version: Option<GetClusterConfigKnownVersion>,
72}
73
74impl GetClusterConfigRequest {
75    pub fn new() -> Self {
76        Self {
77            known_version: None,
78        }
79    }
80}
81
82#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
83pub struct GetCollectionIdRequest<'a> {
84    pub(crate) scope_name: &'a str,
85    pub(crate) collection_name: &'a str,
86}
87
88impl<'a> GetCollectionIdRequest<'a> {
89    pub fn new(scope_name: &'a str, collection_name: &'a str) -> Self {
90        Self {
91            scope_name,
92            collection_name,
93        }
94    }
95}
96
97#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
98pub struct SASLAuthRequest {
99    pub(crate) auth_mechanism: AuthMechanism,
100    pub(crate) payload: Vec<u8>,
101}
102
103impl SASLAuthRequest {
104    pub fn new(auth_mechanism: AuthMechanism, payload: Vec<u8>) -> Self {
105        Self {
106            auth_mechanism,
107            payload,
108        }
109    }
110}
111
112#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
113pub struct SASLStepRequest {
114    pub(crate) auth_mechanism: AuthMechanism,
115    pub(crate) payload: Vec<u8>,
116}
117
118impl SASLStepRequest {
119    pub fn new(auth_mechanism: AuthMechanism, payload: Vec<u8>) -> Self {
120        Self {
121            auth_mechanism,
122            payload,
123        }
124    }
125}
126
127#[derive(Clone, Default, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
128pub struct SASLListMechsRequest {}
129
130impl SASLListMechsRequest {
131    pub fn new() -> Self {
132        Self {}
133    }
134}
135
136#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
137pub struct SetRequest<'a> {
138    pub(crate) collection_id: u32,
139    pub(crate) key: &'a [u8],
140    pub(crate) vbucket_id: u16,
141    pub(crate) flags: u32,
142    pub(crate) value: &'a [u8],
143    pub(crate) datatype: u8,
144    pub(crate) expiry: Option<u32>,
145    pub(crate) preserve_expiry: Option<bool>,
146    pub(crate) cas: Option<u64>,
147    pub(crate) on_behalf_of: Option<&'a str>,
148    pub(crate) durability_level: Option<DurabilityLevel>,
149    pub(crate) durability_level_timeout: Option<Duration>,
150}
151
152impl<'a> SetRequest<'a> {
153    pub fn new(
154        collection_id: u32,
155        key: &'a [u8],
156        vbucket_id: u16,
157        flags: u32,
158        value: &'a [u8],
159        datatype: u8,
160    ) -> Self {
161        Self {
162            collection_id,
163            key,
164            vbucket_id,
165            flags,
166            value,
167            datatype,
168            expiry: None,
169            preserve_expiry: None,
170            cas: None,
171            on_behalf_of: None,
172            durability_level: None,
173            durability_level_timeout: None,
174        }
175    }
176
177    pub fn expiry(mut self, expiry: u32) -> Self {
178        self.expiry = Some(expiry);
179        self
180    }
181
182    pub fn preserve_expiry(mut self, preserve_expiry: bool) -> Self {
183        self.preserve_expiry = Some(preserve_expiry);
184        self
185    }
186
187    pub fn cas(mut self, cas: u64) -> Self {
188        self.cas = Some(cas);
189        self
190    }
191
192    pub fn on_behalf_of(mut self, on_behalf_of: &'a str) -> Self {
193        self.on_behalf_of = Some(on_behalf_of);
194        self
195    }
196
197    pub fn durability_level(mut self, durability_level: DurabilityLevel) -> Self {
198        self.durability_level = Some(durability_level);
199        self
200    }
201
202    pub fn durability_level_timeout(mut self, durability_level_timeout: Duration) -> Self {
203        self.durability_level_timeout = Some(durability_level_timeout);
204        self
205    }
206}
207
208#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
209pub struct GetRequest<'a> {
210    pub(crate) collection_id: u32,
211    pub(crate) key: &'a [u8],
212    pub(crate) vbucket_id: u16,
213    pub(crate) on_behalf_of: Option<&'a str>,
214}
215
216impl<'a> GetRequest<'a> {
217    pub fn new(collection_id: u32, key: &'a [u8], vbucket_id: u16) -> Self {
218        Self {
219            collection_id,
220            key,
221            vbucket_id,
222            on_behalf_of: None,
223        }
224    }
225
226    pub fn on_behalf_of(mut self, on_behalf_of: &'a str) -> Self {
227        self.on_behalf_of = Some(on_behalf_of);
228        self
229    }
230}
231
232#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
233pub struct GetMetaRequest<'a> {
234    pub(crate) collection_id: u32,
235    pub(crate) key: &'a [u8],
236    pub(crate) vbucket_id: u16,
237    pub(crate) on_behalf_of: Option<&'a str>,
238}
239
240impl<'a> GetMetaRequest<'a> {
241    pub fn new(collection_id: u32, key: &'a [u8], vbucket_id: u16) -> Self {
242        Self {
243            collection_id,
244            key,
245            vbucket_id,
246            on_behalf_of: None,
247        }
248    }
249
250    pub fn on_behalf_of(mut self, on_behalf_of: &'a str) -> Self {
251        self.on_behalf_of = Some(on_behalf_of);
252        self
253    }
254}
255
256#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
257pub struct DeleteRequest<'a> {
258    pub(crate) collection_id: u32,
259    pub(crate) key: &'a [u8],
260    pub(crate) vbucket_id: u16,
261    pub(crate) cas: Option<u64>,
262    pub(crate) on_behalf_of: Option<&'a str>,
263    pub(crate) durability_level: Option<DurabilityLevel>,
264    pub(crate) durability_level_timeout: Option<Duration>,
265}
266
267impl<'a> DeleteRequest<'a> {
268    pub fn new(collection_id: u32, key: &'a [u8], vbucket_id: u16) -> Self {
269        Self {
270            collection_id,
271            key,
272            vbucket_id,
273            cas: None,
274            on_behalf_of: None,
275            durability_level: None,
276            durability_level_timeout: None,
277        }
278    }
279
280    pub fn cas(mut self, cas: u64) -> Self {
281        self.cas = Some(cas);
282        self
283    }
284
285    pub fn on_behalf_of(mut self, on_behalf_of: &'a str) -> Self {
286        self.on_behalf_of = Some(on_behalf_of);
287        self
288    }
289
290    pub fn durability_level(mut self, durability_level: DurabilityLevel) -> Self {
291        self.durability_level = Some(durability_level);
292        self
293    }
294
295    pub fn durability_level_timeout(mut self, durability_level_timeout: Duration) -> Self {
296        self.durability_level_timeout = Some(durability_level_timeout);
297        self
298    }
299}
300
301#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
302pub struct GetAndLockRequest<'a> {
303    pub(crate) collection_id: u32,
304    pub(crate) key: &'a [u8],
305    pub(crate) vbucket_id: u16,
306    pub(crate) lock_time: u32,
307    pub(crate) on_behalf_of: Option<&'a str>,
308}
309
310impl<'a> GetAndLockRequest<'a> {
311    pub fn new(collection_id: u32, key: &'a [u8], vbucket_id: u16, lock_time: u32) -> Self {
312        Self {
313            collection_id,
314            key,
315            vbucket_id,
316            lock_time,
317            on_behalf_of: None,
318        }
319    }
320
321    pub fn on_behalf_of(mut self, on_behalf_of: &'a str) -> Self {
322        self.on_behalf_of = Some(on_behalf_of);
323        self
324    }
325}
326
327#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
328pub struct GetAndTouchRequest<'a> {
329    pub(crate) collection_id: u32,
330    pub(crate) key: &'a [u8],
331    pub(crate) vbucket_id: u16,
332    pub(crate) expiry: u32,
333    pub(crate) on_behalf_of: Option<&'a str>,
334}
335
336impl<'a> GetAndTouchRequest<'a> {
337    pub fn new(collection_id: u32, key: &'a [u8], vbucket_id: u16, expiry: u32) -> Self {
338        Self {
339            collection_id,
340            key,
341            vbucket_id,
342            expiry,
343            on_behalf_of: None,
344        }
345    }
346
347    pub fn on_behalf_of(mut self, on_behalf_of: &'a str) -> Self {
348        self.on_behalf_of = Some(on_behalf_of);
349        self
350    }
351}
352
353#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
354pub struct UnlockRequest<'a> {
355    pub(crate) collection_id: u32,
356    pub(crate) key: &'a [u8],
357    pub(crate) vbucket_id: u16,
358    pub(crate) cas: u64,
359    pub(crate) on_behalf_of: Option<&'a str>,
360}
361
362impl<'a> UnlockRequest<'a> {
363    pub fn new(collection_id: u32, key: &'a [u8], vbucket_id: u16, cas: u64) -> Self {
364        Self {
365            collection_id,
366            key,
367            vbucket_id,
368            cas,
369            on_behalf_of: None,
370        }
371    }
372
373    pub fn on_behalf_of(mut self, on_behalf_of: &'a str) -> Self {
374        self.on_behalf_of = Some(on_behalf_of);
375        self
376    }
377}
378
379#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
380pub struct TouchRequest<'a> {
381    pub(crate) collection_id: u32,
382    pub(crate) key: &'a [u8],
383    pub(crate) vbucket_id: u16,
384    pub(crate) expiry: u32,
385    pub(crate) on_behalf_of: Option<&'a str>,
386}
387
388impl<'a> TouchRequest<'a> {
389    pub fn new(collection_id: u32, key: &'a [u8], vbucket_id: u16, expiry: u32) -> Self {
390        Self {
391            collection_id,
392            key,
393            vbucket_id,
394            expiry,
395            on_behalf_of: None,
396        }
397    }
398
399    pub fn on_behalf_of(mut self, on_behalf_of: &'a str) -> Self {
400        self.on_behalf_of = Some(on_behalf_of);
401        self
402    }
403}
404
405#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
406pub struct AddRequest<'a> {
407    pub(crate) collection_id: u32,
408    pub(crate) key: &'a [u8],
409    pub(crate) vbucket_id: u16,
410    pub(crate) flags: u32,
411    pub(crate) value: &'a [u8],
412    pub(crate) datatype: u8,
413    pub(crate) expiry: Option<u32>,
414    pub(crate) on_behalf_of: Option<&'a str>,
415    pub(crate) durability_level: Option<DurabilityLevel>,
416    pub(crate) durability_level_timeout: Option<Duration>,
417}
418
419impl<'a> AddRequest<'a> {
420    pub fn new(
421        collection_id: u32,
422        key: &'a [u8],
423        vbucket_id: u16,
424        flags: u32,
425        value: &'a [u8],
426        datatype: u8,
427    ) -> Self {
428        Self {
429            collection_id,
430            key,
431            vbucket_id,
432            flags,
433            value,
434            datatype,
435            expiry: None,
436            on_behalf_of: None,
437            durability_level: None,
438            durability_level_timeout: None,
439        }
440    }
441
442    pub fn expiry(mut self, expiry: u32) -> Self {
443        self.expiry = Some(expiry);
444        self
445    }
446
447    pub fn on_behalf_of(mut self, on_behalf_of: &'a str) -> Self {
448        self.on_behalf_of = Some(on_behalf_of);
449        self
450    }
451
452    pub fn durability_level(mut self, durability_level: DurabilityLevel) -> Self {
453        self.durability_level = Some(durability_level);
454        self
455    }
456
457    pub fn durability_level_timeout(mut self, durability_level_timeout: Duration) -> Self {
458        self.durability_level_timeout = Some(durability_level_timeout);
459        self
460    }
461}
462
463#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
464pub struct ReplaceRequest<'a> {
465    pub(crate) collection_id: u32,
466    pub(crate) key: &'a [u8],
467    pub(crate) vbucket_id: u16,
468    pub(crate) flags: u32,
469    pub(crate) value: &'a [u8],
470    pub(crate) datatype: u8,
471    pub(crate) expiry: Option<u32>,
472    pub(crate) preserve_expiry: Option<bool>,
473    pub(crate) cas: Option<u64>,
474    pub(crate) on_behalf_of: Option<&'a str>,
475    pub(crate) durability_level: Option<DurabilityLevel>,
476    pub(crate) durability_level_timeout: Option<Duration>,
477}
478
479impl<'a> ReplaceRequest<'a> {
480    pub fn new(
481        collection_id: u32,
482        key: &'a [u8],
483        vbucket_id: u16,
484        flags: u32,
485        value: &'a [u8],
486        datatype: u8,
487    ) -> Self {
488        Self {
489            collection_id,
490            key,
491            vbucket_id,
492            flags,
493            value,
494            datatype,
495            expiry: None,
496            preserve_expiry: None,
497            cas: None,
498            on_behalf_of: None,
499            durability_level: None,
500            durability_level_timeout: None,
501        }
502    }
503
504    pub fn expiry(mut self, expiry: u32) -> Self {
505        self.expiry = Some(expiry);
506        self
507    }
508
509    pub fn preserve_expiry(mut self, preserve_expiry: bool) -> Self {
510        self.preserve_expiry = Some(preserve_expiry);
511        self
512    }
513
514    pub fn cas(mut self, cas: u64) -> Self {
515        self.cas = Some(cas);
516        self
517    }
518
519    pub fn on_behalf_of(mut self, on_behalf_of: &'a str) -> Self {
520        self.on_behalf_of = Some(on_behalf_of);
521        self
522    }
523
524    pub fn durability_level(mut self, durability_level: DurabilityLevel) -> Self {
525        self.durability_level = Some(durability_level);
526        self
527    }
528
529    pub fn durability_level_timeout(mut self, durability_level_timeout: Duration) -> Self {
530        self.durability_level_timeout = Some(durability_level_timeout);
531        self
532    }
533}
534
535#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
536pub struct AppendRequest<'a> {
537    pub(crate) collection_id: u32,
538    pub(crate) key: &'a [u8],
539    pub(crate) vbucket_id: u16,
540    pub(crate) value: &'a [u8],
541    pub(crate) datatype: u8,
542    pub(crate) cas: Option<u64>,
543    pub(crate) on_behalf_of: Option<&'a str>,
544    pub(crate) durability_level: Option<DurabilityLevel>,
545    pub(crate) durability_level_timeout: Option<Duration>,
546}
547
548impl<'a> AppendRequest<'a> {
549    pub fn new(
550        collection_id: u32,
551        key: &'a [u8],
552        vbucket_id: u16,
553        value: &'a [u8],
554        datatype: u8,
555    ) -> Self {
556        Self {
557            collection_id,
558            key,
559            vbucket_id,
560            value,
561            datatype,
562            cas: None,
563            on_behalf_of: None,
564            durability_level: None,
565            durability_level_timeout: None,
566        }
567    }
568
569    pub fn cas(mut self, cas: u64) -> Self {
570        self.cas = Some(cas);
571        self
572    }
573
574    pub fn on_behalf_of(mut self, on_behalf_of: &'a str) -> Self {
575        self.on_behalf_of = Some(on_behalf_of);
576        self
577    }
578
579    pub fn durability_level(mut self, durability_level: DurabilityLevel) -> Self {
580        self.durability_level = Some(durability_level);
581        self
582    }
583
584    pub fn durability_level_timeout(mut self, durability_level_timeout: Duration) -> Self {
585        self.durability_level_timeout = Some(durability_level_timeout);
586        self
587    }
588}
589
590#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
591pub struct PrependRequest<'a> {
592    pub(crate) collection_id: u32,
593    pub(crate) key: &'a [u8],
594    pub(crate) vbucket_id: u16,
595    pub(crate) value: &'a [u8],
596    pub(crate) datatype: u8,
597    pub(crate) cas: Option<u64>,
598    pub(crate) on_behalf_of: Option<&'a str>,
599    pub(crate) durability_level: Option<DurabilityLevel>,
600    pub(crate) durability_level_timeout: Option<Duration>,
601}
602
603impl<'a> PrependRequest<'a> {
604    pub fn new(
605        collection_id: u32,
606        key: &'a [u8],
607        vbucket_id: u16,
608        value: &'a [u8],
609        datatype: u8,
610    ) -> Self {
611        Self {
612            collection_id,
613            key,
614            vbucket_id,
615            value,
616            datatype,
617            cas: None,
618            on_behalf_of: None,
619            durability_level: None,
620            durability_level_timeout: None,
621        }
622    }
623
624    pub fn cas(mut self, cas: u64) -> Self {
625        self.cas = Some(cas);
626        self
627    }
628
629    pub fn on_behalf_of(mut self, on_behalf_of: &'a str) -> Self {
630        self.on_behalf_of = Some(on_behalf_of);
631        self
632    }
633
634    pub fn durability_level(mut self, durability_level: DurabilityLevel) -> Self {
635        self.durability_level = Some(durability_level);
636        self
637    }
638
639    pub fn durability_level_timeout(mut self, durability_level_timeout: Duration) -> Self {
640        self.durability_level_timeout = Some(durability_level_timeout);
641        self
642    }
643}
644
645#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
646pub struct IncrementRequest<'a> {
647    pub(crate) collection_id: u32,
648    pub(crate) key: &'a [u8],
649    pub(crate) vbucket_id: u16,
650    pub(crate) initial: Option<u64>,
651    pub(crate) delta: u64,
652    pub(crate) expiry: Option<u32>,
653    pub(crate) on_behalf_of: Option<&'a str>,
654    pub(crate) durability_level: Option<DurabilityLevel>,
655    pub(crate) durability_level_timeout: Option<Duration>,
656}
657
658impl<'a> IncrementRequest<'a> {
659    pub fn new(collection_id: u32, key: &'a [u8], delta: u64, vbucket_id: u16) -> Self {
660        Self {
661            collection_id,
662            key,
663            vbucket_id,
664            initial: None,
665            delta,
666            expiry: None,
667            on_behalf_of: None,
668            durability_level: None,
669            durability_level_timeout: None,
670        }
671    }
672
673    pub fn initial(mut self, initial: u64) -> Self {
674        self.initial = Some(initial);
675        self
676    }
677
678    pub fn expiry(mut self, expiry: u32) -> Self {
679        self.expiry = Some(expiry);
680        self
681    }
682
683    pub fn on_behalf_of(mut self, on_behalf_of: &'a str) -> Self {
684        self.on_behalf_of = Some(on_behalf_of);
685        self
686    }
687
688    pub fn durability_level(mut self, durability_level: DurabilityLevel) -> Self {
689        self.durability_level = Some(durability_level);
690        self
691    }
692
693    pub fn durability_level_timeout(mut self, durability_level_timeout: Duration) -> Self {
694        self.durability_level_timeout = Some(durability_level_timeout);
695        self
696    }
697}
698
699#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
700pub struct DecrementRequest<'a> {
701    pub(crate) collection_id: u32,
702    pub(crate) key: &'a [u8],
703    pub(crate) vbucket_id: u16,
704    pub(crate) initial: Option<u64>,
705    pub(crate) delta: u64,
706    pub(crate) expiry: Option<u32>,
707    pub(crate) on_behalf_of: Option<&'a str>,
708    pub(crate) durability_level: Option<DurabilityLevel>,
709    pub(crate) durability_level_timeout: Option<Duration>,
710}
711
712impl<'a> DecrementRequest<'a> {
713    pub fn new(collection_id: u32, key: &'a [u8], delta: u64, vbucket_id: u16) -> Self {
714        Self {
715            collection_id,
716            key,
717            vbucket_id,
718            initial: None,
719            delta,
720            expiry: None,
721            on_behalf_of: None,
722            durability_level: None,
723            durability_level_timeout: None,
724        }
725    }
726
727    pub fn initial(mut self, initial: u64) -> Self {
728        self.initial = Some(initial);
729        self
730    }
731
732    pub fn expiry(mut self, expiry: u32) -> Self {
733        self.expiry = Some(expiry);
734        self
735    }
736
737    pub fn on_behalf_of(mut self, on_behalf_of: &'a str) -> Self {
738        self.on_behalf_of = Some(on_behalf_of);
739        self
740    }
741
742    pub fn durability_level(mut self, durability_level: DurabilityLevel) -> Self {
743        self.durability_level = Some(durability_level);
744        self
745    }
746
747    pub fn durability_level_timeout(mut self, durability_level_timeout: Duration) -> Self {
748        self.durability_level_timeout = Some(durability_level_timeout);
749        self
750    }
751}
752
753#[derive(Clone, Debug, Eq, PartialEq)]
754pub struct LookupInRequest<'a> {
755    pub(crate) collection_id: u32,
756    pub(crate) key: &'a [u8],
757    pub(crate) vbucket_id: u16,
758    pub(crate) flags: SubdocDocFlag,
759    pub(crate) ops: &'a [LookupInOp<'a>],
760    pub(crate) on_behalf_of: Option<&'a str>,
761}
762
763impl<'a> LookupInRequest<'a> {
764    pub fn new(
765        collection_id: u32,
766        key: &'a [u8],
767        vbucket_id: u16,
768        flags: SubdocDocFlag,
769        ops: &'a [LookupInOp<'a>],
770    ) -> Self {
771        Self {
772            collection_id,
773            key,
774            vbucket_id,
775            flags,
776            ops,
777            on_behalf_of: None,
778        }
779    }
780
781    pub fn on_behalf_of(mut self, on_behalf_of: &'a str) -> Self {
782        self.on_behalf_of = Some(on_behalf_of);
783        self
784    }
785}
786
787#[derive(Clone, Debug, Eq, PartialEq)]
788pub struct MutateInRequest<'a> {
789    pub(crate) collection_id: u32,
790    pub(crate) key: &'a [u8],
791    pub(crate) vbucket_id: u16,
792    pub(crate) flags: SubdocDocFlag,
793    pub(crate) ops: &'a [MutateInOp<'a>],
794    pub(crate) expiry: Option<u32>,
795    pub(crate) preserve_expiry: Option<bool>,
796    pub(crate) cas: Option<u64>,
797    pub(crate) on_behalf_of: Option<&'a str>,
798    pub(crate) durability_level: Option<DurabilityLevel>,
799    pub(crate) durability_level_timeout: Option<Duration>,
800}
801
802impl<'a> MutateInRequest<'a> {
803    pub fn new(
804        collection_id: u32,
805        key: &'a [u8],
806        vbucket_id: u16,
807        flags: SubdocDocFlag,
808        ops: &'a [MutateInOp<'a>],
809    ) -> Self {
810        Self {
811            collection_id,
812            key,
813            vbucket_id,
814            flags,
815            ops,
816            expiry: None,
817            preserve_expiry: None,
818            cas: None,
819            on_behalf_of: None,
820            durability_level: None,
821            durability_level_timeout: None,
822        }
823    }
824
825    pub fn expiry(mut self, expiry: u32) -> Self {
826        self.expiry = Some(expiry);
827        self
828    }
829
830    pub fn preserve_expiry(mut self, preserve_expiry: bool) -> Self {
831        self.preserve_expiry = Some(preserve_expiry);
832        self
833    }
834
835    pub fn cas(mut self, cas: u64) -> Self {
836        self.cas = Some(cas);
837        self
838    }
839
840    pub fn on_behalf_of(mut self, on_behalf_of: &'a str) -> Self {
841        self.on_behalf_of = Some(on_behalf_of);
842        self
843    }
844
845    pub fn durability_level(mut self, durability_level: DurabilityLevel) -> Self {
846        self.durability_level = Some(durability_level);
847        self
848    }
849
850    pub fn durability_level_timeout(mut self, durability_level_timeout: Duration) -> Self {
851        self.durability_level_timeout = Some(durability_level_timeout);
852        self
853    }
854}
855
856#[derive(Default, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
857pub struct PingRequest<'a> {
858    pub(crate) on_behalf_of: Option<&'a str>,
859}
860
861impl<'a> PingRequest<'a> {
862    pub fn new() -> Self {
863        Self { on_behalf_of: None }
864    }
865
866    pub fn on_behalf_of(mut self, on_behalf_of: &'a str) -> Self {
867        self.on_behalf_of = Some(on_behalf_of);
868        self
869    }
870}