Skip to main content

jacquard_api/sh_tangled/
public_key.rs

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