//! Generated by `trust-tasks-codegen` — do not edit by hand.
//!
//! Spec slug: `did-management/stats/get`. Version: `0.1`.
#[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())
}
}
}
///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())
})
}
}
///`Payload`
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "$id": "https://trusttasks.org/spec/did-management/stats/get/0.1",
/// "title": "Payload",
/// "type": "object",
/// "properties": {
/// "domain": {
/// "description": "Disambiguates `mnemonic` per the category conventions. Absent means the domain is resolved by the category's chain. MUST NOT be present without `mnemonic`: this task has no per-domain aggregate (did-management/stats/timeseries does).",
/// "type": "string",
/// "maxLength": 253,
/// "minLength": 1
/// },
/// "ext": {
/// "$ref": "#/definitions/Ext"
/// },
/// "mnemonic": {
/// "description": "The slot whose counters are read. Absent means the hosting service's server-wide aggregate, which only an administrator may read.",
/// "type": "string",
/// "maxLength": 512,
/// "minLength": 1
/// }
/// },
/// "additionalProperties": false,
/// "dependentRequired": {
/// "domain": [
/// "mnemonic"
/// ]
/// }
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct Payload {
///Disambiguates `mnemonic` per the category conventions. Absent means the domain is resolved by the category's chain. MUST NOT be present without `mnemonic`: this task has no per-domain aggregate (did-management/stats/timeseries does).
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub domain: ::std::option::Option<PayloadDomain>,
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub ext: ::std::option::Option<Ext>,
///The slot whose counters are read. Absent means the hosting service's server-wide aggregate, which only an administrator may read.
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub mnemonic: ::std::option::Option<PayloadMnemonic>,
}
impl ::std::default::Default for Payload {
fn default() -> Self {
Self {
domain: Default::default(),
ext: Default::default(),
mnemonic: Default::default(),
}
}
}
impl Payload {
pub fn builder() -> builder::Payload {
Default::default()
}
}
///Disambiguates `mnemonic` per the category conventions. Absent means the domain is resolved by the category's chain. MUST NOT be present without `mnemonic`: this task has no per-domain aggregate (did-management/stats/timeseries does).
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "Disambiguates `mnemonic` per the category conventions. Absent means the domain is resolved by the category's chain. MUST NOT be present without `mnemonic`: this task has no per-domain aggregate (did-management/stats/timeseries does).",
/// "type": "string",
/// "maxLength": 253,
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct PayloadDomain(::std::string::String);
impl ::std::ops::Deref for PayloadDomain {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<PayloadDomain> for ::std::string::String {
fn from(value: PayloadDomain) -> Self {
value.0
}
}
impl ::std::str::FromStr for PayloadDomain {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() > 253usize {
return Err("longer than 253 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 PayloadDomain {
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 PayloadDomain {
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 PayloadDomain {
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 PayloadDomain {
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 slot whose counters are read. Absent means the hosting service's server-wide aggregate, which only an administrator may read.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "The slot whose counters are read. Absent means the hosting service's server-wide aggregate, which only an administrator may read.",
/// "type": "string",
/// "maxLength": 512,
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct PayloadMnemonic(::std::string::String);
impl ::std::ops::Deref for PayloadMnemonic {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<PayloadMnemonic> for ::std::string::String {
fn from(value: PayloadMnemonic) -> Self {
value.0
}
}
impl ::std::str::FromStr for PayloadMnemonic {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() > 512usize {
return Err("longer than 512 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 PayloadMnemonic {
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 PayloadMnemonic {
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 PayloadMnemonic {
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 PayloadMnemonic {
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())
})
}
}
///`Response`
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "Response",
/// "type": "object",
/// "required": [
/// "totalResolves",
/// "totalUpdates"
/// ],
/// "properties": {
/// "ext": {
/// "$ref": "#/definitions/Ext"
/// },
/// "lastResolvedAt": {
/// "description": "Absent when the scope has never been resolved.",
/// "type": "string",
/// "format": "date-time"
/// },
/// "lastUpdatedAt": {
/// "description": "Absent when the scope has never been updated.",
/// "type": "string",
/// "format": "date-time"
/// },
/// "mnemonic": {
/// "description": "Echo of the slot read. Absent on the server-wide aggregate.",
/// "type": "string"
/// },
/// "totalDids": {
/// "description": "Slots the hosting service holds. Present only on the server-wide aggregate.",
/// "type": "integer",
/// "minimum": 0.0
/// },
/// "totalResolves": {
/// "type": "integer",
/// "minimum": 0.0
/// },
/// "totalUpdates": {
/// "type": "integer",
/// "minimum": 0.0
/// }
/// },
/// "additionalProperties": false,
/// "$anchor": "response"
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct Response {
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub ext: ::std::option::Option<Ext>,
///Absent when the scope has never been resolved.
#[serde(
rename = "lastResolvedAt",
default,
skip_serializing_if = "::std::option::Option::is_none"
)]
pub last_resolved_at: ::std::option::Option<::chrono::DateTime<::chrono::offset::Utc>>,
///Absent when the scope has never been updated.
#[serde(
rename = "lastUpdatedAt",
default,
skip_serializing_if = "::std::option::Option::is_none"
)]
pub last_updated_at: ::std::option::Option<::chrono::DateTime<::chrono::offset::Utc>>,
///Echo of the slot read. Absent on the server-wide aggregate.
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub mnemonic: ::std::option::Option<::std::string::String>,
///Slots the hosting service holds. Present only on the server-wide aggregate.
#[serde(
rename = "totalDids",
default,
skip_serializing_if = "::std::option::Option::is_none"
)]
pub total_dids: ::std::option::Option<u64>,
#[serde(rename = "totalResolves")]
pub total_resolves: u64,
#[serde(rename = "totalUpdates")]
pub total_updates: u64,
}
impl Response {
pub fn builder() -> builder::Response {
Default::default()
}
}
/// Types for composing complex structures.
pub mod builder {
#[derive(Clone, Debug)]
pub struct Payload {
domain: ::std::result::Result<
::std::option::Option<super::PayloadDomain>,
::std::string::String,
>,
ext: ::std::result::Result<::std::option::Option<super::Ext>, ::std::string::String>,
mnemonic: ::std::result::Result<
::std::option::Option<super::PayloadMnemonic>,
::std::string::String,
>,
}
impl ::std::default::Default for Payload {
fn default() -> Self {
Self {
domain: Ok(Default::default()),
ext: Ok(Default::default()),
mnemonic: Ok(Default::default()),
}
}
}
impl Payload {
pub fn domain<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::PayloadDomain>>,
T::Error: ::std::fmt::Display,
{
self.domain = value
.try_into()
.map_err(|e| format!("error converting supplied value for domain: {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 mnemonic<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::PayloadMnemonic>>,
T::Error: ::std::fmt::Display,
{
self.mnemonic = value
.try_into()
.map_err(|e| format!("error converting supplied value for mnemonic: {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 {
domain: value.domain?,
ext: value.ext?,
mnemonic: value.mnemonic?,
})
}
}
impl ::std::convert::From<super::Payload> for Payload {
fn from(value: super::Payload) -> Self {
Self {
domain: Ok(value.domain),
ext: Ok(value.ext),
mnemonic: Ok(value.mnemonic),
}
}
}
#[derive(Clone, Debug)]
pub struct Response {
ext: ::std::result::Result<::std::option::Option<super::Ext>, ::std::string::String>,
last_resolved_at: ::std::result::Result<
::std::option::Option<::chrono::DateTime<::chrono::offset::Utc>>,
::std::string::String,
>,
last_updated_at: ::std::result::Result<
::std::option::Option<::chrono::DateTime<::chrono::offset::Utc>>,
::std::string::String,
>,
mnemonic: ::std::result::Result<
::std::option::Option<::std::string::String>,
::std::string::String,
>,
total_dids: ::std::result::Result<::std::option::Option<u64>, ::std::string::String>,
total_resolves: ::std::result::Result<u64, ::std::string::String>,
total_updates: ::std::result::Result<u64, ::std::string::String>,
}
impl ::std::default::Default for Response {
fn default() -> Self {
Self {
ext: Ok(Default::default()),
last_resolved_at: Ok(Default::default()),
last_updated_at: Ok(Default::default()),
mnemonic: Ok(Default::default()),
total_dids: Ok(Default::default()),
total_resolves: Err("no value supplied for total_resolves".to_string()),
total_updates: Err("no value supplied for total_updates".to_string()),
}
}
}
impl Response {
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 last_resolved_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.last_resolved_at = value
.try_into()
.map_err(|e| format!("error converting supplied value for last_resolved_at: {e}"));
self
}
pub fn last_updated_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.last_updated_at = value
.try_into()
.map_err(|e| format!("error converting supplied value for last_updated_at: {e}"));
self
}
pub fn mnemonic<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<::std::string::String>>,
T::Error: ::std::fmt::Display,
{
self.mnemonic = value
.try_into()
.map_err(|e| format!("error converting supplied value for mnemonic: {e}"));
self
}
pub fn total_dids<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<u64>>,
T::Error: ::std::fmt::Display,
{
self.total_dids = value
.try_into()
.map_err(|e| format!("error converting supplied value for total_dids: {e}"));
self
}
pub fn total_resolves<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<u64>,
T::Error: ::std::fmt::Display,
{
self.total_resolves = value
.try_into()
.map_err(|e| format!("error converting supplied value for total_resolves: {e}"));
self
}
pub fn total_updates<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<u64>,
T::Error: ::std::fmt::Display,
{
self.total_updates = value
.try_into()
.map_err(|e| format!("error converting supplied value for total_updates: {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 {
ext: value.ext?,
last_resolved_at: value.last_resolved_at?,
last_updated_at: value.last_updated_at?,
mnemonic: value.mnemonic?,
total_dids: value.total_dids?,
total_resolves: value.total_resolves?,
total_updates: value.total_updates?,
})
}
}
impl ::std::convert::From<super::Response> for Response {
fn from(value: super::Response) -> Self {
Self {
ext: Ok(value.ext),
last_resolved_at: Ok(value.last_resolved_at),
last_updated_at: Ok(value.last_updated_at),
mnemonic: Ok(value.mnemonic),
total_dids: Ok(value.total_dids),
total_resolves: Ok(value.total_resolves),
total_updates: Ok(value.total_updates),
}
}
}
}
impl crate::Payload for Payload {
const TYPE_URI: &'static str = "https://trusttasks.org/spec/did-management/stats/get/0.1";
const IS_PROOF_REQUIRED: bool = true;
const IS_RECIPIENT_REQUIRED: bool = true;
const PAYLOAD_SCHEMA: Option<&'static str> = Some(
"{\n \"$defs\": {\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 \"Response\": {\n \"$anchor\": \"response\",\n \"additionalProperties\": false,\n \"properties\": {\n \"ext\": {\n \"$ref\": \"#/$defs/Ext\"\n },\n \"lastResolvedAt\": {\n \"description\": \"Absent when the scope has never been resolved.\",\n \"format\": \"date-time\",\n \"type\": \"string\"\n },\n \"lastUpdatedAt\": {\n \"description\": \"Absent when the scope has never been updated.\",\n \"format\": \"date-time\",\n \"type\": \"string\"\n },\n \"mnemonic\": {\n \"description\": \"Echo of the slot read. Absent on the server-wide aggregate.\",\n \"type\": \"string\"\n },\n \"totalDids\": {\n \"description\": \"Slots the hosting service holds. Present only on the server-wide aggregate.\",\n \"minimum\": 0,\n \"type\": \"integer\"\n },\n \"totalResolves\": {\n \"minimum\": 0,\n \"type\": \"integer\"\n },\n \"totalUpdates\": {\n \"minimum\": 0,\n \"type\": \"integer\"\n }\n },\n \"required\": [\n \"totalResolves\",\n \"totalUpdates\"\n ],\n \"title\": \"Stats Get — response payload\",\n \"type\": \"object\"\n }\n },\n \"$id\": \"https://trusttasks.org/spec/did-management/stats/get/0.1\",\n \"$schema\": \"https://json-schema.org/draft/2020-12/schema\",\n \"additionalProperties\": false,\n \"dependentRequired\": {\n \"domain\": [\n \"mnemonic\"\n ]\n },\n \"properties\": {\n \"domain\": {\n \"description\": \"Disambiguates `mnemonic` per the category conventions. Absent means the domain is resolved by the category's chain. MUST NOT be present without `mnemonic`: this task has no per-domain aggregate (did-management/stats/timeseries does).\",\n \"maxLength\": 253,\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"ext\": {\n \"$ref\": \"#/$defs/Ext\"\n },\n \"mnemonic\": {\n \"description\": \"The slot whose counters are read. Absent means the hosting service's server-wide aggregate, which only an administrator may read.\",\n \"maxLength\": 512,\n \"minLength\": 1,\n \"type\": \"string\"\n }\n },\n \"title\": \"Stats Get — payload\",\n \"type\": \"object\"\n}\n",
);
}
impl crate::Payload for Response {
const TYPE_URI: &'static str =
"https://trusttasks.org/spec/did-management/stats/get/0.1#response";
const IS_PROOF_REQUIRED: bool = true;
const IS_RECIPIENT_REQUIRED: bool = true;
const PAYLOAD_SCHEMA: Option<&'static str> = Some(
"{\n \"$defs\": {\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 \"Response\": {\n \"$anchor\": \"response\",\n \"additionalProperties\": false,\n \"properties\": {\n \"ext\": {\n \"$ref\": \"#/$defs/Ext\"\n },\n \"lastResolvedAt\": {\n \"description\": \"Absent when the scope has never been resolved.\",\n \"format\": \"date-time\",\n \"type\": \"string\"\n },\n \"lastUpdatedAt\": {\n \"description\": \"Absent when the scope has never been updated.\",\n \"format\": \"date-time\",\n \"type\": \"string\"\n },\n \"mnemonic\": {\n \"description\": \"Echo of the slot read. Absent on the server-wide aggregate.\",\n \"type\": \"string\"\n },\n \"totalDids\": {\n \"description\": \"Slots the hosting service holds. Present only on the server-wide aggregate.\",\n \"minimum\": 0,\n \"type\": \"integer\"\n },\n \"totalResolves\": {\n \"minimum\": 0,\n \"type\": \"integer\"\n },\n \"totalUpdates\": {\n \"minimum\": 0,\n \"type\": \"integer\"\n }\n },\n \"required\": [\n \"totalResolves\",\n \"totalUpdates\"\n ],\n \"title\": \"Stats Get — response payload\",\n \"type\": \"object\"\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;
}
/// 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::NOT_FOUND, error_codes::UNKNOWN_DOMAIN];
/// 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 {
/// `did-management/stats/get:notFound`
///
/// No slot the caller may read has this `mnemonic`. Returned alike for a slot that does not exist and for one the caller does not own, so the code cannot be used to learn which slots exist.
///
/// Declared `retryable: false`.
pub const NOT_FOUND: crate::DeclaredErrorCode = crate::DeclaredErrorCode {
code: "did-management/stats/get:notFound",
retryable: false,
};
/// `did-management:unknownDomain`
///
/// The submitted `domain` is not a known hosting domain on this consumer. See [category conventions](../../../_shared/0.1/CONVENTIONS.md#2-unknown-domain-error).
///
/// Declared `retryable: false`.
pub const UNKNOWN_DOMAIN: crate::DeclaredErrorCode = crate::DeclaredErrorCode {
code: "did-management:unknownDomain",
retryable: false,
};
}
#[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:9e4a6dbc-5b7f-4acd-9c6d-4f5a6b7c8d01\",\n \"type\": \"https://trusttasks.org/spec/did-management/stats/get/0.1\",\n \"issuer\": \"did:webvh:QmVtaScid5:vta.example.com\",\n \"recipient\": \"did:webvh:QmControlScid2:control.example.com\",\n \"issuedAt\": \"2026-09-27T09:00:00Z\",\n \"payload\": { \"mnemonic\": \"alice\" }\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:9e4a6dbc-5b7f-4acd-9c6d-4f5a6b7c8d02\",\n \"type\": \"https://trusttasks.org/spec/did-management/stats/get/0.1#response\",\n \"threadId\": \"urn:uuid:9e4a6dbc-5b7f-4acd-9c6d-4f5a6b7c8d01\",\n \"issuer\": \"did:webvh:QmControlScid2:control.example.com\",\n \"recipient\": \"did:webvh:QmVtaScid5:vta.example.com\",\n \"issuedAt\": \"2026-09-27T09:00:01Z\",\n \"payload\": {\n \"mnemonic\": \"alice\",\n \"totalResolves\": 1287,\n \"totalUpdates\": 4,\n \"lastResolvedAt\": \"2026-09-27T08:58:12Z\",\n \"lastUpdatedAt\": \"2026-09-20T14:02:00Z\"\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");
}
#[test]
fn response_example_2() {
const JSON: &str = "{\n \"id\": \"urn:uuid:9e4a6dbc-5b7f-4acd-9c6d-4f5a6b7c8d04\",\n \"type\": \"https://trusttasks.org/spec/did-management/stats/get/0.1#response\",\n \"threadId\": \"urn:uuid:9e4a6dbc-5b7f-4acd-9c6d-4f5a6b7c8d03\",\n \"issuer\": \"did:webvh:QmControlScid2:control.example.com\",\n \"recipient\": \"did:webvh:QmAdminScid1:admin.example.com:alice\",\n \"issuedAt\": \"2026-09-27T09:00:01Z\",\n \"payload\": { \"totalDids\": 412, \"totalResolves\": 90211, \"totalUpdates\": 1733, \"lastResolvedAt\": \"2026-09-27T09:00:00Z\", \"lastUpdatedAt\": \"2026-09-27T08:41:07Z\" }\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");
}
/// Each fixture in `payload.invalid-examples.json` MUST be
/// rejected by at least one of: serde deserialization, or
/// JSON-Schema validation under the `validate` feature. The
/// fixture file documents the producer-side bug class that
/// each payload exemplifies; this generated test pins it.
#[cfg(feature = "validate")]
#[test]
fn rejects_invalid_examples() {
use crate::validate::ValidatedPayload;
let fixtures: &[(&str, &str)] = &[
(
"domain without mnemonic — there is no per-domain aggregate on this task.",
"{\n \"domain\": \"did.example.com\"\n}",
),
("Empty mnemonic.", "{\n \"mnemonic\": \"\"\n}"),
(
"Unknown member.",
"{\n \"mnemonic\": \"alice\",\n \"range\": \"lastDay\"\n}",
),
];
for (i, (note, raw)) in fixtures.iter().enumerate() {
let value: serde_json::Value = match serde_json::from_str(raw) {
Ok(v) => v,
Err(_) => continue,
};
let serde_ok = serde_json::from_value::<super::Payload>(value.clone()).is_ok();
let schema_ok = super::Payload::validate_value(&value).is_ok();
assert!(
!(serde_ok && schema_ok),
"invalid-example #{} ({:?}) was accepted by both serde and JSON Schema; \
the fixture's stated failure class is no longer caught:\n{}",
i + 1,
note,
raw
);
}
}
}