Skip to main content

jacquard_api/place_stream/
key.rs

1// @generated by jacquard-lexicon. DO NOT EDIT.
2//
3// Lexicon: place.stream.key
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, BosStr, DefaultStr, FromStaticStr};
14
15#[allow(unused_imports)]
16use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
17use jacquard_common::deps::smol_str::SmolStr;
18use jacquard_common::types::collection::{Collection, RecordError};
19use jacquard_common::types::string::{AtUri, Cid, Datetime};
20use jacquard_common::types::uri::{RecordUri, UriError};
21use jacquard_common::types::value::Data;
22use jacquard_common::xrpc::XrpcResp;
23use jacquard_derive::{IntoStatic, lexicon};
24use jacquard_lexicon::lexicon::LexiconDoc;
25use jacquard_lexicon::schema::LexiconSchema;
26
27#[allow(unused_imports)]
28use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
29use serde::{Serialize, Deserialize};
30/// Record linking an atproto identity with a stream signing key
31
32#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
33#[serde(
34    rename_all = "camelCase",
35    rename = "place.stream.key",
36    tag = "$type",
37    bound(deserialize = "S: Deserialize<'de> + BosStr")
38)]
39pub struct Key<S: BosStr = DefaultStr> {
40    ///Client-declared timestamp when this key was created.
41    pub created_at: Datetime,
42    ///The name of the client that created this key.
43    #[serde(skip_serializing_if = "Option::is_none")]
44    pub created_by: Option<S>,
45    ///The did:key signing key for the stream.
46    pub signing_key: S,
47    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
48    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
49}
50
51/// Typed wrapper for GetRecord response with this collection's record type.
52
53#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
54#[serde(rename_all = "camelCase")]
55pub struct KeyGetRecordOutput<S: BosStr = DefaultStr> {
56    #[serde(skip_serializing_if = "Option::is_none")]
57    pub cid: Option<Cid<S>>,
58    pub uri: AtUri<S>,
59    pub value: Key<S>,
60}
61
62impl<S: BosStr> Key<S> {
63    pub fn uri(uri: S) -> Result<RecordUri<S, KeyRecord>, UriError> {
64        RecordUri::try_from_uri(AtUri::new(uri)?)
65    }
66}
67
68/// Marker type for deserializing records from this collection.
69
70#[derive(Debug, Serialize, Deserialize)]
71pub struct KeyRecord;
72impl XrpcResp for KeyRecord {
73    const NSID: &'static str = "place.stream.key";
74    const ENCODING: &'static str = "application/json";
75    type Output<S: BosStr> = KeyGetRecordOutput<S>;
76    type Err = RecordError;
77}
78
79impl<S: BosStr> From<KeyGetRecordOutput<S>> for Key<S> {
80    fn from(output: KeyGetRecordOutput<S>) -> Self {
81        output.value
82    }
83}
84
85impl<S: BosStr> Collection for Key<S> {
86    const NSID: &'static str = "place.stream.key";
87    type Record = KeyRecord;
88}
89
90impl Collection for KeyRecord {
91    const NSID: &'static str = "place.stream.key";
92    type Record = KeyRecord;
93}
94
95impl<S: BosStr> LexiconSchema for Key<S> {
96    fn nsid() -> &'static str {
97        "place.stream.key"
98    }
99    fn def_name() -> &'static str {
100        "main"
101    }
102    fn lexicon_doc() -> LexiconDoc<'static> {
103        lexicon_doc_place_stream_key()
104    }
105    fn validate(&self) -> Result<(), ConstraintError> {
106        {
107            let value = &self.signing_key;
108            #[allow(unused_comparisons)]
109            if <str>::len(value.as_ref()) > 57usize {
110                return Err(ConstraintError::MaxLength {
111                    path: ValidationPath::from_field("signing_key"),
112                    max: 57usize,
113                    actual: <str>::len(value.as_ref()),
114                });
115            }
116        }
117        {
118            let value = &self.signing_key;
119            #[allow(unused_comparisons)]
120            if <str>::len(value.as_ref()) < 57usize {
121                return Err(ConstraintError::MinLength {
122                    path: ValidationPath::from_field("signing_key"),
123                    min: 57usize,
124                    actual: <str>::len(value.as_ref()),
125                });
126            }
127        }
128        Ok(())
129    }
130}
131
132pub mod key_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 CreatedAt;
143        type SigningKey;
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 CreatedAt = Unset;
150        type SigningKey = Unset;
151    }
152    ///State transition - sets the `created_at` field to Set
153    pub struct SetCreatedAt<St: State = Empty>(PhantomData<fn() -> St>);
154    impl<St: State> sealed::Sealed for SetCreatedAt<St> {}
155    impl<St: State> State for SetCreatedAt<St> {
156        type CreatedAt = Set<members::created_at>;
157        type SigningKey = St::SigningKey;
158    }
159    ///State transition - sets the `signing_key` field to Set
160    pub struct SetSigningKey<St: State = Empty>(PhantomData<fn() -> St>);
161    impl<St: State> sealed::Sealed for SetSigningKey<St> {}
162    impl<St: State> State for SetSigningKey<St> {
163        type CreatedAt = St::CreatedAt;
164        type SigningKey = Set<members::signing_key>;
165    }
166    /// Marker types for field names
167    #[allow(non_camel_case_types)]
168    pub mod members {
169        ///Marker type for the `created_at` field
170        pub struct created_at(());
171        ///Marker type for the `signing_key` field
172        pub struct signing_key(());
173    }
174}
175
176/// Builder for constructing an instance of this type.
177pub struct KeyBuilder<St: key_state::State, S: BosStr = DefaultStr> {
178    _state: PhantomData<fn() -> St>,
179    _fields: (Option<Datetime>, Option<S>, Option<S>),
180    _type: PhantomData<fn() -> S>,
181}
182
183impl Key<DefaultStr> {
184    /// Create a new builder for this type, using the default string type (DefaultStr = SmolStr) if needed
185    pub fn new() -> KeyBuilder<key_state::Empty, DefaultStr> {
186        KeyBuilder::new()
187    }
188}
189
190impl<S: BosStr> Key<S> {
191    /// Create a new builder for this type
192    pub fn builder() -> KeyBuilder<key_state::Empty, S> {
193        KeyBuilder::builder()
194    }
195}
196
197impl KeyBuilder<key_state::Empty, DefaultStr> {
198    /// Create a new builder with all fields unset, using the default string type, if needed
199    pub fn new() -> Self {
200        KeyBuilder {
201            _state: PhantomData,
202            _fields: (None, None, None),
203            _type: PhantomData,
204        }
205    }
206}
207
208impl<S: BosStr> KeyBuilder<key_state::Empty, S> {
209    /// Create a new builder with all fields unset
210    pub fn builder() -> Self {
211        KeyBuilder {
212            _state: PhantomData,
213            _fields: (None, None, None),
214            _type: PhantomData,
215        }
216    }
217}
218
219impl<St, S: BosStr> KeyBuilder<St, S>
220where
221    St: key_state::State,
222    St::CreatedAt: key_state::IsUnset,
223{
224    /// Set the `createdAt` field (required)
225    pub fn created_at(
226        mut self,
227        value: impl Into<Datetime>,
228    ) -> KeyBuilder<key_state::SetCreatedAt<St>, S> {
229        self._fields.0 = Option::Some(value.into());
230        KeyBuilder {
231            _state: PhantomData,
232            _fields: self._fields,
233            _type: PhantomData,
234        }
235    }
236}
237
238impl<St: key_state::State, S: BosStr> KeyBuilder<St, S> {
239    /// Set the `createdBy` field (optional)
240    pub fn created_by(mut self, value: impl Into<Option<S>>) -> Self {
241        self._fields.1 = value.into();
242        self
243    }
244    /// Set the `createdBy` field to an Option value (optional)
245    pub fn maybe_created_by(mut self, value: Option<S>) -> Self {
246        self._fields.1 = value;
247        self
248    }
249}
250
251impl<St, S: BosStr> KeyBuilder<St, S>
252where
253    St: key_state::State,
254    St::SigningKey: key_state::IsUnset,
255{
256    /// Set the `signingKey` field (required)
257    pub fn signing_key(
258        mut self,
259        value: impl Into<S>,
260    ) -> KeyBuilder<key_state::SetSigningKey<St>, S> {
261        self._fields.2 = Option::Some(value.into());
262        KeyBuilder {
263            _state: PhantomData,
264            _fields: self._fields,
265            _type: PhantomData,
266        }
267    }
268}
269
270impl<St, S: BosStr> KeyBuilder<St, S>
271where
272    St: key_state::State,
273    St::CreatedAt: key_state::IsSet,
274    St::SigningKey: key_state::IsSet,
275{
276    /// Build the final struct.
277    pub fn build(self) -> Key<S> {
278        Key {
279            created_at: self._fields.0.unwrap(),
280            created_by: self._fields.1,
281            signing_key: self._fields.2.unwrap(),
282            extra_data: Default::default(),
283        }
284    }
285    /// Build the final struct with custom extra_data.
286    pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Key<S> {
287        Key {
288            created_at: self._fields.0.unwrap(),
289            created_by: self._fields.1,
290            signing_key: self._fields.2.unwrap(),
291            extra_data: Some(extra_data),
292        }
293    }
294}
295
296fn lexicon_doc_place_stream_key() -> LexiconDoc<'static> {
297    #[allow(unused_imports)]
298    use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
299    use jacquard_lexicon::lexicon::*;
300    use alloc::collections::BTreeMap;
301    LexiconDoc {
302        lexicon: Lexicon::Lexicon1,
303        id: CowStr::new_static("place.stream.key"),
304        defs: {
305            let mut map = BTreeMap::new();
306            map.insert(
307                SmolStr::new_static("main"),
308                LexUserType::Record(LexRecord {
309                    description: Some(
310                        CowStr::new_static(
311                            "Record linking an atproto identity with a stream signing key",
312                        ),
313                    ),
314                    key: Some(CowStr::new_static("tid")),
315                    record: LexRecordRecord::Object(LexObject {
316                        required: Some(
317                            vec![
318                                SmolStr::new_static("signingKey"),
319                                SmolStr::new_static("createdAt")
320                            ],
321                        ),
322                        properties: {
323                            #[allow(unused_mut)]
324                            let mut map = BTreeMap::new();
325                            map.insert(
326                                SmolStr::new_static("createdAt"),
327                                LexObjectProperty::String(LexString {
328                                    description: Some(
329                                        CowStr::new_static(
330                                            "Client-declared timestamp when this key was created.",
331                                        ),
332                                    ),
333                                    format: Some(LexStringFormat::Datetime),
334                                    ..Default::default()
335                                }),
336                            );
337                            map.insert(
338                                SmolStr::new_static("createdBy"),
339                                LexObjectProperty::String(LexString {
340                                    description: Some(
341                                        CowStr::new_static(
342                                            "The name of the client that created this key.",
343                                        ),
344                                    ),
345                                    ..Default::default()
346                                }),
347                            );
348                            map.insert(
349                                SmolStr::new_static("signingKey"),
350                                LexObjectProperty::String(LexString {
351                                    description: Some(
352                                        CowStr::new_static(
353                                            "The did:key signing key for the stream.",
354                                        ),
355                                    ),
356                                    min_length: Some(57usize),
357                                    max_length: Some(57usize),
358                                    ..Default::default()
359                                }),
360                            );
361                            map
362                        },
363                        ..Default::default()
364                    }),
365                    ..Default::default()
366                }),
367            );
368            map
369        },
370        ..Default::default()
371    }
372}