jacquard_api/com_atproto/sync/
get_repo.rs1#[allow(unused_imports)]
9use core::marker::PhantomData;
10use jacquard_common::CowStr;
11use jacquard_common::deps::bytes::Bytes;
12use jacquard_common::types::string::{Did, Tid};
13use jacquard_derive::{IntoStatic, open_union};
14use serde::{Serialize, Deserialize};
15
16#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
17#[serde(rename_all = "camelCase")]
18pub struct GetRepo<'a> {
19 #[serde(borrow)]
20 pub did: Did<'a>,
21 #[serde(skip_serializing_if = "Option::is_none")]
22 pub since: Option<Tid>,
23}
24
25
26#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
27#[serde(rename_all = "camelCase")]
28pub struct GetRepoOutput {
29 pub body: Bytes,
30}
31
32
33#[open_union]
34#[derive(
35 Serialize,
36 Deserialize,
37 Debug,
38 Clone,
39 PartialEq,
40 Eq,
41 thiserror::Error,
42 miette::Diagnostic,
43 IntoStatic
44)]
45
46#[serde(tag = "error", content = "message")]
47#[serde(bound(deserialize = "'de: 'a"))]
48pub enum GetRepoError<'a> {
49 #[serde(rename = "RepoNotFound")]
50 RepoNotFound(Option<CowStr<'a>>),
51 #[serde(rename = "RepoTakendown")]
52 RepoTakendown(Option<CowStr<'a>>),
53 #[serde(rename = "RepoSuspended")]
54 RepoSuspended(Option<CowStr<'a>>),
55 #[serde(rename = "RepoDeactivated")]
56 RepoDeactivated(Option<CowStr<'a>>),
57}
58
59impl core::fmt::Display for GetRepoError<'_> {
60 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
61 match self {
62 Self::RepoNotFound(msg) => {
63 write!(f, "RepoNotFound")?;
64 if let Some(msg) = msg {
65 write!(f, ": {}", msg)?;
66 }
67 Ok(())
68 }
69 Self::RepoTakendown(msg) => {
70 write!(f, "RepoTakendown")?;
71 if let Some(msg) = msg {
72 write!(f, ": {}", msg)?;
73 }
74 Ok(())
75 }
76 Self::RepoSuspended(msg) => {
77 write!(f, "RepoSuspended")?;
78 if let Some(msg) = msg {
79 write!(f, ": {}", msg)?;
80 }
81 Ok(())
82 }
83 Self::RepoDeactivated(msg) => {
84 write!(f, "RepoDeactivated")?;
85 if let Some(msg) = msg {
86 write!(f, ": {}", msg)?;
87 }
88 Ok(())
89 }
90 Self::Unknown(err) => write!(f, "Unknown error: {:?}", err),
91 }
92 }
93}
94
95pub struct GetRepoResponse;
97impl jacquard_common::xrpc::XrpcResp for GetRepoResponse {
98 const NSID: &'static str = "com.atproto.sync.getRepo";
99 const ENCODING: &'static str = "application/vnd.ipld.car";
100 type Output<'de> = GetRepoOutput;
101 type Err<'de> = GetRepoError<'de>;
102 fn encode_output(
103 output: &Self::Output<'_>,
104 ) -> Result<Vec<u8>, jacquard_common::xrpc::EncodeError> {
105 Ok(output.body.to_vec())
106 }
107 fn decode_output<'de>(
108 body: &'de [u8],
109 ) -> Result<Self::Output<'de>, jacquard_common::error::DecodeError>
110 where
111 Self::Output<'de>: serde::Deserialize<'de>,
112 {
113 Ok(GetRepoOutput {
114 body: jacquard_common::deps::bytes::Bytes::copy_from_slice(body),
115 })
116 }
117}
118
119impl<'a> jacquard_common::xrpc::XrpcRequest for GetRepo<'a> {
120 const NSID: &'static str = "com.atproto.sync.getRepo";
121 const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
122 type Response = GetRepoResponse;
123}
124
125pub struct GetRepoRequest;
127impl jacquard_common::xrpc::XrpcEndpoint for GetRepoRequest {
128 const PATH: &'static str = "/xrpc/com.atproto.sync.getRepo";
129 const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
130 type Request<'de> = GetRepo<'de>;
131 type Response = GetRepoResponse;
132}
133
134pub mod get_repo_state {
135
136 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
137 #[allow(unused)]
138 use ::core::marker::PhantomData;
139 mod sealed {
140 pub trait Sealed {}
141 }
142 pub trait State: sealed::Sealed {
144 type Did;
145 }
146 pub struct Empty(());
148 impl sealed::Sealed for Empty {}
149 impl State for Empty {
150 type Did = Unset;
151 }
152 pub struct SetDid<S: State = Empty>(PhantomData<fn() -> S>);
154 impl<S: State> sealed::Sealed for SetDid<S> {}
155 impl<S: State> State for SetDid<S> {
156 type Did = Set<members::did>;
157 }
158 #[allow(non_camel_case_types)]
160 pub mod members {
161 pub struct did(());
163 }
164}
165
166pub struct GetRepoBuilder<'a, S: get_repo_state::State> {
168 _state: PhantomData<fn() -> S>,
169 _fields: (Option<Did<'a>>, Option<Tid>),
170 _lifetime: PhantomData<&'a ()>,
171}
172
173impl<'a> GetRepo<'a> {
174 pub fn new() -> GetRepoBuilder<'a, get_repo_state::Empty> {
176 GetRepoBuilder::new()
177 }
178}
179
180impl<'a> GetRepoBuilder<'a, get_repo_state::Empty> {
181 pub fn new() -> Self {
183 GetRepoBuilder {
184 _state: PhantomData,
185 _fields: (None, None),
186 _lifetime: PhantomData,
187 }
188 }
189}
190
191impl<'a, S> GetRepoBuilder<'a, S>
192where
193 S: get_repo_state::State,
194 S::Did: get_repo_state::IsUnset,
195{
196 pub fn did(
198 mut self,
199 value: impl Into<Did<'a>>,
200 ) -> GetRepoBuilder<'a, get_repo_state::SetDid<S>> {
201 self._fields.0 = Option::Some(value.into());
202 GetRepoBuilder {
203 _state: PhantomData,
204 _fields: self._fields,
205 _lifetime: PhantomData,
206 }
207 }
208}
209
210impl<'a, S: get_repo_state::State> GetRepoBuilder<'a, S> {
211 pub fn since(mut self, value: impl Into<Option<Tid>>) -> Self {
213 self._fields.1 = value.into();
214 self
215 }
216 pub fn maybe_since(mut self, value: Option<Tid>) -> Self {
218 self._fields.1 = value;
219 self
220 }
221}
222
223impl<'a, S> GetRepoBuilder<'a, S>
224where
225 S: get_repo_state::State,
226 S::Did: get_repo_state::IsSet,
227{
228 pub fn build(self) -> GetRepo<'a> {
230 GetRepo {
231 did: self._fields.0.unwrap(),
232 since: self._fields.1,
233 }
234 }
235}