#[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, Datetime, 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 = "to.atpr.link",
tag = "$type",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Link<S: BosStr = DefaultStr> {
pub updated_at: Datetime,
pub url: UriValue<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 LinkGetRecordOutput<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub cid: Option<Cid<S>>,
pub uri: AtUri<S>,
pub value: Link<S>,
}
impl<S: BosStr> Link<S> {
pub fn uri(uri: S) -> Result<RecordUri<S, LinkRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new(uri)?)
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct LinkRecord;
impl XrpcResp for LinkRecord {
const NSID: &'static str = "to.atpr.link";
const ENCODING: &'static str = "application/json";
type Output<S: BosStr> = LinkGetRecordOutput<S>;
type Err = RecordError;
}
impl<S: BosStr> From<LinkGetRecordOutput<S>> for Link<S> {
fn from(output: LinkGetRecordOutput<S>) -> Self {
output.value
}
}
impl<S: BosStr> Collection for Link<S> {
const NSID: &'static str = "to.atpr.link";
type Record = LinkRecord;
}
impl Collection for LinkRecord {
const NSID: &'static str = "to.atpr.link";
type Record = LinkRecord;
}
impl<S: BosStr> LexiconSchema for Link<S> {
fn nsid() -> &'static str {
"to.atpr.link"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_to_atpr_link()
}
fn validate(&self) -> Result<(), ConstraintError> {
{
let value = &self.url;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 2048usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("url"),
max: 2048usize,
actual: <str>::len(value.as_ref()),
});
}
}
Ok(())
}
}
pub mod link_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 UpdatedAt;
type Url;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type UpdatedAt = Unset;
type Url = Unset;
}
pub struct SetUpdatedAt<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetUpdatedAt<St> {}
impl<St: State> State for SetUpdatedAt<St> {
type UpdatedAt = Set<members::updated_at>;
type Url = St::Url;
}
pub struct SetUrl<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetUrl<St> {}
impl<St: State> State for SetUrl<St> {
type UpdatedAt = St::UpdatedAt;
type Url = Set<members::url>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct updated_at(());
pub struct url(());
}
}
pub struct LinkBuilder<S: BosStr, St: link_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (Option<Datetime>, Option<UriValue<S>>),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> Link<S> {
pub fn new() -> LinkBuilder<S, link_state::Empty> {
LinkBuilder::new()
}
}
impl<S: BosStr> LinkBuilder<S, link_state::Empty> {
pub fn new() -> Self {
LinkBuilder {
_state: PhantomData,
_fields: (None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St> LinkBuilder<S, St>
where
St: link_state::State,
St::UpdatedAt: link_state::IsUnset,
{
pub fn updated_at(
mut self,
value: impl Into<Datetime>,
) -> LinkBuilder<S, link_state::SetUpdatedAt<St>> {
self._fields.0 = Option::Some(value.into());
LinkBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> LinkBuilder<S, St>
where
St: link_state::State,
St::Url: link_state::IsUnset,
{
pub fn url(mut self, value: impl Into<UriValue<S>>) -> LinkBuilder<S, link_state::SetUrl<St>> {
self._fields.1 = Option::Some(value.into());
LinkBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> LinkBuilder<S, St>
where
St: link_state::State,
St::UpdatedAt: link_state::IsSet,
St::Url: link_state::IsSet,
{
pub fn build(self) -> Link<S> {
Link {
updated_at: self._fields.0.unwrap(),
url: self._fields.1.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Link<S> {
Link {
updated_at: self._fields.0.unwrap(),
url: self._fields.1.unwrap(),
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_to_atpr_link() -> 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("to.atpr.link"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("main"),
LexUserType::Record(LexRecord {
description: Some(CowStr::new_static("A shortened URL mapping")),
key: Some(CowStr::new_static("any")),
record: LexRecordRecord::Object(LexObject {
required: Some(vec![
SmolStr::new_static("url"),
SmolStr::new_static("updatedAt"),
]),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("updatedAt"),
LexObjectProperty::String(LexString {
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("url"),
LexObjectProperty::String(LexString {
format: Some(LexStringFormat::Uri),
max_length: Some(2048usize),
..Default::default()
}),
);
map
},
..Default::default()
}),
..Default::default()
}),
);
map
},
..Default::default()
}
}