//! Generated by `trust-tasks-codegen` — do not edit by hand.
//!
//! Spec slug: `messaging/message/status`. 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())
})
}
}
///Where a sent message stands. `queued`: held for the recipient and not yet handed over. `delivered`: handed to the recipient (pickup or live stream) and not yet removed by it. `collected`: removed by the recipient — acknowledged after pickup, fetched with delete, or deleted or purged by it. `withdrawn`: removed by the sender. `discarded`: removed by the mediator before the recipient took it — expired, or its account was removed. `unknown`: the mediator holds neither the message nor a receipt for it under the requester.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "MessageState",
/// "description": "Where a sent message stands. `queued`: held for the recipient and not yet handed over. `delivered`: handed to the recipient (pickup or live stream) and not yet removed by it. `collected`: removed by the recipient — acknowledged after pickup, fetched with delete, or deleted or purged by it. `withdrawn`: removed by the sender. `discarded`: removed by the mediator before the recipient took it — expired, or its account was removed. `unknown`: the mediator holds neither the message nor a receipt for it under the requester.",
/// "type": "string",
/// "enum": [
/// "queued",
/// "delivered",
/// "collected",
/// "withdrawn",
/// "discarded",
/// "unknown"
/// ]
///}
/// ```
/// </details>
#[derive(
::serde::Deserialize,
::serde::Serialize,
Clone,
Copy,
Debug,
Eq,
Hash,
Ord,
PartialEq,
PartialOrd,
)]
#[non_exhaustive]
pub enum MessageState {
#[serde(rename = "queued")]
Queued,
#[serde(rename = "delivered")]
Delivered,
#[serde(rename = "collected")]
Collected,
#[serde(rename = "withdrawn")]
Withdrawn,
#[serde(rename = "discarded")]
Discarded,
#[serde(rename = "unknown")]
Unknown,
}
impl ::std::fmt::Display for MessageState {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
match *self {
Self::Queued => f.write_str("queued"),
Self::Delivered => f.write_str("delivered"),
Self::Collected => f.write_str("collected"),
Self::Withdrawn => f.write_str("withdrawn"),
Self::Discarded => f.write_str("discarded"),
Self::Unknown => f.write_str("unknown"),
}
}
}
impl ::std::str::FromStr for MessageState {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
match value {
"queued" => Ok(Self::Queued),
"delivered" => Ok(Self::Delivered),
"collected" => Ok(Self::Collected),
"withdrawn" => Ok(Self::Withdrawn),
"discarded" => Ok(Self::Discarded),
"unknown" => Ok(Self::Unknown),
_ => Err("invalid value".into()),
}
}
}
impl ::std::convert::TryFrom<&str> for MessageState {
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 MessageState {
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 MessageState {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
///`Payload`
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "$id": "https://trusttasks.org/spec/messaging/message/status/0.1",
/// "title": "Payload",
/// "type": "object",
/// "required": [
/// "msgIds"
/// ],
/// "properties": {
/// "ext": {
/// "description": "Ecosystem-defined extension members per SPEC.md §4.5.1.",
/// "$ref": "#/definitions/Ext"
/// },
/// "msgIds": {
/// "description": "The messages the requester sent and wants the status of, by the mediator's message identifier.",
/// "type": "array",
/// "items": {
/// "type": "string",
/// "maxLength": 256,
/// "minLength": 1
/// },
/// "maxItems": 100,
/// "minItems": 1,
/// "uniqueItems": true
/// }
/// },
/// "additionalProperties": false
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct Payload {
///Ecosystem-defined extension members per SPEC.md §4.5.1.
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub ext: ::std::option::Option<Ext>,
///The messages the requester sent and wants the status of, by the mediator's message identifier.
#[serde(rename = "msgIds")]
pub msg_ids: Vec<PayloadMsgIdsItem>,
}
impl Payload {
pub fn builder() -> builder::Payload {
Default::default()
}
}
///`PayloadMsgIdsItem`
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "type": "string",
/// "maxLength": 256,
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct PayloadMsgIdsItem(::std::string::String);
impl ::std::ops::Deref for PayloadMsgIdsItem {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<PayloadMsgIdsItem> for ::std::string::String {
fn from(value: PayloadMsgIdsItem) -> Self {
value.0
}
}
impl ::std::str::FromStr for PayloadMsgIdsItem {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() > 256usize {
return Err("longer than 256 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 PayloadMsgIdsItem {
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 PayloadMsgIdsItem {
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 PayloadMsgIdsItem {
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 PayloadMsgIdsItem {
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 success response to a messaging/message/status request. Carried in a Trust Task document whose type is https://trusttasks.org/spec/messaging/message/status/0.1#response.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "Response",
/// "description": "The success response to a messaging/message/status request. Carried in a Trust Task document whose type is https://trusttasks.org/spec/messaging/message/status/0.1#response.",
/// "type": "object",
/// "required": [
/// "statuses"
/// ],
/// "properties": {
/// "ext": {
/// "description": "Ecosystem-defined extension members per SPEC.md §4.5.1.",
/// "$ref": "#/definitions/Ext"
/// },
/// "statuses": {
/// "description": "One entry per requested msgId, in request order.",
/// "type": "array",
/// "items": {
/// "type": "object",
/// "required": [
/// "msgId",
/// "state"
/// ],
/// "properties": {
/// "at": {
/// "description": "When the message reached this state: first handed over for `delivered`, removed for `collected`, `withdrawn` and `discarded`. Absent for `queued` and `unknown`, and wherever the mediator does not disclose it.",
/// "type": "string",
/// "format": "date-time"
/// },
/// "msgId": {
/// "type": "string",
/// "maxLength": 256,
/// "minLength": 1
/// },
/// "state": {
/// "$ref": "#/definitions/MessageState"
/// }
/// },
/// "additionalProperties": false
/// }
/// }
/// },
/// "additionalProperties": false,
/// "$anchor": "response"
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct Response {
///Ecosystem-defined extension members per SPEC.md §4.5.1.
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub ext: ::std::option::Option<Ext>,
///One entry per requested msgId, in request order.
pub statuses: ::std::vec::Vec<ResponseStatusesItem>,
}
impl Response {
pub fn builder() -> builder::Response {
Default::default()
}
}
///`ResponseStatusesItem`
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "type": "object",
/// "required": [
/// "msgId",
/// "state"
/// ],
/// "properties": {
/// "at": {
/// "description": "When the message reached this state: first handed over for `delivered`, removed for `collected`, `withdrawn` and `discarded`. Absent for `queued` and `unknown`, and wherever the mediator does not disclose it.",
/// "type": "string",
/// "format": "date-time"
/// },
/// "msgId": {
/// "type": "string",
/// "maxLength": 256,
/// "minLength": 1
/// },
/// "state": {
/// "$ref": "#/definitions/MessageState"
/// }
/// },
/// "additionalProperties": false
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct ResponseStatusesItem {
///When the message reached this state: first handed over for `delivered`, removed for `collected`, `withdrawn` and `discarded`. Absent for `queued` and `unknown`, and wherever the mediator does not disclose it.
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub at: ::std::option::Option<::chrono::DateTime<::chrono::offset::Utc>>,
#[serde(rename = "msgId")]
pub msg_id: ResponseStatusesItemMsgId,
pub state: MessageState,
}
impl ResponseStatusesItem {
pub fn builder() -> builder::ResponseStatusesItem {
Default::default()
}
}
///`ResponseStatusesItemMsgId`
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "type": "string",
/// "maxLength": 256,
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct ResponseStatusesItemMsgId(::std::string::String);
impl ::std::ops::Deref for ResponseStatusesItemMsgId {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<ResponseStatusesItemMsgId> for ::std::string::String {
fn from(value: ResponseStatusesItemMsgId) -> Self {
value.0
}
}
impl ::std::str::FromStr for ResponseStatusesItemMsgId {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() > 256usize {
return Err("longer than 256 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 ResponseStatusesItemMsgId {
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 ResponseStatusesItemMsgId {
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 ResponseStatusesItemMsgId {
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 ResponseStatusesItemMsgId {
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())
})
}
}
/// Types for composing complex structures.
pub mod builder {
#[derive(Clone, Debug)]
pub struct Payload {
ext: ::std::result::Result<::std::option::Option<super::Ext>, ::std::string::String>,
msg_ids: ::std::result::Result<Vec<super::PayloadMsgIdsItem>, ::std::string::String>,
}
impl ::std::default::Default for Payload {
fn default() -> Self {
Self {
ext: Ok(Default::default()),
msg_ids: Err("no value supplied for msg_ids".to_string()),
}
}
}
impl Payload {
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 msg_ids<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<Vec<super::PayloadMsgIdsItem>>,
T::Error: ::std::fmt::Display,
{
self.msg_ids = value
.try_into()
.map_err(|e| format!("error converting supplied value for msg_ids: {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 {
ext: value.ext?,
msg_ids: value.msg_ids?,
})
}
}
impl ::std::convert::From<super::Payload> for Payload {
fn from(value: super::Payload) -> Self {
Self {
ext: Ok(value.ext),
msg_ids: Ok(value.msg_ids),
}
}
}
#[derive(Clone, Debug)]
pub struct Response {
ext: ::std::result::Result<::std::option::Option<super::Ext>, ::std::string::String>,
statuses: ::std::result::Result<
::std::vec::Vec<super::ResponseStatusesItem>,
::std::string::String,
>,
}
impl ::std::default::Default for Response {
fn default() -> Self {
Self {
ext: Ok(Default::default()),
statuses: Err("no value supplied for statuses".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 statuses<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::vec::Vec<super::ResponseStatusesItem>>,
T::Error: ::std::fmt::Display,
{
self.statuses = value
.try_into()
.map_err(|e| format!("error converting supplied value for statuses: {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?,
statuses: value.statuses?,
})
}
}
impl ::std::convert::From<super::Response> for Response {
fn from(value: super::Response) -> Self {
Self {
ext: Ok(value.ext),
statuses: Ok(value.statuses),
}
}
}
#[derive(Clone, Debug)]
pub struct ResponseStatusesItem {
at: ::std::result::Result<
::std::option::Option<::chrono::DateTime<::chrono::offset::Utc>>,
::std::string::String,
>,
msg_id: ::std::result::Result<super::ResponseStatusesItemMsgId, ::std::string::String>,
state: ::std::result::Result<super::MessageState, ::std::string::String>,
}
impl ::std::default::Default for ResponseStatusesItem {
fn default() -> Self {
Self {
at: Ok(Default::default()),
msg_id: Err("no value supplied for msg_id".to_string()),
state: Err("no value supplied for state".to_string()),
}
}
}
impl ResponseStatusesItem {
pub fn 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.at = value
.try_into()
.map_err(|e| format!("error converting supplied value for at: {e}"));
self
}
pub fn msg_id<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::ResponseStatusesItemMsgId>,
T::Error: ::std::fmt::Display,
{
self.msg_id = value
.try_into()
.map_err(|e| format!("error converting supplied value for msg_id: {e}"));
self
}
pub fn state<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::MessageState>,
T::Error: ::std::fmt::Display,
{
self.state = value
.try_into()
.map_err(|e| format!("error converting supplied value for state: {e}"));
self
}
}
impl ::std::convert::TryFrom<ResponseStatusesItem> for super::ResponseStatusesItem {
type Error = super::error::ConversionError;
fn try_from(
value: ResponseStatusesItem,
) -> ::std::result::Result<Self, super::error::ConversionError> {
Ok(Self {
at: value.at?,
msg_id: value.msg_id?,
state: value.state?,
})
}
}
impl ::std::convert::From<super::ResponseStatusesItem> for ResponseStatusesItem {
fn from(value: super::ResponseStatusesItem) -> Self {
Self {
at: Ok(value.at),
msg_id: Ok(value.msg_id),
state: Ok(value.state),
}
}
}
}
impl crate::Payload for Payload {
const TYPE_URI: &'static str = "https://trusttasks.org/spec/messaging/message/status/0.1";
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 \"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 \"MessageState\": {\n \"description\": \"Where a sent message stands. `queued`: held for the recipient and not yet handed over. `delivered`: handed to the recipient (pickup or live stream) and not yet removed by it. `collected`: removed by the recipient — acknowledged after pickup, fetched with delete, or deleted or purged by it. `withdrawn`: removed by the sender. `discarded`: removed by the mediator before the recipient took it — expired, or its account was removed. `unknown`: the mediator holds neither the message nor a receipt for it under the requester.\",\n \"enum\": [\n \"queued\",\n \"delivered\",\n \"collected\",\n \"withdrawn\",\n \"discarded\",\n \"unknown\"\n ],\n \"title\": \"MessageState\",\n \"type\": \"string\"\n },\n \"Response\": {\n \"$anchor\": \"response\",\n \"additionalProperties\": false,\n \"description\": \"The success response to a messaging/message/status request. Carried in a Trust Task document whose type is https://trusttasks.org/spec/messaging/message/status/0.1#response.\",\n \"properties\": {\n \"ext\": {\n \"$ref\": \"#/$defs/Ext\",\n \"description\": \"Ecosystem-defined extension members per SPEC.md §4.5.1.\"\n },\n \"statuses\": {\n \"description\": \"One entry per requested msgId, in request order.\",\n \"items\": {\n \"additionalProperties\": false,\n \"properties\": {\n \"at\": {\n \"description\": \"When the message reached this state: first handed over for `delivered`, removed for `collected`, `withdrawn` and `discarded`. Absent for `queued` and `unknown`, and wherever the mediator does not disclose it.\",\n \"format\": \"date-time\",\n \"type\": \"string\"\n },\n \"msgId\": {\n \"maxLength\": 256,\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"state\": {\n \"$ref\": \"#/$defs/MessageState\"\n }\n },\n \"required\": [\n \"msgId\",\n \"state\"\n ],\n \"type\": \"object\"\n },\n \"type\": \"array\"\n }\n },\n \"required\": [\n \"statuses\"\n ],\n \"title\": \"Messaging — Message Status — response payload\",\n \"type\": \"object\"\n }\n },\n \"$id\": \"https://trusttasks.org/spec/messaging/message/status/0.1\",\n \"$schema\": \"https://json-schema.org/draft/2020-12/schema\",\n \"additionalProperties\": false,\n \"properties\": {\n \"ext\": {\n \"$ref\": \"#/$defs/Ext\",\n \"description\": \"Ecosystem-defined extension members per SPEC.md §4.5.1.\"\n },\n \"msgIds\": {\n \"description\": \"The messages the requester sent and wants the status of, by the mediator's message identifier.\",\n \"items\": {\n \"maxLength\": 256,\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"maxItems\": 100,\n \"minItems\": 1,\n \"type\": \"array\",\n \"uniqueItems\": true\n }\n },\n \"required\": [\n \"msgIds\"\n ],\n \"title\": \"Messaging — Message Status — payload\",\n \"type\": \"object\"\n}\n",
);
}
impl crate::Payload for Response {
const TYPE_URI: &'static str =
"https://trusttasks.org/spec/messaging/message/status/0.1#response";
const IS_ISSUED_AT_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 \"MessageState\": {\n \"description\": \"Where a sent message stands. `queued`: held for the recipient and not yet handed over. `delivered`: handed to the recipient (pickup or live stream) and not yet removed by it. `collected`: removed by the recipient — acknowledged after pickup, fetched with delete, or deleted or purged by it. `withdrawn`: removed by the sender. `discarded`: removed by the mediator before the recipient took it — expired, or its account was removed. `unknown`: the mediator holds neither the message nor a receipt for it under the requester.\",\n \"enum\": [\n \"queued\",\n \"delivered\",\n \"collected\",\n \"withdrawn\",\n \"discarded\",\n \"unknown\"\n ],\n \"title\": \"MessageState\",\n \"type\": \"string\"\n },\n \"Response\": {\n \"$anchor\": \"response\",\n \"additionalProperties\": false,\n \"description\": \"The success response to a messaging/message/status request. Carried in a Trust Task document whose type is https://trusttasks.org/spec/messaging/message/status/0.1#response.\",\n \"properties\": {\n \"ext\": {\n \"$ref\": \"#/$defs/Ext\",\n \"description\": \"Ecosystem-defined extension members per SPEC.md §4.5.1.\"\n },\n \"statuses\": {\n \"description\": \"One entry per requested msgId, in request order.\",\n \"items\": {\n \"additionalProperties\": false,\n \"properties\": {\n \"at\": {\n \"description\": \"When the message reached this state: first handed over for `delivered`, removed for `collected`, `withdrawn` and `discarded`. Absent for `queued` and `unknown`, and wherever the mediator does not disclose it.\",\n \"format\": \"date-time\",\n \"type\": \"string\"\n },\n \"msgId\": {\n \"maxLength\": 256,\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"state\": {\n \"$ref\": \"#/$defs/MessageState\"\n }\n },\n \"required\": [\n \"msgId\",\n \"state\"\n ],\n \"type\": \"object\"\n },\n \"type\": \"array\"\n }\n },\n \"required\": [\n \"statuses\"\n ],\n \"title\": \"Messaging — Message Status — 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] = &[];
#[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:0b6d3f4a-2c81-4e57-9d1a-5e3f7c2a8b10\",\n \"type\": \"https://trusttasks.org/spec/messaging/message/status/0.1\",\n \"issuer\": \"did:web:community.example\",\n \"recipient\": \"did:web:mediator.example\",\n \"issuedAt\": \"2026-09-26T09:30:00Z\",\n \"payload\": {\n \"msgIds\": [\n \"9f2c1e6b0d4a7c3e5f8a1b2d4c6e8f0a1b3d5c7e9f1a2b4c6d8e0f2a4b6c8d0e\",\n \"4a7c3e5f8a1b2d4c6e8f0a1b3d5c7e9f1a2b4c6d8e0f2a4b6c8d0e9f2c1e6b0d\",\n \"c6e8f0a1b3d5c7e9f1a2b4c6d8e0f2a4b6c8d0e9f2c1e6b0d4a7c3e5f8a1b2d4\"\n ]\n },\n \"proof\": {\n \"type\": \"DataIntegrityProof\",\n \"cryptosuite\": \"eddsa-jcs-2022\",\n \"verificationMethod\": \"did:web:community.example#key-1\",\n \"created\": \"2026-09-26T09:30:00Z\",\n \"proofPurpose\": \"authentication\",\n \"proofValue\": \"z4jK...\"\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:0b6d3f4a-2c81-4e57-9d1a-5e3f7c2a8b11\",\n \"type\": \"https://trusttasks.org/spec/messaging/message/status/0.1#response\",\n \"threadId\": \"urn:uuid:0b6d3f4a-2c81-4e57-9d1a-5e3f7c2a8b10\",\n \"issuer\": \"did:web:mediator.example\",\n \"recipient\": \"did:web:community.example\",\n \"issuedAt\": \"2026-09-26T09:30:01Z\",\n \"payload\": {\n \"statuses\": [\n {\n \"msgId\": \"9f2c1e6b0d4a7c3e5f8a1b2d4c6e8f0a1b3d5c7e9f1a2b4c6d8e0f2a4b6c8d0e\",\n \"state\": \"collected\",\n \"at\": \"2026-09-26T09:29:02Z\"\n },\n {\n \"msgId\": \"4a7c3e5f8a1b2d4c6e8f0a1b3d5c7e9f1a2b4c6d8e0f2a4b6c8d0e9f2c1e6b0d\",\n \"state\": \"queued\"\n },\n {\n \"msgId\": \"c6e8f0a1b3d5c7e9f1a2b4c6d8e0f2a4b6c8d0e9f2c1e6b0d4a7c3e5f8a1b2d4\",\n \"state\": \"discarded\",\n \"at\": \"2026-09-26T09:15:00Z\"\n }\n ]\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");
}
/// 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)] = &[
(
"Empty msgIds — a status request naming nothing is malformed, not an empty answer; minItems: 1 catches it.",
"{\n \"msgIds\": []\n}",
),
(
"More than 100 msgIds — the per-request cap bounds the lookups one document can cause; maxItems: 100 catches it.",
"{\n \"msgIds\": [\n \"m1\",\n \"m2\",\n \"m3\",\n \"m4\",\n \"m5\",\n \"m6\",\n \"m7\",\n \"m8\",\n \"m9\",\n \"m10\",\n \"m11\",\n \"m12\",\n \"m13\",\n \"m14\",\n \"m15\",\n \"m16\",\n \"m17\",\n \"m18\",\n \"m19\",\n \"m20\",\n \"m21\",\n \"m22\",\n \"m23\",\n \"m24\",\n \"m25\",\n \"m26\",\n \"m27\",\n \"m28\",\n \"m29\",\n \"m30\",\n \"m31\",\n \"m32\",\n \"m33\",\n \"m34\",\n \"m35\",\n \"m36\",\n \"m37\",\n \"m38\",\n \"m39\",\n \"m40\",\n \"m41\",\n \"m42\",\n \"m43\",\n \"m44\",\n \"m45\",\n \"m46\",\n \"m47\",\n \"m48\",\n \"m49\",\n \"m50\",\n \"m51\",\n \"m52\",\n \"m53\",\n \"m54\",\n \"m55\",\n \"m56\",\n \"m57\",\n \"m58\",\n \"m59\",\n \"m60\",\n \"m61\",\n \"m62\",\n \"m63\",\n \"m64\",\n \"m65\",\n \"m66\",\n \"m67\",\n \"m68\",\n \"m69\",\n \"m70\",\n \"m71\",\n \"m72\",\n \"m73\",\n \"m74\",\n \"m75\",\n \"m76\",\n \"m77\",\n \"m78\",\n \"m79\",\n \"m80\",\n \"m81\",\n \"m82\",\n \"m83\",\n \"m84\",\n \"m85\",\n \"m86\",\n \"m87\",\n \"m88\",\n \"m89\",\n \"m90\",\n \"m91\",\n \"m92\",\n \"m93\",\n \"m94\",\n \"m95\",\n \"m96\",\n \"m97\",\n \"m98\",\n \"m99\",\n \"m100\",\n \"m101\"\n ]\n}",
),
(
"Duplicate msgIds — statuses are one-per-id in request order, so a duplicate adds nothing and makes the pairing ambiguous; uniqueItems catches it.",
"{\n \"msgIds\": [\n \"9f2c1e\",\n \"9f2c1e\"\n ]\n}",
),
(
"Empty-string msgId — minLength: 1 on each item; an empty handle can never name a stored message.",
"{\n \"msgIds\": [\n \"\"\n ]\n}",
),
(
"A `did` naming another account — this task answers only for the requester's own sent messages, so there is no `did` member; additionalProperties: false catches it.",
"{\n \"did\": \"did:web:alice.example\",\n \"msgIds\": [\n \"9f2c1e\"\n ]\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
);
}
}
}