pub mod checkin;
pub mod drop;
pub mod event;
pub mod find;
pub mod get_book;
pub mod get_books;
pub mod get_library;
pub mod get_location_books;
pub mod list_book_ids;
pub mod list_dropped_books;
pub mod registration;
#[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::string::{AtUri, Datetime, Did, UriValue};
use jacquard_common::types::value::Data;
use jacquard_derive::IntoStatic;
use jacquard_lexicon::lexicon::LexiconDoc;
use jacquard_lexicon::schema::LexiconSchema;
use crate::community_lexicon::location::hthree::Hthree;
use crate::org_passingreads::Actor;
use crate::org_passingreads::AspectRatio;
use crate::org_passingreads::book;
#[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",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct ConfirmedEvent<S: BosStr = DefaultStr> {
pub actor: Actor<S>,
pub event: ConfirmedEventEvent<S>,
pub location: Hthree<S>,
pub occurred_at: Datetime,
pub uri: AtUri<S>,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum ConfirmedEventEvent<S: BosStr = DefaultStr> {
OrgPassingreadsBookCheckin,
OrgPassingreadsBookDrop,
OrgPassingreadsBookFind,
Other(S),
}
impl<S: BosStr> ConfirmedEventEvent<S> {
pub fn as_str(&self) -> &str {
match self {
Self::OrgPassingreadsBookCheckin => "org.passingreads.book.checkin",
Self::OrgPassingreadsBookDrop => "org.passingreads.book.drop",
Self::OrgPassingreadsBookFind => "org.passingreads.book.find",
Self::Other(s) => s.as_ref(),
}
}
pub fn from_value(s: S) -> Self {
match s.as_ref() {
"org.passingreads.book.checkin" => Self::OrgPassingreadsBookCheckin,
"org.passingreads.book.drop" => Self::OrgPassingreadsBookDrop,
"org.passingreads.book.find" => Self::OrgPassingreadsBookFind,
_ => Self::Other(s),
}
}
}
impl<S: BosStr> core::fmt::Display for ConfirmedEventEvent<S> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<S: BosStr> AsRef<str> for ConfirmedEventEvent<S> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<S: BosStr> Serialize for ConfirmedEventEvent<S> {
fn serialize<Ser>(&self, serializer: Ser) -> Result<Ser::Ok, Ser::Error>
where
Ser: serde::Serializer,
{
serializer.serialize_str(self.as_str())
}
}
impl<'de, S: Deserialize<'de> + BosStr> Deserialize<'de> for ConfirmedEventEvent<S> {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let s = S::deserialize(deserializer)?;
Ok(Self::from_value(s))
}
}
impl<S: BosStr + Default> Default for ConfirmedEventEvent<S> {
fn default() -> Self {
Self::Other(Default::default())
}
}
impl<S: BosStr> jacquard_common::IntoStatic for ConfirmedEventEvent<S>
where
S: BosStr + jacquard_common::IntoStatic,
S::Output: BosStr,
{
type Output = ConfirmedEventEvent<S::Output>;
fn into_static(self) -> Self::Output {
match self {
ConfirmedEventEvent::OrgPassingreadsBookCheckin => {
ConfirmedEventEvent::OrgPassingreadsBookCheckin
}
ConfirmedEventEvent::OrgPassingreadsBookDrop => {
ConfirmedEventEvent::OrgPassingreadsBookDrop
}
ConfirmedEventEvent::OrgPassingreadsBookFind => {
ConfirmedEventEvent::OrgPassingreadsBookFind
}
ConfirmedEventEvent::Other(v) => ConfirmedEventEvent::Other(v.into_static()),
}
}
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
rename_all = "camelCase",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct RegistrationView<S: BosStr = DefaultStr> {
pub authors: Vec<S>,
pub book_id: S,
pub occurred_at: Datetime,
#[serde(skip_serializing_if = "Option::is_none")]
pub publication_id: Option<S>,
pub registered_by: Actor<S>,
pub title: S,
#[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",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct StatefulBook<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub aspect_ratio: Option<AspectRatio<S>>,
pub cid: S,
#[serde(skip_serializing_if = "Option::is_none")]
pub cover_url: Option<UriValue<S>>,
pub current_holder: Did<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub current_location: Option<Hthree<S>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub events: Option<Vec<book::ConfirmedEvent<S>>>,
pub registration: book::RegistrationView<S>,
pub state: StatefulBookState<S>,
pub uri: AtUri<S>,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum StatefulBookState<S: BosStr = DefaultStr> {
OrgPassingreadsBookCheckin,
OrgPassingreadsBookDrop,
OrgPassingreadsBookFind,
OrgPassingreadsBookRegistration,
Other(S),
}
impl<S: BosStr> StatefulBookState<S> {
pub fn as_str(&self) -> &str {
match self {
Self::OrgPassingreadsBookCheckin => "org.passingreads.book.checkin",
Self::OrgPassingreadsBookDrop => "org.passingreads.book.drop",
Self::OrgPassingreadsBookFind => "org.passingreads.book.find",
Self::OrgPassingreadsBookRegistration => "org.passingreads.book.registration",
Self::Other(s) => s.as_ref(),
}
}
pub fn from_value(s: S) -> Self {
match s.as_ref() {
"org.passingreads.book.checkin" => Self::OrgPassingreadsBookCheckin,
"org.passingreads.book.drop" => Self::OrgPassingreadsBookDrop,
"org.passingreads.book.find" => Self::OrgPassingreadsBookFind,
"org.passingreads.book.registration" => Self::OrgPassingreadsBookRegistration,
_ => Self::Other(s),
}
}
}
impl<S: BosStr> core::fmt::Display for StatefulBookState<S> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<S: BosStr> AsRef<str> for StatefulBookState<S> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<S: BosStr> Serialize for StatefulBookState<S> {
fn serialize<Ser>(&self, serializer: Ser) -> Result<Ser::Ok, Ser::Error>
where
Ser: serde::Serializer,
{
serializer.serialize_str(self.as_str())
}
}
impl<'de, S: Deserialize<'de> + BosStr> Deserialize<'de> for StatefulBookState<S> {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let s = S::deserialize(deserializer)?;
Ok(Self::from_value(s))
}
}
impl<S: BosStr + Default> Default for StatefulBookState<S> {
fn default() -> Self {
Self::Other(Default::default())
}
}
impl<S: BosStr> jacquard_common::IntoStatic for StatefulBookState<S>
where
S: BosStr + jacquard_common::IntoStatic,
S::Output: BosStr,
{
type Output = StatefulBookState<S::Output>;
fn into_static(self) -> Self::Output {
match self {
StatefulBookState::OrgPassingreadsBookCheckin => {
StatefulBookState::OrgPassingreadsBookCheckin
}
StatefulBookState::OrgPassingreadsBookDrop => {
StatefulBookState::OrgPassingreadsBookDrop
}
StatefulBookState::OrgPassingreadsBookFind => {
StatefulBookState::OrgPassingreadsBookFind
}
StatefulBookState::OrgPassingreadsBookRegistration => {
StatefulBookState::OrgPassingreadsBookRegistration
}
StatefulBookState::Other(v) => StatefulBookState::Other(v.into_static()),
}
}
}
impl<S: BosStr> LexiconSchema for ConfirmedEvent<S> {
fn nsid() -> &'static str {
"org.passingreads.book.defs"
}
fn def_name() -> &'static str {
"confirmedEvent"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_org_passingreads_book_defs()
}
fn validate(&self) -> Result<(), ConstraintError> {
Ok(())
}
}
impl<S: BosStr> LexiconSchema for RegistrationView<S> {
fn nsid() -> &'static str {
"org.passingreads.book.defs"
}
fn def_name() -> &'static str {
"registrationView"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_org_passingreads_book_defs()
}
fn validate(&self) -> Result<(), ConstraintError> {
Ok(())
}
}
impl<S: BosStr> LexiconSchema for StatefulBook<S> {
fn nsid() -> &'static str {
"org.passingreads.book.defs"
}
fn def_name() -> &'static str {
"statefulBook"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_org_passingreads_book_defs()
}
fn validate(&self) -> Result<(), ConstraintError> {
Ok(())
}
}
pub mod confirmed_event_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 Event;
type Location;
type OccurredAt;
type Uri;
type Actor;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Event = Unset;
type Location = Unset;
type OccurredAt = Unset;
type Uri = Unset;
type Actor = Unset;
}
pub struct SetEvent<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetEvent<St> {}
impl<St: State> State for SetEvent<St> {
type Event = Set<members::event>;
type Location = St::Location;
type OccurredAt = St::OccurredAt;
type Uri = St::Uri;
type Actor = St::Actor;
}
pub struct SetLocation<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetLocation<St> {}
impl<St: State> State for SetLocation<St> {
type Event = St::Event;
type Location = Set<members::location>;
type OccurredAt = St::OccurredAt;
type Uri = St::Uri;
type Actor = St::Actor;
}
pub struct SetOccurredAt<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetOccurredAt<St> {}
impl<St: State> State for SetOccurredAt<St> {
type Event = St::Event;
type Location = St::Location;
type OccurredAt = Set<members::occurred_at>;
type Uri = St::Uri;
type Actor = St::Actor;
}
pub struct SetUri<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetUri<St> {}
impl<St: State> State for SetUri<St> {
type Event = St::Event;
type Location = St::Location;
type OccurredAt = St::OccurredAt;
type Uri = Set<members::uri>;
type Actor = St::Actor;
}
pub struct SetActor<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetActor<St> {}
impl<St: State> State for SetActor<St> {
type Event = St::Event;
type Location = St::Location;
type OccurredAt = St::OccurredAt;
type Uri = St::Uri;
type Actor = Set<members::actor>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct event(());
pub struct location(());
pub struct occurred_at(());
pub struct uri(());
pub struct actor(());
}
}
pub struct ConfirmedEventBuilder<S: BosStr, St: confirmed_event_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<Actor<S>>,
Option<ConfirmedEventEvent<S>>,
Option<Hthree<S>>,
Option<Datetime>,
Option<AtUri<S>>,
),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> ConfirmedEvent<S> {
pub fn new() -> ConfirmedEventBuilder<S, confirmed_event_state::Empty> {
ConfirmedEventBuilder::new()
}
}
impl<S: BosStr> ConfirmedEventBuilder<S, confirmed_event_state::Empty> {
pub fn new() -> Self {
ConfirmedEventBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St> ConfirmedEventBuilder<S, St>
where
St: confirmed_event_state::State,
St::Actor: confirmed_event_state::IsUnset,
{
pub fn actor(
mut self,
value: impl Into<Actor<S>>,
) -> ConfirmedEventBuilder<S, confirmed_event_state::SetActor<St>> {
self._fields.0 = Option::Some(value.into());
ConfirmedEventBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> ConfirmedEventBuilder<S, St>
where
St: confirmed_event_state::State,
St::Event: confirmed_event_state::IsUnset,
{
pub fn event(
mut self,
value: impl Into<ConfirmedEventEvent<S>>,
) -> ConfirmedEventBuilder<S, confirmed_event_state::SetEvent<St>> {
self._fields.1 = Option::Some(value.into());
ConfirmedEventBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> ConfirmedEventBuilder<S, St>
where
St: confirmed_event_state::State,
St::Location: confirmed_event_state::IsUnset,
{
pub fn location(
mut self,
value: impl Into<Hthree<S>>,
) -> ConfirmedEventBuilder<S, confirmed_event_state::SetLocation<St>> {
self._fields.2 = Option::Some(value.into());
ConfirmedEventBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> ConfirmedEventBuilder<S, St>
where
St: confirmed_event_state::State,
St::OccurredAt: confirmed_event_state::IsUnset,
{
pub fn occurred_at(
mut self,
value: impl Into<Datetime>,
) -> ConfirmedEventBuilder<S, confirmed_event_state::SetOccurredAt<St>> {
self._fields.3 = Option::Some(value.into());
ConfirmedEventBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> ConfirmedEventBuilder<S, St>
where
St: confirmed_event_state::State,
St::Uri: confirmed_event_state::IsUnset,
{
pub fn uri(
mut self,
value: impl Into<AtUri<S>>,
) -> ConfirmedEventBuilder<S, confirmed_event_state::SetUri<St>> {
self._fields.4 = Option::Some(value.into());
ConfirmedEventBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> ConfirmedEventBuilder<S, St>
where
St: confirmed_event_state::State,
St::Event: confirmed_event_state::IsSet,
St::Location: confirmed_event_state::IsSet,
St::OccurredAt: confirmed_event_state::IsSet,
St::Uri: confirmed_event_state::IsSet,
St::Actor: confirmed_event_state::IsSet,
{
pub fn build(self) -> ConfirmedEvent<S> {
ConfirmedEvent {
actor: self._fields.0.unwrap(),
event: self._fields.1.unwrap(),
location: self._fields.2.unwrap(),
occurred_at: self._fields.3.unwrap(),
uri: self._fields.4.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> ConfirmedEvent<S> {
ConfirmedEvent {
actor: self._fields.0.unwrap(),
event: self._fields.1.unwrap(),
location: self._fields.2.unwrap(),
occurred_at: self._fields.3.unwrap(),
uri: self._fields.4.unwrap(),
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_org_passingreads_book_defs() -> 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("org.passingreads.book.defs"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("confirmedEvent"),
LexUserType::Object(LexObject {
description: Some(
CowStr::new_static(
"A confirmed book event for display purposes. Omits cryptographic fields (bookPub, bookSig) and book reference since it's shown in context of a book.",
),
),
required: Some(
vec![
SmolStr::new_static("uri"), SmolStr::new_static("actor"),
SmolStr::new_static("event"),
SmolStr::new_static("location"),
SmolStr::new_static("occurredAt")
],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("actor"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static("org.passingreads.defs#actor"),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("event"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("What event occurred"),
),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("location"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static(
"community.lexicon.location.hthree#main",
),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("occurredAt"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("When this event occurred"),
),
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("uri"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("The AT URI of this event record"),
),
format: Some(LexStringFormat::AtUri),
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map.insert(
SmolStr::new_static("registrationView"),
LexUserType::Object(LexObject {
description: Some(
CowStr::new_static(
"A view of a book registration for API responses. Omits cryptographic fields (bookPub, bookSig) and the cover blob.",
),
),
required: Some(
vec![
SmolStr::new_static("registeredBy"),
SmolStr::new_static("bookId"), SmolStr::new_static("title"),
SmolStr::new_static("authors"),
SmolStr::new_static("occurredAt")
],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("authors"),
LexObjectProperty::Array(LexArray {
description: Some(
CowStr::new_static(
"Authors of this book, in order of credit",
),
),
items: LexArrayItem::String(LexString {
..Default::default()
}),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("bookId"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"The book's ID (as defined on its QR Code)",
),
),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("occurredAt"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("When the book was registered"),
),
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("publicationId"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("The book's Open Library Edition ID"),
),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("registeredBy"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static("org.passingreads.defs#actor"),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("title"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("The title of the book"),
),
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map.insert(
SmolStr::new_static("statefulBook"),
LexUserType::Object(LexObject {
description: Some(
CowStr::new_static(
"A book with its current state, combining registration data with computed state information.",
),
),
required: Some(
vec![
SmolStr::new_static("uri"), SmolStr::new_static("cid"),
SmolStr::new_static("registration"),
SmolStr::new_static("state"),
SmolStr::new_static("currentHolder")
],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("aspectRatio"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static(
"org.passingreads.defs#aspectRatio",
),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("cid"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"The CID of the book registration record",
),
),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("coverUrl"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Resolved URL to the cover image (from the registration blob)",
),
),
format: Some(LexStringFormat::Uri),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("currentHolder"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"The DID of the current holder of the book",
),
),
format: Some(LexStringFormat::Did),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("currentLocation"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static(
"community.lexicon.location.hthree#main",
),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("events"),
LexObjectProperty::Array(LexArray {
description: Some(
CowStr::new_static(
"List of confirmed events for this book, in chronological order",
),
),
items: LexArrayItem::Ref(LexRef {
r#ref: CowStr::new_static("#confirmedEvent"),
..Default::default()
}),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("registration"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static("#registrationView"),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("state"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"The current state of the book, derived from the latest event",
),
),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("uri"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"The AT URI of the book registration record",
),
),
format: Some(LexStringFormat::AtUri),
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map
},
..Default::default()
}
}
pub mod registration_view_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 BookId;
type Authors;
type OccurredAt;
type Title;
type RegisteredBy;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type BookId = Unset;
type Authors = Unset;
type OccurredAt = Unset;
type Title = Unset;
type RegisteredBy = Unset;
}
pub struct SetBookId<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetBookId<St> {}
impl<St: State> State for SetBookId<St> {
type BookId = Set<members::book_id>;
type Authors = St::Authors;
type OccurredAt = St::OccurredAt;
type Title = St::Title;
type RegisteredBy = St::RegisteredBy;
}
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 BookId = St::BookId;
type Authors = Set<members::authors>;
type OccurredAt = St::OccurredAt;
type Title = St::Title;
type RegisteredBy = St::RegisteredBy;
}
pub struct SetOccurredAt<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetOccurredAt<St> {}
impl<St: State> State for SetOccurredAt<St> {
type BookId = St::BookId;
type Authors = St::Authors;
type OccurredAt = Set<members::occurred_at>;
type Title = St::Title;
type RegisteredBy = St::RegisteredBy;
}
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 BookId = St::BookId;
type Authors = St::Authors;
type OccurredAt = St::OccurredAt;
type Title = Set<members::title>;
type RegisteredBy = St::RegisteredBy;
}
pub struct SetRegisteredBy<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetRegisteredBy<St> {}
impl<St: State> State for SetRegisteredBy<St> {
type BookId = St::BookId;
type Authors = St::Authors;
type OccurredAt = St::OccurredAt;
type Title = St::Title;
type RegisteredBy = Set<members::registered_by>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct book_id(());
pub struct authors(());
pub struct occurred_at(());
pub struct title(());
pub struct registered_by(());
}
}
pub struct RegistrationViewBuilder<S: BosStr, St: registration_view_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<Vec<S>>,
Option<S>,
Option<Datetime>,
Option<S>,
Option<Actor<S>>,
Option<S>,
),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> RegistrationView<S> {
pub fn new() -> RegistrationViewBuilder<S, registration_view_state::Empty> {
RegistrationViewBuilder::new()
}
}
impl<S: BosStr> RegistrationViewBuilder<S, registration_view_state::Empty> {
pub fn new() -> Self {
RegistrationViewBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St> RegistrationViewBuilder<S, St>
where
St: registration_view_state::State,
St::Authors: registration_view_state::IsUnset,
{
pub fn authors(
mut self,
value: impl Into<Vec<S>>,
) -> RegistrationViewBuilder<S, registration_view_state::SetAuthors<St>> {
self._fields.0 = Option::Some(value.into());
RegistrationViewBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> RegistrationViewBuilder<S, St>
where
St: registration_view_state::State,
St::BookId: registration_view_state::IsUnset,
{
pub fn book_id(
mut self,
value: impl Into<S>,
) -> RegistrationViewBuilder<S, registration_view_state::SetBookId<St>> {
self._fields.1 = Option::Some(value.into());
RegistrationViewBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> RegistrationViewBuilder<S, St>
where
St: registration_view_state::State,
St::OccurredAt: registration_view_state::IsUnset,
{
pub fn occurred_at(
mut self,
value: impl Into<Datetime>,
) -> RegistrationViewBuilder<S, registration_view_state::SetOccurredAt<St>> {
self._fields.2 = Option::Some(value.into());
RegistrationViewBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: registration_view_state::State> RegistrationViewBuilder<S, St> {
pub fn publication_id(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.3 = value.into();
self
}
pub fn maybe_publication_id(mut self, value: Option<S>) -> Self {
self._fields.3 = value;
self
}
}
impl<S: BosStr, St> RegistrationViewBuilder<S, St>
where
St: registration_view_state::State,
St::RegisteredBy: registration_view_state::IsUnset,
{
pub fn registered_by(
mut self,
value: impl Into<Actor<S>>,
) -> RegistrationViewBuilder<S, registration_view_state::SetRegisteredBy<St>> {
self._fields.4 = Option::Some(value.into());
RegistrationViewBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> RegistrationViewBuilder<S, St>
where
St: registration_view_state::State,
St::Title: registration_view_state::IsUnset,
{
pub fn title(
mut self,
value: impl Into<S>,
) -> RegistrationViewBuilder<S, registration_view_state::SetTitle<St>> {
self._fields.5 = Option::Some(value.into());
RegistrationViewBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> RegistrationViewBuilder<S, St>
where
St: registration_view_state::State,
St::BookId: registration_view_state::IsSet,
St::Authors: registration_view_state::IsSet,
St::OccurredAt: registration_view_state::IsSet,
St::Title: registration_view_state::IsSet,
St::RegisteredBy: registration_view_state::IsSet,
{
pub fn build(self) -> RegistrationView<S> {
RegistrationView {
authors: self._fields.0.unwrap(),
book_id: self._fields.1.unwrap(),
occurred_at: self._fields.2.unwrap(),
publication_id: self._fields.3,
registered_by: self._fields.4.unwrap(),
title: self._fields.5.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> RegistrationView<S> {
RegistrationView {
authors: self._fields.0.unwrap(),
book_id: self._fields.1.unwrap(),
occurred_at: self._fields.2.unwrap(),
publication_id: self._fields.3,
registered_by: self._fields.4.unwrap(),
title: self._fields.5.unwrap(),
extra_data: Some(extra_data),
}
}
}
pub mod stateful_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 Cid;
type Registration;
type Uri;
type State;
type CurrentHolder;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Cid = Unset;
type Registration = Unset;
type Uri = Unset;
type State = Unset;
type CurrentHolder = Unset;
}
pub struct SetCid<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetCid<St> {}
impl<St: State> State for SetCid<St> {
type Cid = Set<members::cid>;
type Registration = St::Registration;
type Uri = St::Uri;
type State = St::State;
type CurrentHolder = St::CurrentHolder;
}
pub struct SetRegistration<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetRegistration<St> {}
impl<St: State> State for SetRegistration<St> {
type Cid = St::Cid;
type Registration = Set<members::registration>;
type Uri = St::Uri;
type State = St::State;
type CurrentHolder = St::CurrentHolder;
}
pub struct SetUri<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetUri<St> {}
impl<St: State> State for SetUri<St> {
type Cid = St::Cid;
type Registration = St::Registration;
type Uri = Set<members::uri>;
type State = St::State;
type CurrentHolder = St::CurrentHolder;
}
pub struct SetState<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetState<St> {}
impl<St: State> State for SetState<St> {
type Cid = St::Cid;
type Registration = St::Registration;
type Uri = St::Uri;
type State = Set<members::state>;
type CurrentHolder = St::CurrentHolder;
}
pub struct SetCurrentHolder<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetCurrentHolder<St> {}
impl<St: State> State for SetCurrentHolder<St> {
type Cid = St::Cid;
type Registration = St::Registration;
type Uri = St::Uri;
type State = St::State;
type CurrentHolder = Set<members::current_holder>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct cid(());
pub struct registration(());
pub struct uri(());
pub struct state(());
pub struct current_holder(());
}
}
pub struct StatefulBookBuilder<S: BosStr, St: stateful_book_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<AspectRatio<S>>,
Option<S>,
Option<UriValue<S>>,
Option<Did<S>>,
Option<Hthree<S>>,
Option<Vec<book::ConfirmedEvent<S>>>,
Option<book::RegistrationView<S>>,
Option<StatefulBookState<S>>,
Option<AtUri<S>>,
),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> StatefulBook<S> {
pub fn new() -> StatefulBookBuilder<S, stateful_book_state::Empty> {
StatefulBookBuilder::new()
}
}
impl<S: BosStr> StatefulBookBuilder<S, stateful_book_state::Empty> {
pub fn new() -> Self {
StatefulBookBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None, None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St: stateful_book_state::State> StatefulBookBuilder<S, St> {
pub fn aspect_ratio(mut self, value: impl Into<Option<AspectRatio<S>>>) -> Self {
self._fields.0 = value.into();
self
}
pub fn maybe_aspect_ratio(mut self, value: Option<AspectRatio<S>>) -> Self {
self._fields.0 = value;
self
}
}
impl<S: BosStr, St> StatefulBookBuilder<S, St>
where
St: stateful_book_state::State,
St::Cid: stateful_book_state::IsUnset,
{
pub fn cid(
mut self,
value: impl Into<S>,
) -> StatefulBookBuilder<S, stateful_book_state::SetCid<St>> {
self._fields.1 = Option::Some(value.into());
StatefulBookBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: stateful_book_state::State> StatefulBookBuilder<S, St> {
pub fn cover_url(mut self, value: impl Into<Option<UriValue<S>>>) -> Self {
self._fields.2 = value.into();
self
}
pub fn maybe_cover_url(mut self, value: Option<UriValue<S>>) -> Self {
self._fields.2 = value;
self
}
}
impl<S: BosStr, St> StatefulBookBuilder<S, St>
where
St: stateful_book_state::State,
St::CurrentHolder: stateful_book_state::IsUnset,
{
pub fn current_holder(
mut self,
value: impl Into<Did<S>>,
) -> StatefulBookBuilder<S, stateful_book_state::SetCurrentHolder<St>> {
self._fields.3 = Option::Some(value.into());
StatefulBookBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: stateful_book_state::State> StatefulBookBuilder<S, St> {
pub fn current_location(mut self, value: impl Into<Option<Hthree<S>>>) -> Self {
self._fields.4 = value.into();
self
}
pub fn maybe_current_location(mut self, value: Option<Hthree<S>>) -> Self {
self._fields.4 = value;
self
}
}
impl<S: BosStr, St: stateful_book_state::State> StatefulBookBuilder<S, St> {
pub fn events(mut self, value: impl Into<Option<Vec<book::ConfirmedEvent<S>>>>) -> Self {
self._fields.5 = value.into();
self
}
pub fn maybe_events(mut self, value: Option<Vec<book::ConfirmedEvent<S>>>) -> Self {
self._fields.5 = value;
self
}
}
impl<S: BosStr, St> StatefulBookBuilder<S, St>
where
St: stateful_book_state::State,
St::Registration: stateful_book_state::IsUnset,
{
pub fn registration(
mut self,
value: impl Into<book::RegistrationView<S>>,
) -> StatefulBookBuilder<S, stateful_book_state::SetRegistration<St>> {
self._fields.6 = Option::Some(value.into());
StatefulBookBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> StatefulBookBuilder<S, St>
where
St: stateful_book_state::State,
St::State: stateful_book_state::IsUnset,
{
pub fn state(
mut self,
value: impl Into<StatefulBookState<S>>,
) -> StatefulBookBuilder<S, stateful_book_state::SetState<St>> {
self._fields.7 = Option::Some(value.into());
StatefulBookBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> StatefulBookBuilder<S, St>
where
St: stateful_book_state::State,
St::Uri: stateful_book_state::IsUnset,
{
pub fn uri(
mut self,
value: impl Into<AtUri<S>>,
) -> StatefulBookBuilder<S, stateful_book_state::SetUri<St>> {
self._fields.8 = Option::Some(value.into());
StatefulBookBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> StatefulBookBuilder<S, St>
where
St: stateful_book_state::State,
St::Cid: stateful_book_state::IsSet,
St::Registration: stateful_book_state::IsSet,
St::Uri: stateful_book_state::IsSet,
St::State: stateful_book_state::IsSet,
St::CurrentHolder: stateful_book_state::IsSet,
{
pub fn build(self) -> StatefulBook<S> {
StatefulBook {
aspect_ratio: self._fields.0,
cid: self._fields.1.unwrap(),
cover_url: self._fields.2,
current_holder: self._fields.3.unwrap(),
current_location: self._fields.4,
events: self._fields.5,
registration: self._fields.6.unwrap(),
state: self._fields.7.unwrap(),
uri: self._fields.8.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> StatefulBook<S> {
StatefulBook {
aspect_ratio: self._fields.0,
cid: self._fields.1.unwrap(),
cover_url: self._fields.2,
current_holder: self._fields.3.unwrap(),
current_location: self._fields.4,
events: self._fields.5,
registration: self._fields.6.unwrap(),
state: self._fields.7.unwrap(),
uri: self._fields.8.unwrap(),
extra_data: Some(extra_data),
}
}
}