#[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, Language, 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::org_atpodcasting::AppleCategory;
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
rename_all = "camelCase",
rename = "org.atpodcasting.podcast",
tag = "$type",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Podcast<S: BosStr = DefaultStr> {
pub artwork: BlobRef<S>,
pub categories: Vec<AppleCategory<S>>,
pub created_at: Datetime,
pub description: S,
#[serde(skip_serializing_if = "Option::is_none")]
pub explicit: Option<bool>,
pub feed_url: UriValue<S>,
pub guid: S,
pub language: Language,
#[serde(skip_serializing_if = "Option::is_none")]
pub link: Option<UriValue<S>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub moved_to: Option<AtUri<S>>,
pub title: 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 PodcastGetRecordOutput<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub cid: Option<Cid<S>>,
pub uri: AtUri<S>,
pub value: Podcast<S>,
}
impl<S: BosStr> Podcast<S> {
pub fn uri(uri: S) -> Result<RecordUri<S, PodcastRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new(uri)?)
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct PodcastRecord;
impl XrpcResp for PodcastRecord {
const NSID: &'static str = "org.atpodcasting.podcast";
const ENCODING: &'static str = "application/json";
type Output<S: BosStr> = PodcastGetRecordOutput<S>;
type Err = RecordError;
}
impl<S: BosStr> From<PodcastGetRecordOutput<S>> for Podcast<S> {
fn from(output: PodcastGetRecordOutput<S>) -> Self {
output.value
}
}
impl<S: BosStr> Collection for Podcast<S> {
const NSID: &'static str = "org.atpodcasting.podcast";
type Record = PodcastRecord;
}
impl Collection for PodcastRecord {
const NSID: &'static str = "org.atpodcasting.podcast";
type Record = PodcastRecord;
}
impl<S: BosStr> LexiconSchema for Podcast<S> {
fn nsid() -> &'static str {
"org.atpodcasting.podcast"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_org_atpodcasting_podcast()
}
fn validate(&self) -> Result<(), ConstraintError> {
{
let value = &self.artwork;
{
let size = value.blob().size;
if size > 5000000usize {
return Err(ConstraintError::BlobTooLarge {
path: ValidationPath::from_field("artwork"),
max: 5000000usize,
actual: size,
});
}
}
}
{
let value = &self.artwork;
{
let mime = value.blob().mime_type.as_str();
let accepted: &[&str] = &["image/png", "image/jpeg"];
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("artwork"),
accepted: vec![
"image/png".to_string(), "image/jpeg".to_string()
],
actual: mime.to_string(),
});
}
}
}
{
let value = &self.categories;
#[allow(unused_comparisons)]
if value.len() > 3usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("categories"),
max: 3usize,
actual: value.len(),
});
}
}
{
let value = &self.description;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 4000usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("description"),
max: 4000usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.guid;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 36usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("guid"),
max: 36usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.title;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 500usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("title"),
max: 500usize,
actual: <str>::len(value.as_ref()),
});
}
}
Ok(())
}
}
pub mod podcast_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 Guid;
type Artwork;
type Title;
type FeedUrl;
type Description;
type Language;
type Categories;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type CreatedAt = Unset;
type Guid = Unset;
type Artwork = Unset;
type Title = Unset;
type FeedUrl = Unset;
type Description = Unset;
type Language = Unset;
type Categories = 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 Guid = St::Guid;
type Artwork = St::Artwork;
type Title = St::Title;
type FeedUrl = St::FeedUrl;
type Description = St::Description;
type Language = St::Language;
type Categories = St::Categories;
}
pub struct SetGuid<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetGuid<St> {}
impl<St: State> State for SetGuid<St> {
type CreatedAt = St::CreatedAt;
type Guid = Set<members::guid>;
type Artwork = St::Artwork;
type Title = St::Title;
type FeedUrl = St::FeedUrl;
type Description = St::Description;
type Language = St::Language;
type Categories = St::Categories;
}
pub struct SetArtwork<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetArtwork<St> {}
impl<St: State> State for SetArtwork<St> {
type CreatedAt = St::CreatedAt;
type Guid = St::Guid;
type Artwork = Set<members::artwork>;
type Title = St::Title;
type FeedUrl = St::FeedUrl;
type Description = St::Description;
type Language = St::Language;
type Categories = St::Categories;
}
pub struct SetTitle<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetTitle<St> {}
impl<St: State> State for SetTitle<St> {
type CreatedAt = St::CreatedAt;
type Guid = St::Guid;
type Artwork = St::Artwork;
type Title = Set<members::title>;
type FeedUrl = St::FeedUrl;
type Description = St::Description;
type Language = St::Language;
type Categories = St::Categories;
}
pub struct SetFeedUrl<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetFeedUrl<St> {}
impl<St: State> State for SetFeedUrl<St> {
type CreatedAt = St::CreatedAt;
type Guid = St::Guid;
type Artwork = St::Artwork;
type Title = St::Title;
type FeedUrl = Set<members::feed_url>;
type Description = St::Description;
type Language = St::Language;
type Categories = St::Categories;
}
pub struct SetDescription<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetDescription<St> {}
impl<St: State> State for SetDescription<St> {
type CreatedAt = St::CreatedAt;
type Guid = St::Guid;
type Artwork = St::Artwork;
type Title = St::Title;
type FeedUrl = St::FeedUrl;
type Description = Set<members::description>;
type Language = St::Language;
type Categories = St::Categories;
}
pub struct SetLanguage<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetLanguage<St> {}
impl<St: State> State for SetLanguage<St> {
type CreatedAt = St::CreatedAt;
type Guid = St::Guid;
type Artwork = St::Artwork;
type Title = St::Title;
type FeedUrl = St::FeedUrl;
type Description = St::Description;
type Language = Set<members::language>;
type Categories = St::Categories;
}
pub struct SetCategories<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetCategories<St> {}
impl<St: State> State for SetCategories<St> {
type CreatedAt = St::CreatedAt;
type Guid = St::Guid;
type Artwork = St::Artwork;
type Title = St::Title;
type FeedUrl = St::FeedUrl;
type Description = St::Description;
type Language = St::Language;
type Categories = Set<members::categories>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct created_at(());
pub struct guid(());
pub struct artwork(());
pub struct title(());
pub struct feed_url(());
pub struct description(());
pub struct language(());
pub struct categories(());
}
}
pub struct PodcastBuilder<S: BosStr, St: podcast_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<BlobRef<S>>,
Option<Vec<AppleCategory<S>>>,
Option<Datetime>,
Option<S>,
Option<bool>,
Option<UriValue<S>>,
Option<S>,
Option<Language>,
Option<UriValue<S>>,
Option<AtUri<S>>,
Option<S>,
),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> Podcast<S> {
pub fn new() -> PodcastBuilder<S, podcast_state::Empty> {
PodcastBuilder::new()
}
}
impl<S: BosStr> PodcastBuilder<S, podcast_state::Empty> {
pub fn new() -> Self {
PodcastBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None, None, None, None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St> PodcastBuilder<S, St>
where
St: podcast_state::State,
St::Artwork: podcast_state::IsUnset,
{
pub fn artwork(
mut self,
value: impl Into<BlobRef<S>>,
) -> PodcastBuilder<S, podcast_state::SetArtwork<St>> {
self._fields.0 = Option::Some(value.into());
PodcastBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> PodcastBuilder<S, St>
where
St: podcast_state::State,
St::Categories: podcast_state::IsUnset,
{
pub fn categories(
mut self,
value: impl Into<Vec<AppleCategory<S>>>,
) -> PodcastBuilder<S, podcast_state::SetCategories<St>> {
self._fields.1 = Option::Some(value.into());
PodcastBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> PodcastBuilder<S, St>
where
St: podcast_state::State,
St::CreatedAt: podcast_state::IsUnset,
{
pub fn created_at(
mut self,
value: impl Into<Datetime>,
) -> PodcastBuilder<S, podcast_state::SetCreatedAt<St>> {
self._fields.2 = Option::Some(value.into());
PodcastBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> PodcastBuilder<S, St>
where
St: podcast_state::State,
St::Description: podcast_state::IsUnset,
{
pub fn description(
mut self,
value: impl Into<S>,
) -> PodcastBuilder<S, podcast_state::SetDescription<St>> {
self._fields.3 = Option::Some(value.into());
PodcastBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: podcast_state::State> PodcastBuilder<S, St> {
pub fn explicit(mut self, value: impl Into<Option<bool>>) -> Self {
self._fields.4 = value.into();
self
}
pub fn maybe_explicit(mut self, value: Option<bool>) -> Self {
self._fields.4 = value;
self
}
}
impl<S: BosStr, St> PodcastBuilder<S, St>
where
St: podcast_state::State,
St::FeedUrl: podcast_state::IsUnset,
{
pub fn feed_url(
mut self,
value: impl Into<UriValue<S>>,
) -> PodcastBuilder<S, podcast_state::SetFeedUrl<St>> {
self._fields.5 = Option::Some(value.into());
PodcastBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> PodcastBuilder<S, St>
where
St: podcast_state::State,
St::Guid: podcast_state::IsUnset,
{
pub fn guid(
mut self,
value: impl Into<S>,
) -> PodcastBuilder<S, podcast_state::SetGuid<St>> {
self._fields.6 = Option::Some(value.into());
PodcastBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> PodcastBuilder<S, St>
where
St: podcast_state::State,
St::Language: podcast_state::IsUnset,
{
pub fn language(
mut self,
value: impl Into<Language>,
) -> PodcastBuilder<S, podcast_state::SetLanguage<St>> {
self._fields.7 = Option::Some(value.into());
PodcastBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: podcast_state::State> PodcastBuilder<S, St> {
pub fn link(mut self, value: impl Into<Option<UriValue<S>>>) -> Self {
self._fields.8 = value.into();
self
}
pub fn maybe_link(mut self, value: Option<UriValue<S>>) -> Self {
self._fields.8 = value;
self
}
}
impl<S: BosStr, St: podcast_state::State> PodcastBuilder<S, St> {
pub fn moved_to(mut self, value: impl Into<Option<AtUri<S>>>) -> Self {
self._fields.9 = value.into();
self
}
pub fn maybe_moved_to(mut self, value: Option<AtUri<S>>) -> Self {
self._fields.9 = value;
self
}
}
impl<S: BosStr, St> PodcastBuilder<S, St>
where
St: podcast_state::State,
St::Title: podcast_state::IsUnset,
{
pub fn title(
mut self,
value: impl Into<S>,
) -> PodcastBuilder<S, podcast_state::SetTitle<St>> {
self._fields.10 = Option::Some(value.into());
PodcastBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> PodcastBuilder<S, St>
where
St: podcast_state::State,
St::CreatedAt: podcast_state::IsSet,
St::Guid: podcast_state::IsSet,
St::Artwork: podcast_state::IsSet,
St::Title: podcast_state::IsSet,
St::FeedUrl: podcast_state::IsSet,
St::Description: podcast_state::IsSet,
St::Language: podcast_state::IsSet,
St::Categories: podcast_state::IsSet,
{
pub fn build(self) -> Podcast<S> {
Podcast {
artwork: self._fields.0.unwrap(),
categories: self._fields.1.unwrap(),
created_at: self._fields.2.unwrap(),
description: self._fields.3.unwrap(),
explicit: self._fields.4,
feed_url: self._fields.5.unwrap(),
guid: self._fields.6.unwrap(),
language: self._fields.7.unwrap(),
link: self._fields.8,
moved_to: self._fields.9,
title: self._fields.10.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Podcast<S> {
Podcast {
artwork: self._fields.0.unwrap(),
categories: self._fields.1.unwrap(),
created_at: self._fields.2.unwrap(),
description: self._fields.3.unwrap(),
explicit: self._fields.4,
feed_url: self._fields.5.unwrap(),
guid: self._fields.6.unwrap(),
language: self._fields.7.unwrap(),
link: self._fields.8,
moved_to: self._fields.9,
title: self._fields.10.unwrap(),
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_org_atpodcasting_podcast() -> 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.atpodcasting.podcast"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("main"),
LexUserType::Record(LexRecord {
description: Some(
CowStr::new_static(
"A podcast feed/show. Record key is the podcast's Podcasting 2.0 UUIDv5 GUID, enabling direct lookup from RSS feed metadata.",
),
),
key: Some(CowStr::new_static("any")),
record: LexRecordRecord::Object(LexObject {
required: Some(
vec![
SmolStr::new_static("title"),
SmolStr::new_static("description"),
SmolStr::new_static("artwork"),
SmolStr::new_static("language"),
SmolStr::new_static("feedUrl"),
SmolStr::new_static("categories"),
SmolStr::new_static("guid"),
SmolStr::new_static("createdAt")
],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("artwork"),
LexObjectProperty::Blob(LexBlob { ..Default::default() }),
);
map.insert(
SmolStr::new_static("categories"),
LexObjectProperty::Array(LexArray {
description: Some(
CowStr::new_static("Podcast categories (max 3)."),
),
items: LexArrayItem::Union(LexRefUnion {
refs: vec![
CowStr::new_static("org.atpodcasting.defs#appleCategory")
],
..Default::default()
}),
max_length: Some(3usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("createdAt"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("When the podcast record was created."),
),
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("description"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("A description of the podcast."),
),
max_length: Some(4000usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("explicit"),
LexObjectProperty::Boolean(LexBoolean {
..Default::default()
}),
);
map.insert(
SmolStr::new_static("feedUrl"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("URL of the podcast's RSS feed."),
),
format: Some(LexStringFormat::Uri),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("guid"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Podcasting 2.0 UUIDv5 GUID of the podcast. Must match the record key.",
),
),
max_length: Some(36usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("language"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Primary language of the podcast (ISO 639-1 two-letter code, e.g. 'en', 'es', 'pt').",
),
),
format: Some(LexStringFormat::Language),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("link"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"URL of the podcast's homepage or companion website.",
),
),
format: Some(LexStringFormat::Uri),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("movedTo"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"AT URI of the new canonical podcast record after an ownership transfer. When set, consumers should follow this reference to the current record.",
),
),
format: Some(LexStringFormat::AtUri),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("title"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("The name of the podcast."),
),
max_length: Some(500usize),
..Default::default()
}),
);
map
},
..Default::default()
}),
..Default::default()
}),
);
map
},
..Default::default()
}
}