#[allow(unused_imports)]
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::{BosStr, CowStr, DefaultStr, FromStaticStr};
#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::deps::smol_str::SmolStr;
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::types::value::Data;
use jacquard_common::xrpc::XrpcResp;
use jacquard_derive::{IntoStatic, lexicon};
use jacquard_lexicon::lexicon::LexiconDoc;
use jacquard_lexicon::schema::LexiconSchema;
use crate::buzz_bookhive::BookIdentifiers;
#[allow(unused_imports)]
use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
rename_all = "camelCase",
rename = "buzz.bookhive.hiveBook",
tag = "$type",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct HiveBook<S: BosStr = DefaultStr> {
pub authors: S,
#[serde(skip_serializing_if = "Option::is_none")]
pub cover: Option<S>,
pub created_at: Datetime,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<S>,
pub id: S,
#[serde(skip_serializing_if = "Option::is_none")]
pub identifiers: Option<BookIdentifiers<S>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub rating: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub ratings_count: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub source: Option<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub source_id: Option<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub source_url: Option<S>,
pub thumbnail: S,
pub title: S,
pub updated_at: Datetime,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct HiveBookGetRecordOutput<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub cid: Option<Cid<S>>,
pub uri: AtUri<S>,
pub value: HiveBook<S>,
}
impl<S: BosStr> HiveBook<S> {
pub fn uri(uri: S) -> Result<RecordUri<S, HiveBookRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new(uri)?)
}
}
#[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<S: BosStr> = HiveBookGetRecordOutput<S>;
type Err = RecordError;
}
impl<S: BosStr> From<HiveBookGetRecordOutput<S>> for HiveBook<S> {
fn from(output: HiveBookGetRecordOutput<S>) -> Self {
output.value
}
}
impl<S: BosStr> Collection for HiveBook<S> {
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<S: BosStr> LexiconSchema for HiveBook<S> {
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 <str>::len(value.as_ref()) > 512usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("authors"),
max: 512usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.authors;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) < 1usize {
return Err(ConstraintError::MinLength {
path: ValidationPath::from_field("authors"),
min: 1usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.description {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 5000usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("description"),
max: 5000usize,
actual: <str>::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 <str>::len(value.as_ref()) > 512usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("title"),
max: 512usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.title;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) < 1usize {
return Err(ConstraintError::MinLength {
path: ValidationPath::from_field("title"),
min: 1usize,
actual: <str>::len(value.as_ref()),
});
}
}
Ok(())
}
}
pub mod hive_book_state {
pub use crate::builder_types::{IsSet, IsUnset, Set, Unset};
#[allow(unused)]
use ::core::marker::PhantomData;
mod sealed {
pub trait Sealed {}
}
pub trait State: sealed::Sealed {
type UpdatedAt;
type Thumbnail;
type Id;
type Title;
type Authors;
type CreatedAt;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type UpdatedAt = Unset;
type Thumbnail = Unset;
type Id = Unset;
type Title = Unset;
type Authors = Unset;
type CreatedAt = Unset;
}
pub struct SetUpdatedAt<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetUpdatedAt<St> {}
impl<St: State> State for SetUpdatedAt<St> {
type UpdatedAt = Set<members::updated_at>;
type Thumbnail = St::Thumbnail;
type Id = St::Id;
type Title = St::Title;
type Authors = St::Authors;
type CreatedAt = St::CreatedAt;
}
pub struct SetThumbnail<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetThumbnail<St> {}
impl<St: State> State for SetThumbnail<St> {
type UpdatedAt = St::UpdatedAt;
type Thumbnail = Set<members::thumbnail>;
type Id = St::Id;
type Title = St::Title;
type Authors = St::Authors;
type CreatedAt = St::CreatedAt;
}
pub struct SetId<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetId<St> {}
impl<St: State> State for SetId<St> {
type UpdatedAt = St::UpdatedAt;
type Thumbnail = St::Thumbnail;
type Id = Set<members::id>;
type Title = St::Title;
type Authors = St::Authors;
type CreatedAt = St::CreatedAt;
}
pub struct SetTitle<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetTitle<St> {}
impl<St: State> State for SetTitle<St> {
type UpdatedAt = St::UpdatedAt;
type Thumbnail = St::Thumbnail;
type Id = St::Id;
type Title = Set<members::title>;
type Authors = St::Authors;
type CreatedAt = St::CreatedAt;
}
pub struct SetAuthors<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetAuthors<St> {}
impl<St: State> State for SetAuthors<St> {
type UpdatedAt = St::UpdatedAt;
type Thumbnail = St::Thumbnail;
type Id = St::Id;
type Title = St::Title;
type Authors = Set<members::authors>;
type CreatedAt = St::CreatedAt;
}
pub struct SetCreatedAt<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetCreatedAt<St> {}
impl<St: State> State for SetCreatedAt<St> {
type UpdatedAt = St::UpdatedAt;
type Thumbnail = St::Thumbnail;
type Id = St::Id;
type Title = St::Title;
type Authors = St::Authors;
type CreatedAt = Set<members::created_at>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct updated_at(());
pub struct thumbnail(());
pub struct id(());
pub struct title(());
pub struct authors(());
pub struct created_at(());
}
}
pub struct HiveBookBuilder<S: BosStr, St: hive_book_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<S>,
Option<S>,
Option<Datetime>,
Option<S>,
Option<S>,
Option<BookIdentifiers<S>>,
Option<i64>,
Option<i64>,
Option<S>,
Option<S>,
Option<S>,
Option<S>,
Option<S>,
Option<Datetime>,
),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> HiveBook<S> {
pub fn new() -> HiveBookBuilder<S, hive_book_state::Empty> {
HiveBookBuilder::new()
}
}
impl<S: BosStr> HiveBookBuilder<S, hive_book_state::Empty> {
pub fn new() -> Self {
HiveBookBuilder {
_state: PhantomData,
_fields: (
None, None, None, None, None, None, None, None, None, None, None, None, None, None,
),
_type: PhantomData,
}
}
}
impl<S: BosStr, St> HiveBookBuilder<S, St>
where
St: hive_book_state::State,
St::Authors: hive_book_state::IsUnset,
{
pub fn authors(
mut self,
value: impl Into<S>,
) -> HiveBookBuilder<S, hive_book_state::SetAuthors<St>> {
self._fields.0 = Option::Some(value.into());
HiveBookBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: hive_book_state::State> HiveBookBuilder<S, St> {
pub fn cover(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.1 = value.into();
self
}
pub fn maybe_cover(mut self, value: Option<S>) -> Self {
self._fields.1 = value;
self
}
}
impl<S: BosStr, St> HiveBookBuilder<S, St>
where
St: hive_book_state::State,
St::CreatedAt: hive_book_state::IsUnset,
{
pub fn created_at(
mut self,
value: impl Into<Datetime>,
) -> HiveBookBuilder<S, hive_book_state::SetCreatedAt<St>> {
self._fields.2 = Option::Some(value.into());
HiveBookBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: hive_book_state::State> HiveBookBuilder<S, St> {
pub fn description(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.3 = value.into();
self
}
pub fn maybe_description(mut self, value: Option<S>) -> Self {
self._fields.3 = value;
self
}
}
impl<S: BosStr, St> HiveBookBuilder<S, St>
where
St: hive_book_state::State,
St::Id: hive_book_state::IsUnset,
{
pub fn id(mut self, value: impl Into<S>) -> HiveBookBuilder<S, hive_book_state::SetId<St>> {
self._fields.4 = Option::Some(value.into());
HiveBookBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: hive_book_state::State> HiveBookBuilder<S, St> {
pub fn identifiers(mut self, value: impl Into<Option<BookIdentifiers<S>>>) -> Self {
self._fields.5 = value.into();
self
}
pub fn maybe_identifiers(mut self, value: Option<BookIdentifiers<S>>) -> Self {
self._fields.5 = value;
self
}
}
impl<S: BosStr, St: hive_book_state::State> HiveBookBuilder<S, St> {
pub fn rating(mut self, value: impl Into<Option<i64>>) -> Self {
self._fields.6 = value.into();
self
}
pub fn maybe_rating(mut self, value: Option<i64>) -> Self {
self._fields.6 = value;
self
}
}
impl<S: BosStr, St: hive_book_state::State> HiveBookBuilder<S, St> {
pub fn ratings_count(mut self, value: impl Into<Option<i64>>) -> Self {
self._fields.7 = value.into();
self
}
pub fn maybe_ratings_count(mut self, value: Option<i64>) -> Self {
self._fields.7 = value;
self
}
}
impl<S: BosStr, St: hive_book_state::State> HiveBookBuilder<S, St> {
pub fn source(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.8 = value.into();
self
}
pub fn maybe_source(mut self, value: Option<S>) -> Self {
self._fields.8 = value;
self
}
}
impl<S: BosStr, St: hive_book_state::State> HiveBookBuilder<S, St> {
pub fn source_id(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.9 = value.into();
self
}
pub fn maybe_source_id(mut self, value: Option<S>) -> Self {
self._fields.9 = value;
self
}
}
impl<S: BosStr, St: hive_book_state::State> HiveBookBuilder<S, St> {
pub fn source_url(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.10 = value.into();
self
}
pub fn maybe_source_url(mut self, value: Option<S>) -> Self {
self._fields.10 = value;
self
}
}
impl<S: BosStr, St> HiveBookBuilder<S, St>
where
St: hive_book_state::State,
St::Thumbnail: hive_book_state::IsUnset,
{
pub fn thumbnail(
mut self,
value: impl Into<S>,
) -> HiveBookBuilder<S, hive_book_state::SetThumbnail<St>> {
self._fields.11 = Option::Some(value.into());
HiveBookBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> HiveBookBuilder<S, St>
where
St: hive_book_state::State,
St::Title: hive_book_state::IsUnset,
{
pub fn title(
mut self,
value: impl Into<S>,
) -> HiveBookBuilder<S, hive_book_state::SetTitle<St>> {
self._fields.12 = Option::Some(value.into());
HiveBookBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> HiveBookBuilder<S, St>
where
St: hive_book_state::State,
St::UpdatedAt: hive_book_state::IsUnset,
{
pub fn updated_at(
mut self,
value: impl Into<Datetime>,
) -> HiveBookBuilder<S, hive_book_state::SetUpdatedAt<St>> {
self._fields.13 = Option::Some(value.into());
HiveBookBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> HiveBookBuilder<S, St>
where
St: hive_book_state::State,
St::UpdatedAt: hive_book_state::IsSet,
St::Thumbnail: hive_book_state::IsSet,
St::Id: hive_book_state::IsSet,
St::Title: hive_book_state::IsSet,
St::Authors: hive_book_state::IsSet,
St::CreatedAt: hive_book_state::IsSet,
{
pub fn build(self) -> HiveBook<S> {
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(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> HiveBook<S> {
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> {
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
use jacquard_lexicon::lexicon::*;
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()
}
}