#[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::string::UriValue;
use jacquard_common::types::value::Data;
use jacquard_derive::IntoStatic;
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::sh_weaver::embed::external;
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct ExternalEmbed<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 External<S: BosStr = DefaultStr> {
pub embeds: Vec<external::ExternalEmbed<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: Vec<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 ExternalEmbed<S> {
fn nsid() -> &'static str {
"sh.weaver.embed.external"
}
fn def_name() -> &'static str {
"externalEmbed"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_sh_weaver_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 External<S> {
fn nsid() -> &'static str {
"sh.weaver.embed.external"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_sh_weaver_embed_external()
}
fn validate(&self) -> Result<(), ConstraintError> {
{
let value = &self.embeds;
#[allow(unused_comparisons)]
if value.len() > 48usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("embeds"),
max: 48usize,
actual: value.len(),
});
}
}
Ok(())
}
}
impl<S: BosStr> LexiconSchema for View<S> {
fn nsid() -> &'static str {
"sh.weaver.embed.external"
}
fn def_name() -> &'static str {
"view"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_sh_weaver_embed_external()
}
fn validate(&self) -> Result<(), ConstraintError> {
{
let value = &self.external;
#[allow(unused_comparisons)]
if value.len() > 48usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("external"),
max: 48usize,
actual: value.len(),
});
}
}
Ok(())
}
}
impl<S: BosStr> LexiconSchema for ViewExternal<S> {
fn nsid() -> &'static str {
"sh.weaver.embed.external"
}
fn def_name() -> &'static str {
"viewExternal"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_sh_weaver_embed_external()
}
fn validate(&self) -> Result<(), ConstraintError> {
Ok(())
}
}
pub mod external_embed_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 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 ExternalEmbedBuilder<S: BosStr, St: external_embed_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (Option<S>, Option<BlobRef<S>>, Option<S>, Option<UriValue<S>>),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> ExternalEmbed<S> {
pub fn new() -> ExternalEmbedBuilder<S, external_embed_state::Empty> {
ExternalEmbedBuilder::new()
}
}
impl<S: BosStr> ExternalEmbedBuilder<S, external_embed_state::Empty> {
pub fn new() -> Self {
ExternalEmbedBuilder {
_state: PhantomData,
_fields: (None, None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St> ExternalEmbedBuilder<S, St>
where
St: external_embed_state::State,
St::Description: external_embed_state::IsUnset,
{
pub fn description(
mut self,
value: impl Into<S>,
) -> ExternalEmbedBuilder<S, external_embed_state::SetDescription<St>> {
self._fields.0 = Option::Some(value.into());
ExternalEmbedBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: external_embed_state::State> ExternalEmbedBuilder<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> ExternalEmbedBuilder<S, St>
where
St: external_embed_state::State,
St::Title: external_embed_state::IsUnset,
{
pub fn title(
mut self,
value: impl Into<S>,
) -> ExternalEmbedBuilder<S, external_embed_state::SetTitle<St>> {
self._fields.2 = Option::Some(value.into());
ExternalEmbedBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> ExternalEmbedBuilder<S, St>
where
St: external_embed_state::State,
St::Uri: external_embed_state::IsUnset,
{
pub fn uri(
mut self,
value: impl Into<UriValue<S>>,
) -> ExternalEmbedBuilder<S, external_embed_state::SetUri<St>> {
self._fields.3 = Option::Some(value.into());
ExternalEmbedBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> ExternalEmbedBuilder<S, St>
where
St: external_embed_state::State,
St::Uri: external_embed_state::IsSet,
St::Title: external_embed_state::IsSet,
St::Description: external_embed_state::IsSet,
{
pub fn build(self) -> ExternalEmbed<S> {
ExternalEmbed {
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>>,
) -> ExternalEmbed<S> {
ExternalEmbed {
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_sh_weaver_embed_external() -> 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("sh.weaver.embed.external"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("externalEmbed"),
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 {
required: Some(vec![SmolStr::new_static("embeds")]),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("embeds"),
LexObjectProperty::Array(LexArray {
items: LexArrayItem::Ref(LexRef {
r#ref: CowStr::new_static("#externalEmbed"),
..Default::default()
}),
max_length: Some(48usize),
..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::Array(LexArray {
items: LexArrayItem::Ref(LexRef {
r#ref: CowStr::new_static("#viewExternal"),
..Default::default()
}),
max_length: Some(48usize),
..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_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 Embeds;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Embeds = Unset;
}
pub struct SetEmbeds<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetEmbeds<St> {}
impl<St: State> State for SetEmbeds<St> {
type Embeds = Set<members::embeds>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct embeds(());
}
}
pub struct ExternalBuilder<S: BosStr, St: external_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (Option<Vec<external::ExternalEmbed<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,),
_type: PhantomData,
}
}
}
impl<S: BosStr, St> ExternalBuilder<S, St>
where
St: external_state::State,
St::Embeds: external_state::IsUnset,
{
pub fn embeds(
mut self,
value: impl Into<Vec<external::ExternalEmbed<S>>>,
) -> ExternalBuilder<S, external_state::SetEmbeds<St>> {
self._fields.0 = 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::Embeds: external_state::IsSet,
{
pub fn build(self) -> External<S> {
External {
embeds: self._fields.0.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> External<S> {
External {
embeds: self._fields.0.unwrap(),
extra_data: Some(extra_data),
}
}
}
pub mod view_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 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<Vec<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<Vec<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::{Set, Unset, IsSet, IsUnset};
#[allow(unused)]
use ::core::marker::PhantomData;
mod sealed {
pub trait Sealed {}
}
pub trait State: sealed::Sealed {
type Uri;
type Description;
type Title;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Uri = Unset;
type Description = Unset;
type Title = 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 Description = St::Description;
type Title = St::Title;
}
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 Description = Set<members::description>;
type Title = St::Title;
}
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 Description = St::Description;
type Title = Set<members::title>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct uri(());
pub struct description(());
pub struct title(());
}
}
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::Description: view_external_state::IsSet,
St::Title: 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),
}
}
}