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