jacquard_api/place_stream/
key.rs1#[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 Key<'a> {
21 pub created_at: jacquard_common::types::string::Datetime,
23 #[serde(skip_serializing_if = "std::option::Option::is_none")]
25 #[serde(borrow)]
26 pub created_by: Option<jacquard_common::CowStr<'a>>,
27 #[serde(borrow)]
29 pub signing_key: jacquard_common::CowStr<'a>,
30}
31
32pub mod key_state {
33
34 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
35 #[allow(unused)]
36 use ::core::marker::PhantomData;
37 mod sealed {
38 pub trait Sealed {}
39 }
40 pub trait State: sealed::Sealed {
42 type SigningKey;
43 type CreatedAt;
44 }
45 pub struct Empty(());
47 impl sealed::Sealed for Empty {}
48 impl State for Empty {
49 type SigningKey = Unset;
50 type CreatedAt = Unset;
51 }
52 pub struct SetSigningKey<S: State = Empty>(PhantomData<fn() -> S>);
54 impl<S: State> sealed::Sealed for SetSigningKey<S> {}
55 impl<S: State> State for SetSigningKey<S> {
56 type SigningKey = Set<members::signing_key>;
57 type CreatedAt = S::CreatedAt;
58 }
59 pub struct SetCreatedAt<S: State = Empty>(PhantomData<fn() -> S>);
61 impl<S: State> sealed::Sealed for SetCreatedAt<S> {}
62 impl<S: State> State for SetCreatedAt<S> {
63 type SigningKey = S::SigningKey;
64 type CreatedAt = Set<members::created_at>;
65 }
66 #[allow(non_camel_case_types)]
68 pub mod members {
69 pub struct signing_key(());
71 pub struct created_at(());
73 }
74}
75
76pub struct KeyBuilder<'a, S: key_state::State> {
78 _phantom_state: ::core::marker::PhantomData<fn() -> S>,
79 __unsafe_private_named: (
80 ::core::option::Option<jacquard_common::types::string::Datetime>,
81 ::core::option::Option<jacquard_common::CowStr<'a>>,
82 ::core::option::Option<jacquard_common::CowStr<'a>>,
83 ),
84 _phantom: ::core::marker::PhantomData<&'a ()>,
85}
86
87impl<'a> Key<'a> {
88 pub fn new() -> KeyBuilder<'a, key_state::Empty> {
90 KeyBuilder::new()
91 }
92}
93
94impl<'a> KeyBuilder<'a, key_state::Empty> {
95 pub fn new() -> Self {
97 KeyBuilder {
98 _phantom_state: ::core::marker::PhantomData,
99 __unsafe_private_named: (None, None, None),
100 _phantom: ::core::marker::PhantomData,
101 }
102 }
103}
104
105impl<'a, S> KeyBuilder<'a, S>
106where
107 S: key_state::State,
108 S::CreatedAt: key_state::IsUnset,
109{
110 pub fn created_at(
112 mut self,
113 value: impl Into<jacquard_common::types::string::Datetime>,
114 ) -> KeyBuilder<'a, key_state::SetCreatedAt<S>> {
115 self.__unsafe_private_named.0 = ::core::option::Option::Some(value.into());
116 KeyBuilder {
117 _phantom_state: ::core::marker::PhantomData,
118 __unsafe_private_named: self.__unsafe_private_named,
119 _phantom: ::core::marker::PhantomData,
120 }
121 }
122}
123
124impl<'a, S: key_state::State> KeyBuilder<'a, S> {
125 pub fn created_by(
127 mut self,
128 value: impl Into<Option<jacquard_common::CowStr<'a>>>,
129 ) -> Self {
130 self.__unsafe_private_named.1 = value.into();
131 self
132 }
133 pub fn maybe_created_by(
135 mut self,
136 value: Option<jacquard_common::CowStr<'a>>,
137 ) -> Self {
138 self.__unsafe_private_named.1 = value;
139 self
140 }
141}
142
143impl<'a, S> KeyBuilder<'a, S>
144where
145 S: key_state::State,
146 S::SigningKey: key_state::IsUnset,
147{
148 pub fn signing_key(
150 mut self,
151 value: impl Into<jacquard_common::CowStr<'a>>,
152 ) -> KeyBuilder<'a, key_state::SetSigningKey<S>> {
153 self.__unsafe_private_named.2 = ::core::option::Option::Some(value.into());
154 KeyBuilder {
155 _phantom_state: ::core::marker::PhantomData,
156 __unsafe_private_named: self.__unsafe_private_named,
157 _phantom: ::core::marker::PhantomData,
158 }
159 }
160}
161
162impl<'a, S> KeyBuilder<'a, S>
163where
164 S: key_state::State,
165 S::SigningKey: key_state::IsSet,
166 S::CreatedAt: key_state::IsSet,
167{
168 pub fn build(self) -> Key<'a> {
170 Key {
171 created_at: self.__unsafe_private_named.0.unwrap(),
172 created_by: self.__unsafe_private_named.1,
173 signing_key: self.__unsafe_private_named.2.unwrap(),
174 extra_data: Default::default(),
175 }
176 }
177 pub fn build_with_data(
179 self,
180 extra_data: std::collections::BTreeMap<
181 jacquard_common::smol_str::SmolStr,
182 jacquard_common::types::value::Data<'a>,
183 >,
184 ) -> Key<'a> {
185 Key {
186 created_at: self.__unsafe_private_named.0.unwrap(),
187 created_by: self.__unsafe_private_named.1,
188 signing_key: self.__unsafe_private_named.2.unwrap(),
189 extra_data: Some(extra_data),
190 }
191 }
192}
193
194impl<'a> Key<'a> {
195 pub fn uri(
196 uri: impl Into<jacquard_common::CowStr<'a>>,
197 ) -> Result<
198 jacquard_common::types::uri::RecordUri<'a, KeyRecord>,
199 jacquard_common::types::uri::UriError,
200 > {
201 jacquard_common::types::uri::RecordUri::try_from_uri(
202 jacquard_common::types::string::AtUri::new_cow(uri.into())?,
203 )
204 }
205}
206
207#[derive(
209 serde::Serialize,
210 serde::Deserialize,
211 Debug,
212 Clone,
213 PartialEq,
214 Eq,
215 jacquard_derive::IntoStatic
216)]
217#[serde(rename_all = "camelCase")]
218pub struct KeyGetRecordOutput<'a> {
219 #[serde(skip_serializing_if = "std::option::Option::is_none")]
220 #[serde(borrow)]
221 pub cid: std::option::Option<jacquard_common::types::string::Cid<'a>>,
222 #[serde(borrow)]
223 pub uri: jacquard_common::types::string::AtUri<'a>,
224 #[serde(borrow)]
225 pub value: Key<'a>,
226}
227
228impl From<KeyGetRecordOutput<'_>> for Key<'_> {
229 fn from(output: KeyGetRecordOutput<'_>) -> Self {
230 use jacquard_common::IntoStatic;
231 output.value.into_static()
232 }
233}
234
235impl jacquard_common::types::collection::Collection for Key<'_> {
236 const NSID: &'static str = "place.stream.key";
237 type Record = KeyRecord;
238}
239
240#[derive(Debug, serde::Serialize, serde::Deserialize)]
242pub struct KeyRecord;
243impl jacquard_common::xrpc::XrpcResp for KeyRecord {
244 const NSID: &'static str = "place.stream.key";
245 const ENCODING: &'static str = "application/json";
246 type Output<'de> = KeyGetRecordOutput<'de>;
247 type Err<'de> = jacquard_common::types::collection::RecordError<'de>;
248}
249
250impl jacquard_common::types::collection::Collection for KeyRecord {
251 const NSID: &'static str = "place.stream.key";
252 type Record = KeyRecord;
253}
254
255impl<'a> ::jacquard_lexicon::schema::LexiconSchema for Key<'a> {
256 fn nsid() -> &'static str {
257 "place.stream.key"
258 }
259 fn def_name() -> &'static str {
260 "main"
261 }
262 fn lexicon_doc() -> ::jacquard_lexicon::lexicon::LexiconDoc<'static> {
263 lexicon_doc_place_stream_key()
264 }
265 fn validate(
266 &self,
267 ) -> ::std::result::Result<(), ::jacquard_lexicon::validation::ConstraintError> {
268 {
269 let value = &self.signing_key;
270 #[allow(unused_comparisons)]
271 if <str>::len(value.as_ref()) > 57usize {
272 return Err(::jacquard_lexicon::validation::ConstraintError::MaxLength {
273 path: ::jacquard_lexicon::validation::ValidationPath::from_field(
274 "signing_key",
275 ),
276 max: 57usize,
277 actual: <str>::len(value.as_ref()),
278 });
279 }
280 }
281 {
282 let value = &self.signing_key;
283 #[allow(unused_comparisons)]
284 if <str>::len(value.as_ref()) < 57usize {
285 return Err(::jacquard_lexicon::validation::ConstraintError::MinLength {
286 path: ::jacquard_lexicon::validation::ValidationPath::from_field(
287 "signing_key",
288 ),
289 min: 57usize,
290 actual: <str>::len(value.as_ref()),
291 });
292 }
293 }
294 Ok(())
295 }
296}
297
298fn lexicon_doc_place_stream_key() -> ::jacquard_lexicon::lexicon::LexiconDoc<'static> {
299 ::jacquard_lexicon::lexicon::LexiconDoc {
300 lexicon: ::jacquard_lexicon::lexicon::Lexicon::Lexicon1,
301 id: ::jacquard_common::CowStr::new_static("place.stream.key"),
302 revision: None,
303 description: None,
304 defs: {
305 let mut map = ::std::collections::BTreeMap::new();
306 map.insert(
307 ::jacquard_common::smol_str::SmolStr::new_static("main"),
308 ::jacquard_lexicon::lexicon::LexUserType::Record(::jacquard_lexicon::lexicon::LexRecord {
309 description: Some(
310 ::jacquard_common::CowStr::new_static(
311 "Record linking an atproto identity with a stream signing key",
312 ),
313 ),
314 key: Some(::jacquard_common::CowStr::new_static("tid")),
315 record: ::jacquard_lexicon::lexicon::LexRecordRecord::Object(::jacquard_lexicon::lexicon::LexObject {
316 description: None,
317 required: Some(
318 vec![
319 ::jacquard_common::smol_str::SmolStr::new_static("signingKey"),
320 ::jacquard_common::smol_str::SmolStr::new_static("createdAt")
321 ],
322 ),
323 nullable: None,
324 properties: {
325 #[allow(unused_mut)]
326 let mut map = ::std::collections::BTreeMap::new();
327 map.insert(
328 ::jacquard_common::smol_str::SmolStr::new_static(
329 "createdAt",
330 ),
331 ::jacquard_lexicon::lexicon::LexObjectProperty::String(::jacquard_lexicon::lexicon::LexString {
332 description: Some(
333 ::jacquard_common::CowStr::new_static(
334 "Client-declared timestamp when this key was created.",
335 ),
336 ),
337 format: Some(
338 ::jacquard_lexicon::lexicon::LexStringFormat::Datetime,
339 ),
340 default: None,
341 min_length: None,
342 max_length: None,
343 min_graphemes: None,
344 max_graphemes: None,
345 r#enum: None,
346 r#const: None,
347 known_values: None,
348 }),
349 );
350 map.insert(
351 ::jacquard_common::smol_str::SmolStr::new_static(
352 "createdBy",
353 ),
354 ::jacquard_lexicon::lexicon::LexObjectProperty::String(::jacquard_lexicon::lexicon::LexString {
355 description: Some(
356 ::jacquard_common::CowStr::new_static(
357 "The name of the client that created this key.",
358 ),
359 ),
360 format: None,
361 default: None,
362 min_length: None,
363 max_length: None,
364 min_graphemes: None,
365 max_graphemes: None,
366 r#enum: None,
367 r#const: None,
368 known_values: None,
369 }),
370 );
371 map.insert(
372 ::jacquard_common::smol_str::SmolStr::new_static(
373 "signingKey",
374 ),
375 ::jacquard_lexicon::lexicon::LexObjectProperty::String(::jacquard_lexicon::lexicon::LexString {
376 description: Some(
377 ::jacquard_common::CowStr::new_static(
378 "The did:key signing key for the stream.",
379 ),
380 ),
381 format: None,
382 default: None,
383 min_length: Some(57usize),
384 max_length: Some(57usize),
385 min_graphemes: None,
386 max_graphemes: None,
387 r#enum: None,
388 r#const: None,
389 known_values: None,
390 }),
391 );
392 map
393 },
394 }),
395 }),
396 );
397 map
398 },
399 }
400}