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