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;
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};
28/// Record linking an atproto identity with a stream signing key
29
30#[lexicon]
31#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
32#[serde(rename_all = "camelCase", rename = "place.stream.key", tag = "$type")]
33pub struct Key<'a> {
34    ///Client-declared timestamp when this key was created.
35    pub created_at: Datetime,
36    ///The name of the client that created this key.
37    #[serde(skip_serializing_if = "Option::is_none")]
38    #[serde(borrow)]
39    pub created_by: Option<CowStr<'a>>,
40    ///The did:key signing key for the stream.
41    #[serde(borrow)]
42    pub signing_key: CowStr<'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 KeyGetRecordOutput<'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: Key<'a>,
57}
58
59impl<'a> Key<'a> {
60    pub fn uri(
61        uri: impl Into<CowStr<'a>>,
62    ) -> Result<RecordUri<'a, KeyRecord>, 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 KeyRecord;
71impl XrpcResp for KeyRecord {
72    const NSID: &'static str = "place.stream.key";
73    const ENCODING: &'static str = "application/json";
74    type Output<'de> = KeyGetRecordOutput<'de>;
75    type Err<'de> = RecordError<'de>;
76}
77
78impl From<KeyGetRecordOutput<'_>> for Key<'_> {
79    fn from(output: KeyGetRecordOutput<'_>) -> Self {
80        use jacquard_common::IntoStatic;
81        output.value.into_static()
82    }
83}
84
85impl Collection for Key<'_> {
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<'a> LexiconSchema for Key<'a> {
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 SigningKey;
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 SigningKey = Unset;
150        type CreatedAt = Unset;
151    }
152    ///State transition - sets the `signing_key` field to Set
153    pub struct SetSigningKey<S: State = Empty>(PhantomData<fn() -> S>);
154    impl<S: State> sealed::Sealed for SetSigningKey<S> {}
155    impl<S: State> State for SetSigningKey<S> {
156        type SigningKey = Set<members::signing_key>;
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 SigningKey = S::SigningKey;
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 `signing_key` field
170        pub struct signing_key(());
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 KeyBuilder<'a, S: key_state::State> {
178    _state: PhantomData<fn() -> S>,
179    _fields: (Option<Datetime>, Option<CowStr<'a>>, Option<CowStr<'a>>),
180    _lifetime: PhantomData<&'a ()>,
181}
182
183impl<'a> Key<'a> {
184    /// Create a new builder for this type
185    pub fn new() -> KeyBuilder<'a, key_state::Empty> {
186        KeyBuilder::new()
187    }
188}
189
190impl<'a> KeyBuilder<'a, key_state::Empty> {
191    /// Create a new builder with all fields unset
192    pub fn new() -> Self {
193        KeyBuilder {
194            _state: PhantomData,
195            _fields: (None, None, None),
196            _lifetime: PhantomData,
197        }
198    }
199}
200
201impl<'a, S> KeyBuilder<'a, S>
202where
203    S: key_state::State,
204    S::CreatedAt: key_state::IsUnset,
205{
206    /// Set the `createdAt` field (required)
207    pub fn created_at(
208        mut self,
209        value: impl Into<Datetime>,
210    ) -> KeyBuilder<'a, key_state::SetCreatedAt<S>> {
211        self._fields.0 = Option::Some(value.into());
212        KeyBuilder {
213            _state: PhantomData,
214            _fields: self._fields,
215            _lifetime: PhantomData,
216        }
217    }
218}
219
220impl<'a, S: key_state::State> KeyBuilder<'a, S> {
221    /// Set the `createdBy` field (optional)
222    pub fn created_by(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
223        self._fields.1 = value.into();
224        self
225    }
226    /// Set the `createdBy` field to an Option value (optional)
227    pub fn maybe_created_by(mut self, value: Option<CowStr<'a>>) -> Self {
228        self._fields.1 = value;
229        self
230    }
231}
232
233impl<'a, S> KeyBuilder<'a, S>
234where
235    S: key_state::State,
236    S::SigningKey: key_state::IsUnset,
237{
238    /// Set the `signingKey` field (required)
239    pub fn signing_key(
240        mut self,
241        value: impl Into<CowStr<'a>>,
242    ) -> KeyBuilder<'a, key_state::SetSigningKey<S>> {
243        self._fields.2 = Option::Some(value.into());
244        KeyBuilder {
245            _state: PhantomData,
246            _fields: self._fields,
247            _lifetime: PhantomData,
248        }
249    }
250}
251
252impl<'a, S> KeyBuilder<'a, S>
253where
254    S: key_state::State,
255    S::SigningKey: key_state::IsSet,
256    S::CreatedAt: key_state::IsSet,
257{
258    /// Build the final struct
259    pub fn build(self) -> Key<'a> {
260        Key {
261            created_at: self._fields.0.unwrap(),
262            created_by: self._fields.1,
263            signing_key: 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    ) -> Key<'a> {
275        Key {
276            created_at: self._fields.0.unwrap(),
277            created_by: self._fields.1,
278            signing_key: self._fields.2.unwrap(),
279            extra_data: Some(extra_data),
280        }
281    }
282}
283
284fn lexicon_doc_place_stream_key() -> 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("place.stream.key"),
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                            "Record linking an atproto identity with a stream signing key",
300                        ),
301                    ),
302                    key: Some(CowStr::new_static("tid")),
303                    record: LexRecordRecord::Object(LexObject {
304                        required: Some(
305                            vec![
306                                SmolStr::new_static("signingKey"),
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                                    description: Some(
317                                        CowStr::new_static(
318                                            "Client-declared timestamp when this key was created.",
319                                        ),
320                                    ),
321                                    format: Some(LexStringFormat::Datetime),
322                                    ..Default::default()
323                                }),
324                            );
325                            map.insert(
326                                SmolStr::new_static("createdBy"),
327                                LexObjectProperty::String(LexString {
328                                    description: Some(
329                                        CowStr::new_static(
330                                            "The name of the client that created this key.",
331                                        ),
332                                    ),
333                                    ..Default::default()
334                                }),
335                            );
336                            map.insert(
337                                SmolStr::new_static("signingKey"),
338                                LexObjectProperty::String(LexString {
339                                    description: Some(
340                                        CowStr::new_static(
341                                            "The did:key signing key for the stream.",
342                                        ),
343                                    ),
344                                    min_length: Some(57usize),
345                                    max_length: Some(57usize),
346                                    ..Default::default()
347                                }),
348                            );
349                            map
350                        },
351                        ..Default::default()
352                    }),
353                    ..Default::default()
354                }),
355            );
356            map
357        },
358        ..Default::default()
359    }
360}