#[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;
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct HiveBook<'a> {
#[serde(borrow)]
pub authors: CowStr<'a>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub cover: Option<CowStr<'a>>,
pub created_at: Datetime,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub description: Option<CowStr<'a>>,
#[serde(borrow)]
pub id: CowStr<'a>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub identifiers: Option<BookIdentifiers<'a>>,
#[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")]
#[serde(borrow)]
pub source: Option<CowStr<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub source_id: Option<CowStr<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub source_url: Option<CowStr<'a>>,
#[serde(borrow)]
pub thumbnail: CowStr<'a>,
#[serde(borrow)]
pub title: CowStr<'a>,
pub updated_at: Datetime,
}
#[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<Cid<'a>>,
#[serde(borrow)]
pub uri: AtUri<'a>,
#[serde(borrow)]
pub value: HiveBook<'a>,
}
impl<'a> HiveBook<'a> {
pub fn uri(
uri: impl Into<CowStr<'a>>,
) -> Result<RecordUri<'a, HiveBookRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new_cow(uri.into())?)
}
}
#[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<HiveBookGetRecordOutput<'_>> 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 <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::{Set, Unset, IsSet, IsUnset};
#[allow(unused)]
use ::core::marker::PhantomData;
mod sealed {
pub trait Sealed {}
}
pub trait State: sealed::Sealed {
type Title;
type CreatedAt;
type UpdatedAt;
type Id;
type Thumbnail;
type Authors;
}
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;
}
pub struct SetTitle<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetTitle<S> {}
impl<S: State> State for SetTitle<S> {
type Title = Set<members::title>;
type CreatedAt = S::CreatedAt;
type UpdatedAt = S::UpdatedAt;
type Id = S::Id;
type Thumbnail = S::Thumbnail;
type Authors = S::Authors;
}
pub struct SetCreatedAt<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetCreatedAt<S> {}
impl<S: State> State for SetCreatedAt<S> {
type Title = S::Title;
type CreatedAt = Set<members::created_at>;
type UpdatedAt = S::UpdatedAt;
type Id = S::Id;
type Thumbnail = S::Thumbnail;
type Authors = S::Authors;
}
pub struct SetUpdatedAt<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetUpdatedAt<S> {}
impl<S: State> State for SetUpdatedAt<S> {
type Title = S::Title;
type CreatedAt = S::CreatedAt;
type UpdatedAt = Set<members::updated_at>;
type Id = S::Id;
type Thumbnail = S::Thumbnail;
type Authors = S::Authors;
}
pub struct SetId<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetId<S> {}
impl<S: State> State for SetId<S> {
type Title = S::Title;
type CreatedAt = S::CreatedAt;
type UpdatedAt = S::UpdatedAt;
type Id = Set<members::id>;
type Thumbnail = S::Thumbnail;
type Authors = S::Authors;
}
pub struct SetThumbnail<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetThumbnail<S> {}
impl<S: State> State for SetThumbnail<S> {
type Title = S::Title;
type CreatedAt = S::CreatedAt;
type UpdatedAt = S::UpdatedAt;
type Id = S::Id;
type Thumbnail = Set<members::thumbnail>;
type Authors = S::Authors;
}
pub struct SetAuthors<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetAuthors<S> {}
impl<S: State> State for SetAuthors<S> {
type Title = S::Title;
type CreatedAt = S::CreatedAt;
type UpdatedAt = S::UpdatedAt;
type Id = S::Id;
type Thumbnail = S::Thumbnail;
type Authors = Set<members::authors>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct title(());
pub struct created_at(());
pub struct updated_at(());
pub struct id(());
pub struct thumbnail(());
pub struct authors(());
}
}
pub struct HiveBookBuilder<'a, S: hive_book_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (
Option<CowStr<'a>>,
Option<CowStr<'a>>,
Option<Datetime>,
Option<CowStr<'a>>,
Option<CowStr<'a>>,
Option<BookIdentifiers<'a>>,
Option<i64>,
Option<i64>,
Option<CowStr<'a>>,
Option<CowStr<'a>>,
Option<CowStr<'a>>,
Option<CowStr<'a>>,
Option<CowStr<'a>>,
Option<Datetime>,
),
_lifetime: PhantomData<&'a ()>,
}
impl<'a> HiveBook<'a> {
pub fn new() -> HiveBookBuilder<'a, hive_book_state::Empty> {
HiveBookBuilder::new()
}
}
impl<'a> HiveBookBuilder<'a, 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,
),
_lifetime: PhantomData,
}
}
}
impl<'a, S> HiveBookBuilder<'a, S>
where
S: hive_book_state::State,
S::Authors: hive_book_state::IsUnset,
{
pub fn authors(
mut self,
value: impl Into<CowStr<'a>>,
) -> HiveBookBuilder<'a, hive_book_state::SetAuthors<S>> {
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> {
pub fn cover(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
self._fields.1 = value.into();
self
}
pub fn maybe_cover(mut self, value: Option<CowStr<'a>>) -> Self {
self._fields.1 = value;
self
}
}
impl<'a, S> HiveBookBuilder<'a, S>
where
S: hive_book_state::State,
S::CreatedAt: hive_book_state::IsUnset,
{
pub fn created_at(
mut self,
value: impl Into<Datetime>,
) -> HiveBookBuilder<'a, hive_book_state::SetCreatedAt<S>> {
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> {
pub fn description(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
self._fields.3 = value.into();
self
}
pub fn maybe_description(mut self, value: Option<CowStr<'a>>) -> Self {
self._fields.3 = value;
self
}
}
impl<'a, S> HiveBookBuilder<'a, S>
where
S: hive_book_state::State,
S::Id: hive_book_state::IsUnset,
{
pub fn id(
mut self,
value: impl Into<CowStr<'a>>,
) -> HiveBookBuilder<'a, hive_book_state::SetId<S>> {
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> {
pub fn identifiers(mut self, value: impl Into<Option<BookIdentifiers<'a>>>) -> Self {
self._fields.5 = value.into();
self
}
pub fn maybe_identifiers(mut self, value: Option<BookIdentifiers<'a>>) -> Self {
self._fields.5 = value;
self
}
}
impl<'a, S: hive_book_state::State> HiveBookBuilder<'a, S> {
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<'a, S: hive_book_state::State> HiveBookBuilder<'a, S> {
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<'a, S: hive_book_state::State> HiveBookBuilder<'a, S> {
pub fn source(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
self._fields.8 = value.into();
self
}
pub fn maybe_source(mut self, value: Option<CowStr<'a>>) -> Self {
self._fields.8 = value;
self
}
}
impl<'a, S: hive_book_state::State> HiveBookBuilder<'a, S> {
pub fn source_id(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
self._fields.9 = value.into();
self
}
pub fn maybe_source_id(mut self, value: Option<CowStr<'a>>) -> Self {
self._fields.9 = value;
self
}
}
impl<'a, S: hive_book_state::State> HiveBookBuilder<'a, S> {
pub fn source_url(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
self._fields.10 = value.into();
self
}
pub fn maybe_source_url(mut self, value: Option<CowStr<'a>>) -> Self {
self._fields.10 = value;
self
}
}
impl<'a, S> HiveBookBuilder<'a, S>
where
S: hive_book_state::State,
S::Thumbnail: hive_book_state::IsUnset,
{
pub fn thumbnail(
mut self,
value: impl Into<CowStr<'a>>,
) -> HiveBookBuilder<'a, hive_book_state::SetThumbnail<S>> {
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,
{
pub fn title(
mut self,
value: impl Into<CowStr<'a>>,
) -> HiveBookBuilder<'a, hive_book_state::SetTitle<S>> {
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,
{
pub fn updated_at(
mut self,
value: impl Into<Datetime>,
) -> HiveBookBuilder<'a, hive_book_state::SetUpdatedAt<S>> {
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,
{
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(),
}
}
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()
}
}