#[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};
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;
#[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",
rename = "net.anisota.lab.redaction",
tag = "$type",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Redaction<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub author: Option<S>,
pub created_at: Datetime,
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub original: Option<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub redacted: Option<Vec<i64>>,
pub source: AtUri<S>,
pub text: S,
#[serde(skip_serializing_if = "Option::is_none")]
pub word_count: Option<i64>,
#[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 RedactionGetRecordOutput<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub cid: Option<Cid<S>>,
pub uri: AtUri<S>,
pub value: Redaction<S>,
}
impl<S: BosStr> Redaction<S> {
pub fn uri(uri: S) -> Result<RecordUri<S, RedactionRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new(uri)?)
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct RedactionRecord;
impl XrpcResp for RedactionRecord {
const NSID: &'static str = "net.anisota.lab.redaction";
const ENCODING: &'static str = "application/json";
type Output<S: BosStr> = RedactionGetRecordOutput<S>;
type Err = RecordError;
}
impl<S: BosStr> From<RedactionGetRecordOutput<S>> for Redaction<S> {
fn from(output: RedactionGetRecordOutput<S>) -> Self {
output.value
}
}
impl<S: BosStr> Collection for Redaction<S> {
const NSID: &'static str = "net.anisota.lab.redaction";
type Record = RedactionRecord;
}
impl Collection for RedactionRecord {
const NSID: &'static str = "net.anisota.lab.redaction";
type Record = RedactionRecord;
}
impl<S: BosStr> LexiconSchema for Redaction<S> {
fn nsid() -> &'static str {
"net.anisota.lab.redaction"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_net_anisota_lab_redaction()
}
fn validate(&self) -> Result<(), ConstraintError> {
if let Some(ref value) = self.author {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 512usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("author"),
max: 512usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.name {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 800usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("name"),
max: 800usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.name {
{
let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
if count > 100usize {
return Err(ConstraintError::MaxGraphemes {
path: ValidationPath::from_field("name"),
max: 100usize,
actual: count,
});
}
}
}
if let Some(ref value) = self.original {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 12000usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("original"),
max: 12000usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.original {
{
let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
if count > 2000usize {
return Err(ConstraintError::MaxGraphemes {
path: ValidationPath::from_field("original"),
max: 2000usize,
actual: count,
});
}
}
}
if let Some(ref value) = self.redacted {
#[allow(unused_comparisons)]
if value.len() > 4096usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("redacted"),
max: 4096usize,
actual: value.len(),
});
}
}
{
let value = &self.text;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 6000usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("text"),
max: 6000usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.text;
{
let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
if count > 1000usize {
return Err(ConstraintError::MaxGraphemes {
path: ValidationPath::from_field("text"),
max: 1000usize,
actual: count,
});
}
}
}
Ok(())
}
}
pub mod redaction_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 CreatedAt;
type Source;
type Text;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type CreatedAt = Unset;
type Source = Unset;
type Text = Unset;
}
pub struct SetCreatedAt<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetCreatedAt<St> {}
impl<St: State> State for SetCreatedAt<St> {
type CreatedAt = Set<members::created_at>;
type Source = St::Source;
type Text = St::Text;
}
pub struct SetSource<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetSource<St> {}
impl<St: State> State for SetSource<St> {
type CreatedAt = St::CreatedAt;
type Source = Set<members::source>;
type Text = St::Text;
}
pub struct SetText<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetText<St> {}
impl<St: State> State for SetText<St> {
type CreatedAt = St::CreatedAt;
type Source = St::Source;
type Text = Set<members::text>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct created_at(());
pub struct source(());
pub struct text(());
}
}
pub struct RedactionBuilder<St: redaction_state::State, S: BosStr = DefaultStr> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<S>,
Option<Datetime>,
Option<S>,
Option<S>,
Option<Vec<i64>>,
Option<AtUri<S>>,
Option<S>,
Option<i64>,
),
_type: PhantomData<fn() -> S>,
}
impl Redaction<DefaultStr> {
pub fn new() -> RedactionBuilder<redaction_state::Empty, DefaultStr> {
RedactionBuilder::new()
}
}
impl<S: BosStr> Redaction<S> {
pub fn builder() -> RedactionBuilder<redaction_state::Empty, S> {
RedactionBuilder::builder()
}
}
impl RedactionBuilder<redaction_state::Empty, DefaultStr> {
pub fn new() -> Self {
RedactionBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr> RedactionBuilder<redaction_state::Empty, S> {
pub fn builder() -> Self {
RedactionBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None, None, None),
_type: PhantomData,
}
}
}
impl<St: redaction_state::State, S: BosStr> RedactionBuilder<St, S> {
pub fn author(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.0 = value.into();
self
}
pub fn maybe_author(mut self, value: Option<S>) -> Self {
self._fields.0 = value;
self
}
}
impl<St, S: BosStr> RedactionBuilder<St, S>
where
St: redaction_state::State,
St::CreatedAt: redaction_state::IsUnset,
{
pub fn created_at(
mut self,
value: impl Into<Datetime>,
) -> RedactionBuilder<redaction_state::SetCreatedAt<St>, S> {
self._fields.1 = Option::Some(value.into());
RedactionBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<St: redaction_state::State, S: BosStr> RedactionBuilder<St, S> {
pub fn name(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.2 = value.into();
self
}
pub fn maybe_name(mut self, value: Option<S>) -> Self {
self._fields.2 = value;
self
}
}
impl<St: redaction_state::State, S: BosStr> RedactionBuilder<St, S> {
pub fn original(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.3 = value.into();
self
}
pub fn maybe_original(mut self, value: Option<S>) -> Self {
self._fields.3 = value;
self
}
}
impl<St: redaction_state::State, S: BosStr> RedactionBuilder<St, S> {
pub fn redacted(mut self, value: impl Into<Option<Vec<i64>>>) -> Self {
self._fields.4 = value.into();
self
}
pub fn maybe_redacted(mut self, value: Option<Vec<i64>>) -> Self {
self._fields.4 = value;
self
}
}
impl<St, S: BosStr> RedactionBuilder<St, S>
where
St: redaction_state::State,
St::Source: redaction_state::IsUnset,
{
pub fn source(
mut self,
value: impl Into<AtUri<S>>,
) -> RedactionBuilder<redaction_state::SetSource<St>, S> {
self._fields.5 = Option::Some(value.into());
RedactionBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<St, S: BosStr> RedactionBuilder<St, S>
where
St: redaction_state::State,
St::Text: redaction_state::IsUnset,
{
pub fn text(
mut self,
value: impl Into<S>,
) -> RedactionBuilder<redaction_state::SetText<St>, S> {
self._fields.6 = Option::Some(value.into());
RedactionBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<St: redaction_state::State, S: BosStr> RedactionBuilder<St, S> {
pub fn word_count(mut self, value: impl Into<Option<i64>>) -> Self {
self._fields.7 = value.into();
self
}
pub fn maybe_word_count(mut self, value: Option<i64>) -> Self {
self._fields.7 = value;
self
}
}
impl<St, S: BosStr> RedactionBuilder<St, S>
where
St: redaction_state::State,
St::CreatedAt: redaction_state::IsSet,
St::Source: redaction_state::IsSet,
St::Text: redaction_state::IsSet,
{
pub fn build(self) -> Redaction<S> {
Redaction {
author: self._fields.0,
created_at: self._fields.1.unwrap(),
name: self._fields.2,
original: self._fields.3,
redacted: self._fields.4,
source: self._fields.5.unwrap(),
text: self._fields.6.unwrap(),
word_count: self._fields.7,
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Redaction<S> {
Redaction {
author: self._fields.0,
created_at: self._fields.1.unwrap(),
name: self._fields.2,
original: self._fields.3,
redacted: self._fields.4,
source: self._fields.5.unwrap(),
text: self._fields.6.unwrap(),
word_count: self._fields.7,
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_net_anisota_lab_redaction() -> 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("net.anisota.lab.redaction"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("main"),
LexUserType::Record(LexRecord {
description: Some(
CowStr::new_static(
"A redaction (erasure poetry) piece made in the Anisota Lab's Post Redaction Art studio, where the words of an existing post are blacked out one at a time and the words left standing become a found poem. The record keeps the surviving text, the indices of the words that were redacted (so the piece can be reopened over the same post), and an at-uri pointing back at the post the words were drawn from.",
),
),
key: Some(CowStr::new_static("any")),
record: LexRecordRecord::Object(LexObject {
required: Some(
vec![
SmolStr::new_static("source"), SmolStr::new_static("text"),
SmolStr::new_static("createdAt")
],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("author"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"The handle or DID of the source post's author, kept for display and so the backlink reads even if the source can't be re-fetched",
),
),
max_length: Some(512usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("createdAt"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("When the piece was saved"),
),
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("name"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("Optional title for the piece"),
),
max_length: Some(800usize),
max_graphemes: Some(100usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("original"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"A snapshot of the source post's full text, so the piece can still be read if the source post is later deleted or edited",
),
),
max_length: Some(12000usize),
max_graphemes: Some(2000usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("redacted"),
LexObjectProperty::Array(LexArray {
description: Some(
CowStr::new_static(
"Zero-based indices of the word tokens that were blacked out, so the arrangement can be reopened over the same post text",
),
),
items: LexArrayItem::Integer(LexInteger {
..Default::default()
}),
max_length: Some(4096usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("source"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"at-uri of the post whose words were redacted — the piece backlinks to it",
),
),
format: Some(LexStringFormat::AtUri),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("text"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"The found poem — the words left un-redacted, in reading order",
),
),
max_length: Some(6000usize),
max_graphemes: Some(1000usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("wordCount"),
LexObjectProperty::Integer(LexInteger {
..Default::default()
}),
);
map
},
..Default::default()
}),
..Default::default()
}),
);
map
},
..Default::default()
}
}