jacquard_api/com_atproto/sync/
get_blocks.rs1#[derive(
9 serde::Serialize,
10 serde::Deserialize,
11 Debug,
12 Clone,
13 PartialEq,
14 Eq,
15 jacquard_derive::IntoStatic
16)]
17#[serde(rename_all = "camelCase")]
18pub struct GetBlocks<'a> {
19 #[serde(borrow)]
20 pub cids: Vec<jacquard_common::types::string::Cid<'a>>,
21 #[serde(borrow)]
22 pub did: jacquard_common::types::string::Did<'a>,
23}
24
25pub mod get_blocks_state {
26
27 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
28 #[allow(unused)]
29 use ::core::marker::PhantomData;
30 mod sealed {
31 pub trait Sealed {}
32 }
33 pub trait State: sealed::Sealed {
35 type Did;
36 type Cids;
37 }
38 pub struct Empty(());
40 impl sealed::Sealed for Empty {}
41 impl State for Empty {
42 type Did = Unset;
43 type Cids = Unset;
44 }
45 pub struct SetDid<S: State = Empty>(PhantomData<fn() -> S>);
47 impl<S: State> sealed::Sealed for SetDid<S> {}
48 impl<S: State> State for SetDid<S> {
49 type Did = Set<members::did>;
50 type Cids = S::Cids;
51 }
52 pub struct SetCids<S: State = Empty>(PhantomData<fn() -> S>);
54 impl<S: State> sealed::Sealed for SetCids<S> {}
55 impl<S: State> State for SetCids<S> {
56 type Did = S::Did;
57 type Cids = Set<members::cids>;
58 }
59 #[allow(non_camel_case_types)]
61 pub mod members {
62 pub struct did(());
64 pub struct cids(());
66 }
67}
68
69pub struct GetBlocksBuilder<'a, S: get_blocks_state::State> {
71 _phantom_state: ::core::marker::PhantomData<fn() -> S>,
72 __unsafe_private_named: (
73 ::core::option::Option<Vec<jacquard_common::types::string::Cid<'a>>>,
74 ::core::option::Option<jacquard_common::types::string::Did<'a>>,
75 ),
76 _phantom: ::core::marker::PhantomData<&'a ()>,
77}
78
79impl<'a> GetBlocks<'a> {
80 pub fn new() -> GetBlocksBuilder<'a, get_blocks_state::Empty> {
82 GetBlocksBuilder::new()
83 }
84}
85
86impl<'a> GetBlocksBuilder<'a, get_blocks_state::Empty> {
87 pub fn new() -> Self {
89 GetBlocksBuilder {
90 _phantom_state: ::core::marker::PhantomData,
91 __unsafe_private_named: (None, None),
92 _phantom: ::core::marker::PhantomData,
93 }
94 }
95}
96
97impl<'a, S> GetBlocksBuilder<'a, S>
98where
99 S: get_blocks_state::State,
100 S::Cids: get_blocks_state::IsUnset,
101{
102 pub fn cids(
104 mut self,
105 value: impl Into<Vec<jacquard_common::types::string::Cid<'a>>>,
106 ) -> GetBlocksBuilder<'a, get_blocks_state::SetCids<S>> {
107 self.__unsafe_private_named.0 = ::core::option::Option::Some(value.into());
108 GetBlocksBuilder {
109 _phantom_state: ::core::marker::PhantomData,
110 __unsafe_private_named: self.__unsafe_private_named,
111 _phantom: ::core::marker::PhantomData,
112 }
113 }
114}
115
116impl<'a, S> GetBlocksBuilder<'a, S>
117where
118 S: get_blocks_state::State,
119 S::Did: get_blocks_state::IsUnset,
120{
121 pub fn did(
123 mut self,
124 value: impl Into<jacquard_common::types::string::Did<'a>>,
125 ) -> GetBlocksBuilder<'a, get_blocks_state::SetDid<S>> {
126 self.__unsafe_private_named.1 = ::core::option::Option::Some(value.into());
127 GetBlocksBuilder {
128 _phantom_state: ::core::marker::PhantomData,
129 __unsafe_private_named: self.__unsafe_private_named,
130 _phantom: ::core::marker::PhantomData,
131 }
132 }
133}
134
135impl<'a, S> GetBlocksBuilder<'a, S>
136where
137 S: get_blocks_state::State,
138 S::Did: get_blocks_state::IsSet,
139 S::Cids: get_blocks_state::IsSet,
140{
141 pub fn build(self) -> GetBlocks<'a> {
143 GetBlocks {
144 cids: self.__unsafe_private_named.0.unwrap(),
145 did: self.__unsafe_private_named.1.unwrap(),
146 }
147 }
148}
149
150#[derive(
151 serde::Serialize,
152 serde::Deserialize,
153 Debug,
154 Clone,
155 PartialEq,
156 Eq,
157 jacquard_derive::IntoStatic
158)]
159#[serde(rename_all = "camelCase")]
160pub struct GetBlocksOutput {
161 pub body: bytes::Bytes,
162}
163
164#[jacquard_derive::open_union]
165#[derive(
166 serde::Serialize,
167 serde::Deserialize,
168 Debug,
169 Clone,
170 PartialEq,
171 Eq,
172 thiserror::Error,
173 miette::Diagnostic,
174 jacquard_derive::IntoStatic
175)]
176#[serde(tag = "error", content = "message")]
177#[serde(bound(deserialize = "'de: 'a"))]
178pub enum GetBlocksError<'a> {
179 #[serde(rename = "BlockNotFound")]
180 BlockNotFound(std::option::Option<String>),
181 #[serde(rename = "RepoNotFound")]
182 RepoNotFound(std::option::Option<String>),
183 #[serde(rename = "RepoTakendown")]
184 RepoTakendown(std::option::Option<String>),
185 #[serde(rename = "RepoSuspended")]
186 RepoSuspended(std::option::Option<String>),
187 #[serde(rename = "RepoDeactivated")]
188 RepoDeactivated(std::option::Option<String>),
189}
190
191impl std::fmt::Display for GetBlocksError<'_> {
192 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
193 match self {
194 Self::BlockNotFound(msg) => {
195 write!(f, "BlockNotFound")?;
196 if let Some(msg) = msg {
197 write!(f, ": {}", msg)?;
198 }
199 Ok(())
200 }
201 Self::RepoNotFound(msg) => {
202 write!(f, "RepoNotFound")?;
203 if let Some(msg) = msg {
204 write!(f, ": {}", msg)?;
205 }
206 Ok(())
207 }
208 Self::RepoTakendown(msg) => {
209 write!(f, "RepoTakendown")?;
210 if let Some(msg) = msg {
211 write!(f, ": {}", msg)?;
212 }
213 Ok(())
214 }
215 Self::RepoSuspended(msg) => {
216 write!(f, "RepoSuspended")?;
217 if let Some(msg) = msg {
218 write!(f, ": {}", msg)?;
219 }
220 Ok(())
221 }
222 Self::RepoDeactivated(msg) => {
223 write!(f, "RepoDeactivated")?;
224 if let Some(msg) = msg {
225 write!(f, ": {}", msg)?;
226 }
227 Ok(())
228 }
229 Self::Unknown(err) => write!(f, "Unknown error: {:?}", err),
230 }
231 }
232}
233
234pub struct GetBlocksResponse;
237impl jacquard_common::xrpc::XrpcResp for GetBlocksResponse {
238 const NSID: &'static str = "com.atproto.sync.getBlocks";
239 const ENCODING: &'static str = "application/vnd.ipld.car";
240 type Output<'de> = GetBlocksOutput;
241 type Err<'de> = GetBlocksError<'de>;
242 fn encode_output(
243 output: &Self::Output<'_>,
244 ) -> Result<Vec<u8>, jacquard_common::xrpc::EncodeError> {
245 Ok(output.body.to_vec())
246 }
247 fn decode_output<'de>(
248 body: &'de [u8],
249 ) -> Result<Self::Output<'de>, jacquard_common::error::DecodeError>
250 where
251 Self::Output<'de>: serde::Deserialize<'de>,
252 {
253 Ok(GetBlocksOutput {
254 body: bytes::Bytes::copy_from_slice(body),
255 })
256 }
257}
258
259impl<'a> jacquard_common::xrpc::XrpcRequest for GetBlocks<'a> {
260 const NSID: &'static str = "com.atproto.sync.getBlocks";
261 const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
262 type Response = GetBlocksResponse;
263}
264
265pub struct GetBlocksRequest;
268impl jacquard_common::xrpc::XrpcEndpoint for GetBlocksRequest {
269 const PATH: &'static str = "/xrpc/com.atproto.sync.getBlocks";
270 const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
271 type Request<'de> = GetBlocks<'de>;
272 type Response = GetBlocksResponse;
273}