atproto blogging
1// @generated by jacquard-lexicon. DO NOT EDIT.
2//
3// Lexicon: sh.weaver.graph.bookmark
4//
5// This file was automatically generated from Lexicon schemas.
6// Any manual changes will be overwritten on the next regeneration.
7
8/// Bookmark a notebook or entry for later reading.
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 Bookmark<'a> {
21 pub created_at: jacquard_common::types::string::Datetime,
22 /// Optional private note about why you saved this.
23 #[serde(skip_serializing_if = "std::option::Option::is_none")]
24 #[serde(borrow)]
25 pub note: std::option::Option<jacquard_common::CowStr<'a>>,
26 /// The notebook or entry being bookmarked.
27 #[serde(borrow)]
28 pub subject: crate::com_atproto::repo::strong_ref::StrongRef<'a>,
29}
30
31pub mod bookmark_state {
32
33 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
34 #[allow(unused)]
35 use ::core::marker::PhantomData;
36 mod sealed {
37 pub trait Sealed {}
38 }
39 /// State trait tracking which required fields have been set
40 pub trait State: sealed::Sealed {
41 type Subject;
42 type CreatedAt;
43 }
44 /// Empty state - all required fields are unset
45 pub struct Empty(());
46 impl sealed::Sealed for Empty {}
47 impl State for Empty {
48 type Subject = Unset;
49 type CreatedAt = Unset;
50 }
51 ///State transition - sets the `subject` field to Set
52 pub struct SetSubject<S: State = Empty>(PhantomData<fn() -> S>);
53 impl<S: State> sealed::Sealed for SetSubject<S> {}
54 impl<S: State> State for SetSubject<S> {
55 type Subject = Set<members::subject>;
56 type CreatedAt = S::CreatedAt;
57 }
58 ///State transition - sets the `created_at` field to Set
59 pub struct SetCreatedAt<S: State = Empty>(PhantomData<fn() -> S>);
60 impl<S: State> sealed::Sealed for SetCreatedAt<S> {}
61 impl<S: State> State for SetCreatedAt<S> {
62 type Subject = S::Subject;
63 type CreatedAt = Set<members::created_at>;
64 }
65 /// Marker types for field names
66 #[allow(non_camel_case_types)]
67 pub mod members {
68 ///Marker type for the `subject` field
69 pub struct subject(());
70 ///Marker type for the `created_at` field
71 pub struct created_at(());
72 }
73}
74
75/// Builder for constructing an instance of this type
76pub struct BookmarkBuilder<'a, S: bookmark_state::State> {
77 _phantom_state: ::core::marker::PhantomData<fn() -> S>,
78 __unsafe_private_named: (
79 ::core::option::Option<jacquard_common::types::string::Datetime>,
80 ::core::option::Option<jacquard_common::CowStr<'a>>,
81 ::core::option::Option<crate::com_atproto::repo::strong_ref::StrongRef<'a>>,
82 ),
83 _phantom: ::core::marker::PhantomData<&'a ()>,
84}
85
86impl<'a> Bookmark<'a> {
87 /// Create a new builder for this type
88 pub fn new() -> BookmarkBuilder<'a, bookmark_state::Empty> {
89 BookmarkBuilder::new()
90 }
91}
92
93impl<'a> BookmarkBuilder<'a, bookmark_state::Empty> {
94 /// Create a new builder with all fields unset
95 pub fn new() -> Self {
96 BookmarkBuilder {
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> BookmarkBuilder<'a, S>
105where
106 S: bookmark_state::State,
107 S::CreatedAt: bookmark_state::IsUnset,
108{
109 /// Set the `createdAt` field (required)
110 pub fn created_at(
111 mut self,
112 value: impl Into<jacquard_common::types::string::Datetime>,
113 ) -> BookmarkBuilder<'a, bookmark_state::SetCreatedAt<S>> {
114 self.__unsafe_private_named.0 = ::core::option::Option::Some(value.into());
115 BookmarkBuilder {
116 _phantom_state: ::core::marker::PhantomData,
117 __unsafe_private_named: self.__unsafe_private_named,
118 _phantom: ::core::marker::PhantomData,
119 }
120 }
121}
122
123impl<'a, S: bookmark_state::State> BookmarkBuilder<'a, S> {
124 /// Set the `note` field (optional)
125 pub fn note(
126 mut self,
127 value: impl Into<Option<jacquard_common::CowStr<'a>>>,
128 ) -> Self {
129 self.__unsafe_private_named.1 = value.into();
130 self
131 }
132 /// Set the `note` field to an Option value (optional)
133 pub fn maybe_note(mut self, value: Option<jacquard_common::CowStr<'a>>) -> Self {
134 self.__unsafe_private_named.1 = value;
135 self
136 }
137}
138
139impl<'a, S> BookmarkBuilder<'a, S>
140where
141 S: bookmark_state::State,
142 S::Subject: bookmark_state::IsUnset,
143{
144 /// Set the `subject` field (required)
145 pub fn subject(
146 mut self,
147 value: impl Into<crate::com_atproto::repo::strong_ref::StrongRef<'a>>,
148 ) -> BookmarkBuilder<'a, bookmark_state::SetSubject<S>> {
149 self.__unsafe_private_named.2 = ::core::option::Option::Some(value.into());
150 BookmarkBuilder {
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> BookmarkBuilder<'a, S>
159where
160 S: bookmark_state::State,
161 S::Subject: bookmark_state::IsSet,
162 S::CreatedAt: bookmark_state::IsSet,
163{
164 /// Build the final struct
165 pub fn build(self) -> Bookmark<'a> {
166 Bookmark {
167 created_at: self.__unsafe_private_named.0.unwrap(),
168 note: self.__unsafe_private_named.1,
169 subject: self.__unsafe_private_named.2.unwrap(),
170 extra_data: Default::default(),
171 }
172 }
173 /// Build the final struct with custom extra_data
174 pub fn build_with_data(
175 self,
176 extra_data: std::collections::BTreeMap<
177 jacquard_common::smol_str::SmolStr,
178 jacquard_common::types::value::Data<'a>,
179 >,
180 ) -> Bookmark<'a> {
181 Bookmark {
182 created_at: self.__unsafe_private_named.0.unwrap(),
183 note: self.__unsafe_private_named.1,
184 subject: self.__unsafe_private_named.2.unwrap(),
185 extra_data: Some(extra_data),
186 }
187 }
188}
189
190impl<'a> Bookmark<'a> {
191 pub fn uri(
192 uri: impl Into<jacquard_common::CowStr<'a>>,
193 ) -> Result<
194 jacquard_common::types::uri::RecordUri<'a, BookmarkRecord>,
195 jacquard_common::types::uri::UriError,
196 > {
197 jacquard_common::types::uri::RecordUri::try_from_uri(
198 jacquard_common::types::string::AtUri::new_cow(uri.into())?,
199 )
200 }
201}
202
203/// Typed wrapper for GetRecord response with this collection's record type.
204#[derive(
205 serde::Serialize,
206 serde::Deserialize,
207 Debug,
208 Clone,
209 PartialEq,
210 Eq,
211 jacquard_derive::IntoStatic
212)]
213#[serde(rename_all = "camelCase")]
214pub struct BookmarkGetRecordOutput<'a> {
215 #[serde(skip_serializing_if = "std::option::Option::is_none")]
216 #[serde(borrow)]
217 pub cid: std::option::Option<jacquard_common::types::string::Cid<'a>>,
218 #[serde(borrow)]
219 pub uri: jacquard_common::types::string::AtUri<'a>,
220 #[serde(borrow)]
221 pub value: Bookmark<'a>,
222}
223
224impl From<BookmarkGetRecordOutput<'_>> for Bookmark<'_> {
225 fn from(output: BookmarkGetRecordOutput<'_>) -> Self {
226 use jacquard_common::IntoStatic;
227 output.value.into_static()
228 }
229}
230
231impl jacquard_common::types::collection::Collection for Bookmark<'_> {
232 const NSID: &'static str = "sh.weaver.graph.bookmark";
233 type Record = BookmarkRecord;
234}
235
236/// Marker type for deserializing records from this collection.
237#[derive(Debug, serde::Serialize, serde::Deserialize)]
238pub struct BookmarkRecord;
239impl jacquard_common::xrpc::XrpcResp for BookmarkRecord {
240 const NSID: &'static str = "sh.weaver.graph.bookmark";
241 const ENCODING: &'static str = "application/json";
242 type Output<'de> = BookmarkGetRecordOutput<'de>;
243 type Err<'de> = jacquard_common::types::collection::RecordError<'de>;
244}
245
246impl jacquard_common::types::collection::Collection for BookmarkRecord {
247 const NSID: &'static str = "sh.weaver.graph.bookmark";
248 type Record = BookmarkRecord;
249}
250
251impl<'a> ::jacquard_lexicon::schema::LexiconSchema for Bookmark<'a> {
252 fn nsid() -> &'static str {
253 "sh.weaver.graph.bookmark"
254 }
255 fn def_name() -> &'static str {
256 "main"
257 }
258 fn lexicon_doc() -> ::jacquard_lexicon::lexicon::LexiconDoc<'static> {
259 lexicon_doc_sh_weaver_graph_bookmark()
260 }
261 fn validate(
262 &self,
263 ) -> ::core::result::Result<(), ::jacquard_lexicon::validation::ConstraintError> {
264 if let Some(ref value) = self.note {
265 #[allow(unused_comparisons)]
266 if <str>::len(value.as_ref()) > 3000usize {
267 return Err(::jacquard_lexicon::validation::ConstraintError::MaxLength {
268 path: ::jacquard_lexicon::validation::ValidationPath::from_field(
269 "note",
270 ),
271 max: 3000usize,
272 actual: <str>::len(value.as_ref()),
273 });
274 }
275 }
276 if let Some(ref value) = self.note {
277 {
278 let count = ::unicode_segmentation::UnicodeSegmentation::graphemes(
279 value.as_ref(),
280 true,
281 )
282 .count();
283 if count > 300usize {
284 return Err(::jacquard_lexicon::validation::ConstraintError::MaxGraphemes {
285 path: ::jacquard_lexicon::validation::ValidationPath::from_field(
286 "note",
287 ),
288 max: 300usize,
289 actual: count,
290 });
291 }
292 }
293 }
294 Ok(())
295 }
296}
297
298fn lexicon_doc_sh_weaver_graph_bookmark() -> ::jacquard_lexicon::lexicon::LexiconDoc<
299 'static,
300> {
301 ::jacquard_lexicon::lexicon::LexiconDoc {
302 lexicon: ::jacquard_lexicon::lexicon::Lexicon::Lexicon1,
303 id: ::jacquard_common::CowStr::new_static("sh.weaver.graph.bookmark"),
304 revision: None,
305 description: None,
306 defs: {
307 let mut map = ::alloc::collections::BTreeMap::new();
308 map.insert(
309 ::jacquard_common::smol_str::SmolStr::new_static("main"),
310 ::jacquard_lexicon::lexicon::LexUserType::Record(::jacquard_lexicon::lexicon::LexRecord {
311 description: Some(
312 ::jacquard_common::CowStr::new_static(
313 "Bookmark a notebook or entry for later reading.",
314 ),
315 ),
316 key: Some(::jacquard_common::CowStr::new_static("tid")),
317 record: ::jacquard_lexicon::lexicon::LexRecordRecord::Object(::jacquard_lexicon::lexicon::LexObject {
318 description: None,
319 required: Some(
320 vec![
321 ::jacquard_common::smol_str::SmolStr::new_static("subject"),
322 ::jacquard_common::smol_str::SmolStr::new_static("createdAt")
323 ],
324 ),
325 nullable: None,
326 properties: {
327 #[allow(unused_mut)]
328 let mut map = ::alloc::collections::BTreeMap::new();
329 map.insert(
330 ::jacquard_common::smol_str::SmolStr::new_static(
331 "createdAt",
332 ),
333 ::jacquard_lexicon::lexicon::LexObjectProperty::String(::jacquard_lexicon::lexicon::LexString {
334 description: None,
335 format: Some(
336 ::jacquard_lexicon::lexicon::LexStringFormat::Datetime,
337 ),
338 default: None,
339 min_length: None,
340 max_length: None,
341 min_graphemes: None,
342 max_graphemes: None,
343 r#enum: None,
344 r#const: None,
345 known_values: None,
346 }),
347 );
348 map.insert(
349 ::jacquard_common::smol_str::SmolStr::new_static("note"),
350 ::jacquard_lexicon::lexicon::LexObjectProperty::String(::jacquard_lexicon::lexicon::LexString {
351 description: Some(
352 ::jacquard_common::CowStr::new_static(
353 "Optional private note about why you saved this.",
354 ),
355 ),
356 format: None,
357 default: None,
358 min_length: None,
359 max_length: Some(3000usize),
360 min_graphemes: None,
361 max_graphemes: Some(300usize),
362 r#enum: None,
363 r#const: None,
364 known_values: None,
365 }),
366 );
367 map.insert(
368 ::jacquard_common::smol_str::SmolStr::new_static("subject"),
369 ::jacquard_lexicon::lexicon::LexObjectProperty::Ref(::jacquard_lexicon::lexicon::LexRef {
370 description: None,
371 r#ref: ::jacquard_common::CowStr::new_static(
372 "com.atproto.repo.strongRef",
373 ),
374 }),
375 );
376 map
377 },
378 }),
379 }),
380 );
381 map
382 },
383 }
384}