Skip to main content

jacquard_api/app_bsky/feed/
postgate.rs

1// @generated by jacquard-lexicon. DO NOT EDIT.
2//
3// Lexicon: app.bsky.feed.postgate
4//
5// This file was automatically generated from Lexicon schemas.
6// Any manual changes will be overwritten on the next regeneration.
7
8#[allow(unused_imports)]
9use alloc::collections::BTreeMap;
10
11#[allow(unused_imports)]
12use core::marker::PhantomData;
13use jacquard_common::CowStr;
14
15#[allow(unused_imports)]
16use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
17use jacquard_common::types::collection::{Collection, RecordError};
18use jacquard_common::types::string::{AtUri, Cid, Datetime};
19use jacquard_common::types::uri::{RecordUri, UriError};
20use jacquard_common::xrpc::XrpcResp;
21use jacquard_derive::{IntoStatic, lexicon};
22use jacquard_lexicon::lexicon::LexiconDoc;
23use jacquard_lexicon::schema::LexiconSchema;
24
25#[allow(unused_imports)]
26use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
27use serde::{Serialize, Deserialize};
28use crate::app_bsky::feed::postgate;
29/// Disables embedding of this post.
30
31#[lexicon]
32#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
33#[serde(rename_all = "camelCase")]
34pub struct DisableRule<'a> {}
35/// Record defining interaction rules for a post. The record key (rkey) of the postgate record must match the record key of the post, and that record must be in the same repository.
36
37#[lexicon]
38#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
39#[serde(rename_all = "camelCase", rename = "app.bsky.feed.postgate", tag = "$type")]
40pub struct Postgate<'a> {
41    pub created_at: Datetime,
42    ///List of AT-URIs embedding this post that the author has detached from.
43    #[serde(skip_serializing_if = "Option::is_none")]
44    #[serde(borrow)]
45    pub detached_embedding_uris: Option<Vec<AtUri<'a>>>,
46    ///List of rules defining who can embed this post. If value is an empty array or is undefined, no particular rules apply and anyone can embed.
47    #[serde(skip_serializing_if = "Option::is_none")]
48    #[serde(borrow)]
49    pub embedding_rules: Option<Vec<postgate::DisableRule<'a>>>,
50    ///Reference (AT-URI) to the post record.
51    #[serde(borrow)]
52    pub post: AtUri<'a>,
53}
54
55/// Typed wrapper for GetRecord response with this collection's record type.
56
57#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
58#[serde(rename_all = "camelCase")]
59pub struct PostgateGetRecordOutput<'a> {
60    #[serde(skip_serializing_if = "Option::is_none")]
61    #[serde(borrow)]
62    pub cid: Option<Cid<'a>>,
63    #[serde(borrow)]
64    pub uri: AtUri<'a>,
65    #[serde(borrow)]
66    pub value: Postgate<'a>,
67}
68
69impl<'a> Postgate<'a> {
70    pub fn uri(
71        uri: impl Into<CowStr<'a>>,
72    ) -> Result<RecordUri<'a, PostgateRecord>, UriError> {
73        RecordUri::try_from_uri(AtUri::new_cow(uri.into())?)
74    }
75}
76
77impl<'a> LexiconSchema for DisableRule<'a> {
78    fn nsid() -> &'static str {
79        "app.bsky.feed.postgate"
80    }
81    fn def_name() -> &'static str {
82        "disableRule"
83    }
84    fn lexicon_doc() -> LexiconDoc<'static> {
85        lexicon_doc_app_bsky_feed_postgate()
86    }
87    fn validate(&self) -> Result<(), ConstraintError> {
88        Ok(())
89    }
90}
91
92/// Marker type for deserializing records from this collection.
93
94#[derive(Debug, Serialize, Deserialize)]
95pub struct PostgateRecord;
96impl XrpcResp for PostgateRecord {
97    const NSID: &'static str = "app.bsky.feed.postgate";
98    const ENCODING: &'static str = "application/json";
99    type Output<'de> = PostgateGetRecordOutput<'de>;
100    type Err<'de> = RecordError<'de>;
101}
102
103impl From<PostgateGetRecordOutput<'_>> for Postgate<'_> {
104    fn from(output: PostgateGetRecordOutput<'_>) -> Self {
105        use jacquard_common::IntoStatic;
106        output.value.into_static()
107    }
108}
109
110impl Collection for Postgate<'_> {
111    const NSID: &'static str = "app.bsky.feed.postgate";
112    type Record = PostgateRecord;
113}
114
115impl Collection for PostgateRecord {
116    const NSID: &'static str = "app.bsky.feed.postgate";
117    type Record = PostgateRecord;
118}
119
120impl<'a> LexiconSchema for Postgate<'a> {
121    fn nsid() -> &'static str {
122        "app.bsky.feed.postgate"
123    }
124    fn def_name() -> &'static str {
125        "main"
126    }
127    fn lexicon_doc() -> LexiconDoc<'static> {
128        lexicon_doc_app_bsky_feed_postgate()
129    }
130    fn validate(&self) -> Result<(), ConstraintError> {
131        if let Some(ref value) = self.detached_embedding_uris {
132            #[allow(unused_comparisons)]
133            if value.len() > 50usize {
134                return Err(ConstraintError::MaxLength {
135                    path: ValidationPath::from_field("detached_embedding_uris"),
136                    max: 50usize,
137                    actual: value.len(),
138                });
139            }
140        }
141        if let Some(ref value) = self.embedding_rules {
142            #[allow(unused_comparisons)]
143            if value.len() > 5usize {
144                return Err(ConstraintError::MaxLength {
145                    path: ValidationPath::from_field("embedding_rules"),
146                    max: 5usize,
147                    actual: value.len(),
148                });
149            }
150        }
151        Ok(())
152    }
153}
154
155fn lexicon_doc_app_bsky_feed_postgate() -> LexiconDoc<'static> {
156    #[allow(unused_imports)]
157    use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
158    use jacquard_lexicon::lexicon::*;
159    use alloc::collections::BTreeMap;
160    LexiconDoc {
161        lexicon: Lexicon::Lexicon1,
162        id: CowStr::new_static("app.bsky.feed.postgate"),
163        defs: {
164            let mut map = BTreeMap::new();
165            map.insert(
166                SmolStr::new_static("disableRule"),
167                LexUserType::Object(LexObject {
168                    description: Some(
169                        CowStr::new_static("Disables embedding of this post."),
170                    ),
171                    properties: {
172                        #[allow(unused_mut)]
173                        let mut map = BTreeMap::new();
174                        map
175                    },
176                    ..Default::default()
177                }),
178            );
179            map.insert(
180                SmolStr::new_static("main"),
181                LexUserType::Record(LexRecord {
182                    description: Some(
183                        CowStr::new_static(
184                            "Record defining interaction rules for a post. The record key (rkey) of the postgate record must match the record key of the post, and that record must be in the same repository.",
185                        ),
186                    ),
187                    key: Some(CowStr::new_static("tid")),
188                    record: LexRecordRecord::Object(LexObject {
189                        required: Some(
190                            vec![
191                                SmolStr::new_static("post"),
192                                SmolStr::new_static("createdAt")
193                            ],
194                        ),
195                        properties: {
196                            #[allow(unused_mut)]
197                            let mut map = BTreeMap::new();
198                            map.insert(
199                                SmolStr::new_static("createdAt"),
200                                LexObjectProperty::String(LexString {
201                                    format: Some(LexStringFormat::Datetime),
202                                    ..Default::default()
203                                }),
204                            );
205                            map.insert(
206                                SmolStr::new_static("detachedEmbeddingUris"),
207                                LexObjectProperty::Array(LexArray {
208                                    description: Some(
209                                        CowStr::new_static(
210                                            "List of AT-URIs embedding this post that the author has detached from.",
211                                        ),
212                                    ),
213                                    items: LexArrayItem::String(LexString {
214                                        format: Some(LexStringFormat::AtUri),
215                                        ..Default::default()
216                                    }),
217                                    max_length: Some(50usize),
218                                    ..Default::default()
219                                }),
220                            );
221                            map.insert(
222                                SmolStr::new_static("embeddingRules"),
223                                LexObjectProperty::Array(LexArray {
224                                    description: Some(
225                                        CowStr::new_static(
226                                            "List of rules defining who can embed this post. If value is an empty array or is undefined, no particular rules apply and anyone can embed.",
227                                        ),
228                                    ),
229                                    items: LexArrayItem::Union(LexRefUnion {
230                                        refs: vec![CowStr::new_static("#disableRule")],
231                                        ..Default::default()
232                                    }),
233                                    max_length: Some(5usize),
234                                    ..Default::default()
235                                }),
236                            );
237                            map.insert(
238                                SmolStr::new_static("post"),
239                                LexObjectProperty::String(LexString {
240                                    description: Some(
241                                        CowStr::new_static("Reference (AT-URI) to the post record."),
242                                    ),
243                                    format: Some(LexStringFormat::AtUri),
244                                    ..Default::default()
245                                }),
246                            );
247                            map
248                        },
249                        ..Default::default()
250                    }),
251                    ..Default::default()
252                }),
253            );
254            map
255        },
256        ..Default::default()
257    }
258}
259
260pub mod postgate_state {
261
262    pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
263    #[allow(unused)]
264    use ::core::marker::PhantomData;
265    mod sealed {
266        pub trait Sealed {}
267    }
268    /// State trait tracking which required fields have been set
269    pub trait State: sealed::Sealed {
270        type Post;
271        type CreatedAt;
272    }
273    /// Empty state - all required fields are unset
274    pub struct Empty(());
275    impl sealed::Sealed for Empty {}
276    impl State for Empty {
277        type Post = Unset;
278        type CreatedAt = Unset;
279    }
280    ///State transition - sets the `post` field to Set
281    pub struct SetPost<S: State = Empty>(PhantomData<fn() -> S>);
282    impl<S: State> sealed::Sealed for SetPost<S> {}
283    impl<S: State> State for SetPost<S> {
284        type Post = Set<members::post>;
285        type CreatedAt = S::CreatedAt;
286    }
287    ///State transition - sets the `created_at` field to Set
288    pub struct SetCreatedAt<S: State = Empty>(PhantomData<fn() -> S>);
289    impl<S: State> sealed::Sealed for SetCreatedAt<S> {}
290    impl<S: State> State for SetCreatedAt<S> {
291        type Post = S::Post;
292        type CreatedAt = Set<members::created_at>;
293    }
294    /// Marker types for field names
295    #[allow(non_camel_case_types)]
296    pub mod members {
297        ///Marker type for the `post` field
298        pub struct post(());
299        ///Marker type for the `created_at` field
300        pub struct created_at(());
301    }
302}
303
304/// Builder for constructing an instance of this type
305pub struct PostgateBuilder<'a, S: postgate_state::State> {
306    _state: PhantomData<fn() -> S>,
307    _fields: (
308        Option<Datetime>,
309        Option<Vec<AtUri<'a>>>,
310        Option<Vec<postgate::DisableRule<'a>>>,
311        Option<AtUri<'a>>,
312    ),
313    _lifetime: PhantomData<&'a ()>,
314}
315
316impl<'a> Postgate<'a> {
317    /// Create a new builder for this type
318    pub fn new() -> PostgateBuilder<'a, postgate_state::Empty> {
319        PostgateBuilder::new()
320    }
321}
322
323impl<'a> PostgateBuilder<'a, postgate_state::Empty> {
324    /// Create a new builder with all fields unset
325    pub fn new() -> Self {
326        PostgateBuilder {
327            _state: PhantomData,
328            _fields: (None, None, None, None),
329            _lifetime: PhantomData,
330        }
331    }
332}
333
334impl<'a, S> PostgateBuilder<'a, S>
335where
336    S: postgate_state::State,
337    S::CreatedAt: postgate_state::IsUnset,
338{
339    /// Set the `createdAt` field (required)
340    pub fn created_at(
341        mut self,
342        value: impl Into<Datetime>,
343    ) -> PostgateBuilder<'a, postgate_state::SetCreatedAt<S>> {
344        self._fields.0 = Option::Some(value.into());
345        PostgateBuilder {
346            _state: PhantomData,
347            _fields: self._fields,
348            _lifetime: PhantomData,
349        }
350    }
351}
352
353impl<'a, S: postgate_state::State> PostgateBuilder<'a, S> {
354    /// Set the `detachedEmbeddingUris` field (optional)
355    pub fn detached_embedding_uris(
356        mut self,
357        value: impl Into<Option<Vec<AtUri<'a>>>>,
358    ) -> Self {
359        self._fields.1 = value.into();
360        self
361    }
362    /// Set the `detachedEmbeddingUris` field to an Option value (optional)
363    pub fn maybe_detached_embedding_uris(
364        mut self,
365        value: Option<Vec<AtUri<'a>>>,
366    ) -> Self {
367        self._fields.1 = value;
368        self
369    }
370}
371
372impl<'a, S: postgate_state::State> PostgateBuilder<'a, S> {
373    /// Set the `embeddingRules` field (optional)
374    pub fn embedding_rules(
375        mut self,
376        value: impl Into<Option<Vec<postgate::DisableRule<'a>>>>,
377    ) -> Self {
378        self._fields.2 = value.into();
379        self
380    }
381    /// Set the `embeddingRules` field to an Option value (optional)
382    pub fn maybe_embedding_rules(
383        mut self,
384        value: Option<Vec<postgate::DisableRule<'a>>>,
385    ) -> Self {
386        self._fields.2 = value;
387        self
388    }
389}
390
391impl<'a, S> PostgateBuilder<'a, S>
392where
393    S: postgate_state::State,
394    S::Post: postgate_state::IsUnset,
395{
396    /// Set the `post` field (required)
397    pub fn post(
398        mut self,
399        value: impl Into<AtUri<'a>>,
400    ) -> PostgateBuilder<'a, postgate_state::SetPost<S>> {
401        self._fields.3 = Option::Some(value.into());
402        PostgateBuilder {
403            _state: PhantomData,
404            _fields: self._fields,
405            _lifetime: PhantomData,
406        }
407    }
408}
409
410impl<'a, S> PostgateBuilder<'a, S>
411where
412    S: postgate_state::State,
413    S::Post: postgate_state::IsSet,
414    S::CreatedAt: postgate_state::IsSet,
415{
416    /// Build the final struct
417    pub fn build(self) -> Postgate<'a> {
418        Postgate {
419            created_at: self._fields.0.unwrap(),
420            detached_embedding_uris: self._fields.1,
421            embedding_rules: self._fields.2,
422            post: self._fields.3.unwrap(),
423            extra_data: Default::default(),
424        }
425    }
426    /// Build the final struct with custom extra_data
427    pub fn build_with_data(
428        self,
429        extra_data: BTreeMap<
430            jacquard_common::deps::smol_str::SmolStr,
431            jacquard_common::types::value::Data<'a>,
432        >,
433    ) -> Postgate<'a> {
434        Postgate {
435            created_at: self._fields.0.unwrap(),
436            detached_embedding_uris: self._fields.1,
437            embedding_rules: self._fields.2,
438            post: self._fields.3.unwrap(),
439            extra_data: Some(extra_data),
440        }
441    }
442}