jacquard_api/app_bsky/graph/
list.rs

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