#[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, UriValue};
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 = "com.chrisvanderloo.project",
tag = "$type",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Project<S: BosStr = DefaultStr> {
pub description: S,
pub language: S,
#[serde(skip_serializing_if = "Option::is_none")]
pub link: Option<UriValue<S>>,
pub repo: UriValue<S>,
pub title: 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 ProjectGetRecordOutput<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub cid: Option<Cid<S>>,
pub uri: AtUri<S>,
pub value: Project<S>,
}
impl<S: BosStr> Project<S> {
pub fn uri(uri: S) -> Result<RecordUri<S, ProjectRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new(uri)?)
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct ProjectRecord;
impl XrpcResp for ProjectRecord {
const NSID: &'static str = "com.chrisvanderloo.project";
const ENCODING: &'static str = "application/json";
type Output<S: BosStr> = ProjectGetRecordOutput<S>;
type Err = RecordError;
}
impl<S: BosStr> From<ProjectGetRecordOutput<S>> for Project<S> {
fn from(output: ProjectGetRecordOutput<S>) -> Self {
output.value
}
}
impl<S: BosStr> Collection for Project<S> {
const NSID: &'static str = "com.chrisvanderloo.project";
type Record = ProjectRecord;
}
impl Collection for ProjectRecord {
const NSID: &'static str = "com.chrisvanderloo.project";
type Record = ProjectRecord;
}
impl<S: BosStr> LexiconSchema for Project<S> {
fn nsid() -> &'static str {
"com.chrisvanderloo.project"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_com_chrisvanderloo_project()
}
fn validate(&self) -> Result<(), ConstraintError> {
{
let value = &self.description;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 2048usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("description"),
max: 2048usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.language;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 64usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("language"),
max: 64usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.link {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 2048usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("link"),
max: 2048usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.repo;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 2048usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("repo"),
max: 2048usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.title;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 120usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("title"),
max: 120usize,
actual: <str>::len(value.as_ref()),
});
}
}
Ok(())
}
}
pub mod project_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 Title;
type Repo;
type Description;
type Language;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Title = Unset;
type Repo = Unset;
type Description = Unset;
type Language = Unset;
}
pub struct SetTitle<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetTitle<St> {}
impl<St: State> State for SetTitle<St> {
type Title = Set<members::title>;
type Repo = St::Repo;
type Description = St::Description;
type Language = St::Language;
}
pub struct SetRepo<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetRepo<St> {}
impl<St: State> State for SetRepo<St> {
type Title = St::Title;
type Repo = Set<members::repo>;
type Description = St::Description;
type Language = St::Language;
}
pub struct SetDescription<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetDescription<St> {}
impl<St: State> State for SetDescription<St> {
type Title = St::Title;
type Repo = St::Repo;
type Description = Set<members::description>;
type Language = St::Language;
}
pub struct SetLanguage<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetLanguage<St> {}
impl<St: State> State for SetLanguage<St> {
type Title = St::Title;
type Repo = St::Repo;
type Description = St::Description;
type Language = Set<members::language>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct title(());
pub struct repo(());
pub struct description(());
pub struct language(());
}
}
pub struct ProjectBuilder<S: BosStr, St: project_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<S>,
Option<S>,
Option<UriValue<S>>,
Option<UriValue<S>>,
Option<S>,
),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> Project<S> {
pub fn new() -> ProjectBuilder<S, project_state::Empty> {
ProjectBuilder::new()
}
}
impl<S: BosStr> ProjectBuilder<S, project_state::Empty> {
pub fn new() -> Self {
ProjectBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St> ProjectBuilder<S, St>
where
St: project_state::State,
St::Description: project_state::IsUnset,
{
pub fn description(
mut self,
value: impl Into<S>,
) -> ProjectBuilder<S, project_state::SetDescription<St>> {
self._fields.0 = Option::Some(value.into());
ProjectBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> ProjectBuilder<S, St>
where
St: project_state::State,
St::Language: project_state::IsUnset,
{
pub fn language(
mut self,
value: impl Into<S>,
) -> ProjectBuilder<S, project_state::SetLanguage<St>> {
self._fields.1 = Option::Some(value.into());
ProjectBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: project_state::State> ProjectBuilder<S, St> {
pub fn link(mut self, value: impl Into<Option<UriValue<S>>>) -> Self {
self._fields.2 = value.into();
self
}
pub fn maybe_link(mut self, value: Option<UriValue<S>>) -> Self {
self._fields.2 = value;
self
}
}
impl<S: BosStr, St> ProjectBuilder<S, St>
where
St: project_state::State,
St::Repo: project_state::IsUnset,
{
pub fn repo(
mut self,
value: impl Into<UriValue<S>>,
) -> ProjectBuilder<S, project_state::SetRepo<St>> {
self._fields.3 = Option::Some(value.into());
ProjectBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> ProjectBuilder<S, St>
where
St: project_state::State,
St::Title: project_state::IsUnset,
{
pub fn title(mut self, value: impl Into<S>) -> ProjectBuilder<S, project_state::SetTitle<St>> {
self._fields.4 = Option::Some(value.into());
ProjectBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> ProjectBuilder<S, St>
where
St: project_state::State,
St::Title: project_state::IsSet,
St::Repo: project_state::IsSet,
St::Description: project_state::IsSet,
St::Language: project_state::IsSet,
{
pub fn build(self) -> Project<S> {
Project {
description: self._fields.0.unwrap(),
language: self._fields.1.unwrap(),
link: self._fields.2,
repo: self._fields.3.unwrap(),
title: self._fields.4.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Project<S> {
Project {
description: self._fields.0.unwrap(),
language: self._fields.1.unwrap(),
link: self._fields.2,
repo: self._fields.3.unwrap(),
title: self._fields.4.unwrap(),
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_com_chrisvanderloo_project() -> 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("com.chrisvanderloo.project"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("main"),
LexUserType::Record(LexRecord {
description: Some(CowStr::new_static("A project for display on my website.")),
key: Some(CowStr::new_static("any")),
record: LexRecordRecord::Object(LexObject {
required: Some(vec![
SmolStr::new_static("title"),
SmolStr::new_static("description"),
SmolStr::new_static("repo"),
SmolStr::new_static("language"),
]),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("description"),
LexObjectProperty::String(LexString {
max_length: Some(2048usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("language"),
LexObjectProperty::String(LexString {
max_length: Some(64usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("link"),
LexObjectProperty::String(LexString {
format: Some(LexStringFormat::Uri),
max_length: Some(2048usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("repo"),
LexObjectProperty::String(LexString {
format: Some(LexStringFormat::Uri),
max_length: Some(2048usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("title"),
LexObjectProperty::String(LexString {
max_length: Some(120usize),
..Default::default()
}),
);
map
},
..Default::default()
}),
..Default::default()
}),
);
map
},
..Default::default()
}
}