Skip to main content

jacquard_api/place_stream/
multistream.rs

1// @generated by jacquard-lexicon. DO NOT EDIT.
2//
3// Lexicon: place.stream.multistream.defs
4//
5// This file was automatically generated from Lexicon schemas.
6// Any manual changes will be overwritten on the next regeneration.
7
8pub mod create_target;
9pub mod delete_target;
10pub mod list_targets;
11pub mod put_target;
12pub mod target;
13
14
15#[allow(unused_imports)]
16use alloc::collections::BTreeMap;
17
18#[allow(unused_imports)]
19use core::marker::PhantomData;
20use jacquard_common::CowStr;
21
22#[allow(unused_imports)]
23use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
24use jacquard_common::types::string::{AtUri, Cid, Datetime};
25use jacquard_common::types::value::Data;
26use jacquard_derive::{IntoStatic, lexicon};
27use jacquard_lexicon::lexicon::LexiconDoc;
28use jacquard_lexicon::schema::LexiconSchema;
29
30#[allow(unused_imports)]
31use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
32use serde::{Serialize, Deserialize};
33use crate::place_stream::multistream;
34
35#[lexicon]
36#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
37#[serde(rename_all = "camelCase")]
38pub struct Event<'a> {
39    pub created_at: Datetime,
40    #[serde(borrow)]
41    pub message: CowStr<'a>,
42    #[serde(borrow)]
43    pub status: CowStr<'a>,
44}
45
46
47#[lexicon]
48#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
49#[serde(rename_all = "camelCase")]
50pub struct TargetView<'a> {
51    #[serde(borrow)]
52    pub cid: Cid<'a>,
53    #[serde(skip_serializing_if = "Option::is_none")]
54    #[serde(borrow)]
55    pub latest_event: Option<multistream::Event<'a>>,
56    #[serde(borrow)]
57    pub record: Data<'a>,
58    #[serde(borrow)]
59    pub uri: AtUri<'a>,
60}
61
62impl<'a> LexiconSchema for Event<'a> {
63    fn nsid() -> &'static str {
64        "place.stream.multistream.defs"
65    }
66    fn def_name() -> &'static str {
67        "event"
68    }
69    fn lexicon_doc() -> LexiconDoc<'static> {
70        lexicon_doc_place_stream_multistream_defs()
71    }
72    fn validate(&self) -> Result<(), ConstraintError> {
73        Ok(())
74    }
75}
76
77impl<'a> LexiconSchema for TargetView<'a> {
78    fn nsid() -> &'static str {
79        "place.stream.multistream.defs"
80    }
81    fn def_name() -> &'static str {
82        "targetView"
83    }
84    fn lexicon_doc() -> LexiconDoc<'static> {
85        lexicon_doc_place_stream_multistream_defs()
86    }
87    fn validate(&self) -> Result<(), ConstraintError> {
88        Ok(())
89    }
90}
91
92pub mod event_state {
93
94    pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
95    #[allow(unused)]
96    use ::core::marker::PhantomData;
97    mod sealed {
98        pub trait Sealed {}
99    }
100    /// State trait tracking which required fields have been set
101    pub trait State: sealed::Sealed {
102        type CreatedAt;
103        type Message;
104        type Status;
105    }
106    /// Empty state - all required fields are unset
107    pub struct Empty(());
108    impl sealed::Sealed for Empty {}
109    impl State for Empty {
110        type CreatedAt = Unset;
111        type Message = Unset;
112        type Status = Unset;
113    }
114    ///State transition - sets the `created_at` field to Set
115    pub struct SetCreatedAt<S: State = Empty>(PhantomData<fn() -> S>);
116    impl<S: State> sealed::Sealed for SetCreatedAt<S> {}
117    impl<S: State> State for SetCreatedAt<S> {
118        type CreatedAt = Set<members::created_at>;
119        type Message = S::Message;
120        type Status = S::Status;
121    }
122    ///State transition - sets the `message` field to Set
123    pub struct SetMessage<S: State = Empty>(PhantomData<fn() -> S>);
124    impl<S: State> sealed::Sealed for SetMessage<S> {}
125    impl<S: State> State for SetMessage<S> {
126        type CreatedAt = S::CreatedAt;
127        type Message = Set<members::message>;
128        type Status = S::Status;
129    }
130    ///State transition - sets the `status` field to Set
131    pub struct SetStatus<S: State = Empty>(PhantomData<fn() -> S>);
132    impl<S: State> sealed::Sealed for SetStatus<S> {}
133    impl<S: State> State for SetStatus<S> {
134        type CreatedAt = S::CreatedAt;
135        type Message = S::Message;
136        type Status = Set<members::status>;
137    }
138    /// Marker types for field names
139    #[allow(non_camel_case_types)]
140    pub mod members {
141        ///Marker type for the `created_at` field
142        pub struct created_at(());
143        ///Marker type for the `message` field
144        pub struct message(());
145        ///Marker type for the `status` field
146        pub struct status(());
147    }
148}
149
150/// Builder for constructing an instance of this type
151pub struct EventBuilder<'a, S: event_state::State> {
152    _state: PhantomData<fn() -> S>,
153    _fields: (Option<Datetime>, Option<CowStr<'a>>, Option<CowStr<'a>>),
154    _lifetime: PhantomData<&'a ()>,
155}
156
157impl<'a> Event<'a> {
158    /// Create a new builder for this type
159    pub fn new() -> EventBuilder<'a, event_state::Empty> {
160        EventBuilder::new()
161    }
162}
163
164impl<'a> EventBuilder<'a, event_state::Empty> {
165    /// Create a new builder with all fields unset
166    pub fn new() -> Self {
167        EventBuilder {
168            _state: PhantomData,
169            _fields: (None, None, None),
170            _lifetime: PhantomData,
171        }
172    }
173}
174
175impl<'a, S> EventBuilder<'a, S>
176where
177    S: event_state::State,
178    S::CreatedAt: event_state::IsUnset,
179{
180    /// Set the `createdAt` field (required)
181    pub fn created_at(
182        mut self,
183        value: impl Into<Datetime>,
184    ) -> EventBuilder<'a, event_state::SetCreatedAt<S>> {
185        self._fields.0 = Option::Some(value.into());
186        EventBuilder {
187            _state: PhantomData,
188            _fields: self._fields,
189            _lifetime: PhantomData,
190        }
191    }
192}
193
194impl<'a, S> EventBuilder<'a, S>
195where
196    S: event_state::State,
197    S::Message: event_state::IsUnset,
198{
199    /// Set the `message` field (required)
200    pub fn message(
201        mut self,
202        value: impl Into<CowStr<'a>>,
203    ) -> EventBuilder<'a, event_state::SetMessage<S>> {
204        self._fields.1 = Option::Some(value.into());
205        EventBuilder {
206            _state: PhantomData,
207            _fields: self._fields,
208            _lifetime: PhantomData,
209        }
210    }
211}
212
213impl<'a, S> EventBuilder<'a, S>
214where
215    S: event_state::State,
216    S::Status: event_state::IsUnset,
217{
218    /// Set the `status` field (required)
219    pub fn status(
220        mut self,
221        value: impl Into<CowStr<'a>>,
222    ) -> EventBuilder<'a, event_state::SetStatus<S>> {
223        self._fields.2 = Option::Some(value.into());
224        EventBuilder {
225            _state: PhantomData,
226            _fields: self._fields,
227            _lifetime: PhantomData,
228        }
229    }
230}
231
232impl<'a, S> EventBuilder<'a, S>
233where
234    S: event_state::State,
235    S::CreatedAt: event_state::IsSet,
236    S::Message: event_state::IsSet,
237    S::Status: event_state::IsSet,
238{
239    /// Build the final struct
240    pub fn build(self) -> Event<'a> {
241        Event {
242            created_at: self._fields.0.unwrap(),
243            message: self._fields.1.unwrap(),
244            status: self._fields.2.unwrap(),
245            extra_data: Default::default(),
246        }
247    }
248    /// Build the final struct with custom extra_data
249    pub fn build_with_data(
250        self,
251        extra_data: BTreeMap<jacquard_common::deps::smol_str::SmolStr, Data<'a>>,
252    ) -> Event<'a> {
253        Event {
254            created_at: self._fields.0.unwrap(),
255            message: self._fields.1.unwrap(),
256            status: self._fields.2.unwrap(),
257            extra_data: Some(extra_data),
258        }
259    }
260}
261
262fn lexicon_doc_place_stream_multistream_defs() -> LexiconDoc<'static> {
263    #[allow(unused_imports)]
264    use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
265    use jacquard_lexicon::lexicon::*;
266    use alloc::collections::BTreeMap;
267    LexiconDoc {
268        lexicon: Lexicon::Lexicon1,
269        id: CowStr::new_static("place.stream.multistream.defs"),
270        defs: {
271            let mut map = BTreeMap::new();
272            map.insert(
273                SmolStr::new_static("event"),
274                LexUserType::Object(LexObject {
275                    required: Some(
276                        vec![
277                            SmolStr::new_static("message"),
278                            SmolStr::new_static("status"),
279                            SmolStr::new_static("createdAt")
280                        ],
281                    ),
282                    properties: {
283                        #[allow(unused_mut)]
284                        let mut map = BTreeMap::new();
285                        map.insert(
286                            SmolStr::new_static("createdAt"),
287                            LexObjectProperty::String(LexString {
288                                format: Some(LexStringFormat::Datetime),
289                                ..Default::default()
290                            }),
291                        );
292                        map.insert(
293                            SmolStr::new_static("message"),
294                            LexObjectProperty::String(LexString { ..Default::default() }),
295                        );
296                        map.insert(
297                            SmolStr::new_static("status"),
298                            LexObjectProperty::String(LexString { ..Default::default() }),
299                        );
300                        map
301                    },
302                    ..Default::default()
303                }),
304            );
305            map.insert(
306                SmolStr::new_static("targetView"),
307                LexUserType::Object(LexObject {
308                    required: Some(
309                        vec![
310                            SmolStr::new_static("uri"), SmolStr::new_static("cid"),
311                            SmolStr::new_static("record")
312                        ],
313                    ),
314                    properties: {
315                        #[allow(unused_mut)]
316                        let mut map = BTreeMap::new();
317                        map.insert(
318                            SmolStr::new_static("cid"),
319                            LexObjectProperty::String(LexString {
320                                format: Some(LexStringFormat::Cid),
321                                ..Default::default()
322                            }),
323                        );
324                        map.insert(
325                            SmolStr::new_static("latestEvent"),
326                            LexObjectProperty::Ref(LexRef {
327                                r#ref: CowStr::new_static(
328                                    "place.stream.multistream.defs#event",
329                                ),
330                                ..Default::default()
331                            }),
332                        );
333                        map.insert(
334                            SmolStr::new_static("record"),
335                            LexObjectProperty::Unknown(LexUnknown {
336                                ..Default::default()
337                            }),
338                        );
339                        map.insert(
340                            SmolStr::new_static("uri"),
341                            LexObjectProperty::String(LexString {
342                                format: Some(LexStringFormat::AtUri),
343                                ..Default::default()
344                            }),
345                        );
346                        map
347                    },
348                    ..Default::default()
349                }),
350            );
351            map
352        },
353        ..Default::default()
354    }
355}
356
357pub mod target_view_state {
358
359    pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
360    #[allow(unused)]
361    use ::core::marker::PhantomData;
362    mod sealed {
363        pub trait Sealed {}
364    }
365    /// State trait tracking which required fields have been set
366    pub trait State: sealed::Sealed {
367        type Record;
368        type Uri;
369        type Cid;
370    }
371    /// Empty state - all required fields are unset
372    pub struct Empty(());
373    impl sealed::Sealed for Empty {}
374    impl State for Empty {
375        type Record = Unset;
376        type Uri = Unset;
377        type Cid = Unset;
378    }
379    ///State transition - sets the `record` field to Set
380    pub struct SetRecord<S: State = Empty>(PhantomData<fn() -> S>);
381    impl<S: State> sealed::Sealed for SetRecord<S> {}
382    impl<S: State> State for SetRecord<S> {
383        type Record = Set<members::record>;
384        type Uri = S::Uri;
385        type Cid = S::Cid;
386    }
387    ///State transition - sets the `uri` field to Set
388    pub struct SetUri<S: State = Empty>(PhantomData<fn() -> S>);
389    impl<S: State> sealed::Sealed for SetUri<S> {}
390    impl<S: State> State for SetUri<S> {
391        type Record = S::Record;
392        type Uri = Set<members::uri>;
393        type Cid = S::Cid;
394    }
395    ///State transition - sets the `cid` field to Set
396    pub struct SetCid<S: State = Empty>(PhantomData<fn() -> S>);
397    impl<S: State> sealed::Sealed for SetCid<S> {}
398    impl<S: State> State for SetCid<S> {
399        type Record = S::Record;
400        type Uri = S::Uri;
401        type Cid = Set<members::cid>;
402    }
403    /// Marker types for field names
404    #[allow(non_camel_case_types)]
405    pub mod members {
406        ///Marker type for the `record` field
407        pub struct record(());
408        ///Marker type for the `uri` field
409        pub struct uri(());
410        ///Marker type for the `cid` field
411        pub struct cid(());
412    }
413}
414
415/// Builder for constructing an instance of this type
416pub struct TargetViewBuilder<'a, S: target_view_state::State> {
417    _state: PhantomData<fn() -> S>,
418    _fields: (
419        Option<Cid<'a>>,
420        Option<multistream::Event<'a>>,
421        Option<Data<'a>>,
422        Option<AtUri<'a>>,
423    ),
424    _lifetime: PhantomData<&'a ()>,
425}
426
427impl<'a> TargetView<'a> {
428    /// Create a new builder for this type
429    pub fn new() -> TargetViewBuilder<'a, target_view_state::Empty> {
430        TargetViewBuilder::new()
431    }
432}
433
434impl<'a> TargetViewBuilder<'a, target_view_state::Empty> {
435    /// Create a new builder with all fields unset
436    pub fn new() -> Self {
437        TargetViewBuilder {
438            _state: PhantomData,
439            _fields: (None, None, None, None),
440            _lifetime: PhantomData,
441        }
442    }
443}
444
445impl<'a, S> TargetViewBuilder<'a, S>
446where
447    S: target_view_state::State,
448    S::Cid: target_view_state::IsUnset,
449{
450    /// Set the `cid` field (required)
451    pub fn cid(
452        mut self,
453        value: impl Into<Cid<'a>>,
454    ) -> TargetViewBuilder<'a, target_view_state::SetCid<S>> {
455        self._fields.0 = Option::Some(value.into());
456        TargetViewBuilder {
457            _state: PhantomData,
458            _fields: self._fields,
459            _lifetime: PhantomData,
460        }
461    }
462}
463
464impl<'a, S: target_view_state::State> TargetViewBuilder<'a, S> {
465    /// Set the `latestEvent` field (optional)
466    pub fn latest_event(
467        mut self,
468        value: impl Into<Option<multistream::Event<'a>>>,
469    ) -> Self {
470        self._fields.1 = value.into();
471        self
472    }
473    /// Set the `latestEvent` field to an Option value (optional)
474    pub fn maybe_latest_event(mut self, value: Option<multistream::Event<'a>>) -> Self {
475        self._fields.1 = value;
476        self
477    }
478}
479
480impl<'a, S> TargetViewBuilder<'a, S>
481where
482    S: target_view_state::State,
483    S::Record: target_view_state::IsUnset,
484{
485    /// Set the `record` field (required)
486    pub fn record(
487        mut self,
488        value: impl Into<Data<'a>>,
489    ) -> TargetViewBuilder<'a, target_view_state::SetRecord<S>> {
490        self._fields.2 = Option::Some(value.into());
491        TargetViewBuilder {
492            _state: PhantomData,
493            _fields: self._fields,
494            _lifetime: PhantomData,
495        }
496    }
497}
498
499impl<'a, S> TargetViewBuilder<'a, S>
500where
501    S: target_view_state::State,
502    S::Uri: target_view_state::IsUnset,
503{
504    /// Set the `uri` field (required)
505    pub fn uri(
506        mut self,
507        value: impl Into<AtUri<'a>>,
508    ) -> TargetViewBuilder<'a, target_view_state::SetUri<S>> {
509        self._fields.3 = Option::Some(value.into());
510        TargetViewBuilder {
511            _state: PhantomData,
512            _fields: self._fields,
513            _lifetime: PhantomData,
514        }
515    }
516}
517
518impl<'a, S> TargetViewBuilder<'a, S>
519where
520    S: target_view_state::State,
521    S::Record: target_view_state::IsSet,
522    S::Uri: target_view_state::IsSet,
523    S::Cid: target_view_state::IsSet,
524{
525    /// Build the final struct
526    pub fn build(self) -> TargetView<'a> {
527        TargetView {
528            cid: self._fields.0.unwrap(),
529            latest_event: self._fields.1,
530            record: self._fields.2.unwrap(),
531            uri: self._fields.3.unwrap(),
532            extra_data: Default::default(),
533        }
534    }
535    /// Build the final struct with custom extra_data
536    pub fn build_with_data(
537        self,
538        extra_data: BTreeMap<jacquard_common::deps::smol_str::SmolStr, Data<'a>>,
539    ) -> TargetView<'a> {
540        TargetView {
541            cid: self._fields.0.unwrap(),
542            latest_event: self._fields.1,
543            record: self._fields.2.unwrap(),
544            uri: self._fields.3.unwrap(),
545            extra_data: Some(extra_data),
546        }
547    }
548}