pub mod daily;
pub mod monthly;
pub mod weekly;
pub mod yearly;
#[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::net_anisota::chronicle::expedition::ChronicleSignature;
#[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 = "net.anisota.chronicle.log",
tag = "$type",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Log<S: BosStr = DefaultStr> {
pub created_at: Datetime,
#[serde(skip_serializing_if = "Option::is_none")]
pub detail: Option<S>,
pub event: S,
#[serde(skip_serializing_if = "Option::is_none")]
pub expedition_ref: Option<S>,
pub occurred_at: Datetime,
pub signature: ChronicleSignature<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub subject: Option<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 LogGetRecordOutput<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub cid: Option<Cid<S>>,
pub uri: AtUri<S>,
pub value: Log<S>,
}
impl<S: BosStr> Log<S> {
pub fn uri(uri: S) -> Result<RecordUri<S, LogRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new(uri)?)
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct LogRecord;
impl XrpcResp for LogRecord {
const NSID: &'static str = "net.anisota.chronicle.log";
const ENCODING: &'static str = "application/json";
type Output<S: BosStr> = LogGetRecordOutput<S>;
type Err = RecordError;
}
impl<S: BosStr> From<LogGetRecordOutput<S>> for Log<S> {
fn from(output: LogGetRecordOutput<S>) -> Self {
output.value
}
}
impl<S: BosStr> Collection for Log<S> {
const NSID: &'static str = "net.anisota.chronicle.log";
type Record = LogRecord;
}
impl Collection for LogRecord {
const NSID: &'static str = "net.anisota.chronicle.log";
type Record = LogRecord;
}
impl<S: BosStr> LexiconSchema for Log<S> {
fn nsid() -> &'static str {
"net.anisota.chronicle.log"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_net_anisota_chronicle_log()
}
fn validate(&self) -> Result<(), ConstraintError> {
Ok(())
}
}
pub mod log_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 CreatedAt;
type Event;
type OccurredAt;
type Signature;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type CreatedAt = Unset;
type Event = Unset;
type OccurredAt = Unset;
type Signature = Unset;
}
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 CreatedAt = Set<members::created_at>;
type Event = St::Event;
type OccurredAt = St::OccurredAt;
type Signature = St::Signature;
}
pub struct SetEvent<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetEvent<St> {}
impl<St: State> State for SetEvent<St> {
type CreatedAt = St::CreatedAt;
type Event = Set<members::event>;
type OccurredAt = St::OccurredAt;
type Signature = St::Signature;
}
pub struct SetOccurredAt<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetOccurredAt<St> {}
impl<St: State> State for SetOccurredAt<St> {
type CreatedAt = St::CreatedAt;
type Event = St::Event;
type OccurredAt = Set<members::occurred_at>;
type Signature = St::Signature;
}
pub struct SetSignature<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetSignature<St> {}
impl<St: State> State for SetSignature<St> {
type CreatedAt = St::CreatedAt;
type Event = St::Event;
type OccurredAt = St::OccurredAt;
type Signature = Set<members::signature>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct created_at(());
pub struct event(());
pub struct occurred_at(());
pub struct signature(());
}
}
pub struct LogBuilder<St: log_state::State, S: BosStr = DefaultStr> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<Datetime>,
Option<S>,
Option<S>,
Option<S>,
Option<Datetime>,
Option<ChronicleSignature<S>>,
Option<S>,
),
_type: PhantomData<fn() -> S>,
}
impl Log<DefaultStr> {
pub fn new() -> LogBuilder<log_state::Empty, DefaultStr> {
LogBuilder::new()
}
}
impl<S: BosStr> Log<S> {
pub fn builder() -> LogBuilder<log_state::Empty, S> {
LogBuilder::builder()
}
}
impl LogBuilder<log_state::Empty, DefaultStr> {
pub fn new() -> Self {
LogBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr> LogBuilder<log_state::Empty, S> {
pub fn builder() -> Self {
LogBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None, None),
_type: PhantomData,
}
}
}
impl<St, S: BosStr> LogBuilder<St, S>
where
St: log_state::State,
St::CreatedAt: log_state::IsUnset,
{
pub fn created_at(
mut self,
value: impl Into<Datetime>,
) -> LogBuilder<log_state::SetCreatedAt<St>, S> {
self._fields.0 = Option::Some(value.into());
LogBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<St: log_state::State, S: BosStr> LogBuilder<St, S> {
pub fn detail(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.1 = value.into();
self
}
pub fn maybe_detail(mut self, value: Option<S>) -> Self {
self._fields.1 = value;
self
}
}
impl<St, S: BosStr> LogBuilder<St, S>
where
St: log_state::State,
St::Event: log_state::IsUnset,
{
pub fn event(mut self, value: impl Into<S>) -> LogBuilder<log_state::SetEvent<St>, S> {
self._fields.2 = Option::Some(value.into());
LogBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<St: log_state::State, S: BosStr> LogBuilder<St, S> {
pub fn expedition_ref(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.3 = value.into();
self
}
pub fn maybe_expedition_ref(mut self, value: Option<S>) -> Self {
self._fields.3 = value;
self
}
}
impl<St, S: BosStr> LogBuilder<St, S>
where
St: log_state::State,
St::OccurredAt: log_state::IsUnset,
{
pub fn occurred_at(
mut self,
value: impl Into<Datetime>,
) -> LogBuilder<log_state::SetOccurredAt<St>, S> {
self._fields.4 = Option::Some(value.into());
LogBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<St, S: BosStr> LogBuilder<St, S>
where
St: log_state::State,
St::Signature: log_state::IsUnset,
{
pub fn signature(
mut self,
value: impl Into<ChronicleSignature<S>>,
) -> LogBuilder<log_state::SetSignature<St>, S> {
self._fields.5 = Option::Some(value.into());
LogBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<St: log_state::State, S: BosStr> LogBuilder<St, S> {
pub fn subject(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.6 = value.into();
self
}
pub fn maybe_subject(mut self, value: Option<S>) -> Self {
self._fields.6 = value;
self
}
}
impl<St, S: BosStr> LogBuilder<St, S>
where
St: log_state::State,
St::CreatedAt: log_state::IsSet,
St::Event: log_state::IsSet,
St::OccurredAt: log_state::IsSet,
St::Signature: log_state::IsSet,
{
pub fn build(self) -> Log<S> {
Log {
created_at: self._fields.0.unwrap(),
detail: self._fields.1,
event: self._fields.2.unwrap(),
expedition_ref: self._fields.3,
occurred_at: self._fields.4.unwrap(),
signature: self._fields.5.unwrap(),
subject: self._fields.6,
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Log<S> {
Log {
created_at: self._fields.0.unwrap(),
detail: self._fields.1,
event: self._fields.2.unwrap(),
expedition_ref: self._fields.3,
occurred_at: self._fields.4.unwrap(),
signature: self._fields.5.unwrap(),
subject: self._fields.6,
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_net_anisota_chronicle_log() -> 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("net.anisota.chronicle.log"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("main"),
LexUserType::Record(LexRecord {
description: Some(
CowStr::new_static(
"Granular chronicle event log. Each record is a single timestamped event. TID rkey for chronological ordering. Used to capture moments that don't have their own record type (moth sightings, random encounters, item discoveries, etc).",
),
),
key: Some(CowStr::new_static("tid")),
record: LexRecordRecord::Object(LexObject {
required: Some(
vec![
SmolStr::new_static("event"),
SmolStr::new_static("occurredAt"),
SmolStr::new_static("signature"),
SmolStr::new_static("createdAt")
],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("createdAt"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("When the record was created"),
),
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("detail"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Extra context (rarity, reason, conditions, etc.)",
),
),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("event"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Event type. Extensible — new values added as features grow.",
),
),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("expeditionRef"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"AT URI of the parent expedition (if during an expedition)",
),
),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("occurredAt"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("When the event actually happened"),
),
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("signature"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static(
"net.anisota.chronicle.expedition#chronicleSignature",
),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("subject"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"What was involved (specimen name, item id, etc.)",
),
),
..Default::default()
}),
);
map
},
..Default::default()
}),
..Default::default()
}),
);
map
},
..Default::default()
}
}