#[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::{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::ItemImage;
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Item<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub category: Option<CowStr<'a>>,
pub created_at: Datetime,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub description: Option<CowStr<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub external_link: Option<UriValue<'a>>,
#[serde(borrow)]
pub images: Vec<ItemImage<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub metadata: Option<Data<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub notes: Option<CowStr<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default = "_default_item_schema_version")]
pub schema_version: Option<i64>,
#[serde(borrow)]
pub tags: Vec<CowStr<'a>>,
#[serde(borrow)]
pub title: CowStr<'a>,
#[serde(skip_serializing_if = "Option::is_none")]
pub updated_at: Option<Datetime>,
#[serde(borrow)]
pub visibility: ItemVisibility<'a>,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum ItemVisibility<'a> {
Public,
Unlisted,
Private,
Other(CowStr<'a>),
}
impl<'a> ItemVisibility<'a> {
pub fn as_str(&self) -> &str {
match self {
Self::Public => "public",
Self::Unlisted => "unlisted",
Self::Private => "private",
Self::Other(s) => s.as_ref(),
}
}
}
impl<'a> From<&'a str> for ItemVisibility<'a> {
fn from(s: &'a str) -> Self {
match s {
"public" => Self::Public,
"unlisted" => Self::Unlisted,
"private" => Self::Private,
_ => Self::Other(CowStr::from(s)),
}
}
}
impl<'a> From<String> for ItemVisibility<'a> {
fn from(s: String) -> Self {
match s.as_str() {
"public" => Self::Public,
"unlisted" => Self::Unlisted,
"private" => Self::Private,
_ => Self::Other(CowStr::from(s)),
}
}
}
impl<'a> core::fmt::Display for ItemVisibility<'a> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<'a> AsRef<str> for ItemVisibility<'a> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<'a> serde::Serialize for ItemVisibility<'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 ItemVisibility<'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 ItemVisibility<'a> {
fn default() -> Self {
Self::Other(Default::default())
}
}
impl jacquard_common::IntoStatic for ItemVisibility<'_> {
type Output = ItemVisibility<'static>;
fn into_static(self) -> Self::Output {
match self {
ItemVisibility::Public => ItemVisibility::Public,
ItemVisibility::Unlisted => ItemVisibility::Unlisted,
ItemVisibility::Private => ItemVisibility::Private,
ItemVisibility::Other(v) => ItemVisibility::Other(v.into_static()),
}
}
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct ItemGetRecordOutput<'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: Item<'a>,
}
impl<'a> Item<'a> {
pub fn uri(
uri: impl Into<CowStr<'a>>,
) -> Result<RecordUri<'a, ItemRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new_cow(uri.into())?)
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct ItemRecord;
impl XrpcResp for ItemRecord {
const NSID: &'static str = "social.showcase.library.item";
const ENCODING: &'static str = "application/json";
type Output<'de> = ItemGetRecordOutput<'de>;
type Err<'de> = RecordError<'de>;
}
impl From<ItemGetRecordOutput<'_>> for Item<'_> {
fn from(output: ItemGetRecordOutput<'_>) -> Self {
use jacquard_common::IntoStatic;
output.value.into_static()
}
}
impl Collection for Item<'_> {
const NSID: &'static str = "social.showcase.library.item";
type Record = ItemRecord;
}
impl Collection for ItemRecord {
const NSID: &'static str = "social.showcase.library.item";
type Record = ItemRecord;
}
impl<'a> LexiconSchema for Item<'a> {
fn nsid() -> &'static str {
"social.showcase.library.item"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_social_showcase_library_item()
}
fn validate(&self) -> Result<(), ConstraintError> {
if let Some(ref value) = self.category {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 100usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("category"),
max: 100usize,
actual: <str>::len(value.as_ref()),
});
}
}
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()),
});
}
}
{
let value = &self.images;
#[allow(unused_comparisons)]
if value.len() > 6usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("images"),
max: 6usize,
actual: value.len(),
});
}
}
if let Some(ref value) = self.notes {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 2000usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("notes"),
max: 2000usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.tags;
#[allow(unused_comparisons)]
if value.len() > 20usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("tags"),
max: 20usize,
actual: value.len(),
});
}
}
{
let value = &self.title;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 300usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("title"),
max: 300usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.visibility;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 10usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("visibility"),
max: 10usize,
actual: <str>::len(value.as_ref()),
});
}
}
Ok(())
}
}
fn _default_item_schema_version() -> Option<i64> {
Some(1i64)
}
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 Images;
type Visibility;
type CreatedAt;
type Tags;
type Title;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Images = Unset;
type Visibility = Unset;
type CreatedAt = Unset;
type Tags = Unset;
type Title = Unset;
}
pub struct SetImages<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetImages<S> {}
impl<S: State> State for SetImages<S> {
type Images = Set<members::images>;
type Visibility = S::Visibility;
type CreatedAt = S::CreatedAt;
type Tags = S::Tags;
type Title = S::Title;
}
pub struct SetVisibility<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetVisibility<S> {}
impl<S: State> State for SetVisibility<S> {
type Images = S::Images;
type Visibility = Set<members::visibility>;
type CreatedAt = S::CreatedAt;
type Tags = S::Tags;
type Title = S::Title;
}
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 Images = S::Images;
type Visibility = S::Visibility;
type CreatedAt = Set<members::created_at>;
type Tags = S::Tags;
type Title = S::Title;
}
pub struct SetTags<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetTags<S> {}
impl<S: State> State for SetTags<S> {
type Images = S::Images;
type Visibility = S::Visibility;
type CreatedAt = S::CreatedAt;
type Tags = Set<members::tags>;
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 Images = S::Images;
type Visibility = S::Visibility;
type CreatedAt = S::CreatedAt;
type Tags = S::Tags;
type Title = Set<members::title>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct images(());
pub struct visibility(());
pub struct created_at(());
pub struct tags(());
pub struct title(());
}
}
pub struct ItemBuilder<'a, S: item_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (
Option<CowStr<'a>>,
Option<Datetime>,
Option<CowStr<'a>>,
Option<UriValue<'a>>,
Option<Vec<ItemImage<'a>>>,
Option<Data<'a>>,
Option<CowStr<'a>>,
Option<i64>,
Option<Vec<CowStr<'a>>>,
Option<CowStr<'a>>,
Option<Datetime>,
Option<ItemVisibility<'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,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
),
_lifetime: PhantomData,
}
}
}
impl<'a, S: item_state::State> ItemBuilder<'a, S> {
pub fn category(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
self._fields.0 = value.into();
self
}
pub fn maybe_category(mut self, value: Option<CowStr<'a>>) -> Self {
self._fields.0 = value;
self
}
}
impl<'a, S> ItemBuilder<'a, S>
where
S: item_state::State,
S::CreatedAt: item_state::IsUnset,
{
pub fn created_at(
mut self,
value: impl Into<Datetime>,
) -> ItemBuilder<'a, item_state::SetCreatedAt<S>> {
self._fields.1 = Option::Some(value.into());
ItemBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S: item_state::State> ItemBuilder<'a, S> {
pub fn description(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
self._fields.2 = value.into();
self
}
pub fn maybe_description(mut self, value: Option<CowStr<'a>>) -> Self {
self._fields.2 = value;
self
}
}
impl<'a, S: item_state::State> ItemBuilder<'a, S> {
pub fn external_link(mut self, value: impl Into<Option<UriValue<'a>>>) -> Self {
self._fields.3 = value.into();
self
}
pub fn maybe_external_link(mut self, value: Option<UriValue<'a>>) -> Self {
self._fields.3 = value;
self
}
}
impl<'a, S> ItemBuilder<'a, S>
where
S: item_state::State,
S::Images: item_state::IsUnset,
{
pub fn images(
mut self,
value: impl Into<Vec<ItemImage<'a>>>,
) -> ItemBuilder<'a, item_state::SetImages<S>> {
self._fields.4 = Option::Some(value.into());
ItemBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S: item_state::State> ItemBuilder<'a, S> {
pub fn metadata(mut self, value: impl Into<Option<Data<'a>>>) -> Self {
self._fields.5 = value.into();
self
}
pub fn maybe_metadata(mut self, value: Option<Data<'a>>) -> Self {
self._fields.5 = value;
self
}
}
impl<'a, S: item_state::State> ItemBuilder<'a, S> {
pub fn notes(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
self._fields.6 = value.into();
self
}
pub fn maybe_notes(mut self, value: Option<CowStr<'a>>) -> Self {
self._fields.6 = value;
self
}
}
impl<'a, S: item_state::State> ItemBuilder<'a, S> {
pub fn schema_version(mut self, value: impl Into<Option<i64>>) -> Self {
self._fields.7 = value.into();
self
}
pub fn maybe_schema_version(mut self, value: Option<i64>) -> Self {
self._fields.7 = value;
self
}
}
impl<'a, S> ItemBuilder<'a, S>
where
S: item_state::State,
S::Tags: item_state::IsUnset,
{
pub fn tags(
mut self,
value: impl Into<Vec<CowStr<'a>>>,
) -> ItemBuilder<'a, item_state::SetTags<S>> {
self._fields.8 = Option::Some(value.into());
ItemBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> ItemBuilder<'a, S>
where
S: item_state::State,
S::Title: item_state::IsUnset,
{
pub fn title(
mut self,
value: impl Into<CowStr<'a>>,
) -> ItemBuilder<'a, item_state::SetTitle<S>> {
self._fields.9 = Option::Some(value.into());
ItemBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S: item_state::State> ItemBuilder<'a, 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<'a, S> ItemBuilder<'a, S>
where
S: item_state::State,
S::Visibility: item_state::IsUnset,
{
pub fn visibility(
mut self,
value: impl Into<ItemVisibility<'a>>,
) -> ItemBuilder<'a, item_state::SetVisibility<S>> {
self._fields.11 = Option::Some(value.into());
ItemBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> ItemBuilder<'a, S>
where
S: item_state::State,
S::Images: item_state::IsSet,
S::Visibility: item_state::IsSet,
S::CreatedAt: item_state::IsSet,
S::Tags: item_state::IsSet,
S::Title: item_state::IsSet,
{
pub fn build(self) -> Item<'a> {
Item {
category: self._fields.0,
created_at: self._fields.1.unwrap(),
description: self._fields.2,
external_link: self._fields.3,
images: self._fields.4.unwrap(),
metadata: self._fields.5,
notes: self._fields.6,
schema_version: self._fields.7.or_else(|| Some(1i64)),
tags: self._fields.8.unwrap(),
title: self._fields.9.unwrap(),
updated_at: self._fields.10,
visibility: self._fields.11.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(
self,
extra_data: BTreeMap<jacquard_common::deps::smol_str::SmolStr, Data<'a>>,
) -> Item<'a> {
Item {
category: self._fields.0,
created_at: self._fields.1.unwrap(),
description: self._fields.2,
external_link: self._fields.3,
images: self._fields.4.unwrap(),
metadata: self._fields.5,
notes: self._fields.6,
schema_version: self._fields.7.or_else(|| Some(1i64)),
tags: self._fields.8.unwrap(),
title: self._fields.9.unwrap(),
updated_at: self._fields.10,
visibility: self._fields.11.unwrap(),
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_social_showcase_library_item() -> 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.library.item"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("main"),
LexUserType::Record(LexRecord {
description: Some(CowStr::new_static("Showcase item record")),
key: Some(CowStr::new_static("tid")),
record: LexRecordRecord::Object(LexObject {
required: Some(
vec![
SmolStr::new_static("title"), SmolStr::new_static("tags"),
SmolStr::new_static("images"),
SmolStr::new_static("visibility"),
SmolStr::new_static("createdAt")
],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("category"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("Category/type of item"),
),
max_length: Some(100usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("createdAt"),
LexObjectProperty::String(LexString {
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("description"),
LexObjectProperty::String(LexString {
description: Some(CowStr::new_static("Item description")),
max_length: Some(3000usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("externalLink"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("Link to external site"),
),
format: Some(LexStringFormat::Uri),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("images"),
LexObjectProperty::Array(LexArray {
description: Some(
CowStr::new_static(
"Embedded image blobs (max 6 images, 2000x2000px max, 5MB each)",
),
),
items: LexArrayItem::Ref(LexRef {
r#ref: CowStr::new_static("social.showcase.defs#itemImage"),
..Default::default()
}),
max_length: Some(6usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("metadata"),
LexObjectProperty::Unknown(LexUnknown {
..Default::default()
}),
);
map.insert(
SmolStr::new_static("notes"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("Personal notes or story about the item"),
),
max_length: Some(2000usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("schemaVersion"),
LexObjectProperty::Integer(LexInteger {
..Default::default()
}),
);
map.insert(
SmolStr::new_static("tags"),
LexObjectProperty::Array(LexArray {
description: Some(
CowStr::new_static("Tags for discovery (max 20)"),
),
items: LexArrayItem::String(LexString {
max_length: Some(64usize),
..Default::default()
}),
max_length: Some(20usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("title"),
LexObjectProperty::String(LexString {
description: Some(CowStr::new_static("Item title")),
max_length: Some(300usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("updatedAt"),
LexObjectProperty::String(LexString {
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("visibility"),
LexObjectProperty::String(LexString {
max_length: Some(10usize),
..Default::default()
}),
);
map
},
..Default::default()
}),
..Default::default()
}),
);
map
},
..Default::default()
}
}