// @generated by jacquard-lexicon. DO NOT EDIT. // // Lexicon: buzz.bookhive.hiveBook // // 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::buzz_bookhive::BookIdentifiers; /// A book within the hive #[lexicon] #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)] #[serde(rename_all = "camelCase")] pub struct HiveBook<'a> { ///The authors of the book (tab separated) #[serde(borrow)] pub authors: CowStr<'a>, ///URL to full-size cover image #[serde(skip_serializing_if = "Option::is_none")] #[serde(borrow)] pub cover: Option>, pub created_at: Datetime, ///Book description/summary #[serde(skip_serializing_if = "Option::is_none")] #[serde(borrow)] pub description: Option>, ///The book's hive id, used to correlate user's books with the hive #[serde(borrow)] pub id: CowStr<'a>, ///External identifiers for the book #[serde(skip_serializing_if = "Option::is_none")] #[serde(borrow)] pub identifiers: Option>, ///Average rating (0-1000) #[serde(skip_serializing_if = "Option::is_none")] pub rating: Option, ///Number of ratings #[serde(skip_serializing_if = "Option::is_none")] pub ratings_count: Option, ///The source service name (e.g. Goodreads) #[serde(skip_serializing_if = "Option::is_none")] #[serde(borrow)] pub source: Option>, ///ID of the book in the source service #[serde(skip_serializing_if = "Option::is_none")] #[serde(borrow)] pub source_id: Option>, ///URL to the book on the source service #[serde(skip_serializing_if = "Option::is_none")] #[serde(borrow)] pub source_url: Option>, ///URL to thumbnail image #[serde(borrow)] pub thumbnail: CowStr<'a>, ///The title of the book #[serde(borrow)] pub title: CowStr<'a>, pub updated_at: Datetime, } /// 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 HiveBookGetRecordOutput<'a> { #[serde(skip_serializing_if = "Option::is_none")] #[serde(borrow)] pub cid: Option>, #[serde(borrow)] pub uri: AtUri<'a>, #[serde(borrow)] pub value: HiveBook<'a>, } impl<'a> HiveBook<'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 HiveBookRecord; impl XrpcResp for HiveBookRecord { const NSID: &'static str = "buzz.bookhive.hiveBook"; const ENCODING: &'static str = "application/json"; type Output<'de> = HiveBookGetRecordOutput<'de>; type Err<'de> = RecordError<'de>; } impl From> for HiveBook<'_> { fn from(output: HiveBookGetRecordOutput<'_>) -> Self { use jacquard_common::IntoStatic; output.value.into_static() } } impl Collection for HiveBook<'_> { const NSID: &'static str = "buzz.bookhive.hiveBook"; type Record = HiveBookRecord; } impl Collection for HiveBookRecord { const NSID: &'static str = "buzz.bookhive.hiveBook"; type Record = HiveBookRecord; } impl<'a> LexiconSchema for HiveBook<'a> { fn nsid() -> &'static str { "buzz.bookhive.hiveBook" } fn def_name() -> &'static str { "main" } fn lexicon_doc() -> LexiconDoc<'static> { lexicon_doc_buzz_bookhive_hiveBook() } fn validate(&self) -> Result<(), ConstraintError> { { let value = &self.authors; #[allow(unused_comparisons)] if ::len(value.as_ref()) > 512usize { return Err(ConstraintError::MaxLength { path: ValidationPath::from_field("authors"), max: 512usize, actual: ::len(value.as_ref()), }); } } { let value = &self.authors; #[allow(unused_comparisons)] if ::len(value.as_ref()) < 1usize { return Err(ConstraintError::MinLength { path: ValidationPath::from_field("authors"), min: 1usize, actual: ::len(value.as_ref()), }); } } if let Some(ref value) = self.description { #[allow(unused_comparisons)] if ::len(value.as_ref()) > 5000usize { return Err(ConstraintError::MaxLength { path: ValidationPath::from_field("description"), max: 5000usize, actual: ::len(value.as_ref()), }); } } if let Some(ref value) = self.rating { if *value > 1000i64 { return Err(ConstraintError::Maximum { path: ValidationPath::from_field("rating"), max: 1000i64, actual: *value, }); } } if let Some(ref value) = self.rating { if *value < 0i64 { return Err(ConstraintError::Minimum { path: ValidationPath::from_field("rating"), min: 0i64, actual: *value, }); } } { let value = &self.title; #[allow(unused_comparisons)] if ::len(value.as_ref()) > 512usize { return Err(ConstraintError::MaxLength { path: ValidationPath::from_field("title"), max: 512usize, actual: ::len(value.as_ref()), }); } } { let value = &self.title; #[allow(unused_comparisons)] if ::len(value.as_ref()) < 1usize { return Err(ConstraintError::MinLength { path: ValidationPath::from_field("title"), min: 1usize, actual: ::len(value.as_ref()), }); } } Ok(()) } } pub mod hive_book_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 Title; type CreatedAt; type UpdatedAt; type Id; type Thumbnail; type Authors; } /// Empty state - all required fields are unset pub struct Empty(()); impl sealed::Sealed for Empty {} impl State for Empty { type Title = Unset; type CreatedAt = Unset; type UpdatedAt = Unset; type Id = Unset; type Thumbnail = Unset; type Authors = Unset; } ///State transition - sets the `title` field to Set pub struct SetTitle(PhantomData S>); impl sealed::Sealed for SetTitle {} impl State for SetTitle { type Title = Set; type CreatedAt = S::CreatedAt; type UpdatedAt = S::UpdatedAt; type Id = S::Id; type Thumbnail = S::Thumbnail; type Authors = S::Authors; } ///State transition - sets the `created_at` field to Set pub struct SetCreatedAt(PhantomData S>); impl sealed::Sealed for SetCreatedAt {} impl State for SetCreatedAt { type Title = S::Title; type CreatedAt = Set; type UpdatedAt = S::UpdatedAt; type Id = S::Id; type Thumbnail = S::Thumbnail; type Authors = S::Authors; } ///State transition - sets the `updated_at` field to Set pub struct SetUpdatedAt(PhantomData S>); impl sealed::Sealed for SetUpdatedAt {} impl State for SetUpdatedAt { type Title = S::Title; type CreatedAt = S::CreatedAt; type UpdatedAt = Set; type Id = S::Id; type Thumbnail = S::Thumbnail; type Authors = S::Authors; } ///State transition - sets the `id` field to Set pub struct SetId(PhantomData S>); impl sealed::Sealed for SetId {} impl State for SetId { type Title = S::Title; type CreatedAt = S::CreatedAt; type UpdatedAt = S::UpdatedAt; type Id = Set; type Thumbnail = S::Thumbnail; type Authors = S::Authors; } ///State transition - sets the `thumbnail` field to Set pub struct SetThumbnail(PhantomData S>); impl sealed::Sealed for SetThumbnail {} impl State for SetThumbnail { type Title = S::Title; type CreatedAt = S::CreatedAt; type UpdatedAt = S::UpdatedAt; type Id = S::Id; type Thumbnail = Set; type Authors = S::Authors; } ///State transition - sets the `authors` field to Set pub struct SetAuthors(PhantomData S>); impl sealed::Sealed for SetAuthors {} impl State for SetAuthors { type Title = S::Title; type CreatedAt = S::CreatedAt; type UpdatedAt = S::UpdatedAt; type Id = S::Id; type Thumbnail = S::Thumbnail; type Authors = Set; } /// Marker types for field names #[allow(non_camel_case_types)] pub mod members { ///Marker type for the `title` field pub struct title(()); ///Marker type for the `created_at` field pub struct created_at(()); ///Marker type for the `updated_at` field pub struct updated_at(()); ///Marker type for the `id` field pub struct id(()); ///Marker type for the `thumbnail` field pub struct thumbnail(()); ///Marker type for the `authors` field pub struct authors(()); } } /// Builder for constructing an instance of this type pub struct HiveBookBuilder<'a, S: hive_book_state::State> { _state: PhantomData S>, _fields: ( Option>, Option>, Option, Option>, Option>, Option>, Option, Option, Option>, Option>, Option>, Option>, Option>, Option, ), _lifetime: PhantomData<&'a ()>, } impl<'a> HiveBook<'a> { /// Create a new builder for this type pub fn new() -> HiveBookBuilder<'a, hive_book_state::Empty> { HiveBookBuilder::new() } } impl<'a> HiveBookBuilder<'a, hive_book_state::Empty> { /// Create a new builder with all fields unset pub fn new() -> Self { HiveBookBuilder { _state: PhantomData, _fields: ( None, None, None, None, None, None, None, None, None, None, None, None, None, None, ), _lifetime: PhantomData, } } } impl<'a, S> HiveBookBuilder<'a, S> where S: hive_book_state::State, S::Authors: hive_book_state::IsUnset, { /// Set the `authors` field (required) pub fn authors( mut self, value: impl Into>, ) -> HiveBookBuilder<'a, hive_book_state::SetAuthors> { self._fields.0 = Option::Some(value.into()); HiveBookBuilder { _state: PhantomData, _fields: self._fields, _lifetime: PhantomData, } } } impl<'a, S: hive_book_state::State> HiveBookBuilder<'a, S> { /// Set the `cover` field (optional) pub fn cover(mut self, value: impl Into>>) -> Self { self._fields.1 = value.into(); self } /// Set the `cover` field to an Option value (optional) pub fn maybe_cover(mut self, value: Option>) -> Self { self._fields.1 = value; self } } impl<'a, S> HiveBookBuilder<'a, S> where S: hive_book_state::State, S::CreatedAt: hive_book_state::IsUnset, { /// Set the `createdAt` field (required) pub fn created_at( mut self, value: impl Into, ) -> HiveBookBuilder<'a, hive_book_state::SetCreatedAt> { self._fields.2 = Option::Some(value.into()); HiveBookBuilder { _state: PhantomData, _fields: self._fields, _lifetime: PhantomData, } } } impl<'a, S: hive_book_state::State> HiveBookBuilder<'a, S> { /// Set the `description` field (optional) pub fn description(mut self, value: impl Into>>) -> Self { self._fields.3 = value.into(); self } /// Set the `description` field to an Option value (optional) pub fn maybe_description(mut self, value: Option>) -> Self { self._fields.3 = value; self } } impl<'a, S> HiveBookBuilder<'a, S> where S: hive_book_state::State, S::Id: hive_book_state::IsUnset, { /// Set the `id` field (required) pub fn id( mut self, value: impl Into>, ) -> HiveBookBuilder<'a, hive_book_state::SetId> { self._fields.4 = Option::Some(value.into()); HiveBookBuilder { _state: PhantomData, _fields: self._fields, _lifetime: PhantomData, } } } impl<'a, S: hive_book_state::State> HiveBookBuilder<'a, S> { /// Set the `identifiers` field (optional) pub fn identifiers(mut self, value: impl Into>>) -> Self { self._fields.5 = value.into(); self } /// Set the `identifiers` field to an Option value (optional) pub fn maybe_identifiers(mut self, value: Option>) -> Self { self._fields.5 = value; self } } impl<'a, S: hive_book_state::State> HiveBookBuilder<'a, S> { /// Set the `rating` field (optional) pub fn rating(mut self, value: impl Into>) -> Self { self._fields.6 = value.into(); self } /// Set the `rating` field to an Option value (optional) pub fn maybe_rating(mut self, value: Option) -> Self { self._fields.6 = value; self } } impl<'a, S: hive_book_state::State> HiveBookBuilder<'a, S> { /// Set the `ratingsCount` field (optional) pub fn ratings_count(mut self, value: impl Into>) -> Self { self._fields.7 = value.into(); self } /// Set the `ratingsCount` field to an Option value (optional) pub fn maybe_ratings_count(mut self, value: Option) -> Self { self._fields.7 = value; self } } impl<'a, S: hive_book_state::State> HiveBookBuilder<'a, S> { /// Set the `source` field (optional) pub fn source(mut self, value: impl Into>>) -> Self { self._fields.8 = value.into(); self } /// Set the `source` field to an Option value (optional) pub fn maybe_source(mut self, value: Option>) -> Self { self._fields.8 = value; self } } impl<'a, S: hive_book_state::State> HiveBookBuilder<'a, S> { /// Set the `sourceId` field (optional) pub fn source_id(mut self, value: impl Into>>) -> Self { self._fields.9 = value.into(); self } /// Set the `sourceId` field to an Option value (optional) pub fn maybe_source_id(mut self, value: Option>) -> Self { self._fields.9 = value; self } } impl<'a, S: hive_book_state::State> HiveBookBuilder<'a, S> { /// Set the `sourceUrl` field (optional) pub fn source_url(mut self, value: impl Into>>) -> Self { self._fields.10 = value.into(); self } /// Set the `sourceUrl` field to an Option value (optional) pub fn maybe_source_url(mut self, value: Option>) -> Self { self._fields.10 = value; self } } impl<'a, S> HiveBookBuilder<'a, S> where S: hive_book_state::State, S::Thumbnail: hive_book_state::IsUnset, { /// Set the `thumbnail` field (required) pub fn thumbnail( mut self, value: impl Into>, ) -> HiveBookBuilder<'a, hive_book_state::SetThumbnail> { self._fields.11 = Option::Some(value.into()); HiveBookBuilder { _state: PhantomData, _fields: self._fields, _lifetime: PhantomData, } } } impl<'a, S> HiveBookBuilder<'a, S> where S: hive_book_state::State, S::Title: hive_book_state::IsUnset, { /// Set the `title` field (required) pub fn title( mut self, value: impl Into>, ) -> HiveBookBuilder<'a, hive_book_state::SetTitle> { self._fields.12 = Option::Some(value.into()); HiveBookBuilder { _state: PhantomData, _fields: self._fields, _lifetime: PhantomData, } } } impl<'a, S> HiveBookBuilder<'a, S> where S: hive_book_state::State, S::UpdatedAt: hive_book_state::IsUnset, { /// Set the `updatedAt` field (required) pub fn updated_at( mut self, value: impl Into, ) -> HiveBookBuilder<'a, hive_book_state::SetUpdatedAt> { self._fields.13 = Option::Some(value.into()); HiveBookBuilder { _state: PhantomData, _fields: self._fields, _lifetime: PhantomData, } } } impl<'a, S> HiveBookBuilder<'a, S> where S: hive_book_state::State, S::Title: hive_book_state::IsSet, S::CreatedAt: hive_book_state::IsSet, S::UpdatedAt: hive_book_state::IsSet, S::Id: hive_book_state::IsSet, S::Thumbnail: hive_book_state::IsSet, S::Authors: hive_book_state::IsSet, { /// Build the final struct pub fn build(self) -> HiveBook<'a> { HiveBook { authors: self._fields.0.unwrap(), cover: self._fields.1, created_at: self._fields.2.unwrap(), description: self._fields.3, id: self._fields.4.unwrap(), identifiers: self._fields.5, rating: self._fields.6, ratings_count: self._fields.7, source: self._fields.8, source_id: self._fields.9, source_url: self._fields.10, thumbnail: self._fields.11.unwrap(), title: self._fields.12.unwrap(), updated_at: self._fields.13.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>, >, ) -> HiveBook<'a> { HiveBook { authors: self._fields.0.unwrap(), cover: self._fields.1, created_at: self._fields.2.unwrap(), description: self._fields.3, id: self._fields.4.unwrap(), identifiers: self._fields.5, rating: self._fields.6, ratings_count: self._fields.7, source: self._fields.8, source_id: self._fields.9, source_url: self._fields.10, thumbnail: self._fields.11.unwrap(), title: self._fields.12.unwrap(), updated_at: self._fields.13.unwrap(), extra_data: Some(extra_data), } } } fn lexicon_doc_buzz_bookhive_hiveBook() -> 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("buzz.bookhive.hiveBook"), defs: { let mut map = BTreeMap::new(); map.insert( SmolStr::new_static("main"), LexUserType::Record(LexRecord { description: Some(CowStr::new_static("A book within the hive")), key: Some(CowStr::new_static("tid")), record: LexRecordRecord::Object(LexObject { required: Some( vec![ SmolStr::new_static("id"), SmolStr::new_static("title"), SmolStr::new_static("authors"), SmolStr::new_static("createdAt"), SmolStr::new_static("updatedAt"), SmolStr::new_static("thumbnail") ], ), properties: { #[allow(unused_mut)] let mut map = BTreeMap::new(); map.insert( SmolStr::new_static("authors"), LexObjectProperty::String(LexString { description: Some( CowStr::new_static( "The authors of the book (tab separated)", ), ), min_length: Some(1usize), max_length: Some(512usize), ..Default::default() }), ); map.insert( SmolStr::new_static("cover"), LexObjectProperty::String(LexString { description: Some( CowStr::new_static("URL to full-size cover image"), ), ..Default::default() }), ); map.insert( SmolStr::new_static("createdAt"), LexObjectProperty::String(LexString { format: Some(LexStringFormat::Datetime), ..Default::default() }), ); map.insert( SmolStr::new_static("description"), LexObjectProperty::String(LexString { description: Some( CowStr::new_static("Book description/summary"), ), max_length: Some(5000usize), ..Default::default() }), ); map.insert( SmolStr::new_static("id"), LexObjectProperty::String(LexString { description: Some( CowStr::new_static( "The book's hive id, used to correlate user's books with the hive", ), ), ..Default::default() }), ); map.insert( SmolStr::new_static("identifiers"), LexObjectProperty::Ref(LexRef { r#ref: CowStr::new_static( "buzz.bookhive.defs#bookIdentifiers", ), ..Default::default() }), ); map.insert( SmolStr::new_static("rating"), LexObjectProperty::Integer(LexInteger { minimum: Some(0i64), maximum: Some(1000i64), ..Default::default() }), ); map.insert( SmolStr::new_static("ratingsCount"), LexObjectProperty::Integer(LexInteger { ..Default::default() }), ); map.insert( SmolStr::new_static("source"), LexObjectProperty::String(LexString { description: Some( CowStr::new_static( "The source service name (e.g. Goodreads)", ), ), ..Default::default() }), ); map.insert( SmolStr::new_static("sourceId"), LexObjectProperty::String(LexString { description: Some( CowStr::new_static("ID of the book in the source service"), ), ..Default::default() }), ); map.insert( SmolStr::new_static("sourceUrl"), LexObjectProperty::String(LexString { description: Some( CowStr::new_static("URL to the book on the source service"), ), ..Default::default() }), ); map.insert( SmolStr::new_static("thumbnail"), LexObjectProperty::String(LexString { description: Some( CowStr::new_static("URL to thumbnail image"), ), ..Default::default() }), ); map.insert( SmolStr::new_static("title"), LexObjectProperty::String(LexString { description: Some( CowStr::new_static("The title of the book"), ), min_length: Some(1usize), max_length: Some(512usize), ..Default::default() }), ); map.insert( SmolStr::new_static("updatedAt"), LexObjectProperty::String(LexString { format: Some(LexStringFormat::Datetime), ..Default::default() }), ); map }, ..Default::default() }), ..Default::default() }), ); map }, ..Default::default() } }