#[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};
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 = "diy.razorgirl.winter.wikiLink",
tag = "$type",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct WikiLink<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub context: Option<S>,
pub created_at: Datetime,
pub link_type: WikiLinkLinkType<S>,
pub source: AtUri<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub source_anchor: Option<S>,
pub target: AtUri<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub target_anchor: 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 WikiLinkLinkType<S: BosStr = DefaultStr> {
RelatedTo,
DependsOn,
Extends,
Contradicts,
IsExampleOf,
Supersedes,
References,
Defines,
IsPartOf,
Other(S),
}
impl<S: BosStr> WikiLinkLinkType<S> {
pub fn as_str(&self) -> &str {
match self {
Self::RelatedTo => "related-to",
Self::DependsOn => "depends-on",
Self::Extends => "extends",
Self::Contradicts => "contradicts",
Self::IsExampleOf => "is-example-of",
Self::Supersedes => "supersedes",
Self::References => "references",
Self::Defines => "defines",
Self::IsPartOf => "is-part-of",
Self::Other(s) => s.as_ref(),
}
}
pub fn from_value(s: S) -> Self {
match s.as_ref() {
"related-to" => Self::RelatedTo,
"depends-on" => Self::DependsOn,
"extends" => Self::Extends,
"contradicts" => Self::Contradicts,
"is-example-of" => Self::IsExampleOf,
"supersedes" => Self::Supersedes,
"references" => Self::References,
"defines" => Self::Defines,
"is-part-of" => Self::IsPartOf,
_ => Self::Other(s),
}
}
}
impl<S: BosStr> core::fmt::Display for WikiLinkLinkType<S> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<S: BosStr> AsRef<str> for WikiLinkLinkType<S> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<S: BosStr> Serialize for WikiLinkLinkType<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 WikiLinkLinkType<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 WikiLinkLinkType<S> {
fn default() -> Self {
Self::Other(Default::default())
}
}
impl<S: BosStr> jacquard_common::IntoStatic for WikiLinkLinkType<S>
where
S: BosStr + jacquard_common::IntoStatic,
S::Output: BosStr,
{
type Output = WikiLinkLinkType<S::Output>;
fn into_static(self) -> Self::Output {
match self {
WikiLinkLinkType::RelatedTo => WikiLinkLinkType::RelatedTo,
WikiLinkLinkType::DependsOn => WikiLinkLinkType::DependsOn,
WikiLinkLinkType::Extends => WikiLinkLinkType::Extends,
WikiLinkLinkType::Contradicts => WikiLinkLinkType::Contradicts,
WikiLinkLinkType::IsExampleOf => WikiLinkLinkType::IsExampleOf,
WikiLinkLinkType::Supersedes => WikiLinkLinkType::Supersedes,
WikiLinkLinkType::References => WikiLinkLinkType::References,
WikiLinkLinkType::Defines => WikiLinkLinkType::Defines,
WikiLinkLinkType::IsPartOf => WikiLinkLinkType::IsPartOf,
WikiLinkLinkType::Other(v) => WikiLinkLinkType::Other(v.into_static()),
}
}
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct WikiLinkGetRecordOutput<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub cid: Option<Cid<S>>,
pub uri: AtUri<S>,
pub value: WikiLink<S>,
}
impl<S: BosStr> WikiLink<S> {
pub fn uri(uri: S) -> Result<RecordUri<S, WikiLinkRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new(uri)?)
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct WikiLinkRecord;
impl XrpcResp for WikiLinkRecord {
const NSID: &'static str = "diy.razorgirl.winter.wikiLink";
const ENCODING: &'static str = "application/json";
type Output<S: BosStr> = WikiLinkGetRecordOutput<S>;
type Err = RecordError;
}
impl<S: BosStr> From<WikiLinkGetRecordOutput<S>> for WikiLink<S> {
fn from(output: WikiLinkGetRecordOutput<S>) -> Self {
output.value
}
}
impl<S: BosStr> Collection for WikiLink<S> {
const NSID: &'static str = "diy.razorgirl.winter.wikiLink";
type Record = WikiLinkRecord;
}
impl Collection for WikiLinkRecord {
const NSID: &'static str = "diy.razorgirl.winter.wikiLink";
type Record = WikiLinkRecord;
}
impl<S: BosStr> LexiconSchema for WikiLink<S> {
fn nsid() -> &'static str {
"diy.razorgirl.winter.wikiLink"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_diy_razorgirl_winter_wikiLink()
}
fn validate(&self) -> Result<(), ConstraintError> {
if let Some(ref value) = self.context {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 512usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("context"),
max: 512usize,
actual: <str>::len(value.as_ref()),
});
}
}
Ok(())
}
}
pub mod wiki_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 LinkType;
type Target;
type Source;
type CreatedAt;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type LinkType = Unset;
type Target = Unset;
type Source = Unset;
type CreatedAt = Unset;
}
pub struct SetLinkType<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetLinkType<St> {}
impl<St: State> State for SetLinkType<St> {
type LinkType = Set<members::link_type>;
type Target = St::Target;
type Source = St::Source;
type CreatedAt = St::CreatedAt;
}
pub struct SetTarget<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetTarget<St> {}
impl<St: State> State for SetTarget<St> {
type LinkType = St::LinkType;
type Target = Set<members::target>;
type Source = St::Source;
type CreatedAt = St::CreatedAt;
}
pub struct SetSource<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetSource<St> {}
impl<St: State> State for SetSource<St> {
type LinkType = St::LinkType;
type Target = St::Target;
type Source = Set<members::source>;
type CreatedAt = St::CreatedAt;
}
pub struct SetCreatedAt<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetCreatedAt<St> {}
impl<St: State> State for SetCreatedAt<St> {
type LinkType = St::LinkType;
type Target = St::Target;
type Source = St::Source;
type CreatedAt = Set<members::created_at>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct link_type(());
pub struct target(());
pub struct source(());
pub struct created_at(());
}
}
pub struct WikiLinkBuilder<S: BosStr, St: wiki_link_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<S>,
Option<Datetime>,
Option<WikiLinkLinkType<S>>,
Option<AtUri<S>>,
Option<S>,
Option<AtUri<S>>,
Option<S>,
),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> WikiLink<S> {
pub fn new() -> WikiLinkBuilder<S, wiki_link_state::Empty> {
WikiLinkBuilder::new()
}
}
impl<S: BosStr> WikiLinkBuilder<S, wiki_link_state::Empty> {
pub fn new() -> Self {
WikiLinkBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St: wiki_link_state::State> WikiLinkBuilder<S, St> {
pub fn context(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.0 = value.into();
self
}
pub fn maybe_context(mut self, value: Option<S>) -> Self {
self._fields.0 = value;
self
}
}
impl<S: BosStr, St> WikiLinkBuilder<S, St>
where
St: wiki_link_state::State,
St::CreatedAt: wiki_link_state::IsUnset,
{
pub fn created_at(
mut self,
value: impl Into<Datetime>,
) -> WikiLinkBuilder<S, wiki_link_state::SetCreatedAt<St>> {
self._fields.1 = Option::Some(value.into());
WikiLinkBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> WikiLinkBuilder<S, St>
where
St: wiki_link_state::State,
St::LinkType: wiki_link_state::IsUnset,
{
pub fn link_type(
mut self,
value: impl Into<WikiLinkLinkType<S>>,
) -> WikiLinkBuilder<S, wiki_link_state::SetLinkType<St>> {
self._fields.2 = Option::Some(value.into());
WikiLinkBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> WikiLinkBuilder<S, St>
where
St: wiki_link_state::State,
St::Source: wiki_link_state::IsUnset,
{
pub fn source(
mut self,
value: impl Into<AtUri<S>>,
) -> WikiLinkBuilder<S, wiki_link_state::SetSource<St>> {
self._fields.3 = Option::Some(value.into());
WikiLinkBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: wiki_link_state::State> WikiLinkBuilder<S, St> {
pub fn source_anchor(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.4 = value.into();
self
}
pub fn maybe_source_anchor(mut self, value: Option<S>) -> Self {
self._fields.4 = value;
self
}
}
impl<S: BosStr, St> WikiLinkBuilder<S, St>
where
St: wiki_link_state::State,
St::Target: wiki_link_state::IsUnset,
{
pub fn target(
mut self,
value: impl Into<AtUri<S>>,
) -> WikiLinkBuilder<S, wiki_link_state::SetTarget<St>> {
self._fields.5 = Option::Some(value.into());
WikiLinkBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: wiki_link_state::State> WikiLinkBuilder<S, St> {
pub fn target_anchor(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.6 = value.into();
self
}
pub fn maybe_target_anchor(mut self, value: Option<S>) -> Self {
self._fields.6 = value;
self
}
}
impl<S: BosStr, St> WikiLinkBuilder<S, St>
where
St: wiki_link_state::State,
St::LinkType: wiki_link_state::IsSet,
St::Target: wiki_link_state::IsSet,
St::Source: wiki_link_state::IsSet,
St::CreatedAt: wiki_link_state::IsSet,
{
pub fn build(self) -> WikiLink<S> {
WikiLink {
context: self._fields.0,
created_at: self._fields.1.unwrap(),
link_type: self._fields.2.unwrap(),
source: self._fields.3.unwrap(),
source_anchor: self._fields.4,
target: self._fields.5.unwrap(),
target_anchor: self._fields.6,
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> WikiLink<S> {
WikiLink {
context: self._fields.0,
created_at: self._fields.1.unwrap(),
link_type: self._fields.2.unwrap(),
source: self._fields.3.unwrap(),
source_anchor: self._fields.4,
target: self._fields.5.unwrap(),
target_anchor: self._fields.6,
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_diy_razorgirl_winter_wikiLink() -> 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("diy.razorgirl.winter.wikiLink"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("main"),
LexUserType::Record(LexRecord {
key: Some(CowStr::new_static("tid")),
record: LexRecordRecord::Object(LexObject {
required: Some(vec![
SmolStr::new_static("source"),
SmolStr::new_static("target"),
SmolStr::new_static("linkType"),
SmolStr::new_static("createdAt"),
]),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("context"),
LexObjectProperty::String(LexString {
description: Some(CowStr::new_static("Why this link exists")),
max_length: Some(512usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("createdAt"),
LexObjectProperty::String(LexString {
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("linkType"),
LexObjectProperty::String(LexString {
..Default::default()
}),
);
map.insert(
SmolStr::new_static("source"),
LexObjectProperty::String(LexString {
format: Some(LexStringFormat::AtUri),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("sourceAnchor"),
LexObjectProperty::String(LexString {
description: Some(CowStr::new_static(
"Section heading slug in source",
)),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("target"),
LexObjectProperty::String(LexString {
format: Some(LexStringFormat::AtUri),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("targetAnchor"),
LexObjectProperty::String(LexString {
description: Some(CowStr::new_static(
"Section heading slug in target",
)),
..Default::default()
}),
);
map
},
..Default::default()
}),
..Default::default()
}),
);
map
},
..Default::default()
}
}