#[allow(unused_imports)]
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::{CowStr, 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::collection::{Collection, RecordError};
use jacquard_common::types::string::{AtUri, Nsid, Cid, Datetime, Language};
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::{Serialize, Deserialize};
use crate::garden_lexicon::documentation;
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct DefinitionDoc<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<Vec<documentation::LocalizedString<S>>>,
pub name: S,
#[serde(skip_serializing_if = "Option::is_none")]
pub properties: Option<Vec<documentation::PropertyDoc<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", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct LocalizedString<S: BosStr = DefaultStr> {
pub lang: Language,
pub value: 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",
rename = "garden.lexicon.documentation",
tag = "$type",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Documentation<S: BosStr = DefaultStr> {
pub created_at: Datetime,
#[serde(skip_serializing_if = "Option::is_none")]
pub definitions: Option<Vec<documentation::DefinitionDoc<S>>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<Vec<documentation::LocalizedString<S>>>,
pub lexicon: Nsid<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 DocumentationGetRecordOutput<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub cid: Option<Cid<S>>,
pub uri: AtUri<S>,
pub value: Documentation<S>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct PropertyDoc<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<Vec<documentation::LocalizedString<S>>>,
pub name: S,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
impl<S: BosStr> Documentation<S> {
pub fn uri(uri: S) -> Result<RecordUri<S, DocumentationRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new(uri)?)
}
}
impl<S: BosStr> LexiconSchema for DefinitionDoc<S> {
fn nsid() -> &'static str {
"garden.lexicon.documentation"
}
fn def_name() -> &'static str {
"definitionDoc"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_garden_lexicon_documentation()
}
fn validate(&self) -> Result<(), ConstraintError> {
{
let value = &self.name;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 512usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("name"),
max: 512usize,
actual: <str>::len(value.as_ref()),
});
}
}
Ok(())
}
}
impl<S: BosStr> LexiconSchema for LocalizedString<S> {
fn nsid() -> &'static str {
"garden.lexicon.documentation"
}
fn def_name() -> &'static str {
"localizedString"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_garden_lexicon_documentation()
}
fn validate(&self) -> Result<(), ConstraintError> {
{
let value = &self.value;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 10000usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("value"),
max: 10000usize,
actual: <str>::len(value.as_ref()),
});
}
}
Ok(())
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct DocumentationRecord;
impl XrpcResp for DocumentationRecord {
const NSID: &'static str = "garden.lexicon.documentation";
const ENCODING: &'static str = "application/json";
type Output<S: BosStr> = DocumentationGetRecordOutput<S>;
type Err = RecordError;
}
impl<S: BosStr> From<DocumentationGetRecordOutput<S>> for Documentation<S> {
fn from(output: DocumentationGetRecordOutput<S>) -> Self {
output.value
}
}
impl<S: BosStr> Collection for Documentation<S> {
const NSID: &'static str = "garden.lexicon.documentation";
type Record = DocumentationRecord;
}
impl Collection for DocumentationRecord {
const NSID: &'static str = "garden.lexicon.documentation";
type Record = DocumentationRecord;
}
impl<S: BosStr> LexiconSchema for Documentation<S> {
fn nsid() -> &'static str {
"garden.lexicon.documentation"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_garden_lexicon_documentation()
}
fn validate(&self) -> Result<(), ConstraintError> {
Ok(())
}
}
impl<S: BosStr> LexiconSchema for PropertyDoc<S> {
fn nsid() -> &'static str {
"garden.lexicon.documentation"
}
fn def_name() -> &'static str {
"propertyDoc"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_garden_lexicon_documentation()
}
fn validate(&self) -> Result<(), ConstraintError> {
{
let value = &self.name;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 256usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("name"),
max: 256usize,
actual: <str>::len(value.as_ref()),
});
}
}
Ok(())
}
}
fn lexicon_doc_garden_lexicon_documentation() -> 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("garden.lexicon.documentation"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("definitionDoc"),
LexUserType::Object(LexObject {
description: Some(
CowStr::new_static(
"Documentation for a definition within a lexicon.",
),
),
required: Some(vec![SmolStr::new_static("name")]),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("description"),
LexObjectProperty::Array(LexArray {
description: Some(
CowStr::new_static(
"Localized descriptions for this definition.",
),
),
items: LexArrayItem::Ref(LexRef {
r#ref: CowStr::new_static("#localizedString"),
..Default::default()
}),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("name"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"The name of the definition being documented (e.g., 'main', 'replyRef').",
),
),
max_length: Some(512usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("properties"),
LexObjectProperty::Array(LexArray {
description: Some(
CowStr::new_static(
"Documentation for properties within this definition.",
),
),
items: LexArrayItem::Ref(LexRef {
r#ref: CowStr::new_static("#propertyDoc"),
..Default::default()
}),
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map.insert(
SmolStr::new_static("localizedString"),
LexUserType::Object(LexObject {
description: Some(
CowStr::new_static("A string with an associated language code."),
),
required: Some(
vec![SmolStr::new_static("lang"), SmolStr::new_static("value")],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("lang"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"ISO 639 language code (e.g., 'en', 'es', 'ja').",
),
),
format: Some(LexStringFormat::Language),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("value"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("The localized string value."),
),
max_length: Some(10000usize),
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map.insert(
SmolStr::new_static("main"),
LexUserType::Record(LexRecord {
description: Some(
CowStr::new_static(
"Auxiliary documentation for a lexicon schema, supporting localized descriptions for the lexicon and its properties.",
),
),
key: Some(CowStr::new_static("nsid")),
record: LexRecordRecord::Object(LexObject {
required: Some(
vec![
SmolStr::new_static("lexicon"),
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(
"Timestamp when this documentation was created.",
),
),
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("definitions"),
LexObjectProperty::Array(LexArray {
description: Some(
CowStr::new_static(
"Documentation for specific definitions within the lexicon (e.g., main, replyRef).",
),
),
items: LexArrayItem::Ref(LexRef {
r#ref: CowStr::new_static("#definitionDoc"),
..Default::default()
}),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("description"),
LexObjectProperty::Array(LexArray {
description: Some(
CowStr::new_static(
"Localized descriptions for the lexicon.",
),
),
items: LexArrayItem::Ref(LexRef {
r#ref: CowStr::new_static("#localizedString"),
..Default::default()
}),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("lexicon"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"The NSID of the lexicon being documented.",
),
),
format: Some(LexStringFormat::Nsid),
..Default::default()
}),
);
map
},
..Default::default()
}),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("propertyDoc"),
LexUserType::Object(LexObject {
description: Some(
CowStr::new_static(
"Documentation for a specific property within a definition.",
),
),
required: Some(vec![SmolStr::new_static("name")]),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("description"),
LexObjectProperty::Array(LexArray {
description: Some(
CowStr::new_static(
"Localized descriptions for this property.",
),
),
items: LexArrayItem::Ref(LexRef {
r#ref: CowStr::new_static("#localizedString"),
..Default::default()
}),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("name"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("The property name being documented."),
),
max_length: Some(256usize),
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map
},
..Default::default()
}
}
pub mod localized_string_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 Lang;
type Value;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Lang = Unset;
type Value = Unset;
}
pub struct SetLang<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetLang<St> {}
impl<St: State> State for SetLang<St> {
type Lang = Set<members::lang>;
type Value = St::Value;
}
pub struct SetValue<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetValue<St> {}
impl<St: State> State for SetValue<St> {
type Lang = St::Lang;
type Value = Set<members::value>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct lang(());
pub struct value(());
}
}
pub struct LocalizedStringBuilder<S: BosStr, St: localized_string_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (Option<Language>, Option<S>),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> LocalizedString<S> {
pub fn new() -> LocalizedStringBuilder<S, localized_string_state::Empty> {
LocalizedStringBuilder::new()
}
}
impl<S: BosStr> LocalizedStringBuilder<S, localized_string_state::Empty> {
pub fn new() -> Self {
LocalizedStringBuilder {
_state: PhantomData,
_fields: (None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St> LocalizedStringBuilder<S, St>
where
St: localized_string_state::State,
St::Lang: localized_string_state::IsUnset,
{
pub fn lang(
mut self,
value: impl Into<Language>,
) -> LocalizedStringBuilder<S, localized_string_state::SetLang<St>> {
self._fields.0 = Option::Some(value.into());
LocalizedStringBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> LocalizedStringBuilder<S, St>
where
St: localized_string_state::State,
St::Value: localized_string_state::IsUnset,
{
pub fn value(
mut self,
value: impl Into<S>,
) -> LocalizedStringBuilder<S, localized_string_state::SetValue<St>> {
self._fields.1 = Option::Some(value.into());
LocalizedStringBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> LocalizedStringBuilder<S, St>
where
St: localized_string_state::State,
St::Lang: localized_string_state::IsSet,
St::Value: localized_string_state::IsSet,
{
pub fn build(self) -> LocalizedString<S> {
LocalizedString {
lang: self._fields.0.unwrap(),
value: self._fields.1.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(
self,
extra_data: BTreeMap<SmolStr, Data<S>>,
) -> LocalizedString<S> {
LocalizedString {
lang: self._fields.0.unwrap(),
value: self._fields.1.unwrap(),
extra_data: Some(extra_data),
}
}
}
pub mod documentation_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 CreatedAt;
type Lexicon;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type CreatedAt = Unset;
type Lexicon = 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 Lexicon = St::Lexicon;
}
pub struct SetLexicon<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetLexicon<St> {}
impl<St: State> State for SetLexicon<St> {
type CreatedAt = St::CreatedAt;
type Lexicon = Set<members::lexicon>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct created_at(());
pub struct lexicon(());
}
}
pub struct DocumentationBuilder<S: BosStr, St: documentation_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<Datetime>,
Option<Vec<documentation::DefinitionDoc<S>>>,
Option<Vec<documentation::LocalizedString<S>>>,
Option<Nsid<S>>,
),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> Documentation<S> {
pub fn new() -> DocumentationBuilder<S, documentation_state::Empty> {
DocumentationBuilder::new()
}
}
impl<S: BosStr> DocumentationBuilder<S, documentation_state::Empty> {
pub fn new() -> Self {
DocumentationBuilder {
_state: PhantomData,
_fields: (None, None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St> DocumentationBuilder<S, St>
where
St: documentation_state::State,
St::CreatedAt: documentation_state::IsUnset,
{
pub fn created_at(
mut self,
value: impl Into<Datetime>,
) -> DocumentationBuilder<S, documentation_state::SetCreatedAt<St>> {
self._fields.0 = Option::Some(value.into());
DocumentationBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: documentation_state::State> DocumentationBuilder<S, St> {
pub fn definitions(
mut self,
value: impl Into<Option<Vec<documentation::DefinitionDoc<S>>>>,
) -> Self {
self._fields.1 = value.into();
self
}
pub fn maybe_definitions(
mut self,
value: Option<Vec<documentation::DefinitionDoc<S>>>,
) -> Self {
self._fields.1 = value;
self
}
}
impl<S: BosStr, St: documentation_state::State> DocumentationBuilder<S, St> {
pub fn description(
mut self,
value: impl Into<Option<Vec<documentation::LocalizedString<S>>>>,
) -> Self {
self._fields.2 = value.into();
self
}
pub fn maybe_description(
mut self,
value: Option<Vec<documentation::LocalizedString<S>>>,
) -> Self {
self._fields.2 = value;
self
}
}
impl<S: BosStr, St> DocumentationBuilder<S, St>
where
St: documentation_state::State,
St::Lexicon: documentation_state::IsUnset,
{
pub fn lexicon(
mut self,
value: impl Into<Nsid<S>>,
) -> DocumentationBuilder<S, documentation_state::SetLexicon<St>> {
self._fields.3 = Option::Some(value.into());
DocumentationBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> DocumentationBuilder<S, St>
where
St: documentation_state::State,
St::CreatedAt: documentation_state::IsSet,
St::Lexicon: documentation_state::IsSet,
{
pub fn build(self) -> Documentation<S> {
Documentation {
created_at: self._fields.0.unwrap(),
definitions: self._fields.1,
description: self._fields.2,
lexicon: self._fields.3.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(
self,
extra_data: BTreeMap<SmolStr, Data<S>>,
) -> Documentation<S> {
Documentation {
created_at: self._fields.0.unwrap(),
definitions: self._fields.1,
description: self._fields.2,
lexicon: self._fields.3.unwrap(),
extra_data: Some(extra_data),
}
}
}