Skip to main content

jacquard_api/sh_weaver/graph/
bookmark.rs

1// @generated by jacquard-lexicon. DO NOT EDIT.
2//
3// Lexicon: sh.weaver.graph.bookmark
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;
29/// Bookmark a notebook or entry for later reading.
30
31#[lexicon]
32#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
33#[serde(rename_all = "camelCase", rename = "sh.weaver.graph.bookmark", tag = "$type")]
34pub struct Bookmark<'a> {
35    pub created_at: Datetime,
36    ///Optional private note about why you saved this.
37    #[serde(skip_serializing_if = "Option::is_none")]
38    #[serde(borrow)]
39    pub note: Option<CowStr<'a>>,
40    ///The notebook or entry being bookmarked.
41    #[serde(borrow)]
42    pub subject: StrongRef<'a>,
43}
44
45/// Typed wrapper for GetRecord response with this collection's record type.
46
47#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
48#[serde(rename_all = "camelCase")]
49pub struct BookmarkGetRecordOutput<'a> {
50    #[serde(skip_serializing_if = "Option::is_none")]
51    #[serde(borrow)]
52    pub cid: Option<Cid<'a>>,
53    #[serde(borrow)]
54    pub uri: AtUri<'a>,
55    #[serde(borrow)]
56    pub value: Bookmark<'a>,
57}
58
59impl<'a> Bookmark<'a> {
60    pub fn uri(
61        uri: impl Into<CowStr<'a>>,
62    ) -> Result<RecordUri<'a, BookmarkRecord>, UriError> {
63        RecordUri::try_from_uri(AtUri::new_cow(uri.into())?)
64    }
65}
66
67/// Marker type for deserializing records from this collection.
68
69#[derive(Debug, Serialize, Deserialize)]
70pub struct BookmarkRecord;
71impl XrpcResp for BookmarkRecord {
72    const NSID: &'static str = "sh.weaver.graph.bookmark";
73    const ENCODING: &'static str = "application/json";
74    type Output<'de> = BookmarkGetRecordOutput<'de>;
75    type Err<'de> = RecordError<'de>;
76}
77
78impl From<BookmarkGetRecordOutput<'_>> for Bookmark<'_> {
79    fn from(output: BookmarkGetRecordOutput<'_>) -> Self {
80        use jacquard_common::IntoStatic;
81        output.value.into_static()
82    }
83}
84
85impl Collection for Bookmark<'_> {
86    const NSID: &'static str = "sh.weaver.graph.bookmark";
87    type Record = BookmarkRecord;
88}
89
90impl Collection for BookmarkRecord {
91    const NSID: &'static str = "sh.weaver.graph.bookmark";
92    type Record = BookmarkRecord;
93}
94
95impl<'a> LexiconSchema for Bookmark<'a> {
96    fn nsid() -> &'static str {
97        "sh.weaver.graph.bookmark"
98    }
99    fn def_name() -> &'static str {
100        "main"
101    }
102    fn lexicon_doc() -> LexiconDoc<'static> {
103        lexicon_doc_sh_weaver_graph_bookmark()
104    }
105    fn validate(&self) -> Result<(), ConstraintError> {
106        if let Some(ref value) = self.note {
107            #[allow(unused_comparisons)]
108            if <str>::len(value.as_ref()) > 3000usize {
109                return Err(ConstraintError::MaxLength {
110                    path: ValidationPath::from_field("note"),
111                    max: 3000usize,
112                    actual: <str>::len(value.as_ref()),
113                });
114            }
115        }
116        if let Some(ref value) = self.note {
117            {
118                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
119                if count > 300usize {
120                    return Err(ConstraintError::MaxGraphemes {
121                        path: ValidationPath::from_field("note"),
122                        max: 300usize,
123                        actual: count,
124                    });
125                }
126            }
127        }
128        Ok(())
129    }
130}
131
132pub mod bookmark_state {
133
134    pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
135    #[allow(unused)]
136    use ::core::marker::PhantomData;
137    mod sealed {
138        pub trait Sealed {}
139    }
140    /// State trait tracking which required fields have been set
141    pub trait State: sealed::Sealed {
142        type Subject;
143        type CreatedAt;
144    }
145    /// Empty state - all required fields are unset
146    pub struct Empty(());
147    impl sealed::Sealed for Empty {}
148    impl State for Empty {
149        type Subject = Unset;
150        type CreatedAt = Unset;
151    }
152    ///State transition - sets the `subject` field to Set
153    pub struct SetSubject<S: State = Empty>(PhantomData<fn() -> S>);
154    impl<S: State> sealed::Sealed for SetSubject<S> {}
155    impl<S: State> State for SetSubject<S> {
156        type Subject = Set<members::subject>;
157        type CreatedAt = S::CreatedAt;
158    }
159    ///State transition - sets the `created_at` field to Set
160    pub struct SetCreatedAt<S: State = Empty>(PhantomData<fn() -> S>);
161    impl<S: State> sealed::Sealed for SetCreatedAt<S> {}
162    impl<S: State> State for SetCreatedAt<S> {
163        type Subject = S::Subject;
164        type CreatedAt = Set<members::created_at>;
165    }
166    /// Marker types for field names
167    #[allow(non_camel_case_types)]
168    pub mod members {
169        ///Marker type for the `subject` field
170        pub struct subject(());
171        ///Marker type for the `created_at` field
172        pub struct created_at(());
173    }
174}
175
176/// Builder for constructing an instance of this type
177pub struct BookmarkBuilder<'a, S: bookmark_state::State> {
178    _state: PhantomData<fn() -> S>,
179    _fields: (Option<Datetime>, Option<CowStr<'a>>, Option<StrongRef<'a>>),
180    _lifetime: PhantomData<&'a ()>,
181}
182
183impl<'a> Bookmark<'a> {
184    /// Create a new builder for this type
185    pub fn new() -> BookmarkBuilder<'a, bookmark_state::Empty> {
186        BookmarkBuilder::new()
187    }
188}
189
190impl<'a> BookmarkBuilder<'a, bookmark_state::Empty> {
191    /// Create a new builder with all fields unset
192    pub fn new() -> Self {
193        BookmarkBuilder {
194            _state: PhantomData,
195            _fields: (None, None, None),
196            _lifetime: PhantomData,
197        }
198    }
199}
200
201impl<'a, S> BookmarkBuilder<'a, S>
202where
203    S: bookmark_state::State,
204    S::CreatedAt: bookmark_state::IsUnset,
205{
206    /// Set the `createdAt` field (required)
207    pub fn created_at(
208        mut self,
209        value: impl Into<Datetime>,
210    ) -> BookmarkBuilder<'a, bookmark_state::SetCreatedAt<S>> {
211        self._fields.0 = Option::Some(value.into());
212        BookmarkBuilder {
213            _state: PhantomData,
214            _fields: self._fields,
215            _lifetime: PhantomData,
216        }
217    }
218}
219
220impl<'a, S: bookmark_state::State> BookmarkBuilder<'a, S> {
221    /// Set the `note` field (optional)
222    pub fn note(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
223        self._fields.1 = value.into();
224        self
225    }
226    /// Set the `note` field to an Option value (optional)
227    pub fn maybe_note(mut self, value: Option<CowStr<'a>>) -> Self {
228        self._fields.1 = value;
229        self
230    }
231}
232
233impl<'a, S> BookmarkBuilder<'a, S>
234where
235    S: bookmark_state::State,
236    S::Subject: bookmark_state::IsUnset,
237{
238    /// Set the `subject` field (required)
239    pub fn subject(
240        mut self,
241        value: impl Into<StrongRef<'a>>,
242    ) -> BookmarkBuilder<'a, bookmark_state::SetSubject<S>> {
243        self._fields.2 = Option::Some(value.into());
244        BookmarkBuilder {
245            _state: PhantomData,
246            _fields: self._fields,
247            _lifetime: PhantomData,
248        }
249    }
250}
251
252impl<'a, S> BookmarkBuilder<'a, S>
253where
254    S: bookmark_state::State,
255    S::Subject: bookmark_state::IsSet,
256    S::CreatedAt: bookmark_state::IsSet,
257{
258    /// Build the final struct
259    pub fn build(self) -> Bookmark<'a> {
260        Bookmark {
261            created_at: self._fields.0.unwrap(),
262            note: self._fields.1,
263            subject: self._fields.2.unwrap(),
264            extra_data: Default::default(),
265        }
266    }
267    /// Build the final struct with custom extra_data
268    pub fn build_with_data(
269        self,
270        extra_data: BTreeMap<
271            jacquard_common::deps::smol_str::SmolStr,
272            jacquard_common::types::value::Data<'a>,
273        >,
274    ) -> Bookmark<'a> {
275        Bookmark {
276            created_at: self._fields.0.unwrap(),
277            note: self._fields.1,
278            subject: self._fields.2.unwrap(),
279            extra_data: Some(extra_data),
280        }
281    }
282}
283
284fn lexicon_doc_sh_weaver_graph_bookmark() -> LexiconDoc<'static> {
285    #[allow(unused_imports)]
286    use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
287    use jacquard_lexicon::lexicon::*;
288    use alloc::collections::BTreeMap;
289    LexiconDoc {
290        lexicon: Lexicon::Lexicon1,
291        id: CowStr::new_static("sh.weaver.graph.bookmark"),
292        defs: {
293            let mut map = BTreeMap::new();
294            map.insert(
295                SmolStr::new_static("main"),
296                LexUserType::Record(LexRecord {
297                    description: Some(
298                        CowStr::new_static(
299                            "Bookmark a notebook or entry for later reading.",
300                        ),
301                    ),
302                    key: Some(CowStr::new_static("tid")),
303                    record: LexRecordRecord::Object(LexObject {
304                        required: Some(
305                            vec![
306                                SmolStr::new_static("subject"),
307                                SmolStr::new_static("createdAt")
308                            ],
309                        ),
310                        properties: {
311                            #[allow(unused_mut)]
312                            let mut map = BTreeMap::new();
313                            map.insert(
314                                SmolStr::new_static("createdAt"),
315                                LexObjectProperty::String(LexString {
316                                    format: Some(LexStringFormat::Datetime),
317                                    ..Default::default()
318                                }),
319                            );
320                            map.insert(
321                                SmolStr::new_static("note"),
322                                LexObjectProperty::String(LexString {
323                                    description: Some(
324                                        CowStr::new_static(
325                                            "Optional private note about why you saved this.",
326                                        ),
327                                    ),
328                                    max_length: Some(3000usize),
329                                    max_graphemes: Some(300usize),
330                                    ..Default::default()
331                                }),
332                            );
333                            map.insert(
334                                SmolStr::new_static("subject"),
335                                LexObjectProperty::Ref(LexRef {
336                                    r#ref: CowStr::new_static("com.atproto.repo.strongRef"),
337                                    ..Default::default()
338                                }),
339                            );
340                            map
341                        },
342                        ..Default::default()
343                    }),
344                    ..Default::default()
345                }),
346            );
347            map
348        },
349        ..Default::default()
350    }
351}