atproto blogging
1// @generated by jacquard-lexicon. DO NOT EDIT.
2//
3// Lexicon: sh.weaver.graph.list
4//
5// This file was automatically generated from Lexicon schemas.
6// Any manual changes will be overwritten on the next regeneration.
7
8#[derive(Debug, Clone, PartialEq, Eq, Hash)]
9pub enum ListPurpose<'a> {
10 ShWeaverGraphDefsCuratelist,
11 ShWeaverGraphDefsReadinglist,
12 Other(jacquard_common::CowStr<'a>),
13}
14
15impl<'a> ListPurpose<'a> {
16 pub fn as_str(&self) -> &str {
17 match self {
18 Self::ShWeaverGraphDefsCuratelist => "sh.weaver.graph.defs#curatelist",
19 Self::ShWeaverGraphDefsReadinglist => "sh.weaver.graph.defs#readinglist",
20 Self::Other(s) => s.as_ref(),
21 }
22 }
23}
24
25impl<'a> From<&'a str> for ListPurpose<'a> {
26 fn from(s: &'a str) -> Self {
27 match s {
28 "sh.weaver.graph.defs#curatelist" => Self::ShWeaverGraphDefsCuratelist,
29 "sh.weaver.graph.defs#readinglist" => Self::ShWeaverGraphDefsReadinglist,
30 _ => Self::Other(jacquard_common::CowStr::from(s)),
31 }
32 }
33}
34
35impl<'a> From<String> for ListPurpose<'a> {
36 fn from(s: String) -> Self {
37 match s.as_str() {
38 "sh.weaver.graph.defs#curatelist" => Self::ShWeaverGraphDefsCuratelist,
39 "sh.weaver.graph.defs#readinglist" => Self::ShWeaverGraphDefsReadinglist,
40 _ => Self::Other(jacquard_common::CowStr::from(s)),
41 }
42 }
43}
44
45impl<'a> AsRef<str> for ListPurpose<'a> {
46 fn as_ref(&self) -> &str {
47 self.as_str()
48 }
49}
50
51impl<'a> core::fmt::Display for ListPurpose<'a> {
52 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
53 write!(f, "{}", self.as_str())
54 }
55}
56
57impl<'a> serde::Serialize for ListPurpose<'a> {
58 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
59 where
60 S: serde::Serializer,
61 {
62 serializer.serialize_str(self.as_str())
63 }
64}
65
66impl<'de, 'a> serde::Deserialize<'de> for ListPurpose<'a>
67where
68 'de: 'a,
69{
70 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
71 where
72 D: serde::Deserializer<'de>,
73 {
74 let s = <&'de str>::deserialize(deserializer)?;
75 Ok(Self::from(s))
76 }
77}
78
79impl jacquard_common::IntoStatic for ListPurpose<'_> {
80 type Output = ListPurpose<'static>;
81 fn into_static(self) -> Self::Output {
82 match self {
83 ListPurpose::ShWeaverGraphDefsCuratelist => {
84 ListPurpose::ShWeaverGraphDefsCuratelist
85 }
86 ListPurpose::ShWeaverGraphDefsReadinglist => {
87 ListPurpose::ShWeaverGraphDefsReadinglist
88 }
89 ListPurpose::Other(v) => ListPurpose::Other(v.into_static()),
90 }
91 }
92}
93
94/// A curated list of notebooks and/or entries.
95#[jacquard_derive::lexicon]
96#[derive(
97 serde::Serialize,
98 serde::Deserialize,
99 Debug,
100 Clone,
101 PartialEq,
102 Eq,
103 jacquard_derive::IntoStatic
104)]
105#[serde(rename_all = "camelCase")]
106pub struct List<'a> {
107 #[serde(skip_serializing_if = "std::option::Option::is_none")]
108 #[serde(borrow)]
109 pub avatar: std::option::Option<jacquard_common::types::blob::BlobRef<'a>>,
110 pub created_at: jacquard_common::types::string::Datetime,
111 #[serde(skip_serializing_if = "std::option::Option::is_none")]
112 #[serde(borrow)]
113 pub description: std::option::Option<jacquard_common::CowStr<'a>>,
114 /// Display name for the list.
115 #[serde(borrow)]
116 pub name: jacquard_common::CowStr<'a>,
117 /// The purpose/type of list.
118 #[serde(borrow)]
119 pub purpose: crate::sh_weaver::graph::list::ListPurpose<'a>,
120}
121
122pub mod list_state {
123
124 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
125 #[allow(unused)]
126 use ::core::marker::PhantomData;
127 mod sealed {
128 pub trait Sealed {}
129 }
130 /// State trait tracking which required fields have been set
131 pub trait State: sealed::Sealed {
132 type Purpose;
133 type Name;
134 type CreatedAt;
135 }
136 /// Empty state - all required fields are unset
137 pub struct Empty(());
138 impl sealed::Sealed for Empty {}
139 impl State for Empty {
140 type Purpose = Unset;
141 type Name = Unset;
142 type CreatedAt = Unset;
143 }
144 ///State transition - sets the `purpose` field to Set
145 pub struct SetPurpose<S: State = Empty>(PhantomData<fn() -> S>);
146 impl<S: State> sealed::Sealed for SetPurpose<S> {}
147 impl<S: State> State for SetPurpose<S> {
148 type Purpose = Set<members::purpose>;
149 type Name = S::Name;
150 type CreatedAt = S::CreatedAt;
151 }
152 ///State transition - sets the `name` field to Set
153 pub struct SetName<S: State = Empty>(PhantomData<fn() -> S>);
154 impl<S: State> sealed::Sealed for SetName<S> {}
155 impl<S: State> State for SetName<S> {
156 type Purpose = S::Purpose;
157 type Name = Set<members::name>;
158 type CreatedAt = S::CreatedAt;
159 }
160 ///State transition - sets the `created_at` field to Set
161 pub struct SetCreatedAt<S: State = Empty>(PhantomData<fn() -> S>);
162 impl<S: State> sealed::Sealed for SetCreatedAt<S> {}
163 impl<S: State> State for SetCreatedAt<S> {
164 type Purpose = S::Purpose;
165 type Name = S::Name;
166 type CreatedAt = Set<members::created_at>;
167 }
168 /// Marker types for field names
169 #[allow(non_camel_case_types)]
170 pub mod members {
171 ///Marker type for the `purpose` field
172 pub struct purpose(());
173 ///Marker type for the `name` field
174 pub struct name(());
175 ///Marker type for the `created_at` field
176 pub struct created_at(());
177 }
178}
179
180/// Builder for constructing an instance of this type
181pub struct ListBuilder<'a, S: list_state::State> {
182 _phantom_state: ::core::marker::PhantomData<fn() -> S>,
183 __unsafe_private_named: (
184 ::core::option::Option<jacquard_common::types::blob::BlobRef<'a>>,
185 ::core::option::Option<jacquard_common::types::string::Datetime>,
186 ::core::option::Option<jacquard_common::CowStr<'a>>,
187 ::core::option::Option<jacquard_common::CowStr<'a>>,
188 ::core::option::Option<crate::sh_weaver::graph::list::ListPurpose<'a>>,
189 ),
190 _phantom: ::core::marker::PhantomData<&'a ()>,
191}
192
193impl<'a> List<'a> {
194 /// Create a new builder for this type
195 pub fn new() -> ListBuilder<'a, list_state::Empty> {
196 ListBuilder::new()
197 }
198}
199
200impl<'a> ListBuilder<'a, list_state::Empty> {
201 /// Create a new builder with all fields unset
202 pub fn new() -> Self {
203 ListBuilder {
204 _phantom_state: ::core::marker::PhantomData,
205 __unsafe_private_named: (None, None, None, None, None),
206 _phantom: ::core::marker::PhantomData,
207 }
208 }
209}
210
211impl<'a, S: list_state::State> ListBuilder<'a, S> {
212 /// Set the `avatar` field (optional)
213 pub fn avatar(
214 mut self,
215 value: impl Into<Option<jacquard_common::types::blob::BlobRef<'a>>>,
216 ) -> Self {
217 self.__unsafe_private_named.0 = value.into();
218 self
219 }
220 /// Set the `avatar` field to an Option value (optional)
221 pub fn maybe_avatar(
222 mut self,
223 value: Option<jacquard_common::types::blob::BlobRef<'a>>,
224 ) -> Self {
225 self.__unsafe_private_named.0 = value;
226 self
227 }
228}
229
230impl<'a, S> ListBuilder<'a, S>
231where
232 S: list_state::State,
233 S::CreatedAt: list_state::IsUnset,
234{
235 /// Set the `createdAt` field (required)
236 pub fn created_at(
237 mut self,
238 value: impl Into<jacquard_common::types::string::Datetime>,
239 ) -> ListBuilder<'a, list_state::SetCreatedAt<S>> {
240 self.__unsafe_private_named.1 = ::core::option::Option::Some(value.into());
241 ListBuilder {
242 _phantom_state: ::core::marker::PhantomData,
243 __unsafe_private_named: self.__unsafe_private_named,
244 _phantom: ::core::marker::PhantomData,
245 }
246 }
247}
248
249impl<'a, S: list_state::State> ListBuilder<'a, S> {
250 /// Set the `description` field (optional)
251 pub fn description(
252 mut self,
253 value: impl Into<Option<jacquard_common::CowStr<'a>>>,
254 ) -> Self {
255 self.__unsafe_private_named.2 = value.into();
256 self
257 }
258 /// Set the `description` field to an Option value (optional)
259 pub fn maybe_description(
260 mut self,
261 value: Option<jacquard_common::CowStr<'a>>,
262 ) -> Self {
263 self.__unsafe_private_named.2 = value;
264 self
265 }
266}
267
268impl<'a, S> ListBuilder<'a, S>
269where
270 S: list_state::State,
271 S::Name: list_state::IsUnset,
272{
273 /// Set the `name` field (required)
274 pub fn name(
275 mut self,
276 value: impl Into<jacquard_common::CowStr<'a>>,
277 ) -> ListBuilder<'a, list_state::SetName<S>> {
278 self.__unsafe_private_named.3 = ::core::option::Option::Some(value.into());
279 ListBuilder {
280 _phantom_state: ::core::marker::PhantomData,
281 __unsafe_private_named: self.__unsafe_private_named,
282 _phantom: ::core::marker::PhantomData,
283 }
284 }
285}
286
287impl<'a, S> ListBuilder<'a, S>
288where
289 S: list_state::State,
290 S::Purpose: list_state::IsUnset,
291{
292 /// Set the `purpose` field (required)
293 pub fn purpose(
294 mut self,
295 value: impl Into<crate::sh_weaver::graph::list::ListPurpose<'a>>,
296 ) -> ListBuilder<'a, list_state::SetPurpose<S>> {
297 self.__unsafe_private_named.4 = ::core::option::Option::Some(value.into());
298 ListBuilder {
299 _phantom_state: ::core::marker::PhantomData,
300 __unsafe_private_named: self.__unsafe_private_named,
301 _phantom: ::core::marker::PhantomData,
302 }
303 }
304}
305
306impl<'a, S> ListBuilder<'a, S>
307where
308 S: list_state::State,
309 S::Purpose: list_state::IsSet,
310 S::Name: list_state::IsSet,
311 S::CreatedAt: list_state::IsSet,
312{
313 /// Build the final struct
314 pub fn build(self) -> List<'a> {
315 List {
316 avatar: self.__unsafe_private_named.0,
317 created_at: self.__unsafe_private_named.1.unwrap(),
318 description: self.__unsafe_private_named.2,
319 name: self.__unsafe_private_named.3.unwrap(),
320 purpose: self.__unsafe_private_named.4.unwrap(),
321 extra_data: Default::default(),
322 }
323 }
324 /// Build the final struct with custom extra_data
325 pub fn build_with_data(
326 self,
327 extra_data: std::collections::BTreeMap<
328 jacquard_common::smol_str::SmolStr,
329 jacquard_common::types::value::Data<'a>,
330 >,
331 ) -> List<'a> {
332 List {
333 avatar: self.__unsafe_private_named.0,
334 created_at: self.__unsafe_private_named.1.unwrap(),
335 description: self.__unsafe_private_named.2,
336 name: self.__unsafe_private_named.3.unwrap(),
337 purpose: self.__unsafe_private_named.4.unwrap(),
338 extra_data: Some(extra_data),
339 }
340 }
341}
342
343impl<'a> List<'a> {
344 pub fn uri(
345 uri: impl Into<jacquard_common::CowStr<'a>>,
346 ) -> Result<
347 jacquard_common::types::uri::RecordUri<'a, ListRecord>,
348 jacquard_common::types::uri::UriError,
349 > {
350 jacquard_common::types::uri::RecordUri::try_from_uri(
351 jacquard_common::types::string::AtUri::new_cow(uri.into())?,
352 )
353 }
354}
355
356/// Typed wrapper for GetRecord response with this collection's record type.
357#[derive(
358 serde::Serialize,
359 serde::Deserialize,
360 Debug,
361 Clone,
362 PartialEq,
363 Eq,
364 jacquard_derive::IntoStatic
365)]
366#[serde(rename_all = "camelCase")]
367pub struct ListGetRecordOutput<'a> {
368 #[serde(skip_serializing_if = "std::option::Option::is_none")]
369 #[serde(borrow)]
370 pub cid: std::option::Option<jacquard_common::types::string::Cid<'a>>,
371 #[serde(borrow)]
372 pub uri: jacquard_common::types::string::AtUri<'a>,
373 #[serde(borrow)]
374 pub value: List<'a>,
375}
376
377impl From<ListGetRecordOutput<'_>> for List<'_> {
378 fn from(output: ListGetRecordOutput<'_>) -> Self {
379 use jacquard_common::IntoStatic;
380 output.value.into_static()
381 }
382}
383
384impl jacquard_common::types::collection::Collection for List<'_> {
385 const NSID: &'static str = "sh.weaver.graph.list";
386 type Record = ListRecord;
387}
388
389/// Marker type for deserializing records from this collection.
390#[derive(Debug, serde::Serialize, serde::Deserialize)]
391pub struct ListRecord;
392impl jacquard_common::xrpc::XrpcResp for ListRecord {
393 const NSID: &'static str = "sh.weaver.graph.list";
394 const ENCODING: &'static str = "application/json";
395 type Output<'de> = ListGetRecordOutput<'de>;
396 type Err<'de> = jacquard_common::types::collection::RecordError<'de>;
397}
398
399impl jacquard_common::types::collection::Collection for ListRecord {
400 const NSID: &'static str = "sh.weaver.graph.list";
401 type Record = ListRecord;
402}
403
404impl<'a> ::jacquard_lexicon::schema::LexiconSchema for List<'a> {
405 fn nsid() -> &'static str {
406 "sh.weaver.graph.list"
407 }
408 fn def_name() -> &'static str {
409 "main"
410 }
411 fn lexicon_doc() -> ::jacquard_lexicon::lexicon::LexiconDoc<'static> {
412 lexicon_doc_sh_weaver_graph_list()
413 }
414 fn validate(
415 &self,
416 ) -> ::core::result::Result<(), ::jacquard_lexicon::validation::ConstraintError> {
417 if let Some(ref value) = self.description {
418 #[allow(unused_comparisons)]
419 if <str>::len(value.as_ref()) > 3000usize {
420 return Err(::jacquard_lexicon::validation::ConstraintError::MaxLength {
421 path: ::jacquard_lexicon::validation::ValidationPath::from_field(
422 "description",
423 ),
424 max: 3000usize,
425 actual: <str>::len(value.as_ref()),
426 });
427 }
428 }
429 if let Some(ref value) = self.description {
430 {
431 let count = ::unicode_segmentation::UnicodeSegmentation::graphemes(
432 value.as_ref(),
433 true,
434 )
435 .count();
436 if count > 300usize {
437 return Err(::jacquard_lexicon::validation::ConstraintError::MaxGraphemes {
438 path: ::jacquard_lexicon::validation::ValidationPath::from_field(
439 "description",
440 ),
441 max: 300usize,
442 actual: count,
443 });
444 }
445 }
446 }
447 {
448 let value = &self.name;
449 #[allow(unused_comparisons)]
450 if <str>::len(value.as_ref()) > 64usize {
451 return Err(::jacquard_lexicon::validation::ConstraintError::MaxLength {
452 path: ::jacquard_lexicon::validation::ValidationPath::from_field(
453 "name",
454 ),
455 max: 64usize,
456 actual: <str>::len(value.as_ref()),
457 });
458 }
459 }
460 {
461 let value = &self.name;
462 #[allow(unused_comparisons)]
463 if <str>::len(value.as_ref()) < 1usize {
464 return Err(::jacquard_lexicon::validation::ConstraintError::MinLength {
465 path: ::jacquard_lexicon::validation::ValidationPath::from_field(
466 "name",
467 ),
468 min: 1usize,
469 actual: <str>::len(value.as_ref()),
470 });
471 }
472 }
473 Ok(())
474 }
475}
476
477fn lexicon_doc_sh_weaver_graph_list() -> ::jacquard_lexicon::lexicon::LexiconDoc<
478 'static,
479> {
480 ::jacquard_lexicon::lexicon::LexiconDoc {
481 lexicon: ::jacquard_lexicon::lexicon::Lexicon::Lexicon1,
482 id: ::jacquard_common::CowStr::new_static("sh.weaver.graph.list"),
483 revision: None,
484 description: None,
485 defs: {
486 let mut map = ::alloc::collections::BTreeMap::new();
487 map.insert(
488 ::jacquard_common::smol_str::SmolStr::new_static("listPurpose"),
489 ::jacquard_lexicon::lexicon::LexUserType::String(::jacquard_lexicon::lexicon::LexString {
490 description: None,
491 format: None,
492 default: None,
493 min_length: None,
494 max_length: None,
495 min_graphemes: None,
496 max_graphemes: None,
497 r#enum: None,
498 r#const: None,
499 known_values: None,
500 }),
501 );
502 map.insert(
503 ::jacquard_common::smol_str::SmolStr::new_static("main"),
504 ::jacquard_lexicon::lexicon::LexUserType::Record(::jacquard_lexicon::lexicon::LexRecord {
505 description: Some(
506 ::jacquard_common::CowStr::new_static(
507 "A curated list of notebooks and/or entries.",
508 ),
509 ),
510 key: Some(::jacquard_common::CowStr::new_static("tid")),
511 record: ::jacquard_lexicon::lexicon::LexRecordRecord::Object(::jacquard_lexicon::lexicon::LexObject {
512 description: None,
513 required: Some(
514 vec![
515 ::jacquard_common::smol_str::SmolStr::new_static("name"),
516 ::jacquard_common::smol_str::SmolStr::new_static("purpose"),
517 ::jacquard_common::smol_str::SmolStr::new_static("createdAt")
518 ],
519 ),
520 nullable: None,
521 properties: {
522 #[allow(unused_mut)]
523 let mut map = ::alloc::collections::BTreeMap::new();
524 map.insert(
525 ::jacquard_common::smol_str::SmolStr::new_static("avatar"),
526 ::jacquard_lexicon::lexicon::LexObjectProperty::Blob(::jacquard_lexicon::lexicon::LexBlob {
527 description: None,
528 accept: None,
529 max_size: None,
530 }),
531 );
532 map.insert(
533 ::jacquard_common::smol_str::SmolStr::new_static(
534 "createdAt",
535 ),
536 ::jacquard_lexicon::lexicon::LexObjectProperty::String(::jacquard_lexicon::lexicon::LexString {
537 description: None,
538 format: Some(
539 ::jacquard_lexicon::lexicon::LexStringFormat::Datetime,
540 ),
541 default: None,
542 min_length: None,
543 max_length: None,
544 min_graphemes: None,
545 max_graphemes: None,
546 r#enum: None,
547 r#const: None,
548 known_values: None,
549 }),
550 );
551 map.insert(
552 ::jacquard_common::smol_str::SmolStr::new_static(
553 "description",
554 ),
555 ::jacquard_lexicon::lexicon::LexObjectProperty::String(::jacquard_lexicon::lexicon::LexString {
556 description: None,
557 format: None,
558 default: None,
559 min_length: None,
560 max_length: Some(3000usize),
561 min_graphemes: None,
562 max_graphemes: Some(300usize),
563 r#enum: None,
564 r#const: None,
565 known_values: None,
566 }),
567 );
568 map.insert(
569 ::jacquard_common::smol_str::SmolStr::new_static("name"),
570 ::jacquard_lexicon::lexicon::LexObjectProperty::String(::jacquard_lexicon::lexicon::LexString {
571 description: Some(
572 ::jacquard_common::CowStr::new_static(
573 "Display name for the list.",
574 ),
575 ),
576 format: None,
577 default: None,
578 min_length: Some(1usize),
579 max_length: Some(64usize),
580 min_graphemes: None,
581 max_graphemes: None,
582 r#enum: None,
583 r#const: None,
584 known_values: None,
585 }),
586 );
587 map.insert(
588 ::jacquard_common::smol_str::SmolStr::new_static("purpose"),
589 ::jacquard_lexicon::lexicon::LexObjectProperty::Ref(::jacquard_lexicon::lexicon::LexRef {
590 description: None,
591 r#ref: ::jacquard_common::CowStr::new_static("#listPurpose"),
592 }),
593 );
594 map
595 },
596 }),
597 }),
598 );
599 map
600 },
601 }
602}