Skip to main content

jacquard_api/com_atproto/sync/
get_latest_commit.rs

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