jacquard_api/com_atproto/sync/
get_latest_commit.rs1#[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::{Did, Tid, Cid};
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 GetLatestCommit<S: BosStr = DefaultStr> {
23 pub did: Did<S>,
24}
25
26
27#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
28#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
29pub struct GetLatestCommitOutput<S: BosStr = DefaultStr> {
30 pub cid: Cid<S>,
31 pub rev: Tid,
32 #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
33 pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
34}
35
36
37#[derive(
38 Serialize,
39 Deserialize,
40 Debug,
41 Clone,
42 PartialEq,
43 Eq,
44 thiserror::Error,
45 miette::Diagnostic
46)]
47
48#[serde(tag = "error", content = "message")]
49pub enum GetLatestCommitError {
50 #[serde(rename = "RepoNotFound")]
51 RepoNotFound(Option<SmolStr>),
52 #[serde(rename = "RepoTakendown")]
53 RepoTakendown(Option<SmolStr>),
54 #[serde(rename = "RepoSuspended")]
55 RepoSuspended(Option<SmolStr>),
56 #[serde(rename = "RepoDeactivated")]
57 RepoDeactivated(Option<SmolStr>),
58 #[serde(untagged)]
60 Other { error: SmolStr, message: Option<SmolStr> },
61}
62
63impl core::fmt::Display for GetLatestCommitError {
64 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
65 match self {
66 Self::RepoNotFound(msg) => {
67 write!(f, "RepoNotFound")?;
68 if let Some(msg) = msg {
69 write!(f, ": {}", msg)?;
70 }
71 Ok(())
72 }
73 Self::RepoTakendown(msg) => {
74 write!(f, "RepoTakendown")?;
75 if let Some(msg) = msg {
76 write!(f, ": {}", msg)?;
77 }
78 Ok(())
79 }
80 Self::RepoSuspended(msg) => {
81 write!(f, "RepoSuspended")?;
82 if let Some(msg) = msg {
83 write!(f, ": {}", msg)?;
84 }
85 Ok(())
86 }
87 Self::RepoDeactivated(msg) => {
88 write!(f, "RepoDeactivated")?;
89 if let Some(msg) = msg {
90 write!(f, ": {}", msg)?;
91 }
92 Ok(())
93 }
94 Self::Other { error, message } => {
95 write!(f, "{}", error)?;
96 if let Some(msg) = message {
97 write!(f, ": {}", msg)?;
98 }
99 Ok(())
100 }
101 }
102 }
103}
104
105pub struct GetLatestCommitResponse;
109impl jacquard_common::xrpc::XrpcResp for GetLatestCommitResponse {
110 const NSID: &'static str = "com.atproto.sync.getLatestCommit";
111 const ENCODING: &'static str = "application/json";
112 type Output<S: BosStr> = GetLatestCommitOutput<S>;
113 type Err = GetLatestCommitError;
114}
115
116impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for GetLatestCommit<S> {
117 const NSID: &'static str = "com.atproto.sync.getLatestCommit";
118 const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
119 type Response = GetLatestCommitResponse;
120}
121
122pub struct GetLatestCommitRequest;
126impl jacquard_common::xrpc::XrpcEndpoint for GetLatestCommitRequest {
127 const PATH: &'static str = "/xrpc/com.atproto.sync.getLatestCommit";
128 const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
129 type Request<S: BosStr> = GetLatestCommit<S>;
130 type Response = GetLatestCommitResponse;
131}
132
133pub mod get_latest_commit_state {
134
135 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
136 #[allow(unused)]
137 use ::core::marker::PhantomData;
138 mod sealed {
139 pub trait Sealed {}
140 }
141 pub trait State: sealed::Sealed {
143 type Did;
144 }
145 pub struct Empty(());
147 impl sealed::Sealed for Empty {}
148 impl State for Empty {
149 type Did = Unset;
150 }
151 pub struct SetDid<St: State = Empty>(PhantomData<fn() -> St>);
153 impl<St: State> sealed::Sealed for SetDid<St> {}
154 impl<St: State> State for SetDid<St> {
155 type Did = Set<members::did>;
156 }
157 #[allow(non_camel_case_types)]
159 pub mod members {
160 pub struct did(());
162 }
163}
164
165pub struct GetLatestCommitBuilder<
167 St: get_latest_commit_state::State,
168 S: BosStr = DefaultStr,
169> {
170 _state: PhantomData<fn() -> St>,
171 _fields: (Option<Did<S>>,),
172 _type: PhantomData<fn() -> S>,
173}
174
175impl GetLatestCommit<DefaultStr> {
176 pub fn new() -> GetLatestCommitBuilder<get_latest_commit_state::Empty, DefaultStr> {
178 GetLatestCommitBuilder::new()
179 }
180}
181
182impl<S: BosStr> GetLatestCommit<S> {
183 pub fn builder() -> GetLatestCommitBuilder<get_latest_commit_state::Empty, S> {
185 GetLatestCommitBuilder::builder()
186 }
187}
188
189impl GetLatestCommitBuilder<get_latest_commit_state::Empty, DefaultStr> {
190 pub fn new() -> Self {
192 GetLatestCommitBuilder {
193 _state: PhantomData,
194 _fields: (None,),
195 _type: PhantomData,
196 }
197 }
198}
199
200impl<S: BosStr> GetLatestCommitBuilder<get_latest_commit_state::Empty, S> {
201 pub fn builder() -> Self {
203 GetLatestCommitBuilder {
204 _state: PhantomData,
205 _fields: (None,),
206 _type: PhantomData,
207 }
208 }
209}
210
211impl<St, S: BosStr> GetLatestCommitBuilder<St, S>
212where
213 St: get_latest_commit_state::State,
214 St::Did: get_latest_commit_state::IsUnset,
215{
216 pub fn did(
218 mut self,
219 value: impl Into<Did<S>>,
220 ) -> GetLatestCommitBuilder<get_latest_commit_state::SetDid<St>, S> {
221 self._fields.0 = Option::Some(value.into());
222 GetLatestCommitBuilder {
223 _state: PhantomData,
224 _fields: self._fields,
225 _type: PhantomData,
226 }
227 }
228}
229
230impl<St, S: BosStr> GetLatestCommitBuilder<St, S>
231where
232 St: get_latest_commit_state::State,
233 St::Did: get_latest_commit_state::IsSet,
234{
235 pub fn build(self) -> GetLatestCommit<S> {
237 GetLatestCommit {
238 did: self._fields.0.unwrap(),
239 }
240 }
241}