Skip to main content

jacquard_api/com_atproto/server/
get_service_auth.rs

1// @generated by jacquard-lexicon. DO NOT EDIT.
2//
3// Lexicon: com.atproto.server.getServiceAuth
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};
14use jacquard_common::deps::smol_str::SmolStr;
15use jacquard_common::types::string::Nsid;
16use jacquard_common::types::value::Data;
17use jacquard_derive::{IntoStatic, open_union};
18use serde::{Serialize, Deserialize};
19
20#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
21#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
22pub struct GetServiceAuth<S: BosStr = DefaultStr> {
23    pub aud: S,
24    #[serde(skip_serializing_if = "Option::is_none")]
25    pub exp: Option<i64>,
26    #[serde(skip_serializing_if = "Option::is_none")]
27    pub lxm: Option<Nsid<S>>,
28}
29
30
31#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
32#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
33pub struct GetServiceAuthOutput<S: BosStr = DefaultStr> {
34    pub token: S,
35    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
36    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
37}
38
39
40#[derive(
41    Serialize,
42    Deserialize,
43    Debug,
44    Clone,
45    PartialEq,
46    Eq,
47    thiserror::Error,
48    miette::Diagnostic
49)]
50
51#[serde(tag = "error", content = "message")]
52pub enum GetServiceAuthError {
53    /// Indicates that the requested expiration date is not a valid. May be in the past or may be reliant on the requested scopes.
54    #[serde(rename = "BadExpiration")]
55    BadExpiration(Option<SmolStr>),
56    /// Catch-all for unknown error codes.
57    #[serde(untagged)]
58    Other { error: SmolStr, message: Option<SmolStr> },
59}
60
61impl core::fmt::Display for GetServiceAuthError {
62    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
63        match self {
64            Self::BadExpiration(msg) => {
65                write!(f, "BadExpiration")?;
66                if let Some(msg) = msg {
67                    write!(f, ": {}", msg)?;
68                }
69                Ok(())
70            }
71            Self::Other { error, message } => {
72                write!(f, "{}", error)?;
73                if let Some(msg) = message {
74                    write!(f, ": {}", msg)?;
75                }
76                Ok(())
77            }
78        }
79    }
80}
81
82/** Response marker for the `com.atproto.server.getServiceAuth` query.
83
84Implements `jacquard_common::xrpc::XrpcResp`; successful bodies decode as `Self::Output<S>`, which is `GetServiceAuthOutput<S>` for this endpoint.*/
85pub struct GetServiceAuthResponse;
86impl jacquard_common::xrpc::XrpcResp for GetServiceAuthResponse {
87    const NSID: &'static str = "com.atproto.server.getServiceAuth";
88    const ENCODING: &'static str = "application/json";
89    type Output<S: BosStr> = GetServiceAuthOutput<S>;
90    type Err = GetServiceAuthError;
91}
92
93impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for GetServiceAuth<S> {
94    const NSID: &'static str = "com.atproto.server.getServiceAuth";
95    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
96    type Response = GetServiceAuthResponse;
97}
98
99/** Endpoint marker for the `com.atproto.server.getServiceAuth` query.
100
101Path: `/xrpc/com.atproto.server.getServiceAuth`. The request payload type is `GetServiceAuth<S>`; send that request with `jacquard::Client` or use this marker through lower-level `XrpcEndpoint` APIs.*/
102pub struct GetServiceAuthRequest;
103impl jacquard_common::xrpc::XrpcEndpoint for GetServiceAuthRequest {
104    const PATH: &'static str = "/xrpc/com.atproto.server.getServiceAuth";
105    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
106    type Request<S: BosStr> = GetServiceAuth<S>;
107    type Response = GetServiceAuthResponse;
108}
109
110pub mod get_service_auth_state {
111
112    pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
113    #[allow(unused)]
114    use ::core::marker::PhantomData;
115    mod sealed {
116        pub trait Sealed {}
117    }
118    /// State trait tracking which required fields have been set
119    pub trait State: sealed::Sealed {
120        type Aud;
121    }
122    /// Empty state - all required fields are unset
123    pub struct Empty(());
124    impl sealed::Sealed for Empty {}
125    impl State for Empty {
126        type Aud = Unset;
127    }
128    ///State transition - sets the `aud` field to Set
129    pub struct SetAud<St: State = Empty>(PhantomData<fn() -> St>);
130    impl<St: State> sealed::Sealed for SetAud<St> {}
131    impl<St: State> State for SetAud<St> {
132        type Aud = Set<members::aud>;
133    }
134    /// Marker types for field names
135    #[allow(non_camel_case_types)]
136    pub mod members {
137        ///Marker type for the `aud` field
138        pub struct aud(());
139    }
140}
141
142/// Builder for constructing an instance of this type.
143pub struct GetServiceAuthBuilder<
144    St: get_service_auth_state::State,
145    S: BosStr = DefaultStr,
146> {
147    _state: PhantomData<fn() -> St>,
148    _fields: (Option<S>, Option<i64>, Option<Nsid<S>>),
149    _type: PhantomData<fn() -> S>,
150}
151
152impl GetServiceAuth<DefaultStr> {
153    /// Create a new builder for this type, using the default string type (DefaultStr = SmolStr) if needed
154    pub fn new() -> GetServiceAuthBuilder<get_service_auth_state::Empty, DefaultStr> {
155        GetServiceAuthBuilder::new()
156    }
157}
158
159impl<S: BosStr> GetServiceAuth<S> {
160    /// Create a new builder for this type
161    pub fn builder() -> GetServiceAuthBuilder<get_service_auth_state::Empty, S> {
162        GetServiceAuthBuilder::builder()
163    }
164}
165
166impl GetServiceAuthBuilder<get_service_auth_state::Empty, DefaultStr> {
167    /// Create a new builder with all fields unset, using the default string type, if needed
168    pub fn new() -> Self {
169        GetServiceAuthBuilder {
170            _state: PhantomData,
171            _fields: (None, None, None),
172            _type: PhantomData,
173        }
174    }
175}
176
177impl<S: BosStr> GetServiceAuthBuilder<get_service_auth_state::Empty, S> {
178    /// Create a new builder with all fields unset
179    pub fn builder() -> Self {
180        GetServiceAuthBuilder {
181            _state: PhantomData,
182            _fields: (None, None, None),
183            _type: PhantomData,
184        }
185    }
186}
187
188impl<St, S: BosStr> GetServiceAuthBuilder<St, S>
189where
190    St: get_service_auth_state::State,
191    St::Aud: get_service_auth_state::IsUnset,
192{
193    /// Set the `aud` field (required)
194    pub fn aud(
195        mut self,
196        value: impl Into<S>,
197    ) -> GetServiceAuthBuilder<get_service_auth_state::SetAud<St>, S> {
198        self._fields.0 = Option::Some(value.into());
199        GetServiceAuthBuilder {
200            _state: PhantomData,
201            _fields: self._fields,
202            _type: PhantomData,
203        }
204    }
205}
206
207impl<St: get_service_auth_state::State, S: BosStr> GetServiceAuthBuilder<St, S> {
208    /// Set the `exp` field (optional)
209    pub fn exp(mut self, value: impl Into<Option<i64>>) -> Self {
210        self._fields.1 = value.into();
211        self
212    }
213    /// Set the `exp` field to an Option value (optional)
214    pub fn maybe_exp(mut self, value: Option<i64>) -> Self {
215        self._fields.1 = value;
216        self
217    }
218}
219
220impl<St: get_service_auth_state::State, S: BosStr> GetServiceAuthBuilder<St, S> {
221    /// Set the `lxm` field (optional)
222    pub fn lxm(mut self, value: impl Into<Option<Nsid<S>>>) -> Self {
223        self._fields.2 = value.into();
224        self
225    }
226    /// Set the `lxm` field to an Option value (optional)
227    pub fn maybe_lxm(mut self, value: Option<Nsid<S>>) -> Self {
228        self._fields.2 = value;
229        self
230    }
231}
232
233impl<St, S: BosStr> GetServiceAuthBuilder<St, S>
234where
235    St: get_service_auth_state::State,
236    St::Aud: get_service_auth_state::IsSet,
237{
238    /// Build the final struct.
239    pub fn build(self) -> GetServiceAuth<S> {
240        GetServiceAuth {
241            aud: self._fields.0.unwrap(),
242            exp: self._fields.1,
243            lxm: self._fields.2,
244        }
245    }
246}