jacquard_api/app_bsky/graph/
verification.rs1#[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::{Did, Handle, 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#[lexicon]
31#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
32#[serde(rename_all = "camelCase", rename = "app.bsky.graph.verification", tag = "$type")]
33pub struct Verification<'a> {
34 pub created_at: Datetime,
36 #[serde(borrow)]
38 pub display_name: CowStr<'a>,
39 #[serde(borrow)]
41 pub handle: Handle<'a>,
42 #[serde(borrow)]
44 pub subject: Did<'a>,
45}
46
47#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
50#[serde(rename_all = "camelCase")]
51pub struct VerificationGetRecordOutput<'a> {
52 #[serde(skip_serializing_if = "Option::is_none")]
53 #[serde(borrow)]
54 pub cid: Option<Cid<'a>>,
55 #[serde(borrow)]
56 pub uri: AtUri<'a>,
57 #[serde(borrow)]
58 pub value: Verification<'a>,
59}
60
61impl<'a> Verification<'a> {
62 pub fn uri(
63 uri: impl Into<CowStr<'a>>,
64 ) -> Result<RecordUri<'a, VerificationRecord>, UriError> {
65 RecordUri::try_from_uri(AtUri::new_cow(uri.into())?)
66 }
67}
68
69#[derive(Debug, Serialize, Deserialize)]
72pub struct VerificationRecord;
73impl XrpcResp for VerificationRecord {
74 const NSID: &'static str = "app.bsky.graph.verification";
75 const ENCODING: &'static str = "application/json";
76 type Output<'de> = VerificationGetRecordOutput<'de>;
77 type Err<'de> = RecordError<'de>;
78}
79
80impl From<VerificationGetRecordOutput<'_>> for Verification<'_> {
81 fn from(output: VerificationGetRecordOutput<'_>) -> Self {
82 use jacquard_common::IntoStatic;
83 output.value.into_static()
84 }
85}
86
87impl Collection for Verification<'_> {
88 const NSID: &'static str = "app.bsky.graph.verification";
89 type Record = VerificationRecord;
90}
91
92impl Collection for VerificationRecord {
93 const NSID: &'static str = "app.bsky.graph.verification";
94 type Record = VerificationRecord;
95}
96
97impl<'a> LexiconSchema for Verification<'a> {
98 fn nsid() -> &'static str {
99 "app.bsky.graph.verification"
100 }
101 fn def_name() -> &'static str {
102 "main"
103 }
104 fn lexicon_doc() -> LexiconDoc<'static> {
105 lexicon_doc_app_bsky_graph_verification()
106 }
107 fn validate(&self) -> Result<(), ConstraintError> {
108 Ok(())
109 }
110}
111
112pub mod verification_state {
113
114 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
115 #[allow(unused)]
116 use ::core::marker::PhantomData;
117 mod sealed {
118 pub trait Sealed {}
119 }
120 pub trait State: sealed::Sealed {
122 type Subject;
123 type CreatedAt;
124 type DisplayName;
125 type Handle;
126 }
127 pub struct Empty(());
129 impl sealed::Sealed for Empty {}
130 impl State for Empty {
131 type Subject = Unset;
132 type CreatedAt = Unset;
133 type DisplayName = Unset;
134 type Handle = Unset;
135 }
136 pub struct SetSubject<S: State = Empty>(PhantomData<fn() -> S>);
138 impl<S: State> sealed::Sealed for SetSubject<S> {}
139 impl<S: State> State for SetSubject<S> {
140 type Subject = Set<members::subject>;
141 type CreatedAt = S::CreatedAt;
142 type DisplayName = S::DisplayName;
143 type Handle = S::Handle;
144 }
145 pub struct SetCreatedAt<S: State = Empty>(PhantomData<fn() -> S>);
147 impl<S: State> sealed::Sealed for SetCreatedAt<S> {}
148 impl<S: State> State for SetCreatedAt<S> {
149 type Subject = S::Subject;
150 type CreatedAt = Set<members::created_at>;
151 type DisplayName = S::DisplayName;
152 type Handle = S::Handle;
153 }
154 pub struct SetDisplayName<S: State = Empty>(PhantomData<fn() -> S>);
156 impl<S: State> sealed::Sealed for SetDisplayName<S> {}
157 impl<S: State> State for SetDisplayName<S> {
158 type Subject = S::Subject;
159 type CreatedAt = S::CreatedAt;
160 type DisplayName = Set<members::display_name>;
161 type Handle = S::Handle;
162 }
163 pub struct SetHandle<S: State = Empty>(PhantomData<fn() -> S>);
165 impl<S: State> sealed::Sealed for SetHandle<S> {}
166 impl<S: State> State for SetHandle<S> {
167 type Subject = S::Subject;
168 type CreatedAt = S::CreatedAt;
169 type DisplayName = S::DisplayName;
170 type Handle = Set<members::handle>;
171 }
172 #[allow(non_camel_case_types)]
174 pub mod members {
175 pub struct subject(());
177 pub struct created_at(());
179 pub struct display_name(());
181 pub struct handle(());
183 }
184}
185
186pub struct VerificationBuilder<'a, S: verification_state::State> {
188 _state: PhantomData<fn() -> S>,
189 _fields: (Option<Datetime>, Option<CowStr<'a>>, Option<Handle<'a>>, Option<Did<'a>>),
190 _lifetime: PhantomData<&'a ()>,
191}
192
193impl<'a> Verification<'a> {
194 pub fn new() -> VerificationBuilder<'a, verification_state::Empty> {
196 VerificationBuilder::new()
197 }
198}
199
200impl<'a> VerificationBuilder<'a, verification_state::Empty> {
201 pub fn new() -> Self {
203 VerificationBuilder {
204 _state: PhantomData,
205 _fields: (None, None, None, None),
206 _lifetime: PhantomData,
207 }
208 }
209}
210
211impl<'a, S> VerificationBuilder<'a, S>
212where
213 S: verification_state::State,
214 S::CreatedAt: verification_state::IsUnset,
215{
216 pub fn created_at(
218 mut self,
219 value: impl Into<Datetime>,
220 ) -> VerificationBuilder<'a, verification_state::SetCreatedAt<S>> {
221 self._fields.0 = Option::Some(value.into());
222 VerificationBuilder {
223 _state: PhantomData,
224 _fields: self._fields,
225 _lifetime: PhantomData,
226 }
227 }
228}
229
230impl<'a, S> VerificationBuilder<'a, S>
231where
232 S: verification_state::State,
233 S::DisplayName: verification_state::IsUnset,
234{
235 pub fn display_name(
237 mut self,
238 value: impl Into<CowStr<'a>>,
239 ) -> VerificationBuilder<'a, verification_state::SetDisplayName<S>> {
240 self._fields.1 = Option::Some(value.into());
241 VerificationBuilder {
242 _state: PhantomData,
243 _fields: self._fields,
244 _lifetime: PhantomData,
245 }
246 }
247}
248
249impl<'a, S> VerificationBuilder<'a, S>
250where
251 S: verification_state::State,
252 S::Handle: verification_state::IsUnset,
253{
254 pub fn handle(
256 mut self,
257 value: impl Into<Handle<'a>>,
258 ) -> VerificationBuilder<'a, verification_state::SetHandle<S>> {
259 self._fields.2 = Option::Some(value.into());
260 VerificationBuilder {
261 _state: PhantomData,
262 _fields: self._fields,
263 _lifetime: PhantomData,
264 }
265 }
266}
267
268impl<'a, S> VerificationBuilder<'a, S>
269where
270 S: verification_state::State,
271 S::Subject: verification_state::IsUnset,
272{
273 pub fn subject(
275 mut self,
276 value: impl Into<Did<'a>>,
277 ) -> VerificationBuilder<'a, verification_state::SetSubject<S>> {
278 self._fields.3 = Option::Some(value.into());
279 VerificationBuilder {
280 _state: PhantomData,
281 _fields: self._fields,
282 _lifetime: PhantomData,
283 }
284 }
285}
286
287impl<'a, S> VerificationBuilder<'a, S>
288where
289 S: verification_state::State,
290 S::Subject: verification_state::IsSet,
291 S::CreatedAt: verification_state::IsSet,
292 S::DisplayName: verification_state::IsSet,
293 S::Handle: verification_state::IsSet,
294{
295 pub fn build(self) -> Verification<'a> {
297 Verification {
298 created_at: self._fields.0.unwrap(),
299 display_name: self._fields.1.unwrap(),
300 handle: self._fields.2.unwrap(),
301 subject: self._fields.3.unwrap(),
302 extra_data: Default::default(),
303 }
304 }
305 pub fn build_with_data(
307 self,
308 extra_data: BTreeMap<
309 jacquard_common::deps::smol_str::SmolStr,
310 jacquard_common::types::value::Data<'a>,
311 >,
312 ) -> Verification<'a> {
313 Verification {
314 created_at: self._fields.0.unwrap(),
315 display_name: self._fields.1.unwrap(),
316 handle: self._fields.2.unwrap(),
317 subject: self._fields.3.unwrap(),
318 extra_data: Some(extra_data),
319 }
320 }
321}
322
323fn lexicon_doc_app_bsky_graph_verification() -> LexiconDoc<'static> {
324 #[allow(unused_imports)]
325 use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
326 use jacquard_lexicon::lexicon::*;
327 use alloc::collections::BTreeMap;
328 LexiconDoc {
329 lexicon: Lexicon::Lexicon1,
330 id: CowStr::new_static("app.bsky.graph.verification"),
331 defs: {
332 let mut map = BTreeMap::new();
333 map.insert(
334 SmolStr::new_static("main"),
335 LexUserType::Record(LexRecord {
336 description: Some(
337 CowStr::new_static(
338 "Record declaring a verification relationship between two accounts. Verifications are only considered valid by an app if issued by an account the app considers trusted.",
339 ),
340 ),
341 key: Some(CowStr::new_static("tid")),
342 record: LexRecordRecord::Object(LexObject {
343 required: Some(
344 vec![
345 SmolStr::new_static("subject"),
346 SmolStr::new_static("handle"),
347 SmolStr::new_static("displayName"),
348 SmolStr::new_static("createdAt")
349 ],
350 ),
351 properties: {
352 #[allow(unused_mut)]
353 let mut map = BTreeMap::new();
354 map.insert(
355 SmolStr::new_static("createdAt"),
356 LexObjectProperty::String(LexString {
357 description: Some(
358 CowStr::new_static(
359 "Date of when the verification was created.",
360 ),
361 ),
362 format: Some(LexStringFormat::Datetime),
363 ..Default::default()
364 }),
365 );
366 map.insert(
367 SmolStr::new_static("displayName"),
368 LexObjectProperty::String(LexString {
369 description: Some(
370 CowStr::new_static(
371 "Display name of the subject the verification applies to at the moment of verifying, which might not be the same at the time of viewing. The verification is only valid if the current displayName matches the one at the time of verifying.",
372 ),
373 ),
374 ..Default::default()
375 }),
376 );
377 map.insert(
378 SmolStr::new_static("handle"),
379 LexObjectProperty::String(LexString {
380 description: Some(
381 CowStr::new_static(
382 "Handle of the subject the verification applies to at the moment of verifying, which might not be the same at the time of viewing. The verification is only valid if the current handle matches the one at the time of verifying.",
383 ),
384 ),
385 format: Some(LexStringFormat::Handle),
386 ..Default::default()
387 }),
388 );
389 map.insert(
390 SmolStr::new_static("subject"),
391 LexObjectProperty::String(LexString {
392 description: Some(
393 CowStr::new_static(
394 "DID of the subject the verification applies to.",
395 ),
396 ),
397 format: Some(LexStringFormat::Did),
398 ..Default::default()
399 }),
400 );
401 map
402 },
403 ..Default::default()
404 }),
405 ..Default::default()
406 }),
407 );
408 map
409 },
410 ..Default::default()
411 }
412}