Skip to main content

jacquard_api/sh_tangled/
spindle.rs

1// @generated by jacquard-lexicon. DO NOT EDIT.
2//
3// Lexicon: sh.tangled.spindle
4//
5// This file was automatically generated from Lexicon schemas.
6// Any manual changes will be overwritten on the next regeneration.
7
8pub mod member;
9
10
11#[allow(unused_imports)]
12use alloc::collections::BTreeMap;
13
14#[allow(unused_imports)]
15use core::marker::PhantomData;
16use jacquard_common::CowStr;
17
18#[allow(unused_imports)]
19use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
20use jacquard_common::types::collection::{Collection, RecordError};
21use jacquard_common::types::string::{AtUri, Cid, Datetime};
22use jacquard_common::types::uri::{RecordUri, UriError};
23use jacquard_common::xrpc::XrpcResp;
24use jacquard_derive::{IntoStatic, lexicon};
25use jacquard_lexicon::lexicon::LexiconDoc;
26use jacquard_lexicon::schema::LexiconSchema;
27
28#[allow(unused_imports)]
29use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
30use serde::{Serialize, Deserialize};
31
32#[lexicon]
33#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
34#[serde(rename_all = "camelCase", rename = "sh.tangled.spindle", tag = "$type")]
35pub struct Spindle<'a> {
36    pub created_at: Datetime,
37}
38
39/// Typed wrapper for GetRecord response with this collection's record type.
40
41#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
42#[serde(rename_all = "camelCase")]
43pub struct SpindleGetRecordOutput<'a> {
44    #[serde(skip_serializing_if = "Option::is_none")]
45    #[serde(borrow)]
46    pub cid: Option<Cid<'a>>,
47    #[serde(borrow)]
48    pub uri: AtUri<'a>,
49    #[serde(borrow)]
50    pub value: Spindle<'a>,
51}
52
53impl<'a> Spindle<'a> {
54    pub fn uri(
55        uri: impl Into<CowStr<'a>>,
56    ) -> Result<RecordUri<'a, SpindleRecord>, UriError> {
57        RecordUri::try_from_uri(AtUri::new_cow(uri.into())?)
58    }
59}
60
61/// Marker type for deserializing records from this collection.
62
63#[derive(Debug, Serialize, Deserialize)]
64pub struct SpindleRecord;
65impl XrpcResp for SpindleRecord {
66    const NSID: &'static str = "sh.tangled.spindle";
67    const ENCODING: &'static str = "application/json";
68    type Output<'de> = SpindleGetRecordOutput<'de>;
69    type Err<'de> = RecordError<'de>;
70}
71
72impl From<SpindleGetRecordOutput<'_>> for Spindle<'_> {
73    fn from(output: SpindleGetRecordOutput<'_>) -> Self {
74        use jacquard_common::IntoStatic;
75        output.value.into_static()
76    }
77}
78
79impl Collection for Spindle<'_> {
80    const NSID: &'static str = "sh.tangled.spindle";
81    type Record = SpindleRecord;
82}
83
84impl Collection for SpindleRecord {
85    const NSID: &'static str = "sh.tangled.spindle";
86    type Record = SpindleRecord;
87}
88
89impl<'a> LexiconSchema for Spindle<'a> {
90    fn nsid() -> &'static str {
91        "sh.tangled.spindle"
92    }
93    fn def_name() -> &'static str {
94        "main"
95    }
96    fn lexicon_doc() -> LexiconDoc<'static> {
97        lexicon_doc_sh_tangled_spindle()
98    }
99    fn validate(&self) -> Result<(), ConstraintError> {
100        Ok(())
101    }
102}
103
104pub mod spindle_state {
105
106    pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
107    #[allow(unused)]
108    use ::core::marker::PhantomData;
109    mod sealed {
110        pub trait Sealed {}
111    }
112    /// State trait tracking which required fields have been set
113    pub trait State: sealed::Sealed {
114        type CreatedAt;
115    }
116    /// Empty state - all required fields are unset
117    pub struct Empty(());
118    impl sealed::Sealed for Empty {}
119    impl State for Empty {
120        type CreatedAt = Unset;
121    }
122    ///State transition - sets the `created_at` field to Set
123    pub struct SetCreatedAt<S: State = Empty>(PhantomData<fn() -> S>);
124    impl<S: State> sealed::Sealed for SetCreatedAt<S> {}
125    impl<S: State> State for SetCreatedAt<S> {
126        type CreatedAt = Set<members::created_at>;
127    }
128    /// Marker types for field names
129    #[allow(non_camel_case_types)]
130    pub mod members {
131        ///Marker type for the `created_at` field
132        pub struct created_at(());
133    }
134}
135
136/// Builder for constructing an instance of this type
137pub struct SpindleBuilder<'a, S: spindle_state::State> {
138    _state: PhantomData<fn() -> S>,
139    _fields: (Option<Datetime>,),
140    _lifetime: PhantomData<&'a ()>,
141}
142
143impl<'a> Spindle<'a> {
144    /// Create a new builder for this type
145    pub fn new() -> SpindleBuilder<'a, spindle_state::Empty> {
146        SpindleBuilder::new()
147    }
148}
149
150impl<'a> SpindleBuilder<'a, spindle_state::Empty> {
151    /// Create a new builder with all fields unset
152    pub fn new() -> Self {
153        SpindleBuilder {
154            _state: PhantomData,
155            _fields: (None,),
156            _lifetime: PhantomData,
157        }
158    }
159}
160
161impl<'a, S> SpindleBuilder<'a, S>
162where
163    S: spindle_state::State,
164    S::CreatedAt: spindle_state::IsUnset,
165{
166    /// Set the `createdAt` field (required)
167    pub fn created_at(
168        mut self,
169        value: impl Into<Datetime>,
170    ) -> SpindleBuilder<'a, spindle_state::SetCreatedAt<S>> {
171        self._fields.0 = Option::Some(value.into());
172        SpindleBuilder {
173            _state: PhantomData,
174            _fields: self._fields,
175            _lifetime: PhantomData,
176        }
177    }
178}
179
180impl<'a, S> SpindleBuilder<'a, S>
181where
182    S: spindle_state::State,
183    S::CreatedAt: spindle_state::IsSet,
184{
185    /// Build the final struct
186    pub fn build(self) -> Spindle<'a> {
187        Spindle {
188            created_at: self._fields.0.unwrap(),
189            extra_data: Default::default(),
190        }
191    }
192    /// Build the final struct with custom extra_data
193    pub fn build_with_data(
194        self,
195        extra_data: BTreeMap<
196            jacquard_common::deps::smol_str::SmolStr,
197            jacquard_common::types::value::Data<'a>,
198        >,
199    ) -> Spindle<'a> {
200        Spindle {
201            created_at: self._fields.0.unwrap(),
202            extra_data: Some(extra_data),
203        }
204    }
205}
206
207fn lexicon_doc_sh_tangled_spindle() -> LexiconDoc<'static> {
208    #[allow(unused_imports)]
209    use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
210    use jacquard_lexicon::lexicon::*;
211    use alloc::collections::BTreeMap;
212    LexiconDoc {
213        lexicon: Lexicon::Lexicon1,
214        id: CowStr::new_static("sh.tangled.spindle"),
215        defs: {
216            let mut map = BTreeMap::new();
217            map.insert(
218                SmolStr::new_static("main"),
219                LexUserType::Record(LexRecord {
220                    key: Some(CowStr::new_static("any")),
221                    record: LexRecordRecord::Object(LexObject {
222                        required: Some(vec![SmolStr::new_static("createdAt")]),
223                        properties: {
224                            #[allow(unused_mut)]
225                            let mut map = BTreeMap::new();
226                            map.insert(
227                                SmolStr::new_static("createdAt"),
228                                LexObjectProperty::String(LexString {
229                                    format: Some(LexStringFormat::Datetime),
230                                    ..Default::default()
231                                }),
232                            );
233                            map
234                        },
235                        ..Default::default()
236                    }),
237                    ..Default::default()
238                }),
239            );
240            map
241        },
242        ..Default::default()
243    }
244}