jacquard_api/sh_weaver/edit/
root.rs

1// @generated by jacquard-lexicon. DO NOT EDIT.
2//
3// Lexicon: sh.weaver.edit.root
4//
5// This file was automatically generated from Lexicon schemas.
6// Any manual changes will be overwritten on the next regeneration.
7
8/// The starting point for edit history on a notebook.
9#[jacquard_derive::lexicon]
10#[derive(
11    serde::Serialize,
12    serde::Deserialize,
13    Debug,
14    Clone,
15    PartialEq,
16    Eq,
17    jacquard_derive::IntoStatic
18)]
19#[serde(rename_all = "camelCase")]
20pub struct Root<'a> {
21    #[serde(borrow)]
22    pub cid: jacquard_common::types::string::Cid<'a>,
23    #[serde(borrow)]
24    pub doc: crate::sh_weaver::edit::DocRef<'a>,
25    #[serde(borrow)]
26    pub snapshot: jacquard_common::types::blob::BlobRef<'a>,
27    #[serde(borrow)]
28    pub uri: jacquard_common::types::string::AtUri<'a>,
29}
30
31pub mod root_state {
32
33    pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
34    #[allow(unused)]
35    use ::core::marker::PhantomData;
36    mod sealed {
37        pub trait Sealed {}
38    }
39    /// State trait tracking which required fields have been set
40    pub trait State: sealed::Sealed {
41        type Cid;
42        type Uri;
43        type Doc;
44        type Snapshot;
45    }
46    /// Empty state - all required fields are unset
47    pub struct Empty(());
48    impl sealed::Sealed for Empty {}
49    impl State for Empty {
50        type Cid = Unset;
51        type Uri = Unset;
52        type Doc = Unset;
53        type Snapshot = Unset;
54    }
55    ///State transition - sets the `cid` field to Set
56    pub struct SetCid<S: State = Empty>(PhantomData<fn() -> S>);
57    impl<S: State> sealed::Sealed for SetCid<S> {}
58    impl<S: State> State for SetCid<S> {
59        type Cid = Set<members::cid>;
60        type Uri = S::Uri;
61        type Doc = S::Doc;
62        type Snapshot = S::Snapshot;
63    }
64    ///State transition - sets the `uri` field to Set
65    pub struct SetUri<S: State = Empty>(PhantomData<fn() -> S>);
66    impl<S: State> sealed::Sealed for SetUri<S> {}
67    impl<S: State> State for SetUri<S> {
68        type Cid = S::Cid;
69        type Uri = Set<members::uri>;
70        type Doc = S::Doc;
71        type Snapshot = S::Snapshot;
72    }
73    ///State transition - sets the `doc` field to Set
74    pub struct SetDoc<S: State = Empty>(PhantomData<fn() -> S>);
75    impl<S: State> sealed::Sealed for SetDoc<S> {}
76    impl<S: State> State for SetDoc<S> {
77        type Cid = S::Cid;
78        type Uri = S::Uri;
79        type Doc = Set<members::doc>;
80        type Snapshot = S::Snapshot;
81    }
82    ///State transition - sets the `snapshot` field to Set
83    pub struct SetSnapshot<S: State = Empty>(PhantomData<fn() -> S>);
84    impl<S: State> sealed::Sealed for SetSnapshot<S> {}
85    impl<S: State> State for SetSnapshot<S> {
86        type Cid = S::Cid;
87        type Uri = S::Uri;
88        type Doc = S::Doc;
89        type Snapshot = Set<members::snapshot>;
90    }
91    /// Marker types for field names
92    #[allow(non_camel_case_types)]
93    pub mod members {
94        ///Marker type for the `cid` field
95        pub struct cid(());
96        ///Marker type for the `uri` field
97        pub struct uri(());
98        ///Marker type for the `doc` field
99        pub struct doc(());
100        ///Marker type for the `snapshot` field
101        pub struct snapshot(());
102    }
103}
104
105/// Builder for constructing an instance of this type
106pub struct RootBuilder<'a, S: root_state::State> {
107    _phantom_state: ::core::marker::PhantomData<fn() -> S>,
108    __unsafe_private_named: (
109        ::core::option::Option<jacquard_common::types::string::Cid<'a>>,
110        ::core::option::Option<crate::sh_weaver::edit::DocRef<'a>>,
111        ::core::option::Option<jacquard_common::types::blob::BlobRef<'a>>,
112        ::core::option::Option<jacquard_common::types::string::AtUri<'a>>,
113    ),
114    _phantom: ::core::marker::PhantomData<&'a ()>,
115}
116
117impl<'a> Root<'a> {
118    /// Create a new builder for this type
119    pub fn new() -> RootBuilder<'a, root_state::Empty> {
120        RootBuilder::new()
121    }
122}
123
124impl<'a> RootBuilder<'a, root_state::Empty> {
125    /// Create a new builder with all fields unset
126    pub fn new() -> Self {
127        RootBuilder {
128            _phantom_state: ::core::marker::PhantomData,
129            __unsafe_private_named: (None, None, None, None),
130            _phantom: ::core::marker::PhantomData,
131        }
132    }
133}
134
135impl<'a, S> RootBuilder<'a, S>
136where
137    S: root_state::State,
138    S::Cid: root_state::IsUnset,
139{
140    /// Set the `cid` field (required)
141    pub fn cid(
142        mut self,
143        value: impl Into<jacquard_common::types::string::Cid<'a>>,
144    ) -> RootBuilder<'a, root_state::SetCid<S>> {
145        self.__unsafe_private_named.0 = ::core::option::Option::Some(value.into());
146        RootBuilder {
147            _phantom_state: ::core::marker::PhantomData,
148            __unsafe_private_named: self.__unsafe_private_named,
149            _phantom: ::core::marker::PhantomData,
150        }
151    }
152}
153
154impl<'a, S> RootBuilder<'a, S>
155where
156    S: root_state::State,
157    S::Doc: root_state::IsUnset,
158{
159    /// Set the `doc` field (required)
160    pub fn doc(
161        mut self,
162        value: impl Into<crate::sh_weaver::edit::DocRef<'a>>,
163    ) -> RootBuilder<'a, root_state::SetDoc<S>> {
164        self.__unsafe_private_named.1 = ::core::option::Option::Some(value.into());
165        RootBuilder {
166            _phantom_state: ::core::marker::PhantomData,
167            __unsafe_private_named: self.__unsafe_private_named,
168            _phantom: ::core::marker::PhantomData,
169        }
170    }
171}
172
173impl<'a, S> RootBuilder<'a, S>
174where
175    S: root_state::State,
176    S::Snapshot: root_state::IsUnset,
177{
178    /// Set the `snapshot` field (required)
179    pub fn snapshot(
180        mut self,
181        value: impl Into<jacquard_common::types::blob::BlobRef<'a>>,
182    ) -> RootBuilder<'a, root_state::SetSnapshot<S>> {
183        self.__unsafe_private_named.2 = ::core::option::Option::Some(value.into());
184        RootBuilder {
185            _phantom_state: ::core::marker::PhantomData,
186            __unsafe_private_named: self.__unsafe_private_named,
187            _phantom: ::core::marker::PhantomData,
188        }
189    }
190}
191
192impl<'a, S> RootBuilder<'a, S>
193where
194    S: root_state::State,
195    S::Uri: root_state::IsUnset,
196{
197    /// Set the `uri` field (required)
198    pub fn uri(
199        mut self,
200        value: impl Into<jacquard_common::types::string::AtUri<'a>>,
201    ) -> RootBuilder<'a, root_state::SetUri<S>> {
202        self.__unsafe_private_named.3 = ::core::option::Option::Some(value.into());
203        RootBuilder {
204            _phantom_state: ::core::marker::PhantomData,
205            __unsafe_private_named: self.__unsafe_private_named,
206            _phantom: ::core::marker::PhantomData,
207        }
208    }
209}
210
211impl<'a, S> RootBuilder<'a, S>
212where
213    S: root_state::State,
214    S::Cid: root_state::IsSet,
215    S::Uri: root_state::IsSet,
216    S::Doc: root_state::IsSet,
217    S::Snapshot: root_state::IsSet,
218{
219    /// Build the final struct
220    pub fn build(self) -> Root<'a> {
221        Root {
222            cid: self.__unsafe_private_named.0.unwrap(),
223            doc: self.__unsafe_private_named.1.unwrap(),
224            snapshot: self.__unsafe_private_named.2.unwrap(),
225            uri: self.__unsafe_private_named.3.unwrap(),
226            extra_data: Default::default(),
227        }
228    }
229    /// Build the final struct with custom extra_data
230    pub fn build_with_data(
231        self,
232        extra_data: std::collections::BTreeMap<
233            jacquard_common::smol_str::SmolStr,
234            jacquard_common::types::value::Data<'a>,
235        >,
236    ) -> Root<'a> {
237        Root {
238            cid: self.__unsafe_private_named.0.unwrap(),
239            doc: self.__unsafe_private_named.1.unwrap(),
240            snapshot: self.__unsafe_private_named.2.unwrap(),
241            uri: self.__unsafe_private_named.3.unwrap(),
242            extra_data: Some(extra_data),
243        }
244    }
245}
246
247impl<'a> Root<'a> {
248    pub fn uri(
249        uri: impl Into<jacquard_common::CowStr<'a>>,
250    ) -> Result<
251        jacquard_common::types::uri::RecordUri<'a, RootRecord>,
252        jacquard_common::types::uri::UriError,
253    > {
254        jacquard_common::types::uri::RecordUri::try_from_uri(
255            jacquard_common::types::string::AtUri::new_cow(uri.into())?,
256        )
257    }
258}
259
260/// Typed wrapper for GetRecord response with this collection's record type.
261#[derive(
262    serde::Serialize,
263    serde::Deserialize,
264    Debug,
265    Clone,
266    PartialEq,
267    Eq,
268    jacquard_derive::IntoStatic
269)]
270#[serde(rename_all = "camelCase")]
271pub struct RootGetRecordOutput<'a> {
272    #[serde(skip_serializing_if = "std::option::Option::is_none")]
273    #[serde(borrow)]
274    pub cid: std::option::Option<jacquard_common::types::string::Cid<'a>>,
275    #[serde(borrow)]
276    pub uri: jacquard_common::types::string::AtUri<'a>,
277    #[serde(borrow)]
278    pub value: Root<'a>,
279}
280
281impl From<RootGetRecordOutput<'_>> for Root<'_> {
282    fn from(output: RootGetRecordOutput<'_>) -> Self {
283        use jacquard_common::IntoStatic;
284        output.value.into_static()
285    }
286}
287
288impl jacquard_common::types::collection::Collection for Root<'_> {
289    const NSID: &'static str = "sh.weaver.edit.root";
290    type Record = RootRecord;
291}
292
293/// Marker type for deserializing records from this collection.
294#[derive(Debug, serde::Serialize, serde::Deserialize)]
295pub struct RootRecord;
296impl jacquard_common::xrpc::XrpcResp for RootRecord {
297    const NSID: &'static str = "sh.weaver.edit.root";
298    const ENCODING: &'static str = "application/json";
299    type Output<'de> = RootGetRecordOutput<'de>;
300    type Err<'de> = jacquard_common::types::collection::RecordError<'de>;
301}
302
303impl jacquard_common::types::collection::Collection for RootRecord {
304    const NSID: &'static str = "sh.weaver.edit.root";
305    type Record = RootRecord;
306}
307
308impl<'a> ::jacquard_lexicon::schema::LexiconSchema for Root<'a> {
309    fn nsid() -> &'static str {
310        "sh.weaver.edit.root"
311    }
312    fn def_name() -> &'static str {
313        "main"
314    }
315    fn lexicon_doc() -> ::jacquard_lexicon::lexicon::LexiconDoc<'static> {
316        lexicon_doc_sh_weaver_edit_root()
317    }
318    fn validate(
319        &self,
320    ) -> ::std::result::Result<(), ::jacquard_lexicon::validation::ConstraintError> {
321        Ok(())
322    }
323}
324
325fn lexicon_doc_sh_weaver_edit_root() -> ::jacquard_lexicon::lexicon::LexiconDoc<
326    'static,
327> {
328    ::jacquard_lexicon::lexicon::LexiconDoc {
329        lexicon: ::jacquard_lexicon::lexicon::Lexicon::Lexicon1,
330        id: ::jacquard_common::CowStr::new_static("sh.weaver.edit.root"),
331        revision: None,
332        description: None,
333        defs: {
334            let mut map = ::std::collections::BTreeMap::new();
335            map.insert(
336                ::jacquard_common::smol_str::SmolStr::new_static("main"),
337                ::jacquard_lexicon::lexicon::LexUserType::Record(::jacquard_lexicon::lexicon::LexRecord {
338                    description: Some(
339                        ::jacquard_common::CowStr::new_static(
340                            "The starting point for edit history on a notebook.",
341                        ),
342                    ),
343                    key: Some(::jacquard_common::CowStr::new_static("tid")),
344                    record: ::jacquard_lexicon::lexicon::LexRecordRecord::Object(::jacquard_lexicon::lexicon::LexObject {
345                        description: None,
346                        required: Some(
347                            vec![
348                                ::jacquard_common::smol_str::SmolStr::new_static("cid"),
349                                ::jacquard_common::smol_str::SmolStr::new_static("uri"),
350                                ::jacquard_common::smol_str::SmolStr::new_static("doc"),
351                                ::jacquard_common::smol_str::SmolStr::new_static("snapshot")
352                            ],
353                        ),
354                        nullable: None,
355                        properties: {
356                            #[allow(unused_mut)]
357                            let mut map = ::std::collections::BTreeMap::new();
358                            map.insert(
359                                ::jacquard_common::smol_str::SmolStr::new_static("cid"),
360                                ::jacquard_lexicon::lexicon::LexObjectProperty::String(::jacquard_lexicon::lexicon::LexString {
361                                    description: None,
362                                    format: Some(
363                                        ::jacquard_lexicon::lexicon::LexStringFormat::Cid,
364                                    ),
365                                    default: None,
366                                    min_length: None,
367                                    max_length: None,
368                                    min_graphemes: None,
369                                    max_graphemes: None,
370                                    r#enum: None,
371                                    r#const: None,
372                                    known_values: None,
373                                }),
374                            );
375                            map.insert(
376                                ::jacquard_common::smol_str::SmolStr::new_static("doc"),
377                                ::jacquard_lexicon::lexicon::LexObjectProperty::Ref(::jacquard_lexicon::lexicon::LexRef {
378                                    description: None,
379                                    r#ref: ::jacquard_common::CowStr::new_static(
380                                        "sh.weaver.edit.defs#docRef",
381                                    ),
382                                }),
383                            );
384                            map.insert(
385                                ::jacquard_common::smol_str::SmolStr::new_static(
386                                    "snapshot",
387                                ),
388                                ::jacquard_lexicon::lexicon::LexObjectProperty::Blob(::jacquard_lexicon::lexicon::LexBlob {
389                                    description: None,
390                                    accept: None,
391                                    max_size: None,
392                                }),
393                            );
394                            map.insert(
395                                ::jacquard_common::smol_str::SmolStr::new_static("uri"),
396                                ::jacquard_lexicon::lexicon::LexObjectProperty::String(::jacquard_lexicon::lexicon::LexString {
397                                    description: None,
398                                    format: Some(
399                                        ::jacquard_lexicon::lexicon::LexStringFormat::AtUri,
400                                    ),
401                                    default: None,
402                                    min_length: None,
403                                    max_length: None,
404                                    min_graphemes: None,
405                                    max_graphemes: None,
406                                    r#enum: None,
407                                    r#const: None,
408                                    known_values: None,
409                                }),
410                            );
411                            map
412                        },
413                    }),
414                }),
415            );
416            map
417        },
418    }
419}