// @generated by jacquard-lexicon. DO NOT EDIT. // // Lexicon: dev.keytrace.statement // // This file was automatically generated from Lexicon schemas. // Any manual changes will be overwritten on the next regeneration. #[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}; /// A public statement signed by one of the user's own published public keys (dev.keytrace.userPublicKey). #[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 { /// The statement text that was signed. pub content: S, /// Datetime when this statement was created (ISO 8601). pub created_at: Datetime, /// AT URI of the dev.keytrace.userPublicKey record whose private key produced this signature (e.g., at://did:plc:xxx/dev.keytrace.userPublicKey/3k4...) pub key_ref: AtUri, /// Datetime when this statement was retracted. Present only if the statement has been retracted (ISO 8601). #[serde(skip_serializing_if = "Option::is_none")] pub retracted_at: Option, /// Cryptographic signature of the content field, produced by the key referenced in keyRef (PGP cleartext or detached, base64-encoded binary signature). pub sig: S, /// Optional short subject or title for the statement. #[serde(skip_serializing_if = "Option::is_none")] pub subject: Option, #[serde( flatten, default, deserialize_with = "deserialize_statement_extra_data", skip_serializing_if = "Option::is_none" )] pub extra_data: Option>>, } /// Typed wrapper for GetRecord response with this collection's record type. #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)] #[serde(rename_all = "camelCase")] pub struct StatementGetRecordOutput { #[serde(skip_serializing_if = "Option::is_none")] pub cid: Option>, pub uri: AtUri, pub value: Statement, } impl Statement { pub fn uri(uri: S) -> Result, UriError> { RecordUri::try_from_uri(AtUri::new(uri)?) } } /// Marker type for deserializing records from this collection. #[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 = StatementGetRecordOutput; type Err = RecordError; } impl From> for Statement { fn from(output: StatementGetRecordOutput) -> Self { output.value } } impl Collection for Statement { 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 LexiconSchema for Statement { 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 ::len(value.as_ref()) > 10000usize { return Err(ConstraintError::MaxLength { path: ValidationPath::from_field("content"), max: 10000usize, actual: ::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(()) } } fn deserialize_statement_extra_data<'de, S, D>( deserializer: D, ) -> Result>>, D::Error> where S: BosStr + serde::Deserialize<'de>, D: serde::Deserializer<'de>, { let mut data = >> as serde::Deserialize<'de>>::deserialize(deserializer)?; if let Some(extra_data) = &mut data { extra_data.remove("$type"); if extra_data.is_empty() { data = None; } } Ok(data) } pub mod statement_state { pub use crate::builder_types::{IsSet, IsUnset, Set, Unset}; #[allow(unused)] use ::core::marker::PhantomData; mod sealed { pub trait Sealed {} } /// State trait tracking which required fields have been set pub trait State: sealed::Sealed { type Content; type CreatedAt; type KeyRef; type Sig; } /// Empty state - all required fields are unset pub struct Empty(()); impl sealed::Sealed for Empty {} impl State for Empty { type Content = Unset; type CreatedAt = Unset; type KeyRef = Unset; type Sig = Unset; } ///State transition - sets the `content` field to Set pub struct SetContent(PhantomData St>); impl sealed::Sealed for SetContent {} impl State for SetContent { type Content = Set; type CreatedAt = St::CreatedAt; type KeyRef = St::KeyRef; type Sig = St::Sig; } ///State transition - sets the `created_at` field to Set pub struct SetCreatedAt(PhantomData St>); impl sealed::Sealed for SetCreatedAt {} impl State for SetCreatedAt { type Content = St::Content; type CreatedAt = Set; type KeyRef = St::KeyRef; type Sig = St::Sig; } ///State transition - sets the `key_ref` field to Set pub struct SetKeyRef(PhantomData St>); impl sealed::Sealed for SetKeyRef {} impl State for SetKeyRef { type Content = St::Content; type CreatedAt = St::CreatedAt; type KeyRef = Set; type Sig = St::Sig; } ///State transition - sets the `sig` field to Set pub struct SetSig(PhantomData St>); impl sealed::Sealed for SetSig {} impl State for SetSig { type Content = St::Content; type CreatedAt = St::CreatedAt; type KeyRef = St::KeyRef; type Sig = Set; } /// Marker types for field names #[allow(non_camel_case_types)] pub mod members { ///Marker type for the `content` field pub struct content(()); ///Marker type for the `created_at` field pub struct created_at(()); ///Marker type for the `key_ref` field pub struct key_ref(()); ///Marker type for the `sig` field pub struct sig(()); } } /// Builder for constructing an instance of this type. pub struct StatementBuilder { _state: PhantomData St>, _fields: ( Option, Option, Option>, Option, Option, Option, ), _type: PhantomData S>, } impl Statement { /// Create a new builder for this type, using the default string type (DefaultStr = SmolStr) if needed pub fn new() -> StatementBuilder { StatementBuilder::new() } } impl Statement { /// Create a new builder for this type pub fn builder() -> StatementBuilder { StatementBuilder::builder() } } impl StatementBuilder { /// Create a new builder with all fields unset, using the default string type, if needed pub fn new() -> Self { StatementBuilder { _state: PhantomData, _fields: (None, None, None, None, None, None), _type: PhantomData, } } } impl StatementBuilder { /// Create a new builder with all fields unset pub fn builder() -> Self { StatementBuilder { _state: PhantomData, _fields: (None, None, None, None, None, None), _type: PhantomData, } } } impl StatementBuilder where St: statement_state::State, St::Content: statement_state::IsUnset, { /// Set the `content` field (required) pub fn content( mut self, value: impl Into, ) -> StatementBuilder, S> { self._fields.0 = Option::Some(value.into()); StatementBuilder { _state: PhantomData, _fields: self._fields, _type: PhantomData, } } } impl StatementBuilder where St: statement_state::State, St::CreatedAt: statement_state::IsUnset, { /// Set the `createdAt` field (required) pub fn created_at( mut self, value: impl Into, ) -> StatementBuilder, S> { self._fields.1 = Option::Some(value.into()); StatementBuilder { _state: PhantomData, _fields: self._fields, _type: PhantomData, } } } impl StatementBuilder where St: statement_state::State, St::KeyRef: statement_state::IsUnset, { /// Set the `keyRef` field (required) pub fn key_ref( mut self, value: impl Into>, ) -> StatementBuilder, S> { self._fields.2 = Option::Some(value.into()); StatementBuilder { _state: PhantomData, _fields: self._fields, _type: PhantomData, } } } impl StatementBuilder { /// Set the `retractedAt` field (optional) pub fn retracted_at(mut self, value: impl Into>) -> Self { self._fields.3 = value.into(); self } /// Set the `retractedAt` field to an Option value (optional) pub fn maybe_retracted_at(mut self, value: Option) -> Self { self._fields.3 = value; self } } impl StatementBuilder where St: statement_state::State, St::Sig: statement_state::IsUnset, { /// Set the `sig` field (required) pub fn sig(mut self, value: impl Into) -> StatementBuilder, S> { self._fields.4 = Option::Some(value.into()); StatementBuilder { _state: PhantomData, _fields: self._fields, _type: PhantomData, } } } impl StatementBuilder { /// Set the `subject` field (optional) pub fn subject(mut self, value: impl Into>) -> Self { self._fields.5 = value.into(); self } /// Set the `subject` field to an Option value (optional) pub fn maybe_subject(mut self, value: Option) -> Self { self._fields.5 = value; self } } impl StatementBuilder where St: statement_state::State, St::Content: statement_state::IsSet, St::CreatedAt: statement_state::IsSet, St::KeyRef: statement_state::IsSet, St::Sig: statement_state::IsSet, { /// Build the final struct. pub fn build(self) -> Statement { 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(), } } /// Build the final struct with custom extra_data. pub fn build_with_data(self, extra_data: BTreeMap>) -> Statement { 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() } }