#[allow(unused_imports)]
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::CowStr;
#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
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::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;
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase")]
pub struct DefinitionDoc<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub description: Option<Vec<documentation::LocalizedString<'a>>>,
#[serde(borrow)]
pub name: CowStr<'a>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub properties: Option<Vec<documentation::PropertyDoc<'a>>>,
}
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct LocalizedString<'a> {
pub lang: Language,
#[serde(borrow)]
pub value: CowStr<'a>,
}
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Documentation<'a> {
pub created_at: Datetime,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub definitions: Option<Vec<documentation::DefinitionDoc<'a>>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub description: Option<Vec<documentation::LocalizedString<'a>>>,
#[serde(borrow)]
pub lexicon: Nsid<'a>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct DocumentationGetRecordOutput<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub cid: Option<Cid<'a>>,
#[serde(borrow)]
pub uri: AtUri<'a>,
#[serde(borrow)]
pub value: Documentation<'a>,
}
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase")]
pub struct PropertyDoc<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub description: Option<Vec<documentation::LocalizedString<'a>>>,
#[serde(borrow)]
pub name: CowStr<'a>,
}
impl<'a> Documentation<'a> {
pub fn uri(
uri: impl Into<CowStr<'a>>,
) -> Result<RecordUri<'a, DocumentationRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new_cow(uri.into())?)
}
}
impl<'a> LexiconSchema for DefinitionDoc<'a> {
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<'a> LexiconSchema for LocalizedString<'a> {
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<'de> = DocumentationGetRecordOutput<'de>;
type Err<'de> = RecordError<'de>;
}
impl From<DocumentationGetRecordOutput<'_>> for Documentation<'_> {
fn from(output: DocumentationGetRecordOutput<'_>) -> Self {
use jacquard_common::IntoStatic;
output.value.into_static()
}
}
impl Collection for Documentation<'_> {
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<'a> LexiconSchema for Documentation<'a> {
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<'a> LexiconSchema for PropertyDoc<'a> {
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 Value;
type Lang;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Value = Unset;
type Lang = Unset;
}
pub struct SetValue<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetValue<S> {}
impl<S: State> State for SetValue<S> {
type Value = Set<members::value>;
type Lang = S::Lang;
}
pub struct SetLang<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetLang<S> {}
impl<S: State> State for SetLang<S> {
type Value = S::Value;
type Lang = Set<members::lang>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct value(());
pub struct lang(());
}
}
pub struct LocalizedStringBuilder<'a, S: localized_string_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (Option<Language>, Option<CowStr<'a>>),
_lifetime: PhantomData<&'a ()>,
}
impl<'a> LocalizedString<'a> {
pub fn new() -> LocalizedStringBuilder<'a, localized_string_state::Empty> {
LocalizedStringBuilder::new()
}
}
impl<'a> LocalizedStringBuilder<'a, localized_string_state::Empty> {
pub fn new() -> Self {
LocalizedStringBuilder {
_state: PhantomData,
_fields: (None, None),
_lifetime: PhantomData,
}
}
}
impl<'a, S> LocalizedStringBuilder<'a, S>
where
S: localized_string_state::State,
S::Lang: localized_string_state::IsUnset,
{
pub fn lang(
mut self,
value: impl Into<Language>,
) -> LocalizedStringBuilder<'a, localized_string_state::SetLang<S>> {
self._fields.0 = Option::Some(value.into());
LocalizedStringBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> LocalizedStringBuilder<'a, S>
where
S: localized_string_state::State,
S::Value: localized_string_state::IsUnset,
{
pub fn value(
mut self,
value: impl Into<CowStr<'a>>,
) -> LocalizedStringBuilder<'a, localized_string_state::SetValue<S>> {
self._fields.1 = Option::Some(value.into());
LocalizedStringBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> LocalizedStringBuilder<'a, S>
where
S: localized_string_state::State,
S::Value: localized_string_state::IsSet,
S::Lang: localized_string_state::IsSet,
{
pub fn build(self) -> LocalizedString<'a> {
LocalizedString {
lang: self._fields.0.unwrap(),
value: self._fields.1.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(
self,
extra_data: BTreeMap<
jacquard_common::deps::smol_str::SmolStr,
jacquard_common::types::value::Data<'a>,
>,
) -> LocalizedString<'a> {
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 Lexicon;
type CreatedAt;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Lexicon = Unset;
type CreatedAt = Unset;
}
pub struct SetLexicon<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetLexicon<S> {}
impl<S: State> State for SetLexicon<S> {
type Lexicon = Set<members::lexicon>;
type CreatedAt = S::CreatedAt;
}
pub struct SetCreatedAt<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetCreatedAt<S> {}
impl<S: State> State for SetCreatedAt<S> {
type Lexicon = S::Lexicon;
type CreatedAt = Set<members::created_at>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct lexicon(());
pub struct created_at(());
}
}
pub struct DocumentationBuilder<'a, S: documentation_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (
Option<Datetime>,
Option<Vec<documentation::DefinitionDoc<'a>>>,
Option<Vec<documentation::LocalizedString<'a>>>,
Option<Nsid<'a>>,
),
_lifetime: PhantomData<&'a ()>,
}
impl<'a> Documentation<'a> {
pub fn new() -> DocumentationBuilder<'a, documentation_state::Empty> {
DocumentationBuilder::new()
}
}
impl<'a> DocumentationBuilder<'a, documentation_state::Empty> {
pub fn new() -> Self {
DocumentationBuilder {
_state: PhantomData,
_fields: (None, None, None, None),
_lifetime: PhantomData,
}
}
}
impl<'a, S> DocumentationBuilder<'a, S>
where
S: documentation_state::State,
S::CreatedAt: documentation_state::IsUnset,
{
pub fn created_at(
mut self,
value: impl Into<Datetime>,
) -> DocumentationBuilder<'a, documentation_state::SetCreatedAt<S>> {
self._fields.0 = Option::Some(value.into());
DocumentationBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S: documentation_state::State> DocumentationBuilder<'a, S> {
pub fn definitions(
mut self,
value: impl Into<Option<Vec<documentation::DefinitionDoc<'a>>>>,
) -> Self {
self._fields.1 = value.into();
self
}
pub fn maybe_definitions(
mut self,
value: Option<Vec<documentation::DefinitionDoc<'a>>>,
) -> Self {
self._fields.1 = value;
self
}
}
impl<'a, S: documentation_state::State> DocumentationBuilder<'a, S> {
pub fn description(
mut self,
value: impl Into<Option<Vec<documentation::LocalizedString<'a>>>>,
) -> Self {
self._fields.2 = value.into();
self
}
pub fn maybe_description(
mut self,
value: Option<Vec<documentation::LocalizedString<'a>>>,
) -> Self {
self._fields.2 = value;
self
}
}
impl<'a, S> DocumentationBuilder<'a, S>
where
S: documentation_state::State,
S::Lexicon: documentation_state::IsUnset,
{
pub fn lexicon(
mut self,
value: impl Into<Nsid<'a>>,
) -> DocumentationBuilder<'a, documentation_state::SetLexicon<S>> {
self._fields.3 = Option::Some(value.into());
DocumentationBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> DocumentationBuilder<'a, S>
where
S: documentation_state::State,
S::Lexicon: documentation_state::IsSet,
S::CreatedAt: documentation_state::IsSet,
{
pub fn build(self) -> Documentation<'a> {
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<
jacquard_common::deps::smol_str::SmolStr,
jacquard_common::types::value::Data<'a>,
>,
) -> Documentation<'a> {
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),
}
}
}