1use std::collections::BTreeMap;
2
3use serde::{Deserialize, Serialize};
4use serde_json::Value;
5
6use crate::{NodeKind, Revision, VirtualPath};
7
8pub const DEFAULT_PAGE_LIMIT: u32 = 100;
10
11#[non_exhaustive]
13#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
14pub struct ByteRange {
15 pub start: u64,
17 pub end: u64,
19}
20
21impl ByteRange {
22 pub const fn new(start: u64, end: u64) -> Self {
24 Self { start, end }
25 }
26
27 pub const fn len(self) -> u64 {
29 self.end.saturating_sub(self.start)
30 }
31
32 pub const fn is_empty(self) -> bool {
34 self.start >= self.end
35 }
36}
37
38#[non_exhaustive]
40#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
41pub struct PageRequest {
42 pub cursor: Option<String>,
44 pub limit: u32,
46}
47
48impl PageRequest {
49 #[must_use]
51 pub fn cursor(mut self, cursor: Option<String>) -> Self {
52 self.cursor = cursor;
53 self
54 }
55
56 #[must_use]
58 pub const fn limit(mut self, limit: u32) -> Self {
59 self.limit = limit;
60 self
61 }
62}
63
64impl Default for PageRequest {
65 fn default() -> Self {
66 Self {
67 cursor: None,
68 limit: DEFAULT_PAGE_LIMIT,
69 }
70 }
71}
72
73#[non_exhaustive]
75#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
76pub struct StatOptions {
77 pub follow_symlinks: bool,
79}
80
81impl StatOptions {
82 #[must_use]
84 pub const fn follow_symlinks(mut self, follow_symlinks: bool) -> Self {
85 self.follow_symlinks = follow_symlinks;
86 self
87 }
88}
89
90impl Default for StatOptions {
91 fn default() -> Self {
92 Self {
93 follow_symlinks: true,
94 }
95 }
96}
97
98#[non_exhaustive]
100#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
101pub struct TreeOptions {
102 pub max_depth: Option<u32>,
104 pub follow_symlinks: bool,
106}
107
108impl TreeOptions {
109 #[must_use]
111 pub const fn max_depth(mut self, max_depth: Option<u32>) -> Self {
112 self.max_depth = max_depth;
113 self
114 }
115
116 #[must_use]
118 pub const fn follow_symlinks(mut self, follow_symlinks: bool) -> Self {
119 self.follow_symlinks = follow_symlinks;
120 self
121 }
122}
123
124#[non_exhaustive]
126#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
127pub struct CreateOptions {
128 pub parents: bool,
130 pub exist_ok: bool,
132 pub expected_revision: Option<Revision>,
134}
135
136impl CreateOptions {
137 #[must_use]
139 pub const fn parents(mut self, parents: bool) -> Self {
140 self.parents = parents;
141 self
142 }
143
144 #[must_use]
146 pub const fn exist_ok(mut self, exist_ok: bool) -> Self {
147 self.exist_ok = exist_ok;
148 self
149 }
150
151 #[must_use]
153 pub const fn expected_revision(mut self, expected_revision: Option<Revision>) -> Self {
154 self.expected_revision = expected_revision;
155 self
156 }
157}
158
159#[non_exhaustive]
161#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
162pub struct ReadOptions {
163 pub range: Option<ByteRange>,
165 pub follow_symlinks: bool,
167}
168
169impl ReadOptions {
170 #[must_use]
172 pub const fn range(mut self, range: Option<ByteRange>) -> Self {
173 self.range = range;
174 self
175 }
176
177 #[must_use]
179 pub const fn follow_symlinks(mut self, follow_symlinks: bool) -> Self {
180 self.follow_symlinks = follow_symlinks;
181 self
182 }
183}
184
185impl Default for ReadOptions {
186 fn default() -> Self {
187 Self {
188 range: None,
189 follow_symlinks: true,
190 }
191 }
192}
193
194#[non_exhaustive]
196#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
197pub struct WriteOptions {
198 pub create: bool,
200 pub expected_revision: Option<Revision>,
202}
203
204impl WriteOptions {
205 #[must_use]
207 pub const fn create(mut self, create: bool) -> Self {
208 self.create = create;
209 self
210 }
211
212 #[must_use]
214 pub const fn expected_revision(mut self, expected_revision: Option<Revision>) -> Self {
215 self.expected_revision = expected_revision;
216 self
217 }
218
219 pub const fn replace() -> Self {
221 Self {
222 create: false,
223 expected_revision: None,
224 }
225 }
226}
227
228impl Default for WriteOptions {
229 fn default() -> Self {
230 Self {
231 create: true,
232 expected_revision: None,
233 }
234 }
235}
236
237#[non_exhaustive]
239#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
240pub struct MutationOptions {
241 pub expected_revision: Option<Revision>,
243}
244
245impl MutationOptions {
246 #[must_use]
248 pub const fn expected_revision(mut self, expected_revision: Option<Revision>) -> Self {
249 self.expected_revision = expected_revision;
250 self
251 }
252}
253
254#[non_exhaustive]
256#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
257pub struct TouchOptions {
258 pub create: bool,
260 pub expected_revision: Option<Revision>,
262}
263
264impl TouchOptions {
265 #[must_use]
267 pub const fn create(mut self, create: bool) -> Self {
268 self.create = create;
269 self
270 }
271
272 #[must_use]
274 pub const fn expected_revision(mut self, expected_revision: Option<Revision>) -> Self {
275 self.expected_revision = expected_revision;
276 self
277 }
278}
279
280impl Default for TouchOptions {
281 fn default() -> Self {
282 Self {
283 create: true,
284 expected_revision: None,
285 }
286 }
287}
288
289#[non_exhaustive]
291#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
292pub struct CopyOptions {
293 pub recursive: bool,
295 pub overwrite: bool,
297 pub expected_revision: Option<Revision>,
299}
300
301impl CopyOptions {
302 #[must_use]
304 pub const fn recursive(mut self, recursive: bool) -> Self {
305 self.recursive = recursive;
306 self
307 }
308
309 #[must_use]
311 pub const fn overwrite(mut self, overwrite: bool) -> Self {
312 self.overwrite = overwrite;
313 self
314 }
315
316 #[must_use]
318 pub const fn expected_revision(mut self, expected_revision: Option<Revision>) -> Self {
319 self.expected_revision = expected_revision;
320 self
321 }
322}
323
324#[non_exhaustive]
326#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
327pub struct MoveOptions {
328 pub overwrite: bool,
330 pub expected_revision: Option<Revision>,
332}
333
334impl MoveOptions {
335 #[must_use]
337 pub const fn overwrite(mut self, overwrite: bool) -> Self {
338 self.overwrite = overwrite;
339 self
340 }
341
342 #[must_use]
344 pub const fn expected_revision(mut self, expected_revision: Option<Revision>) -> Self {
345 self.expected_revision = expected_revision;
346 self
347 }
348}
349
350#[non_exhaustive]
352#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
353pub struct RemoveOptions {
354 pub recursive: bool,
356 pub expected_revision: Option<Revision>,
358}
359
360impl RemoveOptions {
361 #[must_use]
363 pub const fn recursive(mut self, recursive: bool) -> Self {
364 self.recursive = recursive;
365 self
366 }
367
368 #[must_use]
370 pub const fn expected_revision(mut self, expected_revision: Option<Revision>) -> Self {
371 self.expected_revision = expected_revision;
372 self
373 }
374}
375
376#[non_exhaustive]
378#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
379pub struct FindQuery {
380 pub root: VirtualPath,
382 pub name_contains: Option<String>,
384 pub kind: Option<NodeKind>,
386 pub min_logical_size: Option<u64>,
388 pub max_logical_size: Option<u64>,
390 pub modified_after_ms: Option<i64>,
392 pub modified_before_ms: Option<i64>,
394 pub attributes: BTreeMap<String, Value>,
396}
397
398impl FindQuery {
399 #[must_use]
401 pub fn root(mut self, root: VirtualPath) -> Self {
402 self.root = root;
403 self
404 }
405
406 #[must_use]
408 pub fn name_contains(mut self, name_contains: Option<String>) -> Self {
409 self.name_contains = name_contains;
410 self
411 }
412
413 #[must_use]
415 pub const fn kind(mut self, kind: Option<NodeKind>) -> Self {
416 self.kind = kind;
417 self
418 }
419
420 #[must_use]
422 pub const fn min_logical_size(mut self, min_logical_size: Option<u64>) -> Self {
423 self.min_logical_size = min_logical_size;
424 self
425 }
426
427 #[must_use]
429 pub const fn max_logical_size(mut self, max_logical_size: Option<u64>) -> Self {
430 self.max_logical_size = max_logical_size;
431 self
432 }
433
434 #[must_use]
436 pub const fn modified_after_ms(mut self, modified_after_ms: Option<i64>) -> Self {
437 self.modified_after_ms = modified_after_ms;
438 self
439 }
440
441 #[must_use]
443 pub const fn modified_before_ms(mut self, modified_before_ms: Option<i64>) -> Self {
444 self.modified_before_ms = modified_before_ms;
445 self
446 }
447
448 #[must_use]
450 pub fn attributes(mut self, attributes: BTreeMap<String, Value>) -> Self {
451 self.attributes = attributes;
452 self
453 }
454}
455
456impl Default for FindQuery {
457 fn default() -> Self {
458 Self {
459 root: VirtualPath::root(),
460 name_contains: None,
461 kind: None,
462 min_logical_size: None,
463 max_logical_size: None,
464 modified_after_ms: None,
465 modified_before_ms: None,
466 attributes: BTreeMap::new(),
467 }
468 }
469}
470
471#[non_exhaustive]
473#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
474pub struct ContentQuery {
475 pub root: VirtualPath,
477 pub needle: Vec<u8>,
479}
480
481impl ContentQuery {
482 #[must_use]
484 pub fn root(mut self, root: VirtualPath) -> Self {
485 self.root = root;
486 self
487 }
488
489 #[must_use]
491 pub fn needle(mut self, needle: Vec<u8>) -> Self {
492 self.needle = needle;
493 self
494 }
495}
496
497impl Default for ContentQuery {
498 fn default() -> Self {
499 Self {
500 root: VirtualPath::root(),
501 needle: Vec::new(),
502 }
503 }
504}