#[allow(unused_imports)]
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::CowStr;
#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::types::collection::{Collection, RecordError};
use jacquard_common::types::string::{AtUri, Cid, Datetime};
use jacquard_common::types::uri::{RecordUri, UriError};
use jacquard_common::xrpc::XrpcResp;
use jacquard_derive::{IntoStatic, lexicon};
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::pub_leaflet::pages::linear_document::Quote;
use crate::pub_leaflet::richtext::facet::Facet;
use crate::pub_leaflet::comment;
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct LinearDocumentQuote<'a> {
#[serde(borrow)]
pub document: AtUri<'a>,
#[serde(borrow)]
pub quote: Quote<'a>,
}
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Comment<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub attachment: Option<comment::LinearDocumentQuote<'a>>,
pub created_at: Datetime,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub facets: Option<Vec<Facet<'a>>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub on_page: Option<CowStr<'a>>,
#[serde(borrow)]
pub plaintext: CowStr<'a>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub reply: Option<comment::ReplyRef<'a>>,
#[serde(borrow)]
pub subject: AtUri<'a>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct CommentGetRecordOutput<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub cid: Option<Cid<'a>>,
#[serde(borrow)]
pub uri: AtUri<'a>,
#[serde(borrow)]
pub value: Comment<'a>,
}
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct ReplyRef<'a> {
#[serde(borrow)]
pub parent: AtUri<'a>,
}
impl<'a> Comment<'a> {
pub fn uri(
uri: impl Into<CowStr<'a>>,
) -> Result<RecordUri<'a, CommentRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new_cow(uri.into())?)
}
}
impl<'a> LexiconSchema for LinearDocumentQuote<'a> {
fn nsid() -> &'static str {
"pub.leaflet.comment"
}
fn def_name() -> &'static str {
"linearDocumentQuote"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_pub_leaflet_comment()
}
fn validate(&self) -> Result<(), ConstraintError> {
Ok(())
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct CommentRecord;
impl XrpcResp for CommentRecord {
const NSID: &'static str = "pub.leaflet.comment";
const ENCODING: &'static str = "application/json";
type Output<'de> = CommentGetRecordOutput<'de>;
type Err<'de> = RecordError<'de>;
}
impl From<CommentGetRecordOutput<'_>> for Comment<'_> {
fn from(output: CommentGetRecordOutput<'_>) -> Self {
use jacquard_common::IntoStatic;
output.value.into_static()
}
}
impl Collection for Comment<'_> {
const NSID: &'static str = "pub.leaflet.comment";
type Record = CommentRecord;
}
impl Collection for CommentRecord {
const NSID: &'static str = "pub.leaflet.comment";
type Record = CommentRecord;
}
impl<'a> LexiconSchema for Comment<'a> {
fn nsid() -> &'static str {
"pub.leaflet.comment"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_pub_leaflet_comment()
}
fn validate(&self) -> Result<(), ConstraintError> {
Ok(())
}
}
impl<'a> LexiconSchema for ReplyRef<'a> {
fn nsid() -> &'static str {
"pub.leaflet.comment"
}
fn def_name() -> &'static str {
"replyRef"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_pub_leaflet_comment()
}
fn validate(&self) -> Result<(), ConstraintError> {
Ok(())
}
}
pub mod linear_document_quote_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 Document;
type Quote;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Document = Unset;
type Quote = Unset;
}
pub struct SetDocument<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetDocument<S> {}
impl<S: State> State for SetDocument<S> {
type Document = Set<members::document>;
type Quote = S::Quote;
}
pub struct SetQuote<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetQuote<S> {}
impl<S: State> State for SetQuote<S> {
type Document = S::Document;
type Quote = Set<members::quote>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct document(());
pub struct quote(());
}
}
pub struct LinearDocumentQuoteBuilder<'a, S: linear_document_quote_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (Option<AtUri<'a>>, Option<Quote<'a>>),
_lifetime: PhantomData<&'a ()>,
}
impl<'a> LinearDocumentQuote<'a> {
pub fn new() -> LinearDocumentQuoteBuilder<'a, linear_document_quote_state::Empty> {
LinearDocumentQuoteBuilder::new()
}
}
impl<'a> LinearDocumentQuoteBuilder<'a, linear_document_quote_state::Empty> {
pub fn new() -> Self {
LinearDocumentQuoteBuilder {
_state: PhantomData,
_fields: (None, None),
_lifetime: PhantomData,
}
}
}
impl<'a, S> LinearDocumentQuoteBuilder<'a, S>
where
S: linear_document_quote_state::State,
S::Document: linear_document_quote_state::IsUnset,
{
pub fn document(
mut self,
value: impl Into<AtUri<'a>>,
) -> LinearDocumentQuoteBuilder<'a, linear_document_quote_state::SetDocument<S>> {
self._fields.0 = Option::Some(value.into());
LinearDocumentQuoteBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> LinearDocumentQuoteBuilder<'a, S>
where
S: linear_document_quote_state::State,
S::Quote: linear_document_quote_state::IsUnset,
{
pub fn quote(
mut self,
value: impl Into<Quote<'a>>,
) -> LinearDocumentQuoteBuilder<'a, linear_document_quote_state::SetQuote<S>> {
self._fields.1 = Option::Some(value.into());
LinearDocumentQuoteBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> LinearDocumentQuoteBuilder<'a, S>
where
S: linear_document_quote_state::State,
S::Document: linear_document_quote_state::IsSet,
S::Quote: linear_document_quote_state::IsSet,
{
pub fn build(self) -> LinearDocumentQuote<'a> {
LinearDocumentQuote {
document: self._fields.0.unwrap(),
quote: self._fields.1.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(
self,
extra_data: BTreeMap<
jacquard_common::deps::smol_str::SmolStr,
jacquard_common::types::value::Data<'a>,
>,
) -> LinearDocumentQuote<'a> {
LinearDocumentQuote {
document: self._fields.0.unwrap(),
quote: self._fields.1.unwrap(),
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_pub_leaflet_comment() -> 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("pub.leaflet.comment"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("linearDocumentQuote"),
LexUserType::Object(LexObject {
required: Some(
vec![
SmolStr::new_static("document"), SmolStr::new_static("quote")
],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("document"),
LexObjectProperty::String(LexString {
format: Some(LexStringFormat::AtUri),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("quote"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static(
"pub.leaflet.pages.linearDocument#quote",
),
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map.insert(
SmolStr::new_static("main"),
LexUserType::Record(LexRecord {
description: Some(CowStr::new_static("Record containing a comment")),
key: Some(CowStr::new_static("tid")),
record: LexRecordRecord::Object(LexObject {
required: Some(
vec![
SmolStr::new_static("subject"),
SmolStr::new_static("plaintext"),
SmolStr::new_static("createdAt")
],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("attachment"),
LexObjectProperty::Union(LexRefUnion {
refs: vec![CowStr::new_static("#linearDocumentQuote")],
..Default::default()
}),
);
map.insert(
SmolStr::new_static("createdAt"),
LexObjectProperty::String(LexString {
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("facets"),
LexObjectProperty::Array(LexArray {
items: LexArrayItem::Ref(LexRef {
r#ref: CowStr::new_static("pub.leaflet.richtext.facet"),
..Default::default()
}),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("onPage"),
LexObjectProperty::String(LexString {
..Default::default()
}),
);
map.insert(
SmolStr::new_static("plaintext"),
LexObjectProperty::String(LexString {
..Default::default()
}),
);
map.insert(
SmolStr::new_static("reply"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static("#replyRef"),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("subject"),
LexObjectProperty::String(LexString {
format: Some(LexStringFormat::AtUri),
..Default::default()
}),
);
map
},
..Default::default()
}),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("replyRef"),
LexUserType::Object(LexObject {
required: Some(vec![SmolStr::new_static("parent")]),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("parent"),
LexObjectProperty::String(LexString {
format: Some(LexStringFormat::AtUri),
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map
},
..Default::default()
}
}
pub mod comment_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 Plaintext;
type Subject;
type CreatedAt;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Plaintext = Unset;
type Subject = Unset;
type CreatedAt = Unset;
}
pub struct SetPlaintext<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetPlaintext<S> {}
impl<S: State> State for SetPlaintext<S> {
type Plaintext = Set<members::plaintext>;
type Subject = S::Subject;
type CreatedAt = S::CreatedAt;
}
pub struct SetSubject<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetSubject<S> {}
impl<S: State> State for SetSubject<S> {
type Plaintext = S::Plaintext;
type Subject = Set<members::subject>;
type CreatedAt = S::CreatedAt;
}
pub struct SetCreatedAt<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetCreatedAt<S> {}
impl<S: State> State for SetCreatedAt<S> {
type Plaintext = S::Plaintext;
type Subject = S::Subject;
type CreatedAt = Set<members::created_at>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct plaintext(());
pub struct subject(());
pub struct created_at(());
}
}
pub struct CommentBuilder<'a, S: comment_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (
Option<comment::LinearDocumentQuote<'a>>,
Option<Datetime>,
Option<Vec<Facet<'a>>>,
Option<CowStr<'a>>,
Option<CowStr<'a>>,
Option<comment::ReplyRef<'a>>,
Option<AtUri<'a>>,
),
_lifetime: PhantomData<&'a ()>,
}
impl<'a> Comment<'a> {
pub fn new() -> CommentBuilder<'a, comment_state::Empty> {
CommentBuilder::new()
}
}
impl<'a> CommentBuilder<'a, comment_state::Empty> {
pub fn new() -> Self {
CommentBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None, None),
_lifetime: PhantomData,
}
}
}
impl<'a, S: comment_state::State> CommentBuilder<'a, S> {
pub fn attachment(
mut self,
value: impl Into<Option<comment::LinearDocumentQuote<'a>>>,
) -> Self {
self._fields.0 = value.into();
self
}
pub fn maybe_attachment(
mut self,
value: Option<comment::LinearDocumentQuote<'a>>,
) -> Self {
self._fields.0 = value;
self
}
}
impl<'a, S> CommentBuilder<'a, S>
where
S: comment_state::State,
S::CreatedAt: comment_state::IsUnset,
{
pub fn created_at(
mut self,
value: impl Into<Datetime>,
) -> CommentBuilder<'a, comment_state::SetCreatedAt<S>> {
self._fields.1 = Option::Some(value.into());
CommentBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S: comment_state::State> CommentBuilder<'a, S> {
pub fn facets(mut self, value: impl Into<Option<Vec<Facet<'a>>>>) -> Self {
self._fields.2 = value.into();
self
}
pub fn maybe_facets(mut self, value: Option<Vec<Facet<'a>>>) -> Self {
self._fields.2 = value;
self
}
}
impl<'a, S: comment_state::State> CommentBuilder<'a, S> {
pub fn on_page(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
self._fields.3 = value.into();
self
}
pub fn maybe_on_page(mut self, value: Option<CowStr<'a>>) -> Self {
self._fields.3 = value;
self
}
}
impl<'a, S> CommentBuilder<'a, S>
where
S: comment_state::State,
S::Plaintext: comment_state::IsUnset,
{
pub fn plaintext(
mut self,
value: impl Into<CowStr<'a>>,
) -> CommentBuilder<'a, comment_state::SetPlaintext<S>> {
self._fields.4 = Option::Some(value.into());
CommentBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S: comment_state::State> CommentBuilder<'a, S> {
pub fn reply(mut self, value: impl Into<Option<comment::ReplyRef<'a>>>) -> Self {
self._fields.5 = value.into();
self
}
pub fn maybe_reply(mut self, value: Option<comment::ReplyRef<'a>>) -> Self {
self._fields.5 = value;
self
}
}
impl<'a, S> CommentBuilder<'a, S>
where
S: comment_state::State,
S::Subject: comment_state::IsUnset,
{
pub fn subject(
mut self,
value: impl Into<AtUri<'a>>,
) -> CommentBuilder<'a, comment_state::SetSubject<S>> {
self._fields.6 = Option::Some(value.into());
CommentBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> CommentBuilder<'a, S>
where
S: comment_state::State,
S::Plaintext: comment_state::IsSet,
S::Subject: comment_state::IsSet,
S::CreatedAt: comment_state::IsSet,
{
pub fn build(self) -> Comment<'a> {
Comment {
attachment: self._fields.0,
created_at: self._fields.1.unwrap(),
facets: self._fields.2,
on_page: self._fields.3,
plaintext: self._fields.4.unwrap(),
reply: self._fields.5,
subject: self._fields.6.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(
self,
extra_data: BTreeMap<
jacquard_common::deps::smol_str::SmolStr,
jacquard_common::types::value::Data<'a>,
>,
) -> Comment<'a> {
Comment {
attachment: self._fields.0,
created_at: self._fields.1.unwrap(),
facets: self._fields.2,
on_page: self._fields.3,
plaintext: self._fields.4.unwrap(),
reply: self._fields.5,
subject: self._fields.6.unwrap(),
extra_data: Some(extra_data),
}
}
}
pub mod reply_ref_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 Parent;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Parent = Unset;
}
pub struct SetParent<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetParent<S> {}
impl<S: State> State for SetParent<S> {
type Parent = Set<members::parent>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct parent(());
}
}
pub struct ReplyRefBuilder<'a, S: reply_ref_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (Option<AtUri<'a>>,),
_lifetime: PhantomData<&'a ()>,
}
impl<'a> ReplyRef<'a> {
pub fn new() -> ReplyRefBuilder<'a, reply_ref_state::Empty> {
ReplyRefBuilder::new()
}
}
impl<'a> ReplyRefBuilder<'a, reply_ref_state::Empty> {
pub fn new() -> Self {
ReplyRefBuilder {
_state: PhantomData,
_fields: (None,),
_lifetime: PhantomData,
}
}
}
impl<'a, S> ReplyRefBuilder<'a, S>
where
S: reply_ref_state::State,
S::Parent: reply_ref_state::IsUnset,
{
pub fn parent(
mut self,
value: impl Into<AtUri<'a>>,
) -> ReplyRefBuilder<'a, reply_ref_state::SetParent<S>> {
self._fields.0 = Option::Some(value.into());
ReplyRefBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> ReplyRefBuilder<'a, S>
where
S: reply_ref_state::State,
S::Parent: reply_ref_state::IsSet,
{
pub fn build(self) -> ReplyRef<'a> {
ReplyRef {
parent: self._fields.0.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(
self,
extra_data: BTreeMap<
jacquard_common::deps::smol_str::SmolStr,
jacquard_common::types::value::Data<'a>,
>,
) -> ReplyRef<'a> {
ReplyRef {
parent: self._fields.0.unwrap(),
extra_data: Some(extra_data),
}
}
}