#[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, Cid, Datetime};
use jacquard_common::types::uri::{RecordUri, UriError};
use jacquard_common::xrpc::XrpcResp;
use jacquard_derive::{IntoStatic, lexicon, open_union};
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::app_certified::Did;
use crate::com_atproto::repo::strong_ref::StrongRef;
use crate::org_hypercerts::SmallBlob;
use crate::org_hypercerts::Uri;
use crate::org_hypercerts::context::evaluation;
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Evaluation<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub content: Option<Vec<EvaluationContentItem<'a>>>,
pub created_at: Datetime,
#[serde(borrow)]
pub evaluators: Vec<Did<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub location: Option<StrongRef<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub measurements: Option<Vec<StrongRef<'a>>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub score: Option<evaluation::Score<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub subject: Option<StrongRef<'a>>,
#[serde(borrow)]
pub summary: CowStr<'a>,
}
#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type")]
#[serde(bound(deserialize = "'de: 'a"))]
pub enum EvaluationContentItem<'a> {
#[serde(rename = "org.hypercerts.defs#uri")]
Uri(Box<Uri<'a>>),
#[serde(rename = "org.hypercerts.defs#smallBlob")]
SmallBlob(Box<SmallBlob<'a>>),
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct EvaluationGetRecordOutput<'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: Evaluation<'a>,
}
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Score<'a> {
pub max: i64,
pub min: i64,
pub value: i64,
}
impl<'a> Evaluation<'a> {
pub fn uri(
uri: impl Into<CowStr<'a>>,
) -> Result<RecordUri<'a, EvaluationRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new_cow(uri.into())?)
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct EvaluationRecord;
impl XrpcResp for EvaluationRecord {
const NSID: &'static str = "org.hypercerts.context.evaluation";
const ENCODING: &'static str = "application/json";
type Output<'de> = EvaluationGetRecordOutput<'de>;
type Err<'de> = RecordError<'de>;
}
impl From<EvaluationGetRecordOutput<'_>> for Evaluation<'_> {
fn from(output: EvaluationGetRecordOutput<'_>) -> Self {
use jacquard_common::IntoStatic;
output.value.into_static()
}
}
impl Collection for Evaluation<'_> {
const NSID: &'static str = "org.hypercerts.context.evaluation";
type Record = EvaluationRecord;
}
impl Collection for EvaluationRecord {
const NSID: &'static str = "org.hypercerts.context.evaluation";
type Record = EvaluationRecord;
}
impl<'a> LexiconSchema for Evaluation<'a> {
fn nsid() -> &'static str {
"org.hypercerts.context.evaluation"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_org_hypercerts_context_evaluation()
}
fn validate(&self) -> Result<(), ConstraintError> {
if let Some(ref value) = self.content {
#[allow(unused_comparisons)]
if value.len() > 100usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("content"),
max: 100usize,
actual: value.len(),
});
}
}
{
let value = &self.evaluators;
#[allow(unused_comparisons)]
if value.len() > 1000usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("evaluators"),
max: 1000usize,
actual: value.len(),
});
}
}
if let Some(ref value) = self.measurements {
#[allow(unused_comparisons)]
if value.len() > 100usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("measurements"),
max: 100usize,
actual: value.len(),
});
}
}
{
let value = &self.summary;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 5000usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("summary"),
max: 5000usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.summary;
{
let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
if count > 1000usize {
return Err(ConstraintError::MaxGraphemes {
path: ValidationPath::from_field("summary"),
max: 1000usize,
actual: count,
});
}
}
}
Ok(())
}
}
impl<'a> LexiconSchema for Score<'a> {
fn nsid() -> &'static str {
"org.hypercerts.context.evaluation"
}
fn def_name() -> &'static str {
"score"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_org_hypercerts_context_evaluation()
}
fn validate(&self) -> Result<(), ConstraintError> {
Ok(())
}
}
pub mod evaluation_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 Evaluators;
type Summary;
type CreatedAt;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Evaluators = Unset;
type Summary = Unset;
type CreatedAt = Unset;
}
pub struct SetEvaluators<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetEvaluators<S> {}
impl<S: State> State for SetEvaluators<S> {
type Evaluators = Set<members::evaluators>;
type Summary = S::Summary;
type CreatedAt = S::CreatedAt;
}
pub struct SetSummary<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetSummary<S> {}
impl<S: State> State for SetSummary<S> {
type Evaluators = S::Evaluators;
type Summary = Set<members::summary>;
type CreatedAt = S::CreatedAt;
}
pub struct SetCreatedAt<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetCreatedAt<S> {}
impl<S: State> State for SetCreatedAt<S> {
type Evaluators = S::Evaluators;
type Summary = S::Summary;
type CreatedAt = Set<members::created_at>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct evaluators(());
pub struct summary(());
pub struct created_at(());
}
}
pub struct EvaluationBuilder<'a, S: evaluation_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (
Option<Vec<EvaluationContentItem<'a>>>,
Option<Datetime>,
Option<Vec<Did<'a>>>,
Option<StrongRef<'a>>,
Option<Vec<StrongRef<'a>>>,
Option<evaluation::Score<'a>>,
Option<StrongRef<'a>>,
Option<CowStr<'a>>,
),
_lifetime: PhantomData<&'a ()>,
}
impl<'a> Evaluation<'a> {
pub fn new() -> EvaluationBuilder<'a, evaluation_state::Empty> {
EvaluationBuilder::new()
}
}
impl<'a> EvaluationBuilder<'a, evaluation_state::Empty> {
pub fn new() -> Self {
EvaluationBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None, None, None),
_lifetime: PhantomData,
}
}
}
impl<'a, S: evaluation_state::State> EvaluationBuilder<'a, S> {
pub fn content(
mut self,
value: impl Into<Option<Vec<EvaluationContentItem<'a>>>>,
) -> Self {
self._fields.0 = value.into();
self
}
pub fn maybe_content(
mut self,
value: Option<Vec<EvaluationContentItem<'a>>>,
) -> Self {
self._fields.0 = value;
self
}
}
impl<'a, S> EvaluationBuilder<'a, S>
where
S: evaluation_state::State,
S::CreatedAt: evaluation_state::IsUnset,
{
pub fn created_at(
mut self,
value: impl Into<Datetime>,
) -> EvaluationBuilder<'a, evaluation_state::SetCreatedAt<S>> {
self._fields.1 = Option::Some(value.into());
EvaluationBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> EvaluationBuilder<'a, S>
where
S: evaluation_state::State,
S::Evaluators: evaluation_state::IsUnset,
{
pub fn evaluators(
mut self,
value: impl Into<Vec<Did<'a>>>,
) -> EvaluationBuilder<'a, evaluation_state::SetEvaluators<S>> {
self._fields.2 = Option::Some(value.into());
EvaluationBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S: evaluation_state::State> EvaluationBuilder<'a, S> {
pub fn location(mut self, value: impl Into<Option<StrongRef<'a>>>) -> Self {
self._fields.3 = value.into();
self
}
pub fn maybe_location(mut self, value: Option<StrongRef<'a>>) -> Self {
self._fields.3 = value;
self
}
}
impl<'a, S: evaluation_state::State> EvaluationBuilder<'a, S> {
pub fn measurements(mut self, value: impl Into<Option<Vec<StrongRef<'a>>>>) -> Self {
self._fields.4 = value.into();
self
}
pub fn maybe_measurements(mut self, value: Option<Vec<StrongRef<'a>>>) -> Self {
self._fields.4 = value;
self
}
}
impl<'a, S: evaluation_state::State> EvaluationBuilder<'a, S> {
pub fn score(mut self, value: impl Into<Option<evaluation::Score<'a>>>) -> Self {
self._fields.5 = value.into();
self
}
pub fn maybe_score(mut self, value: Option<evaluation::Score<'a>>) -> Self {
self._fields.5 = value;
self
}
}
impl<'a, S: evaluation_state::State> EvaluationBuilder<'a, S> {
pub fn subject(mut self, value: impl Into<Option<StrongRef<'a>>>) -> Self {
self._fields.6 = value.into();
self
}
pub fn maybe_subject(mut self, value: Option<StrongRef<'a>>) -> Self {
self._fields.6 = value;
self
}
}
impl<'a, S> EvaluationBuilder<'a, S>
where
S: evaluation_state::State,
S::Summary: evaluation_state::IsUnset,
{
pub fn summary(
mut self,
value: impl Into<CowStr<'a>>,
) -> EvaluationBuilder<'a, evaluation_state::SetSummary<S>> {
self._fields.7 = Option::Some(value.into());
EvaluationBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> EvaluationBuilder<'a, S>
where
S: evaluation_state::State,
S::Evaluators: evaluation_state::IsSet,
S::Summary: evaluation_state::IsSet,
S::CreatedAt: evaluation_state::IsSet,
{
pub fn build(self) -> Evaluation<'a> {
Evaluation {
content: self._fields.0,
created_at: self._fields.1.unwrap(),
evaluators: self._fields.2.unwrap(),
location: self._fields.3,
measurements: self._fields.4,
score: self._fields.5,
subject: self._fields.6,
summary: self._fields.7.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>,
>,
) -> Evaluation<'a> {
Evaluation {
content: self._fields.0,
created_at: self._fields.1.unwrap(),
evaluators: self._fields.2.unwrap(),
location: self._fields.3,
measurements: self._fields.4,
score: self._fields.5,
subject: self._fields.6,
summary: self._fields.7.unwrap(),
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_org_hypercerts_context_evaluation() -> 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("org.hypercerts.context.evaluation"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("main"),
LexUserType::Record(LexRecord {
description: Some(
CowStr::new_static(
"An evaluation of a hypercert record (e.g. an activity and its impact).",
),
),
key: Some(CowStr::new_static("tid")),
record: LexRecordRecord::Object(LexObject {
required: Some(
vec![
SmolStr::new_static("evaluators"),
SmolStr::new_static("summary"),
SmolStr::new_static("createdAt")
],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("content"),
LexObjectProperty::Array(LexArray {
description: Some(
CowStr::new_static(
"Evaluation data (URIs or blobs) containing detailed reports or methodology",
),
),
items: LexArrayItem::Union(LexRefUnion {
refs: vec![
CowStr::new_static("org.hypercerts.defs#uri"),
CowStr::new_static("org.hypercerts.defs#smallBlob")
],
..Default::default()
}),
max_length: Some(100usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("createdAt"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Client-declared timestamp when this record was originally created",
),
),
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("evaluators"),
LexObjectProperty::Array(LexArray {
description: Some(
CowStr::new_static("DIDs of the evaluators"),
),
items: LexArrayItem::Ref(LexRef {
r#ref: CowStr::new_static("app.certified.defs#did"),
..Default::default()
}),
max_length: Some(1000usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("location"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static("com.atproto.repo.strongRef"),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("measurements"),
LexObjectProperty::Array(LexArray {
description: Some(
CowStr::new_static(
"Optional references to the measurements that contributed to this evaluation. The record(s) referenced must conform with the lexicon org.hypercerts.context.measurement",
),
),
items: LexArrayItem::Ref(LexRef {
r#ref: CowStr::new_static("com.atproto.repo.strongRef"),
..Default::default()
}),
max_length: Some(100usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("score"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static("#score"),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("subject"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static("com.atproto.repo.strongRef"),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("summary"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("Brief evaluation summary"),
),
max_length: Some(5000usize),
max_graphemes: Some(1000usize),
..Default::default()
}),
);
map
},
..Default::default()
}),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("score"),
LexUserType::Object(LexObject {
description: Some(
CowStr::new_static(
"Overall score for an evaluation on a numeric scale.",
),
),
required: Some(
vec![
SmolStr::new_static("min"), SmolStr::new_static("max"),
SmolStr::new_static("value")
],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("max"),
LexObjectProperty::Integer(LexInteger {
..Default::default()
}),
);
map.insert(
SmolStr::new_static("min"),
LexObjectProperty::Integer(LexInteger {
..Default::default()
}),
);
map.insert(
SmolStr::new_static("value"),
LexObjectProperty::Integer(LexInteger {
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map
},
..Default::default()
}
}
pub mod score_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 Min;
type Value;
type Max;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Min = Unset;
type Value = Unset;
type Max = Unset;
}
pub struct SetMin<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetMin<S> {}
impl<S: State> State for SetMin<S> {
type Min = Set<members::min>;
type Value = S::Value;
type Max = S::Max;
}
pub struct SetValue<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetValue<S> {}
impl<S: State> State for SetValue<S> {
type Min = S::Min;
type Value = Set<members::value>;
type Max = S::Max;
}
pub struct SetMax<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetMax<S> {}
impl<S: State> State for SetMax<S> {
type Min = S::Min;
type Value = S::Value;
type Max = Set<members::max>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct min(());
pub struct value(());
pub struct max(());
}
}
pub struct ScoreBuilder<'a, S: score_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (Option<i64>, Option<i64>, Option<i64>),
_lifetime: PhantomData<&'a ()>,
}
impl<'a> Score<'a> {
pub fn new() -> ScoreBuilder<'a, score_state::Empty> {
ScoreBuilder::new()
}
}
impl<'a> ScoreBuilder<'a, score_state::Empty> {
pub fn new() -> Self {
ScoreBuilder {
_state: PhantomData,
_fields: (None, None, None),
_lifetime: PhantomData,
}
}
}
impl<'a, S> ScoreBuilder<'a, S>
where
S: score_state::State,
S::Max: score_state::IsUnset,
{
pub fn max(
mut self,
value: impl Into<i64>,
) -> ScoreBuilder<'a, score_state::SetMax<S>> {
self._fields.0 = Option::Some(value.into());
ScoreBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> ScoreBuilder<'a, S>
where
S: score_state::State,
S::Min: score_state::IsUnset,
{
pub fn min(
mut self,
value: impl Into<i64>,
) -> ScoreBuilder<'a, score_state::SetMin<S>> {
self._fields.1 = Option::Some(value.into());
ScoreBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> ScoreBuilder<'a, S>
where
S: score_state::State,
S::Value: score_state::IsUnset,
{
pub fn value(
mut self,
value: impl Into<i64>,
) -> ScoreBuilder<'a, score_state::SetValue<S>> {
self._fields.2 = Option::Some(value.into());
ScoreBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> ScoreBuilder<'a, S>
where
S: score_state::State,
S::Min: score_state::IsSet,
S::Value: score_state::IsSet,
S::Max: score_state::IsSet,
{
pub fn build(self) -> Score<'a> {
Score {
max: self._fields.0.unwrap(),
min: self._fields.1.unwrap(),
value: 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>,
>,
) -> Score<'a> {
Score {
max: self._fields.0.unwrap(),
min: self._fields.1.unwrap(),
value: self._fields.2.unwrap(),
extra_data: Some(extra_data),
}
}
}