#[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::collection::{Collection, RecordError};
use jacquard_common::types::string::{AtUri, Cid, Datetime, Language};
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;
use crate::tools_smokesignal::blahg::content::post;
#[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 Attachment<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub alt: Option<S>,
pub content: BlobRef<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",
rename = "tools.smokesignal.blahg.content.post",
tag = "$type",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Post<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub attachments: Option<Vec<post::Attachment<S>>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub content: Option<BlobRef<S>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub langs: Option<Vec<Language>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub published_at: Option<Datetime>,
#[serde(skip_serializing_if = "Option::is_none")]
pub title: Option<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 PostGetRecordOutput<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub cid: Option<Cid<S>>,
pub uri: AtUri<S>,
pub value: Post<S>,
}
impl<S: BosStr> Post<S> {
pub fn uri(uri: S) -> Result<RecordUri<S, PostRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new(uri)?)
}
}
impl<S: BosStr> LexiconSchema for Attachment<S> {
fn nsid() -> &'static str {
"tools.smokesignal.blahg.content.post"
}
fn def_name() -> &'static str {
"attachment"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_tools_smokesignal_blahg_content_post()
}
fn validate(&self) -> Result<(), ConstraintError> {
{
let value = &self.content;
{
let size = value.blob().size;
if size > 3000000usize {
return Err(ConstraintError::BlobTooLarge {
path: ValidationPath::from_field("content"),
max: 3000000usize,
actual: size,
});
}
}
}
{
let value = &self.content;
{
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("content"),
accepted: vec!["image/*".to_string()],
actual: mime.to_string(),
});
}
}
}
Ok(())
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct PostRecord;
impl XrpcResp for PostRecord {
const NSID: &'static str = "tools.smokesignal.blahg.content.post";
const ENCODING: &'static str = "application/json";
type Output<S: BosStr> = PostGetRecordOutput<S>;
type Err = RecordError;
}
impl<S: BosStr> From<PostGetRecordOutput<S>> for Post<S> {
fn from(output: PostGetRecordOutput<S>) -> Self {
output.value
}
}
impl<S: BosStr> Collection for Post<S> {
const NSID: &'static str = "tools.smokesignal.blahg.content.post";
type Record = PostRecord;
}
impl Collection for PostRecord {
const NSID: &'static str = "tools.smokesignal.blahg.content.post";
type Record = PostRecord;
}
impl<S: BosStr> LexiconSchema for Post<S> {
fn nsid() -> &'static str {
"tools.smokesignal.blahg.content.post"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_tools_smokesignal_blahg_content_post()
}
fn validate(&self) -> Result<(), ConstraintError> {
if let Some(ref value) = self.content {
{
let size = value.blob().size;
if size > 1000000usize {
return Err(ConstraintError::BlobTooLarge {
path: ValidationPath::from_field("content"),
max: 1000000usize,
actual: size,
});
}
}
}
if let Some(ref value) = self.content {
{
let mime = value.blob().mime_type.as_str();
let accepted: &[&str] = &["text/plain", "text/html", "text/markdown"];
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("content"),
accepted: vec![
"text/plain".to_string(),
"text/html".to_string(),
"text/markdown".to_string(),
],
actual: mime.to_string(),
});
}
}
}
if let Some(ref value) = self.langs {
#[allow(unused_comparisons)]
if value.len() > 3usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("langs"),
max: 3usize,
actual: value.len(),
});
}
}
if let Some(ref value) = self.title {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 2000usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("title"),
max: 2000usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.title {
{
let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
if count > 200usize {
return Err(ConstraintError::MaxGraphemes {
path: ValidationPath::from_field("title"),
max: 200usize,
actual: count,
});
}
}
}
Ok(())
}
}
pub mod attachment_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 Content;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Content = Unset;
}
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 Content = Set<members::content>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct content(());
}
}
pub struct AttachmentBuilder<S: BosStr, St: attachment_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (Option<S>, Option<BlobRef<S>>),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> Attachment<S> {
pub fn new() -> AttachmentBuilder<S, attachment_state::Empty> {
AttachmentBuilder::new()
}
}
impl<S: BosStr> AttachmentBuilder<S, attachment_state::Empty> {
pub fn new() -> Self {
AttachmentBuilder {
_state: PhantomData,
_fields: (None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St: attachment_state::State> AttachmentBuilder<S, St> {
pub fn alt(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.0 = value.into();
self
}
pub fn maybe_alt(mut self, value: Option<S>) -> Self {
self._fields.0 = value;
self
}
}
impl<S: BosStr, St> AttachmentBuilder<S, St>
where
St: attachment_state::State,
St::Content: attachment_state::IsUnset,
{
pub fn content(
mut self,
value: impl Into<BlobRef<S>>,
) -> AttachmentBuilder<S, attachment_state::SetContent<St>> {
self._fields.1 = Option::Some(value.into());
AttachmentBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> AttachmentBuilder<S, St>
where
St: attachment_state::State,
St::Content: attachment_state::IsSet,
{
pub fn build(self) -> Attachment<S> {
Attachment {
alt: self._fields.0,
content: self._fields.1.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Attachment<S> {
Attachment {
alt: self._fields.0,
content: self._fields.1.unwrap(),
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_tools_smokesignal_blahg_content_post() -> 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("tools.smokesignal.blahg.content.post"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("attachment"),
LexUserType::Object(LexObject {
required: Some(vec![SmolStr::new_static("content")]),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("alt"),
LexObjectProperty::String(LexString {
description: Some(CowStr::new_static(
"Alt text description of the content, for accessibility.",
)),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("content"),
LexObjectProperty::Blob(LexBlob {
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map.insert(
SmolStr::new_static("main"),
LexUserType::Record(LexRecord {
description: Some(CowStr::new_static("A blagh post")),
key: Some(CowStr::new_static("any")),
record: LexRecordRecord::Object(LexObject {
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("attachments"),
LexObjectProperty::Array(LexArray {
items: LexArrayItem::Ref(LexRef {
r#ref: CowStr::new_static("#attachment"),
..Default::default()
}),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("content"),
LexObjectProperty::Blob(LexBlob {
..Default::default()
}),
);
map.insert(
SmolStr::new_static("langs"),
LexObjectProperty::Array(LexArray {
description: Some(CowStr::new_static(
"Indicates human language of text content.",
)),
items: LexArrayItem::String(LexString {
format: Some(LexStringFormat::Language),
..Default::default()
}),
max_length: Some(3usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("publishedAt"),
LexObjectProperty::String(LexString {
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("title"),
LexObjectProperty::String(LexString {
max_length: Some(2000usize),
max_graphemes: Some(200usize),
..Default::default()
}),
);
map
},
..Default::default()
}),
..Default::default()
}),
);
map
},
..Default::default()
}
}
pub mod post_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 {}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {}
#[allow(non_camel_case_types)]
pub mod members {}
}
pub struct PostBuilder<S: BosStr, St: post_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<Vec<post::Attachment<S>>>,
Option<BlobRef<S>>,
Option<Vec<Language>>,
Option<Datetime>,
Option<S>,
),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> Post<S> {
pub fn new() -> PostBuilder<S, post_state::Empty> {
PostBuilder::new()
}
}
impl<S: BosStr> PostBuilder<S, post_state::Empty> {
pub fn new() -> Self {
PostBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St: post_state::State> PostBuilder<S, St> {
pub fn attachments(mut self, value: impl Into<Option<Vec<post::Attachment<S>>>>) -> Self {
self._fields.0 = value.into();
self
}
pub fn maybe_attachments(mut self, value: Option<Vec<post::Attachment<S>>>) -> Self {
self._fields.0 = value;
self
}
}
impl<S: BosStr, St: post_state::State> PostBuilder<S, St> {
pub fn content(mut self, value: impl Into<Option<BlobRef<S>>>) -> Self {
self._fields.1 = value.into();
self
}
pub fn maybe_content(mut self, value: Option<BlobRef<S>>) -> Self {
self._fields.1 = value;
self
}
}
impl<S: BosStr, St: post_state::State> PostBuilder<S, St> {
pub fn langs(mut self, value: impl Into<Option<Vec<Language>>>) -> Self {
self._fields.2 = value.into();
self
}
pub fn maybe_langs(mut self, value: Option<Vec<Language>>) -> Self {
self._fields.2 = value;
self
}
}
impl<S: BosStr, St: post_state::State> PostBuilder<S, St> {
pub fn published_at(mut self, value: impl Into<Option<Datetime>>) -> Self {
self._fields.3 = value.into();
self
}
pub fn maybe_published_at(mut self, value: Option<Datetime>) -> Self {
self._fields.3 = value;
self
}
}
impl<S: BosStr, St: post_state::State> PostBuilder<S, St> {
pub fn title(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.4 = value.into();
self
}
pub fn maybe_title(mut self, value: Option<S>) -> Self {
self._fields.4 = value;
self
}
}
impl<S: BosStr, St> PostBuilder<S, St>
where
St: post_state::State,
{
pub fn build(self) -> Post<S> {
Post {
attachments: self._fields.0,
content: self._fields.1,
langs: self._fields.2,
published_at: self._fields.3,
title: self._fields.4,
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Post<S> {
Post {
attachments: self._fields.0,
content: self._fields.1,
langs: self._fields.2,
published_at: self._fields.3,
title: self._fields.4,
extra_data: Some(extra_data),
}
}
}