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