#[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.carving",
tag = "$type",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Carving<S: BosStr = DefaultStr> {
pub created_at: Datetime,
#[serde(skip_serializing_if = "Option::is_none")]
pub image: Option<S>,
pub ink_color: S,
#[serde(skip_serializing_if = "Option::is_none")]
pub mirror: Option<bool>,
pub name: S,
pub paper_color: S,
pub strokes: 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 CarvingGetRecordOutput<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub cid: Option<Cid<S>>,
pub uri: AtUri<S>,
pub value: Carving<S>,
}
impl<S: BosStr> Carving<S> {
pub fn uri(uri: S) -> Result<RecordUri<S, CarvingRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new(uri)?)
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct CarvingRecord;
impl XrpcResp for CarvingRecord {
const NSID: &'static str = "net.anisota.lab.carving";
const ENCODING: &'static str = "application/json";
type Output<S: BosStr> = CarvingGetRecordOutput<S>;
type Err = RecordError;
}
impl<S: BosStr> From<CarvingGetRecordOutput<S>> for Carving<S> {
fn from(output: CarvingGetRecordOutput<S>) -> Self {
output.value
}
}
impl<S: BosStr> Collection for Carving<S> {
const NSID: &'static str = "net.anisota.lab.carving";
type Record = CarvingRecord;
}
impl Collection for CarvingRecord {
const NSID: &'static str = "net.anisota.lab.carving";
type Record = CarvingRecord;
}
impl<S: BosStr> LexiconSchema for Carving<S> {
fn nsid() -> &'static str {
"net.anisota.lab.carving"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_net_anisota_lab_carving()
}
fn validate(&self) -> Result<(), ConstraintError> {
if let Some(ref value) = self.image {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 200000usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("image"),
max: 200000usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.ink_color;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 64usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("ink_color"),
max: 64usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let 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()),
});
}
}
{
let 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,
});
}
}
}
{
let value = &self.paper_color;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 64usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("paper_color"),
max: 64usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.strokes;
#[allow(unused_comparisons)]
if value.len() > 4096usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("strokes"),
max: 4096usize,
actual: value.len(),
});
}
}
Ok(())
}
}
pub mod carving_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 InkColor;
type Name;
type PaperColor;
type Strokes;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type CreatedAt = Unset;
type InkColor = Unset;
type Name = Unset;
type PaperColor = Unset;
type Strokes = 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 InkColor = St::InkColor;
type Name = St::Name;
type PaperColor = St::PaperColor;
type Strokes = St::Strokes;
}
pub struct SetInkColor<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetInkColor<St> {}
impl<St: State> State for SetInkColor<St> {
type CreatedAt = St::CreatedAt;
type InkColor = Set<members::ink_color>;
type Name = St::Name;
type PaperColor = St::PaperColor;
type Strokes = St::Strokes;
}
pub struct SetName<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetName<St> {}
impl<St: State> State for SetName<St> {
type CreatedAt = St::CreatedAt;
type InkColor = St::InkColor;
type Name = Set<members::name>;
type PaperColor = St::PaperColor;
type Strokes = St::Strokes;
}
pub struct SetPaperColor<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetPaperColor<St> {}
impl<St: State> State for SetPaperColor<St> {
type CreatedAt = St::CreatedAt;
type InkColor = St::InkColor;
type Name = St::Name;
type PaperColor = Set<members::paper_color>;
type Strokes = St::Strokes;
}
pub struct SetStrokes<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetStrokes<St> {}
impl<St: State> State for SetStrokes<St> {
type CreatedAt = St::CreatedAt;
type InkColor = St::InkColor;
type Name = St::Name;
type PaperColor = St::PaperColor;
type Strokes = Set<members::strokes>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct created_at(());
pub struct ink_color(());
pub struct name(());
pub struct paper_color(());
pub struct strokes(());
}
}
pub struct CarvingBuilder<St: carving_state::State, S: BosStr = DefaultStr> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<Datetime>,
Option<S>,
Option<S>,
Option<bool>,
Option<S>,
Option<S>,
Option<Vec<Data<S>>>,
),
_type: PhantomData<fn() -> S>,
}
impl Carving<DefaultStr> {
pub fn new() -> CarvingBuilder<carving_state::Empty, DefaultStr> {
CarvingBuilder::new()
}
}
impl<S: BosStr> Carving<S> {
pub fn builder() -> CarvingBuilder<carving_state::Empty, S> {
CarvingBuilder::builder()
}
}
impl CarvingBuilder<carving_state::Empty, DefaultStr> {
pub fn new() -> Self {
CarvingBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr> CarvingBuilder<carving_state::Empty, S> {
pub fn builder() -> Self {
CarvingBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None, None),
_type: PhantomData,
}
}
}
impl<St, S: BosStr> CarvingBuilder<St, S>
where
St: carving_state::State,
St::CreatedAt: carving_state::IsUnset,
{
pub fn created_at(
mut self,
value: impl Into<Datetime>,
) -> CarvingBuilder<carving_state::SetCreatedAt<St>, S> {
self._fields.0 = Option::Some(value.into());
CarvingBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<St: carving_state::State, S: BosStr> CarvingBuilder<St, S> {
pub fn image(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.1 = value.into();
self
}
pub fn maybe_image(mut self, value: Option<S>) -> Self {
self._fields.1 = value;
self
}
}
impl<St, S: BosStr> CarvingBuilder<St, S>
where
St: carving_state::State,
St::InkColor: carving_state::IsUnset,
{
pub fn ink_color(
mut self,
value: impl Into<S>,
) -> CarvingBuilder<carving_state::SetInkColor<St>, S> {
self._fields.2 = Option::Some(value.into());
CarvingBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<St: carving_state::State, S: BosStr> CarvingBuilder<St, S> {
pub fn mirror(mut self, value: impl Into<Option<bool>>) -> Self {
self._fields.3 = value.into();
self
}
pub fn maybe_mirror(mut self, value: Option<bool>) -> Self {
self._fields.3 = value;
self
}
}
impl<St, S: BosStr> CarvingBuilder<St, S>
where
St: carving_state::State,
St::Name: carving_state::IsUnset,
{
pub fn name(mut self, value: impl Into<S>) -> CarvingBuilder<carving_state::SetName<St>, S> {
self._fields.4 = Option::Some(value.into());
CarvingBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<St, S: BosStr> CarvingBuilder<St, S>
where
St: carving_state::State,
St::PaperColor: carving_state::IsUnset,
{
pub fn paper_color(
mut self,
value: impl Into<S>,
) -> CarvingBuilder<carving_state::SetPaperColor<St>, S> {
self._fields.5 = Option::Some(value.into());
CarvingBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<St, S: BosStr> CarvingBuilder<St, S>
where
St: carving_state::State,
St::Strokes: carving_state::IsUnset,
{
pub fn strokes(
mut self,
value: impl Into<Vec<Data<S>>>,
) -> CarvingBuilder<carving_state::SetStrokes<St>, S> {
self._fields.6 = Option::Some(value.into());
CarvingBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<St, S: BosStr> CarvingBuilder<St, S>
where
St: carving_state::State,
St::CreatedAt: carving_state::IsSet,
St::InkColor: carving_state::IsSet,
St::Name: carving_state::IsSet,
St::PaperColor: carving_state::IsSet,
St::Strokes: carving_state::IsSet,
{
pub fn build(self) -> Carving<S> {
Carving {
created_at: self._fields.0.unwrap(),
image: self._fields.1,
ink_color: self._fields.2.unwrap(),
mirror: self._fields.3,
name: self._fields.4.unwrap(),
paper_color: self._fields.5.unwrap(),
strokes: self._fields.6.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Carving<S> {
Carving {
created_at: self._fields.0.unwrap(),
image: self._fields.1,
ink_color: self._fields.2.unwrap(),
mirror: self._fields.3,
name: self._fields.4.unwrap(),
paper_color: self._fields.5.unwrap(),
strokes: self._fields.6.unwrap(),
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_net_anisota_lab_carving() -> 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.carving"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("main"),
LexUserType::Record(LexRecord {
description: Some(
CowStr::new_static(
"A relief woodblock carving made in the Anisota Lab's Carving studio and saved to the owner's library. Each record stores the gouge paths that carved the block (a compact serialization so the carving can be reopened and edited), the chosen ink and paper colours, whether vertical mirror/symmetry was on, and an optional printed-result PNG thumbnail for display and re-export.",
),
),
key: Some(CowStr::new_static("any")),
record: LexRecordRecord::Object(LexObject {
required: Some(
vec![
SmolStr::new_static("name"), SmolStr::new_static("strokes"),
SmolStr::new_static("inkColor"),
SmolStr::new_static("paperColor"),
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("When the carving was saved"),
),
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("image"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"A PNG data URL thumbnail of the printed result",
),
),
max_length: Some(200000usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("inkColor"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("The ink colour the block prints in"),
),
max_length: Some(64usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("mirror"),
LexObjectProperty::Boolean(LexBoolean {
..Default::default()
}),
);
map.insert(
SmolStr::new_static("name"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("Display name for the carving"),
),
max_length: Some(800usize),
max_graphemes: Some(100usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("paperColor"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("The paper colour the print sits on"),
),
max_length: Some(64usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("strokes"),
LexObjectProperty::Array(LexArray {
description: Some(
CowStr::new_static(
"The gouge paths. Each is an object: { tool, width, points (x and y interleaved, scaled 0..1000), erase }.",
),
),
items: LexArrayItem::Unknown(LexUnknown {
..Default::default()
}),
max_length: Some(4096usize),
..Default::default()
}),
);
map
},
..Default::default()
}),
..Default::default()
}),
);
map
},
..Default::default()
}
}