atproto blogging
1// @generated by jacquard-lexicon. DO NOT EDIT.
2//
3// Lexicon: pub.leaflet.poll.definition
4//
5// This file was automatically generated from Lexicon schemas.
6// Any manual changes will be overwritten on the next regeneration.
7
8/// Record declaring a poll
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 Definition<'a> {
21 #[serde(skip_serializing_if = "std::option::Option::is_none")]
22 pub end_date: std::option::Option<jacquard_common::types::string::Datetime>,
23 #[serde(borrow)]
24 pub name: jacquard_common::CowStr<'a>,
25 #[serde(borrow)]
26 pub options: Vec<crate::pub_leaflet::poll::definition::DefinitionOption<'a>>,
27}
28
29pub mod definition_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 Options;
40 type Name;
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 Options = Unset;
47 type Name = Unset;
48 }
49 ///State transition - sets the `options` field to Set
50 pub struct SetOptions<S: State = Empty>(PhantomData<fn() -> S>);
51 impl<S: State> sealed::Sealed for SetOptions<S> {}
52 impl<S: State> State for SetOptions<S> {
53 type Options = Set<members::options>;
54 type Name = S::Name;
55 }
56 ///State transition - sets the `name` field to Set
57 pub struct SetName<S: State = Empty>(PhantomData<fn() -> S>);
58 impl<S: State> sealed::Sealed for SetName<S> {}
59 impl<S: State> State for SetName<S> {
60 type Options = S::Options;
61 type Name = Set<members::name>;
62 }
63 /// Marker types for field names
64 #[allow(non_camel_case_types)]
65 pub mod members {
66 ///Marker type for the `options` field
67 pub struct options(());
68 ///Marker type for the `name` field
69 pub struct name(());
70 }
71}
72
73/// Builder for constructing an instance of this type
74pub struct DefinitionBuilder<'a, S: definition_state::State> {
75 _phantom_state: ::core::marker::PhantomData<fn() -> S>,
76 __unsafe_private_named: (
77 ::core::option::Option<jacquard_common::types::string::Datetime>,
78 ::core::option::Option<jacquard_common::CowStr<'a>>,
79 ::core::option::Option<
80 Vec<crate::pub_leaflet::poll::definition::DefinitionOption<'a>>,
81 >,
82 ),
83 _phantom: ::core::marker::PhantomData<&'a ()>,
84}
85
86impl<'a> Definition<'a> {
87 /// Create a new builder for this type
88 pub fn new() -> DefinitionBuilder<'a, definition_state::Empty> {
89 DefinitionBuilder::new()
90 }
91}
92
93impl<'a> DefinitionBuilder<'a, definition_state::Empty> {
94 /// Create a new builder with all fields unset
95 pub fn new() -> Self {
96 DefinitionBuilder {
97 _phantom_state: ::core::marker::PhantomData,
98 __unsafe_private_named: (None, None, None),
99 _phantom: ::core::marker::PhantomData,
100 }
101 }
102}
103
104impl<'a, S: definition_state::State> DefinitionBuilder<'a, S> {
105 /// Set the `endDate` field (optional)
106 pub fn end_date(
107 mut self,
108 value: impl Into<Option<jacquard_common::types::string::Datetime>>,
109 ) -> Self {
110 self.__unsafe_private_named.0 = value.into();
111 self
112 }
113 /// Set the `endDate` field to an Option value (optional)
114 pub fn maybe_end_date(
115 mut self,
116 value: Option<jacquard_common::types::string::Datetime>,
117 ) -> Self {
118 self.__unsafe_private_named.0 = value;
119 self
120 }
121}
122
123impl<'a, S> DefinitionBuilder<'a, S>
124where
125 S: definition_state::State,
126 S::Name: definition_state::IsUnset,
127{
128 /// Set the `name` field (required)
129 pub fn name(
130 mut self,
131 value: impl Into<jacquard_common::CowStr<'a>>,
132 ) -> DefinitionBuilder<'a, definition_state::SetName<S>> {
133 self.__unsafe_private_named.1 = ::core::option::Option::Some(value.into());
134 DefinitionBuilder {
135 _phantom_state: ::core::marker::PhantomData,
136 __unsafe_private_named: self.__unsafe_private_named,
137 _phantom: ::core::marker::PhantomData,
138 }
139 }
140}
141
142impl<'a, S> DefinitionBuilder<'a, S>
143where
144 S: definition_state::State,
145 S::Options: definition_state::IsUnset,
146{
147 /// Set the `options` field (required)
148 pub fn options(
149 mut self,
150 value: impl Into<Vec<crate::pub_leaflet::poll::definition::DefinitionOption<'a>>>,
151 ) -> DefinitionBuilder<'a, definition_state::SetOptions<S>> {
152 self.__unsafe_private_named.2 = ::core::option::Option::Some(value.into());
153 DefinitionBuilder {
154 _phantom_state: ::core::marker::PhantomData,
155 __unsafe_private_named: self.__unsafe_private_named,
156 _phantom: ::core::marker::PhantomData,
157 }
158 }
159}
160
161impl<'a, S> DefinitionBuilder<'a, S>
162where
163 S: definition_state::State,
164 S::Options: definition_state::IsSet,
165 S::Name: definition_state::IsSet,
166{
167 /// Build the final struct
168 pub fn build(self) -> Definition<'a> {
169 Definition {
170 end_date: self.__unsafe_private_named.0,
171 name: self.__unsafe_private_named.1.unwrap(),
172 options: self.__unsafe_private_named.2.unwrap(),
173 extra_data: Default::default(),
174 }
175 }
176 /// Build the final struct with custom extra_data
177 pub fn build_with_data(
178 self,
179 extra_data: std::collections::BTreeMap<
180 jacquard_common::smol_str::SmolStr,
181 jacquard_common::types::value::Data<'a>,
182 >,
183 ) -> Definition<'a> {
184 Definition {
185 end_date: self.__unsafe_private_named.0,
186 name: self.__unsafe_private_named.1.unwrap(),
187 options: self.__unsafe_private_named.2.unwrap(),
188 extra_data: Some(extra_data),
189 }
190 }
191}
192
193impl<'a> Definition<'a> {
194 pub fn uri(
195 uri: impl Into<jacquard_common::CowStr<'a>>,
196 ) -> Result<
197 jacquard_common::types::uri::RecordUri<'a, DefinitionRecord>,
198 jacquard_common::types::uri::UriError,
199 > {
200 jacquard_common::types::uri::RecordUri::try_from_uri(
201 jacquard_common::types::string::AtUri::new_cow(uri.into())?,
202 )
203 }
204}
205
206/// Typed wrapper for GetRecord response with this collection's record type.
207#[derive(
208 serde::Serialize,
209 serde::Deserialize,
210 Debug,
211 Clone,
212 PartialEq,
213 Eq,
214 jacquard_derive::IntoStatic
215)]
216#[serde(rename_all = "camelCase")]
217pub struct DefinitionGetRecordOutput<'a> {
218 #[serde(skip_serializing_if = "std::option::Option::is_none")]
219 #[serde(borrow)]
220 pub cid: std::option::Option<jacquard_common::types::string::Cid<'a>>,
221 #[serde(borrow)]
222 pub uri: jacquard_common::types::string::AtUri<'a>,
223 #[serde(borrow)]
224 pub value: Definition<'a>,
225}
226
227impl From<DefinitionGetRecordOutput<'_>> for Definition<'_> {
228 fn from(output: DefinitionGetRecordOutput<'_>) -> Self {
229 use jacquard_common::IntoStatic;
230 output.value.into_static()
231 }
232}
233
234impl jacquard_common::types::collection::Collection for Definition<'_> {
235 const NSID: &'static str = "pub.leaflet.poll.definition";
236 type Record = DefinitionRecord;
237}
238
239/// Marker type for deserializing records from this collection.
240#[derive(Debug, serde::Serialize, serde::Deserialize)]
241pub struct DefinitionRecord;
242impl jacquard_common::xrpc::XrpcResp for DefinitionRecord {
243 const NSID: &'static str = "pub.leaflet.poll.definition";
244 const ENCODING: &'static str = "application/json";
245 type Output<'de> = DefinitionGetRecordOutput<'de>;
246 type Err<'de> = jacquard_common::types::collection::RecordError<'de>;
247}
248
249impl jacquard_common::types::collection::Collection for DefinitionRecord {
250 const NSID: &'static str = "pub.leaflet.poll.definition";
251 type Record = DefinitionRecord;
252}
253
254impl<'a> ::jacquard_lexicon::schema::LexiconSchema for Definition<'a> {
255 fn nsid() -> &'static str {
256 "pub.leaflet.poll.definition"
257 }
258 fn def_name() -> &'static str {
259 "main"
260 }
261 fn lexicon_doc() -> ::jacquard_lexicon::lexicon::LexiconDoc<'static> {
262 lexicon_doc_pub_leaflet_poll_definition()
263 }
264 fn validate(
265 &self,
266 ) -> ::core::result::Result<(), ::jacquard_lexicon::validation::ConstraintError> {
267 {
268 let value = &self.name;
269 #[allow(unused_comparisons)]
270 if <str>::len(value.as_ref()) > 500usize {
271 return Err(::jacquard_lexicon::validation::ConstraintError::MaxLength {
272 path: ::jacquard_lexicon::validation::ValidationPath::from_field(
273 "name",
274 ),
275 max: 500usize,
276 actual: <str>::len(value.as_ref()),
277 });
278 }
279 }
280 {
281 let value = &self.name;
282 {
283 let count = ::unicode_segmentation::UnicodeSegmentation::graphemes(
284 value.as_ref(),
285 true,
286 )
287 .count();
288 if count > 100usize {
289 return Err(::jacquard_lexicon::validation::ConstraintError::MaxGraphemes {
290 path: ::jacquard_lexicon::validation::ValidationPath::from_field(
291 "name",
292 ),
293 max: 100usize,
294 actual: count,
295 });
296 }
297 }
298 }
299 Ok(())
300 }
301}
302
303fn lexicon_doc_pub_leaflet_poll_definition() -> ::jacquard_lexicon::lexicon::LexiconDoc<
304 'static,
305> {
306 ::jacquard_lexicon::lexicon::LexiconDoc {
307 lexicon: ::jacquard_lexicon::lexicon::Lexicon::Lexicon1,
308 id: ::jacquard_common::CowStr::new_static("pub.leaflet.poll.definition"),
309 revision: None,
310 description: None,
311 defs: {
312 let mut map = ::alloc::collections::BTreeMap::new();
313 map.insert(
314 ::jacquard_common::smol_str::SmolStr::new_static("main"),
315 ::jacquard_lexicon::lexicon::LexUserType::Record(::jacquard_lexicon::lexicon::LexRecord {
316 description: Some(
317 ::jacquard_common::CowStr::new_static("Record declaring a poll"),
318 ),
319 key: Some(::jacquard_common::CowStr::new_static("tid")),
320 record: ::jacquard_lexicon::lexicon::LexRecordRecord::Object(::jacquard_lexicon::lexicon::LexObject {
321 description: None,
322 required: Some(
323 vec![
324 ::jacquard_common::smol_str::SmolStr::new_static("name"),
325 ::jacquard_common::smol_str::SmolStr::new_static("options")
326 ],
327 ),
328 nullable: None,
329 properties: {
330 #[allow(unused_mut)]
331 let mut map = ::alloc::collections::BTreeMap::new();
332 map.insert(
333 ::jacquard_common::smol_str::SmolStr::new_static("endDate"),
334 ::jacquard_lexicon::lexicon::LexObjectProperty::String(::jacquard_lexicon::lexicon::LexString {
335 description: None,
336 format: Some(
337 ::jacquard_lexicon::lexicon::LexStringFormat::Datetime,
338 ),
339 default: None,
340 min_length: None,
341 max_length: None,
342 min_graphemes: None,
343 max_graphemes: None,
344 r#enum: None,
345 r#const: None,
346 known_values: None,
347 }),
348 );
349 map.insert(
350 ::jacquard_common::smol_str::SmolStr::new_static("name"),
351 ::jacquard_lexicon::lexicon::LexObjectProperty::String(::jacquard_lexicon::lexicon::LexString {
352 description: None,
353 format: None,
354 default: None,
355 min_length: None,
356 max_length: Some(500usize),
357 min_graphemes: None,
358 max_graphemes: Some(100usize),
359 r#enum: None,
360 r#const: None,
361 known_values: None,
362 }),
363 );
364 map.insert(
365 ::jacquard_common::smol_str::SmolStr::new_static("options"),
366 ::jacquard_lexicon::lexicon::LexObjectProperty::Array(::jacquard_lexicon::lexicon::LexArray {
367 description: None,
368 items: ::jacquard_lexicon::lexicon::LexArrayItem::Ref(::jacquard_lexicon::lexicon::LexRef {
369 description: None,
370 r#ref: ::jacquard_common::CowStr::new_static("#option"),
371 }),
372 min_length: None,
373 max_length: None,
374 }),
375 );
376 map
377 },
378 }),
379 }),
380 );
381 map.insert(
382 ::jacquard_common::smol_str::SmolStr::new_static("option"),
383 ::jacquard_lexicon::lexicon::LexUserType::Object(::jacquard_lexicon::lexicon::LexObject {
384 description: None,
385 required: None,
386 nullable: None,
387 properties: {
388 #[allow(unused_mut)]
389 let mut map = ::alloc::collections::BTreeMap::new();
390 map.insert(
391 ::jacquard_common::smol_str::SmolStr::new_static("text"),
392 ::jacquard_lexicon::lexicon::LexObjectProperty::String(::jacquard_lexicon::lexicon::LexString {
393 description: None,
394 format: None,
395 default: None,
396 min_length: None,
397 max_length: Some(500usize),
398 min_graphemes: None,
399 max_graphemes: Some(50usize),
400 r#enum: None,
401 r#const: None,
402 known_values: None,
403 }),
404 );
405 map
406 },
407 }),
408 );
409 map
410 },
411 }
412}
413
414#[jacquard_derive::lexicon]
415#[derive(
416 serde::Serialize,
417 serde::Deserialize,
418 Debug,
419 Clone,
420 PartialEq,
421 Eq,
422 jacquard_derive::IntoStatic,
423 Default
424)]
425#[serde(rename_all = "camelCase")]
426pub struct DefinitionOption<'a> {
427 #[serde(skip_serializing_if = "std::option::Option::is_none")]
428 #[serde(borrow)]
429 pub text: std::option::Option<jacquard_common::CowStr<'a>>,
430}
431
432impl<'a> ::jacquard_lexicon::schema::LexiconSchema for DefinitionOption<'a> {
433 fn nsid() -> &'static str {
434 "pub.leaflet.poll.definition"
435 }
436 fn def_name() -> &'static str {
437 "option"
438 }
439 fn lexicon_doc() -> ::jacquard_lexicon::lexicon::LexiconDoc<'static> {
440 lexicon_doc_pub_leaflet_poll_definition()
441 }
442 fn validate(
443 &self,
444 ) -> ::core::result::Result<(), ::jacquard_lexicon::validation::ConstraintError> {
445 if let Some(ref value) = self.text {
446 #[allow(unused_comparisons)]
447 if <str>::len(value.as_ref()) > 500usize {
448 return Err(::jacquard_lexicon::validation::ConstraintError::MaxLength {
449 path: ::jacquard_lexicon::validation::ValidationPath::from_field(
450 "text",
451 ),
452 max: 500usize,
453 actual: <str>::len(value.as_ref()),
454 });
455 }
456 }
457 if let Some(ref value) = self.text {
458 {
459 let count = ::unicode_segmentation::UnicodeSegmentation::graphemes(
460 value.as_ref(),
461 true,
462 )
463 .count();
464 if count > 50usize {
465 return Err(::jacquard_lexicon::validation::ConstraintError::MaxGraphemes {
466 path: ::jacquard_lexicon::validation::ValidationPath::from_field(
467 "text",
468 ),
469 max: 50usize,
470 actual: count,
471 });
472 }
473 }
474 }
475 Ok(())
476 }
477}