#[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::blob::BlobRef;
use jacquard_common::types::collection::{Collection, RecordError};
use jacquard_common::types::string::{AtUri, Cid, Datetime};
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::space_remanso::note;
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Image<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub alt: Option<CowStr<'a>>,
#[serde(borrow)]
pub image: BlobRef<'a>,
}
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Note<'a> {
#[serde(borrow)]
pub content: CowStr<'a>,
#[serde(skip_serializing_if = "Option::is_none")]
pub created_at: Option<Datetime>,
#[serde(skip_serializing_if = "Option::is_none")]
pub discoverable: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub font_family: Option<CowStr<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub font_size: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub images: Option<Vec<note::Image<'a>>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub language: Option<NoteLanguage<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub published_at: Option<Datetime>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub theme: Option<NoteTheme<'a>>,
#[serde(borrow)]
pub title: CowStr<'a>,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum NoteLanguage<'a> {
Afr,
Ara,
Aze,
Bel,
Ben,
Bul,
Cat,
Ces,
Ckb,
Cmn,
Dan,
Deu,
Ell,
Eng,
Est,
Eus,
Fin,
Fra,
Hau,
Heb,
Hin,
Hrv,
Hun,
Hye,
Ind,
Isl,
Ita,
Jpn,
Kat,
Kaz,
Kor,
Lit,
Mar,
Mkd,
Nld,
Nob,
Pes,
Pol,
Por,
Ron,
Run,
Rus,
Slk,
Spa,
Srp,
Swe,
Tgl,
Tur,
Ukr,
Vie,
Other(CowStr<'a>),
}
impl<'a> NoteLanguage<'a> {
pub fn as_str(&self) -> &str {
match self {
Self::Afr => "afr",
Self::Ara => "ara",
Self::Aze => "aze",
Self::Bel => "bel",
Self::Ben => "ben",
Self::Bul => "bul",
Self::Cat => "cat",
Self::Ces => "ces",
Self::Ckb => "ckb",
Self::Cmn => "cmn",
Self::Dan => "dan",
Self::Deu => "deu",
Self::Ell => "ell",
Self::Eng => "eng",
Self::Est => "est",
Self::Eus => "eus",
Self::Fin => "fin",
Self::Fra => "fra",
Self::Hau => "hau",
Self::Heb => "heb",
Self::Hin => "hin",
Self::Hrv => "hrv",
Self::Hun => "hun",
Self::Hye => "hye",
Self::Ind => "ind",
Self::Isl => "isl",
Self::Ita => "ita",
Self::Jpn => "jpn",
Self::Kat => "kat",
Self::Kaz => "kaz",
Self::Kor => "kor",
Self::Lit => "lit",
Self::Mar => "mar",
Self::Mkd => "mkd",
Self::Nld => "nld",
Self::Nob => "nob",
Self::Pes => "pes",
Self::Pol => "pol",
Self::Por => "por",
Self::Ron => "ron",
Self::Run => "run",
Self::Rus => "rus",
Self::Slk => "slk",
Self::Spa => "spa",
Self::Srp => "srp",
Self::Swe => "swe",
Self::Tgl => "tgl",
Self::Tur => "tur",
Self::Ukr => "ukr",
Self::Vie => "vie",
Self::Other(s) => s.as_ref(),
}
}
}
impl<'a> From<&'a str> for NoteLanguage<'a> {
fn from(s: &'a str) -> Self {
match s {
"afr" => Self::Afr,
"ara" => Self::Ara,
"aze" => Self::Aze,
"bel" => Self::Bel,
"ben" => Self::Ben,
"bul" => Self::Bul,
"cat" => Self::Cat,
"ces" => Self::Ces,
"ckb" => Self::Ckb,
"cmn" => Self::Cmn,
"dan" => Self::Dan,
"deu" => Self::Deu,
"ell" => Self::Ell,
"eng" => Self::Eng,
"est" => Self::Est,
"eus" => Self::Eus,
"fin" => Self::Fin,
"fra" => Self::Fra,
"hau" => Self::Hau,
"heb" => Self::Heb,
"hin" => Self::Hin,
"hrv" => Self::Hrv,
"hun" => Self::Hun,
"hye" => Self::Hye,
"ind" => Self::Ind,
"isl" => Self::Isl,
"ita" => Self::Ita,
"jpn" => Self::Jpn,
"kat" => Self::Kat,
"kaz" => Self::Kaz,
"kor" => Self::Kor,
"lit" => Self::Lit,
"mar" => Self::Mar,
"mkd" => Self::Mkd,
"nld" => Self::Nld,
"nob" => Self::Nob,
"pes" => Self::Pes,
"pol" => Self::Pol,
"por" => Self::Por,
"ron" => Self::Ron,
"run" => Self::Run,
"rus" => Self::Rus,
"slk" => Self::Slk,
"spa" => Self::Spa,
"srp" => Self::Srp,
"swe" => Self::Swe,
"tgl" => Self::Tgl,
"tur" => Self::Tur,
"ukr" => Self::Ukr,
"vie" => Self::Vie,
_ => Self::Other(CowStr::from(s)),
}
}
}
impl<'a> From<String> for NoteLanguage<'a> {
fn from(s: String) -> Self {
match s.as_str() {
"afr" => Self::Afr,
"ara" => Self::Ara,
"aze" => Self::Aze,
"bel" => Self::Bel,
"ben" => Self::Ben,
"bul" => Self::Bul,
"cat" => Self::Cat,
"ces" => Self::Ces,
"ckb" => Self::Ckb,
"cmn" => Self::Cmn,
"dan" => Self::Dan,
"deu" => Self::Deu,
"ell" => Self::Ell,
"eng" => Self::Eng,
"est" => Self::Est,
"eus" => Self::Eus,
"fin" => Self::Fin,
"fra" => Self::Fra,
"hau" => Self::Hau,
"heb" => Self::Heb,
"hin" => Self::Hin,
"hrv" => Self::Hrv,
"hun" => Self::Hun,
"hye" => Self::Hye,
"ind" => Self::Ind,
"isl" => Self::Isl,
"ita" => Self::Ita,
"jpn" => Self::Jpn,
"kat" => Self::Kat,
"kaz" => Self::Kaz,
"kor" => Self::Kor,
"lit" => Self::Lit,
"mar" => Self::Mar,
"mkd" => Self::Mkd,
"nld" => Self::Nld,
"nob" => Self::Nob,
"pes" => Self::Pes,
"pol" => Self::Pol,
"por" => Self::Por,
"ron" => Self::Ron,
"run" => Self::Run,
"rus" => Self::Rus,
"slk" => Self::Slk,
"spa" => Self::Spa,
"srp" => Self::Srp,
"swe" => Self::Swe,
"tgl" => Self::Tgl,
"tur" => Self::Tur,
"ukr" => Self::Ukr,
"vie" => Self::Vie,
_ => Self::Other(CowStr::from(s)),
}
}
}
impl<'a> core::fmt::Display for NoteLanguage<'a> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<'a> AsRef<str> for NoteLanguage<'a> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<'a> serde::Serialize for NoteLanguage<'a> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_str(self.as_str())
}
}
impl<'de, 'a> serde::Deserialize<'de> for NoteLanguage<'a>
where
'de: 'a,
{
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let s = <&'de str>::deserialize(deserializer)?;
Ok(Self::from(s))
}
}
impl<'a> Default for NoteLanguage<'a> {
fn default() -> Self {
Self::Other(Default::default())
}
}
impl jacquard_common::IntoStatic for NoteLanguage<'_> {
type Output = NoteLanguage<'static>;
fn into_static(self) -> Self::Output {
match self {
NoteLanguage::Afr => NoteLanguage::Afr,
NoteLanguage::Ara => NoteLanguage::Ara,
NoteLanguage::Aze => NoteLanguage::Aze,
NoteLanguage::Bel => NoteLanguage::Bel,
NoteLanguage::Ben => NoteLanguage::Ben,
NoteLanguage::Bul => NoteLanguage::Bul,
NoteLanguage::Cat => NoteLanguage::Cat,
NoteLanguage::Ces => NoteLanguage::Ces,
NoteLanguage::Ckb => NoteLanguage::Ckb,
NoteLanguage::Cmn => NoteLanguage::Cmn,
NoteLanguage::Dan => NoteLanguage::Dan,
NoteLanguage::Deu => NoteLanguage::Deu,
NoteLanguage::Ell => NoteLanguage::Ell,
NoteLanguage::Eng => NoteLanguage::Eng,
NoteLanguage::Est => NoteLanguage::Est,
NoteLanguage::Eus => NoteLanguage::Eus,
NoteLanguage::Fin => NoteLanguage::Fin,
NoteLanguage::Fra => NoteLanguage::Fra,
NoteLanguage::Hau => NoteLanguage::Hau,
NoteLanguage::Heb => NoteLanguage::Heb,
NoteLanguage::Hin => NoteLanguage::Hin,
NoteLanguage::Hrv => NoteLanguage::Hrv,
NoteLanguage::Hun => NoteLanguage::Hun,
NoteLanguage::Hye => NoteLanguage::Hye,
NoteLanguage::Ind => NoteLanguage::Ind,
NoteLanguage::Isl => NoteLanguage::Isl,
NoteLanguage::Ita => NoteLanguage::Ita,
NoteLanguage::Jpn => NoteLanguage::Jpn,
NoteLanguage::Kat => NoteLanguage::Kat,
NoteLanguage::Kaz => NoteLanguage::Kaz,
NoteLanguage::Kor => NoteLanguage::Kor,
NoteLanguage::Lit => NoteLanguage::Lit,
NoteLanguage::Mar => NoteLanguage::Mar,
NoteLanguage::Mkd => NoteLanguage::Mkd,
NoteLanguage::Nld => NoteLanguage::Nld,
NoteLanguage::Nob => NoteLanguage::Nob,
NoteLanguage::Pes => NoteLanguage::Pes,
NoteLanguage::Pol => NoteLanguage::Pol,
NoteLanguage::Por => NoteLanguage::Por,
NoteLanguage::Ron => NoteLanguage::Ron,
NoteLanguage::Run => NoteLanguage::Run,
NoteLanguage::Rus => NoteLanguage::Rus,
NoteLanguage::Slk => NoteLanguage::Slk,
NoteLanguage::Spa => NoteLanguage::Spa,
NoteLanguage::Srp => NoteLanguage::Srp,
NoteLanguage::Swe => NoteLanguage::Swe,
NoteLanguage::Tgl => NoteLanguage::Tgl,
NoteLanguage::Tur => NoteLanguage::Tur,
NoteLanguage::Ukr => NoteLanguage::Ukr,
NoteLanguage::Vie => NoteLanguage::Vie,
NoteLanguage::Other(v) => NoteLanguage::Other(v.into_static()),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum NoteTheme<'a> {
Light,
Dark,
Other(CowStr<'a>),
}
impl<'a> NoteTheme<'a> {
pub fn as_str(&self) -> &str {
match self {
Self::Light => "light",
Self::Dark => "dark",
Self::Other(s) => s.as_ref(),
}
}
}
impl<'a> From<&'a str> for NoteTheme<'a> {
fn from(s: &'a str) -> Self {
match s {
"light" => Self::Light,
"dark" => Self::Dark,
_ => Self::Other(CowStr::from(s)),
}
}
}
impl<'a> From<String> for NoteTheme<'a> {
fn from(s: String) -> Self {
match s.as_str() {
"light" => Self::Light,
"dark" => Self::Dark,
_ => Self::Other(CowStr::from(s)),
}
}
}
impl<'a> core::fmt::Display for NoteTheme<'a> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<'a> AsRef<str> for NoteTheme<'a> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<'a> serde::Serialize for NoteTheme<'a> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_str(self.as_str())
}
}
impl<'de, 'a> serde::Deserialize<'de> for NoteTheme<'a>
where
'de: 'a,
{
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let s = <&'de str>::deserialize(deserializer)?;
Ok(Self::from(s))
}
}
impl<'a> Default for NoteTheme<'a> {
fn default() -> Self {
Self::Other(Default::default())
}
}
impl jacquard_common::IntoStatic for NoteTheme<'_> {
type Output = NoteTheme<'static>;
fn into_static(self) -> Self::Output {
match self {
NoteTheme::Light => NoteTheme::Light,
NoteTheme::Dark => NoteTheme::Dark,
NoteTheme::Other(v) => NoteTheme::Other(v.into_static()),
}
}
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct NoteGetRecordOutput<'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: Note<'a>,
}
impl<'a> Note<'a> {
pub fn uri(
uri: impl Into<CowStr<'a>>,
) -> Result<RecordUri<'a, NoteRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new_cow(uri.into())?)
}
}
impl<'a> LexiconSchema for Image<'a> {
fn nsid() -> &'static str {
"space.remanso.note"
}
fn def_name() -> &'static str {
"image"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_space_remanso_note()
}
fn validate(&self) -> Result<(), ConstraintError> {
if let Some(ref value) = self.alt {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 2000usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("alt"),
max: 2000usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.image;
{
let size = value.blob().size;
if size > 2000000usize {
return Err(ConstraintError::BlobTooLarge {
path: ValidationPath::from_field("image"),
max: 2000000usize,
actual: size,
});
}
}
}
{
let value = &self.image;
{
let mime = value.blob().mime_type.as_str();
let accepted: &[&str] = &["image/*"];
let matched = accepted
.iter()
.any(|pattern| {
if *pattern == "*/*" {
true
} else if pattern.ends_with("/*") {
let prefix = &pattern[..pattern.len() - 2];
mime.starts_with(prefix)
&& mime.as_bytes().get(prefix.len()) == Some(&b'/')
} else {
mime == *pattern
}
});
if !matched {
return Err(ConstraintError::BlobMimeTypeNotAccepted {
path: ValidationPath::from_field("image"),
accepted: vec!["image/*".to_string()],
actual: mime.to_string(),
});
}
}
}
Ok(())
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct NoteRecord;
impl XrpcResp for NoteRecord {
const NSID: &'static str = "space.remanso.note";
const ENCODING: &'static str = "application/json";
type Output<'de> = NoteGetRecordOutput<'de>;
type Err<'de> = RecordError<'de>;
}
impl From<NoteGetRecordOutput<'_>> for Note<'_> {
fn from(output: NoteGetRecordOutput<'_>) -> Self {
use jacquard_common::IntoStatic;
output.value.into_static()
}
}
impl Collection for Note<'_> {
const NSID: &'static str = "space.remanso.note";
type Record = NoteRecord;
}
impl Collection for NoteRecord {
const NSID: &'static str = "space.remanso.note";
type Record = NoteRecord;
}
impl<'a> LexiconSchema for Note<'a> {
fn nsid() -> &'static str {
"space.remanso.note"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_space_remanso_note()
}
fn validate(&self) -> Result<(), ConstraintError> {
{
let value = &self.content;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 30000usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("content"),
max: 30000usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.font_family {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 200usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("font_family"),
max: 200usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.images {
#[allow(unused_comparisons)]
if value.len() > 20usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("images"),
max: 20usize,
actual: value.len(),
});
}
}
if let Some(ref value) = self.language {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 10usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("language"),
max: 10usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let 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()),
});
}
}
Ok(())
}
}
pub mod image_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 Image;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Image = Unset;
}
pub struct SetImage<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetImage<S> {}
impl<S: State> State for SetImage<S> {
type Image = Set<members::image>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct image(());
}
}
pub struct ImageBuilder<'a, S: image_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (Option<CowStr<'a>>, Option<BlobRef<'a>>),
_lifetime: PhantomData<&'a ()>,
}
impl<'a> Image<'a> {
pub fn new() -> ImageBuilder<'a, image_state::Empty> {
ImageBuilder::new()
}
}
impl<'a> ImageBuilder<'a, image_state::Empty> {
pub fn new() -> Self {
ImageBuilder {
_state: PhantomData,
_fields: (None, None),
_lifetime: PhantomData,
}
}
}
impl<'a, S: image_state::State> ImageBuilder<'a, S> {
pub fn alt(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
self._fields.0 = value.into();
self
}
pub fn maybe_alt(mut self, value: Option<CowStr<'a>>) -> Self {
self._fields.0 = value;
self
}
}
impl<'a, S> ImageBuilder<'a, S>
where
S: image_state::State,
S::Image: image_state::IsUnset,
{
pub fn image(
mut self,
value: impl Into<BlobRef<'a>>,
) -> ImageBuilder<'a, image_state::SetImage<S>> {
self._fields.1 = Option::Some(value.into());
ImageBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> ImageBuilder<'a, S>
where
S: image_state::State,
S::Image: image_state::IsSet,
{
pub fn build(self) -> Image<'a> {
Image {
alt: self._fields.0,
image: 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>,
>,
) -> Image<'a> {
Image {
alt: self._fields.0,
image: self._fields.1.unwrap(),
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_space_remanso_note() -> 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("space.remanso.note"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("image"),
LexUserType::Object(LexObject {
required: Some(vec![SmolStr::new_static("image")]),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("alt"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("Alt text for the image."),
),
max_length: Some(2000usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("image"),
LexObjectProperty::Blob(LexBlob { ..Default::default() }),
);
map
},
..Default::default()
}),
);
map.insert(
SmolStr::new_static("main"),
LexUserType::Record(LexRecord {
description: Some(
CowStr::new_static(
"A markdown blog post with LaTeX, GitHub notes, Mermaid, YouTube and Bluesky extensions.",
),
),
key: Some(CowStr::new_static("tid")),
record: LexRecordRecord::Object(LexObject {
required: Some(
vec![
SmolStr::new_static("title"), SmolStr::new_static("content")
],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("content"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Markdown content. Local image paths are replaced with blob CIDs at publish time.",
),
),
max_length: Some(30000usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("createdAt"),
LexObjectProperty::String(LexString {
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("discoverable"),
LexObjectProperty::Boolean(LexBoolean {
..Default::default()
}),
);
map.insert(
SmolStr::new_static("fontFamily"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Font family name available from Coollabs.",
),
),
max_length: Some(200usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("fontSize"),
LexObjectProperty::Integer(LexInteger {
..Default::default()
}),
);
map.insert(
SmolStr::new_static("images"),
LexObjectProperty::Array(LexArray {
description: Some(
CowStr::new_static(
"Blob references for images embedded in the markdown content.",
),
),
items: LexArrayItem::Ref(LexRef {
r#ref: CowStr::new_static("#image"),
..Default::default()
}),
max_length: Some(20usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("language"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Most used language in the note. In ISO 639-3 code.",
),
),
max_length: Some(10usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("publishedAt"),
LexObjectProperty::String(LexString {
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("theme"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("Display theme for the note."),
),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("title"),
LexObjectProperty::String(LexString {
max_length: Some(1000usize),
..Default::default()
}),
);
map
},
..Default::default()
}),
..Default::default()
}),
);
map
},
..Default::default()
}
}
pub mod note_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 Content;
type Title;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Content = Unset;
type Title = Unset;
}
pub struct SetContent<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetContent<S> {}
impl<S: State> State for SetContent<S> {
type Content = Set<members::content>;
type Title = S::Title;
}
pub struct SetTitle<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetTitle<S> {}
impl<S: State> State for SetTitle<S> {
type Content = S::Content;
type Title = Set<members::title>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct content(());
pub struct title(());
}
}
pub struct NoteBuilder<'a, S: note_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (
Option<CowStr<'a>>,
Option<Datetime>,
Option<bool>,
Option<CowStr<'a>>,
Option<i64>,
Option<Vec<note::Image<'a>>>,
Option<NoteLanguage<'a>>,
Option<Datetime>,
Option<NoteTheme<'a>>,
Option<CowStr<'a>>,
),
_lifetime: PhantomData<&'a ()>,
}
impl<'a> Note<'a> {
pub fn new() -> NoteBuilder<'a, note_state::Empty> {
NoteBuilder::new()
}
}
impl<'a> NoteBuilder<'a, note_state::Empty> {
pub fn new() -> Self {
NoteBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None, None, None, None, None),
_lifetime: PhantomData,
}
}
}
impl<'a, S> NoteBuilder<'a, S>
where
S: note_state::State,
S::Content: note_state::IsUnset,
{
pub fn content(
mut self,
value: impl Into<CowStr<'a>>,
) -> NoteBuilder<'a, note_state::SetContent<S>> {
self._fields.0 = Option::Some(value.into());
NoteBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S: note_state::State> NoteBuilder<'a, S> {
pub fn created_at(mut self, value: impl Into<Option<Datetime>>) -> Self {
self._fields.1 = value.into();
self
}
pub fn maybe_created_at(mut self, value: Option<Datetime>) -> Self {
self._fields.1 = value;
self
}
}
impl<'a, S: note_state::State> NoteBuilder<'a, S> {
pub fn discoverable(mut self, value: impl Into<Option<bool>>) -> Self {
self._fields.2 = value.into();
self
}
pub fn maybe_discoverable(mut self, value: Option<bool>) -> Self {
self._fields.2 = value;
self
}
}
impl<'a, S: note_state::State> NoteBuilder<'a, S> {
pub fn font_family(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
self._fields.3 = value.into();
self
}
pub fn maybe_font_family(mut self, value: Option<CowStr<'a>>) -> Self {
self._fields.3 = value;
self
}
}
impl<'a, S: note_state::State> NoteBuilder<'a, S> {
pub fn font_size(mut self, value: impl Into<Option<i64>>) -> Self {
self._fields.4 = value.into();
self
}
pub fn maybe_font_size(mut self, value: Option<i64>) -> Self {
self._fields.4 = value;
self
}
}
impl<'a, S: note_state::State> NoteBuilder<'a, S> {
pub fn images(mut self, value: impl Into<Option<Vec<note::Image<'a>>>>) -> Self {
self._fields.5 = value.into();
self
}
pub fn maybe_images(mut self, value: Option<Vec<note::Image<'a>>>) -> Self {
self._fields.5 = value;
self
}
}
impl<'a, S: note_state::State> NoteBuilder<'a, S> {
pub fn language(mut self, value: impl Into<Option<NoteLanguage<'a>>>) -> Self {
self._fields.6 = value.into();
self
}
pub fn maybe_language(mut self, value: Option<NoteLanguage<'a>>) -> Self {
self._fields.6 = value;
self
}
}
impl<'a, S: note_state::State> NoteBuilder<'a, S> {
pub fn published_at(mut self, value: impl Into<Option<Datetime>>) -> Self {
self._fields.7 = value.into();
self
}
pub fn maybe_published_at(mut self, value: Option<Datetime>) -> Self {
self._fields.7 = value;
self
}
}
impl<'a, S: note_state::State> NoteBuilder<'a, S> {
pub fn theme(mut self, value: impl Into<Option<NoteTheme<'a>>>) -> Self {
self._fields.8 = value.into();
self
}
pub fn maybe_theme(mut self, value: Option<NoteTheme<'a>>) -> Self {
self._fields.8 = value;
self
}
}
impl<'a, S> NoteBuilder<'a, S>
where
S: note_state::State,
S::Title: note_state::IsUnset,
{
pub fn title(
mut self,
value: impl Into<CowStr<'a>>,
) -> NoteBuilder<'a, note_state::SetTitle<S>> {
self._fields.9 = Option::Some(value.into());
NoteBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> NoteBuilder<'a, S>
where
S: note_state::State,
S::Content: note_state::IsSet,
S::Title: note_state::IsSet,
{
pub fn build(self) -> Note<'a> {
Note {
content: self._fields.0.unwrap(),
created_at: self._fields.1,
discoverable: self._fields.2,
font_family: self._fields.3,
font_size: self._fields.4,
images: self._fields.5,
language: self._fields.6,
published_at: self._fields.7,
theme: self._fields.8,
title: self._fields.9.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>,
>,
) -> Note<'a> {
Note {
content: self._fields.0.unwrap(),
created_at: self._fields.1,
discoverable: self._fields.2,
font_family: self._fields.3,
font_size: self._fields.4,
images: self._fields.5,
language: self._fields.6,
published_at: self._fields.7,
theme: self._fields.8,
title: self._fields.9.unwrap(),
extra_data: Some(extra_data),
}
}
}