#[allow(unused_imports)]
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::{BosStr, CowStr, DefaultStr, FromStaticStr};
#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::deps::smol_str::SmolStr;
use jacquard_common::types::collection::{Collection, RecordError};
use jacquard_common::types::string::{AtUri, Cid, Datetime, Did};
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::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
rename_all = "camelCase",
rename = "world.ptah.temp.contribution",
tag = "$type",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Contribution<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub attribution_chain: Option<Vec<AtUri<S>>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub canonical_status: Option<ContributionCanonicalStatus<S>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub contribution_type: Option<ContributionContributionType<S>>,
pub contributor_did: Did<S>,
pub created_at: Datetime,
#[serde(skip_serializing_if = "Option::is_none")]
pub originator_approval: Option<ContributionOriginatorApproval<S>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub public_domain_compliance: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub record_reference: Option<AtUri<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 ContributionCanonicalStatus<S: BosStr = DefaultStr> {
CanonicalStatusOfficial,
CanonicalStatusCommunity,
CanonicalStatusApocryphal,
Other(S),
}
impl<S: BosStr> ContributionCanonicalStatus<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 ContributionCanonicalStatus<S> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<S: BosStr> AsRef<str> for ContributionCanonicalStatus<S> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<S: BosStr> Serialize for ContributionCanonicalStatus<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 ContributionCanonicalStatus<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 ContributionCanonicalStatus<S> {
fn default() -> Self {
Self::Other(Default::default())
}
}
impl<S: BosStr> jacquard_common::IntoStatic for ContributionCanonicalStatus<S>
where
S: BosStr + jacquard_common::IntoStatic,
S::Output: BosStr,
{
type Output = ContributionCanonicalStatus<S::Output>;
fn into_static(self) -> Self::Output {
match self {
ContributionCanonicalStatus::CanonicalStatusOfficial => {
ContributionCanonicalStatus::CanonicalStatusOfficial
}
ContributionCanonicalStatus::CanonicalStatusCommunity => {
ContributionCanonicalStatus::CanonicalStatusCommunity
}
ContributionCanonicalStatus::CanonicalStatusApocryphal => {
ContributionCanonicalStatus::CanonicalStatusApocryphal
}
ContributionCanonicalStatus::Other(v) => {
ContributionCanonicalStatus::Other(v.into_static())
}
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum ContributionContributionType<S: BosStr = DefaultStr> {
Character,
Role,
Action,
Event,
Lore,
Location,
Other(S),
}
impl<S: BosStr> ContributionContributionType<S> {
pub fn as_str(&self) -> &str {
match self {
Self::Character => "character",
Self::Role => "role",
Self::Action => "action",
Self::Event => "event",
Self::Lore => "lore",
Self::Location => "location",
Self::Other(s) => s.as_ref(),
}
}
pub fn from_value(s: S) -> Self {
match s.as_ref() {
"character" => Self::Character,
"role" => Self::Role,
"action" => Self::Action,
"event" => Self::Event,
"lore" => Self::Lore,
"location" => Self::Location,
_ => Self::Other(s),
}
}
}
impl<S: BosStr> core::fmt::Display for ContributionContributionType<S> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<S: BosStr> AsRef<str> for ContributionContributionType<S> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<S: BosStr> Serialize for ContributionContributionType<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 ContributionContributionType<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 ContributionContributionType<S> {
fn default() -> Self {
Self::Other(Default::default())
}
}
impl<S: BosStr> jacquard_common::IntoStatic for ContributionContributionType<S>
where
S: BosStr + jacquard_common::IntoStatic,
S::Output: BosStr,
{
type Output = ContributionContributionType<S::Output>;
fn into_static(self) -> Self::Output {
match self {
ContributionContributionType::Character => ContributionContributionType::Character,
ContributionContributionType::Role => ContributionContributionType::Role,
ContributionContributionType::Action => ContributionContributionType::Action,
ContributionContributionType::Event => ContributionContributionType::Event,
ContributionContributionType::Lore => ContributionContributionType::Lore,
ContributionContributionType::Location => ContributionContributionType::Location,
ContributionContributionType::Other(v) => {
ContributionContributionType::Other(v.into_static())
}
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum ContributionOriginatorApproval<S: BosStr = DefaultStr> {
Approved,
PreApproved,
CommunityCanon,
Other(S),
}
impl<S: BosStr> ContributionOriginatorApproval<S> {
pub fn as_str(&self) -> &str {
match self {
Self::Approved => "approved",
Self::PreApproved => "preApproved",
Self::CommunityCanon => "communityCanon",
Self::Other(s) => s.as_ref(),
}
}
pub fn from_value(s: S) -> Self {
match s.as_ref() {
"approved" => Self::Approved,
"preApproved" => Self::PreApproved,
"communityCanon" => Self::CommunityCanon,
_ => Self::Other(s),
}
}
}
impl<S: BosStr> core::fmt::Display for ContributionOriginatorApproval<S> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<S: BosStr> AsRef<str> for ContributionOriginatorApproval<S> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<S: BosStr> Serialize for ContributionOriginatorApproval<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 ContributionOriginatorApproval<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 ContributionOriginatorApproval<S> {
fn default() -> Self {
Self::Other(Default::default())
}
}
impl<S: BosStr> jacquard_common::IntoStatic for ContributionOriginatorApproval<S>
where
S: BosStr + jacquard_common::IntoStatic,
S::Output: BosStr,
{
type Output = ContributionOriginatorApproval<S::Output>;
fn into_static(self) -> Self::Output {
match self {
ContributionOriginatorApproval::Approved => ContributionOriginatorApproval::Approved,
ContributionOriginatorApproval::PreApproved => {
ContributionOriginatorApproval::PreApproved
}
ContributionOriginatorApproval::CommunityCanon => {
ContributionOriginatorApproval::CommunityCanon
}
ContributionOriginatorApproval::Other(v) => {
ContributionOriginatorApproval::Other(v.into_static())
}
}
}
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct ContributionGetRecordOutput<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub cid: Option<Cid<S>>,
pub uri: AtUri<S>,
pub value: Contribution<S>,
}
impl<S: BosStr> Contribution<S> {
pub fn uri(uri: S) -> Result<RecordUri<S, ContributionRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new(uri)?)
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct ContributionRecord;
impl XrpcResp for ContributionRecord {
const NSID: &'static str = "world.ptah.temp.contribution";
const ENCODING: &'static str = "application/json";
type Output<S: BosStr> = ContributionGetRecordOutput<S>;
type Err = RecordError;
}
impl<S: BosStr> From<ContributionGetRecordOutput<S>> for Contribution<S> {
fn from(output: ContributionGetRecordOutput<S>) -> Self {
output.value
}
}
impl<S: BosStr> Collection for Contribution<S> {
const NSID: &'static str = "world.ptah.temp.contribution";
type Record = ContributionRecord;
}
impl Collection for ContributionRecord {
const NSID: &'static str = "world.ptah.temp.contribution";
type Record = ContributionRecord;
}
impl<S: BosStr> LexiconSchema for Contribution<S> {
fn nsid() -> &'static str {
"world.ptah.temp.contribution"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_world_ptah_temp_contribution()
}
fn validate(&self) -> Result<(), ConstraintError> {
if let Some(ref value) = self.contribution_type {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 640usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("contribution_type"),
max: 640usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.contribution_type {
{
let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
if count > 64usize {
return Err(ConstraintError::MaxGraphemes {
path: ValidationPath::from_field("contribution_type"),
max: 64usize,
actual: count,
});
}
}
}
Ok(())
}
}
pub mod contribution_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 CreatedAt;
type WorldReference;
type ContributorDid;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type CreatedAt = Unset;
type WorldReference = Unset;
type ContributorDid = Unset;
}
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 CreatedAt = Set<members::created_at>;
type WorldReference = St::WorldReference;
type ContributorDid = St::ContributorDid;
}
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 CreatedAt = St::CreatedAt;
type WorldReference = Set<members::world_reference>;
type ContributorDid = St::ContributorDid;
}
pub struct SetContributorDid<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetContributorDid<St> {}
impl<St: State> State for SetContributorDid<St> {
type CreatedAt = St::CreatedAt;
type WorldReference = St::WorldReference;
type ContributorDid = Set<members::contributor_did>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct created_at(());
pub struct world_reference(());
pub struct contributor_did(());
}
}
pub struct ContributionBuilder<S: BosStr, St: contribution_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<Vec<AtUri<S>>>,
Option<ContributionCanonicalStatus<S>>,
Option<ContributionContributionType<S>>,
Option<Did<S>>,
Option<Datetime>,
Option<ContributionOriginatorApproval<S>>,
Option<bool>,
Option<AtUri<S>>,
Option<AtUri<S>>,
),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> Contribution<S> {
pub fn new() -> ContributionBuilder<S, contribution_state::Empty> {
ContributionBuilder::new()
}
}
impl<S: BosStr> ContributionBuilder<S, contribution_state::Empty> {
pub fn new() -> Self {
ContributionBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None, None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St: contribution_state::State> ContributionBuilder<S, St> {
pub fn attribution_chain(mut self, value: impl Into<Option<Vec<AtUri<S>>>>) -> Self {
self._fields.0 = value.into();
self
}
pub fn maybe_attribution_chain(mut self, value: Option<Vec<AtUri<S>>>) -> Self {
self._fields.0 = value;
self
}
}
impl<S: BosStr, St: contribution_state::State> ContributionBuilder<S, St> {
pub fn canonical_status(
mut self,
value: impl Into<Option<ContributionCanonicalStatus<S>>>,
) -> Self {
self._fields.1 = value.into();
self
}
pub fn maybe_canonical_status(mut self, value: Option<ContributionCanonicalStatus<S>>) -> Self {
self._fields.1 = value;
self
}
}
impl<S: BosStr, St: contribution_state::State> ContributionBuilder<S, St> {
pub fn contribution_type(
mut self,
value: impl Into<Option<ContributionContributionType<S>>>,
) -> Self {
self._fields.2 = value.into();
self
}
pub fn maybe_contribution_type(
mut self,
value: Option<ContributionContributionType<S>>,
) -> Self {
self._fields.2 = value;
self
}
}
impl<S: BosStr, St> ContributionBuilder<S, St>
where
St: contribution_state::State,
St::ContributorDid: contribution_state::IsUnset,
{
pub fn contributor_did(
mut self,
value: impl Into<Did<S>>,
) -> ContributionBuilder<S, contribution_state::SetContributorDid<St>> {
self._fields.3 = Option::Some(value.into());
ContributionBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> ContributionBuilder<S, St>
where
St: contribution_state::State,
St::CreatedAt: contribution_state::IsUnset,
{
pub fn created_at(
mut self,
value: impl Into<Datetime>,
) -> ContributionBuilder<S, contribution_state::SetCreatedAt<St>> {
self._fields.4 = Option::Some(value.into());
ContributionBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: contribution_state::State> ContributionBuilder<S, St> {
pub fn originator_approval(
mut self,
value: impl Into<Option<ContributionOriginatorApproval<S>>>,
) -> Self {
self._fields.5 = value.into();
self
}
pub fn maybe_originator_approval(
mut self,
value: Option<ContributionOriginatorApproval<S>>,
) -> Self {
self._fields.5 = value;
self
}
}
impl<S: BosStr, St: contribution_state::State> ContributionBuilder<S, St> {
pub fn public_domain_compliance(mut self, value: impl Into<Option<bool>>) -> Self {
self._fields.6 = value.into();
self
}
pub fn maybe_public_domain_compliance(mut self, value: Option<bool>) -> Self {
self._fields.6 = value;
self
}
}
impl<S: BosStr, St: contribution_state::State> ContributionBuilder<S, St> {
pub fn record_reference(mut self, value: impl Into<Option<AtUri<S>>>) -> Self {
self._fields.7 = value.into();
self
}
pub fn maybe_record_reference(mut self, value: Option<AtUri<S>>) -> Self {
self._fields.7 = value;
self
}
}
impl<S: BosStr, St> ContributionBuilder<S, St>
where
St: contribution_state::State,
St::WorldReference: contribution_state::IsUnset,
{
pub fn world_reference(
mut self,
value: impl Into<AtUri<S>>,
) -> ContributionBuilder<S, contribution_state::SetWorldReference<St>> {
self._fields.8 = Option::Some(value.into());
ContributionBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> ContributionBuilder<S, St>
where
St: contribution_state::State,
St::CreatedAt: contribution_state::IsSet,
St::WorldReference: contribution_state::IsSet,
St::ContributorDid: contribution_state::IsSet,
{
pub fn build(self) -> Contribution<S> {
Contribution {
attribution_chain: self._fields.0,
canonical_status: self._fields.1,
contribution_type: self._fields.2,
contributor_did: self._fields.3.unwrap(),
created_at: self._fields.4.unwrap(),
originator_approval: self._fields.5,
public_domain_compliance: self._fields.6,
record_reference: self._fields.7,
world_reference: self._fields.8.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Contribution<S> {
Contribution {
attribution_chain: self._fields.0,
canonical_status: self._fields.1,
contribution_type: self._fields.2,
contributor_did: self._fields.3.unwrap(),
created_at: self._fields.4.unwrap(),
originator_approval: self._fields.5,
public_domain_compliance: self._fields.6,
record_reference: self._fields.7,
world_reference: self._fields.8.unwrap(),
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_world_ptah_temp_contribution() -> 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("world.ptah.temp.contribution"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("main"),
LexUserType::Record(LexRecord {
description: Some(
CowStr::new_static(
"A deed of addition. Imhotep — the most famous architect in history, deified as the Son of Ptah. Every contributor to a world is an Imhotep. They build within the tradition of the master. Their work is attributed. The lineage is unbroken.",
),
),
key: Some(CowStr::new_static("tid")),
record: LexRecordRecord::Object(LexObject {
required: Some(
vec![
SmolStr::new_static("contributorDID"),
SmolStr::new_static("worldReference"),
SmolStr::new_static("createdAt")
],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("attributionChain"),
LexObjectProperty::Array(LexArray {
description: Some(
CowStr::new_static(
"An array tracing every hand this contribution passed through. AT URIs of prior contribution records or DIDs. This is the Carryforward logic expressed at the protocol layer.",
),
),
items: LexArrayItem::String(LexString {
format: Some(LexStringFormat::AtUri),
..Default::default()
}),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("canonicalStatus"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"The canonical standing of this contribution within the world.",
),
),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("contributionType"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"What kind of contribution and which record type it links to.",
),
),
max_length: Some(640usize),
max_graphemes: Some(64usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("contributorDID"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("Who is making the contribution."),
),
format: Some(LexStringFormat::Did),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("createdAt"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("Timestamp of the contribution."),
),
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("originatorApproval"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"The approval status of this contribution.",
),
),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("publicDomainCompliance"),
LexObjectProperty::Boolean(LexBoolean {
..Default::default()
}),
);
map.insert(
SmolStr::new_static("recordReference"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"The AT URI of the primary record being contributed. The Contribution record is the anchor of attribution — not the exhaustive list of every record the contributor touched. The full scope is discoverable via DID query across record types.",
),
),
format: Some(LexStringFormat::AtUri),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("worldReference"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"The AT URI of the world being contributed to.",
),
),
format: Some(LexStringFormat::AtUri),
..Default::default()
}),
);
map
},
..Default::default()
}),
..Default::default()
}),
);
map
},
..Default::default()
}
}