#[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};
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::at_inlay::pack;
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Export<'a> {
#[serde(borrow)]
pub component: AtUri<'a>,
#[serde(borrow)]
pub r#type: Nsid<'a>,
}
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Pack<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
pub created_at: Option<Datetime>,
#[serde(borrow)]
pub exports: Vec<pack::Export<'a>>,
#[serde(borrow)]
pub name: CowStr<'a>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct PackGetRecordOutput<'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: Pack<'a>,
}
impl<'a> Pack<'a> {
pub fn uri(
uri: impl Into<CowStr<'a>>,
) -> Result<RecordUri<'a, PackRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new_cow(uri.into())?)
}
}
impl<'a> LexiconSchema for Export<'a> {
fn nsid() -> &'static str {
"at.inlay.pack"
}
fn def_name() -> &'static str {
"export"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_at_inlay_pack()
}
fn validate(&self) -> Result<(), ConstraintError> {
Ok(())
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct PackRecord;
impl XrpcResp for PackRecord {
const NSID: &'static str = "at.inlay.pack";
const ENCODING: &'static str = "application/json";
type Output<'de> = PackGetRecordOutput<'de>;
type Err<'de> = RecordError<'de>;
}
impl From<PackGetRecordOutput<'_>> for Pack<'_> {
fn from(output: PackGetRecordOutput<'_>) -> Self {
use jacquard_common::IntoStatic;
output.value.into_static()
}
}
impl Collection for Pack<'_> {
const NSID: &'static str = "at.inlay.pack";
type Record = PackRecord;
}
impl Collection for PackRecord {
const NSID: &'static str = "at.inlay.pack";
type Record = PackRecord;
}
impl<'a> LexiconSchema for Pack<'a> {
fn nsid() -> &'static str {
"at.inlay.pack"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_at_inlay_pack()
}
fn validate(&self) -> Result<(), ConstraintError> {
{
let value = &self.name;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 64usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("name"),
max: 64usize,
actual: <str>::len(value.as_ref()),
});
}
}
Ok(())
}
}
pub mod export_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 Type;
type Component;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Type = Unset;
type Component = Unset;
}
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 Type = Set<members::r#type>;
type Component = S::Component;
}
pub struct SetComponent<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetComponent<S> {}
impl<S: State> State for SetComponent<S> {
type Type = S::Type;
type Component = Set<members::component>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct r#type(());
pub struct component(());
}
}
pub struct ExportBuilder<'a, S: export_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (Option<AtUri<'a>>, Option<Nsid<'a>>),
_lifetime: PhantomData<&'a ()>,
}
impl<'a> Export<'a> {
pub fn new() -> ExportBuilder<'a, export_state::Empty> {
ExportBuilder::new()
}
}
impl<'a> ExportBuilder<'a, export_state::Empty> {
pub fn new() -> Self {
ExportBuilder {
_state: PhantomData,
_fields: (None, None),
_lifetime: PhantomData,
}
}
}
impl<'a, S> ExportBuilder<'a, S>
where
S: export_state::State,
S::Component: export_state::IsUnset,
{
pub fn component(
mut self,
value: impl Into<AtUri<'a>>,
) -> ExportBuilder<'a, export_state::SetComponent<S>> {
self._fields.0 = Option::Some(value.into());
ExportBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> ExportBuilder<'a, S>
where
S: export_state::State,
S::Type: export_state::IsUnset,
{
pub fn r#type(
mut self,
value: impl Into<Nsid<'a>>,
) -> ExportBuilder<'a, export_state::SetType<S>> {
self._fields.1 = Option::Some(value.into());
ExportBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> ExportBuilder<'a, S>
where
S: export_state::State,
S::Type: export_state::IsSet,
S::Component: export_state::IsSet,
{
pub fn build(self) -> Export<'a> {
Export {
component: 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>,
>,
) -> Export<'a> {
Export {
component: self._fields.0.unwrap(),
r#type: self._fields.1.unwrap(),
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_at_inlay_pack() -> 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("at.inlay.pack"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("export"),
LexUserType::Object(LexObject {
required: Some(
vec![
SmolStr::new_static("type"), SmolStr::new_static("component")
],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("component"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("AT-URI of the component record"),
),
format: Some(LexStringFormat::AtUri),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("type"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("NSID of the type being exported"),
),
format: Some(LexStringFormat::Nsid),
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map.insert(
SmolStr::new_static("main"),
LexUserType::Record(LexRecord {
description: Some(
CowStr::new_static("A list of type to component exports"),
),
key: Some(CowStr::new_static("tid")),
record: LexRecordRecord::Object(LexObject {
required: Some(
vec![
SmolStr::new_static("name"), SmolStr::new_static("exports")
],
),
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("exports"),
LexObjectProperty::Array(LexArray {
description: Some(
CowStr::new_static("Type to component mappings"),
),
items: LexArrayItem::Ref(LexRef {
r#ref: CowStr::new_static("#export"),
..Default::default()
}),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("name"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Short slug for the pack (e.g. \"core\", \"ui\")",
),
),
max_length: Some(64usize),
..Default::default()
}),
);
map
},
..Default::default()
}),
..Default::default()
}),
);
map
},
..Default::default()
}
}
pub mod pack_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 Exports;
type Name;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Exports = Unset;
type Name = Unset;
}
pub struct SetExports<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetExports<S> {}
impl<S: State> State for SetExports<S> {
type Exports = Set<members::exports>;
type Name = S::Name;
}
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 Exports = S::Exports;
type Name = Set<members::name>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct exports(());
pub struct name(());
}
}
pub struct PackBuilder<'a, S: pack_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (Option<Datetime>, Option<Vec<pack::Export<'a>>>, Option<CowStr<'a>>),
_lifetime: PhantomData<&'a ()>,
}
impl<'a> Pack<'a> {
pub fn new() -> PackBuilder<'a, pack_state::Empty> {
PackBuilder::new()
}
}
impl<'a> PackBuilder<'a, pack_state::Empty> {
pub fn new() -> Self {
PackBuilder {
_state: PhantomData,
_fields: (None, None, None),
_lifetime: PhantomData,
}
}
}
impl<'a, S: pack_state::State> PackBuilder<'a, S> {
pub fn created_at(mut self, value: impl Into<Option<Datetime>>) -> Self {
self._fields.0 = value.into();
self
}
pub fn maybe_created_at(mut self, value: Option<Datetime>) -> Self {
self._fields.0 = value;
self
}
}
impl<'a, S> PackBuilder<'a, S>
where
S: pack_state::State,
S::Exports: pack_state::IsUnset,
{
pub fn exports(
mut self,
value: impl Into<Vec<pack::Export<'a>>>,
) -> PackBuilder<'a, pack_state::SetExports<S>> {
self._fields.1 = Option::Some(value.into());
PackBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> PackBuilder<'a, S>
where
S: pack_state::State,
S::Name: pack_state::IsUnset,
{
pub fn name(
mut self,
value: impl Into<CowStr<'a>>,
) -> PackBuilder<'a, pack_state::SetName<S>> {
self._fields.2 = Option::Some(value.into());
PackBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> PackBuilder<'a, S>
where
S: pack_state::State,
S::Exports: pack_state::IsSet,
S::Name: pack_state::IsSet,
{
pub fn build(self) -> Pack<'a> {
Pack {
created_at: self._fields.0,
exports: self._fields.1.unwrap(),
name: 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>,
>,
) -> Pack<'a> {
Pack {
created_at: self._fields.0,
exports: self._fields.1.unwrap(),
name: self._fields.2.unwrap(),
extra_data: Some(extra_data),
}
}
}