jacquard_api/com_atproto/sync/
get_record.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 GetRecord<'a> {
19 #[serde(borrow)]
20 pub collection: jacquard_common::types::string::Nsid<'a>,
21 #[serde(borrow)]
22 pub did: jacquard_common::types::string::Did<'a>,
23 #[serde(borrow)]
24 pub rkey: jacquard_common::types::string::RecordKey<
25 jacquard_common::types::string::Rkey<'a>,
26 >,
27}
28
29pub mod get_record_state {
30
31 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
32 #[allow(unused)]
33 use ::core::marker::PhantomData;
34 mod sealed {
35 pub trait Sealed {}
36 }
37 pub trait State: sealed::Sealed {
39 type Did;
40 type Collection;
41 type Rkey;
42 }
43 pub struct Empty(());
45 impl sealed::Sealed for Empty {}
46 impl State for Empty {
47 type Did = Unset;
48 type Collection = Unset;
49 type Rkey = Unset;
50 }
51 pub struct SetDid<S: State = Empty>(PhantomData<fn() -> S>);
53 impl<S: State> sealed::Sealed for SetDid<S> {}
54 impl<S: State> State for SetDid<S> {
55 type Did = Set<members::did>;
56 type Collection = S::Collection;
57 type Rkey = S::Rkey;
58 }
59 pub struct SetCollection<S: State = Empty>(PhantomData<fn() -> S>);
61 impl<S: State> sealed::Sealed for SetCollection<S> {}
62 impl<S: State> State for SetCollection<S> {
63 type Did = S::Did;
64 type Collection = Set<members::collection>;
65 type Rkey = S::Rkey;
66 }
67 pub struct SetRkey<S: State = Empty>(PhantomData<fn() -> S>);
69 impl<S: State> sealed::Sealed for SetRkey<S> {}
70 impl<S: State> State for SetRkey<S> {
71 type Did = S::Did;
72 type Collection = S::Collection;
73 type Rkey = Set<members::rkey>;
74 }
75 #[allow(non_camel_case_types)]
77 pub mod members {
78 pub struct did(());
80 pub struct collection(());
82 pub struct rkey(());
84 }
85}
86
87pub struct GetRecordBuilder<'a, S: get_record_state::State> {
89 _phantom_state: ::core::marker::PhantomData<fn() -> S>,
90 __unsafe_private_named: (
91 ::core::option::Option<jacquard_common::types::string::Nsid<'a>>,
92 ::core::option::Option<jacquard_common::types::string::Did<'a>>,
93 ::core::option::Option<
94 jacquard_common::types::string::RecordKey<
95 jacquard_common::types::string::Rkey<'a>,
96 >,
97 >,
98 ),
99 _phantom: ::core::marker::PhantomData<&'a ()>,
100}
101
102impl<'a> GetRecord<'a> {
103 pub fn new() -> GetRecordBuilder<'a, get_record_state::Empty> {
105 GetRecordBuilder::new()
106 }
107}
108
109impl<'a> GetRecordBuilder<'a, get_record_state::Empty> {
110 pub fn new() -> Self {
112 GetRecordBuilder {
113 _phantom_state: ::core::marker::PhantomData,
114 __unsafe_private_named: (None, None, None),
115 _phantom: ::core::marker::PhantomData,
116 }
117 }
118}
119
120impl<'a, S> GetRecordBuilder<'a, S>
121where
122 S: get_record_state::State,
123 S::Collection: get_record_state::IsUnset,
124{
125 pub fn collection(
127 mut self,
128 value: impl Into<jacquard_common::types::string::Nsid<'a>>,
129 ) -> GetRecordBuilder<'a, get_record_state::SetCollection<S>> {
130 self.__unsafe_private_named.0 = ::core::option::Option::Some(value.into());
131 GetRecordBuilder {
132 _phantom_state: ::core::marker::PhantomData,
133 __unsafe_private_named: self.__unsafe_private_named,
134 _phantom: ::core::marker::PhantomData,
135 }
136 }
137}
138
139impl<'a, S> GetRecordBuilder<'a, S>
140where
141 S: get_record_state::State,
142 S::Did: get_record_state::IsUnset,
143{
144 pub fn did(
146 mut self,
147 value: impl Into<jacquard_common::types::string::Did<'a>>,
148 ) -> GetRecordBuilder<'a, get_record_state::SetDid<S>> {
149 self.__unsafe_private_named.1 = ::core::option::Option::Some(value.into());
150 GetRecordBuilder {
151 _phantom_state: ::core::marker::PhantomData,
152 __unsafe_private_named: self.__unsafe_private_named,
153 _phantom: ::core::marker::PhantomData,
154 }
155 }
156}
157
158impl<'a, S> GetRecordBuilder<'a, S>
159where
160 S: get_record_state::State,
161 S::Rkey: get_record_state::IsUnset,
162{
163 pub fn rkey(
165 mut self,
166 value: impl Into<
167 jacquard_common::types::string::RecordKey<
168 jacquard_common::types::string::Rkey<'a>,
169 >,
170 >,
171 ) -> GetRecordBuilder<'a, get_record_state::SetRkey<S>> {
172 self.__unsafe_private_named.2 = ::core::option::Option::Some(value.into());
173 GetRecordBuilder {
174 _phantom_state: ::core::marker::PhantomData,
175 __unsafe_private_named: self.__unsafe_private_named,
176 _phantom: ::core::marker::PhantomData,
177 }
178 }
179}
180
181impl<'a, S> GetRecordBuilder<'a, S>
182where
183 S: get_record_state::State,
184 S::Did: get_record_state::IsSet,
185 S::Collection: get_record_state::IsSet,
186 S::Rkey: get_record_state::IsSet,
187{
188 pub fn build(self) -> GetRecord<'a> {
190 GetRecord {
191 collection: self.__unsafe_private_named.0.unwrap(),
192 did: self.__unsafe_private_named.1.unwrap(),
193 rkey: self.__unsafe_private_named.2.unwrap(),
194 }
195 }
196}
197
198#[derive(
199 serde::Serialize,
200 serde::Deserialize,
201 Debug,
202 Clone,
203 PartialEq,
204 Eq,
205 jacquard_derive::IntoStatic
206)]
207#[serde(rename_all = "camelCase")]
208pub struct GetRecordOutput {
209 pub body: bytes::Bytes,
210}
211
212#[jacquard_derive::open_union]
213#[derive(
214 serde::Serialize,
215 serde::Deserialize,
216 Debug,
217 Clone,
218 PartialEq,
219 Eq,
220 thiserror::Error,
221 miette::Diagnostic,
222 jacquard_derive::IntoStatic
223)]
224#[serde(tag = "error", content = "message")]
225#[serde(bound(deserialize = "'de: 'a"))]
226pub enum GetRecordError<'a> {
227 #[serde(rename = "RecordNotFound")]
228 RecordNotFound(std::option::Option<String>),
229 #[serde(rename = "RepoNotFound")]
230 RepoNotFound(std::option::Option<String>),
231 #[serde(rename = "RepoTakendown")]
232 RepoTakendown(std::option::Option<String>),
233 #[serde(rename = "RepoSuspended")]
234 RepoSuspended(std::option::Option<String>),
235 #[serde(rename = "RepoDeactivated")]
236 RepoDeactivated(std::option::Option<String>),
237}
238
239impl std::fmt::Display for GetRecordError<'_> {
240 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
241 match self {
242 Self::RecordNotFound(msg) => {
243 write!(f, "RecordNotFound")?;
244 if let Some(msg) = msg {
245 write!(f, ": {}", msg)?;
246 }
247 Ok(())
248 }
249 Self::RepoNotFound(msg) => {
250 write!(f, "RepoNotFound")?;
251 if let Some(msg) = msg {
252 write!(f, ": {}", msg)?;
253 }
254 Ok(())
255 }
256 Self::RepoTakendown(msg) => {
257 write!(f, "RepoTakendown")?;
258 if let Some(msg) = msg {
259 write!(f, ": {}", msg)?;
260 }
261 Ok(())
262 }
263 Self::RepoSuspended(msg) => {
264 write!(f, "RepoSuspended")?;
265 if let Some(msg) = msg {
266 write!(f, ": {}", msg)?;
267 }
268 Ok(())
269 }
270 Self::RepoDeactivated(msg) => {
271 write!(f, "RepoDeactivated")?;
272 if let Some(msg) = msg {
273 write!(f, ": {}", msg)?;
274 }
275 Ok(())
276 }
277 Self::Unknown(err) => write!(f, "Unknown error: {:?}", err),
278 }
279 }
280}
281
282pub struct GetRecordResponse;
285impl jacquard_common::xrpc::XrpcResp for GetRecordResponse {
286 const NSID: &'static str = "com.atproto.sync.getRecord";
287 const ENCODING: &'static str = "application/vnd.ipld.car";
288 type Output<'de> = GetRecordOutput;
289 type Err<'de> = GetRecordError<'de>;
290 fn encode_output(
291 output: &Self::Output<'_>,
292 ) -> Result<Vec<u8>, jacquard_common::xrpc::EncodeError> {
293 Ok(output.body.to_vec())
294 }
295 fn decode_output<'de>(
296 body: &'de [u8],
297 ) -> Result<Self::Output<'de>, jacquard_common::error::DecodeError>
298 where
299 Self::Output<'de>: serde::Deserialize<'de>,
300 {
301 Ok(GetRecordOutput {
302 body: bytes::Bytes::copy_from_slice(body),
303 })
304 }
305}
306
307impl<'a> jacquard_common::xrpc::XrpcRequest for GetRecord<'a> {
308 const NSID: &'static str = "com.atproto.sync.getRecord";
309 const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
310 type Response = GetRecordResponse;
311}
312
313pub struct GetRecordRequest;
316impl jacquard_common::xrpc::XrpcEndpoint for GetRecordRequest {
317 const PATH: &'static str = "/xrpc/com.atproto.sync.getRecord";
318 const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
319 type Request<'de> = GetRecord<'de>;
320 type Response = GetRecordResponse;
321}