//! Generated by `trust-tasks-codegen` — do not edit by hand.
//!
//! Spec slug: `persona/facet/put`. Version: `1.0`.
#![allow(deprecated)]
/// Why this specification version is deprecated (SPEC "Superseded and
/// Withdrawn Versions"), or `None` while it is current.
pub const DEPRECATION: Option<&str> = Some("retired; use persona/world/put/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.
///
#[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.
///
#[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`
///
#[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())
})
}
}
///**Superseded by `WorldColour`** — the same set, under the name the rest of the family now uses. Retained because `persona/facet/*` is retired in favour of `persona/world/*`, and a retired specification's schema is frozen, so the definition it references has to stay. New work references `WorldColour`. 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.
///
#[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.
///
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
#[deprecated(note = "retired; use persona/world/put/1.0")]
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.
///
#[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.
///
#[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.
///
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
#[deprecated(note = "retired; use persona/world/put/1.0")]
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.
///
#[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.
///
#[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(
"{\"$defs\":{\"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.\",\"minimum\":0,\"title\":\"ExpectedVersion\",\"type\":\"integer\"},\"Ext\":{\"additionalProperties\":true,\"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.\",\"minProperties\":1,\"propertyNames\":{\"pattern\":\"^[a-z][a-z0-9-]*(\\\\.[a-z0-9-]+)+$\"},\"title\":\"Ext\",\"type\":\"object\"},\"FacetColour\":{\"description\":\"**Superseded by `WorldColour`** — the same set, under the name the rest of the family now uses. Retained because `persona/facet/*` is retired in favour of `persona/world/*`, and a retired specification's schema is frozen, so the definition it references has to stay. New work references `WorldColour`. 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.\",\"enum\":[\"slate\",\"indigo\",\"teal\",\"moss\",\"sand\",\"clay\",\"rose\",\"plum\"],\"title\":\"FacetColour\",\"type\":\"string\"},\"Response\":{\"$anchor\":\"response\",\"additionalProperties\":false,\"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.\",\"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\":{\"format\":\"date-time\",\"type\":\"string\"},\"ext\":{\"$ref\":\"#/$defs/Ext\"},\"facetId\":{\"$ref\":\"#/$defs/Ulid\"},\"updatedAt\":{\"format\":\"date-time\",\"type\":\"string\"},\"version\":{\"$ref\":\"#/$defs/Version\"}},\"required\":[\"facetId\",\"version\",\"created\",\"updatedAt\"],\"title\":\"Persona Facet Put — response payload\",\"type\":\"object\"},\"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.\",\"pattern\":\"^[0-9A-HJKMNP-TV-Z]{26}$\",\"title\":\"Ulid\",\"type\":\"string\"},\"Version\":{\"description\":\"A value of the store's monotonic write counter. Server-assigned; a producer never chooses one.\",\"minimum\":1,\"title\":\"Version\",\"type\":\"integer\"}},\"$id\":\"https://trusttasks.org/spec/persona/facet/put/1.0\",\"$schema\":\"https://json-schema.org/draft/2020-12/schema\",\"additionalProperties\":false,\"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.\",\"properties\":{\"attributeIds\":{\"default\":[],\"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`.\",\"items\":{\"$ref\":\"#/$defs/Ulid\"},\"maxItems\":1024,\"type\":\"array\",\"uniqueItems\":true},\"colour\":{\"$ref\":\"#/$defs/FacetColour\"},\"expectedVersion\":{\"$ref\":\"#/$defs/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.\"},\"ext\":{\"$ref\":\"#/$defs/Ext\"},\"faceIds\":{\"default\":[],\"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.\",\"items\":{\"$ref\":\"#/$defs/Ulid\"},\"maxItems\":256,\"type\":\"array\",\"uniqueItems\":true},\"facetId\":{\"$ref\":\"#/$defs/Ulid\",\"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`.\"},\"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.\",\"maxLength\":8,\"minLength\":1,\"type\":\"string\"},\"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.\",\"maxLength\":64,\"minLength\":1,\"type\":\"string\"}},\"required\":[\"name\",\"colour\"],\"title\":\"Persona — Facet Put — payload\",\"type\":\"object\"}\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(
"{\"$defs\":{\"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.\",\"minimum\":0,\"title\":\"ExpectedVersion\",\"type\":\"integer\"},\"Ext\":{\"additionalProperties\":true,\"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.\",\"minProperties\":1,\"propertyNames\":{\"pattern\":\"^[a-z][a-z0-9-]*(\\\\.[a-z0-9-]+)+$\"},\"title\":\"Ext\",\"type\":\"object\"},\"FacetColour\":{\"description\":\"**Superseded by `WorldColour`** — the same set, under the name the rest of the family now uses. Retained because `persona/facet/*` is retired in favour of `persona/world/*`, and a retired specification's schema is frozen, so the definition it references has to stay. New work references `WorldColour`. 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.\",\"enum\":[\"slate\",\"indigo\",\"teal\",\"moss\",\"sand\",\"clay\",\"rose\",\"plum\"],\"title\":\"FacetColour\",\"type\":\"string\"},\"Response\":{\"$anchor\":\"response\",\"additionalProperties\":false,\"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.\",\"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\":{\"format\":\"date-time\",\"type\":\"string\"},\"ext\":{\"$ref\":\"#/$defs/Ext\"},\"facetId\":{\"$ref\":\"#/$defs/Ulid\"},\"updatedAt\":{\"format\":\"date-time\",\"type\":\"string\"},\"version\":{\"$ref\":\"#/$defs/Version\"}},\"required\":[\"facetId\",\"version\",\"created\",\"updatedAt\"],\"title\":\"Persona Facet Put — response payload\",\"type\":\"object\"},\"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.\",\"pattern\":\"^[0-9A-HJKMNP-TV-Z]{26}$\",\"title\":\"Ulid\",\"type\":\"string\"},\"Version\":{\"description\":\"A value of the store's monotonic write counter. Server-assigned; a producer never chooses one.\",\"minimum\":1,\"title\":\"Version\",\"type\":\"integer\"}},\"$ref\":\"#/$defs/Response\",\"$schema\":\"https://json-schema.org/draft/2020-12/schema\"}\n",
);
}
impl crate::RequestPayload for Payload {
type Response = Response;
}
/// The earlier `MAJOR.MINOR` of this slug that this version declares it
/// extends (front matter `extends`, SPEC §5.2 "Declared extension"), or
/// `None`. Only the direct declaration; walk a chain with
/// [`crate::extension::extends_for`].
pub const EXTENDS: Option<&str> = None;
/// The extended error codes this specification declares (SPEC §7.3 item 9,
/// §8.5), in declaration order. Empty when it declares none.
pub const ERROR_CODES: &[crate::DeclaredErrorCode] = &[
error_codes::FACE_ALREADY_PLACED,
error_codes::UNRESOLVED_REFERENCE,
error_codes::VERSION_CONFLICT,
];
/// One constant per extended error code this specification declares
/// (SPEC §7.3 item 9), named for its local part.
///
/// Emit these rather than a string literal: the code is read from the
/// specification, so it cannot name a code the specification never
/// declared.
pub mod error_codes {
/// `persona/facet/put:faceAlreadyPlaced`
///
/// One or more of the listed `faceIds` already belongs to a different facet. The details name each offending profile and the facet currently holding it, so a producer can offer to move it rather than guessing. The facet is not written.
///
/// Declared `retryable: false`.
/// Declares a `detailsSchema` for the error's `details` member.
pub const FACE_ALREADY_PLACED: crate::DeclaredErrorCode = crate::DeclaredErrorCode {
code: "persona/facet/put:faceAlreadyPlaced",
retryable: false,
details_schema: ::core::option::Option::Some(
"{\"additionalProperties\":false,\"properties\":{\"placed\":{\"items\":{\"additionalProperties\":false,\"properties\":{\"faceId\":{\"type\":\"string\"},\"facetId\":{\"type\":\"string\"}},\"required\":[\"faceId\",\"facetId\"],\"type\":\"object\"},\"maxItems\":256,\"type\":\"array\"}},\"required\":[\"placed\"],\"type\":\"object\"}",
),
};
/// `persona/facet/put:unresolvedReference`
///
/// A listed `faceId` or `attributeId` names a record the holder does not hold. The details name them. The facet is not written — an arrangement referring to something that never existed is a typo, and accepting it silently makes the typo permanent.
///
/// Declared `retryable: false`.
/// Declares a `detailsSchema` for the error's `details` member.
pub const UNRESOLVED_REFERENCE: crate::DeclaredErrorCode = crate::DeclaredErrorCode {
code: "persona/facet/put:unresolvedReference",
retryable: false,
details_schema: ::core::option::Option::Some(
"{\"additionalProperties\":false,\"properties\":{\"attributeIds\":{\"items\":{\"type\":\"string\"},\"maxItems\":1024,\"type\":\"array\"},\"faceIds\":{\"items\":{\"type\":\"string\"},\"maxItems\":256,\"type\":\"array\"}},\"type\":\"object\"}",
),
};
/// `persona/facet/put:versionConflict`
///
/// The `expectedVersion` precondition failed. Details carry the maintainer's current version.
///
/// Declared `retryable: false`.
pub const VERSION_CONFLICT: crate::DeclaredErrorCode = crate::DeclaredErrorCode {
code: "persona/facet/put:versionConflict",
retryable: false,
details_schema: ::core::option::Option::None,
};
}