Skip to main content

jacquard_api/sh_weaver/notebook/
page.rs

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