//! Generated by `trust-tasks-codegen` — do not edit by hand.
//!
//! Spec slug: `messaging/monitor/subscribe`. 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())
})
}
}
///Selects which events a monitor subscription receives. Every member present narrows the selection (members are ANDed; values within one member are ORed). An empty filter selects everything the requester is entitled to see.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "MonitorFilter",
/// "description": "Selects which events a monitor subscription receives. Every member present narrows the selection (members are ANDed; values within one member are ORed). An empty filter selects everything the requester is entitled to see.",
/// "type": "object",
/// "properties": {
/// "channels": {
/// "type": "array",
/// "items": {
/// "$ref": "#/definitions/TrafficChannel"
/// },
/// "minItems": 1,
/// "uniqueItems": true
/// },
/// "dids": {
/// "description": "Only events whose `from` or `to` is one of these accounts.",
/// "type": "array",
/// "items": {
/// "$ref": "#/definitions/Vid"
/// },
/// "maxItems": 100,
/// "minItems": 1,
/// "uniqueItems": true
/// },
/// "directions": {
/// "type": "array",
/// "items": {
/// "$ref": "#/definitions/TrafficDirection"
/// },
/// "minItems": 1,
/// "uniqueItems": true
/// },
/// "failuresOnly": {
/// "description": "Only events that carry an `outcome`.",
/// "type": "boolean"
/// },
/// "messageTypePrefixes": {
/// "description": "Only events whose `messageType` starts with one of these strings. Events with no `messageType` never match when this member is present.",
/// "type": "array",
/// "items": {
/// "type": "string",
/// "maxLength": 512,
/// "minLength": 1
/// },
/// "maxItems": 20,
/// "minItems": 1,
/// "uniqueItems": true
/// },
/// "protocols": {
/// "type": "array",
/// "items": {
/// "$ref": "#/definitions/WireProtocol"
/// },
/// "minItems": 1,
/// "uniqueItems": true
/// },
/// "stages": {
/// "type": "array",
/// "items": {
/// "$ref": "#/definitions/TrafficStage"
/// },
/// "minItems": 1,
/// "uniqueItems": true
/// }
/// },
/// "additionalProperties": false
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct MonitorFilter {
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub channels: ::std::option::Option<Vec<TrafficChannel>>,
///Only events whose `from` or `to` is one of these accounts.
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub dids: ::std::option::Option<Vec<Vid>>,
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub directions: ::std::option::Option<Vec<TrafficDirection>>,
///Only events that carry an `outcome`.
#[serde(
rename = "failuresOnly",
default,
skip_serializing_if = "::std::option::Option::is_none"
)]
pub failures_only: ::std::option::Option<bool>,
///Only events whose `messageType` starts with one of these strings. Events with no `messageType` never match when this member is present.
#[serde(
rename = "messageTypePrefixes",
default,
skip_serializing_if = "::std::option::Option::is_none"
)]
pub message_type_prefixes: ::std::option::Option<Vec<MonitorFilterMessageTypePrefixesItem>>,
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub protocols: ::std::option::Option<Vec<WireProtocol>>,
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub stages: ::std::option::Option<Vec<TrafficStage>>,
}
impl ::std::default::Default for MonitorFilter {
fn default() -> Self {
Self {
channels: Default::default(),
dids: Default::default(),
directions: Default::default(),
failures_only: Default::default(),
message_type_prefixes: Default::default(),
protocols: Default::default(),
stages: Default::default(),
}
}
}
impl MonitorFilter {
pub fn builder() -> builder::MonitorFilter {
Default::default()
}
}
///`MonitorFilterMessageTypePrefixesItem`
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "type": "string",
/// "maxLength": 512,
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct MonitorFilterMessageTypePrefixesItem(::std::string::String);
impl ::std::ops::Deref for MonitorFilterMessageTypePrefixesItem {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<MonitorFilterMessageTypePrefixesItem> for ::std::string::String {
fn from(value: MonitorFilterMessageTypePrefixesItem) -> Self {
value.0
}
}
impl ::std::str::FromStr for MonitorFilterMessageTypePrefixesItem {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() > 512usize {
return Err("longer than 512 characters".into());
}
if value.chars().count() < 1usize {
return Err("shorter than 1 characters".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for MonitorFilterMessageTypePrefixesItem {
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 MonitorFilterMessageTypePrefixesItem {
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 MonitorFilterMessageTypePrefixesItem {
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 MonitorFilterMessageTypePrefixesItem {
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/monitor/subscribe/0.1",
/// "title": "Payload",
/// "type": "object",
/// "properties": {
/// "ext": {
/// "description": "Ecosystem-defined extension members per SPEC.md §4.5.1.",
/// "$ref": "#/definitions/Ext"
/// },
/// "filter": {
/// "$ref": "#/definitions/MonitorFilter"
/// },
/// "leaseSeconds": {
/// "description": "How long the subscription lives unless renewed. Default 300.",
/// "type": "integer",
/// "maximum": 3600.0,
/// "minimum": 10.0
/// },
/// "maxEventsPerSecond": {
/// "description": "Rate ceiling the subscriber can absorb; the mediator MAY apply a lower one. Events over the ceiling are counted as dropped, never queued.",
/// "type": "integer",
/// "maximum": 1000.0,
/// "minimum": 1.0
/// },
/// "subscriptionId": {
/// "description": "Renew or re-filter an existing subscription held by the same requester. Omitted = create a new one.",
/// "type": "string",
/// "minLength": 1
/// }
/// },
/// "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>,
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub filter: ::std::option::Option<MonitorFilter>,
///How long the subscription lives unless renewed. Default 300.
#[serde(
rename = "leaseSeconds",
default,
skip_serializing_if = "::std::option::Option::is_none"
)]
pub lease_seconds: ::std::option::Option<i64>,
///Rate ceiling the subscriber can absorb; the mediator MAY apply a lower one. Events over the ceiling are counted as dropped, never queued.
#[serde(
rename = "maxEventsPerSecond",
default,
skip_serializing_if = "::std::option::Option::is_none"
)]
pub max_events_per_second: ::std::option::Option<::std::num::NonZeroU64>,
///Renew or re-filter an existing subscription held by the same requester. Omitted = create a new one.
#[serde(
rename = "subscriptionId",
default,
skip_serializing_if = "::std::option::Option::is_none"
)]
pub subscription_id: ::std::option::Option<PayloadSubscriptionId>,
}
impl ::std::default::Default for Payload {
fn default() -> Self {
Self {
ext: Default::default(),
filter: Default::default(),
lease_seconds: Default::default(),
max_events_per_second: Default::default(),
subscription_id: Default::default(),
}
}
}
impl Payload {
pub fn builder() -> builder::Payload {
Default::default()
}
}
///Renew or re-filter an existing subscription held by the same requester. Omitted = create a new one.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "Renew or re-filter an existing subscription held by the same requester. Omitted = create a new one.",
/// "type": "string",
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct PayloadSubscriptionId(::std::string::String);
impl ::std::ops::Deref for PayloadSubscriptionId {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<PayloadSubscriptionId> for ::std::string::String {
fn from(value: PayloadSubscriptionId) -> Self {
value.0
}
}
impl ::std::str::FromStr for PayloadSubscriptionId {
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 PayloadSubscriptionId {
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 PayloadSubscriptionId {
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 PayloadSubscriptionId {
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 PayloadSubscriptionId {
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/monitor/subscribe request. Carried in a Trust Task document whose type is https://trusttasks.org/spec/messaging/monitor/subscribe/0.1#response.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "Response",
/// "description": "The success response to a messaging/monitor/subscribe request. Carried in a Trust Task document whose type is https://trusttasks.org/spec/messaging/monitor/subscribe/0.1#response.",
/// "type": "object",
/// "required": [
/// "expiresAt",
/// "filter",
/// "maxEventsPerSecond",
/// "subscriptionId"
/// ],
/// "properties": {
/// "expiresAt": {
/// "type": "string",
/// "format": "date-time"
/// },
/// "ext": {
/// "description": "Ecosystem-defined extension members per SPEC.md §4.5.1.",
/// "$ref": "#/definitions/Ext"
/// },
/// "filter": {
/// "description": "The filter in force, after the mediator narrowed it to what the requester is entitled to see.",
/// "$ref": "#/definitions/MonitorFilter"
/// },
/// "maxEventsPerSecond": {
/// "description": "The rate ceiling in force.",
/// "type": "integer",
/// "minimum": 1.0
/// },
/// "subscriptionId": {
/// "type": "string",
/// "minLength": 1
/// }
/// },
/// "additionalProperties": false,
/// "$anchor": "response"
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct Response {
#[serde(rename = "expiresAt")]
pub expires_at: ::chrono::DateTime<::chrono::offset::Utc>,
///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 filter in force, after the mediator narrowed it to what the requester is entitled to see.
pub filter: MonitorFilter,
///The rate ceiling in force.
#[serde(rename = "maxEventsPerSecond")]
pub max_events_per_second: ::std::num::NonZeroU64,
#[serde(rename = "subscriptionId")]
pub subscription_id: ResponseSubscriptionId,
}
impl Response {
pub fn builder() -> builder::Response {
Default::default()
}
}
///`ResponseSubscriptionId`
///
/// <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 ResponseSubscriptionId(::std::string::String);
impl ::std::ops::Deref for ResponseSubscriptionId {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<ResponseSubscriptionId> for ::std::string::String {
fn from(value: ResponseSubscriptionId) -> Self {
value.0
}
}
impl ::std::str::FromStr for ResponseSubscriptionId {
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 ResponseSubscriptionId {
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 ResponseSubscriptionId {
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 ResponseSubscriptionId {
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 ResponseSubscriptionId {
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())
})
}
}
///How the traffic reached or left the mediator. `peerMediator` is mediator-to-mediator forwarding.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "TrafficChannel",
/// "description": "How the traffic reached or left the mediator. `peerMediator` is mediator-to-mediator forwarding.",
/// "type": "string",
/// "enum": [
/// "websocket",
/// "rest",
/// "peerMediator",
/// "internal"
/// ]
///}
/// ```
/// </details>
#[derive(
::serde::Deserialize,
::serde::Serialize,
Clone,
Copy,
Debug,
Eq,
Hash,
Ord,
PartialEq,
PartialOrd,
)]
#[non_exhaustive]
pub enum TrafficChannel {
#[serde(rename = "websocket")]
Websocket,
#[serde(rename = "rest")]
Rest,
#[serde(rename = "peerMediator")]
PeerMediator,
#[serde(rename = "internal")]
Internal,
}
impl ::std::fmt::Display for TrafficChannel {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
match *self {
Self::Websocket => f.write_str("websocket"),
Self::Rest => f.write_str("rest"),
Self::PeerMediator => f.write_str("peerMediator"),
Self::Internal => f.write_str("internal"),
}
}
}
impl ::std::str::FromStr for TrafficChannel {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
match value {
"websocket" => Ok(Self::Websocket),
"rest" => Ok(Self::Rest),
"peerMediator" => Ok(Self::PeerMediator),
"internal" => Ok(Self::Internal),
_ => Err("invalid value".into()),
}
}
}
impl ::std::convert::TryFrom<&str> for TrafficChannel {
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 TrafficChannel {
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 TrafficChannel {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
///`inbound`: arriving at the mediator. `outbound`: leaving it (delivery to a recipient, or a forward to another mediator). `internal`: a state change with no wire traffic (expiry, deletion, purge).
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "TrafficDirection",
/// "description": "`inbound`: arriving at the mediator. `outbound`: leaving it (delivery to a recipient, or a forward to another mediator). `internal`: a state change with no wire traffic (expiry, deletion, purge).",
/// "type": "string",
/// "enum": [
/// "inbound",
/// "outbound",
/// "internal"
/// ]
///}
/// ```
/// </details>
#[derive(
::serde::Deserialize,
::serde::Serialize,
Clone,
Copy,
Debug,
Eq,
Hash,
Ord,
PartialEq,
PartialOrd,
)]
#[non_exhaustive]
pub enum TrafficDirection {
#[serde(rename = "inbound")]
Inbound,
#[serde(rename = "outbound")]
Outbound,
#[serde(rename = "internal")]
Internal,
}
impl ::std::fmt::Display for TrafficDirection {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
match *self {
Self::Inbound => f.write_str("inbound"),
Self::Outbound => f.write_str("outbound"),
Self::Internal => f.write_str("internal"),
}
}
}
impl ::std::str::FromStr for TrafficDirection {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
match value {
"inbound" => Ok(Self::Inbound),
"outbound" => Ok(Self::Outbound),
"internal" => Ok(Self::Internal),
_ => Err("invalid value".into()),
}
}
}
impl ::std::convert::TryFrom<&str> for TrafficDirection {
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 TrafficDirection {
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 TrafficDirection {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
///What happened. `received`: a frame arrived. `stored`: it was queued for a local account. `delivered`: handed to its recipient. `forwarded`: relayed to another mediator. `refused`: rejected (see the event's `outcome`). `deleted`: removed by its recipient or an administrator. `expired`: removed by expiry. `purged`: removed by a queue purge.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "TrafficStage",
/// "description": "What happened. `received`: a frame arrived. `stored`: it was queued for a local account. `delivered`: handed to its recipient. `forwarded`: relayed to another mediator. `refused`: rejected (see the event's `outcome`). `deleted`: removed by its recipient or an administrator. `expired`: removed by expiry. `purged`: removed by a queue purge.",
/// "type": "string",
/// "enum": [
/// "received",
/// "stored",
/// "delivered",
/// "forwarded",
/// "refused",
/// "deleted",
/// "expired",
/// "purged"
/// ]
///}
/// ```
/// </details>
#[derive(
::serde::Deserialize,
::serde::Serialize,
Clone,
Copy,
Debug,
Eq,
Hash,
Ord,
PartialEq,
PartialOrd,
)]
#[non_exhaustive]
pub enum TrafficStage {
#[serde(rename = "received")]
Received,
#[serde(rename = "stored")]
Stored,
#[serde(rename = "delivered")]
Delivered,
#[serde(rename = "forwarded")]
Forwarded,
#[serde(rename = "refused")]
Refused,
#[serde(rename = "deleted")]
Deleted,
#[serde(rename = "expired")]
Expired,
#[serde(rename = "purged")]
Purged,
}
impl ::std::fmt::Display for TrafficStage {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
match *self {
Self::Received => f.write_str("received"),
Self::Stored => f.write_str("stored"),
Self::Delivered => f.write_str("delivered"),
Self::Forwarded => f.write_str("forwarded"),
Self::Refused => f.write_str("refused"),
Self::Deleted => f.write_str("deleted"),
Self::Expired => f.write_str("expired"),
Self::Purged => f.write_str("purged"),
}
}
}
impl ::std::str::FromStr for TrafficStage {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
match value {
"received" => Ok(Self::Received),
"stored" => Ok(Self::Stored),
"delivered" => Ok(Self::Delivered),
"forwarded" => Ok(Self::Forwarded),
"refused" => Ok(Self::Refused),
"deleted" => Ok(Self::Deleted),
"expired" => Ok(Self::Expired),
"purged" => Ok(Self::Purged),
_ => Err("invalid value".into()),
}
}
}
impl ::std::convert::TryFrom<&str> for TrafficStage {
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 TrafficStage {
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 TrafficStage {
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())
})
}
}
///The protocol a message travelled in, as the mediator detected it from the wire form. `didcomm` is DIDComm v2 (JWE/JWS); `didcommV1` is a DIDComm v1 envelope; `tsp` is a Trust Spanning Protocol message; `other` is anything the mediator could not classify.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "WireProtocol",
/// "description": "The protocol a message travelled in, as the mediator detected it from the wire form. `didcomm` is DIDComm v2 (JWE/JWS); `didcommV1` is a DIDComm v1 envelope; `tsp` is a Trust Spanning Protocol message; `other` is anything the mediator could not classify.",
/// "type": "string",
/// "enum": [
/// "didcomm",
/// "didcommV1",
/// "tsp",
/// "other"
/// ]
///}
/// ```
/// </details>
#[derive(
::serde::Deserialize,
::serde::Serialize,
Clone,
Copy,
Debug,
Eq,
Hash,
Ord,
PartialEq,
PartialOrd,
)]
#[non_exhaustive]
pub enum WireProtocol {
#[serde(rename = "didcomm")]
Didcomm,
#[serde(rename = "didcommV1")]
DidcommV1,
#[serde(rename = "tsp")]
Tsp,
#[serde(rename = "other")]
Other,
}
impl ::std::fmt::Display for WireProtocol {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
match *self {
Self::Didcomm => f.write_str("didcomm"),
Self::DidcommV1 => f.write_str("didcommV1"),
Self::Tsp => f.write_str("tsp"),
Self::Other => f.write_str("other"),
}
}
}
impl ::std::str::FromStr for WireProtocol {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
match value {
"didcomm" => Ok(Self::Didcomm),
"didcommV1" => Ok(Self::DidcommV1),
"tsp" => Ok(Self::Tsp),
"other" => Ok(Self::Other),
_ => Err("invalid value".into()),
}
}
}
impl ::std::convert::TryFrom<&str> for WireProtocol {
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 WireProtocol {
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 WireProtocol {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
/// Types for composing complex structures.
pub mod builder {
#[derive(Clone, Debug)]
pub struct MonitorFilter {
channels: ::std::result::Result<
::std::option::Option<Vec<super::TrafficChannel>>,
::std::string::String,
>,
dids: ::std::result::Result<::std::option::Option<Vec<super::Vid>>, ::std::string::String>,
directions: ::std::result::Result<
::std::option::Option<Vec<super::TrafficDirection>>,
::std::string::String,
>,
failures_only: ::std::result::Result<::std::option::Option<bool>, ::std::string::String>,
message_type_prefixes: ::std::result::Result<
::std::option::Option<Vec<super::MonitorFilterMessageTypePrefixesItem>>,
::std::string::String,
>,
protocols: ::std::result::Result<
::std::option::Option<Vec<super::WireProtocol>>,
::std::string::String,
>,
stages: ::std::result::Result<
::std::option::Option<Vec<super::TrafficStage>>,
::std::string::String,
>,
}
impl ::std::default::Default for MonitorFilter {
fn default() -> Self {
Self {
channels: Ok(Default::default()),
dids: Ok(Default::default()),
directions: Ok(Default::default()),
failures_only: Ok(Default::default()),
message_type_prefixes: Ok(Default::default()),
protocols: Ok(Default::default()),
stages: Ok(Default::default()),
}
}
}
impl MonitorFilter {
pub fn channels<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<Vec<super::TrafficChannel>>>,
T::Error: ::std::fmt::Display,
{
self.channels = value
.try_into()
.map_err(|e| format!("error converting supplied value for channels: {e}"));
self
}
pub fn dids<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<Vec<super::Vid>>>,
T::Error: ::std::fmt::Display,
{
self.dids = value
.try_into()
.map_err(|e| format!("error converting supplied value for dids: {e}"));
self
}
pub fn directions<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<Vec<super::TrafficDirection>>>,
T::Error: ::std::fmt::Display,
{
self.directions = value
.try_into()
.map_err(|e| format!("error converting supplied value for directions: {e}"));
self
}
pub fn failures_only<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<bool>>,
T::Error: ::std::fmt::Display,
{
self.failures_only = value
.try_into()
.map_err(|e| format!("error converting supplied value for failures_only: {e}"));
self
}
pub fn message_type_prefixes<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<
::std::option::Option<Vec<super::MonitorFilterMessageTypePrefixesItem>>,
>,
T::Error: ::std::fmt::Display,
{
self.message_type_prefixes = value.try_into().map_err(|e| {
format!("error converting supplied value for message_type_prefixes: {e}")
});
self
}
pub fn protocols<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<Vec<super::WireProtocol>>>,
T::Error: ::std::fmt::Display,
{
self.protocols = value
.try_into()
.map_err(|e| format!("error converting supplied value for protocols: {e}"));
self
}
pub fn stages<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<Vec<super::TrafficStage>>>,
T::Error: ::std::fmt::Display,
{
self.stages = value
.try_into()
.map_err(|e| format!("error converting supplied value for stages: {e}"));
self
}
}
impl ::std::convert::TryFrom<MonitorFilter> for super::MonitorFilter {
type Error = super::error::ConversionError;
fn try_from(
value: MonitorFilter,
) -> ::std::result::Result<Self, super::error::ConversionError> {
Ok(Self {
channels: value.channels?,
dids: value.dids?,
directions: value.directions?,
failures_only: value.failures_only?,
message_type_prefixes: value.message_type_prefixes?,
protocols: value.protocols?,
stages: value.stages?,
})
}
}
impl ::std::convert::From<super::MonitorFilter> for MonitorFilter {
fn from(value: super::MonitorFilter) -> Self {
Self {
channels: Ok(value.channels),
dids: Ok(value.dids),
directions: Ok(value.directions),
failures_only: Ok(value.failures_only),
message_type_prefixes: Ok(value.message_type_prefixes),
protocols: Ok(value.protocols),
stages: Ok(value.stages),
}
}
}
#[derive(Clone, Debug)]
pub struct Payload {
ext: ::std::result::Result<::std::option::Option<super::Ext>, ::std::string::String>,
filter: ::std::result::Result<
::std::option::Option<super::MonitorFilter>,
::std::string::String,
>,
lease_seconds: ::std::result::Result<::std::option::Option<i64>, ::std::string::String>,
max_events_per_second: ::std::result::Result<
::std::option::Option<::std::num::NonZeroU64>,
::std::string::String,
>,
subscription_id: ::std::result::Result<
::std::option::Option<super::PayloadSubscriptionId>,
::std::string::String,
>,
}
impl ::std::default::Default for Payload {
fn default() -> Self {
Self {
ext: Ok(Default::default()),
filter: Ok(Default::default()),
lease_seconds: Ok(Default::default()),
max_events_per_second: Ok(Default::default()),
subscription_id: Ok(Default::default()),
}
}
}
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 filter<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::MonitorFilter>>,
T::Error: ::std::fmt::Display,
{
self.filter = value
.try_into()
.map_err(|e| format!("error converting supplied value for filter: {e}"));
self
}
pub fn lease_seconds<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<i64>>,
T::Error: ::std::fmt::Display,
{
self.lease_seconds = value
.try_into()
.map_err(|e| format!("error converting supplied value for lease_seconds: {e}"));
self
}
pub fn max_events_per_second<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<::std::num::NonZeroU64>>,
T::Error: ::std::fmt::Display,
{
self.max_events_per_second = value.try_into().map_err(|e| {
format!("error converting supplied value for max_events_per_second: {e}")
});
self
}
pub fn subscription_id<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::PayloadSubscriptionId>>,
T::Error: ::std::fmt::Display,
{
self.subscription_id = value
.try_into()
.map_err(|e| format!("error converting supplied value for subscription_id: {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?,
filter: value.filter?,
lease_seconds: value.lease_seconds?,
max_events_per_second: value.max_events_per_second?,
subscription_id: value.subscription_id?,
})
}
}
impl ::std::convert::From<super::Payload> for Payload {
fn from(value: super::Payload) -> Self {
Self {
ext: Ok(value.ext),
filter: Ok(value.filter),
lease_seconds: Ok(value.lease_seconds),
max_events_per_second: Ok(value.max_events_per_second),
subscription_id: Ok(value.subscription_id),
}
}
}
#[derive(Clone, Debug)]
pub struct Response {
expires_at:
::std::result::Result<::chrono::DateTime<::chrono::offset::Utc>, ::std::string::String>,
ext: ::std::result::Result<::std::option::Option<super::Ext>, ::std::string::String>,
filter: ::std::result::Result<super::MonitorFilter, ::std::string::String>,
max_events_per_second: ::std::result::Result<::std::num::NonZeroU64, ::std::string::String>,
subscription_id:
::std::result::Result<super::ResponseSubscriptionId, ::std::string::String>,
}
impl ::std::default::Default for Response {
fn default() -> Self {
Self {
expires_at: Err("no value supplied for expires_at".to_string()),
ext: Ok(Default::default()),
filter: Err("no value supplied for filter".to_string()),
max_events_per_second: Err(
"no value supplied for max_events_per_second".to_string()
),
subscription_id: Err("no value supplied for subscription_id".to_string()),
}
}
}
impl Response {
pub fn expires_at<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::chrono::DateTime<::chrono::offset::Utc>>,
T::Error: ::std::fmt::Display,
{
self.expires_at = value
.try_into()
.map_err(|e| format!("error converting supplied value for expires_at: {e}"));
self
}
pub fn ext<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::Ext>>,
T::Error: ::std::fmt::Display,
{
self.ext = value
.try_into()
.map_err(|e| format!("error converting supplied value for ext: {e}"));
self
}
pub fn filter<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::MonitorFilter>,
T::Error: ::std::fmt::Display,
{
self.filter = value
.try_into()
.map_err(|e| format!("error converting supplied value for filter: {e}"));
self
}
pub fn max_events_per_second<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::num::NonZeroU64>,
T::Error: ::std::fmt::Display,
{
self.max_events_per_second = value.try_into().map_err(|e| {
format!("error converting supplied value for max_events_per_second: {e}")
});
self
}
pub fn subscription_id<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::ResponseSubscriptionId>,
T::Error: ::std::fmt::Display,
{
self.subscription_id = value
.try_into()
.map_err(|e| format!("error converting supplied value for subscription_id: {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 {
expires_at: value.expires_at?,
ext: value.ext?,
filter: value.filter?,
max_events_per_second: value.max_events_per_second?,
subscription_id: value.subscription_id?,
})
}
}
impl ::std::convert::From<super::Response> for Response {
fn from(value: super::Response) -> Self {
Self {
expires_at: Ok(value.expires_at),
ext: Ok(value.ext),
filter: Ok(value.filter),
max_events_per_second: Ok(value.max_events_per_second),
subscription_id: Ok(value.subscription_id),
}
}
}
}
impl crate::Payload for Payload {
const TYPE_URI: &'static str = "https://trusttasks.org/spec/messaging/monitor/subscribe/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 \"MonitorFilter\": {\n \"additionalProperties\": false,\n \"description\": \"Selects which events a monitor subscription receives. Every member present narrows the selection (members are ANDed; values within one member are ORed). An empty filter selects everything the requester is entitled to see.\",\n \"properties\": {\n \"channels\": {\n \"items\": {\n \"$ref\": \"#/$defs/TrafficChannel\"\n },\n \"minItems\": 1,\n \"type\": \"array\",\n \"uniqueItems\": true\n },\n \"dids\": {\n \"description\": \"Only events whose `from` or `to` is one of these accounts.\",\n \"items\": {\n \"$ref\": \"#/$defs/Vid\"\n },\n \"maxItems\": 100,\n \"minItems\": 1,\n \"type\": \"array\",\n \"uniqueItems\": true\n },\n \"directions\": {\n \"items\": {\n \"$ref\": \"#/$defs/TrafficDirection\"\n },\n \"minItems\": 1,\n \"type\": \"array\",\n \"uniqueItems\": true\n },\n \"failuresOnly\": {\n \"description\": \"Only events that carry an `outcome`.\",\n \"type\": \"boolean\"\n },\n \"messageTypePrefixes\": {\n \"description\": \"Only events whose `messageType` starts with one of these strings. Events with no `messageType` never match when this member is present.\",\n \"items\": {\n \"maxLength\": 512,\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"maxItems\": 20,\n \"minItems\": 1,\n \"type\": \"array\",\n \"uniqueItems\": true\n },\n \"protocols\": {\n \"items\": {\n \"$ref\": \"#/$defs/WireProtocol\"\n },\n \"minItems\": 1,\n \"type\": \"array\",\n \"uniqueItems\": true\n },\n \"stages\": {\n \"items\": {\n \"$ref\": \"#/$defs/TrafficStage\"\n },\n \"minItems\": 1,\n \"type\": \"array\",\n \"uniqueItems\": true\n }\n },\n \"title\": \"MonitorFilter\",\n \"type\": \"object\"\n },\n \"Response\": {\n \"$anchor\": \"response\",\n \"additionalProperties\": false,\n \"description\": \"The success response to a messaging/monitor/subscribe request. Carried in a Trust Task document whose type is https://trusttasks.org/spec/messaging/monitor/subscribe/0.1#response.\",\n \"properties\": {\n \"expiresAt\": {\n \"format\": \"date-time\",\n \"type\": \"string\"\n },\n \"ext\": {\n \"$ref\": \"#/$defs/Ext\",\n \"description\": \"Ecosystem-defined extension members per SPEC.md §4.5.1.\"\n },\n \"filter\": {\n \"$ref\": \"#/$defs/MonitorFilter\",\n \"description\": \"The filter in force, after the mediator narrowed it to what the requester is entitled to see.\"\n },\n \"maxEventsPerSecond\": {\n \"description\": \"The rate ceiling in force.\",\n \"minimum\": 1,\n \"type\": \"integer\"\n },\n \"subscriptionId\": {\n \"minLength\": 1,\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"subscriptionId\",\n \"expiresAt\",\n \"filter\",\n \"maxEventsPerSecond\"\n ],\n \"title\": \"Messaging — Subscribe to Traffic Monitor — response payload\",\n \"type\": \"object\"\n },\n \"TrafficChannel\": {\n \"description\": \"How the traffic reached or left the mediator. `peerMediator` is mediator-to-mediator forwarding.\",\n \"enum\": [\n \"websocket\",\n \"rest\",\n \"peerMediator\",\n \"internal\"\n ],\n \"title\": \"TrafficChannel\",\n \"type\": \"string\"\n },\n \"TrafficDirection\": {\n \"description\": \"`inbound`: arriving at the mediator. `outbound`: leaving it (delivery to a recipient, or a forward to another mediator). `internal`: a state change with no wire traffic (expiry, deletion, purge).\",\n \"enum\": [\n \"inbound\",\n \"outbound\",\n \"internal\"\n ],\n \"title\": \"TrafficDirection\",\n \"type\": \"string\"\n },\n \"TrafficStage\": {\n \"description\": \"What happened. `received`: a frame arrived. `stored`: it was queued for a local account. `delivered`: handed to its recipient. `forwarded`: relayed to another mediator. `refused`: rejected (see the event's `outcome`). `deleted`: removed by its recipient or an administrator. `expired`: removed by expiry. `purged`: removed by a queue purge.\",\n \"enum\": [\n \"received\",\n \"stored\",\n \"delivered\",\n \"forwarded\",\n \"refused\",\n \"deleted\",\n \"expired\",\n \"purged\"\n ],\n \"title\": \"TrafficStage\",\n \"type\": \"string\"\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 \"WireProtocol\": {\n \"description\": \"The protocol a message travelled in, as the mediator detected it from the wire form. `didcomm` is DIDComm v2 (JWE/JWS); `didcommV1` is a DIDComm v1 envelope; `tsp` is a Trust Spanning Protocol message; `other` is anything the mediator could not classify.\",\n \"enum\": [\n \"didcomm\",\n \"didcommV1\",\n \"tsp\",\n \"other\"\n ],\n \"title\": \"WireProtocol\",\n \"type\": \"string\"\n }\n },\n \"$id\": \"https://trusttasks.org/spec/messaging/monitor/subscribe/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 \"filter\": {\n \"$ref\": \"#/$defs/MonitorFilter\"\n },\n \"leaseSeconds\": {\n \"description\": \"How long the subscription lives unless renewed. Default 300.\",\n \"maximum\": 3600,\n \"minimum\": 10,\n \"type\": \"integer\"\n },\n \"maxEventsPerSecond\": {\n \"description\": \"Rate ceiling the subscriber can absorb; the mediator MAY apply a lower one. Events over the ceiling are counted as dropped, never queued.\",\n \"maximum\": 1000,\n \"minimum\": 1,\n \"type\": \"integer\"\n },\n \"subscriptionId\": {\n \"description\": \"Renew or re-filter an existing subscription held by the same requester. Omitted = create a new one.\",\n \"minLength\": 1,\n \"type\": \"string\"\n }\n },\n \"title\": \"Messaging — Subscribe to Traffic Monitor — payload\",\n \"type\": \"object\"\n}\n",
);
}
impl crate::Payload for Response {
const TYPE_URI: &'static str =
"https://trusttasks.org/spec/messaging/monitor/subscribe/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 \"MonitorFilter\": {\n \"additionalProperties\": false,\n \"description\": \"Selects which events a monitor subscription receives. Every member present narrows the selection (members are ANDed; values within one member are ORed). An empty filter selects everything the requester is entitled to see.\",\n \"properties\": {\n \"channels\": {\n \"items\": {\n \"$ref\": \"#/$defs/TrafficChannel\"\n },\n \"minItems\": 1,\n \"type\": \"array\",\n \"uniqueItems\": true\n },\n \"dids\": {\n \"description\": \"Only events whose `from` or `to` is one of these accounts.\",\n \"items\": {\n \"$ref\": \"#/$defs/Vid\"\n },\n \"maxItems\": 100,\n \"minItems\": 1,\n \"type\": \"array\",\n \"uniqueItems\": true\n },\n \"directions\": {\n \"items\": {\n \"$ref\": \"#/$defs/TrafficDirection\"\n },\n \"minItems\": 1,\n \"type\": \"array\",\n \"uniqueItems\": true\n },\n \"failuresOnly\": {\n \"description\": \"Only events that carry an `outcome`.\",\n \"type\": \"boolean\"\n },\n \"messageTypePrefixes\": {\n \"description\": \"Only events whose `messageType` starts with one of these strings. Events with no `messageType` never match when this member is present.\",\n \"items\": {\n \"maxLength\": 512,\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"maxItems\": 20,\n \"minItems\": 1,\n \"type\": \"array\",\n \"uniqueItems\": true\n },\n \"protocols\": {\n \"items\": {\n \"$ref\": \"#/$defs/WireProtocol\"\n },\n \"minItems\": 1,\n \"type\": \"array\",\n \"uniqueItems\": true\n },\n \"stages\": {\n \"items\": {\n \"$ref\": \"#/$defs/TrafficStage\"\n },\n \"minItems\": 1,\n \"type\": \"array\",\n \"uniqueItems\": true\n }\n },\n \"title\": \"MonitorFilter\",\n \"type\": \"object\"\n },\n \"Response\": {\n \"$anchor\": \"response\",\n \"additionalProperties\": false,\n \"description\": \"The success response to a messaging/monitor/subscribe request. Carried in a Trust Task document whose type is https://trusttasks.org/spec/messaging/monitor/subscribe/0.1#response.\",\n \"properties\": {\n \"expiresAt\": {\n \"format\": \"date-time\",\n \"type\": \"string\"\n },\n \"ext\": {\n \"$ref\": \"#/$defs/Ext\",\n \"description\": \"Ecosystem-defined extension members per SPEC.md §4.5.1.\"\n },\n \"filter\": {\n \"$ref\": \"#/$defs/MonitorFilter\",\n \"description\": \"The filter in force, after the mediator narrowed it to what the requester is entitled to see.\"\n },\n \"maxEventsPerSecond\": {\n \"description\": \"The rate ceiling in force.\",\n \"minimum\": 1,\n \"type\": \"integer\"\n },\n \"subscriptionId\": {\n \"minLength\": 1,\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"subscriptionId\",\n \"expiresAt\",\n \"filter\",\n \"maxEventsPerSecond\"\n ],\n \"title\": \"Messaging — Subscribe to Traffic Monitor — response payload\",\n \"type\": \"object\"\n },\n \"TrafficChannel\": {\n \"description\": \"How the traffic reached or left the mediator. `peerMediator` is mediator-to-mediator forwarding.\",\n \"enum\": [\n \"websocket\",\n \"rest\",\n \"peerMediator\",\n \"internal\"\n ],\n \"title\": \"TrafficChannel\",\n \"type\": \"string\"\n },\n \"TrafficDirection\": {\n \"description\": \"`inbound`: arriving at the mediator. `outbound`: leaving it (delivery to a recipient, or a forward to another mediator). `internal`: a state change with no wire traffic (expiry, deletion, purge).\",\n \"enum\": [\n \"inbound\",\n \"outbound\",\n \"internal\"\n ],\n \"title\": \"TrafficDirection\",\n \"type\": \"string\"\n },\n \"TrafficStage\": {\n \"description\": \"What happened. `received`: a frame arrived. `stored`: it was queued for a local account. `delivered`: handed to its recipient. `forwarded`: relayed to another mediator. `refused`: rejected (see the event's `outcome`). `deleted`: removed by its recipient or an administrator. `expired`: removed by expiry. `purged`: removed by a queue purge.\",\n \"enum\": [\n \"received\",\n \"stored\",\n \"delivered\",\n \"forwarded\",\n \"refused\",\n \"deleted\",\n \"expired\",\n \"purged\"\n ],\n \"title\": \"TrafficStage\",\n \"type\": \"string\"\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 \"WireProtocol\": {\n \"description\": \"The protocol a message travelled in, as the mediator detected it from the wire form. `didcomm` is DIDComm v2 (JWE/JWS); `didcommV1` is a DIDComm v1 envelope; `tsp` is a Trust Spanning Protocol message; `other` is anything the mediator could not classify.\",\n \"enum\": [\n \"didcomm\",\n \"didcommV1\",\n \"tsp\",\n \"other\"\n ],\n \"title\": \"WireProtocol\",\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_SUBSCRIPTION,
error_codes::TOO_MANY_SUBSCRIPTIONS,
];
/// 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/monitor/subscribe:unknownSubscription`
///
/// The request names a `subscriptionId` the mediator does not hold for this requester — it never existed, has expired, was ended, or belongs to someone else. Omit `subscriptionId` to open a new subscription.
///
/// Declared `retryable: false`.
pub const UNKNOWN_SUBSCRIPTION: crate::DeclaredErrorCode = crate::DeclaredErrorCode {
code: "messaging/monitor/subscribe:unknownSubscription",
retryable: false,
};
/// `messaging/monitor/subscribe:tooManySubscriptions`
///
/// The requester already holds the maximum number of concurrent subscriptions the mediator allows. End one, or wait for one to expire.
///
/// Declared `retryable: true`.
pub const TOO_MANY_SUBSCRIPTIONS: crate::DeclaredErrorCode = crate::DeclaredErrorCode {
code: "messaging/monitor/subscribe:tooManySubscriptions",
retryable: true,
};
}
#[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:9d4e2c71-0a6b-4f3e-8c21-5e7f1a2b3c01\",\n \"type\": \"https://trusttasks.org/spec/messaging/monitor/subscribe/0.1\",\n \"issuer\": \"did:web:admin.example\",\n \"recipient\": \"did:web:mediator.example\",\n \"issuedAt\": \"2026-09-21T11:00:00Z\",\n \"payload\": {\n \"filter\": {\n \"dids\": [\"did:web:alice.example\"],\n \"protocols\": [\"didcomm\", \"tsp\"],\n \"failuresOnly\": true\n },\n \"leaseSeconds\": 600,\n \"maxEventsPerSecond\": 50\n },\n \"proof\": {\n \"type\": \"DataIntegrityProof\",\n \"cryptosuite\": \"eddsa-jcs-2022\",\n \"verificationMethod\": \"did:web:admin.example#key-1\",\n \"created\": \"2026-09-21T11:00:00Z\",\n \"proofPurpose\": \"assertionMethod\",\n \"proofValue\": \"z5mc...\"\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:9d4e2c71-0a6b-4f3e-8c21-5e7f1a2b3c02\",\n \"type\": \"https://trusttasks.org/spec/messaging/monitor/subscribe/0.1#response\",\n \"threadId\": \"urn:uuid:9d4e2c71-0a6b-4f3e-8c21-5e7f1a2b3c01\",\n \"issuer\": \"did:web:mediator.example\",\n \"recipient\": \"did:web:admin.example\",\n \"issuedAt\": \"2026-09-21T11:00:00Z\",\n \"payload\": {\n \"subscriptionId\": \"mon_8f3a2c1e9b7d4a60\",\n \"expiresAt\": \"2026-09-21T11:10:00Z\",\n \"filter\": {\n \"dids\": [\"did:web:alice.example\"],\n \"protocols\": [\"didcomm\", \"tsp\"],\n \"failuresOnly\": true\n },\n \"maxEventsPerSecond\": 20\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");
}
}