jacquard_api/pub_leaflet/
document.rs

1// @generated by jacquard-lexicon. DO NOT EDIT.
2//
3// Lexicon: pub.leaflet.document
4//
5// This file was automatically generated from Lexicon schemas.
6// Any manual changes will be overwritten on the next regeneration.
7
8/// Record containing a document
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 Document<'a> {
21    #[serde(borrow)]
22    pub author: jacquard_common::types::ident::AtIdentifier<'a>,
23    #[serde(skip_serializing_if = "std::option::Option::is_none")]
24    #[serde(borrow)]
25    pub description: Option<jacquard_common::CowStr<'a>>,
26    #[serde(borrow)]
27    pub pages: Vec<DocumentPagesItem<'a>>,
28    #[serde(skip_serializing_if = "std::option::Option::is_none")]
29    #[serde(borrow)]
30    pub post_ref: Option<crate::com_atproto::repo::strong_ref::StrongRef<'a>>,
31    #[serde(borrow)]
32    pub publication: jacquard_common::types::string::AtUri<'a>,
33    #[serde(skip_serializing_if = "std::option::Option::is_none")]
34    pub published_at: Option<jacquard_common::types::string::Datetime>,
35    #[serde(borrow)]
36    pub title: jacquard_common::CowStr<'a>,
37}
38
39pub mod document_state {
40
41    pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
42    #[allow(unused)]
43    use ::core::marker::PhantomData;
44    mod sealed {
45        pub trait Sealed {}
46    }
47    /// State trait tracking which required fields have been set
48    pub trait State: sealed::Sealed {
49        type Pages;
50        type Author;
51        type Title;
52        type Publication;
53    }
54    /// Empty state - all required fields are unset
55    pub struct Empty(());
56    impl sealed::Sealed for Empty {}
57    impl State for Empty {
58        type Pages = Unset;
59        type Author = Unset;
60        type Title = Unset;
61        type Publication = Unset;
62    }
63    ///State transition - sets the `pages` field to Set
64    pub struct SetPages<S: State = Empty>(PhantomData<fn() -> S>);
65    impl<S: State> sealed::Sealed for SetPages<S> {}
66    impl<S: State> State for SetPages<S> {
67        type Pages = Set<members::pages>;
68        type Author = S::Author;
69        type Title = S::Title;
70        type Publication = S::Publication;
71    }
72    ///State transition - sets the `author` field to Set
73    pub struct SetAuthor<S: State = Empty>(PhantomData<fn() -> S>);
74    impl<S: State> sealed::Sealed for SetAuthor<S> {}
75    impl<S: State> State for SetAuthor<S> {
76        type Pages = S::Pages;
77        type Author = Set<members::author>;
78        type Title = S::Title;
79        type Publication = S::Publication;
80    }
81    ///State transition - sets the `title` field to Set
82    pub struct SetTitle<S: State = Empty>(PhantomData<fn() -> S>);
83    impl<S: State> sealed::Sealed for SetTitle<S> {}
84    impl<S: State> State for SetTitle<S> {
85        type Pages = S::Pages;
86        type Author = S::Author;
87        type Title = Set<members::title>;
88        type Publication = S::Publication;
89    }
90    ///State transition - sets the `publication` field to Set
91    pub struct SetPublication<S: State = Empty>(PhantomData<fn() -> S>);
92    impl<S: State> sealed::Sealed for SetPublication<S> {}
93    impl<S: State> State for SetPublication<S> {
94        type Pages = S::Pages;
95        type Author = S::Author;
96        type Title = S::Title;
97        type Publication = Set<members::publication>;
98    }
99    /// Marker types for field names
100    #[allow(non_camel_case_types)]
101    pub mod members {
102        ///Marker type for the `pages` field
103        pub struct pages(());
104        ///Marker type for the `author` field
105        pub struct author(());
106        ///Marker type for the `title` field
107        pub struct title(());
108        ///Marker type for the `publication` field
109        pub struct publication(());
110    }
111}
112
113/// Builder for constructing an instance of this type
114pub struct DocumentBuilder<'a, S: document_state::State> {
115    _phantom_state: ::core::marker::PhantomData<fn() -> S>,
116    __unsafe_private_named: (
117        ::core::option::Option<jacquard_common::types::ident::AtIdentifier<'a>>,
118        ::core::option::Option<jacquard_common::CowStr<'a>>,
119        ::core::option::Option<Vec<DocumentPagesItem<'a>>>,
120        ::core::option::Option<crate::com_atproto::repo::strong_ref::StrongRef<'a>>,
121        ::core::option::Option<jacquard_common::types::string::AtUri<'a>>,
122        ::core::option::Option<jacquard_common::types::string::Datetime>,
123        ::core::option::Option<jacquard_common::CowStr<'a>>,
124    ),
125    _phantom: ::core::marker::PhantomData<&'a ()>,
126}
127
128impl<'a> Document<'a> {
129    /// Create a new builder for this type
130    pub fn new() -> DocumentBuilder<'a, document_state::Empty> {
131        DocumentBuilder::new()
132    }
133}
134
135impl<'a> DocumentBuilder<'a, document_state::Empty> {
136    /// Create a new builder with all fields unset
137    pub fn new() -> Self {
138        DocumentBuilder {
139            _phantom_state: ::core::marker::PhantomData,
140            __unsafe_private_named: (None, None, None, None, None, None, None),
141            _phantom: ::core::marker::PhantomData,
142        }
143    }
144}
145
146impl<'a, S> DocumentBuilder<'a, S>
147where
148    S: document_state::State,
149    S::Author: document_state::IsUnset,
150{
151    /// Set the `author` field (required)
152    pub fn author(
153        mut self,
154        value: impl Into<jacquard_common::types::ident::AtIdentifier<'a>>,
155    ) -> DocumentBuilder<'a, document_state::SetAuthor<S>> {
156        self.__unsafe_private_named.0 = ::core::option::Option::Some(value.into());
157        DocumentBuilder {
158            _phantom_state: ::core::marker::PhantomData,
159            __unsafe_private_named: self.__unsafe_private_named,
160            _phantom: ::core::marker::PhantomData,
161        }
162    }
163}
164
165impl<'a, S: document_state::State> DocumentBuilder<'a, S> {
166    /// Set the `description` field (optional)
167    pub fn description(
168        mut self,
169        value: impl Into<Option<jacquard_common::CowStr<'a>>>,
170    ) -> Self {
171        self.__unsafe_private_named.1 = value.into();
172        self
173    }
174    /// Set the `description` field to an Option value (optional)
175    pub fn maybe_description(
176        mut self,
177        value: Option<jacquard_common::CowStr<'a>>,
178    ) -> Self {
179        self.__unsafe_private_named.1 = value;
180        self
181    }
182}
183
184impl<'a, S> DocumentBuilder<'a, S>
185where
186    S: document_state::State,
187    S::Pages: document_state::IsUnset,
188{
189    /// Set the `pages` field (required)
190    pub fn pages(
191        mut self,
192        value: impl Into<Vec<DocumentPagesItem<'a>>>,
193    ) -> DocumentBuilder<'a, document_state::SetPages<S>> {
194        self.__unsafe_private_named.2 = ::core::option::Option::Some(value.into());
195        DocumentBuilder {
196            _phantom_state: ::core::marker::PhantomData,
197            __unsafe_private_named: self.__unsafe_private_named,
198            _phantom: ::core::marker::PhantomData,
199        }
200    }
201}
202
203impl<'a, S: document_state::State> DocumentBuilder<'a, S> {
204    /// Set the `postRef` field (optional)
205    pub fn post_ref(
206        mut self,
207        value: impl Into<Option<crate::com_atproto::repo::strong_ref::StrongRef<'a>>>,
208    ) -> Self {
209        self.__unsafe_private_named.3 = value.into();
210        self
211    }
212    /// Set the `postRef` field to an Option value (optional)
213    pub fn maybe_post_ref(
214        mut self,
215        value: Option<crate::com_atproto::repo::strong_ref::StrongRef<'a>>,
216    ) -> Self {
217        self.__unsafe_private_named.3 = value;
218        self
219    }
220}
221
222impl<'a, S> DocumentBuilder<'a, S>
223where
224    S: document_state::State,
225    S::Publication: document_state::IsUnset,
226{
227    /// Set the `publication` field (required)
228    pub fn publication(
229        mut self,
230        value: impl Into<jacquard_common::types::string::AtUri<'a>>,
231    ) -> DocumentBuilder<'a, document_state::SetPublication<S>> {
232        self.__unsafe_private_named.4 = ::core::option::Option::Some(value.into());
233        DocumentBuilder {
234            _phantom_state: ::core::marker::PhantomData,
235            __unsafe_private_named: self.__unsafe_private_named,
236            _phantom: ::core::marker::PhantomData,
237        }
238    }
239}
240
241impl<'a, S: document_state::State> DocumentBuilder<'a, S> {
242    /// Set the `publishedAt` field (optional)
243    pub fn published_at(
244        mut self,
245        value: impl Into<Option<jacquard_common::types::string::Datetime>>,
246    ) -> Self {
247        self.__unsafe_private_named.5 = value.into();
248        self
249    }
250    /// Set the `publishedAt` field to an Option value (optional)
251    pub fn maybe_published_at(
252        mut self,
253        value: Option<jacquard_common::types::string::Datetime>,
254    ) -> Self {
255        self.__unsafe_private_named.5 = value;
256        self
257    }
258}
259
260impl<'a, S> DocumentBuilder<'a, S>
261where
262    S: document_state::State,
263    S::Title: document_state::IsUnset,
264{
265    /// Set the `title` field (required)
266    pub fn title(
267        mut self,
268        value: impl Into<jacquard_common::CowStr<'a>>,
269    ) -> DocumentBuilder<'a, document_state::SetTitle<S>> {
270        self.__unsafe_private_named.6 = ::core::option::Option::Some(value.into());
271        DocumentBuilder {
272            _phantom_state: ::core::marker::PhantomData,
273            __unsafe_private_named: self.__unsafe_private_named,
274            _phantom: ::core::marker::PhantomData,
275        }
276    }
277}
278
279impl<'a, S> DocumentBuilder<'a, S>
280where
281    S: document_state::State,
282    S::Pages: document_state::IsSet,
283    S::Author: document_state::IsSet,
284    S::Title: document_state::IsSet,
285    S::Publication: document_state::IsSet,
286{
287    /// Build the final struct
288    pub fn build(self) -> Document<'a> {
289        Document {
290            author: self.__unsafe_private_named.0.unwrap(),
291            description: self.__unsafe_private_named.1,
292            pages: self.__unsafe_private_named.2.unwrap(),
293            post_ref: self.__unsafe_private_named.3,
294            publication: self.__unsafe_private_named.4.unwrap(),
295            published_at: self.__unsafe_private_named.5,
296            title: self.__unsafe_private_named.6.unwrap(),
297            extra_data: Default::default(),
298        }
299    }
300    /// Build the final struct with custom extra_data
301    pub fn build_with_data(
302        self,
303        extra_data: std::collections::BTreeMap<
304            jacquard_common::smol_str::SmolStr,
305            jacquard_common::types::value::Data<'a>,
306        >,
307    ) -> Document<'a> {
308        Document {
309            author: self.__unsafe_private_named.0.unwrap(),
310            description: self.__unsafe_private_named.1,
311            pages: self.__unsafe_private_named.2.unwrap(),
312            post_ref: self.__unsafe_private_named.3,
313            publication: self.__unsafe_private_named.4.unwrap(),
314            published_at: self.__unsafe_private_named.5,
315            title: self.__unsafe_private_named.6.unwrap(),
316            extra_data: Some(extra_data),
317        }
318    }
319}
320
321impl<'a> Document<'a> {
322    pub fn uri(
323        uri: impl Into<jacquard_common::CowStr<'a>>,
324    ) -> Result<
325        jacquard_common::types::uri::RecordUri<'a, DocumentRecord>,
326        jacquard_common::types::uri::UriError,
327    > {
328        jacquard_common::types::uri::RecordUri::try_from_uri(
329            jacquard_common::types::string::AtUri::new_cow(uri.into())?,
330        )
331    }
332}
333
334#[jacquard_derive::open_union]
335#[derive(
336    serde::Serialize,
337    serde::Deserialize,
338    Debug,
339    Clone,
340    PartialEq,
341    Eq,
342    jacquard_derive::IntoStatic
343)]
344#[serde(tag = "$type")]
345#[serde(bound(deserialize = "'de: 'a"))]
346pub enum DocumentPagesItem<'a> {
347    #[serde(rename = "pub.leaflet.pages.linearDocument")]
348    LinearDocument(Box<crate::pub_leaflet::pages::linear_document::LinearDocument<'a>>),
349    #[serde(rename = "pub.leaflet.pages.canvas")]
350    Canvas(Box<crate::pub_leaflet::pages::canvas::Canvas<'a>>),
351}
352
353/// Typed wrapper for GetRecord response with this collection's record type.
354#[derive(
355    serde::Serialize,
356    serde::Deserialize,
357    Debug,
358    Clone,
359    PartialEq,
360    Eq,
361    jacquard_derive::IntoStatic
362)]
363#[serde(rename_all = "camelCase")]
364pub struct DocumentGetRecordOutput<'a> {
365    #[serde(skip_serializing_if = "std::option::Option::is_none")]
366    #[serde(borrow)]
367    pub cid: std::option::Option<jacquard_common::types::string::Cid<'a>>,
368    #[serde(borrow)]
369    pub uri: jacquard_common::types::string::AtUri<'a>,
370    #[serde(borrow)]
371    pub value: Document<'a>,
372}
373
374impl From<DocumentGetRecordOutput<'_>> for Document<'_> {
375    fn from(output: DocumentGetRecordOutput<'_>) -> Self {
376        use jacquard_common::IntoStatic;
377        output.value.into_static()
378    }
379}
380
381impl jacquard_common::types::collection::Collection for Document<'_> {
382    const NSID: &'static str = "pub.leaflet.document";
383    type Record = DocumentRecord;
384}
385
386/// Marker type for deserializing records from this collection.
387#[derive(Debug, serde::Serialize, serde::Deserialize)]
388pub struct DocumentRecord;
389impl jacquard_common::xrpc::XrpcResp for DocumentRecord {
390    const NSID: &'static str = "pub.leaflet.document";
391    const ENCODING: &'static str = "application/json";
392    type Output<'de> = DocumentGetRecordOutput<'de>;
393    type Err<'de> = jacquard_common::types::collection::RecordError<'de>;
394}
395
396impl jacquard_common::types::collection::Collection for DocumentRecord {
397    const NSID: &'static str = "pub.leaflet.document";
398    type Record = DocumentRecord;
399}
400
401impl<'a> ::jacquard_lexicon::schema::LexiconSchema for Document<'a> {
402    fn nsid() -> &'static str {
403        "pub.leaflet.document"
404    }
405    fn def_name() -> &'static str {
406        "main"
407    }
408    fn lexicon_doc() -> ::jacquard_lexicon::lexicon::LexiconDoc<'static> {
409        lexicon_doc_pub_leaflet_document()
410    }
411    fn validate(
412        &self,
413    ) -> ::std::result::Result<(), ::jacquard_lexicon::validation::ConstraintError> {
414        if let Some(ref value) = self.description {
415            #[allow(unused_comparisons)]
416            if <str>::len(value.as_ref()) > 3000usize {
417                return Err(::jacquard_lexicon::validation::ConstraintError::MaxLength {
418                    path: ::jacquard_lexicon::validation::ValidationPath::from_field(
419                        "description",
420                    ),
421                    max: 3000usize,
422                    actual: <str>::len(value.as_ref()),
423                });
424            }
425        }
426        if let Some(ref value) = self.description {
427            {
428                let count = ::unicode_segmentation::UnicodeSegmentation::graphemes(
429                        value.as_ref(),
430                        true,
431                    )
432                    .count();
433                if count > 300usize {
434                    return Err(::jacquard_lexicon::validation::ConstraintError::MaxGraphemes {
435                        path: ::jacquard_lexicon::validation::ValidationPath::from_field(
436                            "description",
437                        ),
438                        max: 300usize,
439                        actual: count,
440                    });
441                }
442            }
443        }
444        {
445            let value = &self.title;
446            #[allow(unused_comparisons)]
447            if <str>::len(value.as_ref()) > 1280usize {
448                return Err(::jacquard_lexicon::validation::ConstraintError::MaxLength {
449                    path: ::jacquard_lexicon::validation::ValidationPath::from_field(
450                        "title",
451                    ),
452                    max: 1280usize,
453                    actual: <str>::len(value.as_ref()),
454                });
455            }
456        }
457        {
458            let value = &self.title;
459            {
460                let count = ::unicode_segmentation::UnicodeSegmentation::graphemes(
461                        value.as_ref(),
462                        true,
463                    )
464                    .count();
465                if count > 128usize {
466                    return Err(::jacquard_lexicon::validation::ConstraintError::MaxGraphemes {
467                        path: ::jacquard_lexicon::validation::ValidationPath::from_field(
468                            "title",
469                        ),
470                        max: 128usize,
471                        actual: count,
472                    });
473                }
474            }
475        }
476        Ok(())
477    }
478}
479
480fn lexicon_doc_pub_leaflet_document() -> ::jacquard_lexicon::lexicon::LexiconDoc<
481    'static,
482> {
483    ::jacquard_lexicon::lexicon::LexiconDoc {
484        lexicon: ::jacquard_lexicon::lexicon::Lexicon::Lexicon1,
485        id: ::jacquard_common::CowStr::new_static("pub.leaflet.document"),
486        revision: None,
487        description: None,
488        defs: {
489            let mut map = ::std::collections::BTreeMap::new();
490            map.insert(
491                ::jacquard_common::smol_str::SmolStr::new_static("main"),
492                ::jacquard_lexicon::lexicon::LexUserType::Record(::jacquard_lexicon::lexicon::LexRecord {
493                    description: Some(
494                        ::jacquard_common::CowStr::new_static(
495                            "Record containing a document",
496                        ),
497                    ),
498                    key: Some(::jacquard_common::CowStr::new_static("tid")),
499                    record: ::jacquard_lexicon::lexicon::LexRecordRecord::Object(::jacquard_lexicon::lexicon::LexObject {
500                        description: None,
501                        required: Some(
502                            vec![
503                                ::jacquard_common::smol_str::SmolStr::new_static("pages"),
504                                ::jacquard_common::smol_str::SmolStr::new_static("author"),
505                                ::jacquard_common::smol_str::SmolStr::new_static("title"),
506                                ::jacquard_common::smol_str::SmolStr::new_static("publication")
507                            ],
508                        ),
509                        nullable: None,
510                        properties: {
511                            #[allow(unused_mut)]
512                            let mut map = ::std::collections::BTreeMap::new();
513                            map.insert(
514                                ::jacquard_common::smol_str::SmolStr::new_static("author"),
515                                ::jacquard_lexicon::lexicon::LexObjectProperty::String(::jacquard_lexicon::lexicon::LexString {
516                                    description: None,
517                                    format: Some(
518                                        ::jacquard_lexicon::lexicon::LexStringFormat::AtIdentifier,
519                                    ),
520                                    default: None,
521                                    min_length: None,
522                                    max_length: None,
523                                    min_graphemes: None,
524                                    max_graphemes: None,
525                                    r#enum: None,
526                                    r#const: None,
527                                    known_values: None,
528                                }),
529                            );
530                            map.insert(
531                                ::jacquard_common::smol_str::SmolStr::new_static(
532                                    "description",
533                                ),
534                                ::jacquard_lexicon::lexicon::LexObjectProperty::String(::jacquard_lexicon::lexicon::LexString {
535                                    description: None,
536                                    format: None,
537                                    default: None,
538                                    min_length: None,
539                                    max_length: Some(3000usize),
540                                    min_graphemes: None,
541                                    max_graphemes: Some(300usize),
542                                    r#enum: None,
543                                    r#const: None,
544                                    known_values: None,
545                                }),
546                            );
547                            map.insert(
548                                ::jacquard_common::smol_str::SmolStr::new_static("pages"),
549                                ::jacquard_lexicon::lexicon::LexObjectProperty::Array(::jacquard_lexicon::lexicon::LexArray {
550                                    description: None,
551                                    items: ::jacquard_lexicon::lexicon::LexArrayItem::Union(::jacquard_lexicon::lexicon::LexRefUnion {
552                                        description: None,
553                                        refs: vec![
554                                            ::jacquard_common::CowStr::new_static("pub.leaflet.pages.linearDocument"),
555                                            ::jacquard_common::CowStr::new_static("pub.leaflet.pages.canvas")
556                                        ],
557                                        closed: None,
558                                    }),
559                                    min_length: None,
560                                    max_length: None,
561                                }),
562                            );
563                            map.insert(
564                                ::jacquard_common::smol_str::SmolStr::new_static("postRef"),
565                                ::jacquard_lexicon::lexicon::LexObjectProperty::Ref(::jacquard_lexicon::lexicon::LexRef {
566                                    description: None,
567                                    r#ref: ::jacquard_common::CowStr::new_static(
568                                        "com.atproto.repo.strongRef",
569                                    ),
570                                }),
571                            );
572                            map.insert(
573                                ::jacquard_common::smol_str::SmolStr::new_static(
574                                    "publication",
575                                ),
576                                ::jacquard_lexicon::lexicon::LexObjectProperty::String(::jacquard_lexicon::lexicon::LexString {
577                                    description: None,
578                                    format: Some(
579                                        ::jacquard_lexicon::lexicon::LexStringFormat::AtUri,
580                                    ),
581                                    default: None,
582                                    min_length: None,
583                                    max_length: None,
584                                    min_graphemes: None,
585                                    max_graphemes: None,
586                                    r#enum: None,
587                                    r#const: None,
588                                    known_values: None,
589                                }),
590                            );
591                            map.insert(
592                                ::jacquard_common::smol_str::SmolStr::new_static(
593                                    "publishedAt",
594                                ),
595                                ::jacquard_lexicon::lexicon::LexObjectProperty::String(::jacquard_lexicon::lexicon::LexString {
596                                    description: None,
597                                    format: Some(
598                                        ::jacquard_lexicon::lexicon::LexStringFormat::Datetime,
599                                    ),
600                                    default: None,
601                                    min_length: None,
602                                    max_length: None,
603                                    min_graphemes: None,
604                                    max_graphemes: None,
605                                    r#enum: None,
606                                    r#const: None,
607                                    known_values: None,
608                                }),
609                            );
610                            map.insert(
611                                ::jacquard_common::smol_str::SmolStr::new_static("title"),
612                                ::jacquard_lexicon::lexicon::LexObjectProperty::String(::jacquard_lexicon::lexicon::LexString {
613                                    description: None,
614                                    format: None,
615                                    default: None,
616                                    min_length: None,
617                                    max_length: Some(1280usize),
618                                    min_graphemes: None,
619                                    max_graphemes: Some(128usize),
620                                    r#enum: None,
621                                    r#const: None,
622                                    known_values: None,
623                                }),
624                            );
625                            map
626                        },
627                    }),
628                }),
629            );
630            map
631        },
632    }
633}