#[allow(unused_imports)]
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::{CowStr, BosStr, DefaultStr, FromStaticStr};
#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::deps::smol_str::SmolStr;
use jacquard_common::types::blob::BlobRef;
use jacquard_common::types::collection::{Collection, RecordError};
use jacquard_common::types::string::{AtUri, Cid, Datetime, UriValue};
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::{Serialize, Deserialize};
use crate::social_showcase::ShowcaseItem;
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
rename_all = "camelCase",
rename = "social.showcase.profile.profile",
tag = "$type",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Profile<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub accent_color: Option<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub avatar: Option<BlobRef<S>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub banner: Option<BlobRef<S>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub bio: Option<S>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default = "_default_profile_collection_count")]
pub collection_count: Option<i64>,
pub created_at: Datetime,
pub did: S,
#[serde(skip_serializing_if = "Option::is_none")]
pub display_name: Option<S>,
pub handle: S,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default = "_default_profile_item_count")]
pub item_count: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default = "_default_profile_schema_version")]
pub schema_version: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub showcase: Option<Vec<ShowcaseItem<S>>>,
pub tags: Vec<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub theme: Option<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub updated_at: Option<Datetime>,
#[serde(skip_serializing_if = "Option::is_none")]
pub website: Option<UriValue<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 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 = "social.showcase.profile.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 = "social.showcase.profile.profile";
type Record = ProfileRecord;
}
impl Collection for ProfileRecord {
const NSID: &'static str = "social.showcase.profile.profile";
type Record = ProfileRecord;
}
impl<S: BosStr> LexiconSchema for Profile<S> {
fn nsid() -> &'static str {
"social.showcase.profile.profile"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_social_showcase_profile_profile()
}
fn validate(&self) -> Result<(), ConstraintError> {
if let Some(ref value) = self.accent_color {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 7usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("accent_color"),
max: 7usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.avatar {
{
let size = value.blob().size;
if size > 1000000usize {
return Err(ConstraintError::BlobTooLarge {
path: ValidationPath::from_field("avatar"),
max: 1000000usize,
actual: size,
});
}
}
}
if let Some(ref value) = self.avatar {
{
let mime = value.blob().mime_type.as_str();
let accepted: &[&str] = &["image/png", "image/jpeg", "image/webp"];
let matched = accepted
.iter()
.any(|pattern| {
if *pattern == "*/*" {
true
} else if pattern.ends_with("/*") {
let prefix = &pattern[..pattern.len() - 2];
mime.starts_with(prefix)
&& mime.as_bytes().get(prefix.len()) == Some(&b'/')
} else {
mime == *pattern
}
});
if !matched {
return Err(ConstraintError::BlobMimeTypeNotAccepted {
path: ValidationPath::from_field("avatar"),
accepted: vec![
"image/png".to_string(), "image/jpeg".to_string(),
"image/webp".to_string()
],
actual: mime.to_string(),
});
}
}
}
if let Some(ref value) = self.banner {
{
let size = value.blob().size;
if size > 1000000usize {
return Err(ConstraintError::BlobTooLarge {
path: ValidationPath::from_field("banner"),
max: 1000000usize,
actual: size,
});
}
}
}
if let Some(ref value) = self.banner {
{
let mime = value.blob().mime_type.as_str();
let accepted: &[&str] = &["image/png", "image/jpeg", "image/webp"];
let matched = accepted
.iter()
.any(|pattern| {
if *pattern == "*/*" {
true
} else if pattern.ends_with("/*") {
let prefix = &pattern[..pattern.len() - 2];
mime.starts_with(prefix)
&& mime.as_bytes().get(prefix.len()) == Some(&b'/')
} else {
mime == *pattern
}
});
if !matched {
return Err(ConstraintError::BlobMimeTypeNotAccepted {
path: ValidationPath::from_field("banner"),
accepted: vec![
"image/png".to_string(), "image/jpeg".to_string(),
"image/webp".to_string()
],
actual: mime.to_string(),
});
}
}
}
if let Some(ref value) = self.bio {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 256usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("bio"),
max: 256usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.did;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 2048usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("did"),
max: 2048usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.display_name {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 64usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("display_name"),
max: 64usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.handle;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 253usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("handle"),
max: 253usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.showcase {
#[allow(unused_comparisons)]
if value.len() > 4usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("showcase"),
max: 4usize,
actual: value.len(),
});
}
}
{
let value = &self.tags;
#[allow(unused_comparisons)]
if value.len() > 10usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("tags"),
max: 10usize,
actual: value.len(),
});
}
}
if let Some(ref value) = self.theme {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 64usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("theme"),
max: 64usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.website {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 2048usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("website"),
max: 2048usize,
actual: <str>::len(value.as_ref()),
});
}
}
Ok(())
}
}
fn _default_profile_collection_count() -> Option<i64> {
Some(0i64)
}
fn _default_profile_item_count() -> Option<i64> {
Some(0i64)
}
fn _default_profile_schema_version() -> Option<i64> {
Some(1i64)
}
pub mod profile_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 CreatedAt;
type Handle;
type Tags;
type Did;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type CreatedAt = Unset;
type Handle = Unset;
type Tags = Unset;
type Did = 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 Handle = St::Handle;
type Tags = St::Tags;
type Did = St::Did;
}
pub struct SetHandle<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetHandle<St> {}
impl<St: State> State for SetHandle<St> {
type CreatedAt = St::CreatedAt;
type Handle = Set<members::handle>;
type Tags = St::Tags;
type Did = St::Did;
}
pub struct SetTags<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetTags<St> {}
impl<St: State> State for SetTags<St> {
type CreatedAt = St::CreatedAt;
type Handle = St::Handle;
type Tags = Set<members::tags>;
type Did = St::Did;
}
pub struct SetDid<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetDid<St> {}
impl<St: State> State for SetDid<St> {
type CreatedAt = St::CreatedAt;
type Handle = St::Handle;
type Tags = St::Tags;
type Did = Set<members::did>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct created_at(());
pub struct handle(());
pub struct tags(());
pub struct did(());
}
}
pub struct ProfileBuilder<S: BosStr, St: profile_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<S>,
Option<BlobRef<S>>,
Option<BlobRef<S>>,
Option<S>,
Option<i64>,
Option<Datetime>,
Option<S>,
Option<S>,
Option<S>,
Option<i64>,
Option<i64>,
Option<Vec<ShowcaseItem<S>>>,
Option<Vec<S>>,
Option<S>,
Option<Datetime>,
Option<UriValue<S>>,
),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> Profile<S> {
pub fn new() -> ProfileBuilder<S, profile_state::Empty> {
ProfileBuilder::new()
}
}
impl<S: BosStr> ProfileBuilder<S, profile_state::Empty> {
pub fn new() -> Self {
ProfileBuilder {
_state: PhantomData,
_fields: (
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
),
_type: PhantomData,
}
}
}
impl<S: BosStr, St: profile_state::State> ProfileBuilder<S, St> {
pub fn accent_color(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.0 = value.into();
self
}
pub fn maybe_accent_color(mut self, value: Option<S>) -> Self {
self._fields.0 = value;
self
}
}
impl<S: BosStr, St: profile_state::State> ProfileBuilder<S, St> {
pub fn avatar(mut self, value: impl Into<Option<BlobRef<S>>>) -> Self {
self._fields.1 = value.into();
self
}
pub fn maybe_avatar(mut self, value: Option<BlobRef<S>>) -> Self {
self._fields.1 = value;
self
}
}
impl<S: BosStr, St: profile_state::State> ProfileBuilder<S, St> {
pub fn banner(mut self, value: impl Into<Option<BlobRef<S>>>) -> Self {
self._fields.2 = value.into();
self
}
pub fn maybe_banner(mut self, value: Option<BlobRef<S>>) -> Self {
self._fields.2 = value;
self
}
}
impl<S: BosStr, St: profile_state::State> ProfileBuilder<S, St> {
pub fn bio(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.3 = value.into();
self
}
pub fn maybe_bio(mut self, value: Option<S>) -> Self {
self._fields.3 = value;
self
}
}
impl<S: BosStr, St: profile_state::State> ProfileBuilder<S, St> {
pub fn collection_count(mut self, value: impl Into<Option<i64>>) -> Self {
self._fields.4 = value.into();
self
}
pub fn maybe_collection_count(mut self, value: Option<i64>) -> Self {
self._fields.4 = value;
self
}
}
impl<S: BosStr, St> ProfileBuilder<S, St>
where
St: profile_state::State,
St::CreatedAt: profile_state::IsUnset,
{
pub fn created_at(
mut self,
value: impl Into<Datetime>,
) -> ProfileBuilder<S, profile_state::SetCreatedAt<St>> {
self._fields.5 = Option::Some(value.into());
ProfileBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> ProfileBuilder<S, St>
where
St: profile_state::State,
St::Did: profile_state::IsUnset,
{
pub fn did(
mut self,
value: impl Into<S>,
) -> ProfileBuilder<S, profile_state::SetDid<St>> {
self._fields.6 = Option::Some(value.into());
ProfileBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: profile_state::State> ProfileBuilder<S, St> {
pub fn display_name(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.7 = value.into();
self
}
pub fn maybe_display_name(mut self, value: Option<S>) -> Self {
self._fields.7 = value;
self
}
}
impl<S: BosStr, St> ProfileBuilder<S, St>
where
St: profile_state::State,
St::Handle: profile_state::IsUnset,
{
pub fn handle(
mut self,
value: impl Into<S>,
) -> ProfileBuilder<S, profile_state::SetHandle<St>> {
self._fields.8 = Option::Some(value.into());
ProfileBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: profile_state::State> ProfileBuilder<S, St> {
pub fn item_count(mut self, value: impl Into<Option<i64>>) -> Self {
self._fields.9 = value.into();
self
}
pub fn maybe_item_count(mut self, value: Option<i64>) -> Self {
self._fields.9 = value;
self
}
}
impl<S: BosStr, St: profile_state::State> ProfileBuilder<S, St> {
pub fn schema_version(mut self, value: impl Into<Option<i64>>) -> Self {
self._fields.10 = value.into();
self
}
pub fn maybe_schema_version(mut self, value: Option<i64>) -> Self {
self._fields.10 = value;
self
}
}
impl<S: BosStr, St: profile_state::State> ProfileBuilder<S, St> {
pub fn showcase(mut self, value: impl Into<Option<Vec<ShowcaseItem<S>>>>) -> Self {
self._fields.11 = value.into();
self
}
pub fn maybe_showcase(mut self, value: Option<Vec<ShowcaseItem<S>>>) -> Self {
self._fields.11 = value;
self
}
}
impl<S: BosStr, St> ProfileBuilder<S, St>
where
St: profile_state::State,
St::Tags: profile_state::IsUnset,
{
pub fn tags(
mut self,
value: impl Into<Vec<S>>,
) -> ProfileBuilder<S, profile_state::SetTags<St>> {
self._fields.12 = Option::Some(value.into());
ProfileBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: profile_state::State> ProfileBuilder<S, St> {
pub fn theme(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.13 = value.into();
self
}
pub fn maybe_theme(mut self, value: Option<S>) -> Self {
self._fields.13 = value;
self
}
}
impl<S: BosStr, St: profile_state::State> ProfileBuilder<S, St> {
pub fn updated_at(mut self, value: impl Into<Option<Datetime>>) -> Self {
self._fields.14 = value.into();
self
}
pub fn maybe_updated_at(mut self, value: Option<Datetime>) -> Self {
self._fields.14 = value;
self
}
}
impl<S: BosStr, St: profile_state::State> ProfileBuilder<S, St> {
pub fn website(mut self, value: impl Into<Option<UriValue<S>>>) -> Self {
self._fields.15 = value.into();
self
}
pub fn maybe_website(mut self, value: Option<UriValue<S>>) -> Self {
self._fields.15 = value;
self
}
}
impl<S: BosStr, St> ProfileBuilder<S, St>
where
St: profile_state::State,
St::CreatedAt: profile_state::IsSet,
St::Handle: profile_state::IsSet,
St::Tags: profile_state::IsSet,
St::Did: profile_state::IsSet,
{
pub fn build(self) -> Profile<S> {
Profile {
accent_color: self._fields.0,
avatar: self._fields.1,
banner: self._fields.2,
bio: self._fields.3,
collection_count: self._fields.4.or_else(|| Some(0i64)),
created_at: self._fields.5.unwrap(),
did: self._fields.6.unwrap(),
display_name: self._fields.7,
handle: self._fields.8.unwrap(),
item_count: self._fields.9.or_else(|| Some(0i64)),
schema_version: self._fields.10.or_else(|| Some(1i64)),
showcase: self._fields.11,
tags: self._fields.12.unwrap(),
theme: self._fields.13,
updated_at: self._fields.14,
website: self._fields.15,
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Profile<S> {
Profile {
accent_color: self._fields.0,
avatar: self._fields.1,
banner: self._fields.2,
bio: self._fields.3,
collection_count: self._fields.4.or_else(|| Some(0i64)),
created_at: self._fields.5.unwrap(),
did: self._fields.6.unwrap(),
display_name: self._fields.7,
handle: self._fields.8.unwrap(),
item_count: self._fields.9.or_else(|| Some(0i64)),
schema_version: self._fields.10.or_else(|| Some(1i64)),
showcase: self._fields.11,
tags: self._fields.12.unwrap(),
theme: self._fields.13,
updated_at: self._fields.14,
website: self._fields.15,
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_social_showcase_profile_profile() -> 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("social.showcase.profile.profile"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("main"),
LexUserType::Record(LexRecord {
description: Some(CowStr::new_static("User profile record")),
key: Some(CowStr::new_static("literal:self")),
record: LexRecordRecord::Object(LexObject {
required: Some(
vec![
SmolStr::new_static("did"), SmolStr::new_static("handle"),
SmolStr::new_static("tags"),
SmolStr::new_static("createdAt")
],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("accentColor"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Custom accent color hex code (e.g. #2e4a6e)",
),
),
max_length: Some(7usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("avatar"),
LexObjectProperty::Blob(LexBlob { ..Default::default() }),
);
map.insert(
SmolStr::new_static("banner"),
LexObjectProperty::Blob(LexBlob { ..Default::default() }),
);
map.insert(
SmolStr::new_static("bio"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("Profile description"),
),
max_length: Some(256usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("collectionCount"),
LexObjectProperty::Integer(LexInteger {
..Default::default()
}),
);
map.insert(
SmolStr::new_static("createdAt"),
LexObjectProperty::String(LexString {
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("did"),
LexObjectProperty::String(LexString {
description: Some(CowStr::new_static("User's DID")),
max_length: Some(2048usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("displayName"),
LexObjectProperty::String(LexString {
description: Some(CowStr::new_static("Display name")),
max_length: Some(64usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("handle"),
LexObjectProperty::String(LexString {
description: Some(CowStr::new_static("User's handle")),
max_length: Some(253usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("itemCount"),
LexObjectProperty::Integer(LexInteger {
..Default::default()
}),
);
map.insert(
SmolStr::new_static("schemaVersion"),
LexObjectProperty::Integer(LexInteger {
..Default::default()
}),
);
map.insert(
SmolStr::new_static("showcase"),
LexObjectProperty::Array(LexArray {
description: Some(
CowStr::new_static("Featured showcase items"),
),
items: LexArrayItem::Ref(LexRef {
r#ref: CowStr::new_static(
"social.showcase.defs#showcaseItem",
),
..Default::default()
}),
max_length: Some(4usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("tags"),
LexObjectProperty::Array(LexArray {
description: Some(
CowStr::new_static("Profile tags for discovery (max 10)"),
),
items: LexArrayItem::String(LexString {
max_length: Some(64usize),
..Default::default()
}),
max_length: Some(10usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("theme"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("Profile theme preset name"),
),
max_length: Some(64usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("updatedAt"),
LexObjectProperty::String(LexString {
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("website"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("External website URL"),
),
format: Some(LexStringFormat::Uri),
max_length: Some(2048usize),
..Default::default()
}),
);
map
},
..Default::default()
}),
..Default::default()
}),
);
map
},
..Default::default()
}
}