// @generated by jacquard-lexicon. DO NOT EDIT. // // Lexicon: my.skylights.rel // // This file was automatically generated from Lexicon schemas. // Any manual changes will be overwritten on the next regeneration. #[allow(unused_imports)] use alloc::collections::BTreeMap; #[allow(unused_imports)] use core::marker::PhantomData; use jacquard_common::CowStr; #[allow(unused_imports)] use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation; use jacquard_common::types::collection::{Collection, RecordError}; use jacquard_common::types::string::{AtUri, Cid, Datetime}; use jacquard_common::types::uri::{RecordUri, UriError}; use jacquard_common::xrpc::XrpcResp; use jacquard_derive::{IntoStatic, lexicon}; use jacquard_lexicon::lexicon::LexiconDoc; use jacquard_lexicon::schema::LexiconSchema; #[allow(unused_imports)] use jacquard_lexicon::validation::{ConstraintError, ValidationPath}; use serde::{Serialize, Deserialize}; use crate::my_skylights::Item; use crate::my_skylights::rel; #[lexicon] #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)] #[serde(rename_all = "camelCase")] pub struct Rel<'a> { #[serde(skip_serializing_if = "Option::is_none")] pub finished_at: Option>, #[serde(borrow)] pub item: Item<'a>, #[serde(skip_serializing_if = "Option::is_none")] #[serde(borrow)] pub note: Option>, #[serde(skip_serializing_if = "Option::is_none")] #[serde(borrow)] pub rating: Option>, } /// Typed wrapper for GetRecord response with this collection's record type. #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)] #[serde(rename_all = "camelCase")] pub struct RelGetRecordOutput<'a> { #[serde(skip_serializing_if = "Option::is_none")] #[serde(borrow)] pub cid: Option>, #[serde(borrow)] pub uri: AtUri<'a>, #[serde(borrow)] pub value: Rel<'a>, } #[lexicon] #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)] #[serde(rename_all = "camelCase")] pub struct Note<'a> { pub created_at: Datetime, pub updated_at: Datetime, #[serde(borrow)] pub value: CowStr<'a>, } #[lexicon] #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)] #[serde(rename_all = "camelCase")] pub struct Rating<'a> { pub created_at: Datetime, pub value: i64, } impl<'a> Rel<'a> { pub fn uri( uri: impl Into>, ) -> Result, UriError> { RecordUri::try_from_uri(AtUri::new_cow(uri.into())?) } } /// Marker type for deserializing records from this collection. #[derive(Debug, Serialize, Deserialize)] pub struct RelRecord; impl XrpcResp for RelRecord { const NSID: &'static str = "my.skylights.rel"; const ENCODING: &'static str = "application/json"; type Output<'de> = RelGetRecordOutput<'de>; type Err<'de> = RecordError<'de>; } impl From> for Rel<'_> { fn from(output: RelGetRecordOutput<'_>) -> Self { use jacquard_common::IntoStatic; output.value.into_static() } } impl Collection for Rel<'_> { const NSID: &'static str = "my.skylights.rel"; type Record = RelRecord; } impl Collection for RelRecord { const NSID: &'static str = "my.skylights.rel"; type Record = RelRecord; } impl<'a> LexiconSchema for Rel<'a> { fn nsid() -> &'static str { "my.skylights.rel" } fn def_name() -> &'static str { "main" } fn lexicon_doc() -> LexiconDoc<'static> { lexicon_doc_my_skylights_rel() } fn validate(&self) -> Result<(), ConstraintError> { Ok(()) } } impl<'a> LexiconSchema for Note<'a> { fn nsid() -> &'static str { "my.skylights.rel" } fn def_name() -> &'static str { "note" } fn lexicon_doc() -> LexiconDoc<'static> { lexicon_doc_my_skylights_rel() } fn validate(&self) -> Result<(), ConstraintError> { Ok(()) } } impl<'a> LexiconSchema for Rating<'a> { fn nsid() -> &'static str { "my.skylights.rel" } fn def_name() -> &'static str { "rating" } fn lexicon_doc() -> LexiconDoc<'static> { lexicon_doc_my_skylights_rel() } fn validate(&self) -> Result<(), ConstraintError> { { let value = &self.value; if *value > 10i64 { return Err(ConstraintError::Maximum { path: ValidationPath::from_field("value"), max: 10i64, actual: *value, }); } } { let value = &self.value; if *value < 1i64 { return Err(ConstraintError::Minimum { path: ValidationPath::from_field("value"), min: 1i64, actual: *value, }); } } Ok(()) } } pub mod rel_state { pub use crate::builder_types::{Set, Unset, IsSet, IsUnset}; #[allow(unused)] use ::core::marker::PhantomData; mod sealed { pub trait Sealed {} } /// State trait tracking which required fields have been set pub trait State: sealed::Sealed { type Item; } /// Empty state - all required fields are unset pub struct Empty(()); impl sealed::Sealed for Empty {} impl State for Empty { type Item = Unset; } ///State transition - sets the `item` field to Set pub struct SetItem(PhantomData S>); impl sealed::Sealed for SetItem {} impl State for SetItem { type Item = Set; } /// Marker types for field names #[allow(non_camel_case_types)] pub mod members { ///Marker type for the `item` field pub struct item(()); } } /// Builder for constructing an instance of this type pub struct RelBuilder<'a, S: rel_state::State> { _state: PhantomData S>, _fields: ( Option>, Option>, Option>, Option>, ), _lifetime: PhantomData<&'a ()>, } impl<'a> Rel<'a> { /// Create a new builder for this type pub fn new() -> RelBuilder<'a, rel_state::Empty> { RelBuilder::new() } } impl<'a> RelBuilder<'a, rel_state::Empty> { /// Create a new builder with all fields unset pub fn new() -> Self { RelBuilder { _state: PhantomData, _fields: (None, None, None, None), _lifetime: PhantomData, } } } impl<'a, S: rel_state::State> RelBuilder<'a, S> { /// Set the `finishedAt` field (optional) pub fn finished_at(mut self, value: impl Into>>) -> Self { self._fields.0 = value.into(); self } /// Set the `finishedAt` field to an Option value (optional) pub fn maybe_finished_at(mut self, value: Option>) -> Self { self._fields.0 = value; self } } impl<'a, S> RelBuilder<'a, S> where S: rel_state::State, S::Item: rel_state::IsUnset, { /// Set the `item` field (required) pub fn item( mut self, value: impl Into>, ) -> RelBuilder<'a, rel_state::SetItem> { self._fields.1 = Option::Some(value.into()); RelBuilder { _state: PhantomData, _fields: self._fields, _lifetime: PhantomData, } } } impl<'a, S: rel_state::State> RelBuilder<'a, S> { /// Set the `note` field (optional) pub fn note(mut self, value: impl Into>>) -> Self { self._fields.2 = value.into(); self } /// Set the `note` field to an Option value (optional) pub fn maybe_note(mut self, value: Option>) -> Self { self._fields.2 = value; self } } impl<'a, S: rel_state::State> RelBuilder<'a, S> { /// Set the `rating` field (optional) pub fn rating(mut self, value: impl Into>>) -> Self { self._fields.3 = value.into(); self } /// Set the `rating` field to an Option value (optional) pub fn maybe_rating(mut self, value: Option>) -> Self { self._fields.3 = value; self } } impl<'a, S> RelBuilder<'a, S> where S: rel_state::State, S::Item: rel_state::IsSet, { /// Build the final struct pub fn build(self) -> Rel<'a> { Rel { finished_at: self._fields.0, item: self._fields.1.unwrap(), note: self._fields.2, rating: self._fields.3, extra_data: Default::default(), } } /// Build the final struct with custom extra_data pub fn build_with_data( self, extra_data: BTreeMap< jacquard_common::deps::smol_str::SmolStr, jacquard_common::types::value::Data<'a>, >, ) -> Rel<'a> { Rel { finished_at: self._fields.0, item: self._fields.1.unwrap(), note: self._fields.2, rating: self._fields.3, extra_data: Some(extra_data), } } } fn lexicon_doc_my_skylights_rel() -> LexiconDoc<'static> { #[allow(unused_imports)] use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType}; use jacquard_lexicon::lexicon::*; use alloc::collections::BTreeMap; LexiconDoc { lexicon: Lexicon::Lexicon1, id: CowStr::new_static("my.skylights.rel"), defs: { let mut map = BTreeMap::new(); map.insert( SmolStr::new_static("main"), LexUserType::Record(LexRecord { key: Some(CowStr::new_static("tid")), record: LexRecordRecord::Object(LexObject { required: Some(vec![SmolStr::new_static("item")]), properties: { #[allow(unused_mut)] let mut map = BTreeMap::new(); map.insert( SmolStr::new_static("finishedAt"), LexObjectProperty::Array(LexArray { items: LexArrayItem::String(LexString { format: Some(LexStringFormat::Datetime), ..Default::default() }), ..Default::default() }), ); map.insert( SmolStr::new_static("item"), LexObjectProperty::Ref(LexRef { r#ref: CowStr::new_static("my.skylights.defs#item"), ..Default::default() }), ); map.insert( SmolStr::new_static("note"), LexObjectProperty::Ref(LexRef { r#ref: CowStr::new_static("#note"), ..Default::default() }), ); map.insert( SmolStr::new_static("rating"), LexObjectProperty::Ref(LexRef { r#ref: CowStr::new_static("#rating"), ..Default::default() }), ); map }, ..Default::default() }), ..Default::default() }), ); map.insert( SmolStr::new_static("note"), LexUserType::Object(LexObject { required: Some( vec![ SmolStr::new_static("value"), SmolStr::new_static("createdAt"), SmolStr::new_static("updatedAt") ], ), properties: { #[allow(unused_mut)] let mut map = BTreeMap::new(); map.insert( SmolStr::new_static("createdAt"), LexObjectProperty::String(LexString { format: Some(LexStringFormat::Datetime), ..Default::default() }), ); map.insert( SmolStr::new_static("updatedAt"), LexObjectProperty::String(LexString { format: Some(LexStringFormat::Datetime), ..Default::default() }), ); map.insert( SmolStr::new_static("value"), LexObjectProperty::String(LexString { ..Default::default() }), ); map }, ..Default::default() }), ); map.insert( SmolStr::new_static("rating"), LexUserType::Object(LexObject { required: Some( vec![ SmolStr::new_static("value"), SmolStr::new_static("createdAt") ], ), properties: { #[allow(unused_mut)] let mut map = BTreeMap::new(); map.insert( SmolStr::new_static("createdAt"), LexObjectProperty::String(LexString { format: Some(LexStringFormat::Datetime), ..Default::default() }), ); map.insert( SmolStr::new_static("value"), LexObjectProperty::Integer(LexInteger { minimum: Some(1i64), maximum: Some(10i64), ..Default::default() }), ); map }, ..Default::default() }), ); map }, ..Default::default() } } pub mod note_state { pub use crate::builder_types::{Set, Unset, IsSet, IsUnset}; #[allow(unused)] use ::core::marker::PhantomData; mod sealed { pub trait Sealed {} } /// State trait tracking which required fields have been set pub trait State: sealed::Sealed { type UpdatedAt; type CreatedAt; type Value; } /// Empty state - all required fields are unset pub struct Empty(()); impl sealed::Sealed for Empty {} impl State for Empty { type UpdatedAt = Unset; type CreatedAt = Unset; type Value = Unset; } ///State transition - sets the `updated_at` field to Set pub struct SetUpdatedAt(PhantomData S>); impl sealed::Sealed for SetUpdatedAt {} impl State for SetUpdatedAt { type UpdatedAt = Set; type CreatedAt = S::CreatedAt; type Value = S::Value; } ///State transition - sets the `created_at` field to Set pub struct SetCreatedAt(PhantomData S>); impl sealed::Sealed for SetCreatedAt {} impl State for SetCreatedAt { type UpdatedAt = S::UpdatedAt; type CreatedAt = Set; type Value = S::Value; } ///State transition - sets the `value` field to Set pub struct SetValue(PhantomData S>); impl sealed::Sealed for SetValue {} impl State for SetValue { type UpdatedAt = S::UpdatedAt; type CreatedAt = S::CreatedAt; type Value = Set; } /// Marker types for field names #[allow(non_camel_case_types)] pub mod members { ///Marker type for the `updated_at` field pub struct updated_at(()); ///Marker type for the `created_at` field pub struct created_at(()); ///Marker type for the `value` field pub struct value(()); } } /// Builder for constructing an instance of this type pub struct NoteBuilder<'a, S: note_state::State> { _state: PhantomData S>, _fields: (Option, Option, Option>), _lifetime: PhantomData<&'a ()>, } impl<'a> Note<'a> { /// Create a new builder for this type pub fn new() -> NoteBuilder<'a, note_state::Empty> { NoteBuilder::new() } } impl<'a> NoteBuilder<'a, note_state::Empty> { /// Create a new builder with all fields unset pub fn new() -> Self { NoteBuilder { _state: PhantomData, _fields: (None, None, None), _lifetime: PhantomData, } } } impl<'a, S> NoteBuilder<'a, S> where S: note_state::State, S::CreatedAt: note_state::IsUnset, { /// Set the `createdAt` field (required) pub fn created_at( mut self, value: impl Into, ) -> NoteBuilder<'a, note_state::SetCreatedAt> { self._fields.0 = Option::Some(value.into()); NoteBuilder { _state: PhantomData, _fields: self._fields, _lifetime: PhantomData, } } } impl<'a, S> NoteBuilder<'a, S> where S: note_state::State, S::UpdatedAt: note_state::IsUnset, { /// Set the `updatedAt` field (required) pub fn updated_at( mut self, value: impl Into, ) -> NoteBuilder<'a, note_state::SetUpdatedAt> { self._fields.1 = Option::Some(value.into()); NoteBuilder { _state: PhantomData, _fields: self._fields, _lifetime: PhantomData, } } } impl<'a, S> NoteBuilder<'a, S> where S: note_state::State, S::Value: note_state::IsUnset, { /// Set the `value` field (required) pub fn value( mut self, value: impl Into>, ) -> NoteBuilder<'a, note_state::SetValue> { self._fields.2 = Option::Some(value.into()); NoteBuilder { _state: PhantomData, _fields: self._fields, _lifetime: PhantomData, } } } impl<'a, S> NoteBuilder<'a, S> where S: note_state::State, S::UpdatedAt: note_state::IsSet, S::CreatedAt: note_state::IsSet, S::Value: note_state::IsSet, { /// Build the final struct pub fn build(self) -> Note<'a> { Note { created_at: self._fields.0.unwrap(), updated_at: self._fields.1.unwrap(), value: self._fields.2.unwrap(), extra_data: Default::default(), } } /// Build the final struct with custom extra_data pub fn build_with_data( self, extra_data: BTreeMap< jacquard_common::deps::smol_str::SmolStr, jacquard_common::types::value::Data<'a>, >, ) -> Note<'a> { Note { created_at: self._fields.0.unwrap(), updated_at: self._fields.1.unwrap(), value: self._fields.2.unwrap(), extra_data: Some(extra_data), } } } pub mod rating_state { pub use crate::builder_types::{Set, Unset, IsSet, IsUnset}; #[allow(unused)] use ::core::marker::PhantomData; mod sealed { pub trait Sealed {} } /// State trait tracking which required fields have been set pub trait State: sealed::Sealed { type CreatedAt; type Value; } /// Empty state - all required fields are unset pub struct Empty(()); impl sealed::Sealed for Empty {} impl State for Empty { type CreatedAt = Unset; type Value = Unset; } ///State transition - sets the `created_at` field to Set pub struct SetCreatedAt(PhantomData S>); impl sealed::Sealed for SetCreatedAt {} impl State for SetCreatedAt { type CreatedAt = Set; type Value = S::Value; } ///State transition - sets the `value` field to Set pub struct SetValue(PhantomData S>); impl sealed::Sealed for SetValue {} impl State for SetValue { type CreatedAt = S::CreatedAt; type Value = Set; } /// Marker types for field names #[allow(non_camel_case_types)] pub mod members { ///Marker type for the `created_at` field pub struct created_at(()); ///Marker type for the `value` field pub struct value(()); } } /// Builder for constructing an instance of this type pub struct RatingBuilder<'a, S: rating_state::State> { _state: PhantomData S>, _fields: (Option, Option), _lifetime: PhantomData<&'a ()>, } impl<'a> Rating<'a> { /// Create a new builder for this type pub fn new() -> RatingBuilder<'a, rating_state::Empty> { RatingBuilder::new() } } impl<'a> RatingBuilder<'a, rating_state::Empty> { /// Create a new builder with all fields unset pub fn new() -> Self { RatingBuilder { _state: PhantomData, _fields: (None, None), _lifetime: PhantomData, } } } impl<'a, S> RatingBuilder<'a, S> where S: rating_state::State, S::CreatedAt: rating_state::IsUnset, { /// Set the `createdAt` field (required) pub fn created_at( mut self, value: impl Into, ) -> RatingBuilder<'a, rating_state::SetCreatedAt> { self._fields.0 = Option::Some(value.into()); RatingBuilder { _state: PhantomData, _fields: self._fields, _lifetime: PhantomData, } } } impl<'a, S> RatingBuilder<'a, S> where S: rating_state::State, S::Value: rating_state::IsUnset, { /// Set the `value` field (required) pub fn value( mut self, value: impl Into, ) -> RatingBuilder<'a, rating_state::SetValue> { self._fields.1 = Option::Some(value.into()); RatingBuilder { _state: PhantomData, _fields: self._fields, _lifetime: PhantomData, } } } impl<'a, S> RatingBuilder<'a, S> where S: rating_state::State, S::CreatedAt: rating_state::IsSet, S::Value: rating_state::IsSet, { /// Build the final struct pub fn build(self) -> Rating<'a> { Rating { created_at: self._fields.0.unwrap(), value: self._fields.1.unwrap(), extra_data: Default::default(), } } /// Build the final struct with custom extra_data pub fn build_with_data( self, extra_data: BTreeMap< jacquard_common::deps::smol_str::SmolStr, jacquard_common::types::value::Data<'a>, >, ) -> Rating<'a> { Rating { created_at: self._fields.0.unwrap(), value: self._fields.1.unwrap(), extra_data: Some(extra_data), } } }