#[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::collection::{Collection, RecordError};
use jacquard_common::types::string::{AtUri, Cid, Datetime, 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;
use crate::app_greengale::blog::BlobMetadata;
use crate::app_greengale::blog::Ogp;
use crate::app_greengale::blog::Theme;
#[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 ContentRef<S: BosStr = DefaultStr> {
pub uri: AtUri<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 = "app.greengale.document",
tag = "$type",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Document<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub blobs: Option<Vec<BlobMetadata<S>>>,
pub content: S,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default = "_default_document_latex")]
pub latex: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub ogp: Option<Ogp<S>>,
pub path: S,
pub published_at: Datetime,
#[serde(skip_serializing_if = "Option::is_none")]
pub subtitle: Option<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub tags: Option<Vec<S>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub theme: Option<Theme<S>>,
pub title: S,
pub url: UriValue<S>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default = "_default_document_visibility")]
pub visibility: 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 DocumentGetRecordOutput<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub cid: Option<Cid<S>>,
pub uri: AtUri<S>,
pub value: Document<S>,
}
impl<S: BosStr> Document<S> {
pub fn uri(uri: S) -> Result<RecordUri<S, DocumentRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new(uri)?)
}
}
impl<S: BosStr> LexiconSchema for ContentRef<S> {
fn nsid() -> &'static str {
"app.greengale.document"
}
fn def_name() -> &'static str {
"contentRef"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_app_greengale_document()
}
fn validate(&self) -> Result<(), ConstraintError> {
Ok(())
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct DocumentRecord;
impl XrpcResp for DocumentRecord {
const NSID: &'static str = "app.greengale.document";
const ENCODING: &'static str = "application/json";
type Output<S: BosStr> = DocumentGetRecordOutput<S>;
type Err = RecordError;
}
impl<S: BosStr> From<DocumentGetRecordOutput<S>> for Document<S> {
fn from(output: DocumentGetRecordOutput<S>) -> Self {
output.value
}
}
impl<S: BosStr> Collection for Document<S> {
const NSID: &'static str = "app.greengale.document";
type Record = DocumentRecord;
}
impl Collection for DocumentRecord {
const NSID: &'static str = "app.greengale.document";
type Record = DocumentRecord;
}
impl<S: BosStr> LexiconSchema for Document<S> {
fn nsid() -> &'static str {
"app.greengale.document"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_app_greengale_document()
}
fn validate(&self) -> Result<(), ConstraintError> {
{
let value = &self.content;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 100000usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("content"),
max: 100000usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.path;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 500usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("path"),
max: 500usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.subtitle {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 1000usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("subtitle"),
max: 1000usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.tags {
#[allow(unused_comparisons)]
if value.len() > 100usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("tags"),
max: 100usize,
actual: value.len(),
});
}
}
{
let value = &self.title;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 1000usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("title"),
max: 1000usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.url;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 2048usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("url"),
max: 2048usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.visibility {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 16usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("visibility"),
max: 16usize,
actual: <str>::len(value.as_ref()),
});
}
}
Ok(())
}
}
pub mod content_ref_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;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Uri = 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>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct uri(());
}
}
pub struct ContentRefBuilder<S: BosStr, St: content_ref_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (Option<AtUri<S>>,),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> ContentRef<S> {
pub fn new() -> ContentRefBuilder<S, content_ref_state::Empty> {
ContentRefBuilder::new()
}
}
impl<S: BosStr> ContentRefBuilder<S, content_ref_state::Empty> {
pub fn new() -> Self {
ContentRefBuilder {
_state: PhantomData,
_fields: (None,),
_type: PhantomData,
}
}
}
impl<S: BosStr, St> ContentRefBuilder<S, St>
where
St: content_ref_state::State,
St::Uri: content_ref_state::IsUnset,
{
pub fn uri(
mut self,
value: impl Into<AtUri<S>>,
) -> ContentRefBuilder<S, content_ref_state::SetUri<St>> {
self._fields.0 = Option::Some(value.into());
ContentRefBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> ContentRefBuilder<S, St>
where
St: content_ref_state::State,
St::Uri: content_ref_state::IsSet,
{
pub fn build(self) -> ContentRef<S> {
ContentRef {
uri: self._fields.0.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> ContentRef<S> {
ContentRef {
uri: self._fields.0.unwrap(),
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_app_greengale_document() -> 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.greengale.document"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("contentRef"),
LexUserType::Object(LexObject {
description: Some(
CowStr::new_static(
"Reference to external content via AT-URI. Used in site.standard.document content union.",
),
),
required: Some(vec![SmolStr::new_static("uri")]),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("uri"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"AT-URI pointing to the full document content",
),
),
format: Some(LexStringFormat::AtUri),
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map.insert(
SmolStr::new_static("main"),
LexUserType::Record(LexRecord {
description: Some(
CowStr::new_static(
"A markdown document with extended theme and LaTeX support.",
),
),
key: Some(CowStr::new_static("tid")),
record: LexRecordRecord::Object(LexObject {
required: Some(
vec![
SmolStr::new_static("content"), SmolStr::new_static("url"),
SmolStr::new_static("path"), SmolStr::new_static("title"),
SmolStr::new_static("publishedAt")
],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("blobs"),
LexObjectProperty::Array(LexArray {
items: LexArrayItem::Ref(LexRef {
r#ref: CowStr::new_static(
"app.greengale.blog.defs#blobMetadata",
),
..Default::default()
}),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("content"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("Markdown content of the document"),
),
max_length: Some(100000usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("latex"),
LexObjectProperty::Boolean(LexBoolean {
..Default::default()
}),
);
map.insert(
SmolStr::new_static("ogp"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static("app.greengale.blog.defs#ogp"),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("path"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Document path relative to the publication URL (e.g., /handle/rkey)",
),
),
max_length: Some(500usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("publishedAt"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("Publication timestamp"),
),
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("subtitle"),
LexObjectProperty::String(LexString {
max_length: Some(1000usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("tags"),
LexObjectProperty::Array(LexArray {
description: Some(
CowStr::new_static(
"Optional array of strings to tag/categorize the document. Avoid prepending with hashtags.",
),
),
items: LexArrayItem::String(LexString {
max_length: Some(100usize),
max_graphemes: Some(50usize),
..Default::default()
}),
max_length: Some(100usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("theme"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static("app.greengale.blog.defs#theme"),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("title"),
LexObjectProperty::String(LexString {
description: Some(CowStr::new_static("Document title")),
max_length: Some(1000usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("url"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Base publication URL (e.g., https://greengale.app)",
),
),
format: Some(LexStringFormat::Uri),
max_length: Some(2048usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("visibility"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("Controls who can view this document"),
),
max_length: Some(16usize),
..Default::default()
}),
);
map
},
..Default::default()
}),
..Default::default()
}),
);
map
},
..Default::default()
}
}
fn _default_document_latex() -> Option<bool> {
Some(false)
}
fn _default_document_visibility<S: FromStaticStr>() -> ::core::option::Option<S> {
Some(S::from_static("public"))
}
pub mod document_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 PublishedAt;
type Content;
type Url;
type Path;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Title = Unset;
type PublishedAt = Unset;
type Content = Unset;
type Url = Unset;
type Path = 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 PublishedAt = St::PublishedAt;
type Content = St::Content;
type Url = St::Url;
type Path = St::Path;
}
pub struct SetPublishedAt<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetPublishedAt<St> {}
impl<St: State> State for SetPublishedAt<St> {
type Title = St::Title;
type PublishedAt = Set<members::published_at>;
type Content = St::Content;
type Url = St::Url;
type Path = St::Path;
}
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 Title = St::Title;
type PublishedAt = St::PublishedAt;
type Content = Set<members::content>;
type Url = St::Url;
type Path = St::Path;
}
pub struct SetUrl<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetUrl<St> {}
impl<St: State> State for SetUrl<St> {
type Title = St::Title;
type PublishedAt = St::PublishedAt;
type Content = St::Content;
type Url = Set<members::url>;
type Path = St::Path;
}
pub struct SetPath<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetPath<St> {}
impl<St: State> State for SetPath<St> {
type Title = St::Title;
type PublishedAt = St::PublishedAt;
type Content = St::Content;
type Url = St::Url;
type Path = Set<members::path>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct title(());
pub struct published_at(());
pub struct content(());
pub struct url(());
pub struct path(());
}
}
pub struct DocumentBuilder<S: BosStr, St: document_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<Vec<BlobMetadata<S>>>,
Option<S>,
Option<bool>,
Option<Ogp<S>>,
Option<S>,
Option<Datetime>,
Option<S>,
Option<Vec<S>>,
Option<Theme<S>>,
Option<S>,
Option<UriValue<S>>,
Option<S>,
),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> Document<S> {
pub fn new() -> DocumentBuilder<S, document_state::Empty> {
DocumentBuilder::new()
}
}
impl<S: BosStr> DocumentBuilder<S, document_state::Empty> {
pub fn new() -> Self {
DocumentBuilder {
_state: PhantomData,
_fields: (
None, None, None, None, None, None, None, None, None, None, None, None,
),
_type: PhantomData,
}
}
}
impl<S: BosStr, St: document_state::State> DocumentBuilder<S, St> {
pub fn blobs(mut self, value: impl Into<Option<Vec<BlobMetadata<S>>>>) -> Self {
self._fields.0 = value.into();
self
}
pub fn maybe_blobs(mut self, value: Option<Vec<BlobMetadata<S>>>) -> Self {
self._fields.0 = value;
self
}
}
impl<S: BosStr, St> DocumentBuilder<S, St>
where
St: document_state::State,
St::Content: document_state::IsUnset,
{
pub fn content(
mut self,
value: impl Into<S>,
) -> DocumentBuilder<S, document_state::SetContent<St>> {
self._fields.1 = Option::Some(value.into());
DocumentBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: document_state::State> DocumentBuilder<S, St> {
pub fn latex(mut self, value: impl Into<Option<bool>>) -> Self {
self._fields.2 = value.into();
self
}
pub fn maybe_latex(mut self, value: Option<bool>) -> Self {
self._fields.2 = value;
self
}
}
impl<S: BosStr, St: document_state::State> DocumentBuilder<S, St> {
pub fn ogp(mut self, value: impl Into<Option<Ogp<S>>>) -> Self {
self._fields.3 = value.into();
self
}
pub fn maybe_ogp(mut self, value: Option<Ogp<S>>) -> Self {
self._fields.3 = value;
self
}
}
impl<S: BosStr, St> DocumentBuilder<S, St>
where
St: document_state::State,
St::Path: document_state::IsUnset,
{
pub fn path(mut self, value: impl Into<S>) -> DocumentBuilder<S, document_state::SetPath<St>> {
self._fields.4 = Option::Some(value.into());
DocumentBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> DocumentBuilder<S, St>
where
St: document_state::State,
St::PublishedAt: document_state::IsUnset,
{
pub fn published_at(
mut self,
value: impl Into<Datetime>,
) -> DocumentBuilder<S, document_state::SetPublishedAt<St>> {
self._fields.5 = Option::Some(value.into());
DocumentBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: document_state::State> DocumentBuilder<S, St> {
pub fn subtitle(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.6 = value.into();
self
}
pub fn maybe_subtitle(mut self, value: Option<S>) -> Self {
self._fields.6 = value;
self
}
}
impl<S: BosStr, St: document_state::State> DocumentBuilder<S, St> {
pub fn tags(mut self, value: impl Into<Option<Vec<S>>>) -> Self {
self._fields.7 = value.into();
self
}
pub fn maybe_tags(mut self, value: Option<Vec<S>>) -> Self {
self._fields.7 = value;
self
}
}
impl<S: BosStr, St: document_state::State> DocumentBuilder<S, St> {
pub fn theme(mut self, value: impl Into<Option<Theme<S>>>) -> Self {
self._fields.8 = value.into();
self
}
pub fn maybe_theme(mut self, value: Option<Theme<S>>) -> Self {
self._fields.8 = value;
self
}
}
impl<S: BosStr, St> DocumentBuilder<S, St>
where
St: document_state::State,
St::Title: document_state::IsUnset,
{
pub fn title(
mut self,
value: impl Into<S>,
) -> DocumentBuilder<S, document_state::SetTitle<St>> {
self._fields.9 = Option::Some(value.into());
DocumentBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> DocumentBuilder<S, St>
where
St: document_state::State,
St::Url: document_state::IsUnset,
{
pub fn url(
mut self,
value: impl Into<UriValue<S>>,
) -> DocumentBuilder<S, document_state::SetUrl<St>> {
self._fields.10 = Option::Some(value.into());
DocumentBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: document_state::State> DocumentBuilder<S, St> {
pub fn visibility(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.11 = value.into();
self
}
pub fn maybe_visibility(mut self, value: Option<S>) -> Self {
self._fields.11 = value;
self
}
}
impl<S: BosStr, St> DocumentBuilder<S, St>
where
St: document_state::State,
St::Title: document_state::IsSet,
St::PublishedAt: document_state::IsSet,
St::Content: document_state::IsSet,
St::Url: document_state::IsSet,
St::Path: document_state::IsSet,
{
pub fn build(self) -> Document<S> {
Document {
blobs: self._fields.0,
content: self._fields.1.unwrap(),
latex: self._fields.2.or_else(|| Some(false)),
ogp: self._fields.3,
path: self._fields.4.unwrap(),
published_at: self._fields.5.unwrap(),
subtitle: self._fields.6,
tags: self._fields.7,
theme: self._fields.8,
title: self._fields.9.unwrap(),
url: self._fields.10.unwrap(),
visibility: self._fields.11.or_else(|| Some(S::from_static("public"))),
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Document<S> {
Document {
blobs: self._fields.0,
content: self._fields.1.unwrap(),
latex: self._fields.2.or_else(|| Some(false)),
ogp: self._fields.3,
path: self._fields.4.unwrap(),
published_at: self._fields.5.unwrap(),
subtitle: self._fields.6,
tags: self._fields.7,
theme: self._fields.8,
title: self._fields.9.unwrap(),
url: self._fields.10.unwrap(),
visibility: self._fields.11.or_else(|| Some(S::from_static("public"))),
extra_data: Some(extra_data),
}
}
}