//! Generated by `trust-tasks-codegen` — do not edit by hand.
//!
//! Spec slug: `persona/facet/put`. Version: `1.0`.
#[allow(unused_imports)]
use serde::{Deserialize, Serialize};
/// Error types.
pub mod error {
/// Error from a `TryFrom` or `FromStr` implementation.
pub struct ConversionError(::std::borrow::Cow<'static, str>);
impl ::std::error::Error for ConversionError {}
impl ::std::fmt::Display for ConversionError {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> Result<(), ::std::fmt::Error> {
::std::fmt::Display::fmt(&self.0, f)
}
}
impl ::std::fmt::Debug for ConversionError {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> Result<(), ::std::fmt::Error> {
::std::fmt::Debug::fmt(&self.0, f)
}
}
impl From<&'static str> for ConversionError {
fn from(value: &'static str) -> Self {
Self(value.into())
}
}
impl From<String> for ConversionError {
fn from(value: String) -> Self {
Self(value.into())
}
}
}
///Optimistic-concurrency precondition. A positive value requires the record's current `version` to equal it exactly; zero means create-only and applies only when no live record exists at the address.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "ExpectedVersion",
/// "description": "Optimistic-concurrency precondition. A positive value requires the record's current `version` to equal it exactly; zero means create-only and applies only when no live record exists at the address.",
/// "type": "integer",
/// "minimum": 0.0
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(transparent)]
pub struct ExpectedVersion(pub u64);
impl ::std::ops::Deref for ExpectedVersion {
type Target = u64;
fn deref(&self) -> &u64 {
&self.0
}
}
impl ::std::convert::From<ExpectedVersion> for u64 {
fn from(value: ExpectedVersion) -> Self {
value.0
}
}
impl ::std::convert::From<u64> for ExpectedVersion {
fn from(value: u64) -> Self {
Self(value)
}
}
impl ::std::str::FromStr for ExpectedVersion {
type Err = <u64 as ::std::str::FromStr>::Err;
fn from_str(value: &str) -> ::std::result::Result<Self, Self::Err> {
Ok(Self(value.parse()?))
}
}
impl ::std::convert::TryFrom<&str> for ExpectedVersion {
type Error = <u64 as ::std::str::FromStr>::Err;
fn try_from(value: &str) -> ::std::result::Result<Self, Self::Error> {
value.parse()
}
}
impl ::std::convert::TryFrom<String> for ExpectedVersion {
type Error = <u64 as ::std::str::FromStr>::Err;
fn try_from(value: String) -> ::std::result::Result<Self, Self::Error> {
value.parse()
}
}
impl ::std::fmt::Display for ExpectedVersion {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
self.0.fmt(f)
}
}
///Vendor-namespaced extension object per SPEC.md §4.5.1. Each immediate key MUST be a reverse-DNS namespace; structure under each namespace is opaque to the framework.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "Ext",
/// "description": "Vendor-namespaced extension object per SPEC.md §4.5.1. Each immediate key MUST be a reverse-DNS namespace; structure under each namespace is opaque to the framework.",
/// "type": "object",
/// "minProperties": 1,
/// "additionalProperties": true,
/// "propertyNames": {
/// "pattern": "^[a-z][a-z0-9-]*(\\.[a-z0-9-]+)+$"
/// }
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(transparent)]
pub struct Ext(pub ::std::collections::HashMap<ExtKey, ::serde_json::Value>);
impl ::std::ops::Deref for Ext {
type Target = ::std::collections::HashMap<ExtKey, ::serde_json::Value>;
fn deref(&self) -> &::std::collections::HashMap<ExtKey, ::serde_json::Value> {
&self.0
}
}
impl ::std::convert::From<Ext> for ::std::collections::HashMap<ExtKey, ::serde_json::Value> {
fn from(value: Ext) -> Self {
value.0
}
}
impl ::std::convert::From<::std::collections::HashMap<ExtKey, ::serde_json::Value>> for Ext {
fn from(value: ::std::collections::HashMap<ExtKey, ::serde_json::Value>) -> Self {
Self(value)
}
}
///`ExtKey`
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "type": "string",
/// "pattern": "^[a-z][a-z0-9-]*(\\.[a-z0-9-]+)+$"
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct ExtKey(::std::string::String);
impl ::std::ops::Deref for ExtKey {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<ExtKey> for ::std::string::String {
fn from(value: ExtKey) -> Self {
value.0
}
}
impl ::std::str::FromStr for ExtKey {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
static PATTERN: ::std::sync::LazyLock<::regress::Regex> =
::std::sync::LazyLock::new(|| {
::regress::Regex::new("^[a-z][a-z0-9-]*(\\.[a-z0-9-]+)+$").unwrap()
});
if PATTERN.find(value).is_none() {
return Err("doesn't match pattern \"^[a-z][a-z0-9-]*(\\.[a-z0-9-]+)+$\"".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for ExtKey {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for ExtKey {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for ExtKey {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl<'de> ::serde::Deserialize<'de> for ExtKey {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
::std::string::String::deserialize(deserializer)?
.parse()
.map_err(|e: self::error::ConversionError| {
<D::Error as ::serde::de::Error>::custom(e.to_string())
})
}
}
///A colour **name**, resolved by each consumer against its own palette — never a hex value or any other literal. Two reasons, and both are about the consumer rather than the holder. A literal cannot be legible in a terminal, in a light theme and in a dark one at once, so a stored `#8B0000` is a colour that is wrong somewhere and the holder has no way to know where. And a consumer that reserves colours to mean something — an error, a warning, an irreversible act — must be able to keep a holder's decorative choice out of that channel; it cannot do that with an arbitrary value, and it can do it trivially with a closed set it maps itself. The eight members are chosen to be distinguishable from one another and deliberately carry no status connotation: none is named for success, warning or danger.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "FacetColour",
/// "description": "A colour **name**, resolved by each consumer against its own palette — never a hex value or any other literal. Two reasons, and both are about the consumer rather than the holder. A literal cannot be legible in a terminal, in a light theme and in a dark one at once, so a stored `#8B0000` is a colour that is wrong somewhere and the holder has no way to know where. And a consumer that reserves colours to mean something — an error, a warning, an irreversible act — must be able to keep a holder's decorative choice out of that channel; it cannot do that with an arbitrary value, and it can do it trivially with a closed set it maps itself. The eight members are chosen to be distinguishable from one another and deliberately carry no status connotation: none is named for success, warning or danger.",
/// "type": "string",
/// "enum": [
/// "slate",
/// "indigo",
/// "teal",
/// "moss",
/// "sand",
/// "clay",
/// "rose",
/// "plum"
/// ]
///}
/// ```
/// </details>
#[derive(
::serde::Deserialize,
::serde::Serialize,
Clone,
Copy,
Debug,
Eq,
Hash,
Ord,
PartialEq,
PartialOrd,
)]
#[non_exhaustive]
pub enum FacetColour {
#[serde(rename = "slate")]
Slate,
#[serde(rename = "indigo")]
Indigo,
#[serde(rename = "teal")]
Teal,
#[serde(rename = "moss")]
Moss,
#[serde(rename = "sand")]
Sand,
#[serde(rename = "clay")]
Clay,
#[serde(rename = "rose")]
Rose,
#[serde(rename = "plum")]
Plum,
}
impl ::std::fmt::Display for FacetColour {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
match *self {
Self::Slate => f.write_str("slate"),
Self::Indigo => f.write_str("indigo"),
Self::Teal => f.write_str("teal"),
Self::Moss => f.write_str("moss"),
Self::Sand => f.write_str("sand"),
Self::Clay => f.write_str("clay"),
Self::Rose => f.write_str("rose"),
Self::Plum => f.write_str("plum"),
}
}
}
impl ::std::str::FromStr for FacetColour {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
match value {
"slate" => Ok(Self::Slate),
"indigo" => Ok(Self::Indigo),
"teal" => Ok(Self::Teal),
"moss" => Ok(Self::Moss),
"sand" => Ok(Self::Sand),
"clay" => Ok(Self::Clay),
"rose" => Ok(Self::Rose),
"plum" => Ok(Self::Plum),
_ => Err("invalid value".into()),
}
}
}
impl ::std::convert::TryFrom<&str> for FacetColour {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for FacetColour {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for FacetColour {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
///Create or replace one facet: a named part of the holder's life, and the faces and attributes that belong to it. Omit `facetId` to create; supply it to replace. `expectedVersion` makes the write conditional.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "$id": "https://trusttasks.org/spec/persona/facet/put/1.0",
/// "title": "Payload",
/// "description": "Create or replace one facet: a named part of the holder's life, and the faces and attributes that belong to it. Omit `facetId` to create; supply it to replace. `expectedVersion` makes the write conditional.",
/// "type": "object",
/// "required": [
/// "colour",
/// "name"
/// ],
/// "properties": {
/// "attributeIds": {
/// "description": "Attributes belonging to this facet. Unlike a profile, an attribute MAY belong to several — a mobile number is genuinely both work and home — so no exclusivity is enforced and none should be inferred. Same replace semantics as `faceIds`.",
/// "default": [],
/// "type": "array",
/// "items": {
/// "$ref": "#/definitions/Ulid"
/// },
/// "maxItems": 1024,
/// "uniqueItems": true
/// },
/// "colour": {
/// "$ref": "#/definitions/FacetColour"
/// },
/// "expectedVersion": {
/// "description": "Optional precondition. Omit for last-writer-wins. Supply the version a prior read returned to make the write conditional; supply 0 to create only.",
/// "$ref": "#/definitions/ExpectedVersion"
/// },
/// "ext": {
/// "$ref": "#/definitions/Ext"
/// },
/// "faceIds": {
/// "description": "Profiles belonging to this facet. A profile belongs to at most one facet — see `persona/facet/put:faceAlreadyPlaced` — because the facet is where a consumer reads a profile's colour from, and two answers is no answer. Omission on a replace means an empty list, not 'leave as they were': this is a replace, and a member whose absence meant 'keep' would make it impossible to empty one.",
/// "default": [],
/// "type": "array",
/// "items": {
/// "$ref": "#/definitions/Ulid"
/// },
/// "maxItems": 256,
/// "uniqueItems": true
/// },
/// "facetId": {
/// "description": "Omit to create — the maintainer assigns one and returns it. Supply to replace an existing facet, or to make a create idempotent under retry; a supplied id that already exists is a replacement, and a producer that meant to create MUST pair it with `expectedVersion: 0`.",
/// "$ref": "#/definitions/Ulid"
/// },
/// "icon": {
/// "description": "One or two emoji, as a decorative mark beside the name. Bounded at 8 bytes because it is a mark and not a field: anything longer is text, and text belongs in `name` where a consumer will lay it out. A maintainer stores it opaquely and MUST NOT parse it; a consumer that cannot render emoji omits it and shows the name, which is why it is OPTIONAL and carries no meaning of its own.",
/// "type": "string",
/// "maxLength": 8,
/// "minLength": 1
/// },
/// "name": {
/// "description": "The holder's name for this part of their life — \"Work\", \"Home\", \"Play\". Never disclosed to a verifier; it is how the holder finds it again. A maintainer MUST NOT interpret it: it is not a scope, a policy input, or a name a counterparty ever sees.",
/// "type": "string",
/// "maxLength": 64,
/// "minLength": 1
/// }
/// },
/// "additionalProperties": false
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct Payload {
///Attributes belonging to this facet. Unlike a profile, an attribute MAY belong to several — a mobile number is genuinely both work and home — so no exclusivity is enforced and none should be inferred. Same replace semantics as `faceIds`.
#[serde(rename = "attributeIds", default = "defaults::payload_attribute_ids")]
pub attribute_ids: Vec<Ulid>,
pub colour: FacetColour,
///Optional precondition. Omit for last-writer-wins. Supply the version a prior read returned to make the write conditional; supply 0 to create only.
#[serde(
rename = "expectedVersion",
default,
skip_serializing_if = "::std::option::Option::is_none"
)]
pub expected_version: ::std::option::Option<ExpectedVersion>,
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub ext: ::std::option::Option<Ext>,
///Profiles belonging to this facet. A profile belongs to at most one facet — see `persona/facet/put:faceAlreadyPlaced` — because the facet is where a consumer reads a profile's colour from, and two answers is no answer. Omission on a replace means an empty list, not 'leave as they were': this is a replace, and a member whose absence meant 'keep' would make it impossible to empty one.
#[serde(rename = "faceIds", default = "defaults::payload_face_ids")]
pub face_ids: Vec<Ulid>,
///Omit to create — the maintainer assigns one and returns it. Supply to replace an existing facet, or to make a create idempotent under retry; a supplied id that already exists is a replacement, and a producer that meant to create MUST pair it with `expectedVersion: 0`.
#[serde(
rename = "facetId",
default,
skip_serializing_if = "::std::option::Option::is_none"
)]
pub facet_id: ::std::option::Option<Ulid>,
///One or two emoji, as a decorative mark beside the name. Bounded at 8 bytes because it is a mark and not a field: anything longer is text, and text belongs in `name` where a consumer will lay it out. A maintainer stores it opaquely and MUST NOT parse it; a consumer that cannot render emoji omits it and shows the name, which is why it is OPTIONAL and carries no meaning of its own.
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub icon: ::std::option::Option<PayloadIcon>,
///The holder's name for this part of their life — "Work", "Home", "Play". Never disclosed to a verifier; it is how the holder finds it again. A maintainer MUST NOT interpret it: it is not a scope, a policy input, or a name a counterparty ever sees.
pub name: PayloadName,
}
impl Payload {
pub fn builder() -> builder::Payload {
Default::default()
}
}
///One or two emoji, as a decorative mark beside the name. Bounded at 8 bytes because it is a mark and not a field: anything longer is text, and text belongs in `name` where a consumer will lay it out. A maintainer stores it opaquely and MUST NOT parse it; a consumer that cannot render emoji omits it and shows the name, which is why it is OPTIONAL and carries no meaning of its own.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "One or two emoji, as a decorative mark beside the name. Bounded at 8 bytes because it is a mark and not a field: anything longer is text, and text belongs in `name` where a consumer will lay it out. A maintainer stores it opaquely and MUST NOT parse it; a consumer that cannot render emoji omits it and shows the name, which is why it is OPTIONAL and carries no meaning of its own.",
/// "type": "string",
/// "maxLength": 8,
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct PayloadIcon(::std::string::String);
impl ::std::ops::Deref for PayloadIcon {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<PayloadIcon> for ::std::string::String {
fn from(value: PayloadIcon) -> Self {
value.0
}
}
impl ::std::str::FromStr for PayloadIcon {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() > 8usize {
return Err("longer than 8 characters".into());
}
if value.chars().count() < 1usize {
return Err("shorter than 1 characters".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for PayloadIcon {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for PayloadIcon {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for PayloadIcon {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl<'de> ::serde::Deserialize<'de> for PayloadIcon {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
::std::string::String::deserialize(deserializer)?
.parse()
.map_err(|e: self::error::ConversionError| {
<D::Error as ::serde::de::Error>::custom(e.to_string())
})
}
}
///The holder's name for this part of their life — "Work", "Home", "Play". Never disclosed to a verifier; it is how the holder finds it again. A maintainer MUST NOT interpret it: it is not a scope, a policy input, or a name a counterparty ever sees.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "The holder's name for this part of their life — \"Work\", \"Home\", \"Play\". Never disclosed to a verifier; it is how the holder finds it again. A maintainer MUST NOT interpret it: it is not a scope, a policy input, or a name a counterparty ever sees.",
/// "type": "string",
/// "maxLength": 64,
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct PayloadName(::std::string::String);
impl ::std::ops::Deref for PayloadName {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<PayloadName> for ::std::string::String {
fn from(value: PayloadName) -> Self {
value.0
}
}
impl ::std::str::FromStr for PayloadName {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() > 64usize {
return Err("longer than 64 characters".into());
}
if value.chars().count() < 1usize {
return Err("shorter than 1 characters".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for PayloadName {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for PayloadName {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for PayloadName {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl<'de> ::serde::Deserialize<'de> for PayloadName {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
::std::string::String::deserialize(deserializer)?
.parse()
.map_err(|e: self::error::ConversionError| {
<D::Error as ::serde::de::Error>::custom(e.to_string())
})
}
}
///Success response to persona/facet/put. Type https://trusttasks.org/spec/persona/facet/put/1.0#response. A failed precondition is not a success: it is a trust-task-error carrying persona/facet/put:versionConflict.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "Response",
/// "description": "Success response to persona/facet/put. Type https://trusttasks.org/spec/persona/facet/put/1.0#response. A failed precondition is not a success: it is a trust-task-error carrying persona/facet/put:versionConflict.",
/// "type": "object",
/// "required": [
/// "created",
/// "facetId",
/// "updatedAt",
/// "version"
/// ],
/// "properties": {
/// "created": {
/// "description": "True when this write created the facet, false when it replaced one. A producer that omitted `facetId` can still be told which happened, because a retried create with a supplied id is a replacement.",
/// "type": "boolean"
/// },
/// "createdAt": {
/// "type": "string",
/// "format": "date-time"
/// },
/// "ext": {
/// "$ref": "#/definitions/Ext"
/// },
/// "facetId": {
/// "$ref": "#/definitions/Ulid"
/// },
/// "updatedAt": {
/// "type": "string",
/// "format": "date-time"
/// },
/// "version": {
/// "$ref": "#/definitions/Version"
/// }
/// },
/// "additionalProperties": false,
/// "$anchor": "response"
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct Response {
///True when this write created the facet, false when it replaced one. A producer that omitted `facetId` can still be told which happened, because a retried create with a supplied id is a replacement.
pub created: bool,
#[serde(
rename = "createdAt",
default,
skip_serializing_if = "::std::option::Option::is_none"
)]
pub created_at: ::std::option::Option<::chrono::DateTime<::chrono::offset::Utc>>,
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub ext: ::std::option::Option<Ext>,
#[serde(rename = "facetId")]
pub facet_id: Ulid,
#[serde(rename = "updatedAt")]
pub updated_at: ::chrono::DateTime<::chrono::offset::Utc>,
pub version: Version,
}
impl Response {
pub fn builder() -> builder::Response {
Default::default()
}
}
///A ULID in Crockford base32, uppercase. Used for `attributeId` and `profileId`. Chosen over a UUID because the leading 48 bits are a timestamp, so a key-ordered scan of the store is also creation-ordered and a `list` needs no secondary sort. Server-assigned on create; a producer MAY supply one to make a create idempotent, and a maintainer MUST reject a supplied value that already exists rather than silently overwriting.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "Ulid",
/// "description": "A ULID in Crockford base32, uppercase. Used for `attributeId` and `profileId`. Chosen over a UUID because the leading 48 bits are a timestamp, so a key-ordered scan of the store is also creation-ordered and a `list` needs no secondary sort. Server-assigned on create; a producer MAY supply one to make a create idempotent, and a maintainer MUST reject a supplied value that already exists rather than silently overwriting.",
/// "type": "string",
/// "pattern": "^[0-9A-HJKMNP-TV-Z]{26}$"
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct Ulid(::std::string::String);
impl ::std::ops::Deref for Ulid {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<Ulid> for ::std::string::String {
fn from(value: Ulid) -> Self {
value.0
}
}
impl ::std::str::FromStr for Ulid {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
static PATTERN: ::std::sync::LazyLock<::regress::Regex> =
::std::sync::LazyLock::new(|| {
::regress::Regex::new("^[0-9A-HJKMNP-TV-Z]{26}$").unwrap()
});
if PATTERN.find(value).is_none() {
return Err("doesn't match pattern \"^[0-9A-HJKMNP-TV-Z]{26}$\"".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for Ulid {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for Ulid {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for Ulid {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl<'de> ::serde::Deserialize<'de> for Ulid {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
::std::string::String::deserialize(deserializer)?
.parse()
.map_err(|e: self::error::ConversionError| {
<D::Error as ::serde::de::Error>::custom(e.to_string())
})
}
}
///A value of the store's monotonic write counter. Server-assigned; a producer never chooses one.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "Version",
/// "description": "A value of the store's monotonic write counter. Server-assigned; a producer never chooses one.",
/// "type": "integer",
/// "minimum": 1.0
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(transparent)]
pub struct Version(pub ::std::num::NonZeroU64);
impl ::std::ops::Deref for Version {
type Target = ::std::num::NonZeroU64;
fn deref(&self) -> &::std::num::NonZeroU64 {
&self.0
}
}
impl ::std::convert::From<Version> for ::std::num::NonZeroU64 {
fn from(value: Version) -> Self {
value.0
}
}
impl ::std::convert::From<::std::num::NonZeroU64> for Version {
fn from(value: ::std::num::NonZeroU64) -> Self {
Self(value)
}
}
impl ::std::str::FromStr for Version {
type Err = <::std::num::NonZeroU64 as ::std::str::FromStr>::Err;
fn from_str(value: &str) -> ::std::result::Result<Self, Self::Err> {
Ok(Self(value.parse()?))
}
}
impl ::std::convert::TryFrom<&str> for Version {
type Error = <::std::num::NonZeroU64 as ::std::str::FromStr>::Err;
fn try_from(value: &str) -> ::std::result::Result<Self, Self::Error> {
value.parse()
}
}
impl ::std::convert::TryFrom<String> for Version {
type Error = <::std::num::NonZeroU64 as ::std::str::FromStr>::Err;
fn try_from(value: String) -> ::std::result::Result<Self, Self::Error> {
value.parse()
}
}
impl ::std::fmt::Display for Version {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
self.0.fmt(f)
}
}
/// Types for composing complex structures.
pub mod builder {
#[derive(Clone, Debug)]
pub struct Payload {
attribute_ids: ::std::result::Result<Vec<super::Ulid>, ::std::string::String>,
colour: ::std::result::Result<super::FacetColour, ::std::string::String>,
expected_version: ::std::result::Result<
::std::option::Option<super::ExpectedVersion>,
::std::string::String,
>,
ext: ::std::result::Result<::std::option::Option<super::Ext>, ::std::string::String>,
face_ids: ::std::result::Result<Vec<super::Ulid>, ::std::string::String>,
facet_id: ::std::result::Result<::std::option::Option<super::Ulid>, ::std::string::String>,
icon:
::std::result::Result<::std::option::Option<super::PayloadIcon>, ::std::string::String>,
name: ::std::result::Result<super::PayloadName, ::std::string::String>,
}
impl ::std::default::Default for Payload {
fn default() -> Self {
Self {
attribute_ids: Ok(super::defaults::payload_attribute_ids()),
colour: Err("no value supplied for colour".to_string()),
expected_version: Ok(Default::default()),
ext: Ok(Default::default()),
face_ids: Ok(super::defaults::payload_face_ids()),
facet_id: Ok(Default::default()),
icon: Ok(Default::default()),
name: Err("no value supplied for name".to_string()),
}
}
}
impl Payload {
pub fn attribute_ids<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<Vec<super::Ulid>>,
T::Error: ::std::fmt::Display,
{
self.attribute_ids = value
.try_into()
.map_err(|e| format!("error converting supplied value for attribute_ids: {e}"));
self
}
pub fn colour<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::FacetColour>,
T::Error: ::std::fmt::Display,
{
self.colour = value
.try_into()
.map_err(|e| format!("error converting supplied value for colour: {e}"));
self
}
pub fn expected_version<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::ExpectedVersion>>,
T::Error: ::std::fmt::Display,
{
self.expected_version = value
.try_into()
.map_err(|e| format!("error converting supplied value for expected_version: {e}"));
self
}
pub fn ext<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::Ext>>,
T::Error: ::std::fmt::Display,
{
self.ext = value
.try_into()
.map_err(|e| format!("error converting supplied value for ext: {e}"));
self
}
pub fn face_ids<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<Vec<super::Ulid>>,
T::Error: ::std::fmt::Display,
{
self.face_ids = value
.try_into()
.map_err(|e| format!("error converting supplied value for face_ids: {e}"));
self
}
pub fn facet_id<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::Ulid>>,
T::Error: ::std::fmt::Display,
{
self.facet_id = value
.try_into()
.map_err(|e| format!("error converting supplied value for facet_id: {e}"));
self
}
pub fn icon<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::PayloadIcon>>,
T::Error: ::std::fmt::Display,
{
self.icon = value
.try_into()
.map_err(|e| format!("error converting supplied value for icon: {e}"));
self
}
pub fn name<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::PayloadName>,
T::Error: ::std::fmt::Display,
{
self.name = value
.try_into()
.map_err(|e| format!("error converting supplied value for name: {e}"));
self
}
}
impl ::std::convert::TryFrom<Payload> for super::Payload {
type Error = super::error::ConversionError;
fn try_from(value: Payload) -> ::std::result::Result<Self, super::error::ConversionError> {
Ok(Self {
attribute_ids: value.attribute_ids?,
colour: value.colour?,
expected_version: value.expected_version?,
ext: value.ext?,
face_ids: value.face_ids?,
facet_id: value.facet_id?,
icon: value.icon?,
name: value.name?,
})
}
}
impl ::std::convert::From<super::Payload> for Payload {
fn from(value: super::Payload) -> Self {
Self {
attribute_ids: Ok(value.attribute_ids),
colour: Ok(value.colour),
expected_version: Ok(value.expected_version),
ext: Ok(value.ext),
face_ids: Ok(value.face_ids),
facet_id: Ok(value.facet_id),
icon: Ok(value.icon),
name: Ok(value.name),
}
}
}
#[derive(Clone, Debug)]
pub struct Response {
created: ::std::result::Result<bool, ::std::string::String>,
created_at: ::std::result::Result<
::std::option::Option<::chrono::DateTime<::chrono::offset::Utc>>,
::std::string::String,
>,
ext: ::std::result::Result<::std::option::Option<super::Ext>, ::std::string::String>,
facet_id: ::std::result::Result<super::Ulid, ::std::string::String>,
updated_at:
::std::result::Result<::chrono::DateTime<::chrono::offset::Utc>, ::std::string::String>,
version: ::std::result::Result<super::Version, ::std::string::String>,
}
impl ::std::default::Default for Response {
fn default() -> Self {
Self {
created: Err("no value supplied for created".to_string()),
created_at: Ok(Default::default()),
ext: Ok(Default::default()),
facet_id: Err("no value supplied for facet_id".to_string()),
updated_at: Err("no value supplied for updated_at".to_string()),
version: Err("no value supplied for version".to_string()),
}
}
}
impl Response {
pub fn created<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<bool>,
T::Error: ::std::fmt::Display,
{
self.created = value
.try_into()
.map_err(|e| format!("error converting supplied value for created: {e}"));
self
}
pub fn created_at<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<
::std::option::Option<::chrono::DateTime<::chrono::offset::Utc>>,
>,
T::Error: ::std::fmt::Display,
{
self.created_at = value
.try_into()
.map_err(|e| format!("error converting supplied value for created_at: {e}"));
self
}
pub fn ext<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::Ext>>,
T::Error: ::std::fmt::Display,
{
self.ext = value
.try_into()
.map_err(|e| format!("error converting supplied value for ext: {e}"));
self
}
pub fn facet_id<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::Ulid>,
T::Error: ::std::fmt::Display,
{
self.facet_id = value
.try_into()
.map_err(|e| format!("error converting supplied value for facet_id: {e}"));
self
}
pub fn updated_at<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::chrono::DateTime<::chrono::offset::Utc>>,
T::Error: ::std::fmt::Display,
{
self.updated_at = value
.try_into()
.map_err(|e| format!("error converting supplied value for updated_at: {e}"));
self
}
pub fn version<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::Version>,
T::Error: ::std::fmt::Display,
{
self.version = value
.try_into()
.map_err(|e| format!("error converting supplied value for version: {e}"));
self
}
}
impl ::std::convert::TryFrom<Response> for super::Response {
type Error = super::error::ConversionError;
fn try_from(value: Response) -> ::std::result::Result<Self, super::error::ConversionError> {
Ok(Self {
created: value.created?,
created_at: value.created_at?,
ext: value.ext?,
facet_id: value.facet_id?,
updated_at: value.updated_at?,
version: value.version?,
})
}
}
impl ::std::convert::From<super::Response> for Response {
fn from(value: super::Response) -> Self {
Self {
created: Ok(value.created),
created_at: Ok(value.created_at),
ext: Ok(value.ext),
facet_id: Ok(value.facet_id),
updated_at: Ok(value.updated_at),
version: Ok(value.version),
}
}
}
}
/// Generation of default values for serde.
pub mod defaults {
pub(super) fn payload_attribute_ids() -> Vec<super::Ulid> {
vec![]
}
pub(super) fn payload_face_ids() -> Vec<super::Ulid> {
vec![]
}
}
impl crate::Payload for Payload {
const TYPE_URI: &'static str = "https://trusttasks.org/spec/persona/facet/put/1.0";
const IS_PROOF_REQUIRED: bool = true;
const IS_ISSUED_AT_REQUIRED: bool = true;
const IS_RECIPIENT_REQUIRED: bool = true;
const PAYLOAD_SCHEMA: Option<&'static str> = Some(
"{\n \"$defs\": {\n \"ExpectedVersion\": {\n \"description\": \"Optimistic-concurrency precondition. A positive value requires the record's current `version` to equal it exactly; zero means create-only and applies only when no live record exists at the address.\",\n \"minimum\": 0,\n \"title\": \"ExpectedVersion\",\n \"type\": \"integer\"\n },\n \"Ext\": {\n \"additionalProperties\": true,\n \"description\": \"Vendor-namespaced extension object per SPEC.md §4.5.1. Each immediate key MUST be a reverse-DNS namespace; structure under each namespace is opaque to the framework.\",\n \"minProperties\": 1,\n \"propertyNames\": {\n \"pattern\": \"^[a-z][a-z0-9-]*(\\\\.[a-z0-9-]+)+$\"\n },\n \"title\": \"Ext\",\n \"type\": \"object\"\n },\n \"FacetColour\": {\n \"description\": \"A colour **name**, resolved by each consumer against its own palette — never a hex value or any other literal. Two reasons, and both are about the consumer rather than the holder. A literal cannot be legible in a terminal, in a light theme and in a dark one at once, so a stored `#8B0000` is a colour that is wrong somewhere and the holder has no way to know where. And a consumer that reserves colours to mean something — an error, a warning, an irreversible act — must be able to keep a holder's decorative choice out of that channel; it cannot do that with an arbitrary value, and it can do it trivially with a closed set it maps itself. The eight members are chosen to be distinguishable from one another and deliberately carry no status connotation: none is named for success, warning or danger.\",\n \"enum\": [\n \"slate\",\n \"indigo\",\n \"teal\",\n \"moss\",\n \"sand\",\n \"clay\",\n \"rose\",\n \"plum\"\n ],\n \"title\": \"FacetColour\",\n \"type\": \"string\"\n },\n \"Response\": {\n \"$anchor\": \"response\",\n \"additionalProperties\": false,\n \"description\": \"Success response to persona/facet/put. Type https://trusttasks.org/spec/persona/facet/put/1.0#response. A failed precondition is not a success: it is a trust-task-error carrying persona/facet/put:versionConflict.\",\n \"properties\": {\n \"created\": {\n \"description\": \"True when this write created the facet, false when it replaced one. A producer that omitted `facetId` can still be told which happened, because a retried create with a supplied id is a replacement.\",\n \"type\": \"boolean\"\n },\n \"createdAt\": {\n \"format\": \"date-time\",\n \"type\": \"string\"\n },\n \"ext\": {\n \"$ref\": \"#/$defs/Ext\"\n },\n \"facetId\": {\n \"$ref\": \"#/$defs/Ulid\"\n },\n \"updatedAt\": {\n \"format\": \"date-time\",\n \"type\": \"string\"\n },\n \"version\": {\n \"$ref\": \"#/$defs/Version\"\n }\n },\n \"required\": [\n \"facetId\",\n \"version\",\n \"created\",\n \"updatedAt\"\n ],\n \"title\": \"Persona Facet Put — response payload\",\n \"type\": \"object\"\n },\n \"Ulid\": {\n \"description\": \"A ULID in Crockford base32, uppercase. Used for `attributeId` and `profileId`. Chosen over a UUID because the leading 48 bits are a timestamp, so a key-ordered scan of the store is also creation-ordered and a `list` needs no secondary sort. Server-assigned on create; a producer MAY supply one to make a create idempotent, and a maintainer MUST reject a supplied value that already exists rather than silently overwriting.\",\n \"pattern\": \"^[0-9A-HJKMNP-TV-Z]{26}$\",\n \"title\": \"Ulid\",\n \"type\": \"string\"\n },\n \"Version\": {\n \"description\": \"A value of the store's monotonic write counter. Server-assigned; a producer never chooses one.\",\n \"minimum\": 1,\n \"title\": \"Version\",\n \"type\": \"integer\"\n }\n },\n \"$id\": \"https://trusttasks.org/spec/persona/facet/put/1.0\",\n \"$schema\": \"https://json-schema.org/draft/2020-12/schema\",\n \"additionalProperties\": false,\n \"description\": \"Create or replace one facet: a named part of the holder's life, and the faces and attributes that belong to it. Omit `facetId` to create; supply it to replace. `expectedVersion` makes the write conditional.\",\n \"properties\": {\n \"attributeIds\": {\n \"default\": [],\n \"description\": \"Attributes belonging to this facet. Unlike a profile, an attribute MAY belong to several — a mobile number is genuinely both work and home — so no exclusivity is enforced and none should be inferred. Same replace semantics as `faceIds`.\",\n \"items\": {\n \"$ref\": \"#/$defs/Ulid\"\n },\n \"maxItems\": 1024,\n \"type\": \"array\",\n \"uniqueItems\": true\n },\n \"colour\": {\n \"$ref\": \"#/$defs/FacetColour\"\n },\n \"expectedVersion\": {\n \"$ref\": \"#/$defs/ExpectedVersion\",\n \"description\": \"Optional precondition. Omit for last-writer-wins. Supply the version a prior read returned to make the write conditional; supply 0 to create only.\"\n },\n \"ext\": {\n \"$ref\": \"#/$defs/Ext\"\n },\n \"faceIds\": {\n \"default\": [],\n \"description\": \"Profiles belonging to this facet. A profile belongs to at most one facet — see `persona/facet/put:faceAlreadyPlaced` — because the facet is where a consumer reads a profile's colour from, and two answers is no answer. Omission on a replace means an empty list, not 'leave as they were': this is a replace, and a member whose absence meant 'keep' would make it impossible to empty one.\",\n \"items\": {\n \"$ref\": \"#/$defs/Ulid\"\n },\n \"maxItems\": 256,\n \"type\": \"array\",\n \"uniqueItems\": true\n },\n \"facetId\": {\n \"$ref\": \"#/$defs/Ulid\",\n \"description\": \"Omit to create — the maintainer assigns one and returns it. Supply to replace an existing facet, or to make a create idempotent under retry; a supplied id that already exists is a replacement, and a producer that meant to create MUST pair it with `expectedVersion: 0`.\"\n },\n \"icon\": {\n \"description\": \"One or two emoji, as a decorative mark beside the name. Bounded at 8 bytes because it is a mark and not a field: anything longer is text, and text belongs in `name` where a consumer will lay it out. A maintainer stores it opaquely and MUST NOT parse it; a consumer that cannot render emoji omits it and shows the name, which is why it is OPTIONAL and carries no meaning of its own.\",\n \"maxLength\": 8,\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"name\": {\n \"description\": \"The holder's name for this part of their life — \\\"Work\\\", \\\"Home\\\", \\\"Play\\\". Never disclosed to a verifier; it is how the holder finds it again. A maintainer MUST NOT interpret it: it is not a scope, a policy input, or a name a counterparty ever sees.\",\n \"maxLength\": 64,\n \"minLength\": 1,\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"name\",\n \"colour\"\n ],\n \"title\": \"Persona — Facet Put — payload\",\n \"type\": \"object\"\n}\n",
);
}
impl crate::Payload for Response {
const TYPE_URI: &'static str = "https://trusttasks.org/spec/persona/facet/put/1.0#response";
const IS_PROOF_REQUIRED: bool = true;
const IS_ISSUED_AT_REQUIRED: bool = true;
const IS_RECIPIENT_REQUIRED: bool = true;
const PAYLOAD_SCHEMA: Option<&'static str> = Some(
"{\n \"$defs\": {\n \"ExpectedVersion\": {\n \"description\": \"Optimistic-concurrency precondition. A positive value requires the record's current `version` to equal it exactly; zero means create-only and applies only when no live record exists at the address.\",\n \"minimum\": 0,\n \"title\": \"ExpectedVersion\",\n \"type\": \"integer\"\n },\n \"Ext\": {\n \"additionalProperties\": true,\n \"description\": \"Vendor-namespaced extension object per SPEC.md §4.5.1. Each immediate key MUST be a reverse-DNS namespace; structure under each namespace is opaque to the framework.\",\n \"minProperties\": 1,\n \"propertyNames\": {\n \"pattern\": \"^[a-z][a-z0-9-]*(\\\\.[a-z0-9-]+)+$\"\n },\n \"title\": \"Ext\",\n \"type\": \"object\"\n },\n \"FacetColour\": {\n \"description\": \"A colour **name**, resolved by each consumer against its own palette — never a hex value or any other literal. Two reasons, and both are about the consumer rather than the holder. A literal cannot be legible in a terminal, in a light theme and in a dark one at once, so a stored `#8B0000` is a colour that is wrong somewhere and the holder has no way to know where. And a consumer that reserves colours to mean something — an error, a warning, an irreversible act — must be able to keep a holder's decorative choice out of that channel; it cannot do that with an arbitrary value, and it can do it trivially with a closed set it maps itself. The eight members are chosen to be distinguishable from one another and deliberately carry no status connotation: none is named for success, warning or danger.\",\n \"enum\": [\n \"slate\",\n \"indigo\",\n \"teal\",\n \"moss\",\n \"sand\",\n \"clay\",\n \"rose\",\n \"plum\"\n ],\n \"title\": \"FacetColour\",\n \"type\": \"string\"\n },\n \"Response\": {\n \"$anchor\": \"response\",\n \"additionalProperties\": false,\n \"description\": \"Success response to persona/facet/put. Type https://trusttasks.org/spec/persona/facet/put/1.0#response. A failed precondition is not a success: it is a trust-task-error carrying persona/facet/put:versionConflict.\",\n \"properties\": {\n \"created\": {\n \"description\": \"True when this write created the facet, false when it replaced one. A producer that omitted `facetId` can still be told which happened, because a retried create with a supplied id is a replacement.\",\n \"type\": \"boolean\"\n },\n \"createdAt\": {\n \"format\": \"date-time\",\n \"type\": \"string\"\n },\n \"ext\": {\n \"$ref\": \"#/$defs/Ext\"\n },\n \"facetId\": {\n \"$ref\": \"#/$defs/Ulid\"\n },\n \"updatedAt\": {\n \"format\": \"date-time\",\n \"type\": \"string\"\n },\n \"version\": {\n \"$ref\": \"#/$defs/Version\"\n }\n },\n \"required\": [\n \"facetId\",\n \"version\",\n \"created\",\n \"updatedAt\"\n ],\n \"title\": \"Persona Facet Put — response payload\",\n \"type\": \"object\"\n },\n \"Ulid\": {\n \"description\": \"A ULID in Crockford base32, uppercase. Used for `attributeId` and `profileId`. Chosen over a UUID because the leading 48 bits are a timestamp, so a key-ordered scan of the store is also creation-ordered and a `list` needs no secondary sort. Server-assigned on create; a producer MAY supply one to make a create idempotent, and a maintainer MUST reject a supplied value that already exists rather than silently overwriting.\",\n \"pattern\": \"^[0-9A-HJKMNP-TV-Z]{26}$\",\n \"title\": \"Ulid\",\n \"type\": \"string\"\n },\n \"Version\": {\n \"description\": \"A value of the store's monotonic write counter. Server-assigned; a producer never chooses one.\",\n \"minimum\": 1,\n \"title\": \"Version\",\n \"type\": \"integer\"\n }\n },\n \"$ref\": \"#/$defs/Response\",\n \"$schema\": \"https://json-schema.org/draft/2020-12/schema\"\n}\n",
);
}
impl crate::RequestPayload for Payload {
type Response = Response;
}
#[cfg(test)]
mod conformance {
//! Round-trip tests harvested from the spec's `spec.md`,
//! plus a `rejects_invalid_examples` test for any fixtures
//! in `payload.invalid-examples.json` (validate feature).
#[test]
fn request_example_1() {
const JSON: &str = "{\n \"id\": \"urn:uuid:00000000-0000-4000-8000-000000000001\",\n \"type\": \"https://trusttasks.org/spec/persona/facet/put/1.0#request\",\n \"issuer\": \"did:example:holder\",\n \"recipient\": \"did:example:agent\",\n \"issuedAt\": \"2026-01-01T00:00:00Z\",\n \"threadId\": \"urn:uuid:00000000-0000-4000-8000-0000000000ff\",\n \"payload\": {\n \"name\": \"Work\",\n \"colour\": \"teal\",\n \"icon\": \"💼\",\n \"faceIds\": [\"01J8XR3QK9V0000000000000A1\", \"01J8XR3QK9V0000000000000A2\"],\n \"attributeIds\": [\"01J8XR3QK9V0000000000000B7\"],\n \"expectedVersion\": 0\n }\n}\n";
let doc: crate::TrustTask<super::Payload> =
serde_json::from_str(JSON).expect("deserialize request example");
let rendered = serde_json::to_value(&doc).expect("re-serialize");
let expected: serde_json::Value = serde_json::from_str(JSON).expect("re-parse expected");
assert_eq!(rendered, expected, "request example failed round-trip");
}
#[test]
fn response_example_1() {
const JSON: &str = "{\n \"id\": \"urn:uuid:00000000-0000-4000-8000-000000000002\",\n \"type\": \"https://trusttasks.org/spec/persona/facet/put/1.0#response\",\n \"issuer\": \"did:example:agent\",\n \"recipient\": \"did:example:holder\",\n \"issuedAt\": \"2026-01-01T00:00:01Z\",\n \"threadId\": \"urn:uuid:00000000-0000-4000-8000-0000000000ff\",\n \"payload\": {\n \"facetId\": \"01J8XR3QK9V0000000000000C4\",\n \"version\": 1,\n \"created\": true,\n \"createdAt\": \"2026-01-01T00:00:01Z\",\n \"updatedAt\": \"2026-01-01T00:00:01Z\"\n }\n}\n";
let doc: crate::TrustTask<super::Response> =
serde_json::from_str(JSON).expect("deserialize response example");
let rendered = serde_json::to_value(&doc).expect("re-serialize");
let expected: serde_json::Value = serde_json::from_str(JSON).expect("re-parse expected");
assert_eq!(rendered, expected, "response example failed round-trip");
}
}