#[allow(unused_imports)]
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use core::marker::PhantomData;
#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::types::string::{AtUri, RecordKey, Rkey};
use jacquard_common::types::value::Data;
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::{Serialize, Deserialize};
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Indexable<'a> {
#[serde(borrow)]
pub id: RecordKey<Rkey<'a>>,
pub index: i64,
#[serde(borrow)]
pub name: Data<'a>,
}
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase")]
pub struct TypedRef<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub r#ref: Option<AtUri<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub r#type: Option<RecordKey<Rkey<'a>>>,
}
impl<'a> LexiconSchema for Indexable<'a> {
fn nsid() -> &'static str {
"dev.tsunagite.types"
}
fn def_name() -> &'static str {
"indexable"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_dev_tsunagite_types()
}
fn validate(&self) -> Result<(), ConstraintError> {
{
let value = &self.id;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 32usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("id"),
max: 32usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.id;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) < 1usize {
return Err(ConstraintError::MinLength {
path: ValidationPath::from_field("id"),
min: 1usize,
actual: <str>::len(value.as_ref()),
});
}
}
Ok(())
}
}
impl<'a> LexiconSchema for TypedRef<'a> {
fn nsid() -> &'static str {
"dev.tsunagite.types"
}
fn def_name() -> &'static str {
"typedRef"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_dev_tsunagite_types()
}
fn validate(&self) -> Result<(), ConstraintError> {
Ok(())
}
}
pub mod indexable_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 Index;
type Id;
type Name;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Index = Unset;
type Id = Unset;
type Name = Unset;
}
pub struct SetIndex<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetIndex<S> {}
impl<S: State> State for SetIndex<S> {
type Index = Set<members::index>;
type Id = S::Id;
type Name = S::Name;
}
pub struct SetId<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetId<S> {}
impl<S: State> State for SetId<S> {
type Index = S::Index;
type Id = Set<members::id>;
type Name = S::Name;
}
pub struct SetName<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetName<S> {}
impl<S: State> State for SetName<S> {
type Index = S::Index;
type Id = S::Id;
type Name = Set<members::name>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct index(());
pub struct id(());
pub struct name(());
}
}
pub struct IndexableBuilder<'a, S: indexable_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (Option<RecordKey<Rkey<'a>>>, Option<i64>, Option<Data<'a>>),
_lifetime: PhantomData<&'a ()>,
}
impl<'a> Indexable<'a> {
pub fn new() -> IndexableBuilder<'a, indexable_state::Empty> {
IndexableBuilder::new()
}
}
impl<'a> IndexableBuilder<'a, indexable_state::Empty> {
pub fn new() -> Self {
IndexableBuilder {
_state: PhantomData,
_fields: (None, None, None),
_lifetime: PhantomData,
}
}
}
impl<'a, S> IndexableBuilder<'a, S>
where
S: indexable_state::State,
S::Id: indexable_state::IsUnset,
{
pub fn id(
mut self,
value: impl Into<RecordKey<Rkey<'a>>>,
) -> IndexableBuilder<'a, indexable_state::SetId<S>> {
self._fields.0 = Option::Some(value.into());
IndexableBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> IndexableBuilder<'a, S>
where
S: indexable_state::State,
S::Index: indexable_state::IsUnset,
{
pub fn index(
mut self,
value: impl Into<i64>,
) -> IndexableBuilder<'a, indexable_state::SetIndex<S>> {
self._fields.1 = Option::Some(value.into());
IndexableBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> IndexableBuilder<'a, S>
where
S: indexable_state::State,
S::Name: indexable_state::IsUnset,
{
pub fn name(
mut self,
value: impl Into<Data<'a>>,
) -> IndexableBuilder<'a, indexable_state::SetName<S>> {
self._fields.2 = Option::Some(value.into());
IndexableBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> IndexableBuilder<'a, S>
where
S: indexable_state::State,
S::Index: indexable_state::IsSet,
S::Id: indexable_state::IsSet,
S::Name: indexable_state::IsSet,
{
pub fn build(self) -> Indexable<'a> {
Indexable {
id: self._fields.0.unwrap(),
index: self._fields.1.unwrap(),
name: self._fields.2.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(
self,
extra_data: BTreeMap<jacquard_common::deps::smol_str::SmolStr, Data<'a>>,
) -> Indexable<'a> {
Indexable {
id: self._fields.0.unwrap(),
index: self._fields.1.unwrap(),
name: self._fields.2.unwrap(),
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_dev_tsunagite_types() -> 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("dev.tsunagite.types"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("indexable"),
LexUserType::Object(LexObject {
description: Some(
CowStr::new_static(
"A named value with a numeric index for sorting.",
),
),
required: Some(
vec![
SmolStr::new_static("id"), SmolStr::new_static("name"),
SmolStr::new_static("index")
],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("id"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"The internal ID for the value, limited to the RecordKey character set.",
),
),
format: Some(LexStringFormat::RecordKey),
min_length: Some(1usize),
max_length: Some(32usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("index"),
LexObjectProperty::Integer(LexInteger {
..Default::default()
}),
);
map.insert(
SmolStr::new_static("name"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static("dev.tsunagite.translatable"),
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map.insert(
SmolStr::new_static("typedRef"),
LexUserType::Object(LexObject {
description: Some(
CowStr::new_static(
"A typed record reference that does not require a CID hash.",
),
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("ref"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"The AT URI of the record this object references.",
),
),
format: Some(LexStringFormat::AtUri),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("type"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"The type of the record this object references.",
),
),
format: Some(LexStringFormat::RecordKey),
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map
},
..Default::default()
}
}