atproto blogging
1// @generated by jacquard-lexicon. DO NOT EDIT.
2//
3// Lexicon: sh.weaver.publish.blob
4//
5// This file was automatically generated from Lexicon schemas.
6// Any manual changes will be overwritten on the next regeneration.
7
8/// A simple record referencing a file hosted on a PDS
9#[jacquard_derive::lexicon]
10#[derive(
11 serde::Serialize,
12 serde::Deserialize,
13 Debug,
14 Clone,
15 PartialEq,
16 Eq,
17 jacquard_derive::IntoStatic
18)]
19#[serde(rename_all = "camelCase")]
20pub struct Blob<'a> {
21 /// relative path to the blob
22 #[serde(borrow)]
23 pub path: jacquard_common::CowStr<'a>,
24 /// Reference to the uploaded file
25 #[serde(borrow)]
26 pub upload: jacquard_common::types::blob::BlobRef<'a>,
27}
28
29pub mod blob_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 /// State trait tracking which required fields have been set
38 pub trait State: sealed::Sealed {
39 type Path;
40 type Upload;
41 }
42 /// Empty state - all required fields are unset
43 pub struct Empty(());
44 impl sealed::Sealed for Empty {}
45 impl State for Empty {
46 type Path = Unset;
47 type Upload = Unset;
48 }
49 ///State transition - sets the `path` field to Set
50 pub struct SetPath<S: State = Empty>(PhantomData<fn() -> S>);
51 impl<S: State> sealed::Sealed for SetPath<S> {}
52 impl<S: State> State for SetPath<S> {
53 type Path = Set<members::path>;
54 type Upload = S::Upload;
55 }
56 ///State transition - sets the `upload` field to Set
57 pub struct SetUpload<S: State = Empty>(PhantomData<fn() -> S>);
58 impl<S: State> sealed::Sealed for SetUpload<S> {}
59 impl<S: State> State for SetUpload<S> {
60 type Path = S::Path;
61 type Upload = Set<members::upload>;
62 }
63 /// Marker types for field names
64 #[allow(non_camel_case_types)]
65 pub mod members {
66 ///Marker type for the `path` field
67 pub struct path(());
68 ///Marker type for the `upload` field
69 pub struct upload(());
70 }
71}
72
73/// Builder for constructing an instance of this type
74pub struct BlobBuilder<'a, S: blob_state::State> {
75 _phantom_state: ::core::marker::PhantomData<fn() -> S>,
76 __unsafe_private_named: (
77 ::core::option::Option<jacquard_common::CowStr<'a>>,
78 ::core::option::Option<jacquard_common::types::blob::BlobRef<'a>>,
79 ),
80 _phantom: ::core::marker::PhantomData<&'a ()>,
81}
82
83impl<'a> Blob<'a> {
84 /// Create a new builder for this type
85 pub fn new() -> BlobBuilder<'a, blob_state::Empty> {
86 BlobBuilder::new()
87 }
88}
89
90impl<'a> BlobBuilder<'a, blob_state::Empty> {
91 /// Create a new builder with all fields unset
92 pub fn new() -> Self {
93 BlobBuilder {
94 _phantom_state: ::core::marker::PhantomData,
95 __unsafe_private_named: (None, None),
96 _phantom: ::core::marker::PhantomData,
97 }
98 }
99}
100
101impl<'a, S> BlobBuilder<'a, S>
102where
103 S: blob_state::State,
104 S::Path: blob_state::IsUnset,
105{
106 /// Set the `path` field (required)
107 pub fn path(
108 mut self,
109 value: impl Into<jacquard_common::CowStr<'a>>,
110 ) -> BlobBuilder<'a, blob_state::SetPath<S>> {
111 self.__unsafe_private_named.0 = ::core::option::Option::Some(value.into());
112 BlobBuilder {
113 _phantom_state: ::core::marker::PhantomData,
114 __unsafe_private_named: self.__unsafe_private_named,
115 _phantom: ::core::marker::PhantomData,
116 }
117 }
118}
119
120impl<'a, S> BlobBuilder<'a, S>
121where
122 S: blob_state::State,
123 S::Upload: blob_state::IsUnset,
124{
125 /// Set the `upload` field (required)
126 pub fn upload(
127 mut self,
128 value: impl Into<jacquard_common::types::blob::BlobRef<'a>>,
129 ) -> BlobBuilder<'a, blob_state::SetUpload<S>> {
130 self.__unsafe_private_named.1 = ::core::option::Option::Some(value.into());
131 BlobBuilder {
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> BlobBuilder<'a, S>
140where
141 S: blob_state::State,
142 S::Path: blob_state::IsSet,
143 S::Upload: blob_state::IsSet,
144{
145 /// Build the final struct
146 pub fn build(self) -> Blob<'a> {
147 Blob {
148 path: self.__unsafe_private_named.0.unwrap(),
149 upload: self.__unsafe_private_named.1.unwrap(),
150 extra_data: Default::default(),
151 }
152 }
153 /// Build the final struct with custom extra_data
154 pub fn build_with_data(
155 self,
156 extra_data: std::collections::BTreeMap<
157 jacquard_common::smol_str::SmolStr,
158 jacquard_common::types::value::Data<'a>,
159 >,
160 ) -> Blob<'a> {
161 Blob {
162 path: self.__unsafe_private_named.0.unwrap(),
163 upload: self.__unsafe_private_named.1.unwrap(),
164 extra_data: Some(extra_data),
165 }
166 }
167}
168
169impl<'a> Blob<'a> {
170 pub fn uri(
171 uri: impl Into<jacquard_common::CowStr<'a>>,
172 ) -> Result<
173 jacquard_common::types::uri::RecordUri<'a, BlobRecord>,
174 jacquard_common::types::uri::UriError,
175 > {
176 jacquard_common::types::uri::RecordUri::try_from_uri(
177 jacquard_common::types::string::AtUri::new_cow(uri.into())?,
178 )
179 }
180}
181
182/// Typed wrapper for GetRecord response with this collection's record type.
183#[derive(
184 serde::Serialize,
185 serde::Deserialize,
186 Debug,
187 Clone,
188 PartialEq,
189 Eq,
190 jacquard_derive::IntoStatic
191)]
192#[serde(rename_all = "camelCase")]
193pub struct BlobGetRecordOutput<'a> {
194 #[serde(skip_serializing_if = "std::option::Option::is_none")]
195 #[serde(borrow)]
196 pub cid: std::option::Option<jacquard_common::types::string::Cid<'a>>,
197 #[serde(borrow)]
198 pub uri: jacquard_common::types::string::AtUri<'a>,
199 #[serde(borrow)]
200 pub value: Blob<'a>,
201}
202
203impl From<BlobGetRecordOutput<'_>> for Blob<'_> {
204 fn from(output: BlobGetRecordOutput<'_>) -> Self {
205 use jacquard_common::IntoStatic;
206 output.value.into_static()
207 }
208}
209
210impl jacquard_common::types::collection::Collection for Blob<'_> {
211 const NSID: &'static str = "sh.weaver.publish.blob";
212 type Record = BlobRecord;
213}
214
215/// Marker type for deserializing records from this collection.
216#[derive(Debug, serde::Serialize, serde::Deserialize)]
217pub struct BlobRecord;
218impl jacquard_common::xrpc::XrpcResp for BlobRecord {
219 const NSID: &'static str = "sh.weaver.publish.blob";
220 const ENCODING: &'static str = "application/json";
221 type Output<'de> = BlobGetRecordOutput<'de>;
222 type Err<'de> = jacquard_common::types::collection::RecordError<'de>;
223}
224
225impl jacquard_common::types::collection::Collection for BlobRecord {
226 const NSID: &'static str = "sh.weaver.publish.blob";
227 type Record = BlobRecord;
228}
229
230impl<'a> ::jacquard_lexicon::schema::LexiconSchema for Blob<'a> {
231 fn nsid() -> &'static str {
232 "sh.weaver.publish.blob"
233 }
234 fn def_name() -> &'static str {
235 "main"
236 }
237 fn lexicon_doc() -> ::jacquard_lexicon::lexicon::LexiconDoc<'static> {
238 lexicon_doc_sh_weaver_publish_blob()
239 }
240 fn validate(
241 &self,
242 ) -> ::core::result::Result<(), ::jacquard_lexicon::validation::ConstraintError> {
243 {
244 let value = &self.path;
245 #[allow(unused_comparisons)]
246 if <str>::len(value.as_ref()) < 1usize {
247 return Err(::jacquard_lexicon::validation::ConstraintError::MinLength {
248 path: ::jacquard_lexicon::validation::ValidationPath::from_field(
249 "path",
250 ),
251 min: 1usize,
252 actual: <str>::len(value.as_ref()),
253 });
254 }
255 }
256 Ok(())
257 }
258}
259
260fn lexicon_doc_sh_weaver_publish_blob() -> ::jacquard_lexicon::lexicon::LexiconDoc<
261 'static,
262> {
263 ::jacquard_lexicon::lexicon::LexiconDoc {
264 lexicon: ::jacquard_lexicon::lexicon::Lexicon::Lexicon1,
265 id: ::jacquard_common::CowStr::new_static("sh.weaver.publish.blob"),
266 revision: None,
267 description: None,
268 defs: {
269 let mut map = ::alloc::collections::BTreeMap::new();
270 map.insert(
271 ::jacquard_common::smol_str::SmolStr::new_static("main"),
272 ::jacquard_lexicon::lexicon::LexUserType::Record(::jacquard_lexicon::lexicon::LexRecord {
273 description: Some(
274 ::jacquard_common::CowStr::new_static(
275 "A simple record referencing a file hosted on a PDS",
276 ),
277 ),
278 key: Some(::jacquard_common::CowStr::new_static("tid")),
279 record: ::jacquard_lexicon::lexicon::LexRecordRecord::Object(::jacquard_lexicon::lexicon::LexObject {
280 description: None,
281 required: Some(
282 vec![
283 ::jacquard_common::smol_str::SmolStr::new_static("upload"),
284 ::jacquard_common::smol_str::SmolStr::new_static("path")
285 ],
286 ),
287 nullable: None,
288 properties: {
289 #[allow(unused_mut)]
290 let mut map = ::alloc::collections::BTreeMap::new();
291 map.insert(
292 ::jacquard_common::smol_str::SmolStr::new_static("path"),
293 ::jacquard_lexicon::lexicon::LexObjectProperty::String(::jacquard_lexicon::lexicon::LexString {
294 description: Some(
295 ::jacquard_common::CowStr::new_static(
296 "relative path to the blob",
297 ),
298 ),
299 format: None,
300 default: None,
301 min_length: Some(1usize),
302 max_length: None,
303 min_graphemes: None,
304 max_graphemes: None,
305 r#enum: None,
306 r#const: None,
307 known_values: None,
308 }),
309 );
310 map.insert(
311 ::jacquard_common::smol_str::SmolStr::new_static("upload"),
312 ::jacquard_lexicon::lexicon::LexObjectProperty::Blob(::jacquard_lexicon::lexicon::LexBlob {
313 description: None,
314 accept: None,
315 max_size: None,
316 }),
317 );
318 map
319 },
320 }),
321 }),
322 );
323 map
324 },
325 }
326}