#[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, open_union};
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::place_wisp::fs;
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Directory<'a> {
#[serde(borrow)]
pub entries: Vec<fs::Entry<'a>>,
#[serde(borrow)]
pub r#type: CowStr<'a>,
}
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Entry<'a> {
#[serde(borrow)]
pub name: CowStr<'a>,
#[serde(borrow)]
pub node: EntryNode<'a>,
}
#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type", bound(deserialize = "'de: 'a"))]
pub enum EntryNode<'a> {
#[serde(rename = "place.wisp.fs#file")]
File(Box<fs::File<'a>>),
#[serde(rename = "place.wisp.fs#directory")]
Directory(Box<fs::Directory<'a>>),
#[serde(rename = "place.wisp.fs#subfs")]
Subfs(Box<fs::Subfs<'a>>),
}
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct File<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
pub base64: Option<bool>,
#[serde(borrow)]
pub blob: BlobRef<'a>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub encoding: Option<CowStr<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub mime_type: Option<CowStr<'a>>,
#[serde(borrow)]
pub r#type: CowStr<'a>,
}
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", rename = "place.wisp.fs", tag = "$type")]
pub struct Fs<'a> {
pub created_at: Datetime,
#[serde(skip_serializing_if = "Option::is_none")]
pub file_count: Option<i64>,
#[serde(borrow)]
pub root: fs::Directory<'a>,
#[serde(borrow)]
pub site: CowStr<'a>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct FsGetRecordOutput<'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: Fs<'a>,
}
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Subfs<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
pub flat: Option<bool>,
#[serde(borrow)]
pub subject: AtUri<'a>,
#[serde(borrow)]
pub r#type: CowStr<'a>,
}
impl<'a> Fs<'a> {
pub fn uri(uri: impl Into<CowStr<'a>>) -> Result<RecordUri<'a, FsRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new_cow(uri.into())?)
}
}
impl<'a> LexiconSchema for Directory<'a> {
fn nsid() -> &'static str {
"place.wisp.fs"
}
fn def_name() -> &'static str {
"directory"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_place_wisp_fs()
}
fn validate(&self) -> Result<(), ConstraintError> {
{
let value = &self.entries;
#[allow(unused_comparisons)]
if value.len() > 500usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("entries"),
max: 500usize,
actual: value.len(),
});
}
}
Ok(())
}
}
impl<'a> LexiconSchema for Entry<'a> {
fn nsid() -> &'static str {
"place.wisp.fs"
}
fn def_name() -> &'static str {
"entry"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_place_wisp_fs()
}
fn validate(&self) -> Result<(), ConstraintError> {
{
let value = &self.name;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 255usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("name"),
max: 255usize,
actual: <str>::len(value.as_ref()),
});
}
}
Ok(())
}
}
impl<'a> LexiconSchema for File<'a> {
fn nsid() -> &'static str {
"place.wisp.fs"
}
fn def_name() -> &'static str {
"file"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_place_wisp_fs()
}
fn validate(&self) -> Result<(), ConstraintError> {
{
let value = &self.blob;
{
let size = value.blob().size;
if size > 1000000000usize {
return Err(ConstraintError::BlobTooLarge {
path: ValidationPath::from_field("blob"),
max: 1000000000usize,
actual: size,
});
}
}
}
{
let value = &self.blob;
{
let mime = value.blob().mime_type.as_str();
let accepted: &[&str] = &["*/*"];
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("blob"),
accepted: vec!["*/*".to_string()],
actual: mime.to_string(),
});
}
}
}
Ok(())
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct FsRecord;
impl XrpcResp for FsRecord {
const NSID: &'static str = "place.wisp.fs";
const ENCODING: &'static str = "application/json";
type Output<'de> = FsGetRecordOutput<'de>;
type Err<'de> = RecordError<'de>;
}
impl From<FsGetRecordOutput<'_>> for Fs<'_> {
fn from(output: FsGetRecordOutput<'_>) -> Self {
use jacquard_common::IntoStatic;
output.value.into_static()
}
}
impl Collection for Fs<'_> {
const NSID: &'static str = "place.wisp.fs";
type Record = FsRecord;
}
impl Collection for FsRecord {
const NSID: &'static str = "place.wisp.fs";
type Record = FsRecord;
}
impl<'a> LexiconSchema for Fs<'a> {
fn nsid() -> &'static str {
"place.wisp.fs"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_place_wisp_fs()
}
fn validate(&self) -> Result<(), ConstraintError> {
if let Some(ref value) = self.file_count {
if *value > 1000i64 {
return Err(ConstraintError::Maximum {
path: ValidationPath::from_field("file_count"),
max: 1000i64,
actual: *value,
});
}
}
if let Some(ref value) = self.file_count {
if *value < 0i64 {
return Err(ConstraintError::Minimum {
path: ValidationPath::from_field("file_count"),
min: 0i64,
actual: *value,
});
}
}
Ok(())
}
}
impl<'a> LexiconSchema for Subfs<'a> {
fn nsid() -> &'static str {
"place.wisp.fs"
}
fn def_name() -> &'static str {
"subfs"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_place_wisp_fs()
}
fn validate(&self) -> Result<(), ConstraintError> {
Ok(())
}
}
pub mod directory_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 Entries;
type Type;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Entries = Unset;
type Type = Unset;
}
pub struct SetEntries<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetEntries<S> {}
impl<S: State> State for SetEntries<S> {
type Entries = Set<members::entries>;
type Type = S::Type;
}
pub struct SetType<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetType<S> {}
impl<S: State> State for SetType<S> {
type Entries = S::Entries;
type Type = Set<members::r#type>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct entries(());
pub struct r#type(());
}
}
pub struct DirectoryBuilder<'a, S: directory_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (Option<Vec<fs::Entry<'a>>>, Option<CowStr<'a>>),
_lifetime: PhantomData<&'a ()>,
}
impl<'a> Directory<'a> {
pub fn new() -> DirectoryBuilder<'a, directory_state::Empty> {
DirectoryBuilder::new()
}
}
impl<'a> DirectoryBuilder<'a, directory_state::Empty> {
pub fn new() -> Self {
DirectoryBuilder {
_state: PhantomData,
_fields: (None, None),
_lifetime: PhantomData,
}
}
}
impl<'a, S> DirectoryBuilder<'a, S>
where
S: directory_state::State,
S::Entries: directory_state::IsUnset,
{
pub fn entries(
mut self,
value: impl Into<Vec<fs::Entry<'a>>>,
) -> DirectoryBuilder<'a, directory_state::SetEntries<S>> {
self._fields.0 = Option::Some(value.into());
DirectoryBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> DirectoryBuilder<'a, S>
where
S: directory_state::State,
S::Type: directory_state::IsUnset,
{
pub fn r#type(
mut self,
value: impl Into<CowStr<'a>>,
) -> DirectoryBuilder<'a, directory_state::SetType<S>> {
self._fields.1 = Option::Some(value.into());
DirectoryBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> DirectoryBuilder<'a, S>
where
S: directory_state::State,
S::Entries: directory_state::IsSet,
S::Type: directory_state::IsSet,
{
pub fn build(self) -> Directory<'a> {
Directory {
entries: self._fields.0.unwrap(),
r#type: 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>,
>,
) -> Directory<'a> {
Directory {
entries: self._fields.0.unwrap(),
r#type: self._fields.1.unwrap(),
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_place_wisp_fs() -> 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("place.wisp.fs"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("directory"),
LexUserType::Object(LexObject {
required: Some(
vec![SmolStr::new_static("type"), SmolStr::new_static("entries")],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("entries"),
LexObjectProperty::Array(LexArray {
items: LexArrayItem::Ref(LexRef {
r#ref: CowStr::new_static("#entry"),
..Default::default()
}),
max_length: Some(500usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("type"),
LexObjectProperty::String(LexString { ..Default::default() }),
);
map
},
..Default::default()
}),
);
map.insert(
SmolStr::new_static("entry"),
LexUserType::Object(LexObject {
required: Some(
vec![SmolStr::new_static("name"), SmolStr::new_static("node")],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("name"),
LexObjectProperty::String(LexString {
max_length: Some(255usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("node"),
LexObjectProperty::Union(LexRefUnion {
refs: vec![
CowStr::new_static("#file"),
CowStr::new_static("#directory"),
CowStr::new_static("#subfs")
],
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map.insert(
SmolStr::new_static("file"),
LexUserType::Object(LexObject {
required: Some(
vec![SmolStr::new_static("type"), SmolStr::new_static("blob")],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("base64"),
LexObjectProperty::Boolean(LexBoolean {
..Default::default()
}),
);
map.insert(
SmolStr::new_static("blob"),
LexObjectProperty::Blob(LexBlob { ..Default::default() }),
);
map.insert(
SmolStr::new_static("encoding"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Content encoding (e.g., gzip for compressed files)",
),
),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("mimeType"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("Original MIME type before compression"),
),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("type"),
LexObjectProperty::String(LexString { ..Default::default() }),
);
map
},
..Default::default()
}),
);
map.insert(
SmolStr::new_static("main"),
LexUserType::Record(LexRecord {
description: Some(
CowStr::new_static("Virtual filesystem manifest for a Wisp site"),
),
record: LexRecordRecord::Object(LexObject {
required: Some(
vec![
SmolStr::new_static("site"), SmolStr::new_static("root"),
SmolStr::new_static("createdAt")
],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("createdAt"),
LexObjectProperty::String(LexString {
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("fileCount"),
LexObjectProperty::Integer(LexInteger {
minimum: Some(0i64),
maximum: Some(1000i64),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("root"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static("#directory"),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("site"),
LexObjectProperty::String(LexString {
..Default::default()
}),
);
map
},
..Default::default()
}),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("subfs"),
LexUserType::Object(LexObject {
required: Some(
vec![SmolStr::new_static("type"), SmolStr::new_static("subject")],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("flat"),
LexObjectProperty::Boolean(LexBoolean {
..Default::default()
}),
);
map.insert(
SmolStr::new_static("subject"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"AT-URI pointing to a place.wisp.subfs record containing this subtree.",
),
),
format: Some(LexStringFormat::AtUri),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("type"),
LexObjectProperty::String(LexString { ..Default::default() }),
);
map
},
..Default::default()
}),
);
map
},
..Default::default()
}
}
pub mod entry_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 Name;
type Node;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Name = Unset;
type Node = Unset;
}
pub struct SetName<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetName<S> {}
impl<S: State> State for SetName<S> {
type Name = Set<members::name>;
type Node = S::Node;
}
pub struct SetNode<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetNode<S> {}
impl<S: State> State for SetNode<S> {
type Name = S::Name;
type Node = Set<members::node>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct name(());
pub struct node(());
}
}
pub struct EntryBuilder<'a, S: entry_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (Option<CowStr<'a>>, Option<EntryNode<'a>>),
_lifetime: PhantomData<&'a ()>,
}
impl<'a> Entry<'a> {
pub fn new() -> EntryBuilder<'a, entry_state::Empty> {
EntryBuilder::new()
}
}
impl<'a> EntryBuilder<'a, entry_state::Empty> {
pub fn new() -> Self {
EntryBuilder {
_state: PhantomData,
_fields: (None, None),
_lifetime: PhantomData,
}
}
}
impl<'a, S> EntryBuilder<'a, S>
where
S: entry_state::State,
S::Name: entry_state::IsUnset,
{
pub fn name(
mut self,
value: impl Into<CowStr<'a>>,
) -> EntryBuilder<'a, entry_state::SetName<S>> {
self._fields.0 = Option::Some(value.into());
EntryBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> EntryBuilder<'a, S>
where
S: entry_state::State,
S::Node: entry_state::IsUnset,
{
pub fn node(
mut self,
value: impl Into<EntryNode<'a>>,
) -> EntryBuilder<'a, entry_state::SetNode<S>> {
self._fields.1 = Option::Some(value.into());
EntryBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> EntryBuilder<'a, S>
where
S: entry_state::State,
S::Name: entry_state::IsSet,
S::Node: entry_state::IsSet,
{
pub fn build(self) -> Entry<'a> {
Entry {
name: self._fields.0.unwrap(),
node: 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>,
>,
) -> Entry<'a> {
Entry {
name: self._fields.0.unwrap(),
node: self._fields.1.unwrap(),
extra_data: Some(extra_data),
}
}
}
pub mod file_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 Blob;
type Type;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Blob = Unset;
type Type = Unset;
}
pub struct SetBlob<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetBlob<S> {}
impl<S: State> State for SetBlob<S> {
type Blob = Set<members::blob>;
type Type = S::Type;
}
pub struct SetType<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetType<S> {}
impl<S: State> State for SetType<S> {
type Blob = S::Blob;
type Type = Set<members::r#type>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct blob(());
pub struct r#type(());
}
}
pub struct FileBuilder<'a, S: file_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (
Option<bool>,
Option<BlobRef<'a>>,
Option<CowStr<'a>>,
Option<CowStr<'a>>,
Option<CowStr<'a>>,
),
_lifetime: PhantomData<&'a ()>,
}
impl<'a> File<'a> {
pub fn new() -> FileBuilder<'a, file_state::Empty> {
FileBuilder::new()
}
}
impl<'a> FileBuilder<'a, file_state::Empty> {
pub fn new() -> Self {
FileBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None),
_lifetime: PhantomData,
}
}
}
impl<'a, S: file_state::State> FileBuilder<'a, S> {
pub fn base64(mut self, value: impl Into<Option<bool>>) -> Self {
self._fields.0 = value.into();
self
}
pub fn maybe_base64(mut self, value: Option<bool>) -> Self {
self._fields.0 = value;
self
}
}
impl<'a, S> FileBuilder<'a, S>
where
S: file_state::State,
S::Blob: file_state::IsUnset,
{
pub fn blob(
mut self,
value: impl Into<BlobRef<'a>>,
) -> FileBuilder<'a, file_state::SetBlob<S>> {
self._fields.1 = Option::Some(value.into());
FileBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S: file_state::State> FileBuilder<'a, S> {
pub fn encoding(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
self._fields.2 = value.into();
self
}
pub fn maybe_encoding(mut self, value: Option<CowStr<'a>>) -> Self {
self._fields.2 = value;
self
}
}
impl<'a, S: file_state::State> FileBuilder<'a, S> {
pub fn mime_type(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
self._fields.3 = value.into();
self
}
pub fn maybe_mime_type(mut self, value: Option<CowStr<'a>>) -> Self {
self._fields.3 = value;
self
}
}
impl<'a, S> FileBuilder<'a, S>
where
S: file_state::State,
S::Type: file_state::IsUnset,
{
pub fn r#type(
mut self,
value: impl Into<CowStr<'a>>,
) -> FileBuilder<'a, file_state::SetType<S>> {
self._fields.4 = Option::Some(value.into());
FileBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> FileBuilder<'a, S>
where
S: file_state::State,
S::Blob: file_state::IsSet,
S::Type: file_state::IsSet,
{
pub fn build(self) -> File<'a> {
File {
base64: self._fields.0,
blob: self._fields.1.unwrap(),
encoding: self._fields.2,
mime_type: self._fields.3,
r#type: self._fields.4.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>,
>,
) -> File<'a> {
File {
base64: self._fields.0,
blob: self._fields.1.unwrap(),
encoding: self._fields.2,
mime_type: self._fields.3,
r#type: self._fields.4.unwrap(),
extra_data: Some(extra_data),
}
}
}
pub mod fs_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 Site;
type Root;
type CreatedAt;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Site = Unset;
type Root = Unset;
type CreatedAt = Unset;
}
pub struct SetSite<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetSite<S> {}
impl<S: State> State for SetSite<S> {
type Site = Set<members::site>;
type Root = S::Root;
type CreatedAt = S::CreatedAt;
}
pub struct SetRoot<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetRoot<S> {}
impl<S: State> State for SetRoot<S> {
type Site = S::Site;
type Root = Set<members::root>;
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 Site = S::Site;
type Root = S::Root;
type CreatedAt = Set<members::created_at>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct site(());
pub struct root(());
pub struct created_at(());
}
}
pub struct FsBuilder<'a, S: fs_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (
Option<Datetime>,
Option<i64>,
Option<fs::Directory<'a>>,
Option<CowStr<'a>>,
),
_lifetime: PhantomData<&'a ()>,
}
impl<'a> Fs<'a> {
pub fn new() -> FsBuilder<'a, fs_state::Empty> {
FsBuilder::new()
}
}
impl<'a> FsBuilder<'a, fs_state::Empty> {
pub fn new() -> Self {
FsBuilder {
_state: PhantomData,
_fields: (None, None, None, None),
_lifetime: PhantomData,
}
}
}
impl<'a, S> FsBuilder<'a, S>
where
S: fs_state::State,
S::CreatedAt: fs_state::IsUnset,
{
pub fn created_at(
mut self,
value: impl Into<Datetime>,
) -> FsBuilder<'a, fs_state::SetCreatedAt<S>> {
self._fields.0 = Option::Some(value.into());
FsBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S: fs_state::State> FsBuilder<'a, S> {
pub fn file_count(mut self, value: impl Into<Option<i64>>) -> Self {
self._fields.1 = value.into();
self
}
pub fn maybe_file_count(mut self, value: Option<i64>) -> Self {
self._fields.1 = value;
self
}
}
impl<'a, S> FsBuilder<'a, S>
where
S: fs_state::State,
S::Root: fs_state::IsUnset,
{
pub fn root(
mut self,
value: impl Into<fs::Directory<'a>>,
) -> FsBuilder<'a, fs_state::SetRoot<S>> {
self._fields.2 = Option::Some(value.into());
FsBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> FsBuilder<'a, S>
where
S: fs_state::State,
S::Site: fs_state::IsUnset,
{
pub fn site(
mut self,
value: impl Into<CowStr<'a>>,
) -> FsBuilder<'a, fs_state::SetSite<S>> {
self._fields.3 = Option::Some(value.into());
FsBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> FsBuilder<'a, S>
where
S: fs_state::State,
S::Site: fs_state::IsSet,
S::Root: fs_state::IsSet,
S::CreatedAt: fs_state::IsSet,
{
pub fn build(self) -> Fs<'a> {
Fs {
created_at: self._fields.0.unwrap(),
file_count: self._fields.1,
root: self._fields.2.unwrap(),
site: 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>,
>,
) -> Fs<'a> {
Fs {
created_at: self._fields.0.unwrap(),
file_count: self._fields.1,
root: self._fields.2.unwrap(),
site: self._fields.3.unwrap(),
extra_data: Some(extra_data),
}
}
}
pub mod subfs_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 Subject;
type Type;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Subject = Unset;
type Type = Unset;
}
pub struct SetSubject<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetSubject<S> {}
impl<S: State> State for SetSubject<S> {
type Subject = Set<members::subject>;
type Type = S::Type;
}
pub struct SetType<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetType<S> {}
impl<S: State> State for SetType<S> {
type Subject = S::Subject;
type Type = Set<members::r#type>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct subject(());
pub struct r#type(());
}
}
pub struct SubfsBuilder<'a, S: subfs_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (Option<bool>, Option<AtUri<'a>>, Option<CowStr<'a>>),
_lifetime: PhantomData<&'a ()>,
}
impl<'a> Subfs<'a> {
pub fn new() -> SubfsBuilder<'a, subfs_state::Empty> {
SubfsBuilder::new()
}
}
impl<'a> SubfsBuilder<'a, subfs_state::Empty> {
pub fn new() -> Self {
SubfsBuilder {
_state: PhantomData,
_fields: (None, None, None),
_lifetime: PhantomData,
}
}
}
impl<'a, S: subfs_state::State> SubfsBuilder<'a, S> {
pub fn flat(mut self, value: impl Into<Option<bool>>) -> Self {
self._fields.0 = value.into();
self
}
pub fn maybe_flat(mut self, value: Option<bool>) -> Self {
self._fields.0 = value;
self
}
}
impl<'a, S> SubfsBuilder<'a, S>
where
S: subfs_state::State,
S::Subject: subfs_state::IsUnset,
{
pub fn subject(
mut self,
value: impl Into<AtUri<'a>>,
) -> SubfsBuilder<'a, subfs_state::SetSubject<S>> {
self._fields.1 = Option::Some(value.into());
SubfsBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> SubfsBuilder<'a, S>
where
S: subfs_state::State,
S::Type: subfs_state::IsUnset,
{
pub fn r#type(
mut self,
value: impl Into<CowStr<'a>>,
) -> SubfsBuilder<'a, subfs_state::SetType<S>> {
self._fields.2 = Option::Some(value.into());
SubfsBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> SubfsBuilder<'a, S>
where
S: subfs_state::State,
S::Subject: subfs_state::IsSet,
S::Type: subfs_state::IsSet,
{
pub fn build(self) -> Subfs<'a> {
Subfs {
flat: self._fields.0,
subject: self._fields.1.unwrap(),
r#type: self._fields.2.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>,
>,
) -> Subfs<'a> {
Subfs {
flat: self._fields.0,
subject: self._fields.1.unwrap(),
r#type: self._fields.2.unwrap(),
extra_data: Some(extra_data),
}
}
}