#[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};
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 = "coop.hypha.spores.site.config",
tag = "$type",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Config<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub body_font: Option<ConfigBodyFont<S>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub font_body: Option<ConfigFontBody<S>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub font_heading: Option<ConfigFontHeading<S>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub heading_font: Option<ConfigHeadingFont<S>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub subtitle: Option<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub title: Option<S>,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum ConfigBodyFont<S: BosStr = DefaultStr> {
WorkSans,
Georgia,
JetbrainsMono,
CourierNew,
Other(S),
}
impl<S: BosStr> ConfigBodyFont<S> {
pub fn as_str(&self) -> &str {
match self {
Self::WorkSans => "work-sans",
Self::Georgia => "georgia",
Self::JetbrainsMono => "jetbrains-mono",
Self::CourierNew => "courier-new",
Self::Other(s) => s.as_ref(),
}
}
pub fn from_value(s: S) -> Self {
match s.as_ref() {
"work-sans" => Self::WorkSans,
"georgia" => Self::Georgia,
"jetbrains-mono" => Self::JetbrainsMono,
"courier-new" => Self::CourierNew,
_ => Self::Other(s),
}
}
}
impl<S: BosStr> core::fmt::Display for ConfigBodyFont<S> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<S: BosStr> AsRef<str> for ConfigBodyFont<S> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<S: BosStr> Serialize for ConfigBodyFont<S> {
fn serialize<Ser>(&self, serializer: Ser) -> Result<Ser::Ok, Ser::Error>
where
Ser: serde::Serializer,
{
serializer.serialize_str(self.as_str())
}
}
impl<'de, S: Deserialize<'de> + BosStr> Deserialize<'de> for ConfigBodyFont<S> {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let s = S::deserialize(deserializer)?;
Ok(Self::from_value(s))
}
}
impl<S: BosStr + Default> Default for ConfigBodyFont<S> {
fn default() -> Self {
Self::Other(Default::default())
}
}
impl<S: BosStr> jacquard_common::IntoStatic for ConfigBodyFont<S>
where
S: BosStr + jacquard_common::IntoStatic,
S::Output: BosStr,
{
type Output = ConfigBodyFont<S::Output>;
fn into_static(self) -> Self::Output {
match self {
ConfigBodyFont::WorkSans => ConfigBodyFont::WorkSans,
ConfigBodyFont::Georgia => ConfigBodyFont::Georgia,
ConfigBodyFont::JetbrainsMono => ConfigBodyFont::JetbrainsMono,
ConfigBodyFont::CourierNew => ConfigBodyFont::CourierNew,
ConfigBodyFont::Other(v) => ConfigBodyFont::Other(v.into_static()),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum ConfigFontBody<S: BosStr = DefaultStr> {
WorkSans,
Georgia,
JetbrainsMono,
CourierNew,
Other(S),
}
impl<S: BosStr> ConfigFontBody<S> {
pub fn as_str(&self) -> &str {
match self {
Self::WorkSans => "work-sans",
Self::Georgia => "georgia",
Self::JetbrainsMono => "jetbrains-mono",
Self::CourierNew => "courier-new",
Self::Other(s) => s.as_ref(),
}
}
pub fn from_value(s: S) -> Self {
match s.as_ref() {
"work-sans" => Self::WorkSans,
"georgia" => Self::Georgia,
"jetbrains-mono" => Self::JetbrainsMono,
"courier-new" => Self::CourierNew,
_ => Self::Other(s),
}
}
}
impl<S: BosStr> core::fmt::Display for ConfigFontBody<S> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<S: BosStr> AsRef<str> for ConfigFontBody<S> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<S: BosStr> Serialize for ConfigFontBody<S> {
fn serialize<Ser>(&self, serializer: Ser) -> Result<Ser::Ok, Ser::Error>
where
Ser: serde::Serializer,
{
serializer.serialize_str(self.as_str())
}
}
impl<'de, S: Deserialize<'de> + BosStr> Deserialize<'de> for ConfigFontBody<S> {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let s = S::deserialize(deserializer)?;
Ok(Self::from_value(s))
}
}
impl<S: BosStr + Default> Default for ConfigFontBody<S> {
fn default() -> Self {
Self::Other(Default::default())
}
}
impl<S: BosStr> jacquard_common::IntoStatic for ConfigFontBody<S>
where
S: BosStr + jacquard_common::IntoStatic,
S::Output: BosStr,
{
type Output = ConfigFontBody<S::Output>;
fn into_static(self) -> Self::Output {
match self {
ConfigFontBody::WorkSans => ConfigFontBody::WorkSans,
ConfigFontBody::Georgia => ConfigFontBody::Georgia,
ConfigFontBody::JetbrainsMono => ConfigFontBody::JetbrainsMono,
ConfigFontBody::CourierNew => ConfigFontBody::CourierNew,
ConfigFontBody::Other(v) => ConfigFontBody::Other(v.into_static()),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum ConfigFontHeading<S: BosStr = DefaultStr> {
WorkSans,
Georgia,
JetbrainsMono,
CourierNew,
Other(S),
}
impl<S: BosStr> ConfigFontHeading<S> {
pub fn as_str(&self) -> &str {
match self {
Self::WorkSans => "work-sans",
Self::Georgia => "georgia",
Self::JetbrainsMono => "jetbrains-mono",
Self::CourierNew => "courier-new",
Self::Other(s) => s.as_ref(),
}
}
pub fn from_value(s: S) -> Self {
match s.as_ref() {
"work-sans" => Self::WorkSans,
"georgia" => Self::Georgia,
"jetbrains-mono" => Self::JetbrainsMono,
"courier-new" => Self::CourierNew,
_ => Self::Other(s),
}
}
}
impl<S: BosStr> core::fmt::Display for ConfigFontHeading<S> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<S: BosStr> AsRef<str> for ConfigFontHeading<S> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<S: BosStr> Serialize for ConfigFontHeading<S> {
fn serialize<Ser>(&self, serializer: Ser) -> Result<Ser::Ok, Ser::Error>
where
Ser: serde::Serializer,
{
serializer.serialize_str(self.as_str())
}
}
impl<'de, S: Deserialize<'de> + BosStr> Deserialize<'de> for ConfigFontHeading<S> {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let s = S::deserialize(deserializer)?;
Ok(Self::from_value(s))
}
}
impl<S: BosStr + Default> Default for ConfigFontHeading<S> {
fn default() -> Self {
Self::Other(Default::default())
}
}
impl<S: BosStr> jacquard_common::IntoStatic for ConfigFontHeading<S>
where
S: BosStr + jacquard_common::IntoStatic,
S::Output: BosStr,
{
type Output = ConfigFontHeading<S::Output>;
fn into_static(self) -> Self::Output {
match self {
ConfigFontHeading::WorkSans => ConfigFontHeading::WorkSans,
ConfigFontHeading::Georgia => ConfigFontHeading::Georgia,
ConfigFontHeading::JetbrainsMono => ConfigFontHeading::JetbrainsMono,
ConfigFontHeading::CourierNew => ConfigFontHeading::CourierNew,
ConfigFontHeading::Other(v) => ConfigFontHeading::Other(v.into_static()),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum ConfigHeadingFont<S: BosStr = DefaultStr> {
WorkSans,
Georgia,
JetbrainsMono,
CourierNew,
Other(S),
}
impl<S: BosStr> ConfigHeadingFont<S> {
pub fn as_str(&self) -> &str {
match self {
Self::WorkSans => "work-sans",
Self::Georgia => "georgia",
Self::JetbrainsMono => "jetbrains-mono",
Self::CourierNew => "courier-new",
Self::Other(s) => s.as_ref(),
}
}
pub fn from_value(s: S) -> Self {
match s.as_ref() {
"work-sans" => Self::WorkSans,
"georgia" => Self::Georgia,
"jetbrains-mono" => Self::JetbrainsMono,
"courier-new" => Self::CourierNew,
_ => Self::Other(s),
}
}
}
impl<S: BosStr> core::fmt::Display for ConfigHeadingFont<S> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<S: BosStr> AsRef<str> for ConfigHeadingFont<S> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<S: BosStr> Serialize for ConfigHeadingFont<S> {
fn serialize<Ser>(&self, serializer: Ser) -> Result<Ser::Ok, Ser::Error>
where
Ser: serde::Serializer,
{
serializer.serialize_str(self.as_str())
}
}
impl<'de, S: Deserialize<'de> + BosStr> Deserialize<'de> for ConfigHeadingFont<S> {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let s = S::deserialize(deserializer)?;
Ok(Self::from_value(s))
}
}
impl<S: BosStr + Default> Default for ConfigHeadingFont<S> {
fn default() -> Self {
Self::Other(Default::default())
}
}
impl<S: BosStr> jacquard_common::IntoStatic for ConfigHeadingFont<S>
where
S: BosStr + jacquard_common::IntoStatic,
S::Output: BosStr,
{
type Output = ConfigHeadingFont<S::Output>;
fn into_static(self) -> Self::Output {
match self {
ConfigHeadingFont::WorkSans => ConfigHeadingFont::WorkSans,
ConfigHeadingFont::Georgia => ConfigHeadingFont::Georgia,
ConfigHeadingFont::JetbrainsMono => ConfigHeadingFont::JetbrainsMono,
ConfigHeadingFont::CourierNew => ConfigHeadingFont::CourierNew,
ConfigHeadingFont::Other(v) => ConfigHeadingFont::Other(v.into_static()),
}
}
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct ConfigGetRecordOutput<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub cid: Option<Cid<S>>,
pub uri: AtUri<S>,
pub value: Config<S>,
}
impl<S: BosStr> Config<S> {
pub fn uri(uri: S) -> Result<RecordUri<S, ConfigRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new(uri)?)
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct ConfigRecord;
impl XrpcResp for ConfigRecord {
const NSID: &'static str = "coop.hypha.spores.site.config";
const ENCODING: &'static str = "application/json";
type Output<S: BosStr> = ConfigGetRecordOutput<S>;
type Err = RecordError;
}
impl<S: BosStr> From<ConfigGetRecordOutput<S>> for Config<S> {
fn from(output: ConfigGetRecordOutput<S>) -> Self {
output.value
}
}
impl<S: BosStr> Collection for Config<S> {
const NSID: &'static str = "coop.hypha.spores.site.config";
type Record = ConfigRecord;
}
impl Collection for ConfigRecord {
const NSID: &'static str = "coop.hypha.spores.site.config";
type Record = ConfigRecord;
}
impl<S: BosStr> LexiconSchema for Config<S> {
fn nsid() -> &'static str {
"coop.hypha.spores.site.config"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_coop_hypha_spores_site_config()
}
fn validate(&self) -> Result<(), ConstraintError> {
if let Some(ref value) = self.body_font {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 50usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("body_font"),
max: 50usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.font_body {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 50usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("font_body"),
max: 50usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.font_heading {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 50usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("font_heading"),
max: 50usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.heading_font {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 50usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("heading_font"),
max: 50usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.subtitle {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 2000usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("subtitle"),
max: 2000usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.subtitle {
{
let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
if count > 200usize {
return Err(ConstraintError::MaxGraphemes {
path: ValidationPath::from_field("subtitle"),
max: 200usize,
actual: count,
});
}
}
}
if let Some(ref value) = self.title {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 1000usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("title"),
max: 1000usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.title {
{
let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
if count > 100usize {
return Err(ConstraintError::MaxGraphemes {
path: ValidationPath::from_field("title"),
max: 100usize,
actual: count,
});
}
}
}
Ok(())
}
}
pub mod config_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 {}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {}
#[allow(non_camel_case_types)]
pub mod members {}
}
pub struct ConfigBuilder<S: BosStr, St: config_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<ConfigBodyFont<S>>,
Option<ConfigFontBody<S>>,
Option<ConfigFontHeading<S>>,
Option<ConfigHeadingFont<S>>,
Option<S>,
Option<S>,
),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> Config<S> {
pub fn new() -> ConfigBuilder<S, config_state::Empty> {
ConfigBuilder::new()
}
}
impl<S: BosStr> ConfigBuilder<S, config_state::Empty> {
pub fn new() -> Self {
ConfigBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St: config_state::State> ConfigBuilder<S, St> {
pub fn body_font(mut self, value: impl Into<Option<ConfigBodyFont<S>>>) -> Self {
self._fields.0 = value.into();
self
}
pub fn maybe_body_font(mut self, value: Option<ConfigBodyFont<S>>) -> Self {
self._fields.0 = value;
self
}
}
impl<S: BosStr, St: config_state::State> ConfigBuilder<S, St> {
pub fn font_body(mut self, value: impl Into<Option<ConfigFontBody<S>>>) -> Self {
self._fields.1 = value.into();
self
}
pub fn maybe_font_body(mut self, value: Option<ConfigFontBody<S>>) -> Self {
self._fields.1 = value;
self
}
}
impl<S: BosStr, St: config_state::State> ConfigBuilder<S, St> {
pub fn font_heading(mut self, value: impl Into<Option<ConfigFontHeading<S>>>) -> Self {
self._fields.2 = value.into();
self
}
pub fn maybe_font_heading(mut self, value: Option<ConfigFontHeading<S>>) -> Self {
self._fields.2 = value;
self
}
}
impl<S: BosStr, St: config_state::State> ConfigBuilder<S, St> {
pub fn heading_font(mut self, value: impl Into<Option<ConfigHeadingFont<S>>>) -> Self {
self._fields.3 = value.into();
self
}
pub fn maybe_heading_font(mut self, value: Option<ConfigHeadingFont<S>>) -> Self {
self._fields.3 = value;
self
}
}
impl<S: BosStr, St: config_state::State> ConfigBuilder<S, St> {
pub fn subtitle(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.4 = value.into();
self
}
pub fn maybe_subtitle(mut self, value: Option<S>) -> Self {
self._fields.4 = value;
self
}
}
impl<S: BosStr, St: config_state::State> ConfigBuilder<S, St> {
pub fn title(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.5 = value.into();
self
}
pub fn maybe_title(mut self, value: Option<S>) -> Self {
self._fields.5 = value;
self
}
}
impl<S: BosStr, St> ConfigBuilder<S, St>
where
St: config_state::State,
{
pub fn build(self) -> Config<S> {
Config {
body_font: self._fields.0,
font_body: self._fields.1,
font_heading: self._fields.2,
heading_font: self._fields.3,
subtitle: self._fields.4,
title: self._fields.5,
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Config<S> {
Config {
body_font: self._fields.0,
font_body: self._fields.1,
font_heading: self._fields.2,
heading_font: self._fields.3,
subtitle: self._fields.4,
title: self._fields.5,
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_coop_hypha_spores_site_config() -> 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("coop.hypha.spores.site.config"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("main"),
LexUserType::Record(LexRecord {
description: Some(CowStr::new_static(
"Site configuration for spores.garden, including title and subtitle.",
)),
key: Some(CowStr::new_static("literal:self")),
record: LexRecordRecord::Object(LexObject {
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("bodyFont"),
LexObjectProperty::String(LexString {
description: Some(CowStr::new_static("Body font ID")),
max_length: Some(50usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("fontBody"),
LexObjectProperty::String(LexString {
description: Some(CowStr::new_static(
"Deprecated legacy key for body font ID",
)),
max_length: Some(50usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("fontHeading"),
LexObjectProperty::String(LexString {
description: Some(CowStr::new_static(
"Deprecated legacy key for heading font ID",
)),
max_length: Some(50usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("headingFont"),
LexObjectProperty::String(LexString {
description: Some(CowStr::new_static("Heading font ID")),
max_length: Some(50usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("subtitle"),
LexObjectProperty::String(LexString {
description: Some(CowStr::new_static("Site subtitle")),
max_length: Some(2000usize),
max_graphemes: Some(200usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("title"),
LexObjectProperty::String(LexString {
description: Some(CowStr::new_static("Site title")),
max_length: Some(1000usize),
max_graphemes: Some(100usize),
..Default::default()
}),
);
map
},
..Default::default()
}),
..Default::default()
}),
);
map
},
..Default::default()
}
}