#[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};
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 = "dev.keytrace.statement",
tag = "$type",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Statement<S: BosStr = DefaultStr> {
pub content: S,
pub created_at: Datetime,
pub key_ref: AtUri<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub retracted_at: Option<Datetime>,
pub sig: S,
#[serde(skip_serializing_if = "Option::is_none")]
pub subject: Option<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")]
pub struct StatementGetRecordOutput<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub cid: Option<Cid<S>>,
pub uri: AtUri<S>,
pub value: Statement<S>,
}
impl<S: BosStr> Statement<S> {
pub fn uri(uri: S) -> Result<RecordUri<S, StatementRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new(uri)?)
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct StatementRecord;
impl XrpcResp for StatementRecord {
const NSID: &'static str = "dev.keytrace.statement";
const ENCODING: &'static str = "application/json";
type Output<S: BosStr> = StatementGetRecordOutput<S>;
type Err = RecordError;
}
impl<S: BosStr> From<StatementGetRecordOutput<S>> for Statement<S> {
fn from(output: StatementGetRecordOutput<S>) -> Self {
output.value
}
}
impl<S: BosStr> Collection for Statement<S> {
const NSID: &'static str = "dev.keytrace.statement";
type Record = StatementRecord;
}
impl Collection for StatementRecord {
const NSID: &'static str = "dev.keytrace.statement";
type Record = StatementRecord;
}
impl<S: BosStr> LexiconSchema for Statement<S> {
fn nsid() -> &'static str {
"dev.keytrace.statement"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_dev_keytrace_statement()
}
fn validate(&self) -> Result<(), ConstraintError> {
{
let value = &self.content;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 10000usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("content"),
max: 10000usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let 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.subject {
{
let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
if count > 256usize {
return Err(ConstraintError::MaxGraphemes {
path: ValidationPath::from_field("subject"),
max: 256usize,
actual: count,
});
}
}
}
Ok(())
}
}
pub mod statement_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 Sig;
type KeyRef;
type CreatedAt;
type Content;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Sig = Unset;
type KeyRef = Unset;
type CreatedAt = Unset;
type Content = Unset;
}
pub struct SetSig<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetSig<St> {}
impl<St: State> State for SetSig<St> {
type Sig = Set<members::sig>;
type KeyRef = St::KeyRef;
type CreatedAt = St::CreatedAt;
type Content = St::Content;
}
pub struct SetKeyRef<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetKeyRef<St> {}
impl<St: State> State for SetKeyRef<St> {
type Sig = St::Sig;
type KeyRef = Set<members::key_ref>;
type CreatedAt = St::CreatedAt;
type Content = St::Content;
}
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 Sig = St::Sig;
type KeyRef = St::KeyRef;
type CreatedAt = Set<members::created_at>;
type Content = St::Content;
}
pub struct SetContent<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetContent<St> {}
impl<St: State> State for SetContent<St> {
type Sig = St::Sig;
type KeyRef = St::KeyRef;
type CreatedAt = St::CreatedAt;
type Content = Set<members::content>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct sig(());
pub struct key_ref(());
pub struct created_at(());
pub struct content(());
}
}
pub struct StatementBuilder<S: BosStr, St: statement_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<S>,
Option<Datetime>,
Option<AtUri<S>>,
Option<Datetime>,
Option<S>,
Option<S>,
),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> Statement<S> {
pub fn new() -> StatementBuilder<S, statement_state::Empty> {
StatementBuilder::new()
}
}
impl<S: BosStr> StatementBuilder<S, statement_state::Empty> {
pub fn new() -> Self {
StatementBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St> StatementBuilder<S, St>
where
St: statement_state::State,
St::Content: statement_state::IsUnset,
{
pub fn content(
mut self,
value: impl Into<S>,
) -> StatementBuilder<S, statement_state::SetContent<St>> {
self._fields.0 = Option::Some(value.into());
StatementBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> StatementBuilder<S, St>
where
St: statement_state::State,
St::CreatedAt: statement_state::IsUnset,
{
pub fn created_at(
mut self,
value: impl Into<Datetime>,
) -> StatementBuilder<S, statement_state::SetCreatedAt<St>> {
self._fields.1 = Option::Some(value.into());
StatementBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> StatementBuilder<S, St>
where
St: statement_state::State,
St::KeyRef: statement_state::IsUnset,
{
pub fn key_ref(
mut self,
value: impl Into<AtUri<S>>,
) -> StatementBuilder<S, statement_state::SetKeyRef<St>> {
self._fields.2 = Option::Some(value.into());
StatementBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: statement_state::State> StatementBuilder<S, St> {
pub fn retracted_at(mut self, value: impl Into<Option<Datetime>>) -> Self {
self._fields.3 = value.into();
self
}
pub fn maybe_retracted_at(mut self, value: Option<Datetime>) -> Self {
self._fields.3 = value;
self
}
}
impl<S: BosStr, St> StatementBuilder<S, St>
where
St: statement_state::State,
St::Sig: statement_state::IsUnset,
{
pub fn sig(mut self, value: impl Into<S>) -> StatementBuilder<S, statement_state::SetSig<St>> {
self._fields.4 = Option::Some(value.into());
StatementBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: statement_state::State> StatementBuilder<S, St> {
pub fn subject(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.5 = value.into();
self
}
pub fn maybe_subject(mut self, value: Option<S>) -> Self {
self._fields.5 = value;
self
}
}
impl<S: BosStr, St> StatementBuilder<S, St>
where
St: statement_state::State,
St::Sig: statement_state::IsSet,
St::KeyRef: statement_state::IsSet,
St::CreatedAt: statement_state::IsSet,
St::Content: statement_state::IsSet,
{
pub fn build(self) -> Statement<S> {
Statement {
content: self._fields.0.unwrap(),
created_at: self._fields.1.unwrap(),
key_ref: self._fields.2.unwrap(),
retracted_at: self._fields.3,
sig: self._fields.4.unwrap(),
subject: self._fields.5,
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Statement<S> {
Statement {
content: self._fields.0.unwrap(),
created_at: self._fields.1.unwrap(),
key_ref: self._fields.2.unwrap(),
retracted_at: self._fields.3,
sig: self._fields.4.unwrap(),
subject: self._fields.5,
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_dev_keytrace_statement() -> 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("dev.keytrace.statement"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("main"),
LexUserType::Record(LexRecord {
description: Some(
CowStr::new_static(
"A public statement signed by one of the user's own published public keys (dev.keytrace.userPublicKey).",
),
),
key: Some(CowStr::new_static("tid")),
record: LexRecordRecord::Object(LexObject {
required: Some(
vec![
SmolStr::new_static("content"),
SmolStr::new_static("keyRef"), SmolStr::new_static("sig"),
SmolStr::new_static("createdAt")
],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("content"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("The statement text that was signed."),
),
max_length: Some(10000usize),
max_graphemes: Some(10000usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("createdAt"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Datetime when this statement was created (ISO 8601).",
),
),
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("keyRef"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"AT URI of the dev.keytrace.userPublicKey record whose private key produced this signature (e.g., at://did:plc:xxx/dev.keytrace.userPublicKey/3k4...)",
),
),
format: Some(LexStringFormat::AtUri),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("retractedAt"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Datetime when this statement was retracted. Present only if the statement has been retracted (ISO 8601).",
),
),
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("sig"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Cryptographic signature of the content field, produced by the key referenced in keyRef (PGP cleartext or detached, base64-encoded binary signature).",
),
),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("subject"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Optional short subject or title for the statement.",
),
),
max_graphemes: Some(256usize),
..Default::default()
}),
);
map
},
..Default::default()
}),
..Default::default()
}),
);
map
},
..Default::default()
}
}