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::CowStr;
#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::types::string::{Did, AtUri, Datetime, UriValue};
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::community_lexicon::location::hthree::Hthree;
use crate::org_passingreads::Actor;
use crate::org_passingreads::AspectRatio;
use crate::org_passingreads::book;
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct ConfirmedEvent<'a> {
#[serde(borrow)]
pub actor: Actor<'a>,
#[serde(borrow)]
pub event: ConfirmedEventEvent<'a>,
#[serde(borrow)]
pub location: Hthree<'a>,
pub occurred_at: Datetime,
#[serde(borrow)]
pub uri: AtUri<'a>,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum ConfirmedEventEvent<'a> {
OrgPassingreadsBookCheckin,
OrgPassingreadsBookDrop,
OrgPassingreadsBookFind,
Other(CowStr<'a>),
}
impl<'a> ConfirmedEventEvent<'a> {
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(),
}
}
}
impl<'a> From<&'a str> for ConfirmedEventEvent<'a> {
fn from(s: &'a str) -> Self {
match s {
"org.passingreads.book.checkin" => Self::OrgPassingreadsBookCheckin,
"org.passingreads.book.drop" => Self::OrgPassingreadsBookDrop,
"org.passingreads.book.find" => Self::OrgPassingreadsBookFind,
_ => Self::Other(CowStr::from(s)),
}
}
}
impl<'a> From<String> for ConfirmedEventEvent<'a> {
fn from(s: String) -> Self {
match s.as_str() {
"org.passingreads.book.checkin" => Self::OrgPassingreadsBookCheckin,
"org.passingreads.book.drop" => Self::OrgPassingreadsBookDrop,
"org.passingreads.book.find" => Self::OrgPassingreadsBookFind,
_ => Self::Other(CowStr::from(s)),
}
}
}
impl<'a> core::fmt::Display for ConfirmedEventEvent<'a> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<'a> AsRef<str> for ConfirmedEventEvent<'a> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<'a> serde::Serialize for ConfirmedEventEvent<'a> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_str(self.as_str())
}
}
impl<'de, 'a> serde::Deserialize<'de> for ConfirmedEventEvent<'a>
where
'de: 'a,
{
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let s = <&'de str>::deserialize(deserializer)?;
Ok(Self::from(s))
}
}
impl<'a> Default for ConfirmedEventEvent<'a> {
fn default() -> Self {
Self::Other(Default::default())
}
}
impl jacquard_common::IntoStatic for ConfirmedEventEvent<'_> {
type Output = ConfirmedEventEvent<'static>;
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()),
}
}
}
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct RegistrationView<'a> {
#[serde(borrow)]
pub authors: Vec<CowStr<'a>>,
#[serde(borrow)]
pub book_id: CowStr<'a>,
pub occurred_at: Datetime,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub publication_id: Option<CowStr<'a>>,
#[serde(borrow)]
pub registered_by: Actor<'a>,
#[serde(borrow)]
pub title: CowStr<'a>,
}
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct StatefulBook<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub aspect_ratio: Option<AspectRatio<'a>>,
#[serde(borrow)]
pub cid: CowStr<'a>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub cover_url: Option<UriValue<'a>>,
#[serde(borrow)]
pub current_holder: Did<'a>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub current_location: Option<Hthree<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub events: Option<Vec<book::ConfirmedEvent<'a>>>,
#[serde(borrow)]
pub registration: book::RegistrationView<'a>,
#[serde(borrow)]
pub state: StatefulBookState<'a>,
#[serde(borrow)]
pub uri: AtUri<'a>,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum StatefulBookState<'a> {
OrgPassingreadsBookCheckin,
OrgPassingreadsBookDrop,
OrgPassingreadsBookFind,
OrgPassingreadsBookRegistration,
Other(CowStr<'a>),
}
impl<'a> StatefulBookState<'a> {
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(),
}
}
}
impl<'a> From<&'a str> for StatefulBookState<'a> {
fn from(s: &'a str) -> Self {
match s {
"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(CowStr::from(s)),
}
}
}
impl<'a> From<String> for StatefulBookState<'a> {
fn from(s: String) -> Self {
match s.as_str() {
"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(CowStr::from(s)),
}
}
}
impl<'a> core::fmt::Display for StatefulBookState<'a> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<'a> AsRef<str> for StatefulBookState<'a> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<'a> serde::Serialize for StatefulBookState<'a> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_str(self.as_str())
}
}
impl<'de, 'a> serde::Deserialize<'de> for StatefulBookState<'a>
where
'de: 'a,
{
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let s = <&'de str>::deserialize(deserializer)?;
Ok(Self::from(s))
}
}
impl<'a> Default for StatefulBookState<'a> {
fn default() -> Self {
Self::Other(Default::default())
}
}
impl jacquard_common::IntoStatic for StatefulBookState<'_> {
type Output = StatefulBookState<'static>;
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<'a> LexiconSchema for ConfirmedEvent<'a> {
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<'a> LexiconSchema for RegistrationView<'a> {
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<'a> LexiconSchema for StatefulBook<'a> {
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::{Set, Unset, IsSet, IsUnset};
#[allow(unused)]
use ::core::marker::PhantomData;
mod sealed {
pub trait Sealed {}
}
pub trait State: sealed::Sealed {
type Event;
type Actor;
type Uri;
type Location;
type OccurredAt;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Event = Unset;
type Actor = Unset;
type Uri = Unset;
type Location = Unset;
type OccurredAt = Unset;
}
pub struct SetEvent<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetEvent<S> {}
impl<S: State> State for SetEvent<S> {
type Event = Set<members::event>;
type Actor = S::Actor;
type Uri = S::Uri;
type Location = S::Location;
type OccurredAt = S::OccurredAt;
}
pub struct SetActor<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetActor<S> {}
impl<S: State> State for SetActor<S> {
type Event = S::Event;
type Actor = Set<members::actor>;
type Uri = S::Uri;
type Location = S::Location;
type OccurredAt = S::OccurredAt;
}
pub struct SetUri<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetUri<S> {}
impl<S: State> State for SetUri<S> {
type Event = S::Event;
type Actor = S::Actor;
type Uri = Set<members::uri>;
type Location = S::Location;
type OccurredAt = S::OccurredAt;
}
pub struct SetLocation<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetLocation<S> {}
impl<S: State> State for SetLocation<S> {
type Event = S::Event;
type Actor = S::Actor;
type Uri = S::Uri;
type Location = Set<members::location>;
type OccurredAt = S::OccurredAt;
}
pub struct SetOccurredAt<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetOccurredAt<S> {}
impl<S: State> State for SetOccurredAt<S> {
type Event = S::Event;
type Actor = S::Actor;
type Uri = S::Uri;
type Location = S::Location;
type OccurredAt = Set<members::occurred_at>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct event(());
pub struct actor(());
pub struct uri(());
pub struct location(());
pub struct occurred_at(());
}
}
pub struct ConfirmedEventBuilder<'a, S: confirmed_event_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (
Option<Actor<'a>>,
Option<ConfirmedEventEvent<'a>>,
Option<Hthree<'a>>,
Option<Datetime>,
Option<AtUri<'a>>,
),
_lifetime: PhantomData<&'a ()>,
}
impl<'a> ConfirmedEvent<'a> {
pub fn new() -> ConfirmedEventBuilder<'a, confirmed_event_state::Empty> {
ConfirmedEventBuilder::new()
}
}
impl<'a> ConfirmedEventBuilder<'a, confirmed_event_state::Empty> {
pub fn new() -> Self {
ConfirmedEventBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None),
_lifetime: PhantomData,
}
}
}
impl<'a, S> ConfirmedEventBuilder<'a, S>
where
S: confirmed_event_state::State,
S::Actor: confirmed_event_state::IsUnset,
{
pub fn actor(
mut self,
value: impl Into<Actor<'a>>,
) -> ConfirmedEventBuilder<'a, confirmed_event_state::SetActor<S>> {
self._fields.0 = Option::Some(value.into());
ConfirmedEventBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> ConfirmedEventBuilder<'a, S>
where
S: confirmed_event_state::State,
S::Event: confirmed_event_state::IsUnset,
{
pub fn event(
mut self,
value: impl Into<ConfirmedEventEvent<'a>>,
) -> ConfirmedEventBuilder<'a, confirmed_event_state::SetEvent<S>> {
self._fields.1 = Option::Some(value.into());
ConfirmedEventBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> ConfirmedEventBuilder<'a, S>
where
S: confirmed_event_state::State,
S::Location: confirmed_event_state::IsUnset,
{
pub fn location(
mut self,
value: impl Into<Hthree<'a>>,
) -> ConfirmedEventBuilder<'a, confirmed_event_state::SetLocation<S>> {
self._fields.2 = Option::Some(value.into());
ConfirmedEventBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> ConfirmedEventBuilder<'a, S>
where
S: confirmed_event_state::State,
S::OccurredAt: confirmed_event_state::IsUnset,
{
pub fn occurred_at(
mut self,
value: impl Into<Datetime>,
) -> ConfirmedEventBuilder<'a, confirmed_event_state::SetOccurredAt<S>> {
self._fields.3 = Option::Some(value.into());
ConfirmedEventBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> ConfirmedEventBuilder<'a, S>
where
S: confirmed_event_state::State,
S::Uri: confirmed_event_state::IsUnset,
{
pub fn uri(
mut self,
value: impl Into<AtUri<'a>>,
) -> ConfirmedEventBuilder<'a, confirmed_event_state::SetUri<S>> {
self._fields.4 = Option::Some(value.into());
ConfirmedEventBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> ConfirmedEventBuilder<'a, S>
where
S: confirmed_event_state::State,
S::Event: confirmed_event_state::IsSet,
S::Actor: confirmed_event_state::IsSet,
S::Uri: confirmed_event_state::IsSet,
S::Location: confirmed_event_state::IsSet,
S::OccurredAt: confirmed_event_state::IsSet,
{
pub fn build(self) -> ConfirmedEvent<'a> {
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<
jacquard_common::deps::smol_str::SmolStr,
jacquard_common::types::value::Data<'a>,
>,
) -> ConfirmedEvent<'a> {
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> {
#[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("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::{Set, Unset, IsSet, IsUnset};
#[allow(unused)]
use ::core::marker::PhantomData;
mod sealed {
pub trait Sealed {}
}
pub trait State: sealed::Sealed {
type Title;
type OccurredAt;
type Authors;
type RegisteredBy;
type BookId;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Title = Unset;
type OccurredAt = Unset;
type Authors = Unset;
type RegisteredBy = Unset;
type BookId = 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 OccurredAt = S::OccurredAt;
type Authors = S::Authors;
type RegisteredBy = S::RegisteredBy;
type BookId = S::BookId;
}
pub struct SetOccurredAt<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetOccurredAt<S> {}
impl<S: State> State for SetOccurredAt<S> {
type Title = S::Title;
type OccurredAt = Set<members::occurred_at>;
type Authors = S::Authors;
type RegisteredBy = S::RegisteredBy;
type BookId = S::BookId;
}
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 OccurredAt = S::OccurredAt;
type Authors = Set<members::authors>;
type RegisteredBy = S::RegisteredBy;
type BookId = S::BookId;
}
pub struct SetRegisteredBy<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetRegisteredBy<S> {}
impl<S: State> State for SetRegisteredBy<S> {
type Title = S::Title;
type OccurredAt = S::OccurredAt;
type Authors = S::Authors;
type RegisteredBy = Set<members::registered_by>;
type BookId = S::BookId;
}
pub struct SetBookId<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetBookId<S> {}
impl<S: State> State for SetBookId<S> {
type Title = S::Title;
type OccurredAt = S::OccurredAt;
type Authors = S::Authors;
type RegisteredBy = S::RegisteredBy;
type BookId = Set<members::book_id>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct title(());
pub struct occurred_at(());
pub struct authors(());
pub struct registered_by(());
pub struct book_id(());
}
}
pub struct RegistrationViewBuilder<'a, S: registration_view_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (
Option<Vec<CowStr<'a>>>,
Option<CowStr<'a>>,
Option<Datetime>,
Option<CowStr<'a>>,
Option<Actor<'a>>,
Option<CowStr<'a>>,
),
_lifetime: PhantomData<&'a ()>,
}
impl<'a> RegistrationView<'a> {
pub fn new() -> RegistrationViewBuilder<'a, registration_view_state::Empty> {
RegistrationViewBuilder::new()
}
}
impl<'a> RegistrationViewBuilder<'a, registration_view_state::Empty> {
pub fn new() -> Self {
RegistrationViewBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None),
_lifetime: PhantomData,
}
}
}
impl<'a, S> RegistrationViewBuilder<'a, S>
where
S: registration_view_state::State,
S::Authors: registration_view_state::IsUnset,
{
pub fn authors(
mut self,
value: impl Into<Vec<CowStr<'a>>>,
) -> RegistrationViewBuilder<'a, registration_view_state::SetAuthors<S>> {
self._fields.0 = Option::Some(value.into());
RegistrationViewBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> RegistrationViewBuilder<'a, S>
where
S: registration_view_state::State,
S::BookId: registration_view_state::IsUnset,
{
pub fn book_id(
mut self,
value: impl Into<CowStr<'a>>,
) -> RegistrationViewBuilder<'a, registration_view_state::SetBookId<S>> {
self._fields.1 = Option::Some(value.into());
RegistrationViewBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> RegistrationViewBuilder<'a, S>
where
S: registration_view_state::State,
S::OccurredAt: registration_view_state::IsUnset,
{
pub fn occurred_at(
mut self,
value: impl Into<Datetime>,
) -> RegistrationViewBuilder<'a, registration_view_state::SetOccurredAt<S>> {
self._fields.2 = Option::Some(value.into());
RegistrationViewBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S: registration_view_state::State> RegistrationViewBuilder<'a, S> {
pub fn publication_id(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
self._fields.3 = value.into();
self
}
pub fn maybe_publication_id(mut self, value: Option<CowStr<'a>>) -> Self {
self._fields.3 = value;
self
}
}
impl<'a, S> RegistrationViewBuilder<'a, S>
where
S: registration_view_state::State,
S::RegisteredBy: registration_view_state::IsUnset,
{
pub fn registered_by(
mut self,
value: impl Into<Actor<'a>>,
) -> RegistrationViewBuilder<'a, registration_view_state::SetRegisteredBy<S>> {
self._fields.4 = Option::Some(value.into());
RegistrationViewBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> RegistrationViewBuilder<'a, S>
where
S: registration_view_state::State,
S::Title: registration_view_state::IsUnset,
{
pub fn title(
mut self,
value: impl Into<CowStr<'a>>,
) -> RegistrationViewBuilder<'a, registration_view_state::SetTitle<S>> {
self._fields.5 = Option::Some(value.into());
RegistrationViewBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> RegistrationViewBuilder<'a, S>
where
S: registration_view_state::State,
S::Title: registration_view_state::IsSet,
S::OccurredAt: registration_view_state::IsSet,
S::Authors: registration_view_state::IsSet,
S::RegisteredBy: registration_view_state::IsSet,
S::BookId: registration_view_state::IsSet,
{
pub fn build(self) -> RegistrationView<'a> {
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<
jacquard_common::deps::smol_str::SmolStr,
jacquard_common::types::value::Data<'a>,
>,
) -> RegistrationView<'a> {
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::{Set, Unset, IsSet, IsUnset};
#[allow(unused)]
use ::core::marker::PhantomData;
mod sealed {
pub trait Sealed {}
}
pub trait State: sealed::Sealed {
type State;
type Registration;
type CurrentHolder;
type Uri;
type Cid;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type State = Unset;
type Registration = Unset;
type CurrentHolder = Unset;
type Uri = Unset;
type Cid = Unset;
}
pub struct SetState<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetState<S> {}
impl<S: State> State for SetState<S> {
type State = Set<members::state>;
type Registration = S::Registration;
type CurrentHolder = S::CurrentHolder;
type Uri = S::Uri;
type Cid = S::Cid;
}
pub struct SetRegistration<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetRegistration<S> {}
impl<S: State> State for SetRegistration<S> {
type State = S::State;
type Registration = Set<members::registration>;
type CurrentHolder = S::CurrentHolder;
type Uri = S::Uri;
type Cid = S::Cid;
}
pub struct SetCurrentHolder<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetCurrentHolder<S> {}
impl<S: State> State for SetCurrentHolder<S> {
type State = S::State;
type Registration = S::Registration;
type CurrentHolder = Set<members::current_holder>;
type Uri = S::Uri;
type Cid = S::Cid;
}
pub struct SetUri<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetUri<S> {}
impl<S: State> State for SetUri<S> {
type State = S::State;
type Registration = S::Registration;
type CurrentHolder = S::CurrentHolder;
type Uri = Set<members::uri>;
type Cid = S::Cid;
}
pub struct SetCid<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetCid<S> {}
impl<S: State> State for SetCid<S> {
type State = S::State;
type Registration = S::Registration;
type CurrentHolder = S::CurrentHolder;
type Uri = S::Uri;
type Cid = Set<members::cid>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct state(());
pub struct registration(());
pub struct current_holder(());
pub struct uri(());
pub struct cid(());
}
}
pub struct StatefulBookBuilder<'a, S: stateful_book_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (
Option<AspectRatio<'a>>,
Option<CowStr<'a>>,
Option<UriValue<'a>>,
Option<Did<'a>>,
Option<Hthree<'a>>,
Option<Vec<book::ConfirmedEvent<'a>>>,
Option<book::RegistrationView<'a>>,
Option<StatefulBookState<'a>>,
Option<AtUri<'a>>,
),
_lifetime: PhantomData<&'a ()>,
}
impl<'a> StatefulBook<'a> {
pub fn new() -> StatefulBookBuilder<'a, stateful_book_state::Empty> {
StatefulBookBuilder::new()
}
}
impl<'a> StatefulBookBuilder<'a, stateful_book_state::Empty> {
pub fn new() -> Self {
StatefulBookBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None, None, None, None),
_lifetime: PhantomData,
}
}
}
impl<'a, S: stateful_book_state::State> StatefulBookBuilder<'a, S> {
pub fn aspect_ratio(mut self, value: impl Into<Option<AspectRatio<'a>>>) -> Self {
self._fields.0 = value.into();
self
}
pub fn maybe_aspect_ratio(mut self, value: Option<AspectRatio<'a>>) -> Self {
self._fields.0 = value;
self
}
}
impl<'a, S> StatefulBookBuilder<'a, S>
where
S: stateful_book_state::State,
S::Cid: stateful_book_state::IsUnset,
{
pub fn cid(
mut self,
value: impl Into<CowStr<'a>>,
) -> StatefulBookBuilder<'a, stateful_book_state::SetCid<S>> {
self._fields.1 = Option::Some(value.into());
StatefulBookBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S: stateful_book_state::State> StatefulBookBuilder<'a, S> {
pub fn cover_url(mut self, value: impl Into<Option<UriValue<'a>>>) -> Self {
self._fields.2 = value.into();
self
}
pub fn maybe_cover_url(mut self, value: Option<UriValue<'a>>) -> Self {
self._fields.2 = value;
self
}
}
impl<'a, S> StatefulBookBuilder<'a, S>
where
S: stateful_book_state::State,
S::CurrentHolder: stateful_book_state::IsUnset,
{
pub fn current_holder(
mut self,
value: impl Into<Did<'a>>,
) -> StatefulBookBuilder<'a, stateful_book_state::SetCurrentHolder<S>> {
self._fields.3 = Option::Some(value.into());
StatefulBookBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S: stateful_book_state::State> StatefulBookBuilder<'a, S> {
pub fn current_location(mut self, value: impl Into<Option<Hthree<'a>>>) -> Self {
self._fields.4 = value.into();
self
}
pub fn maybe_current_location(mut self, value: Option<Hthree<'a>>) -> Self {
self._fields.4 = value;
self
}
}
impl<'a, S: stateful_book_state::State> StatefulBookBuilder<'a, S> {
pub fn events(
mut self,
value: impl Into<Option<Vec<book::ConfirmedEvent<'a>>>>,
) -> Self {
self._fields.5 = value.into();
self
}
pub fn maybe_events(mut self, value: Option<Vec<book::ConfirmedEvent<'a>>>) -> Self {
self._fields.5 = value;
self
}
}
impl<'a, S> StatefulBookBuilder<'a, S>
where
S: stateful_book_state::State,
S::Registration: stateful_book_state::IsUnset,
{
pub fn registration(
mut self,
value: impl Into<book::RegistrationView<'a>>,
) -> StatefulBookBuilder<'a, stateful_book_state::SetRegistration<S>> {
self._fields.6 = Option::Some(value.into());
StatefulBookBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> StatefulBookBuilder<'a, S>
where
S: stateful_book_state::State,
S::State: stateful_book_state::IsUnset,
{
pub fn state(
mut self,
value: impl Into<StatefulBookState<'a>>,
) -> StatefulBookBuilder<'a, stateful_book_state::SetState<S>> {
self._fields.7 = Option::Some(value.into());
StatefulBookBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> StatefulBookBuilder<'a, S>
where
S: stateful_book_state::State,
S::Uri: stateful_book_state::IsUnset,
{
pub fn uri(
mut self,
value: impl Into<AtUri<'a>>,
) -> StatefulBookBuilder<'a, stateful_book_state::SetUri<S>> {
self._fields.8 = Option::Some(value.into());
StatefulBookBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> StatefulBookBuilder<'a, S>
where
S: stateful_book_state::State,
S::State: stateful_book_state::IsSet,
S::Registration: stateful_book_state::IsSet,
S::CurrentHolder: stateful_book_state::IsSet,
S::Uri: stateful_book_state::IsSet,
S::Cid: stateful_book_state::IsSet,
{
pub fn build(self) -> StatefulBook<'a> {
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<
jacquard_common::deps::smol_str::SmolStr,
jacquard_common::types::value::Data<'a>,
>,
) -> StatefulBook<'a> {
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),
}
}
}