Skip to main content

jacquard_api/com_atproto/server/
create_app_password.rs

1// @generated by jacquard-lexicon. DO NOT EDIT.
2//
3// Lexicon: com.atproto.server.createAppPassword
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::string::Datetime;
18use jacquard_derive::{IntoStatic, lexicon, open_union};
19use jacquard_lexicon::lexicon::LexiconDoc;
20use jacquard_lexicon::schema::LexiconSchema;
21
22#[allow(unused_imports)]
23use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
24use serde::{Serialize, Deserialize};
25use crate::com_atproto::server::create_app_password;
26
27#[lexicon]
28#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
29#[serde(rename_all = "camelCase")]
30pub struct AppPassword<'a> {
31    pub created_at: Datetime,
32    #[serde(borrow)]
33    pub name: CowStr<'a>,
34    #[serde(borrow)]
35    pub password: CowStr<'a>,
36    #[serde(skip_serializing_if = "Option::is_none")]
37    pub privileged: Option<bool>,
38}
39
40
41#[lexicon]
42#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
43#[serde(rename_all = "camelCase")]
44pub struct CreateAppPassword<'a> {
45    ///A short name for the App Password, to help distinguish them.
46    #[serde(borrow)]
47    pub name: CowStr<'a>,
48    ///If an app password has 'privileged' access to possibly sensitive account state. Meant for use with trusted clients.
49    #[serde(skip_serializing_if = "Option::is_none")]
50    pub privileged: Option<bool>,
51}
52
53
54#[lexicon]
55#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
56#[serde(rename_all = "camelCase")]
57pub struct CreateAppPasswordOutput<'a> {
58    #[serde(flatten)]
59    #[serde(borrow)]
60    pub value: jacquard_common::types::value::Data<'a>,
61}
62
63
64#[open_union]
65#[derive(
66    Serialize,
67    Deserialize,
68    Debug,
69    Clone,
70    PartialEq,
71    Eq,
72    thiserror::Error,
73    miette::Diagnostic,
74    IntoStatic
75)]
76
77#[serde(tag = "error", content = "message")]
78#[serde(bound(deserialize = "'de: 'a"))]
79pub enum CreateAppPasswordError<'a> {
80    #[serde(rename = "AccountTakedown")]
81    AccountTakedown(Option<CowStr<'a>>),
82}
83
84impl core::fmt::Display for CreateAppPasswordError<'_> {
85    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
86        match self {
87            Self::AccountTakedown(msg) => {
88                write!(f, "AccountTakedown")?;
89                if let Some(msg) = msg {
90                    write!(f, ": {}", msg)?;
91                }
92                Ok(())
93            }
94            Self::Unknown(err) => write!(f, "Unknown error: {:?}", err),
95        }
96    }
97}
98
99impl<'a> LexiconSchema for AppPassword<'a> {
100    fn nsid() -> &'static str {
101        "com.atproto.server.createAppPassword"
102    }
103    fn def_name() -> &'static str {
104        "appPassword"
105    }
106    fn lexicon_doc() -> LexiconDoc<'static> {
107        lexicon_doc_com_atproto_server_createAppPassword()
108    }
109    fn validate(&self) -> Result<(), ConstraintError> {
110        Ok(())
111    }
112}
113
114/// Response type for com.atproto.server.createAppPassword
115pub struct CreateAppPasswordResponse;
116impl jacquard_common::xrpc::XrpcResp for CreateAppPasswordResponse {
117    const NSID: &'static str = "com.atproto.server.createAppPassword";
118    const ENCODING: &'static str = "application/json";
119    type Output<'de> = CreateAppPasswordOutput<'de>;
120    type Err<'de> = CreateAppPasswordError<'de>;
121}
122
123impl<'a> jacquard_common::xrpc::XrpcRequest for CreateAppPassword<'a> {
124    const NSID: &'static str = "com.atproto.server.createAppPassword";
125    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
126        "application/json",
127    );
128    type Response = CreateAppPasswordResponse;
129}
130
131/// Endpoint type for com.atproto.server.createAppPassword
132pub struct CreateAppPasswordRequest;
133impl jacquard_common::xrpc::XrpcEndpoint for CreateAppPasswordRequest {
134    const PATH: &'static str = "/xrpc/com.atproto.server.createAppPassword";
135    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
136        "application/json",
137    );
138    type Request<'de> = CreateAppPassword<'de>;
139    type Response = CreateAppPasswordResponse;
140}
141
142pub mod app_password_state {
143
144    pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
145    #[allow(unused)]
146    use ::core::marker::PhantomData;
147    mod sealed {
148        pub trait Sealed {}
149    }
150    /// State trait tracking which required fields have been set
151    pub trait State: sealed::Sealed {
152        type Name;
153        type Password;
154        type CreatedAt;
155    }
156    /// Empty state - all required fields are unset
157    pub struct Empty(());
158    impl sealed::Sealed for Empty {}
159    impl State for Empty {
160        type Name = Unset;
161        type Password = Unset;
162        type CreatedAt = Unset;
163    }
164    ///State transition - sets the `name` field to Set
165    pub struct SetName<S: State = Empty>(PhantomData<fn() -> S>);
166    impl<S: State> sealed::Sealed for SetName<S> {}
167    impl<S: State> State for SetName<S> {
168        type Name = Set<members::name>;
169        type Password = S::Password;
170        type CreatedAt = S::CreatedAt;
171    }
172    ///State transition - sets the `password` field to Set
173    pub struct SetPassword<S: State = Empty>(PhantomData<fn() -> S>);
174    impl<S: State> sealed::Sealed for SetPassword<S> {}
175    impl<S: State> State for SetPassword<S> {
176        type Name = S::Name;
177        type Password = Set<members::password>;
178        type CreatedAt = S::CreatedAt;
179    }
180    ///State transition - sets the `created_at` field to Set
181    pub struct SetCreatedAt<S: State = Empty>(PhantomData<fn() -> S>);
182    impl<S: State> sealed::Sealed for SetCreatedAt<S> {}
183    impl<S: State> State for SetCreatedAt<S> {
184        type Name = S::Name;
185        type Password = S::Password;
186        type CreatedAt = Set<members::created_at>;
187    }
188    /// Marker types for field names
189    #[allow(non_camel_case_types)]
190    pub mod members {
191        ///Marker type for the `name` field
192        pub struct name(());
193        ///Marker type for the `password` field
194        pub struct password(());
195        ///Marker type for the `created_at` field
196        pub struct created_at(());
197    }
198}
199
200/// Builder for constructing an instance of this type
201pub struct AppPasswordBuilder<'a, S: app_password_state::State> {
202    _state: PhantomData<fn() -> S>,
203    _fields: (Option<Datetime>, Option<CowStr<'a>>, Option<CowStr<'a>>, Option<bool>),
204    _lifetime: PhantomData<&'a ()>,
205}
206
207impl<'a> AppPassword<'a> {
208    /// Create a new builder for this type
209    pub fn new() -> AppPasswordBuilder<'a, app_password_state::Empty> {
210        AppPasswordBuilder::new()
211    }
212}
213
214impl<'a> AppPasswordBuilder<'a, app_password_state::Empty> {
215    /// Create a new builder with all fields unset
216    pub fn new() -> Self {
217        AppPasswordBuilder {
218            _state: PhantomData,
219            _fields: (None, None, None, None),
220            _lifetime: PhantomData,
221        }
222    }
223}
224
225impl<'a, S> AppPasswordBuilder<'a, S>
226where
227    S: app_password_state::State,
228    S::CreatedAt: app_password_state::IsUnset,
229{
230    /// Set the `createdAt` field (required)
231    pub fn created_at(
232        mut self,
233        value: impl Into<Datetime>,
234    ) -> AppPasswordBuilder<'a, app_password_state::SetCreatedAt<S>> {
235        self._fields.0 = Option::Some(value.into());
236        AppPasswordBuilder {
237            _state: PhantomData,
238            _fields: self._fields,
239            _lifetime: PhantomData,
240        }
241    }
242}
243
244impl<'a, S> AppPasswordBuilder<'a, S>
245where
246    S: app_password_state::State,
247    S::Name: app_password_state::IsUnset,
248{
249    /// Set the `name` field (required)
250    pub fn name(
251        mut self,
252        value: impl Into<CowStr<'a>>,
253    ) -> AppPasswordBuilder<'a, app_password_state::SetName<S>> {
254        self._fields.1 = Option::Some(value.into());
255        AppPasswordBuilder {
256            _state: PhantomData,
257            _fields: self._fields,
258            _lifetime: PhantomData,
259        }
260    }
261}
262
263impl<'a, S> AppPasswordBuilder<'a, S>
264where
265    S: app_password_state::State,
266    S::Password: app_password_state::IsUnset,
267{
268    /// Set the `password` field (required)
269    pub fn password(
270        mut self,
271        value: impl Into<CowStr<'a>>,
272    ) -> AppPasswordBuilder<'a, app_password_state::SetPassword<S>> {
273        self._fields.2 = Option::Some(value.into());
274        AppPasswordBuilder {
275            _state: PhantomData,
276            _fields: self._fields,
277            _lifetime: PhantomData,
278        }
279    }
280}
281
282impl<'a, S: app_password_state::State> AppPasswordBuilder<'a, S> {
283    /// Set the `privileged` field (optional)
284    pub fn privileged(mut self, value: impl Into<Option<bool>>) -> Self {
285        self._fields.3 = value.into();
286        self
287    }
288    /// Set the `privileged` field to an Option value (optional)
289    pub fn maybe_privileged(mut self, value: Option<bool>) -> Self {
290        self._fields.3 = value;
291        self
292    }
293}
294
295impl<'a, S> AppPasswordBuilder<'a, S>
296where
297    S: app_password_state::State,
298    S::Name: app_password_state::IsSet,
299    S::Password: app_password_state::IsSet,
300    S::CreatedAt: app_password_state::IsSet,
301{
302    /// Build the final struct
303    pub fn build(self) -> AppPassword<'a> {
304        AppPassword {
305            created_at: self._fields.0.unwrap(),
306            name: self._fields.1.unwrap(),
307            password: self._fields.2.unwrap(),
308            privileged: self._fields.3,
309            extra_data: Default::default(),
310        }
311    }
312    /// Build the final struct with custom extra_data
313    pub fn build_with_data(
314        self,
315        extra_data: BTreeMap<
316            jacquard_common::deps::smol_str::SmolStr,
317            jacquard_common::types::value::Data<'a>,
318        >,
319    ) -> AppPassword<'a> {
320        AppPassword {
321            created_at: self._fields.0.unwrap(),
322            name: self._fields.1.unwrap(),
323            password: self._fields.2.unwrap(),
324            privileged: self._fields.3,
325            extra_data: Some(extra_data),
326        }
327    }
328}
329
330fn lexicon_doc_com_atproto_server_createAppPassword() -> LexiconDoc<'static> {
331    #[allow(unused_imports)]
332    use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
333    use jacquard_lexicon::lexicon::*;
334    use alloc::collections::BTreeMap;
335    LexiconDoc {
336        lexicon: Lexicon::Lexicon1,
337        id: CowStr::new_static("com.atproto.server.createAppPassword"),
338        defs: {
339            let mut map = BTreeMap::new();
340            map.insert(
341                SmolStr::new_static("appPassword"),
342                LexUserType::Object(LexObject {
343                    required: Some(
344                        vec![
345                            SmolStr::new_static("name"), SmolStr::new_static("password"),
346                            SmolStr::new_static("createdAt")
347                        ],
348                    ),
349                    properties: {
350                        #[allow(unused_mut)]
351                        let mut map = BTreeMap::new();
352                        map.insert(
353                            SmolStr::new_static("createdAt"),
354                            LexObjectProperty::String(LexString {
355                                format: Some(LexStringFormat::Datetime),
356                                ..Default::default()
357                            }),
358                        );
359                        map.insert(
360                            SmolStr::new_static("name"),
361                            LexObjectProperty::String(LexString { ..Default::default() }),
362                        );
363                        map.insert(
364                            SmolStr::new_static("password"),
365                            LexObjectProperty::String(LexString { ..Default::default() }),
366                        );
367                        map.insert(
368                            SmolStr::new_static("privileged"),
369                            LexObjectProperty::Boolean(LexBoolean {
370                                ..Default::default()
371                            }),
372                        );
373                        map
374                    },
375                    ..Default::default()
376                }),
377            );
378            map.insert(
379                SmolStr::new_static("main"),
380                LexUserType::XrpcProcedure(LexXrpcProcedure {
381                    input: Some(LexXrpcBody {
382                        encoding: CowStr::new_static("application/json"),
383                        schema: Some(
384                            LexXrpcBodySchema::Object(LexObject {
385                                required: Some(vec![SmolStr::new_static("name")]),
386                                properties: {
387                                    #[allow(unused_mut)]
388                                    let mut map = BTreeMap::new();
389                                    map.insert(
390                                        SmolStr::new_static("name"),
391                                        LexObjectProperty::String(LexString {
392                                            description: Some(
393                                                CowStr::new_static(
394                                                    "A short name for the App Password, to help distinguish them.",
395                                                ),
396                                            ),
397                                            ..Default::default()
398                                        }),
399                                    );
400                                    map.insert(
401                                        SmolStr::new_static("privileged"),
402                                        LexObjectProperty::Boolean(LexBoolean {
403                                            ..Default::default()
404                                        }),
405                                    );
406                                    map
407                                },
408                                ..Default::default()
409                            }),
410                        ),
411                        ..Default::default()
412                    }),
413                    ..Default::default()
414                }),
415            );
416            map
417        },
418        ..Default::default()
419    }
420}