#[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::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, 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::network_cosmik::Provenance;
use crate::network_cosmik::card;
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
rename_all = "camelCase",
rename = "network.cosmik.card",
tag = "$type",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Card<S: BosStr = DefaultStr> {
pub content: CardContent<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub created_at: Option<Datetime>,
#[serde(skip_serializing_if = "Option::is_none")]
pub original_card: Option<StrongRef<S>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub parent_card: Option<StrongRef<S>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub provenance: Option<Provenance<S>>,
pub r#type: CardType<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub url: Option<UriValue<S>>,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub enum CardContent<S: BosStr = DefaultStr> {
#[serde(rename = "network.cosmik.card#urlContent")]
UrlContent(Box<card::UrlContent<S>>),
#[serde(rename = "network.cosmik.card#noteContent")]
NoteContent(Box<card::NoteContent<S>>),
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum CardType<S: BosStr = DefaultStr> {
Url,
Note,
Other(S),
}
impl<S: BosStr> CardType<S> {
pub fn as_str(&self) -> &str {
match self {
Self::Url => "URL",
Self::Note => "NOTE",
Self::Other(s) => s.as_ref(),
}
}
pub fn from_value(s: S) -> Self {
match s.as_ref() {
"URL" => Self::Url,
"NOTE" => Self::Note,
_ => Self::Other(s),
}
}
}
impl<S: BosStr> core::fmt::Display for CardType<S> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<S: BosStr> AsRef<str> for CardType<S> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<S: BosStr> Serialize for CardType<S> {
fn serialize<Ser>(&self, serializer: Ser) -> Result<Ser::Ok, Ser::Error>
where
Ser: serde::Serializer,
{
serializer.serialize_str(self.as_str())
}
}
impl<'de, S: Deserialize<'de> + BosStr> Deserialize<'de> for CardType<S> {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let s = S::deserialize(deserializer)?;
Ok(Self::from_value(s))
}
}
impl<S: BosStr + Default> Default for CardType<S> {
fn default() -> Self {
Self::Other(Default::default())
}
}
impl<S: BosStr> jacquard_common::IntoStatic for CardType<S>
where
S: BosStr + jacquard_common::IntoStatic,
S::Output: BosStr,
{
type Output = CardType<S::Output>;
fn into_static(self) -> Self::Output {
match self {
CardType::Url => CardType::Url,
CardType::Note => CardType::Note,
CardType::Other(v) => CardType::Other(v.into_static()),
}
}
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct CardGetRecordOutput<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub cid: Option<Cid<S>>,
pub uri: AtUri<S>,
pub value: Card<S>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct NoteContent<S: BosStr = DefaultStr> {
pub text: 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", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct UrlContent<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub metadata: Option<card::UrlMetadata<S>>,
pub url: 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, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct UrlMetadata<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub author: Option<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub doi: Option<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub image_url: Option<UriValue<S>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub isbn: Option<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub published_date: Option<Datetime>,
#[serde(skip_serializing_if = "Option::is_none")]
pub retrieved_at: Option<Datetime>,
#[serde(skip_serializing_if = "Option::is_none")]
pub site_name: Option<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub title: Option<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub r#type: Option<S>,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
impl<S: BosStr> Card<S> {
pub fn uri(uri: S) -> Result<RecordUri<S, CardRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new(uri)?)
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct CardRecord;
impl XrpcResp for CardRecord {
const NSID: &'static str = "network.cosmik.card";
const ENCODING: &'static str = "application/json";
type Output<S: BosStr> = CardGetRecordOutput<S>;
type Err = RecordError;
}
impl<S: BosStr> From<CardGetRecordOutput<S>> for Card<S> {
fn from(output: CardGetRecordOutput<S>) -> Self {
output.value
}
}
impl<S: BosStr> Collection for Card<S> {
const NSID: &'static str = "network.cosmik.card";
type Record = CardRecord;
}
impl Collection for CardRecord {
const NSID: &'static str = "network.cosmik.card";
type Record = CardRecord;
}
impl<S: BosStr> LexiconSchema for Card<S> {
fn nsid() -> &'static str {
"network.cosmik.card"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_network_cosmik_card()
}
fn validate(&self) -> Result<(), ConstraintError> {
Ok(())
}
}
impl<S: BosStr> LexiconSchema for NoteContent<S> {
fn nsid() -> &'static str {
"network.cosmik.card"
}
fn def_name() -> &'static str {
"noteContent"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_network_cosmik_card()
}
fn validate(&self) -> Result<(), ConstraintError> {
{
let value = &self.text;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 10000usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("text"),
max: 10000usize,
actual: <str>::len(value.as_ref()),
});
}
}
Ok(())
}
}
impl<S: BosStr> LexiconSchema for UrlContent<S> {
fn nsid() -> &'static str {
"network.cosmik.card"
}
fn def_name() -> &'static str {
"urlContent"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_network_cosmik_card()
}
fn validate(&self) -> Result<(), ConstraintError> {
Ok(())
}
}
impl<S: BosStr> LexiconSchema for UrlMetadata<S> {
fn nsid() -> &'static str {
"network.cosmik.card"
}
fn def_name() -> &'static str {
"urlMetadata"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_network_cosmik_card()
}
fn validate(&self) -> Result<(), ConstraintError> {
Ok(())
}
}
pub mod card_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 Type;
type Content;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Type = Unset;
type Content = Unset;
}
pub struct SetType<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetType<St> {}
impl<St: State> State for SetType<St> {
type Type = Set<members::r#type>;
type Content = St::Content;
}
pub struct SetContent<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetContent<St> {}
impl<St: State> State for SetContent<St> {
type Type = St::Type;
type Content = Set<members::content>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct r#type(());
pub struct content(());
}
}
pub struct CardBuilder<S: BosStr, St: card_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<CardContent<S>>,
Option<Datetime>,
Option<StrongRef<S>>,
Option<StrongRef<S>>,
Option<Provenance<S>>,
Option<CardType<S>>,
Option<UriValue<S>>,
),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> Card<S> {
pub fn new() -> CardBuilder<S, card_state::Empty> {
CardBuilder::new()
}
}
impl<S: BosStr> CardBuilder<S, card_state::Empty> {
pub fn new() -> Self {
CardBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St> CardBuilder<S, St>
where
St: card_state::State,
St::Content: card_state::IsUnset,
{
pub fn content(
mut self,
value: impl Into<CardContent<S>>,
) -> CardBuilder<S, card_state::SetContent<St>> {
self._fields.0 = Option::Some(value.into());
CardBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: card_state::State> CardBuilder<S, St> {
pub fn created_at(mut self, value: impl Into<Option<Datetime>>) -> Self {
self._fields.1 = value.into();
self
}
pub fn maybe_created_at(mut self, value: Option<Datetime>) -> Self {
self._fields.1 = value;
self
}
}
impl<S: BosStr, St: card_state::State> CardBuilder<S, St> {
pub fn original_card(mut self, value: impl Into<Option<StrongRef<S>>>) -> Self {
self._fields.2 = value.into();
self
}
pub fn maybe_original_card(mut self, value: Option<StrongRef<S>>) -> Self {
self._fields.2 = value;
self
}
}
impl<S: BosStr, St: card_state::State> CardBuilder<S, St> {
pub fn parent_card(mut self, value: impl Into<Option<StrongRef<S>>>) -> Self {
self._fields.3 = value.into();
self
}
pub fn maybe_parent_card(mut self, value: Option<StrongRef<S>>) -> Self {
self._fields.3 = value;
self
}
}
impl<S: BosStr, St: card_state::State> CardBuilder<S, St> {
pub fn provenance(mut self, value: impl Into<Option<Provenance<S>>>) -> Self {
self._fields.4 = value.into();
self
}
pub fn maybe_provenance(mut self, value: Option<Provenance<S>>) -> Self {
self._fields.4 = value;
self
}
}
impl<S: BosStr, St> CardBuilder<S, St>
where
St: card_state::State,
St::Type: card_state::IsUnset,
{
pub fn r#type(
mut self,
value: impl Into<CardType<S>>,
) -> CardBuilder<S, card_state::SetType<St>> {
self._fields.5 = Option::Some(value.into());
CardBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: card_state::State> CardBuilder<S, St> {
pub fn url(mut self, value: impl Into<Option<UriValue<S>>>) -> Self {
self._fields.6 = value.into();
self
}
pub fn maybe_url(mut self, value: Option<UriValue<S>>) -> Self {
self._fields.6 = value;
self
}
}
impl<S: BosStr, St> CardBuilder<S, St>
where
St: card_state::State,
St::Type: card_state::IsSet,
St::Content: card_state::IsSet,
{
pub fn build(self) -> Card<S> {
Card {
content: self._fields.0.unwrap(),
created_at: self._fields.1,
original_card: self._fields.2,
parent_card: self._fields.3,
provenance: self._fields.4,
r#type: self._fields.5.unwrap(),
url: self._fields.6,
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Card<S> {
Card {
content: self._fields.0.unwrap(),
created_at: self._fields.1,
original_card: self._fields.2,
parent_card: self._fields.3,
provenance: self._fields.4,
r#type: self._fields.5.unwrap(),
url: self._fields.6,
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_network_cosmik_card() -> 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("network.cosmik.card"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("main"),
LexUserType::Record(LexRecord {
description: Some(
CowStr::new_static("A record representing a card with content."),
),
key: Some(CowStr::new_static("tid")),
record: LexRecordRecord::Object(LexObject {
required: Some(
vec![
SmolStr::new_static("type"), SmolStr::new_static("content")
],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("content"),
LexObjectProperty::Union(LexRefUnion {
description: Some(
CowStr::new_static(
"The specific content of the card, determined by the card type.",
),
),
refs: vec![
CowStr::new_static("#urlContent"),
CowStr::new_static("#noteContent")
],
..Default::default()
}),
);
map.insert(
SmolStr::new_static("createdAt"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Timestamp when this card was created (usually set by PDS).",
),
),
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("originalCard"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static("com.atproto.repo.strongRef"),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("parentCard"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static("com.atproto.repo.strongRef"),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("provenance"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static("network.cosmik.defs#provenance"),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("type"),
LexObjectProperty::String(LexString {
description: Some(CowStr::new_static("The type of card")),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("url"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Optional URL associated with the card. Required for URL cards, optional for NOTE cards.",
),
),
format: Some(LexStringFormat::Uri),
..Default::default()
}),
);
map
},
..Default::default()
}),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("noteContent"),
LexUserType::Object(LexObject {
description: Some(
CowStr::new_static("Content structure for a note card."),
),
required: Some(vec![SmolStr::new_static("text")]),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("text"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("The note text content"),
),
max_length: Some(10000usize),
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map.insert(
SmolStr::new_static("urlContent"),
LexUserType::Object(LexObject {
description: Some(
CowStr::new_static("Content structure for a URL card."),
),
required: Some(vec![SmolStr::new_static("url")]),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("metadata"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static("#urlMetadata"),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("url"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("The URL being saved"),
),
format: Some(LexStringFormat::Uri),
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map.insert(
SmolStr::new_static("urlMetadata"),
LexUserType::Object(LexObject {
description: Some(CowStr::new_static("Metadata about a URL.")),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("author"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("Author of the content"),
),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("description"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("Description of the page"),
),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("doi"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Digital Object Identifier (DOI) for academic content",
),
),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("imageUrl"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("URL of a representative image"),
),
format: Some(LexStringFormat::Uri),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("isbn"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"International Standard Book Number (ISBN) for books",
),
),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("publishedDate"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("When the content was published"),
),
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("retrievedAt"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("When the metadata was retrieved"),
),
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("siteName"),
LexObjectProperty::String(LexString {
description: Some(CowStr::new_static("Name of the site")),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("title"),
LexObjectProperty::String(LexString {
description: Some(CowStr::new_static("Title of the page")),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("type"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Type of content (e.g., 'video', 'article')",
),
),
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map
},
..Default::default()
}
}
pub mod url_content_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 Url;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Url = Unset;
}
pub struct SetUrl<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetUrl<St> {}
impl<St: State> State for SetUrl<St> {
type Url = Set<members::url>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct url(());
}
}
pub struct UrlContentBuilder<S: BosStr, St: url_content_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (Option<card::UrlMetadata<S>>, Option<UriValue<S>>),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> UrlContent<S> {
pub fn new() -> UrlContentBuilder<S, url_content_state::Empty> {
UrlContentBuilder::new()
}
}
impl<S: BosStr> UrlContentBuilder<S, url_content_state::Empty> {
pub fn new() -> Self {
UrlContentBuilder {
_state: PhantomData,
_fields: (None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St: url_content_state::State> UrlContentBuilder<S, St> {
pub fn metadata(mut self, value: impl Into<Option<card::UrlMetadata<S>>>) -> Self {
self._fields.0 = value.into();
self
}
pub fn maybe_metadata(mut self, value: Option<card::UrlMetadata<S>>) -> Self {
self._fields.0 = value;
self
}
}
impl<S: BosStr, St> UrlContentBuilder<S, St>
where
St: url_content_state::State,
St::Url: url_content_state::IsUnset,
{
pub fn url(
mut self,
value: impl Into<UriValue<S>>,
) -> UrlContentBuilder<S, url_content_state::SetUrl<St>> {
self._fields.1 = Option::Some(value.into());
UrlContentBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> UrlContentBuilder<S, St>
where
St: url_content_state::State,
St::Url: url_content_state::IsSet,
{
pub fn build(self) -> UrlContent<S> {
UrlContent {
metadata: self._fields.0,
url: self._fields.1.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(
self,
extra_data: BTreeMap<SmolStr, Data<S>>,
) -> UrlContent<S> {
UrlContent {
metadata: self._fields.0,
url: self._fields.1.unwrap(),
extra_data: Some(extra_data),
}
}
}