#[allow(unused_imports)]
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::CowStr;
use jacquard_common::deps::bytes::Bytes;
#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::types::collection::{Collection, RecordError};
use jacquard_common::types::string::{AtUri, Cid, UriValue};
use jacquard_common::types::uri::{RecordUri, UriError};
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};
use crate::com_germnetwork::declaration;
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Declaration<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
pub continuity_proofs: Option<Vec<Bytes>>,
#[serde(with = "jacquard_common::serde_bytes_helper")]
pub current_key: Bytes,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default, with = "jacquard_common::opt_serde_bytes_helper")]
pub key_package: Option<Bytes>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub message_me: Option<declaration::MessageMe<'a>>,
#[serde(borrow)]
pub version: CowStr<'a>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct DeclarationGetRecordOutput<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub cid: Option<Cid<'a>>,
#[serde(borrow)]
pub uri: AtUri<'a>,
#[serde(borrow)]
pub value: Declaration<'a>,
}
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct MessageMe<'a> {
#[serde(borrow)]
pub message_me_url: UriValue<'a>,
#[serde(borrow)]
pub show_button_to: MessageMeShowButtonTo<'a>,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum MessageMeShowButtonTo<'a> {
None,
UsersIFollow,
Everyone,
Other(CowStr<'a>),
}
impl<'a> MessageMeShowButtonTo<'a> {
pub fn as_str(&self) -> &str {
match self {
Self::None => "none",
Self::UsersIFollow => "usersIFollow",
Self::Everyone => "everyone",
Self::Other(s) => s.as_ref(),
}
}
}
impl<'a> From<&'a str> for MessageMeShowButtonTo<'a> {
fn from(s: &'a str) -> Self {
match s {
"none" => Self::None,
"usersIFollow" => Self::UsersIFollow,
"everyone" => Self::Everyone,
_ => Self::Other(CowStr::from(s)),
}
}
}
impl<'a> From<String> for MessageMeShowButtonTo<'a> {
fn from(s: String) -> Self {
match s.as_str() {
"none" => Self::None,
"usersIFollow" => Self::UsersIFollow,
"everyone" => Self::Everyone,
_ => Self::Other(CowStr::from(s)),
}
}
}
impl<'a> core::fmt::Display for MessageMeShowButtonTo<'a> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<'a> AsRef<str> for MessageMeShowButtonTo<'a> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<'a> serde::Serialize for MessageMeShowButtonTo<'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 MessageMeShowButtonTo<'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 MessageMeShowButtonTo<'a> {
fn default() -> Self {
Self::Other(Default::default())
}
}
impl jacquard_common::IntoStatic for MessageMeShowButtonTo<'_> {
type Output = MessageMeShowButtonTo<'static>;
fn into_static(self) -> Self::Output {
match self {
MessageMeShowButtonTo::None => MessageMeShowButtonTo::None,
MessageMeShowButtonTo::UsersIFollow => MessageMeShowButtonTo::UsersIFollow,
MessageMeShowButtonTo::Everyone => MessageMeShowButtonTo::Everyone,
MessageMeShowButtonTo::Other(v) => {
MessageMeShowButtonTo::Other(v.into_static())
}
}
}
}
impl<'a> Declaration<'a> {
pub fn uri(
uri: impl Into<CowStr<'a>>,
) -> Result<RecordUri<'a, DeclarationRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new_cow(uri.into())?)
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct DeclarationRecord;
impl XrpcResp for DeclarationRecord {
const NSID: &'static str = "com.germnetwork.declaration";
const ENCODING: &'static str = "application/json";
type Output<'de> = DeclarationGetRecordOutput<'de>;
type Err<'de> = RecordError<'de>;
}
impl From<DeclarationGetRecordOutput<'_>> for Declaration<'_> {
fn from(output: DeclarationGetRecordOutput<'_>) -> Self {
use jacquard_common::IntoStatic;
output.value.into_static()
}
}
impl Collection for Declaration<'_> {
const NSID: &'static str = "com.germnetwork.declaration";
type Record = DeclarationRecord;
}
impl Collection for DeclarationRecord {
const NSID: &'static str = "com.germnetwork.declaration";
type Record = DeclarationRecord;
}
impl<'a> LexiconSchema for Declaration<'a> {
fn nsid() -> &'static str {
"com.germnetwork.declaration"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_com_germnetwork_declaration()
}
fn validate(&self) -> Result<(), ConstraintError> {
if let Some(ref value) = self.continuity_proofs {
#[allow(unused_comparisons)]
if value.len() > 1000usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("continuity_proofs"),
max: 1000usize,
actual: value.len(),
});
}
}
{
let value = &self.version;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 14usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("version"),
max: 14usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.version;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) < 5usize {
return Err(ConstraintError::MinLength {
path: ValidationPath::from_field("version"),
min: 5usize,
actual: <str>::len(value.as_ref()),
});
}
}
Ok(())
}
}
impl<'a> LexiconSchema for MessageMe<'a> {
fn nsid() -> &'static str {
"com.germnetwork.declaration"
}
fn def_name() -> &'static str {
"messageMe"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_com_germnetwork_declaration()
}
fn validate(&self) -> Result<(), ConstraintError> {
{
let value = &self.message_me_url;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 2047usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("message_me_url"),
max: 2047usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.message_me_url;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) < 1usize {
return Err(ConstraintError::MinLength {
path: ValidationPath::from_field("message_me_url"),
min: 1usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.show_button_to;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 100usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("show_button_to"),
max: 100usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.show_button_to;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) < 1usize {
return Err(ConstraintError::MinLength {
path: ValidationPath::from_field("show_button_to"),
min: 1usize,
actual: <str>::len(value.as_ref()),
});
}
}
Ok(())
}
}
pub mod declaration_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 Version;
type CurrentKey;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Version = Unset;
type CurrentKey = Unset;
}
pub struct SetVersion<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetVersion<S> {}
impl<S: State> State for SetVersion<S> {
type Version = Set<members::version>;
type CurrentKey = S::CurrentKey;
}
pub struct SetCurrentKey<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetCurrentKey<S> {}
impl<S: State> State for SetCurrentKey<S> {
type Version = S::Version;
type CurrentKey = Set<members::current_key>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct version(());
pub struct current_key(());
}
}
pub struct DeclarationBuilder<'a, S: declaration_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (
Option<Vec<Bytes>>,
Option<Bytes>,
Option<Bytes>,
Option<declaration::MessageMe<'a>>,
Option<CowStr<'a>>,
),
_lifetime: PhantomData<&'a ()>,
}
impl<'a> Declaration<'a> {
pub fn new() -> DeclarationBuilder<'a, declaration_state::Empty> {
DeclarationBuilder::new()
}
}
impl<'a> DeclarationBuilder<'a, declaration_state::Empty> {
pub fn new() -> Self {
DeclarationBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None),
_lifetime: PhantomData,
}
}
}
impl<'a, S: declaration_state::State> DeclarationBuilder<'a, S> {
pub fn continuity_proofs(mut self, value: impl Into<Option<Vec<Bytes>>>) -> Self {
self._fields.0 = value.into();
self
}
pub fn maybe_continuity_proofs(mut self, value: Option<Vec<Bytes>>) -> Self {
self._fields.0 = value;
self
}
}
impl<'a, S> DeclarationBuilder<'a, S>
where
S: declaration_state::State,
S::CurrentKey: declaration_state::IsUnset,
{
pub fn current_key(
mut self,
value: impl Into<Bytes>,
) -> DeclarationBuilder<'a, declaration_state::SetCurrentKey<S>> {
self._fields.1 = Option::Some(value.into());
DeclarationBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S: declaration_state::State> DeclarationBuilder<'a, S> {
pub fn key_package(mut self, value: impl Into<Option<Bytes>>) -> Self {
self._fields.2 = value.into();
self
}
pub fn maybe_key_package(mut self, value: Option<Bytes>) -> Self {
self._fields.2 = value;
self
}
}
impl<'a, S: declaration_state::State> DeclarationBuilder<'a, S> {
pub fn message_me(
mut self,
value: impl Into<Option<declaration::MessageMe<'a>>>,
) -> Self {
self._fields.3 = value.into();
self
}
pub fn maybe_message_me(
mut self,
value: Option<declaration::MessageMe<'a>>,
) -> Self {
self._fields.3 = value;
self
}
}
impl<'a, S> DeclarationBuilder<'a, S>
where
S: declaration_state::State,
S::Version: declaration_state::IsUnset,
{
pub fn version(
mut self,
value: impl Into<CowStr<'a>>,
) -> DeclarationBuilder<'a, declaration_state::SetVersion<S>> {
self._fields.4 = Option::Some(value.into());
DeclarationBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> DeclarationBuilder<'a, S>
where
S: declaration_state::State,
S::Version: declaration_state::IsSet,
S::CurrentKey: declaration_state::IsSet,
{
pub fn build(self) -> Declaration<'a> {
Declaration {
continuity_proofs: self._fields.0,
current_key: self._fields.1.unwrap(),
key_package: self._fields.2,
message_me: self._fields.3,
version: 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>,
>,
) -> Declaration<'a> {
Declaration {
continuity_proofs: self._fields.0,
current_key: self._fields.1.unwrap(),
key_package: self._fields.2,
message_me: self._fields.3,
version: self._fields.4.unwrap(),
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_com_germnetwork_declaration() -> 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("com.germnetwork.declaration"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("main"),
LexUserType::Record(LexRecord {
description: Some(
CowStr::new_static("A declaration of a Germ Network account"),
),
key: Some(CowStr::new_static("literal:self")),
record: LexRecordRecord::Object(LexObject {
required: Some(
vec![
SmolStr::new_static("version"),
SmolStr::new_static("currentKey")
],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("continuityProofs"),
LexObjectProperty::Array(LexArray {
description: Some(
CowStr::new_static(
"Array of opaque values to allow for key rolling",
),
),
items: LexArrayItem::Bytes(LexBytes {
..Default::default()
}),
max_length: Some(1000usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("currentKey"),
LexObjectProperty::Bytes(LexBytes { ..Default::default() }),
);
map.insert(
SmolStr::new_static("keyPackage"),
LexObjectProperty::Bytes(LexBytes { ..Default::default() }),
);
map.insert(
SmolStr::new_static("messageMe"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static("#messageMe"),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("version"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Semver version number, without pre-release or build information, for the format of opaque content",
),
),
min_length: Some(5usize),
max_length: Some(14usize),
..Default::default()
}),
);
map
},
..Default::default()
}),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("messageMe"),
LexUserType::Object(LexObject {
required: Some(
vec![
SmolStr::new_static("showButtonTo"),
SmolStr::new_static("messageMeUrl")
],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("messageMeUrl"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"A URL to present to an account that does not have its own com.germnetwork.declaration record, must have an empty fragment component, where the app should fill in the fragment component with the DIDs of the two accounts who wish to message each other",
),
),
format: Some(LexStringFormat::Uri),
min_length: Some(1usize),
max_length: Some(2047usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("showButtonTo"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"The policy of who can message the account, this value is included in the keyPackage, but is duplicated here to allow applications to decide if they should show a 'Message on Germ' button to the viewer.",
),
),
min_length: Some(1usize),
max_length: Some(100usize),
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map
},
..Default::default()
}
}
pub mod message_me_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 ShowButtonTo;
type MessageMeUrl;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type ShowButtonTo = Unset;
type MessageMeUrl = Unset;
}
pub struct SetShowButtonTo<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetShowButtonTo<S> {}
impl<S: State> State for SetShowButtonTo<S> {
type ShowButtonTo = Set<members::show_button_to>;
type MessageMeUrl = S::MessageMeUrl;
}
pub struct SetMessageMeUrl<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetMessageMeUrl<S> {}
impl<S: State> State for SetMessageMeUrl<S> {
type ShowButtonTo = S::ShowButtonTo;
type MessageMeUrl = Set<members::message_me_url>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct show_button_to(());
pub struct message_me_url(());
}
}
pub struct MessageMeBuilder<'a, S: message_me_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (Option<UriValue<'a>>, Option<MessageMeShowButtonTo<'a>>),
_lifetime: PhantomData<&'a ()>,
}
impl<'a> MessageMe<'a> {
pub fn new() -> MessageMeBuilder<'a, message_me_state::Empty> {
MessageMeBuilder::new()
}
}
impl<'a> MessageMeBuilder<'a, message_me_state::Empty> {
pub fn new() -> Self {
MessageMeBuilder {
_state: PhantomData,
_fields: (None, None),
_lifetime: PhantomData,
}
}
}
impl<'a, S> MessageMeBuilder<'a, S>
where
S: message_me_state::State,
S::MessageMeUrl: message_me_state::IsUnset,
{
pub fn message_me_url(
mut self,
value: impl Into<UriValue<'a>>,
) -> MessageMeBuilder<'a, message_me_state::SetMessageMeUrl<S>> {
self._fields.0 = Option::Some(value.into());
MessageMeBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> MessageMeBuilder<'a, S>
where
S: message_me_state::State,
S::ShowButtonTo: message_me_state::IsUnset,
{
pub fn show_button_to(
mut self,
value: impl Into<MessageMeShowButtonTo<'a>>,
) -> MessageMeBuilder<'a, message_me_state::SetShowButtonTo<S>> {
self._fields.1 = Option::Some(value.into());
MessageMeBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> MessageMeBuilder<'a, S>
where
S: message_me_state::State,
S::ShowButtonTo: message_me_state::IsSet,
S::MessageMeUrl: message_me_state::IsSet,
{
pub fn build(self) -> MessageMe<'a> {
MessageMe {
message_me_url: self._fields.0.unwrap(),
show_button_to: self._fields.1.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>,
>,
) -> MessageMe<'a> {
MessageMe {
message_me_url: self._fields.0.unwrap(),
show_button_to: self._fields.1.unwrap(),
extra_data: Some(extra_data),
}
}
}