1use crate::{
4 AccessGrants, AccessRevisionNo, ActorId, AttributeKey, AttributeRevisionNo, AttributeValue,
5 CommitId, CommitPrecondition, DeleteDirectoryBehavior, DestinationBehavior, InodeId,
6 RevisionNo,
7};
8use crate::{SnapshotId, Subject};
9use std::collections::BTreeMap;
10
11#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
13pub enum AttributeInclusion {
14 Include,
16 #[default]
18 Omit,
19}
20
21impl std::fmt::Display for AttributeInclusion {
22 fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
23 formatter.write_str(match self {
24 Self::Include => "true",
25 Self::Omit => "false",
26 })
27 }
28}
29
30#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
32#[serde(deny_unknown_fields)]
33pub struct CommitOptions {
34 pub actor_id: ActorId,
36 #[serde(skip)]
38 pub subject: Option<Subject>,
39 pub commit_id: Option<CommitId>,
41 pub message: Option<String>,
43 #[serde(default, skip_serializing_if = "Vec::is_empty")]
45 pub preconditions: Vec<CommitPrecondition>,
46}
47
48impl CommitOptions {
49 pub fn new(actor: ActorId) -> Self {
51 Self {
52 actor_id: actor,
53 subject: None,
54 commit_id: None,
55 message: None,
56 preconditions: Vec::new(),
57 }
58 }
59}
60
61#[derive(Debug, Clone, PartialEq, Eq)]
63pub struct StatPathOptions {
64 pub include_attributes: AttributeInclusion,
66 pub snapshot_id: Option<SnapshotId>,
68}
69
70impl Default for StatPathOptions {
71 fn default() -> Self {
72 Self {
73 include_attributes: AttributeInclusion::Include,
74 snapshot_id: None,
75 }
76 }
77}
78
79#[derive(Debug, Clone, PartialEq, Eq, Default)]
81pub struct ListPathEntriesOptions {
82 pub include_attributes: AttributeInclusion,
84 pub snapshot_id: Option<SnapshotId>,
86}
87
88#[derive(Debug, Clone, PartialEq, Eq, Default)]
90pub struct ListInodeChildrenOptions {
91 pub include_attributes: AttributeInclusion,
93 pub snapshot_id: Option<SnapshotId>,
95}
96
97#[derive(Debug, Clone, PartialEq, Eq)]
99pub struct UpdateAttributesOptions {
100 pub set: BTreeMap<AttributeKey, AttributeValue>,
103 pub remove: Vec<AttributeKey>,
105 pub commit: CommitOptions,
107 pub expected_inode_id: Option<InodeId>,
109 pub expected_attributes_revision_no: Option<AttributeRevisionNo>,
111}
112
113impl UpdateAttributesOptions {
114 pub fn new(actor: ActorId) -> Self {
116 Self {
117 set: BTreeMap::new(),
118 remove: Vec::new(),
119 commit: CommitOptions::new(actor),
120 expected_inode_id: None,
121 expected_attributes_revision_no: None,
122 }
123 }
124}
125
126#[derive(Debug, Clone, PartialEq, Eq)]
128pub struct UpdateAccessOptions {
129 pub boundary: bool,
131 pub grants: AccessGrants,
133 pub commit: CommitOptions,
135 pub expected_inode_id: Option<InodeId>,
137 pub expected_access_revision_no: Option<AccessRevisionNo>,
139}
140
141impl UpdateAccessOptions {
142 pub fn new(actor: ActorId, grants: AccessGrants) -> Self {
144 Self {
145 boundary: false,
146 grants,
147 commit: CommitOptions::new(actor),
148 expected_inode_id: None,
149 expected_access_revision_no: None,
150 }
151 }
152}
153
154#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
156#[serde(deny_unknown_fields)]
157pub struct PutFileOptions {
158 pub behavior: DestinationBehavior,
160 pub commit: CommitOptions,
162 pub expected_inode_id: Option<InodeId>,
164 pub expected_revision_no: Option<RevisionNo>,
167}
168
169impl PutFileOptions {
170 pub fn new(actor: ActorId) -> Self {
172 Self {
173 behavior: DestinationBehavior::NoReplace,
174 commit: CommitOptions::new(actor),
175 expected_inode_id: None,
176 expected_revision_no: None,
177 }
178 }
179}
180
181#[derive(Debug, Clone, PartialEq, Eq)]
183pub struct CreateDirectoryOptions {
184 pub commit: CommitOptions,
186 pub parents: bool,
188}
189
190impl CreateDirectoryOptions {
191 pub fn new(actor: ActorId) -> Self {
193 Self {
194 commit: CommitOptions::new(actor),
195 parents: false,
196 }
197 }
198}
199
200#[derive(Debug, Clone, PartialEq, Eq)]
202pub struct DeleteOptions {
203 pub behavior: DeleteDirectoryBehavior,
205 pub commit: CommitOptions,
207 pub expected_inode_id: Option<InodeId>,
209}
210
211impl DeleteOptions {
212 pub fn new(actor: ActorId) -> Self {
214 Self {
215 behavior: DeleteDirectoryBehavior::NonRecursive,
216 commit: CommitOptions::new(actor),
217 expected_inode_id: None,
218 }
219 }
220}
221
222#[derive(Debug, Clone, PartialEq, Eq)]
224pub struct MoveOptions {
225 pub behavior: DestinationBehavior,
227 pub commit: CommitOptions,
229 pub expected_destination_inode_id: Option<InodeId>,
231 pub expected_destination_revision_no: Option<RevisionNo>,
234}
235
236impl MoveOptions {
237 pub fn new(actor: ActorId) -> Self {
239 Self {
240 behavior: DestinationBehavior::NoReplace,
241 commit: CommitOptions::new(actor),
242 expected_destination_inode_id: None,
243 expected_destination_revision_no: None,
244 }
245 }
246}
247
248#[derive(Debug, Clone, PartialEq, Eq)]
250pub struct CopyOptions {
251 pub behavior: DestinationBehavior,
253 pub commit: CommitOptions,
255 pub expected_destination_inode_id: Option<InodeId>,
257 pub expected_destination_revision_no: Option<RevisionNo>,
260}
261
262impl CopyOptions {
263 pub fn new(actor: ActorId) -> Self {
265 Self {
266 behavior: DestinationBehavior::NoReplace,
267 commit: CommitOptions::new(actor),
268 expected_destination_inode_id: None,
269 expected_destination_revision_no: None,
270 }
271 }
272}
273
274#[derive(Debug, Clone, PartialEq, Eq)]
276pub struct RestoreRevisionOptions {
277 pub commit: CommitOptions,
279}
280
281impl RestoreRevisionOptions {
282 pub fn new(actor: ActorId) -> Self {
284 Self {
285 commit: CommitOptions::new(actor),
286 }
287 }
288}
289
290#[derive(Debug, Clone, PartialEq, Eq)]
292pub struct UndeleteOptions {
293 pub commit: CommitOptions,
295}
296
297impl UndeleteOptions {
298 pub fn new(actor: ActorId) -> Self {
300 Self {
301 commit: CommitOptions::new(actor),
302 }
303 }
304}
305
306#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
308pub struct DirectMultipartUploadOptions {
309 pub part_size_bytes: Option<u64>,
312}
313
314#[derive(Debug, Clone, PartialEq, Eq)]
316pub struct ForkNamespaceOptions {
317 pub actor_id: ActorId,
319 pub snapshot_id: Option<crate::SnapshotId>,
321}
322
323impl ForkNamespaceOptions {
324 pub fn new(actor_id: ActorId) -> Self {
326 Self {
327 actor_id,
328 snapshot_id: None,
329 }
330 }
331}