#[jacquard_derive::lexicon]
#[derive(
serde::Serialize,
serde::Deserialize,
Debug,
Clone,
PartialEq,
Eq,
jacquard_derive::IntoStatic
)]
#[serde(rename_all = "camelCase")]
pub struct Document<'a> {
#[serde(borrow)]
pub author: jacquard_common::types::ident::AtIdentifier<'a>,
#[serde(skip_serializing_if = "std::option::Option::is_none")]
#[serde(borrow)]
pub cover_image: std::option::Option<jacquard_common::types::blob::BlobRef<'a>>,
#[serde(skip_serializing_if = "std::option::Option::is_none")]
#[serde(borrow)]
pub description: std::option::Option<jacquard_common::CowStr<'a>>,
#[serde(borrow)]
pub pages: Vec<DocumentPagesItem<'a>>,
#[serde(skip_serializing_if = "std::option::Option::is_none")]
#[serde(borrow)]
pub post_ref: std::option::Option<
crate::com_atproto::repo::strong_ref::StrongRef<'a>,
>,
#[serde(skip_serializing_if = "std::option::Option::is_none")]
#[serde(borrow)]
pub preferences: std::option::Option<
crate::pub_leaflet::publication::Preferences<'a>,
>,
#[serde(skip_serializing_if = "std::option::Option::is_none")]
#[serde(borrow)]
pub publication: std::option::Option<jacquard_common::types::string::AtUri<'a>>,
#[serde(skip_serializing_if = "std::option::Option::is_none")]
pub published_at: std::option::Option<jacquard_common::types::string::Datetime>,
#[serde(skip_serializing_if = "std::option::Option::is_none")]
#[serde(borrow)]
pub tags: std::option::Option<Vec<jacquard_common::CowStr<'a>>>,
#[serde(skip_serializing_if = "std::option::Option::is_none")]
#[serde(borrow)]
pub theme: std::option::Option<crate::pub_leaflet::publication::Theme<'a>>,
#[serde(borrow)]
pub title: jacquard_common::CowStr<'a>,
}
pub mod document_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 Author;
type Pages;
type Title;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Author = Unset;
type Pages = Unset;
type Title = Unset;
}
pub struct SetAuthor<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetAuthor<S> {}
impl<S: State> State for SetAuthor<S> {
type Author = Set<members::author>;
type Pages = S::Pages;
type Title = S::Title;
}
pub struct SetPages<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetPages<S> {}
impl<S: State> State for SetPages<S> {
type Author = S::Author;
type Pages = Set<members::pages>;
type Title = S::Title;
}
pub struct SetTitle<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetTitle<S> {}
impl<S: State> State for SetTitle<S> {
type Author = S::Author;
type Pages = S::Pages;
type Title = Set<members::title>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct author(());
pub struct pages(());
pub struct title(());
}
}
pub struct DocumentBuilder<'a, S: document_state::State> {
_phantom_state: ::core::marker::PhantomData<fn() -> S>,
__unsafe_private_named: (
::core::option::Option<jacquard_common::types::ident::AtIdentifier<'a>>,
::core::option::Option<jacquard_common::types::blob::BlobRef<'a>>,
::core::option::Option<jacquard_common::CowStr<'a>>,
::core::option::Option<Vec<DocumentPagesItem<'a>>>,
::core::option::Option<crate::com_atproto::repo::strong_ref::StrongRef<'a>>,
::core::option::Option<crate::pub_leaflet::publication::Preferences<'a>>,
::core::option::Option<jacquard_common::types::string::AtUri<'a>>,
::core::option::Option<jacquard_common::types::string::Datetime>,
::core::option::Option<Vec<jacquard_common::CowStr<'a>>>,
::core::option::Option<crate::pub_leaflet::publication::Theme<'a>>,
::core::option::Option<jacquard_common::CowStr<'a>>,
),
_phantom: ::core::marker::PhantomData<&'a ()>,
}
impl<'a> Document<'a> {
pub fn new() -> DocumentBuilder<'a, document_state::Empty> {
DocumentBuilder::new()
}
}
impl<'a> DocumentBuilder<'a, document_state::Empty> {
pub fn new() -> Self {
DocumentBuilder {
_phantom_state: ::core::marker::PhantomData,
__unsafe_private_named: (
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
),
_phantom: ::core::marker::PhantomData,
}
}
}
impl<'a, S> DocumentBuilder<'a, S>
where
S: document_state::State,
S::Author: document_state::IsUnset,
{
pub fn author(
mut self,
value: impl Into<jacquard_common::types::ident::AtIdentifier<'a>>,
) -> DocumentBuilder<'a, document_state::SetAuthor<S>> {
self.__unsafe_private_named.0 = ::core::option::Option::Some(value.into());
DocumentBuilder {
_phantom_state: ::core::marker::PhantomData,
__unsafe_private_named: self.__unsafe_private_named,
_phantom: ::core::marker::PhantomData,
}
}
}
impl<'a, S: document_state::State> DocumentBuilder<'a, S> {
pub fn cover_image(
mut self,
value: impl Into<Option<jacquard_common::types::blob::BlobRef<'a>>>,
) -> Self {
self.__unsafe_private_named.1 = value.into();
self
}
pub fn maybe_cover_image(
mut self,
value: Option<jacquard_common::types::blob::BlobRef<'a>>,
) -> Self {
self.__unsafe_private_named.1 = value;
self
}
}
impl<'a, S: document_state::State> DocumentBuilder<'a, S> {
pub fn description(
mut self,
value: impl Into<Option<jacquard_common::CowStr<'a>>>,
) -> Self {
self.__unsafe_private_named.2 = value.into();
self
}
pub fn maybe_description(
mut self,
value: Option<jacquard_common::CowStr<'a>>,
) -> Self {
self.__unsafe_private_named.2 = value;
self
}
}
impl<'a, S> DocumentBuilder<'a, S>
where
S: document_state::State,
S::Pages: document_state::IsUnset,
{
pub fn pages(
mut self,
value: impl Into<Vec<DocumentPagesItem<'a>>>,
) -> DocumentBuilder<'a, document_state::SetPages<S>> {
self.__unsafe_private_named.3 = ::core::option::Option::Some(value.into());
DocumentBuilder {
_phantom_state: ::core::marker::PhantomData,
__unsafe_private_named: self.__unsafe_private_named,
_phantom: ::core::marker::PhantomData,
}
}
}
impl<'a, S: document_state::State> DocumentBuilder<'a, S> {
pub fn post_ref(
mut self,
value: impl Into<Option<crate::com_atproto::repo::strong_ref::StrongRef<'a>>>,
) -> Self {
self.__unsafe_private_named.4 = value.into();
self
}
pub fn maybe_post_ref(
mut self,
value: Option<crate::com_atproto::repo::strong_ref::StrongRef<'a>>,
) -> Self {
self.__unsafe_private_named.4 = value;
self
}
}
impl<'a, S: document_state::State> DocumentBuilder<'a, S> {
pub fn preferences(
mut self,
value: impl Into<Option<crate::pub_leaflet::publication::Preferences<'a>>>,
) -> Self {
self.__unsafe_private_named.5 = value.into();
self
}
pub fn maybe_preferences(
mut self,
value: Option<crate::pub_leaflet::publication::Preferences<'a>>,
) -> Self {
self.__unsafe_private_named.5 = value;
self
}
}
impl<'a, S: document_state::State> DocumentBuilder<'a, S> {
pub fn publication(
mut self,
value: impl Into<Option<jacquard_common::types::string::AtUri<'a>>>,
) -> Self {
self.__unsafe_private_named.6 = value.into();
self
}
pub fn maybe_publication(
mut self,
value: Option<jacquard_common::types::string::AtUri<'a>>,
) -> Self {
self.__unsafe_private_named.6 = value;
self
}
}
impl<'a, S: document_state::State> DocumentBuilder<'a, S> {
pub fn published_at(
mut self,
value: impl Into<Option<jacquard_common::types::string::Datetime>>,
) -> Self {
self.__unsafe_private_named.7 = value.into();
self
}
pub fn maybe_published_at(
mut self,
value: Option<jacquard_common::types::string::Datetime>,
) -> Self {
self.__unsafe_private_named.7 = value;
self
}
}
impl<'a, S: document_state::State> DocumentBuilder<'a, S> {
pub fn tags(
mut self,
value: impl Into<Option<Vec<jacquard_common::CowStr<'a>>>>,
) -> Self {
self.__unsafe_private_named.8 = value.into();
self
}
pub fn maybe_tags(
mut self,
value: Option<Vec<jacquard_common::CowStr<'a>>>,
) -> Self {
self.__unsafe_private_named.8 = value;
self
}
}
impl<'a, S: document_state::State> DocumentBuilder<'a, S> {
pub fn theme(
mut self,
value: impl Into<Option<crate::pub_leaflet::publication::Theme<'a>>>,
) -> Self {
self.__unsafe_private_named.9 = value.into();
self
}
pub fn maybe_theme(
mut self,
value: Option<crate::pub_leaflet::publication::Theme<'a>>,
) -> Self {
self.__unsafe_private_named.9 = value;
self
}
}
impl<'a, S> DocumentBuilder<'a, S>
where
S: document_state::State,
S::Title: document_state::IsUnset,
{
pub fn title(
mut self,
value: impl Into<jacquard_common::CowStr<'a>>,
) -> DocumentBuilder<'a, document_state::SetTitle<S>> {
self.__unsafe_private_named.10 = ::core::option::Option::Some(value.into());
DocumentBuilder {
_phantom_state: ::core::marker::PhantomData,
__unsafe_private_named: self.__unsafe_private_named,
_phantom: ::core::marker::PhantomData,
}
}
}
impl<'a, S> DocumentBuilder<'a, S>
where
S: document_state::State,
S::Author: document_state::IsSet,
S::Pages: document_state::IsSet,
S::Title: document_state::IsSet,
{
pub fn build(self) -> Document<'a> {
Document {
author: self.__unsafe_private_named.0.unwrap(),
cover_image: self.__unsafe_private_named.1,
description: self.__unsafe_private_named.2,
pages: self.__unsafe_private_named.3.unwrap(),
post_ref: self.__unsafe_private_named.4,
preferences: self.__unsafe_private_named.5,
publication: self.__unsafe_private_named.6,
published_at: self.__unsafe_private_named.7,
tags: self.__unsafe_private_named.8,
theme: self.__unsafe_private_named.9,
title: self.__unsafe_private_named.10.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(
self,
extra_data: std::collections::BTreeMap<
jacquard_common::deps::smol_str::SmolStr,
jacquard_common::types::value::Data<'a>,
>,
) -> Document<'a> {
Document {
author: self.__unsafe_private_named.0.unwrap(),
cover_image: self.__unsafe_private_named.1,
description: self.__unsafe_private_named.2,
pages: self.__unsafe_private_named.3.unwrap(),
post_ref: self.__unsafe_private_named.4,
preferences: self.__unsafe_private_named.5,
publication: self.__unsafe_private_named.6,
published_at: self.__unsafe_private_named.7,
tags: self.__unsafe_private_named.8,
theme: self.__unsafe_private_named.9,
title: self.__unsafe_private_named.10.unwrap(),
extra_data: Some(extra_data),
}
}
}
impl<'a> Document<'a> {
pub fn uri(
uri: impl Into<jacquard_common::CowStr<'a>>,
) -> Result<
jacquard_common::types::uri::RecordUri<'a, DocumentRecord>,
jacquard_common::types::uri::UriError,
> {
jacquard_common::types::uri::RecordUri::try_from_uri(
jacquard_common::types::string::AtUri::new_cow(uri.into())?,
)
}
}
#[jacquard_derive::open_union]
#[derive(
serde::Serialize,
serde::Deserialize,
Debug,
Clone,
PartialEq,
Eq,
jacquard_derive::IntoStatic
)]
#[serde(tag = "$type")]
#[serde(bound(deserialize = "'de: 'a"))]
pub enum DocumentPagesItem<'a> {
#[serde(rename = "pub.leaflet.pages.linearDocument")]
LinearDocument(Box<crate::pub_leaflet::pages::linear_document::LinearDocument<'a>>),
#[serde(rename = "pub.leaflet.pages.canvas")]
Canvas(Box<crate::pub_leaflet::pages::canvas::Canvas<'a>>),
}
#[derive(
serde::Serialize,
serde::Deserialize,
Debug,
Clone,
PartialEq,
Eq,
jacquard_derive::IntoStatic
)]
#[serde(rename_all = "camelCase")]
pub struct DocumentGetRecordOutput<'a> {
#[serde(skip_serializing_if = "std::option::Option::is_none")]
#[serde(borrow)]
pub cid: std::option::Option<jacquard_common::types::string::Cid<'a>>,
#[serde(borrow)]
pub uri: jacquard_common::types::string::AtUri<'a>,
#[serde(borrow)]
pub value: Document<'a>,
}
impl From<DocumentGetRecordOutput<'_>> for Document<'_> {
fn from(output: DocumentGetRecordOutput<'_>) -> Self {
use jacquard_common::IntoStatic;
output.value.into_static()
}
}
impl jacquard_common::types::collection::Collection for Document<'_> {
const NSID: &'static str = "pub.leaflet.document";
type Record = DocumentRecord;
}
#[derive(Debug, serde::Serialize, serde::Deserialize)]
pub struct DocumentRecord;
impl jacquard_common::xrpc::XrpcResp for DocumentRecord {
const NSID: &'static str = "pub.leaflet.document";
const ENCODING: &'static str = "application/json";
type Output<'de> = DocumentGetRecordOutput<'de>;
type Err<'de> = jacquard_common::types::collection::RecordError<'de>;
}
impl jacquard_common::types::collection::Collection for DocumentRecord {
const NSID: &'static str = "pub.leaflet.document";
type Record = DocumentRecord;
}
impl<'a> ::jacquard_lexicon::schema::LexiconSchema for Document<'a> {
fn nsid() -> &'static str {
"pub.leaflet.document"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> ::jacquard_lexicon::lexicon::LexiconDoc<'static> {
lexicon_doc_pub_leaflet_document()
}
fn validate(
&self,
) -> ::core::result::Result<(), ::jacquard_lexicon::validation::ConstraintError> {
if let Some(ref value) = self.cover_image {
{
let size = value.blob().size;
if size > 1000000usize {
return Err(::jacquard_lexicon::validation::ConstraintError::BlobTooLarge {
path: ::jacquard_lexicon::validation::ValidationPath::from_field(
"cover_image",
),
max: 1000000usize,
actual: size,
});
}
}
}
if let Some(ref value) = self.cover_image {
{
let mime = value.blob().mime_type.as_str();
let accepted: &[&str] = &["image/png", "image/jpeg", "image/webp"];
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(::jacquard_lexicon::validation::ConstraintError::BlobMimeTypeNotAccepted {
path: ::jacquard_lexicon::validation::ValidationPath::from_field(
"cover_image",
),
accepted: vec![
"image/png".to_string(), "image/jpeg".to_string(),
"image/webp".to_string()
],
actual: mime.to_string(),
});
}
}
}
if let Some(ref value) = self.description {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 30000usize {
return Err(::jacquard_lexicon::validation::ConstraintError::MaxLength {
path: ::jacquard_lexicon::validation::ValidationPath::from_field(
"description",
),
max: 30000usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.description {
{
let count = jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation::graphemes(
value.as_ref(),
true,
)
.count();
if count > 3000usize {
return Err(::jacquard_lexicon::validation::ConstraintError::MaxGraphemes {
path: ::jacquard_lexicon::validation::ValidationPath::from_field(
"description",
),
max: 3000usize,
actual: count,
});
}
}
}
{
let value = &self.title;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 5000usize {
return Err(::jacquard_lexicon::validation::ConstraintError::MaxLength {
path: ::jacquard_lexicon::validation::ValidationPath::from_field(
"title",
),
max: 5000usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.title;
{
let count = jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation::graphemes(
value.as_ref(),
true,
)
.count();
if count > 500usize {
return Err(::jacquard_lexicon::validation::ConstraintError::MaxGraphemes {
path: ::jacquard_lexicon::validation::ValidationPath::from_field(
"title",
),
max: 500usize,
actual: count,
});
}
}
}
Ok(())
}
}
fn lexicon_doc_pub_leaflet_document() -> ::jacquard_lexicon::lexicon::LexiconDoc<
'static,
> {
::jacquard_lexicon::lexicon::LexiconDoc {
lexicon: ::jacquard_lexicon::lexicon::Lexicon::Lexicon1,
id: ::jacquard_common::CowStr::new_static("pub.leaflet.document"),
revision: None,
description: None,
defs: {
let mut map = ::alloc::collections::BTreeMap::new();
map.insert(
::jacquard_common::deps::smol_str::SmolStr::new_static("main"),
::jacquard_lexicon::lexicon::LexUserType::Record(::jacquard_lexicon::lexicon::LexRecord {
description: Some(
::jacquard_common::CowStr::new_static(
"Record containing a document",
),
),
key: Some(::jacquard_common::CowStr::new_static("tid")),
record: ::jacquard_lexicon::lexicon::LexRecordRecord::Object(::jacquard_lexicon::lexicon::LexObject {
description: None,
required: Some(
vec![
::jacquard_common::deps::smol_str::SmolStr::new_static("pages"),
::jacquard_common::deps::smol_str::SmolStr::new_static("author"),
::jacquard_common::deps::smol_str::SmolStr::new_static("title")
],
),
nullable: None,
properties: {
#[allow(unused_mut)]
let mut map = ::alloc::collections::BTreeMap::new();
map.insert(
::jacquard_common::deps::smol_str::SmolStr::new_static(
"author",
),
::jacquard_lexicon::lexicon::LexObjectProperty::String(::jacquard_lexicon::lexicon::LexString {
description: None,
format: Some(
::jacquard_lexicon::lexicon::LexStringFormat::AtIdentifier,
),
default: None,
min_length: None,
max_length: None,
min_graphemes: None,
max_graphemes: None,
r#enum: None,
r#const: None,
known_values: None,
}),
);
map.insert(
::jacquard_common::deps::smol_str::SmolStr::new_static(
"coverImage",
),
::jacquard_lexicon::lexicon::LexObjectProperty::Blob(::jacquard_lexicon::lexicon::LexBlob {
description: None,
accept: None,
max_size: None,
}),
);
map.insert(
::jacquard_common::deps::smol_str::SmolStr::new_static(
"description",
),
::jacquard_lexicon::lexicon::LexObjectProperty::String(::jacquard_lexicon::lexicon::LexString {
description: None,
format: None,
default: None,
min_length: None,
max_length: Some(30000usize),
min_graphemes: None,
max_graphemes: Some(3000usize),
r#enum: None,
r#const: None,
known_values: None,
}),
);
map.insert(
::jacquard_common::deps::smol_str::SmolStr::new_static(
"pages",
),
::jacquard_lexicon::lexicon::LexObjectProperty::Array(::jacquard_lexicon::lexicon::LexArray {
description: None,
items: ::jacquard_lexicon::lexicon::LexArrayItem::Union(::jacquard_lexicon::lexicon::LexRefUnion {
description: None,
refs: vec![
::jacquard_common::CowStr::new_static("pub.leaflet.pages.linearDocument"),
::jacquard_common::CowStr::new_static("pub.leaflet.pages.canvas")
],
closed: None,
}),
min_length: None,
max_length: None,
}),
);
map.insert(
::jacquard_common::deps::smol_str::SmolStr::new_static(
"postRef",
),
::jacquard_lexicon::lexicon::LexObjectProperty::Ref(::jacquard_lexicon::lexicon::LexRef {
description: None,
r#ref: ::jacquard_common::CowStr::new_static(
"com.atproto.repo.strongRef",
),
}),
);
map.insert(
::jacquard_common::deps::smol_str::SmolStr::new_static(
"preferences",
),
::jacquard_lexicon::lexicon::LexObjectProperty::Ref(::jacquard_lexicon::lexicon::LexRef {
description: None,
r#ref: ::jacquard_common::CowStr::new_static(
"pub.leaflet.publication#preferences",
),
}),
);
map.insert(
::jacquard_common::deps::smol_str::SmolStr::new_static(
"publication",
),
::jacquard_lexicon::lexicon::LexObjectProperty::String(::jacquard_lexicon::lexicon::LexString {
description: None,
format: Some(
::jacquard_lexicon::lexicon::LexStringFormat::AtUri,
),
default: None,
min_length: None,
max_length: None,
min_graphemes: None,
max_graphemes: None,
r#enum: None,
r#const: None,
known_values: None,
}),
);
map.insert(
::jacquard_common::deps::smol_str::SmolStr::new_static(
"publishedAt",
),
::jacquard_lexicon::lexicon::LexObjectProperty::String(::jacquard_lexicon::lexicon::LexString {
description: None,
format: Some(
::jacquard_lexicon::lexicon::LexStringFormat::Datetime,
),
default: None,
min_length: None,
max_length: None,
min_graphemes: None,
max_graphemes: None,
r#enum: None,
r#const: None,
known_values: None,
}),
);
map.insert(
::jacquard_common::deps::smol_str::SmolStr::new_static(
"tags",
),
::jacquard_lexicon::lexicon::LexObjectProperty::Array(::jacquard_lexicon::lexicon::LexArray {
description: None,
items: ::jacquard_lexicon::lexicon::LexArrayItem::String(::jacquard_lexicon::lexicon::LexString {
description: None,
format: None,
default: None,
min_length: None,
max_length: Some(50usize),
min_graphemes: None,
max_graphemes: None,
r#enum: None,
r#const: None,
known_values: None,
}),
min_length: None,
max_length: None,
}),
);
map.insert(
::jacquard_common::deps::smol_str::SmolStr::new_static(
"theme",
),
::jacquard_lexicon::lexicon::LexObjectProperty::Ref(::jacquard_lexicon::lexicon::LexRef {
description: None,
r#ref: ::jacquard_common::CowStr::new_static(
"pub.leaflet.publication#theme",
),
}),
);
map.insert(
::jacquard_common::deps::smol_str::SmolStr::new_static(
"title",
),
::jacquard_lexicon::lexicon::LexObjectProperty::String(::jacquard_lexicon::lexicon::LexString {
description: None,
format: None,
default: None,
min_length: None,
max_length: Some(5000usize),
min_graphemes: None,
max_graphemes: Some(500usize),
r#enum: None,
r#const: None,
known_values: None,
}),
);
map
},
}),
}),
);
map
},
}
}