#[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.sigil",
tag = "$type",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Sigil<S: BosStr = DefaultStr> {
pub created_at: Datetime,
#[serde(skip_serializing_if = "Option::is_none")]
pub meta: Option<Data<S>>,
pub method: S,
pub name: S,
#[serde(skip_serializing_if = "Option::is_none")]
pub points: Option<Vec<i64>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub svg: Option<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 SigilGetRecordOutput<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub cid: Option<Cid<S>>,
pub uri: AtUri<S>,
pub value: Sigil<S>,
}
impl<S: BosStr> Sigil<S> {
pub fn uri(uri: S) -> Result<RecordUri<S, SigilRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new(uri)?)
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct SigilRecord;
impl XrpcResp for SigilRecord {
const NSID: &'static str = "net.anisota.lab.sigil";
const ENCODING: &'static str = "application/json";
type Output<S: BosStr> = SigilGetRecordOutput<S>;
type Err = RecordError;
}
impl<S: BosStr> From<SigilGetRecordOutput<S>> for Sigil<S> {
fn from(output: SigilGetRecordOutput<S>) -> Self {
output.value
}
}
impl<S: BosStr> Collection for Sigil<S> {
const NSID: &'static str = "net.anisota.lab.sigil";
type Record = SigilRecord;
}
impl Collection for SigilRecord {
const NSID: &'static str = "net.anisota.lab.sigil";
type Record = SigilRecord;
}
impl<S: BosStr> LexiconSchema for Sigil<S> {
fn nsid() -> &'static str {
"net.anisota.lab.sigil"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_net_anisota_lab_sigil()
}
fn validate(&self) -> Result<(), ConstraintError> {
{
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,
});
}
}
}
if let Some(ref value) = self.points {
#[allow(unused_comparisons)]
if value.len() > 4096usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("points"),
max: 4096usize,
actual: value.len(),
});
}
}
if let Some(ref value) = self.svg {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 60000usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("svg"),
max: 60000usize,
actual: <str>::len(value.as_ref()),
});
}
}
Ok(())
}
}
pub mod sigil_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 Method;
type Name;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type CreatedAt = Unset;
type Method = Unset;
type Name = 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 Method = St::Method;
type Name = St::Name;
}
pub struct SetMethod<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetMethod<St> {}
impl<St: State> State for SetMethod<St> {
type CreatedAt = St::CreatedAt;
type Method = Set<members::method>;
type Name = St::Name;
}
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 Method = St::Method;
type Name = Set<members::name>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct created_at(());
pub struct method(());
pub struct name(());
}
}
pub struct SigilBuilder<St: sigil_state::State, S: BosStr = DefaultStr> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<Datetime>,
Option<Data<S>>,
Option<S>,
Option<S>,
Option<Vec<i64>>,
Option<S>,
),
_type: PhantomData<fn() -> S>,
}
impl Sigil<DefaultStr> {
pub fn new() -> SigilBuilder<sigil_state::Empty, DefaultStr> {
SigilBuilder::new()
}
}
impl<S: BosStr> Sigil<S> {
pub fn builder() -> SigilBuilder<sigil_state::Empty, S> {
SigilBuilder::builder()
}
}
impl SigilBuilder<sigil_state::Empty, DefaultStr> {
pub fn new() -> Self {
SigilBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr> SigilBuilder<sigil_state::Empty, S> {
pub fn builder() -> Self {
SigilBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None),
_type: PhantomData,
}
}
}
impl<St, S: BosStr> SigilBuilder<St, S>
where
St: sigil_state::State,
St::CreatedAt: sigil_state::IsUnset,
{
pub fn created_at(
mut self,
value: impl Into<Datetime>,
) -> SigilBuilder<sigil_state::SetCreatedAt<St>, S> {
self._fields.0 = Option::Some(value.into());
SigilBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<St: sigil_state::State, S: BosStr> SigilBuilder<St, S> {
pub fn meta(mut self, value: impl Into<Option<Data<S>>>) -> Self {
self._fields.1 = value.into();
self
}
pub fn maybe_meta(mut self, value: Option<Data<S>>) -> Self {
self._fields.1 = value;
self
}
}
impl<St, S: BosStr> SigilBuilder<St, S>
where
St: sigil_state::State,
St::Method: sigil_state::IsUnset,
{
pub fn method(mut self, value: impl Into<S>) -> SigilBuilder<sigil_state::SetMethod<St>, S> {
self._fields.2 = Option::Some(value.into());
SigilBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<St, S: BosStr> SigilBuilder<St, S>
where
St: sigil_state::State,
St::Name: sigil_state::IsUnset,
{
pub fn name(mut self, value: impl Into<S>) -> SigilBuilder<sigil_state::SetName<St>, S> {
self._fields.3 = Option::Some(value.into());
SigilBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<St: sigil_state::State, S: BosStr> SigilBuilder<St, S> {
pub fn points(mut self, value: impl Into<Option<Vec<i64>>>) -> Self {
self._fields.4 = value.into();
self
}
pub fn maybe_points(mut self, value: Option<Vec<i64>>) -> Self {
self._fields.4 = value;
self
}
}
impl<St: sigil_state::State, S: BosStr> SigilBuilder<St, S> {
pub fn svg(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.5 = value.into();
self
}
pub fn maybe_svg(mut self, value: Option<S>) -> Self {
self._fields.5 = value;
self
}
}
impl<St, S: BosStr> SigilBuilder<St, S>
where
St: sigil_state::State,
St::CreatedAt: sigil_state::IsSet,
St::Method: sigil_state::IsSet,
St::Name: sigil_state::IsSet,
{
pub fn build(self) -> Sigil<S> {
Sigil {
created_at: self._fields.0.unwrap(),
meta: self._fields.1,
method: self._fields.2.unwrap(),
name: self._fields.3.unwrap(),
points: self._fields.4,
svg: self._fields.5,
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Sigil<S> {
Sigil {
created_at: self._fields.0.unwrap(),
meta: self._fields.1,
method: self._fields.2.unwrap(),
name: self._fields.3.unwrap(),
points: self._fields.4,
svg: self._fields.5,
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_net_anisota_lab_sigil() -> 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.sigil"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("main"),
LexUserType::Record(LexRecord {
description: Some(
CowStr::new_static(
"A sigil crafted in the Anisota Lab's Sigil studio and saved to the owner's library. Each record stores the finished figure as a standalone SVG (for display and re-export) and its normalised 'core path' as integer coordinates (x and y interleaved, scaled 0..1000) — the single line a sigil is, and the shape a future gesture-passcode could be matched against. 'method' records which bench made it (intent, square, wheel or draw).",
),
),
key: Some(CowStr::new_static("any")),
record: LexRecordRecord::Object(LexObject {
required: Some(
vec![
SmolStr::new_static("name"), SmolStr::new_static("method"),
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 sigil was saved"),
),
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("meta"),
LexObjectProperty::Unknown(LexUnknown {
..Default::default()
}),
);
map.insert(
SmolStr::new_static("method"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("Which crafting method produced it"),
),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("name"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("Display name for the sigil"),
),
max_length: Some(800usize),
max_graphemes: Some(100usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("points"),
LexObjectProperty::Array(LexArray {
description: Some(
CowStr::new_static(
"The normalised core path: x and y interleaved, each scaled to 0..1000",
),
),
items: LexArrayItem::Integer(LexInteger {
..Default::default()
}),
max_length: Some(4096usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("svg"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"A standalone SVG document of the finished figure",
),
),
max_length: Some(60000usize),
..Default::default()
}),
);
map
},
..Default::default()
}),
..Default::default()
}),
);
map
},
..Default::default()
}
}