Skip to main content

jacquard_api/com_atproto/sync/
get_blocks.rs

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