#[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.poetry",
tag = "$type",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Poetry<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub board: Option<Data<S>>,
pub created_at: Datetime,
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub sources: Option<Vec<AtUri<S>>>,
pub text: S,
#[serde(skip_serializing_if = "Option::is_none")]
pub tiles: Option<Vec<Data<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 PoetryGetRecordOutput<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub cid: Option<Cid<S>>,
pub uri: AtUri<S>,
pub value: Poetry<S>,
}
impl<S: BosStr> Poetry<S> {
pub fn uri(uri: S) -> Result<RecordUri<S, PoetryRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new(uri)?)
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct PoetryRecord;
impl XrpcResp for PoetryRecord {
const NSID: &'static str = "net.anisota.lab.poetry";
const ENCODING: &'static str = "application/json";
type Output<S: BosStr> = PoetryGetRecordOutput<S>;
type Err = RecordError;
}
impl<S: BosStr> From<PoetryGetRecordOutput<S>> for Poetry<S> {
fn from(output: PoetryGetRecordOutput<S>) -> Self {
output.value
}
}
impl<S: BosStr> Collection for Poetry<S> {
const NSID: &'static str = "net.anisota.lab.poetry";
type Record = PoetryRecord;
}
impl Collection for PoetryRecord {
const NSID: &'static str = "net.anisota.lab.poetry";
type Record = PoetryRecord;
}
impl<S: BosStr> LexiconSchema for Poetry<S> {
fn nsid() -> &'static str {
"net.anisota.lab.poetry"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_net_anisota_lab_poetry()
}
fn validate(&self) -> Result<(), ConstraintError> {
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.sources {
#[allow(unused_comparisons)]
if value.len() > 512usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("sources"),
max: 512usize,
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,
});
}
}
}
if let Some(ref value) = self.tiles {
#[allow(unused_comparisons)]
if value.len() > 512usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("tiles"),
max: 512usize,
actual: value.len(),
});
}
}
Ok(())
}
}
pub mod poetry_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 Text;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type CreatedAt = 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 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 Text = Set<members::text>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct created_at(());
pub struct text(());
}
}
pub struct PoetryBuilder<St: poetry_state::State, S: BosStr = DefaultStr> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<Data<S>>,
Option<Datetime>,
Option<S>,
Option<Vec<AtUri<S>>>,
Option<S>,
Option<Vec<Data<S>>>,
),
_type: PhantomData<fn() -> S>,
}
impl Poetry<DefaultStr> {
pub fn new() -> PoetryBuilder<poetry_state::Empty, DefaultStr> {
PoetryBuilder::new()
}
}
impl<S: BosStr> Poetry<S> {
pub fn builder() -> PoetryBuilder<poetry_state::Empty, S> {
PoetryBuilder::builder()
}
}
impl PoetryBuilder<poetry_state::Empty, DefaultStr> {
pub fn new() -> Self {
PoetryBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr> PoetryBuilder<poetry_state::Empty, S> {
pub fn builder() -> Self {
PoetryBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None),
_type: PhantomData,
}
}
}
impl<St: poetry_state::State, S: BosStr> PoetryBuilder<St, S> {
pub fn board(mut self, value: impl Into<Option<Data<S>>>) -> Self {
self._fields.0 = value.into();
self
}
pub fn maybe_board(mut self, value: Option<Data<S>>) -> Self {
self._fields.0 = value;
self
}
}
impl<St, S: BosStr> PoetryBuilder<St, S>
where
St: poetry_state::State,
St::CreatedAt: poetry_state::IsUnset,
{
pub fn created_at(
mut self,
value: impl Into<Datetime>,
) -> PoetryBuilder<poetry_state::SetCreatedAt<St>, S> {
self._fields.1 = Option::Some(value.into());
PoetryBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<St: poetry_state::State, S: BosStr> PoetryBuilder<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: poetry_state::State, S: BosStr> PoetryBuilder<St, S> {
pub fn sources(mut self, value: impl Into<Option<Vec<AtUri<S>>>>) -> Self {
self._fields.3 = value.into();
self
}
pub fn maybe_sources(mut self, value: Option<Vec<AtUri<S>>>) -> Self {
self._fields.3 = value;
self
}
}
impl<St, S: BosStr> PoetryBuilder<St, S>
where
St: poetry_state::State,
St::Text: poetry_state::IsUnset,
{
pub fn text(mut self, value: impl Into<S>) -> PoetryBuilder<poetry_state::SetText<St>, S> {
self._fields.4 = Option::Some(value.into());
PoetryBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<St: poetry_state::State, S: BosStr> PoetryBuilder<St, S> {
pub fn tiles(mut self, value: impl Into<Option<Vec<Data<S>>>>) -> Self {
self._fields.5 = value.into();
self
}
pub fn maybe_tiles(mut self, value: Option<Vec<Data<S>>>) -> Self {
self._fields.5 = value;
self
}
}
impl<St, S: BosStr> PoetryBuilder<St, S>
where
St: poetry_state::State,
St::CreatedAt: poetry_state::IsSet,
St::Text: poetry_state::IsSet,
{
pub fn build(self) -> Poetry<S> {
Poetry {
board: self._fields.0,
created_at: self._fields.1.unwrap(),
name: self._fields.2,
sources: self._fields.3,
text: self._fields.4.unwrap(),
tiles: self._fields.5,
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Poetry<S> {
Poetry {
board: self._fields.0,
created_at: self._fields.1.unwrap(),
name: self._fields.2,
sources: self._fields.3,
text: self._fields.4.unwrap(),
tiles: self._fields.5,
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_net_anisota_lab_poetry() -> 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.poetry"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("main"),
LexUserType::Record(LexRecord {
description: Some(
CowStr::new_static(
"A fridge-poetry composition made in the Anisota Lab's Word Magnets studio, where word tiles drawn from the author's own recent posts are arranged on a field into a short poem. The record keeps the assembled text, the placed tiles with their positions (so the arrangement can be reopened), and at-uri references to the posts the used words were drawn from.",
),
),
key: Some(CowStr::new_static("any")),
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("board"),
LexObjectProperty::Unknown(LexUnknown {
..Default::default()
}),
);
map.insert(
SmolStr::new_static("createdAt"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("When the poem 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 poem"),
),
max_length: Some(800usize),
max_graphemes: Some(100usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("sources"),
LexObjectProperty::Array(LexArray {
description: Some(
CowStr::new_static(
"at-uri references to the author's own posts that the used words were drawn from",
),
),
items: LexArrayItem::String(LexString {
format: Some(LexStringFormat::AtUri),
..Default::default()
}),
max_length: Some(512usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("text"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"The assembled poem — the placed word tiles read top-to-bottom, left-to-right",
),
),
max_length: Some(6000usize),
max_graphemes: Some(1000usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("tiles"),
LexObjectProperty::Array(LexArray {
description: Some(
CowStr::new_static(
"The placed word tiles and their positions, so the arrangement can be reopened. Each is an object: { word, fragment, x, y, rot } where x/y are the tile centre as a 0..1000 fraction of the field and rot is degrees.",
),
),
items: LexArrayItem::Unknown(LexUnknown {
..Default::default()
}),
max_length: Some(512usize),
..Default::default()
}),
);
map
},
..Default::default()
}),
..Default::default()
}),
);
map
},
..Default::default()
}
}