#[allow(unused_imports)]
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::{BosStr, DefaultStr, FromStaticStr};
#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::deps::smol_str::SmolStr;
use jacquard_common::types::string::{AtUri, RecordKey, Rkey};
use jacquard_common::types::value::Data;
use jacquard_derive::IntoStatic;
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",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Indexable<S: BosStr = DefaultStr> {
pub id: RecordKey<Rkey<S>>,
pub index: i64,
pub name: 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, Default)]
#[serde(
rename_all = "camelCase",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct TypedRef<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub r#ref: Option<AtUri<S>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub r#type: Option<RecordKey<Rkey<S>>>,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
impl<S: BosStr> LexiconSchema for Indexable<S> {
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<S: BosStr> LexiconSchema for TypedRef<S> {
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::{IsSet, IsUnset, Set, Unset};
#[allow(unused)]
use ::core::marker::PhantomData;
mod sealed {
pub trait Sealed {}
}
pub trait State: sealed::Sealed {
type Name;
type Index;
type Id;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Name = Unset;
type Index = Unset;
type Id = Unset;
}
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 Name = Set<members::name>;
type Index = St::Index;
type Id = St::Id;
}
pub struct SetIndex<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetIndex<St> {}
impl<St: State> State for SetIndex<St> {
type Name = St::Name;
type Index = Set<members::index>;
type Id = St::Id;
}
pub struct SetId<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetId<St> {}
impl<St: State> State for SetId<St> {
type Name = St::Name;
type Index = St::Index;
type Id = Set<members::id>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct name(());
pub struct index(());
pub struct id(());
}
}
pub struct IndexableBuilder<S: BosStr, St: indexable_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (Option<RecordKey<Rkey<S>>>, Option<i64>, Option<Data<S>>),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> Indexable<S> {
pub fn new() -> IndexableBuilder<S, indexable_state::Empty> {
IndexableBuilder::new()
}
}
impl<S: BosStr> IndexableBuilder<S, indexable_state::Empty> {
pub fn new() -> Self {
IndexableBuilder {
_state: PhantomData,
_fields: (None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St> IndexableBuilder<S, St>
where
St: indexable_state::State,
St::Id: indexable_state::IsUnset,
{
pub fn id(
mut self,
value: impl Into<RecordKey<Rkey<S>>>,
) -> IndexableBuilder<S, indexable_state::SetId<St>> {
self._fields.0 = Option::Some(value.into());
IndexableBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> IndexableBuilder<S, St>
where
St: indexable_state::State,
St::Index: indexable_state::IsUnset,
{
pub fn index(
mut self,
value: impl Into<i64>,
) -> IndexableBuilder<S, indexable_state::SetIndex<St>> {
self._fields.1 = Option::Some(value.into());
IndexableBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> IndexableBuilder<S, St>
where
St: indexable_state::State,
St::Name: indexable_state::IsUnset,
{
pub fn name(
mut self,
value: impl Into<Data<S>>,
) -> IndexableBuilder<S, indexable_state::SetName<St>> {
self._fields.2 = Option::Some(value.into());
IndexableBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> IndexableBuilder<S, St>
where
St: indexable_state::State,
St::Name: indexable_state::IsSet,
St::Index: indexable_state::IsSet,
St::Id: indexable_state::IsSet,
{
pub fn build(self) -> Indexable<S> {
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<SmolStr, Data<S>>) -> Indexable<S> {
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> {
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("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()
}
}