#[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;
use crate::community_lexicon::app::AccountIndicator;
use crate::community_lexicon::app::Image;
use crate::community_lexicon::app::LexiconInterop;
use crate::community_lexicon::app::Link;
use crate::community_lexicon::app::Platform;
use crate::community_lexicon::app::Status;
#[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 = "community.lexicon.app.profile",
tag = "$type",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Profile<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub account_indicators: Option<Vec<AccountIndicator<S>>>,
pub created_at: Datetime,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub images: Option<Vec<Image<S>>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub lexicons: Option<LexiconInterop<S>>,
pub links: Vec<Link<S>>,
pub name: S,
#[serde(skip_serializing_if = "Option::is_none")]
pub platforms: Option<Vec<Platform<S>>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub status: Option<Status<S>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub tags: Option<Vec<S>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub updated_at: Option<Datetime>,
#[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 ProfileGetRecordOutput<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub cid: Option<Cid<S>>,
pub uri: AtUri<S>,
pub value: Profile<S>,
}
impl<S: BosStr> Profile<S> {
pub fn uri(uri: S) -> Result<RecordUri<S, ProfileRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new(uri)?)
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct ProfileRecord;
impl XrpcResp for ProfileRecord {
const NSID: &'static str = "community.lexicon.app.profile";
const ENCODING: &'static str = "application/json";
type Output<S: BosStr> = ProfileGetRecordOutput<S>;
type Err = RecordError;
}
impl<S: BosStr> From<ProfileGetRecordOutput<S>> for Profile<S> {
fn from(output: ProfileGetRecordOutput<S>) -> Self {
output.value
}
}
impl<S: BosStr> Collection for Profile<S> {
const NSID: &'static str = "community.lexicon.app.profile";
type Record = ProfileRecord;
}
impl Collection for ProfileRecord {
const NSID: &'static str = "community.lexicon.app.profile";
type Record = ProfileRecord;
}
impl<S: BosStr> LexiconSchema for Profile<S> {
fn nsid() -> &'static str {
"community.lexicon.app.profile"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_community_lexicon_app_profile()
}
fn validate(&self) -> Result<(), ConstraintError> {
if let Some(ref value) = self.account_indicators {
#[allow(unused_comparisons)]
if value.len() > 12usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("account_indicators"),
max: 12usize,
actual: value.len(),
});
}
}
if let Some(ref value) = self.description {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 3000usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("description"),
max: 3000usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.description {
{
let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
if count > 300usize {
return Err(ConstraintError::MaxGraphemes {
path: ValidationPath::from_field("description"),
max: 300usize,
actual: count,
});
}
}
}
if let Some(ref value) = self.images {
#[allow(unused_comparisons)]
if value.len() > 24usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("images"),
max: 24usize,
actual: value.len(),
});
}
}
{
let value = &self.links;
#[allow(unused_comparisons)]
if value.len() > 12usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("links"),
max: 12usize,
actual: value.len(),
});
}
}
{
let value = &self.links;
#[allow(unused_comparisons)]
if value.len() < 1usize {
return Err(ConstraintError::MinLength {
path: ValidationPath::from_field("links"),
min: 1usize,
actual: value.len(),
});
}
}
{
let value = &self.name;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 200usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("name"),
max: 200usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.name;
{
let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
if count > 100usize {
return Err(ConstraintError::MaxGraphemes {
path: ValidationPath::from_field("name"),
max: 100usize,
actual: count,
});
}
}
}
if let Some(ref value) = self.platforms {
#[allow(unused_comparisons)]
if value.len() > 12usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("platforms"),
max: 12usize,
actual: value.len(),
});
}
}
if let Some(ref value) = self.tags {
#[allow(unused_comparisons)]
if value.len() > 10usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("tags"),
max: 10usize,
actual: value.len(),
});
}
}
Ok(())
}
}
pub mod profile_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 Links;
type Name;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type CreatedAt = Unset;
type Links = Unset;
type Name = 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 Links = St::Links;
type Name = St::Name;
}
pub struct SetLinks<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetLinks<St> {}
impl<St: State> State for SetLinks<St> {
type CreatedAt = St::CreatedAt;
type Links = Set<members::links>;
type Name = St::Name;
}
pub struct SetName<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetName<St> {}
impl<St: State> State for SetName<St> {
type CreatedAt = St::CreatedAt;
type Links = St::Links;
type Name = Set<members::name>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct created_at(());
pub struct links(());
pub struct name(());
}
}
pub struct ProfileBuilder<St: profile_state::State, S: BosStr = DefaultStr> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<Vec<AccountIndicator<S>>>,
Option<Datetime>,
Option<S>,
Option<Vec<Image<S>>>,
Option<LexiconInterop<S>>,
Option<Vec<Link<S>>>,
Option<S>,
Option<Vec<Platform<S>>>,
Option<Status<S>>,
Option<Vec<S>>,
Option<Datetime>,
),
_type: PhantomData<fn() -> S>,
}
impl Profile<DefaultStr> {
pub fn new() -> ProfileBuilder<profile_state::Empty, DefaultStr> {
ProfileBuilder::new()
}
}
impl<S: BosStr> Profile<S> {
pub fn builder() -> ProfileBuilder<profile_state::Empty, S> {
ProfileBuilder::builder()
}
}
impl ProfileBuilder<profile_state::Empty, DefaultStr> {
pub fn new() -> Self {
ProfileBuilder {
_state: PhantomData,
_fields: (
None, None, None, None, None, None, None, None, None, None, None,
),
_type: PhantomData,
}
}
}
impl<S: BosStr> ProfileBuilder<profile_state::Empty, S> {
pub fn builder() -> Self {
ProfileBuilder {
_state: PhantomData,
_fields: (
None, None, None, None, None, None, None, None, None, None, None,
),
_type: PhantomData,
}
}
}
impl<St: profile_state::State, S: BosStr> ProfileBuilder<St, S> {
pub fn account_indicators(
mut self,
value: impl Into<Option<Vec<AccountIndicator<S>>>>,
) -> Self {
self._fields.0 = value.into();
self
}
pub fn maybe_account_indicators(mut self, value: Option<Vec<AccountIndicator<S>>>) -> Self {
self._fields.0 = value;
self
}
}
impl<St, S: BosStr> ProfileBuilder<St, S>
where
St: profile_state::State,
St::CreatedAt: profile_state::IsUnset,
{
pub fn created_at(
mut self,
value: impl Into<Datetime>,
) -> ProfileBuilder<profile_state::SetCreatedAt<St>, S> {
self._fields.1 = Option::Some(value.into());
ProfileBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<St: profile_state::State, S: BosStr> ProfileBuilder<St, S> {
pub fn description(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.2 = value.into();
self
}
pub fn maybe_description(mut self, value: Option<S>) -> Self {
self._fields.2 = value;
self
}
}
impl<St: profile_state::State, S: BosStr> ProfileBuilder<St, S> {
pub fn images(mut self, value: impl Into<Option<Vec<Image<S>>>>) -> Self {
self._fields.3 = value.into();
self
}
pub fn maybe_images(mut self, value: Option<Vec<Image<S>>>) -> Self {
self._fields.3 = value;
self
}
}
impl<St: profile_state::State, S: BosStr> ProfileBuilder<St, S> {
pub fn lexicons(mut self, value: impl Into<Option<LexiconInterop<S>>>) -> Self {
self._fields.4 = value.into();
self
}
pub fn maybe_lexicons(mut self, value: Option<LexiconInterop<S>>) -> Self {
self._fields.4 = value;
self
}
}
impl<St, S: BosStr> ProfileBuilder<St, S>
where
St: profile_state::State,
St::Links: profile_state::IsUnset,
{
pub fn links(
mut self,
value: impl Into<Vec<Link<S>>>,
) -> ProfileBuilder<profile_state::SetLinks<St>, S> {
self._fields.5 = Option::Some(value.into());
ProfileBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<St, S: BosStr> ProfileBuilder<St, S>
where
St: profile_state::State,
St::Name: profile_state::IsUnset,
{
pub fn name(mut self, value: impl Into<S>) -> ProfileBuilder<profile_state::SetName<St>, S> {
self._fields.6 = Option::Some(value.into());
ProfileBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<St: profile_state::State, S: BosStr> ProfileBuilder<St, S> {
pub fn platforms(mut self, value: impl Into<Option<Vec<Platform<S>>>>) -> Self {
self._fields.7 = value.into();
self
}
pub fn maybe_platforms(mut self, value: Option<Vec<Platform<S>>>) -> Self {
self._fields.7 = value;
self
}
}
impl<St: profile_state::State, S: BosStr> ProfileBuilder<St, S> {
pub fn status(mut self, value: impl Into<Option<Status<S>>>) -> Self {
self._fields.8 = value.into();
self
}
pub fn maybe_status(mut self, value: Option<Status<S>>) -> Self {
self._fields.8 = value;
self
}
}
impl<St: profile_state::State, S: BosStr> ProfileBuilder<St, S> {
pub fn tags(mut self, value: impl Into<Option<Vec<S>>>) -> Self {
self._fields.9 = value.into();
self
}
pub fn maybe_tags(mut self, value: Option<Vec<S>>) -> Self {
self._fields.9 = value;
self
}
}
impl<St: profile_state::State, S: BosStr> ProfileBuilder<St, S> {
pub fn updated_at(mut self, value: impl Into<Option<Datetime>>) -> Self {
self._fields.10 = value.into();
self
}
pub fn maybe_updated_at(mut self, value: Option<Datetime>) -> Self {
self._fields.10 = value;
self
}
}
impl<St, S: BosStr> ProfileBuilder<St, S>
where
St: profile_state::State,
St::CreatedAt: profile_state::IsSet,
St::Links: profile_state::IsSet,
St::Name: profile_state::IsSet,
{
pub fn build(self) -> Profile<S> {
Profile {
account_indicators: self._fields.0,
created_at: self._fields.1.unwrap(),
description: self._fields.2,
images: self._fields.3,
lexicons: self._fields.4,
links: self._fields.5.unwrap(),
name: self._fields.6.unwrap(),
platforms: self._fields.7,
status: self._fields.8,
tags: self._fields.9,
updated_at: self._fields.10,
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Profile<S> {
Profile {
account_indicators: self._fields.0,
created_at: self._fields.1.unwrap(),
description: self._fields.2,
images: self._fields.3,
lexicons: self._fields.4,
links: self._fields.5.unwrap(),
name: self._fields.6.unwrap(),
platforms: self._fields.7,
status: self._fields.8,
tags: self._fields.9,
updated_at: self._fields.10,
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_community_lexicon_app_profile() -> 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("community.lexicon.app.profile"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("main"),
LexUserType::Record(LexRecord {
description: Some(
CowStr::new_static(
"The canonical self-published profile for an app built on or for the AT Protocol.",
),
),
key: Some(CowStr::new_static("literal:self")),
record: LexRecordRecord::Object(LexObject {
required: Some(
vec![
SmolStr::new_static("name"), SmolStr::new_static("links"),
SmolStr::new_static("createdAt")
],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("accountIndicators"),
LexObjectProperty::Array(LexArray {
description: Some(
CowStr::new_static(
"Records whose presence in an account can indicate that the account probably uses this app.",
),
),
items: LexArrayItem::Ref(LexRef {
r#ref: CowStr::new_static(
"community.lexicon.app.defs#accountIndicator",
),
..Default::default()
}),
max_length: Some(12usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("createdAt"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Client-declared timestamp when this profile was created.",
),
),
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("description"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"A short description of what the app does.",
),
),
max_length: Some(3000usize),
max_graphemes: Some(300usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("images"),
LexObjectProperty::Array(LexArray {
description: Some(
CowStr::new_static(
"Visual assets for directories and stores, such as icons, hero images, screenshots, banners, and social cards.",
),
),
items: LexArrayItem::Ref(LexRef {
r#ref: CowStr::new_static(
"community.lexicon.app.defs#image",
),
..Default::default()
}),
max_length: Some(24usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("lexicons"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static(
"community.lexicon.app.defs#lexiconInterop",
),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("links"),
LexObjectProperty::Array(LexArray {
description: Some(
CowStr::new_static(
"Relevant destinations for the app. The first link should be the primary destination.",
),
),
items: LexArrayItem::Ref(LexRef {
r#ref: CowStr::new_static(
"community.lexicon.app.defs#link",
),
..Default::default()
}),
min_length: Some(1usize),
max_length: Some(12usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("name"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("The display name of the app."),
),
max_length: Some(200usize),
max_graphemes: Some(100usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("platforms"),
LexObjectProperty::Array(LexArray {
description: Some(
CowStr::new_static("Platforms where this app is available."),
),
items: LexArrayItem::Ref(LexRef {
r#ref: CowStr::new_static(
"community.lexicon.app.defs#platform",
),
..Default::default()
}),
max_length: Some(12usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("status"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static(
"community.lexicon.app.defs#status",
),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("tags"),
LexObjectProperty::Array(LexArray {
description: Some(
CowStr::new_static(
"Open discovery tags for filtering and search, preferably lowercase. Do not use tags for platforms or lexicon interoperability.",
),
),
items: LexArrayItem::String(LexString {
max_length: Some(64usize),
max_graphemes: Some(32usize),
..Default::default()
}),
max_length: Some(10usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("updatedAt"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Client-declared timestamp when this profile was last updated.",
),
),
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map
},
..Default::default()
}),
..Default::default()
}),
);
map
},
..Default::default()
}
}