#[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, Language};
use jacquard_common::types::uri::{RecordUri, UriError};
use jacquard_common::xrpc::XrpcResp;
use jacquard_derive::{IntoStatic, lexicon, open_union};
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::app_bsky::embed::external::ExternalRecord;
use crate::app_bsky::embed::images::Images;
use crate::app_bsky::embed::record::Record;
use crate::app_bsky::embed::record_with_media::RecordWithMedia;
use crate::app_bsky::embed::video::Video;
use crate::app_bsky::richtext::facet::Facet;
use crate::com_atproto::label::SelfLabels;
use crate::com_atproto::repo::strong_ref::StrongRef;
use crate::net_anisota::feed::post;
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Post<'a> {
pub created_at: Datetime,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub embed: Option<PostEmbed<'a>>,
#[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 labels: Option<SelfLabels<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub langs: Option<Vec<Language>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub reply: Option<post::ReplyRef<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub tags: Option<Vec<CowStr<'a>>>,
#[serde(borrow)]
pub text: CowStr<'a>,
}
#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type")]
#[serde(bound(deserialize = "'de: 'a"))]
pub enum PostEmbed<'a> {
#[serde(rename = "app.bsky.embed.images")]
Images(Box<Images<'a>>),
#[serde(rename = "app.bsky.embed.video")]
Video(Box<Video<'a>>),
#[serde(rename = "app.bsky.embed.external")]
External(Box<ExternalRecord<'a>>),
#[serde(rename = "app.bsky.embed.record")]
Record(Box<Record<'a>>),
#[serde(rename = "app.bsky.embed.recordWithMedia")]
RecordWithMedia(Box<RecordWithMedia<'a>>),
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct PostGetRecordOutput<'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: Post<'a>,
}
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct ReplyRef<'a> {
#[serde(borrow)]
pub parent: StrongRef<'a>,
#[serde(borrow)]
pub root: StrongRef<'a>,
}
impl<'a> Post<'a> {
pub fn uri(
uri: impl Into<CowStr<'a>>,
) -> Result<RecordUri<'a, PostRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new_cow(uri.into())?)
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct PostRecord;
impl XrpcResp for PostRecord {
const NSID: &'static str = "net.anisota.feed.post";
const ENCODING: &'static str = "application/json";
type Output<'de> = PostGetRecordOutput<'de>;
type Err<'de> = RecordError<'de>;
}
impl From<PostGetRecordOutput<'_>> for Post<'_> {
fn from(output: PostGetRecordOutput<'_>) -> Self {
use jacquard_common::IntoStatic;
output.value.into_static()
}
}
impl Collection for Post<'_> {
const NSID: &'static str = "net.anisota.feed.post";
type Record = PostRecord;
}
impl Collection for PostRecord {
const NSID: &'static str = "net.anisota.feed.post";
type Record = PostRecord;
}
impl<'a> LexiconSchema for Post<'a> {
fn nsid() -> &'static str {
"net.anisota.feed.post"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_net_anisota_feed_post()
}
fn validate(&self) -> Result<(), ConstraintError> {
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.tags {
#[allow(unused_comparisons)]
if value.len() > 8usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("tags"),
max: 8usize,
actual: value.len(),
});
}
}
{
let value = &self.text;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 3000usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("text"),
max: 3000usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.text;
{
let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
if count > 300usize {
return Err(ConstraintError::MaxGraphemes {
path: ValidationPath::from_field("text"),
max: 300usize,
actual: count,
});
}
}
}
Ok(())
}
}
impl<'a> LexiconSchema for ReplyRef<'a> {
fn nsid() -> &'static str {
"net.anisota.feed.post"
}
fn def_name() -> &'static str {
"replyRef"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_net_anisota_feed_post()
}
fn validate(&self) -> Result<(), ConstraintError> {
Ok(())
}
}
pub mod post_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 Text;
type CreatedAt;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Text = Unset;
type CreatedAt = Unset;
}
pub struct SetText<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetText<S> {}
impl<S: State> State for SetText<S> {
type Text = Set<members::text>;
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 Text = S::Text;
type CreatedAt = Set<members::created_at>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct text(());
pub struct created_at(());
}
}
pub struct PostBuilder<'a, S: post_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (
Option<Datetime>,
Option<PostEmbed<'a>>,
Option<Vec<Facet<'a>>>,
Option<SelfLabels<'a>>,
Option<Vec<Language>>,
Option<post::ReplyRef<'a>>,
Option<Vec<CowStr<'a>>>,
Option<CowStr<'a>>,
),
_lifetime: PhantomData<&'a ()>,
}
impl<'a> Post<'a> {
pub fn new() -> PostBuilder<'a, post_state::Empty> {
PostBuilder::new()
}
}
impl<'a> PostBuilder<'a, post_state::Empty> {
pub fn new() -> Self {
PostBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None, None, None),
_lifetime: PhantomData,
}
}
}
impl<'a, S> PostBuilder<'a, S>
where
S: post_state::State,
S::CreatedAt: post_state::IsUnset,
{
pub fn created_at(
mut self,
value: impl Into<Datetime>,
) -> PostBuilder<'a, post_state::SetCreatedAt<S>> {
self._fields.0 = Option::Some(value.into());
PostBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S: post_state::State> PostBuilder<'a, S> {
pub fn embed(mut self, value: impl Into<Option<PostEmbed<'a>>>) -> Self {
self._fields.1 = value.into();
self
}
pub fn maybe_embed(mut self, value: Option<PostEmbed<'a>>) -> Self {
self._fields.1 = value;
self
}
}
impl<'a, S: post_state::State> PostBuilder<'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: post_state::State> PostBuilder<'a, S> {
pub fn labels(mut self, value: impl Into<Option<SelfLabels<'a>>>) -> Self {
self._fields.3 = value.into();
self
}
pub fn maybe_labels(mut self, value: Option<SelfLabels<'a>>) -> Self {
self._fields.3 = value;
self
}
}
impl<'a, S: post_state::State> PostBuilder<'a, S> {
pub fn langs(mut self, value: impl Into<Option<Vec<Language>>>) -> Self {
self._fields.4 = value.into();
self
}
pub fn maybe_langs(mut self, value: Option<Vec<Language>>) -> Self {
self._fields.4 = value;
self
}
}
impl<'a, S: post_state::State> PostBuilder<'a, S> {
pub fn reply(mut self, value: impl Into<Option<post::ReplyRef<'a>>>) -> Self {
self._fields.5 = value.into();
self
}
pub fn maybe_reply(mut self, value: Option<post::ReplyRef<'a>>) -> Self {
self._fields.5 = value;
self
}
}
impl<'a, S: post_state::State> PostBuilder<'a, S> {
pub fn tags(mut self, value: impl Into<Option<Vec<CowStr<'a>>>>) -> Self {
self._fields.6 = value.into();
self
}
pub fn maybe_tags(mut self, value: Option<Vec<CowStr<'a>>>) -> Self {
self._fields.6 = value;
self
}
}
impl<'a, S> PostBuilder<'a, S>
where
S: post_state::State,
S::Text: post_state::IsUnset,
{
pub fn text(
mut self,
value: impl Into<CowStr<'a>>,
) -> PostBuilder<'a, post_state::SetText<S>> {
self._fields.7 = Option::Some(value.into());
PostBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> PostBuilder<'a, S>
where
S: post_state::State,
S::Text: post_state::IsSet,
S::CreatedAt: post_state::IsSet,
{
pub fn build(self) -> Post<'a> {
Post {
created_at: self._fields.0.unwrap(),
embed: self._fields.1,
facets: self._fields.2,
labels: self._fields.3,
langs: self._fields.4,
reply: self._fields.5,
tags: self._fields.6,
text: self._fields.7.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>,
>,
) -> Post<'a> {
Post {
created_at: self._fields.0.unwrap(),
embed: self._fields.1,
facets: self._fields.2,
labels: self._fields.3,
langs: self._fields.4,
reply: self._fields.5,
tags: self._fields.6,
text: self._fields.7.unwrap(),
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_net_anisota_feed_post() -> 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("net.anisota.feed.post"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("main"),
LexUserType::Record(LexRecord {
description: Some(
CowStr::new_static(
"A post that can be created on the Anisota network",
),
),
key: Some(CowStr::new_static("tid")),
record: LexRecordRecord::Object(LexObject {
required: Some(
vec![
SmolStr::new_static("text"),
SmolStr::new_static("createdAt")
],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("createdAt"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Client-declared timestamp when this post was created.",
),
),
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("embed"),
LexObjectProperty::Union(LexRefUnion {
refs: vec![
CowStr::new_static("app.bsky.embed.images"),
CowStr::new_static("app.bsky.embed.video"),
CowStr::new_static("app.bsky.embed.external"),
CowStr::new_static("app.bsky.embed.record"),
CowStr::new_static("app.bsky.embed.recordWithMedia")
],
..Default::default()
}),
);
map.insert(
SmolStr::new_static("facets"),
LexObjectProperty::Array(LexArray {
description: Some(
CowStr::new_static(
"Annotations of text (mentions, URLs, hashtags, etc)",
),
),
items: LexArrayItem::Ref(LexRef {
r#ref: CowStr::new_static("app.bsky.richtext.facet"),
..Default::default()
}),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("labels"),
LexObjectProperty::Union(LexRefUnion {
description: Some(
CowStr::new_static(
"Self-label values for this post. Effectively content warnings.",
),
),
refs: vec![
CowStr::new_static("com.atproto.label.defs#selfLabels")
],
..Default::default()
}),
);
map.insert(
SmolStr::new_static("langs"),
LexObjectProperty::Array(LexArray {
description: Some(
CowStr::new_static(
"Indicates human language of post primary text content.",
),
),
items: LexArrayItem::String(LexString {
format: Some(LexStringFormat::Language),
..Default::default()
}),
max_length: Some(3usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("reply"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static("#replyRef"),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("tags"),
LexObjectProperty::Array(LexArray {
description: Some(
CowStr::new_static(
"Additional hashtags, in addition to any included in post text and facets.",
),
),
items: LexArrayItem::String(LexString {
max_length: Some(640usize),
max_graphemes: Some(64usize),
..Default::default()
}),
max_length: Some(8usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("text"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"The primary post content. May be an empty string, if there are embeds.",
),
),
max_length: Some(3000usize),
max_graphemes: Some(300usize),
..Default::default()
}),
);
map
},
..Default::default()
}),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("replyRef"),
LexUserType::Object(LexObject {
required: Some(
vec![SmolStr::new_static("root"), SmolStr::new_static("parent")],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("parent"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static("com.atproto.repo.strongRef"),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("root"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static("com.atproto.repo.strongRef"),
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map
},
..Default::default()
}
}
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 Root;
type Parent;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Root = Unset;
type Parent = Unset;
}
pub struct SetRoot<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetRoot<S> {}
impl<S: State> State for SetRoot<S> {
type Root = Set<members::root>;
type Parent = S::Parent;
}
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 Root = S::Root;
type Parent = Set<members::parent>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct root(());
pub struct parent(());
}
}
pub struct ReplyRefBuilder<'a, S: reply_ref_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (Option<StrongRef<'a>>, Option<StrongRef<'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, 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<StrongRef<'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::Root: reply_ref_state::IsUnset,
{
pub fn root(
mut self,
value: impl Into<StrongRef<'a>>,
) -> ReplyRefBuilder<'a, reply_ref_state::SetRoot<S>> {
self._fields.1 = 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::Root: reply_ref_state::IsSet,
S::Parent: reply_ref_state::IsSet,
{
pub fn build(self) -> ReplyRef<'a> {
ReplyRef {
parent: self._fields.0.unwrap(),
root: 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>,
>,
) -> ReplyRef<'a> {
ReplyRef {
parent: self._fields.0.unwrap(),
root: self._fields.1.unwrap(),
extra_data: Some(extra_data),
}
}
}