//! Generated by `trust-tasks-codegen` — do not edit by hand.
//!
//! Spec slug: `messaging/message/delete`. 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/messaging/message/delete/0.1",
/// "title": "Payload",
/// "type": "object",
/// "required": [
/// "msgIds"
/// ],
/// "properties": {
/// "did": {
/// "description": "The account whose queue holds the messages. Omitted = the requester's own account. A requester without administrative standing may name only itself.",
/// "$ref": "#/definitions/Vid"
/// },
/// "ext": {
/// "description": "Ecosystem-defined extension members per SPEC.md §4.5.1.",
/// "$ref": "#/definitions/Ext"
/// },
/// "msgIds": {
/// "type": "array",
/// "items": {
/// "type": "string",
/// "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 {
///The account whose queue holds the messages. Omitted = the requester's own account. A requester without administrative standing may name only itself.
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub did: ::std::option::Option<Vid>,
///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>,
#[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",
/// "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() < 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/delete request. Carried in a Trust Task document whose type is https://trusttasks.org/spec/messaging/message/delete/0.1#response.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "Response",
/// "description": "The success response to a messaging/message/delete request. Carried in a Trust Task document whose type is https://trusttasks.org/spec/messaging/message/delete/0.1#response.",
/// "type": "object",
/// "required": [
/// "results"
/// ],
/// "properties": {
/// "ext": {
/// "description": "Ecosystem-defined extension members per SPEC.md §4.5.1.",
/// "$ref": "#/definitions/Ext"
/// },
/// "results": {
/// "description": "One entry per requested msgId, in request order.",
/// "type": "array",
/// "items": {
/// "type": "object",
/// "required": [
/// "deleted",
/// "msgId"
/// ],
/// "properties": {
/// "deleted": {
/// "type": "boolean"
/// },
/// "msgId": {
/// "type": "string",
/// "minLength": 1
/// },
/// "reason": {
/// "description": "Why it was not deleted. `notFound`: no such message. `notInAccount`: the message exists but is not in the named account's queues.",
/// "type": "string",
/// "enum": [
/// "notFound",
/// "notInAccount"
/// ]
/// }
/// },
/// "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 results: ::std::vec::Vec<ResponseResultsItem>,
}
impl Response {
pub fn builder() -> builder::Response {
Default::default()
}
}
///`ResponseResultsItem`
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "type": "object",
/// "required": [
/// "deleted",
/// "msgId"
/// ],
/// "properties": {
/// "deleted": {
/// "type": "boolean"
/// },
/// "msgId": {
/// "type": "string",
/// "minLength": 1
/// },
/// "reason": {
/// "description": "Why it was not deleted. `notFound`: no such message. `notInAccount`: the message exists but is not in the named account's queues.",
/// "type": "string",
/// "enum": [
/// "notFound",
/// "notInAccount"
/// ]
/// }
/// },
/// "additionalProperties": false
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct ResponseResultsItem {
pub deleted: bool,
#[serde(rename = "msgId")]
pub msg_id: ResponseResultsItemMsgId,
///Why it was not deleted. `notFound`: no such message. `notInAccount`: the message exists but is not in the named account's queues.
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub reason: ::std::option::Option<ResponseResultsItemReason>,
}
impl ResponseResultsItem {
pub fn builder() -> builder::ResponseResultsItem {
Default::default()
}
}
///`ResponseResultsItemMsgId`
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "type": "string",
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct ResponseResultsItemMsgId(::std::string::String);
impl ::std::ops::Deref for ResponseResultsItemMsgId {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<ResponseResultsItemMsgId> for ::std::string::String {
fn from(value: ResponseResultsItemMsgId) -> Self {
value.0
}
}
impl ::std::str::FromStr for ResponseResultsItemMsgId {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() < 1usize {
return Err("shorter than 1 characters".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for ResponseResultsItemMsgId {
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 ResponseResultsItemMsgId {
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 ResponseResultsItemMsgId {
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 ResponseResultsItemMsgId {
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())
})
}
}
///Why it was not deleted. `notFound`: no such message. `notInAccount`: the message exists but is not in the named account's queues.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "Why it was not deleted. `notFound`: no such message. `notInAccount`: the message exists but is not in the named account's queues.",
/// "type": "string",
/// "enum": [
/// "notFound",
/// "notInAccount"
/// ]
///}
/// ```
/// </details>
#[derive(
::serde::Deserialize,
::serde::Serialize,
Clone,
Copy,
Debug,
Eq,
Hash,
Ord,
PartialEq,
PartialOrd,
)]
#[non_exhaustive]
pub enum ResponseResultsItemReason {
#[serde(rename = "notFound")]
NotFound,
#[serde(rename = "notInAccount")]
NotInAccount,
}
impl ::std::fmt::Display for ResponseResultsItemReason {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
match *self {
Self::NotFound => f.write_str("notFound"),
Self::NotInAccount => f.write_str("notInAccount"),
}
}
}
impl ::std::str::FromStr for ResponseResultsItemReason {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
match value {
"notFound" => Ok(Self::NotFound),
"notInAccount" => Ok(Self::NotInAccount),
_ => Err("invalid value".into()),
}
}
}
impl ::std::convert::TryFrom<&str> for ResponseResultsItemReason {
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 ResponseResultsItemReason {
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 ResponseResultsItemReason {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
///A Verifiable Identifier (SPEC §4.8). For a mediator-served account this is the account's controlling DID, carried verbatim and compared by exact string equality. For privacy — and because some mediators key accounts by a one-way hash and never hold the full DID — a stable hash of the DID (e.g. its SHA-256 digest) is an equally valid value here: producer and consumer simply agree on the same opaque identifier and compare by exact string equality. The field carries whichever form the issuing mediator uses.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "Vid",
/// "description": "A Verifiable Identifier (SPEC §4.8). For a mediator-served account this is the account's controlling DID, carried verbatim and compared by exact string equality. For privacy — and because some mediators key accounts by a one-way hash and never hold the full DID — a stable hash of the DID (e.g. its SHA-256 digest) is an equally valid value here: producer and consumer simply agree on the same opaque identifier and compare by exact string equality. The field carries whichever form the issuing mediator uses.",
/// "type": "string",
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct Vid(::std::string::String);
impl ::std::ops::Deref for Vid {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<Vid> for ::std::string::String {
fn from(value: Vid) -> Self {
value.0
}
}
impl ::std::str::FromStr for Vid {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() < 1usize {
return Err("shorter than 1 characters".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for Vid {
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 Vid {
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 Vid {
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 Vid {
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 {
did: ::std::result::Result<::std::option::Option<super::Vid>, ::std::string::String>,
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 {
did: Ok(Default::default()),
ext: Ok(Default::default()),
msg_ids: Err("no value supplied for msg_ids".to_string()),
}
}
}
impl Payload {
pub fn did<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::Vid>>,
T::Error: ::std::fmt::Display,
{
self.did = value
.try_into()
.map_err(|e| format!("error converting supplied value for did: {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 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 {
did: value.did?,
ext: value.ext?,
msg_ids: value.msg_ids?,
})
}
}
impl ::std::convert::From<super::Payload> for Payload {
fn from(value: super::Payload) -> Self {
Self {
did: Ok(value.did),
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>,
results: ::std::result::Result<
::std::vec::Vec<super::ResponseResultsItem>,
::std::string::String,
>,
}
impl ::std::default::Default for Response {
fn default() -> Self {
Self {
ext: Ok(Default::default()),
results: Err("no value supplied for results".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 results<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::vec::Vec<super::ResponseResultsItem>>,
T::Error: ::std::fmt::Display,
{
self.results = value
.try_into()
.map_err(|e| format!("error converting supplied value for results: {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?,
results: value.results?,
})
}
}
impl ::std::convert::From<super::Response> for Response {
fn from(value: super::Response) -> Self {
Self {
ext: Ok(value.ext),
results: Ok(value.results),
}
}
}
#[derive(Clone, Debug)]
pub struct ResponseResultsItem {
deleted: ::std::result::Result<bool, ::std::string::String>,
msg_id: ::std::result::Result<super::ResponseResultsItemMsgId, ::std::string::String>,
reason: ::std::result::Result<
::std::option::Option<super::ResponseResultsItemReason>,
::std::string::String,
>,
}
impl ::std::default::Default for ResponseResultsItem {
fn default() -> Self {
Self {
deleted: Err("no value supplied for deleted".to_string()),
msg_id: Err("no value supplied for msg_id".to_string()),
reason: Ok(Default::default()),
}
}
}
impl ResponseResultsItem {
pub fn deleted<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<bool>,
T::Error: ::std::fmt::Display,
{
self.deleted = value
.try_into()
.map_err(|e| format!("error converting supplied value for deleted: {e}"));
self
}
pub fn msg_id<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::ResponseResultsItemMsgId>,
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 reason<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::ResponseResultsItemReason>>,
T::Error: ::std::fmt::Display,
{
self.reason = value
.try_into()
.map_err(|e| format!("error converting supplied value for reason: {e}"));
self
}
}
impl ::std::convert::TryFrom<ResponseResultsItem> for super::ResponseResultsItem {
type Error = super::error::ConversionError;
fn try_from(
value: ResponseResultsItem,
) -> ::std::result::Result<Self, super::error::ConversionError> {
Ok(Self {
deleted: value.deleted?,
msg_id: value.msg_id?,
reason: value.reason?,
})
}
}
impl ::std::convert::From<super::ResponseResultsItem> for ResponseResultsItem {
fn from(value: super::ResponseResultsItem) -> Self {
Self {
deleted: Ok(value.deleted),
msg_id: Ok(value.msg_id),
reason: Ok(value.reason),
}
}
}
}
impl crate::Payload for Payload {
const TYPE_URI: &'static str = "https://trusttasks.org/spec/messaging/message/delete/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 \"Response\": {\n \"$anchor\": \"response\",\n \"additionalProperties\": false,\n \"description\": \"The success response to a messaging/message/delete request. Carried in a Trust Task document whose type is https://trusttasks.org/spec/messaging/message/delete/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 \"results\": {\n \"description\": \"One entry per requested msgId, in request order.\",\n \"items\": {\n \"additionalProperties\": false,\n \"properties\": {\n \"deleted\": {\n \"type\": \"boolean\"\n },\n \"msgId\": {\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"reason\": {\n \"description\": \"Why it was not deleted. `notFound`: no such message. `notInAccount`: the message exists but is not in the named account's queues.\",\n \"enum\": [\n \"notFound\",\n \"notInAccount\"\n ],\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"msgId\",\n \"deleted\"\n ],\n \"type\": \"object\"\n },\n \"type\": \"array\"\n }\n },\n \"required\": [\n \"results\"\n ],\n \"title\": \"Messaging — Delete Messages — response payload\",\n \"type\": \"object\"\n },\n \"Vid\": {\n \"description\": \"A Verifiable Identifier (SPEC §4.8). For a mediator-served account this is the account's controlling DID, carried verbatim and compared by exact string equality. For privacy — and because some mediators key accounts by a one-way hash and never hold the full DID — a stable hash of the DID (e.g. its SHA-256 digest) is an equally valid value here: producer and consumer simply agree on the same opaque identifier and compare by exact string equality. The field carries whichever form the issuing mediator uses.\",\n \"minLength\": 1,\n \"title\": \"Vid\",\n \"type\": \"string\"\n }\n },\n \"$id\": \"https://trusttasks.org/spec/messaging/message/delete/0.1\",\n \"$schema\": \"https://json-schema.org/draft/2020-12/schema\",\n \"additionalProperties\": false,\n \"properties\": {\n \"did\": {\n \"$ref\": \"#/$defs/Vid\",\n \"description\": \"The account whose queue holds the messages. Omitted = the requester's own account. A requester without administrative standing may name only itself.\"\n },\n \"ext\": {\n \"$ref\": \"#/$defs/Ext\",\n \"description\": \"Ecosystem-defined extension members per SPEC.md §4.5.1.\"\n },\n \"msgIds\": {\n \"items\": {\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 — Delete Messages — payload\",\n \"type\": \"object\"\n}\n",
);
}
impl crate::Payload for Response {
const TYPE_URI: &'static str =
"https://trusttasks.org/spec/messaging/message/delete/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 \"Response\": {\n \"$anchor\": \"response\",\n \"additionalProperties\": false,\n \"description\": \"The success response to a messaging/message/delete request. Carried in a Trust Task document whose type is https://trusttasks.org/spec/messaging/message/delete/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 \"results\": {\n \"description\": \"One entry per requested msgId, in request order.\",\n \"items\": {\n \"additionalProperties\": false,\n \"properties\": {\n \"deleted\": {\n \"type\": \"boolean\"\n },\n \"msgId\": {\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"reason\": {\n \"description\": \"Why it was not deleted. `notFound`: no such message. `notInAccount`: the message exists but is not in the named account's queues.\",\n \"enum\": [\n \"notFound\",\n \"notInAccount\"\n ],\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"msgId\",\n \"deleted\"\n ],\n \"type\": \"object\"\n },\n \"type\": \"array\"\n }\n },\n \"required\": [\n \"results\"\n ],\n \"title\": \"Messaging — Delete Messages — response payload\",\n \"type\": \"object\"\n },\n \"Vid\": {\n \"description\": \"A Verifiable Identifier (SPEC §4.8). For a mediator-served account this is the account's controlling DID, carried verbatim and compared by exact string equality. For privacy — and because some mediators key accounts by a one-way hash and never hold the full DID — a stable hash of the DID (e.g. its SHA-256 digest) is an equally valid value here: producer and consumer simply agree on the same opaque identifier and compare by exact string equality. The field carries whichever form the issuing mediator uses.\",\n \"minLength\": 1,\n \"title\": \"Vid\",\n \"type\": \"string\"\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::UNKNOWN_ACCOUNT,
error_codes::ROOT_ADMIN_REQUIRED,
];
/// 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 {
/// `messaging/message/delete:unknownAccount`
///
/// The named account (`did`) has no account at this mediator.
///
/// Declared `retryable: false`.
pub const UNKNOWN_ACCOUNT: crate::DeclaredErrorCode = crate::DeclaredErrorCode {
code: "messaging/message/delete:unknownAccount",
retryable: false,
};
/// `messaging/message/delete:rootAdminRequired`
///
/// The target account holds the admin, rootAdmin, or mediator role, and the requester is not a rootAdmin.
///
/// Declared `retryable: false`.
pub const ROOT_ADMIN_REQUIRED: crate::DeclaredErrorCode = crate::DeclaredErrorCode {
code: "messaging/message/delete:rootAdminRequired",
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:2b8e4a60-51c7-4a9e-8f0d-6b3c1d2e4f01\",\n \"type\": \"https://trusttasks.org/spec/messaging/message/delete/0.1\",\n \"issuer\": \"did:web:admin.example\",\n \"recipient\": \"did:web:mediator.example\",\n \"issuedAt\": \"2026-09-21T10:05:00Z\",\n \"payload\": {\n \"did\": \"did:web:alice.example\",\n \"msgIds\": [\"1726912345000-0\", \"1726912399000-0\"]\n },\n \"proof\": {\n \"type\": \"DataIntegrityProof\",\n \"cryptosuite\": \"eddsa-jcs-2022\",\n \"verificationMethod\": \"did:web:admin.example#key-1\",\n \"created\": \"2026-09-21T10:05:00Z\",\n \"proofPurpose\": \"assertionMethod\",\n \"proofValue\": \"z4hq...\"\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:2b8e4a60-51c7-4a9e-8f0d-6b3c1d2e4f02\",\n \"type\": \"https://trusttasks.org/spec/messaging/message/delete/0.1#response\",\n \"threadId\": \"urn:uuid:2b8e4a60-51c7-4a9e-8f0d-6b3c1d2e4f01\",\n \"issuer\": \"did:web:mediator.example\",\n \"recipient\": \"did:web:admin.example\",\n \"issuedAt\": \"2026-09-21T10:05:01Z\",\n \"payload\": {\n \"results\": [\n { \"msgId\": \"1726912345000-0\", \"deleted\": true },\n { \"msgId\": \"1726912399000-0\", \"deleted\": false, \"reason\": \"notFound\" }\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 delete naming nothing is a malformed request, not a successful no-op; minItems: 1 catches it.",
"{\n \"msgIds\": []\n}",
),
(
"More than 100 msgIds — the per-request cap bounds the work and the audit entry 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 — results are one-per-id in request order, so a duplicate would make the second result ambiguous (deleted by this request, or notFound because the first entry removed it); uniqueItems catches it.",
"{\n \"msgIds\": [\n \"1726912345000-0\",\n \"1726912345000-0\"\n ]\n}",
),
(
"Empty-string msgId — minLength: 1 on each item; an empty handle can never name a stored message.",
"{\n \"msgIds\": [\n \"\"\n ]\n}",
),
(
"Unknown top-level member — additionalProperties: false catches `queue`, which a caller might add expecting to scope the delete; msgIds already identify the messages across both queues.",
"{\n \"msgIds\": [\n \"1726912345000-0\"\n ],\n \"queue\": \"receive\"\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
);
}
}
}