#[allow(unused_imports)]
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::{CowStr, BosStr, 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::{Did, 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;
#[allow(unused_imports)]
use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
use serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
rename_all = "camelCase",
rename = "world.ptah.temp.lore",
tag = "$type",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Lore<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub authorship_record: Option<Did<S>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub canonical_status: Option<LoreCanonicalStatus<S>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub characters: Option<Vec<AtUri<S>>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub content: Option<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub contribution_type: Option<LoreContributionType<S>>,
pub created_at: Datetime,
pub creator_did: Did<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub source_references: Option<Vec<AtUri<S>>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub timeline_position: Option<S>,
pub title: S,
pub world_reference: 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 LoreCanonicalStatus<S: BosStr = DefaultStr> {
CanonicalStatusOfficial,
CanonicalStatusCommunity,
CanonicalStatusApocryphal,
Other(S),
}
impl<S: BosStr> LoreCanonicalStatus<S> {
pub fn as_str(&self) -> &str {
match self {
Self::CanonicalStatusOfficial => {
"world.ptah.temp.defs#canonicalStatusOfficial"
}
Self::CanonicalStatusCommunity => {
"world.ptah.temp.defs#canonicalStatusCommunity"
}
Self::CanonicalStatusApocryphal => {
"world.ptah.temp.defs#canonicalStatusApocryphal"
}
Self::Other(s) => s.as_ref(),
}
}
pub fn from_value(s: S) -> Self {
match s.as_ref() {
"world.ptah.temp.defs#canonicalStatusOfficial" => {
Self::CanonicalStatusOfficial
}
"world.ptah.temp.defs#canonicalStatusCommunity" => {
Self::CanonicalStatusCommunity
}
"world.ptah.temp.defs#canonicalStatusApocryphal" => {
Self::CanonicalStatusApocryphal
}
_ => Self::Other(s),
}
}
}
impl<S: BosStr> core::fmt::Display for LoreCanonicalStatus<S> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<S: BosStr> AsRef<str> for LoreCanonicalStatus<S> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<S: BosStr> Serialize for LoreCanonicalStatus<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 LoreCanonicalStatus<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 LoreCanonicalStatus<S> {
fn default() -> Self {
Self::Other(Default::default())
}
}
impl<S: BosStr> jacquard_common::IntoStatic for LoreCanonicalStatus<S>
where
S: BosStr + jacquard_common::IntoStatic,
S::Output: BosStr,
{
type Output = LoreCanonicalStatus<S::Output>;
fn into_static(self) -> Self::Output {
match self {
LoreCanonicalStatus::CanonicalStatusOfficial => {
LoreCanonicalStatus::CanonicalStatusOfficial
}
LoreCanonicalStatus::CanonicalStatusCommunity => {
LoreCanonicalStatus::CanonicalStatusCommunity
}
LoreCanonicalStatus::CanonicalStatusApocryphal => {
LoreCanonicalStatus::CanonicalStatusApocryphal
}
LoreCanonicalStatus::Other(v) => LoreCanonicalStatus::Other(v.into_static()),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum LoreContributionType<S: BosStr = DefaultStr> {
Originator,
Community,
Other(S),
}
impl<S: BosStr> LoreContributionType<S> {
pub fn as_str(&self) -> &str {
match self {
Self::Originator => "originator",
Self::Community => "community",
Self::Other(s) => s.as_ref(),
}
}
pub fn from_value(s: S) -> Self {
match s.as_ref() {
"originator" => Self::Originator,
"community" => Self::Community,
_ => Self::Other(s),
}
}
}
impl<S: BosStr> core::fmt::Display for LoreContributionType<S> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<S: BosStr> AsRef<str> for LoreContributionType<S> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<S: BosStr> Serialize for LoreContributionType<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 LoreContributionType<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 LoreContributionType<S> {
fn default() -> Self {
Self::Other(Default::default())
}
}
impl<S: BosStr> jacquard_common::IntoStatic for LoreContributionType<S>
where
S: BosStr + jacquard_common::IntoStatic,
S::Output: BosStr,
{
type Output = LoreContributionType<S::Output>;
fn into_static(self) -> Self::Output {
match self {
LoreContributionType::Originator => LoreContributionType::Originator,
LoreContributionType::Community => LoreContributionType::Community,
LoreContributionType::Other(v) => {
LoreContributionType::Other(v.into_static())
}
}
}
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct LoreGetRecordOutput<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub cid: Option<Cid<S>>,
pub uri: AtUri<S>,
pub value: Lore<S>,
}
impl<S: BosStr> Lore<S> {
pub fn uri(uri: S) -> Result<RecordUri<S, LoreRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new(uri)?)
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct LoreRecord;
impl XrpcResp for LoreRecord {
const NSID: &'static str = "world.ptah.temp.lore";
const ENCODING: &'static str = "application/json";
type Output<S: BosStr> = LoreGetRecordOutput<S>;
type Err = RecordError;
}
impl<S: BosStr> From<LoreGetRecordOutput<S>> for Lore<S> {
fn from(output: LoreGetRecordOutput<S>) -> Self {
output.value
}
}
impl<S: BosStr> Collection for Lore<S> {
const NSID: &'static str = "world.ptah.temp.lore";
type Record = LoreRecord;
}
impl Collection for LoreRecord {
const NSID: &'static str = "world.ptah.temp.lore";
type Record = LoreRecord;
}
impl<S: BosStr> LexiconSchema for Lore<S> {
fn nsid() -> &'static str {
"world.ptah.temp.lore"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_world_ptah_temp_lore()
}
fn validate(&self) -> Result<(), ConstraintError> {
if let Some(ref value) = self.content {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 102400usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("content"),
max: 102400usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.content {
{
let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
if count > 10000usize {
return Err(ConstraintError::MaxGraphemes {
path: ValidationPath::from_field("content"),
max: 10000usize,
actual: count,
});
}
}
}
if let Some(ref value) = self.timeline_position {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 2560usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("timeline_position"),
max: 2560usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.timeline_position {
{
let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
if count > 256usize {
return Err(ConstraintError::MaxGraphemes {
path: ValidationPath::from_field("timeline_position"),
max: 256usize,
actual: count,
});
}
}
}
{
let value = &self.title;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 640usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("title"),
max: 640usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.title;
{
let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
if count > 64usize {
return Err(ConstraintError::MaxGraphemes {
path: ValidationPath::from_field("title"),
max: 64usize,
actual: count,
});
}
}
}
Ok(())
}
}
pub mod lore_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 CreatorDid;
type WorldReference;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Title = Unset;
type CreatedAt = Unset;
type CreatorDid = Unset;
type WorldReference = Unset;
}
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 Title = Set<members::title>;
type CreatedAt = St::CreatedAt;
type CreatorDid = St::CreatorDid;
type WorldReference = St::WorldReference;
}
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 Title = St::Title;
type CreatedAt = Set<members::created_at>;
type CreatorDid = St::CreatorDid;
type WorldReference = St::WorldReference;
}
pub struct SetCreatorDid<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetCreatorDid<St> {}
impl<St: State> State for SetCreatorDid<St> {
type Title = St::Title;
type CreatedAt = St::CreatedAt;
type CreatorDid = Set<members::creator_did>;
type WorldReference = St::WorldReference;
}
pub struct SetWorldReference<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetWorldReference<St> {}
impl<St: State> State for SetWorldReference<St> {
type Title = St::Title;
type CreatedAt = St::CreatedAt;
type CreatorDid = St::CreatorDid;
type WorldReference = Set<members::world_reference>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct title(());
pub struct created_at(());
pub struct creator_did(());
pub struct world_reference(());
}
}
pub struct LoreBuilder<S: BosStr, St: lore_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<Did<S>>,
Option<LoreCanonicalStatus<S>>,
Option<Vec<AtUri<S>>>,
Option<S>,
Option<LoreContributionType<S>>,
Option<Datetime>,
Option<Did<S>>,
Option<Vec<AtUri<S>>>,
Option<S>,
Option<S>,
Option<AtUri<S>>,
),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> Lore<S> {
pub fn new() -> LoreBuilder<S, lore_state::Empty> {
LoreBuilder::new()
}
}
impl<S: BosStr> LoreBuilder<S, lore_state::Empty> {
pub fn new() -> Self {
LoreBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None, None, None, None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St: lore_state::State> LoreBuilder<S, St> {
pub fn authorship_record(mut self, value: impl Into<Option<Did<S>>>) -> Self {
self._fields.0 = value.into();
self
}
pub fn maybe_authorship_record(mut self, value: Option<Did<S>>) -> Self {
self._fields.0 = value;
self
}
}
impl<S: BosStr, St: lore_state::State> LoreBuilder<S, St> {
pub fn canonical_status(
mut self,
value: impl Into<Option<LoreCanonicalStatus<S>>>,
) -> Self {
self._fields.1 = value.into();
self
}
pub fn maybe_canonical_status(
mut self,
value: Option<LoreCanonicalStatus<S>>,
) -> Self {
self._fields.1 = value;
self
}
}
impl<S: BosStr, St: lore_state::State> LoreBuilder<S, St> {
pub fn characters(mut self, value: impl Into<Option<Vec<AtUri<S>>>>) -> Self {
self._fields.2 = value.into();
self
}
pub fn maybe_characters(mut self, value: Option<Vec<AtUri<S>>>) -> Self {
self._fields.2 = value;
self
}
}
impl<S: BosStr, St: lore_state::State> LoreBuilder<S, St> {
pub fn content(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.3 = value.into();
self
}
pub fn maybe_content(mut self, value: Option<S>) -> Self {
self._fields.3 = value;
self
}
}
impl<S: BosStr, St: lore_state::State> LoreBuilder<S, St> {
pub fn contribution_type(
mut self,
value: impl Into<Option<LoreContributionType<S>>>,
) -> Self {
self._fields.4 = value.into();
self
}
pub fn maybe_contribution_type(
mut self,
value: Option<LoreContributionType<S>>,
) -> Self {
self._fields.4 = value;
self
}
}
impl<S: BosStr, St> LoreBuilder<S, St>
where
St: lore_state::State,
St::CreatedAt: lore_state::IsUnset,
{
pub fn created_at(
mut self,
value: impl Into<Datetime>,
) -> LoreBuilder<S, lore_state::SetCreatedAt<St>> {
self._fields.5 = Option::Some(value.into());
LoreBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> LoreBuilder<S, St>
where
St: lore_state::State,
St::CreatorDid: lore_state::IsUnset,
{
pub fn creator_did(
mut self,
value: impl Into<Did<S>>,
) -> LoreBuilder<S, lore_state::SetCreatorDid<St>> {
self._fields.6 = Option::Some(value.into());
LoreBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: lore_state::State> LoreBuilder<S, St> {
pub fn source_references(mut self, value: impl Into<Option<Vec<AtUri<S>>>>) -> Self {
self._fields.7 = value.into();
self
}
pub fn maybe_source_references(mut self, value: Option<Vec<AtUri<S>>>) -> Self {
self._fields.7 = value;
self
}
}
impl<S: BosStr, St: lore_state::State> LoreBuilder<S, St> {
pub fn timeline_position(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.8 = value.into();
self
}
pub fn maybe_timeline_position(mut self, value: Option<S>) -> Self {
self._fields.8 = value;
self
}
}
impl<S: BosStr, St> LoreBuilder<S, St>
where
St: lore_state::State,
St::Title: lore_state::IsUnset,
{
pub fn title(
mut self,
value: impl Into<S>,
) -> LoreBuilder<S, lore_state::SetTitle<St>> {
self._fields.9 = Option::Some(value.into());
LoreBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> LoreBuilder<S, St>
where
St: lore_state::State,
St::WorldReference: lore_state::IsUnset,
{
pub fn world_reference(
mut self,
value: impl Into<AtUri<S>>,
) -> LoreBuilder<S, lore_state::SetWorldReference<St>> {
self._fields.10 = Option::Some(value.into());
LoreBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> LoreBuilder<S, St>
where
St: lore_state::State,
St::Title: lore_state::IsSet,
St::CreatedAt: lore_state::IsSet,
St::CreatorDid: lore_state::IsSet,
St::WorldReference: lore_state::IsSet,
{
pub fn build(self) -> Lore<S> {
Lore {
authorship_record: self._fields.0,
canonical_status: self._fields.1,
characters: self._fields.2,
content: self._fields.3,
contribution_type: self._fields.4,
created_at: self._fields.5.unwrap(),
creator_did: self._fields.6.unwrap(),
source_references: self._fields.7,
timeline_position: self._fields.8,
title: self._fields.9.unwrap(),
world_reference: self._fields.10.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Lore<S> {
Lore {
authorship_record: self._fields.0,
canonical_status: self._fields.1,
characters: self._fields.2,
content: self._fields.3,
contribution_type: self._fields.4,
created_at: self._fields.5.unwrap(),
creator_did: self._fields.6.unwrap(),
source_references: self._fields.7,
timeline_position: self._fields.8,
title: self._fields.9.unwrap(),
world_reference: self._fields.10.unwrap(),
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_world_ptah_temp_lore() -> 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("world.ptah.temp.lore"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("main"),
LexUserType::Record(LexRecord {
description: Some(
CowStr::new_static(
"The Shabaka Stone of the world. It preserves what happened. It cannot be erased. It names who made it. It is the theological text of a world that anyone can read and nobody can alter.",
),
),
key: Some(CowStr::new_static("tid")),
record: LexRecordRecord::Object(LexObject {
required: Some(
vec![
SmolStr::new_static("title"),
SmolStr::new_static("creatorDID"),
SmolStr::new_static("worldReference"),
SmolStr::new_static("createdAt")
],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("authorshipRecord"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Permanent link to the creator. Provenance travels with every piece of history.",
),
),
format: Some(LexStringFormat::Did),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("canonicalStatus"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"The canonical standing of this lore within its world.",
),
),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("characters"),
LexObjectProperty::Array(LexArray {
description: Some(
CowStr::new_static(
"AT URIs of the character records involved in this lore.",
),
),
items: LexArrayItem::String(LexString {
format: Some(LexStringFormat::AtUri),
..Default::default()
}),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("content"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("The actual narrative. The history."),
),
max_length: Some(102400usize),
max_graphemes: Some(10000usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("contributionType"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Whether this lore was written by the world originator or a community contributor.",
),
),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("createdAt"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("Real-world timestamp of creation."),
),
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("creatorDID"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("Who authored this lore entry."),
),
format: Some(LexStringFormat::Did),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("sourceReferences"),
LexObjectProperty::Array(LexArray {
description: Some(
CowStr::new_static(
"AT URIs of the action and event records this lore was generated from. Lore does not appear from nowhere — it traces back to things that actually happened. This is the most important field in this record.",
),
),
items: LexArrayItem::String(LexString {
format: Some(LexStringFormat::AtUri),
..Default::default()
}),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("timelinePosition"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Where this sits in the world's chronology. In-world time, era, epoch, cycle — whatever the world uses.",
),
),
max_length: Some(2560usize),
max_graphemes: Some(256usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("title"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("The name of this piece of lore."),
),
max_length: Some(640usize),
max_graphemes: Some(64usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("worldReference"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"The AT URI of the world this lore belongs to.",
),
),
format: Some(LexStringFormat::AtUri),
..Default::default()
}),
);
map
},
..Default::default()
}),
..Default::default()
}),
);
map
},
..Default::default()
}
}