//! Generated by `trust-tasks-codegen` — do not edit by hand.
//!
//! Spec slug: `messaging/queue/purge`. 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/queue/purge/0.1",
/// "title": "Payload",
/// "type": "object",
/// "required": [
/// "queue"
/// ],
/// "properties": {
/// "did": {
/// "description": "The account whose queue to purge. Omitted = the requester's own account. A requester without administrative standing may name only itself.",
/// "$ref": "#/definitions/Vid"
/// },
/// "dryRun": {
/// "description": "Report what would be purged and purge nothing. Default false.",
/// "type": "boolean"
/// },
/// "ext": {
/// "description": "Ecosystem-defined extension members per SPEC.md §4.5.1.",
/// "$ref": "#/definitions/Ext"
/// },
/// "olderThanSeconds": {
/// "description": "Only messages queued at least this long.",
/// "type": "integer",
/// "minimum": 0.0
/// },
/// "peer": {
/// "description": "Only messages exchanged with this counterparty: in a send queue, the recipient; in a receive queue, the sender.",
/// "$ref": "#/definitions/Vid"
/// },
/// "queue": {
/// "$ref": "#/definitions/Queue"
/// }
/// },
/// "additionalProperties": false
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct Payload {
///The account whose queue to purge. 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>,
///Report what would be purged and purge nothing. Default false.
#[serde(
rename = "dryRun",
default,
skip_serializing_if = "::std::option::Option::is_none"
)]
pub dry_run: ::std::option::Option<bool>,
///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>,
///Only messages queued at least this long.
#[serde(
rename = "olderThanSeconds",
default,
skip_serializing_if = "::std::option::Option::is_none"
)]
pub older_than_seconds: ::std::option::Option<u64>,
///Only messages exchanged with this counterparty: in a send queue, the recipient; in a receive queue, the sender.
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub peer: ::std::option::Option<Vid>,
pub queue: Queue,
}
impl Payload {
pub fn builder() -> builder::Payload {
Default::default()
}
}
///Which of an account's two queues. `receive` holds messages addressed to the account awaiting its pickup. `send` holds messages the account sent that are still held against it until their recipient deletes them — so a stalled recipient fills its senders' send queues.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "Queue",
/// "description": "Which of an account's two queues. `receive` holds messages addressed to the account awaiting its pickup. `send` holds messages the account sent that are still held against it until their recipient deletes them — so a stalled recipient fills its senders' send queues.",
/// "type": "string",
/// "enum": [
/// "receive",
/// "send"
/// ]
///}
/// ```
/// </details>
#[derive(
::serde::Deserialize,
::serde::Serialize,
Clone,
Copy,
Debug,
Eq,
Hash,
Ord,
PartialEq,
PartialOrd,
)]
#[non_exhaustive]
pub enum Queue {
#[serde(rename = "receive")]
Receive,
#[serde(rename = "send")]
Send,
}
impl ::std::fmt::Display for Queue {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
match *self {
Self::Receive => f.write_str("receive"),
Self::Send => f.write_str("send"),
}
}
}
impl ::std::str::FromStr for Queue {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
match value {
"receive" => Ok(Self::Receive),
"send" => Ok(Self::Send),
_ => Err("invalid value".into()),
}
}
}
impl ::std::convert::TryFrom<&str> for Queue {
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 Queue {
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 Queue {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
///The success response to a messaging/queue/purge request. Carried in a Trust Task document whose type is https://trusttasks.org/spec/messaging/queue/purge/0.1#response.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "Response",
/// "description": "The success response to a messaging/queue/purge request. Carried in a Trust Task document whose type is https://trusttasks.org/spec/messaging/queue/purge/0.1#response.",
/// "type": "object",
/// "required": [
/// "dryRun",
/// "matched",
/// "purged"
/// ],
/// "properties": {
/// "dryRun": {
/// "type": "boolean"
/// },
/// "ext": {
/// "description": "Ecosystem-defined extension members per SPEC.md §4.5.1.",
/// "$ref": "#/definitions/Ext"
/// },
/// "matched": {
/// "description": "Messages that matched the selection.",
/// "type": "integer",
/// "minimum": 0.0
/// },
/// "matchedBytes": {
/// "type": "integer",
/// "minimum": 0.0
/// },
/// "purged": {
/// "description": "Messages actually removed. 0 on a dry run.",
/// "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(rename = "dryRun")]
pub dry_run: bool,
///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>,
///Messages that matched the selection.
pub matched: u64,
#[serde(
rename = "matchedBytes",
default,
skip_serializing_if = "::std::option::Option::is_none"
)]
pub matched_bytes: ::std::option::Option<u64>,
///Messages actually removed. 0 on a dry run.
pub purged: u64,
}
impl Response {
pub fn builder() -> builder::Response {
Default::default()
}
}
///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>,
dry_run: ::std::result::Result<::std::option::Option<bool>, ::std::string::String>,
ext: ::std::result::Result<::std::option::Option<super::Ext>, ::std::string::String>,
older_than_seconds:
::std::result::Result<::std::option::Option<u64>, ::std::string::String>,
peer: ::std::result::Result<::std::option::Option<super::Vid>, ::std::string::String>,
queue: ::std::result::Result<super::Queue, ::std::string::String>,
}
impl ::std::default::Default for Payload {
fn default() -> Self {
Self {
did: Ok(Default::default()),
dry_run: Ok(Default::default()),
ext: Ok(Default::default()),
older_than_seconds: Ok(Default::default()),
peer: Ok(Default::default()),
queue: Err("no value supplied for queue".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 dry_run<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<bool>>,
T::Error: ::std::fmt::Display,
{
self.dry_run = value
.try_into()
.map_err(|e| format!("error converting supplied value for dry_run: {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 older_than_seconds<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<u64>>,
T::Error: ::std::fmt::Display,
{
self.older_than_seconds = value.try_into().map_err(|e| {
format!("error converting supplied value for older_than_seconds: {e}")
});
self
}
pub fn peer<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::Vid>>,
T::Error: ::std::fmt::Display,
{
self.peer = value
.try_into()
.map_err(|e| format!("error converting supplied value for peer: {e}"));
self
}
pub fn queue<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::Queue>,
T::Error: ::std::fmt::Display,
{
self.queue = value
.try_into()
.map_err(|e| format!("error converting supplied value for queue: {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?,
dry_run: value.dry_run?,
ext: value.ext?,
older_than_seconds: value.older_than_seconds?,
peer: value.peer?,
queue: value.queue?,
})
}
}
impl ::std::convert::From<super::Payload> for Payload {
fn from(value: super::Payload) -> Self {
Self {
did: Ok(value.did),
dry_run: Ok(value.dry_run),
ext: Ok(value.ext),
older_than_seconds: Ok(value.older_than_seconds),
peer: Ok(value.peer),
queue: Ok(value.queue),
}
}
}
#[derive(Clone, Debug)]
pub struct Response {
dry_run: ::std::result::Result<bool, ::std::string::String>,
ext: ::std::result::Result<::std::option::Option<super::Ext>, ::std::string::String>,
matched: ::std::result::Result<u64, ::std::string::String>,
matched_bytes: ::std::result::Result<::std::option::Option<u64>, ::std::string::String>,
purged: ::std::result::Result<u64, ::std::string::String>,
}
impl ::std::default::Default for Response {
fn default() -> Self {
Self {
dry_run: Err("no value supplied for dry_run".to_string()),
ext: Ok(Default::default()),
matched: Err("no value supplied for matched".to_string()),
matched_bytes: Ok(Default::default()),
purged: Err("no value supplied for purged".to_string()),
}
}
}
impl Response {
pub fn dry_run<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<bool>,
T::Error: ::std::fmt::Display,
{
self.dry_run = value
.try_into()
.map_err(|e| format!("error converting supplied value for dry_run: {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 matched<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<u64>,
T::Error: ::std::fmt::Display,
{
self.matched = value
.try_into()
.map_err(|e| format!("error converting supplied value for matched: {e}"));
self
}
pub fn matched_bytes<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<u64>>,
T::Error: ::std::fmt::Display,
{
self.matched_bytes = value
.try_into()
.map_err(|e| format!("error converting supplied value for matched_bytes: {e}"));
self
}
pub fn purged<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<u64>,
T::Error: ::std::fmt::Display,
{
self.purged = value
.try_into()
.map_err(|e| format!("error converting supplied value for purged: {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 {
dry_run: value.dry_run?,
ext: value.ext?,
matched: value.matched?,
matched_bytes: value.matched_bytes?,
purged: value.purged?,
})
}
}
impl ::std::convert::From<super::Response> for Response {
fn from(value: super::Response) -> Self {
Self {
dry_run: Ok(value.dry_run),
ext: Ok(value.ext),
matched: Ok(value.matched),
matched_bytes: Ok(value.matched_bytes),
purged: Ok(value.purged),
}
}
}
}
impl crate::Payload for Payload {
const TYPE_URI: &'static str = "https://trusttasks.org/spec/messaging/queue/purge/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 \"Queue\": {\n \"description\": \"Which of an account's two queues. `receive` holds messages addressed to the account awaiting its pickup. `send` holds messages the account sent that are still held against it until their recipient deletes them — so a stalled recipient fills its senders' send queues.\",\n \"enum\": [\n \"receive\",\n \"send\"\n ],\n \"title\": \"Queue\",\n \"type\": \"string\"\n },\n \"Response\": {\n \"$anchor\": \"response\",\n \"additionalProperties\": false,\n \"description\": \"The success response to a messaging/queue/purge request. Carried in a Trust Task document whose type is https://trusttasks.org/spec/messaging/queue/purge/0.1#response.\",\n \"properties\": {\n \"dryRun\": {\n \"type\": \"boolean\"\n },\n \"ext\": {\n \"$ref\": \"#/$defs/Ext\",\n \"description\": \"Ecosystem-defined extension members per SPEC.md §4.5.1.\"\n },\n \"matched\": {\n \"description\": \"Messages that matched the selection.\",\n \"minimum\": 0,\n \"type\": \"integer\"\n },\n \"matchedBytes\": {\n \"minimum\": 0,\n \"type\": \"integer\"\n },\n \"purged\": {\n \"description\": \"Messages actually removed. 0 on a dry run.\",\n \"minimum\": 0,\n \"type\": \"integer\"\n }\n },\n \"required\": [\n \"matched\",\n \"purged\",\n \"dryRun\"\n ],\n \"title\": \"Messaging — Purge Queue — 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/queue/purge/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 to purge. Omitted = the requester's own account. A requester without administrative standing may name only itself.\"\n },\n \"dryRun\": {\n \"description\": \"Report what would be purged and purge nothing. Default false.\",\n \"type\": \"boolean\"\n },\n \"ext\": {\n \"$ref\": \"#/$defs/Ext\",\n \"description\": \"Ecosystem-defined extension members per SPEC.md §4.5.1.\"\n },\n \"olderThanSeconds\": {\n \"description\": \"Only messages queued at least this long.\",\n \"minimum\": 0,\n \"type\": \"integer\"\n },\n \"peer\": {\n \"$ref\": \"#/$defs/Vid\",\n \"description\": \"Only messages exchanged with this counterparty: in a send queue, the recipient; in a receive queue, the sender.\"\n },\n \"queue\": {\n \"$ref\": \"#/$defs/Queue\"\n }\n },\n \"required\": [\n \"queue\"\n ],\n \"title\": \"Messaging — Purge Queue — payload\",\n \"type\": \"object\"\n}\n",
);
}
impl crate::Payload for Response {
const TYPE_URI: &'static str = "https://trusttasks.org/spec/messaging/queue/purge/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 \"Queue\": {\n \"description\": \"Which of an account's two queues. `receive` holds messages addressed to the account awaiting its pickup. `send` holds messages the account sent that are still held against it until their recipient deletes them — so a stalled recipient fills its senders' send queues.\",\n \"enum\": [\n \"receive\",\n \"send\"\n ],\n \"title\": \"Queue\",\n \"type\": \"string\"\n },\n \"Response\": {\n \"$anchor\": \"response\",\n \"additionalProperties\": false,\n \"description\": \"The success response to a messaging/queue/purge request. Carried in a Trust Task document whose type is https://trusttasks.org/spec/messaging/queue/purge/0.1#response.\",\n \"properties\": {\n \"dryRun\": {\n \"type\": \"boolean\"\n },\n \"ext\": {\n \"$ref\": \"#/$defs/Ext\",\n \"description\": \"Ecosystem-defined extension members per SPEC.md §4.5.1.\"\n },\n \"matched\": {\n \"description\": \"Messages that matched the selection.\",\n \"minimum\": 0,\n \"type\": \"integer\"\n },\n \"matchedBytes\": {\n \"minimum\": 0,\n \"type\": \"integer\"\n },\n \"purged\": {\n \"description\": \"Messages actually removed. 0 on a dry run.\",\n \"minimum\": 0,\n \"type\": \"integer\"\n }\n },\n \"required\": [\n \"matched\",\n \"purged\",\n \"dryRun\"\n ],\n \"title\": \"Messaging — Purge Queue — 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/queue/purge:unknownAccount`
///
/// The named account does not exist at this mediator.
///
/// Declared `retryable: false`.
pub const UNKNOWN_ACCOUNT: crate::DeclaredErrorCode = crate::DeclaredErrorCode {
code: "messaging/queue/purge:unknownAccount",
retryable: false,
};
/// `messaging/queue/purge:rootAdminRequired`
///
/// The target account holds the admin, rootAdmin, or mediator role, and purging a privileged account's queue requires the requester to be a rootAdmin.
///
/// Declared `retryable: false`.
pub const ROOT_ADMIN_REQUIRED: crate::DeclaredErrorCode = crate::DeclaredErrorCode {
code: "messaging/queue/purge: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:c1e8a3f4-5b7d-4c29-9e0a-6f2b8d1c4e01\",\n \"type\": \"https://trusttasks.org/spec/messaging/queue/purge/0.1\",\n \"issuer\": \"did:web:admin.example\",\n \"recipient\": \"did:web:mediator.example\",\n \"issuedAt\": \"2026-09-21T10:10:00Z\",\n \"payload\": {\n \"did\": \"did:web:alice.example\",\n \"queue\": \"send\",\n \"peer\": \"did:web:carol.example\",\n \"olderThanSeconds\": 3600,\n \"dryRun\": true\n },\n \"proof\": {\n \"type\": \"DataIntegrityProof\",\n \"cryptosuite\": \"eddsa-jcs-2022\",\n \"verificationMethod\": \"did:web:admin.example#key-1\",\n \"created\": \"2026-09-21T10:10:00Z\",\n \"proofPurpose\": \"assertionMethod\",\n \"proofValue\": \"z3Wq...\"\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:c1e8a3f4-5b7d-4c29-9e0a-6f2b8d1c4e02\",\n \"type\": \"https://trusttasks.org/spec/messaging/queue/purge/0.1#response\",\n \"threadId\": \"urn:uuid:c1e8a3f4-5b7d-4c29-9e0a-6f2b8d1c4e01\",\n \"issuer\": \"did:web:mediator.example\",\n \"recipient\": \"did:web:admin.example\",\n \"issuedAt\": \"2026-09-21T10:10:00Z\",\n \"payload\": {\n \"matched\": 912,\n \"matchedBytes\": 1771204,\n \"purged\": 0,\n \"dryRun\": true\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)] = &[
(
"Missing `queue` — there is no implicit 'both queues' purge; the requester must name exactly one.",
"{\n \"did\": \"did:web:alice.example\",\n \"dryRun\": true\n}",
),
(
"Unknown top-level member — additionalProperties: false must reject `all` rather than silently ignore a widening the producer thought it asked for.",
"{\n \"all\": true,\n \"queue\": \"send\"\n}",
),
(
"Negative `olderThanSeconds` — an age filter cannot select messages from the future.",
"{\n \"olderThanSeconds\": -60,\n \"queue\": \"receive\"\n}",
),
(
"`queue` outside the Queue enum — `inbox` is a store-internal name, not the wire vocabulary.",
"{\n \"queue\": \"inbox\"\n}",
),
(
"`dryRun` as a string — a truthy string must not be read as a boolean, or a preview could become a real purge.",
"{\n \"dryRun\": \"false\",\n \"queue\": \"send\"\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
);
}
}
}