#[allow(unused_imports)]
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::CowStr;
#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::types::collection::RecordError;
use jacquard_common::types::string::{AtUri, Cid, Datetime};
use jacquard_common::types::uri::{RecordUri, UriError};
use jacquard_common::xrpc::XrpcResp;
use jacquard_derive::{IntoStatic, lexicon, open_union};
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_atproto::repo::strong_ref::StrongRef;
use crate::org_hypercerts::LargeImage;
use crate::org_hypercerts::SmallImage;
use crate::org_hypercerts::Uri;
use crate::pub_leaflet::pages::linear_document::LinearDocument;
use crate::org_hypercerts::collection;
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Item<'a> {
#[serde(borrow)]
pub item_identifier: StrongRef<'a>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub item_weight: Option<CowStr<'a>>,
}
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Collection<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub avatar: Option<CollectionAvatar<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub banner: Option<CollectionBanner<'a>>,
pub created_at: Datetime,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub description: Option<LinearDocument<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub items: Option<Vec<collection::Item<'a>>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub location: Option<StrongRef<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub short_description: Option<CowStr<'a>>,
#[serde(borrow)]
pub title: CowStr<'a>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub r#type: Option<CowStr<'a>>,
}
#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type")]
#[serde(bound(deserialize = "'de: 'a"))]
pub enum CollectionAvatar<'a> {
#[serde(rename = "org.hypercerts.defs#uri")]
Uri(Box<Uri<'a>>),
#[serde(rename = "org.hypercerts.defs#smallImage")]
SmallImage(Box<SmallImage<'a>>),
}
#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type")]
#[serde(bound(deserialize = "'de: 'a"))]
pub enum CollectionBanner<'a> {
#[serde(rename = "org.hypercerts.defs#uri")]
Uri(Box<Uri<'a>>),
#[serde(rename = "org.hypercerts.defs#largeImage")]
LargeImage(Box<LargeImage<'a>>),
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct CollectionGetRecordOutput<'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: Collection<'a>,
}
impl<'a> Collection<'a> {
pub fn uri(
uri: impl Into<CowStr<'a>>,
) -> Result<RecordUri<'a, CollectionRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new_cow(uri.into())?)
}
}
impl<'a> LexiconSchema for Item<'a> {
fn nsid() -> &'static str {
"org.hypercerts.collection"
}
fn def_name() -> &'static str {
"item"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_org_hypercerts_collection()
}
fn validate(&self) -> Result<(), ConstraintError> {
if let Some(ref value) = self.item_weight {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 100usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("item_weight"),
max: 100usize,
actual: <str>::len(value.as_ref()),
});
}
}
Ok(())
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct CollectionRecord;
impl XrpcResp for CollectionRecord {
const NSID: &'static str = "org.hypercerts.collection";
const ENCODING: &'static str = "application/json";
type Output<'de> = CollectionGetRecordOutput<'de>;
type Err<'de> = RecordError<'de>;
}
impl From<CollectionGetRecordOutput<'_>> for Collection<'_> {
fn from(output: CollectionGetRecordOutput<'_>) -> Self {
use jacquard_common::IntoStatic;
output.value.into_static()
}
}
impl jacquard_common::types::collection::Collection for Collection<'_> {
const NSID: &'static str = "org.hypercerts.collection";
type Record = CollectionRecord;
}
impl jacquard_common::types::collection::Collection for CollectionRecord {
const NSID: &'static str = "org.hypercerts.collection";
type Record = CollectionRecord;
}
impl<'a> LexiconSchema for Collection<'a> {
fn nsid() -> &'static str {
"org.hypercerts.collection"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_org_hypercerts_collection()
}
fn validate(&self) -> Result<(), ConstraintError> {
if let Some(ref value) = self.items {
#[allow(unused_comparisons)]
if value.len() > 1000usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("items"),
max: 1000usize,
actual: value.len(),
});
}
}
if let Some(ref value) = self.short_description {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 3000usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("short_description"),
max: 3000usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.short_description {
{
let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
if count > 300usize {
return Err(ConstraintError::MaxGraphemes {
path: ValidationPath::from_field("short_description"),
max: 300usize,
actual: count,
});
}
}
}
{
let value = &self.title;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 800usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("title"),
max: 800usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.title;
{
let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
if count > 80usize {
return Err(ConstraintError::MaxGraphemes {
path: ValidationPath::from_field("title"),
max: 80usize,
actual: count,
});
}
}
}
if let Some(ref value) = self.r#type {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 64usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("type"),
max: 64usize,
actual: <str>::len(value.as_ref()),
});
}
}
Ok(())
}
}
pub mod item_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 ItemIdentifier;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type ItemIdentifier = Unset;
}
pub struct SetItemIdentifier<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetItemIdentifier<S> {}
impl<S: State> State for SetItemIdentifier<S> {
type ItemIdentifier = Set<members::item_identifier>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct item_identifier(());
}
}
pub struct ItemBuilder<'a, S: item_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (Option<StrongRef<'a>>, Option<CowStr<'a>>),
_lifetime: PhantomData<&'a ()>,
}
impl<'a> Item<'a> {
pub fn new() -> ItemBuilder<'a, item_state::Empty> {
ItemBuilder::new()
}
}
impl<'a> ItemBuilder<'a, item_state::Empty> {
pub fn new() -> Self {
ItemBuilder {
_state: PhantomData,
_fields: (None, None),
_lifetime: PhantomData,
}
}
}
impl<'a, S> ItemBuilder<'a, S>
where
S: item_state::State,
S::ItemIdentifier: item_state::IsUnset,
{
pub fn item_identifier(
mut self,
value: impl Into<StrongRef<'a>>,
) -> ItemBuilder<'a, item_state::SetItemIdentifier<S>> {
self._fields.0 = Option::Some(value.into());
ItemBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S: item_state::State> ItemBuilder<'a, S> {
pub fn item_weight(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
self._fields.1 = value.into();
self
}
pub fn maybe_item_weight(mut self, value: Option<CowStr<'a>>) -> Self {
self._fields.1 = value;
self
}
}
impl<'a, S> ItemBuilder<'a, S>
where
S: item_state::State,
S::ItemIdentifier: item_state::IsSet,
{
pub fn build(self) -> Item<'a> {
Item {
item_identifier: self._fields.0.unwrap(),
item_weight: self._fields.1,
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>,
>,
) -> Item<'a> {
Item {
item_identifier: self._fields.0.unwrap(),
item_weight: self._fields.1,
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_org_hypercerts_collection() -> 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("org.hypercerts.collection"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("item"),
LexUserType::Object(LexObject {
required: Some(vec![SmolStr::new_static("itemIdentifier")]),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("itemIdentifier"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static("com.atproto.repo.strongRef"),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("itemWeight"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Optional weight for this item (positive numeric value stored as string). Weights do not need to sum to a specific total; normalization can be performed by the consuming application as needed.",
),
),
max_length: Some(100usize),
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map.insert(
SmolStr::new_static("main"),
LexUserType::Record(LexRecord {
description: Some(
CowStr::new_static(
"A collection/group of items (activities and/or other collections). Collections support recursive nesting.",
),
),
key: Some(CowStr::new_static("tid")),
record: LexRecordRecord::Object(LexObject {
required: Some(
vec![
SmolStr::new_static("title"),
SmolStr::new_static("createdAt")
],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("avatar"),
LexObjectProperty::Union(LexRefUnion {
description: Some(
CowStr::new_static(
"The collection's avatar/profile image as a URI or image blob.",
),
),
refs: vec![
CowStr::new_static("org.hypercerts.defs#uri"),
CowStr::new_static("org.hypercerts.defs#smallImage")
],
..Default::default()
}),
);
map.insert(
SmolStr::new_static("banner"),
LexObjectProperty::Union(LexRefUnion {
description: Some(
CowStr::new_static(
"Larger horizontal image to display behind the collection view.",
),
),
refs: vec![
CowStr::new_static("org.hypercerts.defs#uri"),
CowStr::new_static("org.hypercerts.defs#largeImage")
],
..Default::default()
}),
);
map.insert(
SmolStr::new_static("createdAt"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Client-declared timestamp when this record was originally created",
),
),
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("description"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static(
"pub.leaflet.pages.linearDocument#main",
),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("items"),
LexObjectProperty::Array(LexArray {
description: Some(
CowStr::new_static(
"Array of items in this collection with optional weights.",
),
),
items: LexArrayItem::Ref(LexRef {
r#ref: CowStr::new_static("#item"),
..Default::default()
}),
max_length: Some(1000usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("location"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static("com.atproto.repo.strongRef"),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("shortDescription"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Short summary of this collection, suitable for previews and list views",
),
),
max_length: Some(3000usize),
max_graphemes: Some(300usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("title"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Display name for this collection (e.g. 'Q1 2025 Impact Projects')",
),
),
max_length: Some(800usize),
max_graphemes: Some(80usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("type"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"The type of this collection. Possible fields can be 'favorites', 'project', or any other type of collection.",
),
),
max_length: Some(64usize),
..Default::default()
}),
);
map
},
..Default::default()
}),
..Default::default()
}),
);
map
},
..Default::default()
}
}
pub mod collection_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 Title;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type CreatedAt = Unset;
type Title = Unset;
}
pub struct SetCreatedAt<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetCreatedAt<S> {}
impl<S: State> State for SetCreatedAt<S> {
type CreatedAt = Set<members::created_at>;
type Title = S::Title;
}
pub struct SetTitle<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetTitle<S> {}
impl<S: State> State for SetTitle<S> {
type CreatedAt = S::CreatedAt;
type Title = Set<members::title>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct created_at(());
pub struct title(());
}
}
pub struct CollectionBuilder<'a, S: collection_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (
Option<CollectionAvatar<'a>>,
Option<CollectionBanner<'a>>,
Option<Datetime>,
Option<LinearDocument<'a>>,
Option<Vec<collection::Item<'a>>>,
Option<StrongRef<'a>>,
Option<CowStr<'a>>,
Option<CowStr<'a>>,
Option<CowStr<'a>>,
),
_lifetime: PhantomData<&'a ()>,
}
impl<'a> Collection<'a> {
pub fn new() -> CollectionBuilder<'a, collection_state::Empty> {
CollectionBuilder::new()
}
}
impl<'a> CollectionBuilder<'a, collection_state::Empty> {
pub fn new() -> Self {
CollectionBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None, None, None, None),
_lifetime: PhantomData,
}
}
}
impl<'a, S: collection_state::State> CollectionBuilder<'a, S> {
pub fn avatar(mut self, value: impl Into<Option<CollectionAvatar<'a>>>) -> Self {
self._fields.0 = value.into();
self
}
pub fn maybe_avatar(mut self, value: Option<CollectionAvatar<'a>>) -> Self {
self._fields.0 = value;
self
}
}
impl<'a, S: collection_state::State> CollectionBuilder<'a, S> {
pub fn banner(mut self, value: impl Into<Option<CollectionBanner<'a>>>) -> Self {
self._fields.1 = value.into();
self
}
pub fn maybe_banner(mut self, value: Option<CollectionBanner<'a>>) -> Self {
self._fields.1 = value;
self
}
}
impl<'a, S> CollectionBuilder<'a, S>
where
S: collection_state::State,
S::CreatedAt: collection_state::IsUnset,
{
pub fn created_at(
mut self,
value: impl Into<Datetime>,
) -> CollectionBuilder<'a, collection_state::SetCreatedAt<S>> {
self._fields.2 = Option::Some(value.into());
CollectionBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S: collection_state::State> CollectionBuilder<'a, S> {
pub fn description(mut self, value: impl Into<Option<LinearDocument<'a>>>) -> Self {
self._fields.3 = value.into();
self
}
pub fn maybe_description(mut self, value: Option<LinearDocument<'a>>) -> Self {
self._fields.3 = value;
self
}
}
impl<'a, S: collection_state::State> CollectionBuilder<'a, S> {
pub fn items(mut self, value: impl Into<Option<Vec<collection::Item<'a>>>>) -> Self {
self._fields.4 = value.into();
self
}
pub fn maybe_items(mut self, value: Option<Vec<collection::Item<'a>>>) -> Self {
self._fields.4 = value;
self
}
}
impl<'a, S: collection_state::State> CollectionBuilder<'a, S> {
pub fn location(mut self, value: impl Into<Option<StrongRef<'a>>>) -> Self {
self._fields.5 = value.into();
self
}
pub fn maybe_location(mut self, value: Option<StrongRef<'a>>) -> Self {
self._fields.5 = value;
self
}
}
impl<'a, S: collection_state::State> CollectionBuilder<'a, S> {
pub fn short_description(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
self._fields.6 = value.into();
self
}
pub fn maybe_short_description(mut self, value: Option<CowStr<'a>>) -> Self {
self._fields.6 = value;
self
}
}
impl<'a, S> CollectionBuilder<'a, S>
where
S: collection_state::State,
S::Title: collection_state::IsUnset,
{
pub fn title(
mut self,
value: impl Into<CowStr<'a>>,
) -> CollectionBuilder<'a, collection_state::SetTitle<S>> {
self._fields.7 = Option::Some(value.into());
CollectionBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S: collection_state::State> CollectionBuilder<'a, S> {
pub fn r#type(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
self._fields.8 = value.into();
self
}
pub fn maybe_type(mut self, value: Option<CowStr<'a>>) -> Self {
self._fields.8 = value;
self
}
}
impl<'a, S> CollectionBuilder<'a, S>
where
S: collection_state::State,
S::CreatedAt: collection_state::IsSet,
S::Title: collection_state::IsSet,
{
pub fn build(self) -> Collection<'a> {
Collection {
avatar: self._fields.0,
banner: self._fields.1,
created_at: self._fields.2.unwrap(),
description: self._fields.3,
items: self._fields.4,
location: self._fields.5,
short_description: self._fields.6,
title: self._fields.7.unwrap(),
r#type: self._fields.8,
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>,
>,
) -> Collection<'a> {
Collection {
avatar: self._fields.0,
banner: self._fields.1,
created_at: self._fields.2.unwrap(),
description: self._fields.3,
items: self._fields.4,
location: self._fields.5,
short_description: self._fields.6,
title: self._fields.7.unwrap(),
r#type: self._fields.8,
extra_data: Some(extra_data),
}
}
}