Skip to main content

fslite_command/
command.rs

1//! The typed operation codec: one [`Command`] variant per
2//! `fslite_core::FileSystem` operation. Byte payloads are bounded, in-memory
3//! `Vec<u8>` (base64 on the wire, via [`crate::bytes_b64`]) — this codec is
4//! sized for CLI use, not for streaming arbitrarily large files.
5
6use fslite_core::{
7    BatchOperation, ChangeCursor, ContentQuery, CopyOptions, CreateOptions, FindQuery, LinkTarget,
8    MoveOptions, MutationOptions, PageRequest, ReadOptions, RemoveOptions, StatOptions,
9    TouchOptions, TrashId, TreeOptions, VirtualPath, WriteOptions,
10};
11use serde::{Deserialize, Serialize};
12
13/// One typed filesystem operation, serializable for local execution,
14/// remote transport, or storage as a `batch --file` script.
15#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
16#[serde(rename_all = "snake_case")]
17pub enum Command {
18    WorkspaceUsage,
19    Stat {
20        path: VirtualPath,
21        options: StatOptions,
22    },
23    Exists {
24        path: VirtualPath,
25        options: StatOptions,
26    },
27    ReadDir {
28        path: VirtualPath,
29        page: PageRequest,
30    },
31    Tree {
32        path: VirtualPath,
33        options: TreeOptions,
34        page: PageRequest,
35    },
36    Mkdir {
37        path: VirtualPath,
38        options: CreateOptions,
39    },
40    Read {
41        path: VirtualPath,
42        options: ReadOptions,
43    },
44    Write {
45        path: VirtualPath,
46        #[serde(with = "crate::bytes_b64")]
47        bytes: Vec<u8>,
48        options: WriteOptions,
49    },
50    WriteAt {
51        path: VirtualPath,
52        offset: u64,
53        #[serde(with = "crate::bytes_b64")]
54        bytes: Vec<u8>,
55        options: WriteOptions,
56    },
57    Append {
58        path: VirtualPath,
59        #[serde(with = "crate::bytes_b64")]
60        bytes: Vec<u8>,
61        options: WriteOptions,
62    },
63    Truncate {
64        path: VirtualPath,
65        length: u64,
66        options: MutationOptions,
67    },
68    Touch {
69        path: VirtualPath,
70        options: TouchOptions,
71    },
72    Copy {
73        from: VirtualPath,
74        to: VirtualPath,
75        options: CopyOptions,
76    },
77    Move {
78        from: VirtualPath,
79        to: VirtualPath,
80        options: MoveOptions,
81    },
82    Remove {
83        path: VirtualPath,
84        options: RemoveOptions,
85    },
86    Symlink {
87        target: LinkTarget,
88        link: VirtualPath,
89        options: CreateOptions,
90    },
91    ReadLink {
92        path: VirtualPath,
93    },
94    Trash {
95        path: VirtualPath,
96        options: MutationOptions,
97    },
98    ListTrash {
99        page: PageRequest,
100    },
101    Restore {
102        trash: TrashId,
103        destination: Option<VirtualPath>,
104        options: MutationOptions,
105    },
106    Purge {
107        trash: TrashId,
108    },
109    SetAttribute {
110        path: VirtualPath,
111        key: String,
112        #[serde(with = "crate::bytes_b64")]
113        value: Vec<u8>,
114        options: MutationOptions,
115    },
116    RemoveAttribute {
117        path: VirtualPath,
118        key: String,
119        options: MutationOptions,
120    },
121    Glob {
122        pattern: String,
123        page: PageRequest,
124    },
125    Find {
126        query: FindQuery,
127        page: PageRequest,
128    },
129    SearchContent {
130        query: ContentQuery,
131        page: PageRequest,
132    },
133    Changes {
134        after: Option<ChangeCursor>,
135        page: PageRequest,
136    },
137    Batch(Vec<BatchOperation>),
138}