#[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;
use crate::sh_tangled::label::op;
#[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 = "sh.tangled.label.op",
tag = "$type",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Op<S: BosStr = DefaultStr> {
pub add: Vec<op::Operand<S>>,
pub delete: Vec<op::Operand<S>>,
pub performed_at: Datetime,
pub subject: AtUri<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 OpGetRecordOutput<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub cid: Option<Cid<S>>,
pub uri: AtUri<S>,
pub value: Op<S>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
rename_all = "camelCase",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Operand<S: BosStr = DefaultStr> {
pub key: AtUri<S>,
pub value: S,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
impl<S: BosStr> Op<S> {
pub fn uri(uri: S) -> Result<RecordUri<S, OpRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new(uri)?)
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct OpRecord;
impl XrpcResp for OpRecord {
const NSID: &'static str = "sh.tangled.label.op";
const ENCODING: &'static str = "application/json";
type Output<S: BosStr> = OpGetRecordOutput<S>;
type Err = RecordError;
}
impl<S: BosStr> From<OpGetRecordOutput<S>> for Op<S> {
fn from(output: OpGetRecordOutput<S>) -> Self {
output.value
}
}
impl<S: BosStr> Collection for Op<S> {
const NSID: &'static str = "sh.tangled.label.op";
type Record = OpRecord;
}
impl Collection for OpRecord {
const NSID: &'static str = "sh.tangled.label.op";
type Record = OpRecord;
}
impl<S: BosStr> LexiconSchema for Op<S> {
fn nsid() -> &'static str {
"sh.tangled.label.op"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_sh_tangled_label_op()
}
fn validate(&self) -> Result<(), ConstraintError> {
Ok(())
}
}
impl<S: BosStr> LexiconSchema for Operand<S> {
fn nsid() -> &'static str {
"sh.tangled.label.op"
}
fn def_name() -> &'static str {
"operand"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_sh_tangled_label_op()
}
fn validate(&self) -> Result<(), ConstraintError> {
Ok(())
}
}
pub mod op_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 Subject;
type Add;
type PerformedAt;
type Delete;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Subject = Unset;
type Add = Unset;
type PerformedAt = Unset;
type Delete = Unset;
}
pub struct SetSubject<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetSubject<St> {}
impl<St: State> State for SetSubject<St> {
type Subject = Set<members::subject>;
type Add = St::Add;
type PerformedAt = St::PerformedAt;
type Delete = St::Delete;
}
pub struct SetAdd<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetAdd<St> {}
impl<St: State> State for SetAdd<St> {
type Subject = St::Subject;
type Add = Set<members::add>;
type PerformedAt = St::PerformedAt;
type Delete = St::Delete;
}
pub struct SetPerformedAt<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetPerformedAt<St> {}
impl<St: State> State for SetPerformedAt<St> {
type Subject = St::Subject;
type Add = St::Add;
type PerformedAt = Set<members::performed_at>;
type Delete = St::Delete;
}
pub struct SetDelete<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetDelete<St> {}
impl<St: State> State for SetDelete<St> {
type Subject = St::Subject;
type Add = St::Add;
type PerformedAt = St::PerformedAt;
type Delete = Set<members::delete>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct subject(());
pub struct add(());
pub struct performed_at(());
pub struct delete(());
}
}
pub struct OpBuilder<S: BosStr, St: op_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<Vec<op::Operand<S>>>,
Option<Vec<op::Operand<S>>>,
Option<Datetime>,
Option<AtUri<S>>,
),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> Op<S> {
pub fn new() -> OpBuilder<S, op_state::Empty> {
OpBuilder::new()
}
}
impl<S: BosStr> OpBuilder<S, op_state::Empty> {
pub fn new() -> Self {
OpBuilder {
_state: PhantomData,
_fields: (None, None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St> OpBuilder<S, St>
where
St: op_state::State,
St::Add: op_state::IsUnset,
{
pub fn add(
mut self,
value: impl Into<Vec<op::Operand<S>>>,
) -> OpBuilder<S, op_state::SetAdd<St>> {
self._fields.0 = Option::Some(value.into());
OpBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> OpBuilder<S, St>
where
St: op_state::State,
St::Delete: op_state::IsUnset,
{
pub fn delete(
mut self,
value: impl Into<Vec<op::Operand<S>>>,
) -> OpBuilder<S, op_state::SetDelete<St>> {
self._fields.1 = Option::Some(value.into());
OpBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> OpBuilder<S, St>
where
St: op_state::State,
St::PerformedAt: op_state::IsUnset,
{
pub fn performed_at(
mut self,
value: impl Into<Datetime>,
) -> OpBuilder<S, op_state::SetPerformedAt<St>> {
self._fields.2 = Option::Some(value.into());
OpBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> OpBuilder<S, St>
where
St: op_state::State,
St::Subject: op_state::IsUnset,
{
pub fn subject(mut self, value: impl Into<AtUri<S>>) -> OpBuilder<S, op_state::SetSubject<St>> {
self._fields.3 = Option::Some(value.into());
OpBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> OpBuilder<S, St>
where
St: op_state::State,
St::Subject: op_state::IsSet,
St::Add: op_state::IsSet,
St::PerformedAt: op_state::IsSet,
St::Delete: op_state::IsSet,
{
pub fn build(self) -> Op<S> {
Op {
add: self._fields.0.unwrap(),
delete: self._fields.1.unwrap(),
performed_at: self._fields.2.unwrap(),
subject: self._fields.3.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Op<S> {
Op {
add: self._fields.0.unwrap(),
delete: self._fields.1.unwrap(),
performed_at: self._fields.2.unwrap(),
subject: self._fields.3.unwrap(),
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_sh_tangled_label_op() -> 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("sh.tangled.label.op"),
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("subject"), SmolStr::new_static("add"),
SmolStr::new_static("delete"),
SmolStr::new_static("performedAt")
],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("add"),
LexObjectProperty::Array(LexArray {
items: LexArrayItem::Ref(LexRef {
r#ref: CowStr::new_static("#operand"),
..Default::default()
}),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("delete"),
LexObjectProperty::Array(LexArray {
items: LexArrayItem::Ref(LexRef {
r#ref: CowStr::new_static("#operand"),
..Default::default()
}),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("performedAt"),
LexObjectProperty::String(LexString {
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("subject"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"The subject (task, pull or discussion) of this label. Appviews may apply a `scope` check and refuse this op.",
),
),
format: Some(LexStringFormat::AtUri),
..Default::default()
}),
);
map
},
..Default::default()
}),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("operand"),
LexUserType::Object(LexObject {
required: Some(
vec![SmolStr::new_static("key"), SmolStr::new_static("value")],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("key"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("ATURI to the label definition"),
),
format: Some(LexStringFormat::AtUri),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("value"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Stringified value of the label. This is first unstringed by appviews and then interpreted as a concrete value.",
),
),
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map
},
..Default::default()
}
}
pub mod operand_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 Key;
type Value;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Key = Unset;
type Value = Unset;
}
pub struct SetKey<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetKey<St> {}
impl<St: State> State for SetKey<St> {
type Key = Set<members::key>;
type Value = St::Value;
}
pub struct SetValue<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetValue<St> {}
impl<St: State> State for SetValue<St> {
type Key = St::Key;
type Value = Set<members::value>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct key(());
pub struct value(());
}
}
pub struct OperandBuilder<S: BosStr, St: operand_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (Option<AtUri<S>>, Option<S>),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> Operand<S> {
pub fn new() -> OperandBuilder<S, operand_state::Empty> {
OperandBuilder::new()
}
}
impl<S: BosStr> OperandBuilder<S, operand_state::Empty> {
pub fn new() -> Self {
OperandBuilder {
_state: PhantomData,
_fields: (None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St> OperandBuilder<S, St>
where
St: operand_state::State,
St::Key: operand_state::IsUnset,
{
pub fn key(
mut self,
value: impl Into<AtUri<S>>,
) -> OperandBuilder<S, operand_state::SetKey<St>> {
self._fields.0 = Option::Some(value.into());
OperandBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> OperandBuilder<S, St>
where
St: operand_state::State,
St::Value: operand_state::IsUnset,
{
pub fn value(mut self, value: impl Into<S>) -> OperandBuilder<S, operand_state::SetValue<St>> {
self._fields.1 = Option::Some(value.into());
OperandBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> OperandBuilder<S, St>
where
St: operand_state::State,
St::Key: operand_state::IsSet,
St::Value: operand_state::IsSet,
{
pub fn build(self) -> Operand<S> {
Operand {
key: self._fields.0.unwrap(),
value: self._fields.1.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Operand<S> {
Operand {
key: self._fields.0.unwrap(),
value: self._fields.1.unwrap(),
extra_data: Some(extra_data),
}
}
}