// @generated by jacquard-lexicon. DO NOT EDIT. // // Lexicon: network.cosmik.card // // This file was automatically generated from Lexicon schemas. // Any manual changes will be overwritten on the next regeneration. #[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::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; /// A record representing a card with content. #[lexicon] #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)] #[serde(rename_all = "camelCase")] pub struct Card<'a> { ///The specific content of the card, determined by the card type. #[serde(borrow)] pub content: CardContent<'a>, ///Timestamp when this card was created (usually set by PDS). #[serde(skip_serializing_if = "Option::is_none")] pub created_at: Option, ///Optional strong reference to the original card (for NOTE cards). #[serde(skip_serializing_if = "Option::is_none")] #[serde(borrow)] pub original_card: Option>, ///Optional strong reference to a parent card (for NOTE cards). #[serde(skip_serializing_if = "Option::is_none")] #[serde(borrow)] pub parent_card: Option>, ///Optional provenance information for this card. #[serde(skip_serializing_if = "Option::is_none")] #[serde(borrow)] pub provenance: Option>, ///The type of card #[serde(borrow)] pub r#type: CardType<'a>, ///Optional URL associated with the card. Required for URL cards, optional for NOTE cards. #[serde(skip_serializing_if = "Option::is_none")] #[serde(borrow)] pub url: Option>, } #[open_union] #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)] #[serde(tag = "$type")] #[serde(bound(deserialize = "'de: 'a"))] pub enum CardContent<'a> { #[serde(rename = "network.cosmik.card#urlContent")] UrlContent(Box>), #[serde(rename = "network.cosmik.card#noteContent")] NoteContent(Box>), } /// The type of card #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum CardType<'a> { Url, Note, Other(CowStr<'a>), } impl<'a> CardType<'a> { pub fn as_str(&self) -> &str { match self { Self::Url => "URL", Self::Note => "NOTE", Self::Other(s) => s.as_ref(), } } } impl<'a> From<&'a str> for CardType<'a> { fn from(s: &'a str) -> Self { match s { "URL" => Self::Url, "NOTE" => Self::Note, _ => Self::Other(CowStr::from(s)), } } } impl<'a> From for CardType<'a> { fn from(s: String) -> Self { match s.as_str() { "URL" => Self::Url, "NOTE" => Self::Note, _ => Self::Other(CowStr::from(s)), } } } impl<'a> core::fmt::Display for CardType<'a> { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { write!(f, "{}", self.as_str()) } } impl<'a> AsRef for CardType<'a> { fn as_ref(&self) -> &str { self.as_str() } } impl<'a> serde::Serialize for CardType<'a> { fn serialize(&self, serializer: S) -> Result where S: serde::Serializer, { serializer.serialize_str(self.as_str()) } } impl<'de, 'a> serde::Deserialize<'de> for CardType<'a> where 'de: 'a, { fn deserialize(deserializer: D) -> Result where D: serde::Deserializer<'de>, { let s = <&'de str>::deserialize(deserializer)?; Ok(Self::from(s)) } } impl<'a> Default for CardType<'a> { fn default() -> Self { Self::Other(Default::default()) } } impl jacquard_common::IntoStatic for CardType<'_> { type Output = CardType<'static>; fn into_static(self) -> Self::Output { match self { CardType::Url => CardType::Url, CardType::Note => CardType::Note, CardType::Other(v) => CardType::Other(v.into_static()), } } } /// Typed wrapper for GetRecord response with this collection's record type. #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)] #[serde(rename_all = "camelCase")] pub struct CardGetRecordOutput<'a> { #[serde(skip_serializing_if = "Option::is_none")] #[serde(borrow)] pub cid: Option>, #[serde(borrow)] pub uri: AtUri<'a>, #[serde(borrow)] pub value: Card<'a>, } /// Content structure for a note card. #[lexicon] #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)] #[serde(rename_all = "camelCase")] pub struct NoteContent<'a> { ///The note text content #[serde(borrow)] pub text: CowStr<'a>, } /// Content structure for a URL card. #[lexicon] #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)] #[serde(rename_all = "camelCase")] pub struct UrlContent<'a> { ///Optional metadata about the URL #[serde(skip_serializing_if = "Option::is_none")] #[serde(borrow)] pub metadata: Option>, ///The URL being saved #[serde(borrow)] pub url: UriValue<'a>, } /// Metadata about a URL. #[lexicon] #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)] #[serde(rename_all = "camelCase")] pub struct UrlMetadata<'a> { ///Author of the content #[serde(skip_serializing_if = "Option::is_none")] #[serde(borrow)] pub author: Option>, ///Description of the page #[serde(skip_serializing_if = "Option::is_none")] #[serde(borrow)] pub description: Option>, ///Digital Object Identifier (DOI) for academic content #[serde(skip_serializing_if = "Option::is_none")] #[serde(borrow)] pub doi: Option>, ///URL of a representative image #[serde(skip_serializing_if = "Option::is_none")] #[serde(borrow)] pub image_url: Option>, ///International Standard Book Number (ISBN) for books #[serde(skip_serializing_if = "Option::is_none")] #[serde(borrow)] pub isbn: Option>, ///When the content was published #[serde(skip_serializing_if = "Option::is_none")] pub published_date: Option, ///When the metadata was retrieved #[serde(skip_serializing_if = "Option::is_none")] pub retrieved_at: Option, ///Name of the site #[serde(skip_serializing_if = "Option::is_none")] #[serde(borrow)] pub site_name: Option>, ///Title of the page #[serde(skip_serializing_if = "Option::is_none")] #[serde(borrow)] pub title: Option>, ///Type of content (e.g., 'video', 'article') #[serde(skip_serializing_if = "Option::is_none")] #[serde(borrow)] pub r#type: Option>, } impl<'a> Card<'a> { pub fn uri( uri: impl Into>, ) -> Result, UriError> { RecordUri::try_from_uri(AtUri::new_cow(uri.into())?) } } /// Marker type for deserializing records from this collection. #[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<'de> = CardGetRecordOutput<'de>; type Err<'de> = RecordError<'de>; } impl From> for Card<'_> { fn from(output: CardGetRecordOutput<'_>) -> Self { use jacquard_common::IntoStatic; output.value.into_static() } } impl Collection for Card<'_> { 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<'a> LexiconSchema for Card<'a> { 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<'a> LexiconSchema for NoteContent<'a> { 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 ::len(value.as_ref()) > 10000usize { return Err(ConstraintError::MaxLength { path: ValidationPath::from_field("text"), max: 10000usize, actual: ::len(value.as_ref()), }); } } Ok(()) } } impl<'a> LexiconSchema for UrlContent<'a> { 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<'a> LexiconSchema for UrlMetadata<'a> { 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 {} } /// State trait tracking which required fields have been set pub trait State: sealed::Sealed { type Content; type Type; } /// Empty state - all required fields are unset pub struct Empty(()); impl sealed::Sealed for Empty {} impl State for Empty { type Content = Unset; type Type = Unset; } ///State transition - sets the `content` field to Set pub struct SetContent(PhantomData S>); impl sealed::Sealed for SetContent {} impl State for SetContent { type Content = Set; type Type = S::Type; } ///State transition - sets the `type` field to Set pub struct SetType(PhantomData S>); impl sealed::Sealed for SetType {} impl State for SetType { type Content = S::Content; type Type = Set; } /// Marker types for field names #[allow(non_camel_case_types)] pub mod members { ///Marker type for the `content` field pub struct content(()); ///Marker type for the `type` field pub struct r#type(()); } } /// Builder for constructing an instance of this type pub struct CardBuilder<'a, S: card_state::State> { _state: PhantomData S>, _fields: ( Option>, Option, Option>, Option>, Option>, Option>, Option>, ), _lifetime: PhantomData<&'a ()>, } impl<'a> Card<'a> { /// Create a new builder for this type pub fn new() -> CardBuilder<'a, card_state::Empty> { CardBuilder::new() } } impl<'a> CardBuilder<'a, card_state::Empty> { /// Create a new builder with all fields unset pub fn new() -> Self { CardBuilder { _state: PhantomData, _fields: (None, None, None, None, None, None, None), _lifetime: PhantomData, } } } impl<'a, S> CardBuilder<'a, S> where S: card_state::State, S::Content: card_state::IsUnset, { /// Set the `content` field (required) pub fn content( mut self, value: impl Into>, ) -> CardBuilder<'a, card_state::SetContent> { self._fields.0 = Option::Some(value.into()); CardBuilder { _state: PhantomData, _fields: self._fields, _lifetime: PhantomData, } } } impl<'a, S: card_state::State> CardBuilder<'a, S> { /// Set the `createdAt` field (optional) pub fn created_at(mut self, value: impl Into>) -> Self { self._fields.1 = value.into(); self } /// Set the `createdAt` field to an Option value (optional) pub fn maybe_created_at(mut self, value: Option) -> Self { self._fields.1 = value; self } } impl<'a, S: card_state::State> CardBuilder<'a, S> { /// Set the `originalCard` field (optional) pub fn original_card(mut self, value: impl Into>>) -> Self { self._fields.2 = value.into(); self } /// Set the `originalCard` field to an Option value (optional) pub fn maybe_original_card(mut self, value: Option>) -> Self { self._fields.2 = value; self } } impl<'a, S: card_state::State> CardBuilder<'a, S> { /// Set the `parentCard` field (optional) pub fn parent_card(mut self, value: impl Into>>) -> Self { self._fields.3 = value.into(); self } /// Set the `parentCard` field to an Option value (optional) pub fn maybe_parent_card(mut self, value: Option>) -> Self { self._fields.3 = value; self } } impl<'a, S: card_state::State> CardBuilder<'a, S> { /// Set the `provenance` field (optional) pub fn provenance(mut self, value: impl Into>>) -> Self { self._fields.4 = value.into(); self } /// Set the `provenance` field to an Option value (optional) pub fn maybe_provenance(mut self, value: Option>) -> Self { self._fields.4 = value; self } } impl<'a, S> CardBuilder<'a, S> where S: card_state::State, S::Type: card_state::IsUnset, { /// Set the `type` field (required) pub fn r#type( mut self, value: impl Into>, ) -> CardBuilder<'a, card_state::SetType> { self._fields.5 = Option::Some(value.into()); CardBuilder { _state: PhantomData, _fields: self._fields, _lifetime: PhantomData, } } } impl<'a, S: card_state::State> CardBuilder<'a, S> { /// Set the `url` field (optional) pub fn url(mut self, value: impl Into>>) -> Self { self._fields.6 = value.into(); self } /// Set the `url` field to an Option value (optional) pub fn maybe_url(mut self, value: Option>) -> Self { self._fields.6 = value; self } } impl<'a, S> CardBuilder<'a, S> where S: card_state::State, S::Content: card_state::IsSet, S::Type: card_state::IsSet, { /// Build the final struct pub fn build(self) -> Card<'a> { 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(), } } /// Build the final struct with custom extra_data pub fn build_with_data( self, extra_data: BTreeMap< jacquard_common::deps::smol_str::SmolStr, jacquard_common::types::value::Data<'a>, >, ) -> Card<'a> { 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 {} } /// State trait tracking which required fields have been set pub trait State: sealed::Sealed { type Url; } /// Empty state - all required fields are unset pub struct Empty(()); impl sealed::Sealed for Empty {} impl State for Empty { type Url = Unset; } ///State transition - sets the `url` field to Set pub struct SetUrl(PhantomData S>); impl sealed::Sealed for SetUrl {} impl State for SetUrl { type Url = Set; } /// Marker types for field names #[allow(non_camel_case_types)] pub mod members { ///Marker type for the `url` field pub struct url(()); } } /// Builder for constructing an instance of this type pub struct UrlContentBuilder<'a, S: url_content_state::State> { _state: PhantomData S>, _fields: (Option>, Option>), _lifetime: PhantomData<&'a ()>, } impl<'a> UrlContent<'a> { /// Create a new builder for this type pub fn new() -> UrlContentBuilder<'a, url_content_state::Empty> { UrlContentBuilder::new() } } impl<'a> UrlContentBuilder<'a, url_content_state::Empty> { /// Create a new builder with all fields unset pub fn new() -> Self { UrlContentBuilder { _state: PhantomData, _fields: (None, None), _lifetime: PhantomData, } } } impl<'a, S: url_content_state::State> UrlContentBuilder<'a, S> { /// Set the `metadata` field (optional) pub fn metadata(mut self, value: impl Into>>) -> Self { self._fields.0 = value.into(); self } /// Set the `metadata` field to an Option value (optional) pub fn maybe_metadata(mut self, value: Option>) -> Self { self._fields.0 = value; self } } impl<'a, S> UrlContentBuilder<'a, S> where S: url_content_state::State, S::Url: url_content_state::IsUnset, { /// Set the `url` field (required) pub fn url( mut self, value: impl Into>, ) -> UrlContentBuilder<'a, url_content_state::SetUrl> { self._fields.1 = Option::Some(value.into()); UrlContentBuilder { _state: PhantomData, _fields: self._fields, _lifetime: PhantomData, } } } impl<'a, S> UrlContentBuilder<'a, S> where S: url_content_state::State, S::Url: url_content_state::IsSet, { /// Build the final struct pub fn build(self) -> UrlContent<'a> { UrlContent { metadata: self._fields.0, url: self._fields.1.unwrap(), extra_data: Default::default(), } } /// Build the final struct with custom extra_data pub fn build_with_data( self, extra_data: BTreeMap< jacquard_common::deps::smol_str::SmolStr, jacquard_common::types::value::Data<'a>, >, ) -> UrlContent<'a> { UrlContent { metadata: self._fields.0, url: self._fields.1.unwrap(), extra_data: Some(extra_data), } } }