#[allow(unused_imports)]
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::{BosStr, CowStr, 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::string::UriValue;
use jacquard_common::types::value::Data;
use jacquard_derive::IntoStatic;
use jacquard_lexicon::lexicon::LexiconDoc;
use jacquard_lexicon::schema::LexiconSchema;
use crate::app_bsky::embed::external;
#[allow(unused_imports)]
use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
rename_all = "camelCase",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct External<S: BosStr = DefaultStr> {
pub description: S,
#[serde(skip_serializing_if = "Option::is_none")]
pub thumb: Option<BlobRef<S>>,
pub title: S,
pub uri: 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)]
#[serde(
rename_all = "camelCase",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct ExternalRecord<S: BosStr = DefaultStr> {
pub external: external::External<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 View<S: BosStr = DefaultStr> {
pub external: external::ViewExternal<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 ViewExternal<S: BosStr = DefaultStr> {
pub description: S,
#[serde(skip_serializing_if = "Option::is_none")]
pub thumb: Option<UriValue<S>>,
pub title: S,
pub uri: UriValue<S>,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
impl<S: BosStr> LexiconSchema for External<S> {
fn nsid() -> &'static str {
"app.bsky.embed.external"
}
fn def_name() -> &'static str {
"external"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_app_bsky_embed_external()
}
fn validate(&self) -> Result<(), ConstraintError> {
if let Some(ref value) = self.thumb {
{
let size = value.blob().size;
if size > 1000000usize {
return Err(ConstraintError::BlobTooLarge {
path: ValidationPath::from_field("thumb"),
max: 1000000usize,
actual: size,
});
}
}
}
if let Some(ref value) = self.thumb {
{
let mime = value.blob().mime_type.as_str();
let accepted: &[&str] = &["image/*"];
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("thumb"),
accepted: vec!["image/*".to_string()],
actual: mime.to_string(),
});
}
}
}
Ok(())
}
}
impl<S: BosStr> LexiconSchema for ExternalRecord<S> {
fn nsid() -> &'static str {
"app.bsky.embed.external"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_app_bsky_embed_external()
}
fn validate(&self) -> Result<(), ConstraintError> {
Ok(())
}
}
impl<S: BosStr> LexiconSchema for View<S> {
fn nsid() -> &'static str {
"app.bsky.embed.external"
}
fn def_name() -> &'static str {
"view"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_app_bsky_embed_external()
}
fn validate(&self) -> Result<(), ConstraintError> {
Ok(())
}
}
impl<S: BosStr> LexiconSchema for ViewExternal<S> {
fn nsid() -> &'static str {
"app.bsky.embed.external"
}
fn def_name() -> &'static str {
"viewExternal"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_app_bsky_embed_external()
}
fn validate(&self) -> Result<(), ConstraintError> {
Ok(())
}
}
pub mod external_state {
pub use crate::builder_types::{IsSet, IsUnset, Set, Unset};
#[allow(unused)]
use ::core::marker::PhantomData;
mod sealed {
pub trait Sealed {}
}
pub trait State: sealed::Sealed {
type Title;
type Description;
type Uri;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Title = Unset;
type Description = Unset;
type Uri = Unset;
}
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 Title = Set<members::title>;
type Description = St::Description;
type Uri = St::Uri;
}
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 Title = St::Title;
type Description = Set<members::description>;
type Uri = St::Uri;
}
pub struct SetUri<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetUri<St> {}
impl<St: State> State for SetUri<St> {
type Title = St::Title;
type Description = St::Description;
type Uri = Set<members::uri>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct title(());
pub struct description(());
pub struct uri(());
}
}
pub struct ExternalBuilder<S: BosStr, St: external_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<S>,
Option<BlobRef<S>>,
Option<S>,
Option<UriValue<S>>,
),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> External<S> {
pub fn new() -> ExternalBuilder<S, external_state::Empty> {
ExternalBuilder::new()
}
}
impl<S: BosStr> ExternalBuilder<S, external_state::Empty> {
pub fn new() -> Self {
ExternalBuilder {
_state: PhantomData,
_fields: (None, None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St> ExternalBuilder<S, St>
where
St: external_state::State,
St::Description: external_state::IsUnset,
{
pub fn description(
mut self,
value: impl Into<S>,
) -> ExternalBuilder<S, external_state::SetDescription<St>> {
self._fields.0 = Option::Some(value.into());
ExternalBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: external_state::State> ExternalBuilder<S, St> {
pub fn thumb(mut self, value: impl Into<Option<BlobRef<S>>>) -> Self {
self._fields.1 = value.into();
self
}
pub fn maybe_thumb(mut self, value: Option<BlobRef<S>>) -> Self {
self._fields.1 = value;
self
}
}
impl<S: BosStr, St> ExternalBuilder<S, St>
where
St: external_state::State,
St::Title: external_state::IsUnset,
{
pub fn title(
mut self,
value: impl Into<S>,
) -> ExternalBuilder<S, external_state::SetTitle<St>> {
self._fields.2 = Option::Some(value.into());
ExternalBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> ExternalBuilder<S, St>
where
St: external_state::State,
St::Uri: external_state::IsUnset,
{
pub fn uri(
mut self,
value: impl Into<UriValue<S>>,
) -> ExternalBuilder<S, external_state::SetUri<St>> {
self._fields.3 = Option::Some(value.into());
ExternalBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> ExternalBuilder<S, St>
where
St: external_state::State,
St::Title: external_state::IsSet,
St::Description: external_state::IsSet,
St::Uri: external_state::IsSet,
{
pub fn build(self) -> External<S> {
External {
description: self._fields.0.unwrap(),
thumb: self._fields.1,
title: self._fields.2.unwrap(),
uri: self._fields.3.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> External<S> {
External {
description: self._fields.0.unwrap(),
thumb: self._fields.1,
title: self._fields.2.unwrap(),
uri: self._fields.3.unwrap(),
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_app_bsky_embed_external() -> LexiconDoc<'static> {
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
use jacquard_lexicon::lexicon::*;
LexiconDoc {
lexicon: Lexicon::Lexicon1,
id: CowStr::new_static("app.bsky.embed.external"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("external"),
LexUserType::Object(LexObject {
required: Some(vec![
SmolStr::new_static("uri"),
SmolStr::new_static("title"),
SmolStr::new_static("description"),
]),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("description"),
LexObjectProperty::String(LexString {
..Default::default()
}),
);
map.insert(
SmolStr::new_static("thumb"),
LexObjectProperty::Blob(LexBlob {
..Default::default()
}),
);
map.insert(
SmolStr::new_static("title"),
LexObjectProperty::String(LexString {
..Default::default()
}),
);
map.insert(
SmolStr::new_static("uri"),
LexObjectProperty::String(LexString {
format: Some(LexStringFormat::Uri),
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map.insert(
SmolStr::new_static("main"),
LexUserType::Object(LexObject {
description: Some(
CowStr::new_static(
"A representation of some externally linked content (eg, a URL and 'card'), embedded in a Bluesky record (eg, a post).",
),
),
required: Some(vec![SmolStr::new_static("external")]),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("external"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static("#external"),
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map.insert(
SmolStr::new_static("view"),
LexUserType::Object(LexObject {
required: Some(vec![SmolStr::new_static("external")]),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("external"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static("#viewExternal"),
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map.insert(
SmolStr::new_static("viewExternal"),
LexUserType::Object(LexObject {
required: Some(vec![
SmolStr::new_static("uri"),
SmolStr::new_static("title"),
SmolStr::new_static("description"),
]),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("description"),
LexObjectProperty::String(LexString {
..Default::default()
}),
);
map.insert(
SmolStr::new_static("thumb"),
LexObjectProperty::String(LexString {
format: Some(LexStringFormat::Uri),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("title"),
LexObjectProperty::String(LexString {
..Default::default()
}),
);
map.insert(
SmolStr::new_static("uri"),
LexObjectProperty::String(LexString {
format: Some(LexStringFormat::Uri),
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map
},
..Default::default()
}
}
pub mod external_record_state {
pub use crate::builder_types::{IsSet, IsUnset, Set, Unset};
#[allow(unused)]
use ::core::marker::PhantomData;
mod sealed {
pub trait Sealed {}
}
pub trait State: sealed::Sealed {
type External;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type External = Unset;
}
pub struct SetExternal<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetExternal<St> {}
impl<St: State> State for SetExternal<St> {
type External = Set<members::external>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct external(());
}
}
pub struct ExternalRecordBuilder<S: BosStr, St: external_record_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (Option<external::External<S>>,),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> ExternalRecord<S> {
pub fn new() -> ExternalRecordBuilder<S, external_record_state::Empty> {
ExternalRecordBuilder::new()
}
}
impl<S: BosStr> ExternalRecordBuilder<S, external_record_state::Empty> {
pub fn new() -> Self {
ExternalRecordBuilder {
_state: PhantomData,
_fields: (None,),
_type: PhantomData,
}
}
}
impl<S: BosStr, St> ExternalRecordBuilder<S, St>
where
St: external_record_state::State,
St::External: external_record_state::IsUnset,
{
pub fn external(
mut self,
value: impl Into<external::External<S>>,
) -> ExternalRecordBuilder<S, external_record_state::SetExternal<St>> {
self._fields.0 = Option::Some(value.into());
ExternalRecordBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> ExternalRecordBuilder<S, St>
where
St: external_record_state::State,
St::External: external_record_state::IsSet,
{
pub fn build(self) -> ExternalRecord<S> {
ExternalRecord {
external: self._fields.0.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> ExternalRecord<S> {
ExternalRecord {
external: self._fields.0.unwrap(),
extra_data: Some(extra_data),
}
}
}
pub mod view_state {
pub use crate::builder_types::{IsSet, IsUnset, Set, Unset};
#[allow(unused)]
use ::core::marker::PhantomData;
mod sealed {
pub trait Sealed {}
}
pub trait State: sealed::Sealed {
type External;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type External = Unset;
}
pub struct SetExternal<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetExternal<St> {}
impl<St: State> State for SetExternal<St> {
type External = Set<members::external>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct external(());
}
}
pub struct ViewBuilder<S: BosStr, St: view_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (Option<external::ViewExternal<S>>,),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> View<S> {
pub fn new() -> ViewBuilder<S, view_state::Empty> {
ViewBuilder::new()
}
}
impl<S: BosStr> ViewBuilder<S, view_state::Empty> {
pub fn new() -> Self {
ViewBuilder {
_state: PhantomData,
_fields: (None,),
_type: PhantomData,
}
}
}
impl<S: BosStr, St> ViewBuilder<S, St>
where
St: view_state::State,
St::External: view_state::IsUnset,
{
pub fn external(
mut self,
value: impl Into<external::ViewExternal<S>>,
) -> ViewBuilder<S, view_state::SetExternal<St>> {
self._fields.0 = Option::Some(value.into());
ViewBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> ViewBuilder<S, St>
where
St: view_state::State,
St::External: view_state::IsSet,
{
pub fn build(self) -> View<S> {
View {
external: self._fields.0.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> View<S> {
View {
external: self._fields.0.unwrap(),
extra_data: Some(extra_data),
}
}
}
pub mod view_external_state {
pub use crate::builder_types::{IsSet, IsUnset, Set, Unset};
#[allow(unused)]
use ::core::marker::PhantomData;
mod sealed {
pub trait Sealed {}
}
pub trait State: sealed::Sealed {
type Uri;
type Title;
type Description;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Uri = Unset;
type Title = Unset;
type Description = Unset;
}
pub struct SetUri<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetUri<St> {}
impl<St: State> State for SetUri<St> {
type Uri = Set<members::uri>;
type Title = St::Title;
type Description = St::Description;
}
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 Uri = St::Uri;
type Title = Set<members::title>;
type Description = St::Description;
}
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 Uri = St::Uri;
type Title = St::Title;
type Description = Set<members::description>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct uri(());
pub struct title(());
pub struct description(());
}
}
pub struct ViewExternalBuilder<S: BosStr, St: view_external_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<S>,
Option<UriValue<S>>,
Option<S>,
Option<UriValue<S>>,
),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> ViewExternal<S> {
pub fn new() -> ViewExternalBuilder<S, view_external_state::Empty> {
ViewExternalBuilder::new()
}
}
impl<S: BosStr> ViewExternalBuilder<S, view_external_state::Empty> {
pub fn new() -> Self {
ViewExternalBuilder {
_state: PhantomData,
_fields: (None, None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St> ViewExternalBuilder<S, St>
where
St: view_external_state::State,
St::Description: view_external_state::IsUnset,
{
pub fn description(
mut self,
value: impl Into<S>,
) -> ViewExternalBuilder<S, view_external_state::SetDescription<St>> {
self._fields.0 = Option::Some(value.into());
ViewExternalBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: view_external_state::State> ViewExternalBuilder<S, St> {
pub fn thumb(mut self, value: impl Into<Option<UriValue<S>>>) -> Self {
self._fields.1 = value.into();
self
}
pub fn maybe_thumb(mut self, value: Option<UriValue<S>>) -> Self {
self._fields.1 = value;
self
}
}
impl<S: BosStr, St> ViewExternalBuilder<S, St>
where
St: view_external_state::State,
St::Title: view_external_state::IsUnset,
{
pub fn title(
mut self,
value: impl Into<S>,
) -> ViewExternalBuilder<S, view_external_state::SetTitle<St>> {
self._fields.2 = Option::Some(value.into());
ViewExternalBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> ViewExternalBuilder<S, St>
where
St: view_external_state::State,
St::Uri: view_external_state::IsUnset,
{
pub fn uri(
mut self,
value: impl Into<UriValue<S>>,
) -> ViewExternalBuilder<S, view_external_state::SetUri<St>> {
self._fields.3 = Option::Some(value.into());
ViewExternalBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> ViewExternalBuilder<S, St>
where
St: view_external_state::State,
St::Uri: view_external_state::IsSet,
St::Title: view_external_state::IsSet,
St::Description: view_external_state::IsSet,
{
pub fn build(self) -> ViewExternal<S> {
ViewExternal {
description: self._fields.0.unwrap(),
thumb: self._fields.1,
title: self._fields.2.unwrap(),
uri: self._fields.3.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> ViewExternal<S> {
ViewExternal {
description: self._fields.0.unwrap(),
thumb: self._fields.1,
title: self._fields.2.unwrap(),
uri: self._fields.3.unwrap(),
extra_data: Some(extra_data),
}
}
}