//! Generated by `trust-tasks-codegen` — do not edit by hand.
//!
//! Spec slug: `messaging/monitor/event`. 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())
})
}
}
///One observed step in the life of one message at the mediator. Carries metadata only — never a message body.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "MonitorEvent",
/// "description": "One observed step in the life of one message at the mediator. Carries metadata only — never a message body.",
/// "type": "object",
/// "required": [
/// "at",
/// "channel",
/// "direction",
/// "protocol",
/// "stage"
/// ],
/// "properties": {
/// "at": {
/// "description": "When the step happened, with sub-second precision where the mediator has it.",
/// "type": "string",
/// "format": "date-time"
/// },
/// "channel": {
/// "$ref": "#/definitions/TrafficChannel"
/// },
/// "direction": {
/// "$ref": "#/definitions/TrafficDirection"
/// },
/// "from": {
/// "description": "The sender, where the mediator knows it.",
/// "$ref": "#/definitions/Vid"
/// },
/// "latencyMs": {
/// "description": "For `delivered` and `forwarded`: milliseconds since the message was stored.",
/// "type": "integer",
/// "minimum": 0.0
/// },
/// "messageType": {
/// "description": "The plaintext message type, present only when the mediator itself was the addressee and read it (a routing forward, a pickup request, a trust-task type URI, a trust ping). Absent for end-to-end-encrypted traffic the mediator only relays.",
/// "type": "string",
/// "maxLength": 512,
/// "minLength": 1
/// },
/// "msgId": {
/// "description": "The stored message's identifier, once it has one; correlates the events of one message and matches MessageMeta.msgId.",
/// "type": "string",
/// "maxLength": 256,
/// "minLength": 1
/// },
/// "outcome": {
/// "description": "Present when stage is `refused`, and on any other stage that failed.",
/// "$ref": "#/definitions/TrafficOutcome"
/// },
/// "protocol": {
/// "$ref": "#/definitions/WireProtocol"
/// },
/// "size": {
/// "description": "Frame size in bytes.",
/// "type": "integer",
/// "minimum": 0.0
/// },
/// "stage": {
/// "$ref": "#/definitions/TrafficStage"
/// },
/// "to": {
/// "description": "The recipient, where the mediator knows it.",
/// "$ref": "#/definitions/Vid"
/// }
/// },
/// "additionalProperties": false
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct MonitorEvent {
///When the step happened, with sub-second precision where the mediator has it.
pub at: ::chrono::DateTime<::chrono::offset::Utc>,
pub channel: TrafficChannel,
pub direction: TrafficDirection,
///The sender, where the mediator knows it.
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub from: ::std::option::Option<Vid>,
///For `delivered` and `forwarded`: milliseconds since the message was stored.
#[serde(
rename = "latencyMs",
default,
skip_serializing_if = "::std::option::Option::is_none"
)]
pub latency_ms: ::std::option::Option<u64>,
///The plaintext message type, present only when the mediator itself was the addressee and read it (a routing forward, a pickup request, a trust-task type URI, a trust ping). Absent for end-to-end-encrypted traffic the mediator only relays.
#[serde(
rename = "messageType",
default,
skip_serializing_if = "::std::option::Option::is_none"
)]
pub message_type: ::std::option::Option<MonitorEventMessageType>,
///The stored message's identifier, once it has one; correlates the events of one message and matches MessageMeta.msgId.
#[serde(
rename = "msgId",
default,
skip_serializing_if = "::std::option::Option::is_none"
)]
pub msg_id: ::std::option::Option<MonitorEventMsgId>,
///Present when stage is `refused`, and on any other stage that failed.
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub outcome: ::std::option::Option<TrafficOutcome>,
pub protocol: WireProtocol,
///Frame size in bytes.
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub size: ::std::option::Option<u64>,
pub stage: TrafficStage,
///The recipient, where the mediator knows it.
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub to: ::std::option::Option<Vid>,
}
impl MonitorEvent {
pub fn builder() -> builder::MonitorEvent {
Default::default()
}
}
///The plaintext message type, present only when the mediator itself was the addressee and read it (a routing forward, a pickup request, a trust-task type URI, a trust ping). Absent for end-to-end-encrypted traffic the mediator only relays.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "The plaintext message type, present only when the mediator itself was the addressee and read it (a routing forward, a pickup request, a trust-task type URI, a trust ping). Absent for end-to-end-encrypted traffic the mediator only relays.",
/// "type": "string",
/// "maxLength": 512,
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct MonitorEventMessageType(::std::string::String);
impl ::std::ops::Deref for MonitorEventMessageType {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<MonitorEventMessageType> for ::std::string::String {
fn from(value: MonitorEventMessageType) -> Self {
value.0
}
}
impl ::std::str::FromStr for MonitorEventMessageType {
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 MonitorEventMessageType {
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 MonitorEventMessageType {
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 MonitorEventMessageType {
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 MonitorEventMessageType {
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 stored message's identifier, once it has one; correlates the events of one message and matches MessageMeta.msgId.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "The stored message's identifier, once it has one; correlates the events of one message and matches MessageMeta.msgId.",
/// "type": "string",
/// "maxLength": 256,
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct MonitorEventMsgId(::std::string::String);
impl ::std::ops::Deref for MonitorEventMsgId {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<MonitorEventMsgId> for ::std::string::String {
fn from(value: MonitorEventMsgId) -> Self {
value.0
}
}
impl ::std::str::FromStr for MonitorEventMsgId {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() > 256usize {
return Err("longer than 256 characters".into());
}
if value.chars().count() < 1usize {
return Err("shorter than 1 characters".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for MonitorEventMsgId {
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 MonitorEventMsgId {
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 MonitorEventMsgId {
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 MonitorEventMsgId {
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/event/0.1",
/// "title": "Payload",
/// "type": "object",
/// "required": [
/// "dropped",
/// "events",
/// "expiresAt",
/// "seq",
/// "subscriptionId"
/// ],
/// "properties": {
/// "dropped": {
/// "description": "Events that matched the filter but were discarded since the previous batch — rate ceiling exceeded or subscriber not connected.",
/// "type": "integer",
/// "minimum": 0.0
/// },
/// "events": {
/// "description": "Events in the order the mediator observed them. May be empty on a heartbeat batch.",
/// "type": "array",
/// "items": {
/// "$ref": "#/definitions/MonitorEvent"
/// },
/// "maxItems": 500
/// },
/// "expiresAt": {
/// "description": "The subscription's current expiry, so the subscriber can renew before it lapses.",
/// "type": "string",
/// "format": "date-time"
/// },
/// "ext": {
/// "description": "Ecosystem-defined extension members per SPEC.md §4.5.1.",
/// "$ref": "#/definitions/Ext"
/// },
/// "seq": {
/// "description": "Batch sequence number, starting at 1 and increasing by exactly 1 per batch within a subscription. A gap means batches were lost in transit.",
/// "type": "integer",
/// "minimum": 1.0
/// },
/// "subscriptionId": {
/// "type": "string",
/// "minLength": 1
/// }
/// },
/// "additionalProperties": false
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct Payload {
///Events that matched the filter but were discarded since the previous batch — rate ceiling exceeded or subscriber not connected.
pub dropped: u64,
///Events in the order the mediator observed them. May be empty on a heartbeat batch.
pub events: ::std::vec::Vec<MonitorEvent>,
///The subscription's current expiry, so the subscriber can renew before it lapses.
#[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>,
///Batch sequence number, starting at 1 and increasing by exactly 1 per batch within a subscription. A gap means batches were lost in transit.
pub seq: ::std::num::NonZeroU64,
#[serde(rename = "subscriptionId")]
pub subscription_id: PayloadSubscriptionId,
}
impl Payload {
pub fn builder() -> builder::Payload {
Default::default()
}
}
///`PayloadSubscriptionId`
///
/// <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 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())
})
}
}
///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()
}
}
///Why a frame was refused or failed.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "TrafficOutcome",
/// "description": "Why a frame was refused or failed.",
/// "type": "object",
/// "required": [
/// "code"
/// ],
/// "properties": {
/// "code": {
/// "description": "The stable error code the mediator returned to the sender (a trust-task-error or problem-report code).",
/// "type": "string",
/// "maxLength": 256,
/// "minLength": 1
/// },
/// "detail": {
/// "description": "Short human-readable explanation. Not machine-parsed.",
/// "type": "string",
/// "maxLength": 1024
/// }
/// },
/// "additionalProperties": false
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct TrafficOutcome {
///The stable error code the mediator returned to the sender (a trust-task-error or problem-report code).
pub code: TrafficOutcomeCode,
///Short human-readable explanation. Not machine-parsed.
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub detail: ::std::option::Option<TrafficOutcomeDetail>,
}
impl TrafficOutcome {
pub fn builder() -> builder::TrafficOutcome {
Default::default()
}
}
///The stable error code the mediator returned to the sender (a trust-task-error or problem-report code).
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "The stable error code the mediator returned to the sender (a trust-task-error or problem-report code).",
/// "type": "string",
/// "maxLength": 256,
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct TrafficOutcomeCode(::std::string::String);
impl ::std::ops::Deref for TrafficOutcomeCode {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<TrafficOutcomeCode> for ::std::string::String {
fn from(value: TrafficOutcomeCode) -> Self {
value.0
}
}
impl ::std::str::FromStr for TrafficOutcomeCode {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() > 256usize {
return Err("longer than 256 characters".into());
}
if value.chars().count() < 1usize {
return Err("shorter than 1 characters".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for TrafficOutcomeCode {
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 TrafficOutcomeCode {
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 TrafficOutcomeCode {
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 TrafficOutcomeCode {
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())
})
}
}
///Short human-readable explanation. Not machine-parsed.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "Short human-readable explanation. Not machine-parsed.",
/// "type": "string",
/// "maxLength": 1024
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct TrafficOutcomeDetail(::std::string::String);
impl ::std::ops::Deref for TrafficOutcomeDetail {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<TrafficOutcomeDetail> for ::std::string::String {
fn from(value: TrafficOutcomeDetail) -> Self {
value.0
}
}
impl ::std::str::FromStr for TrafficOutcomeDetail {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() > 1024usize {
return Err("longer than 1024 characters".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for TrafficOutcomeDetail {
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 TrafficOutcomeDetail {
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 TrafficOutcomeDetail {
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 TrafficOutcomeDetail {
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())
})
}
}
///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 MonitorEvent {
at: ::std::result::Result<::chrono::DateTime<::chrono::offset::Utc>, ::std::string::String>,
channel: ::std::result::Result<super::TrafficChannel, ::std::string::String>,
direction: ::std::result::Result<super::TrafficDirection, ::std::string::String>,
from: ::std::result::Result<::std::option::Option<super::Vid>, ::std::string::String>,
latency_ms: ::std::result::Result<::std::option::Option<u64>, ::std::string::String>,
message_type: ::std::result::Result<
::std::option::Option<super::MonitorEventMessageType>,
::std::string::String,
>,
msg_id: ::std::result::Result<
::std::option::Option<super::MonitorEventMsgId>,
::std::string::String,
>,
outcome: ::std::result::Result<
::std::option::Option<super::TrafficOutcome>,
::std::string::String,
>,
protocol: ::std::result::Result<super::WireProtocol, ::std::string::String>,
size: ::std::result::Result<::std::option::Option<u64>, ::std::string::String>,
stage: ::std::result::Result<super::TrafficStage, ::std::string::String>,
to: ::std::result::Result<::std::option::Option<super::Vid>, ::std::string::String>,
}
impl ::std::default::Default for MonitorEvent {
fn default() -> Self {
Self {
at: Err("no value supplied for at".to_string()),
channel: Err("no value supplied for channel".to_string()),
direction: Err("no value supplied for direction".to_string()),
from: Ok(Default::default()),
latency_ms: Ok(Default::default()),
message_type: Ok(Default::default()),
msg_id: Ok(Default::default()),
outcome: Ok(Default::default()),
protocol: Err("no value supplied for protocol".to_string()),
size: Ok(Default::default()),
stage: Err("no value supplied for stage".to_string()),
to: Ok(Default::default()),
}
}
}
impl MonitorEvent {
pub fn at<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::chrono::DateTime<::chrono::offset::Utc>>,
T::Error: ::std::fmt::Display,
{
self.at = value
.try_into()
.map_err(|e| format!("error converting supplied value for at: {e}"));
self
}
pub fn channel<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::TrafficChannel>,
T::Error: ::std::fmt::Display,
{
self.channel = value
.try_into()
.map_err(|e| format!("error converting supplied value for channel: {e}"));
self
}
pub fn direction<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::TrafficDirection>,
T::Error: ::std::fmt::Display,
{
self.direction = value
.try_into()
.map_err(|e| format!("error converting supplied value for direction: {e}"));
self
}
pub fn from<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::Vid>>,
T::Error: ::std::fmt::Display,
{
self.from = value
.try_into()
.map_err(|e| format!("error converting supplied value for from: {e}"));
self
}
pub fn latency_ms<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<u64>>,
T::Error: ::std::fmt::Display,
{
self.latency_ms = value
.try_into()
.map_err(|e| format!("error converting supplied value for latency_ms: {e}"));
self
}
pub fn message_type<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::MonitorEventMessageType>>,
T::Error: ::std::fmt::Display,
{
self.message_type = value
.try_into()
.map_err(|e| format!("error converting supplied value for message_type: {e}"));
self
}
pub fn msg_id<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::MonitorEventMsgId>>,
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 outcome<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::TrafficOutcome>>,
T::Error: ::std::fmt::Display,
{
self.outcome = value
.try_into()
.map_err(|e| format!("error converting supplied value for outcome: {e}"));
self
}
pub fn protocol<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::WireProtocol>,
T::Error: ::std::fmt::Display,
{
self.protocol = value
.try_into()
.map_err(|e| format!("error converting supplied value for protocol: {e}"));
self
}
pub fn size<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<u64>>,
T::Error: ::std::fmt::Display,
{
self.size = value
.try_into()
.map_err(|e| format!("error converting supplied value for size: {e}"));
self
}
pub fn stage<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::TrafficStage>,
T::Error: ::std::fmt::Display,
{
self.stage = value
.try_into()
.map_err(|e| format!("error converting supplied value for stage: {e}"));
self
}
pub fn to<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::Vid>>,
T::Error: ::std::fmt::Display,
{
self.to = value
.try_into()
.map_err(|e| format!("error converting supplied value for to: {e}"));
self
}
}
impl ::std::convert::TryFrom<MonitorEvent> for super::MonitorEvent {
type Error = super::error::ConversionError;
fn try_from(
value: MonitorEvent,
) -> ::std::result::Result<Self, super::error::ConversionError> {
Ok(Self {
at: value.at?,
channel: value.channel?,
direction: value.direction?,
from: value.from?,
latency_ms: value.latency_ms?,
message_type: value.message_type?,
msg_id: value.msg_id?,
outcome: value.outcome?,
protocol: value.protocol?,
size: value.size?,
stage: value.stage?,
to: value.to?,
})
}
}
impl ::std::convert::From<super::MonitorEvent> for MonitorEvent {
fn from(value: super::MonitorEvent) -> Self {
Self {
at: Ok(value.at),
channel: Ok(value.channel),
direction: Ok(value.direction),
from: Ok(value.from),
latency_ms: Ok(value.latency_ms),
message_type: Ok(value.message_type),
msg_id: Ok(value.msg_id),
outcome: Ok(value.outcome),
protocol: Ok(value.protocol),
size: Ok(value.size),
stage: Ok(value.stage),
to: Ok(value.to),
}
}
}
#[derive(Clone, Debug)]
pub struct Payload {
dropped: ::std::result::Result<u64, ::std::string::String>,
events: ::std::result::Result<::std::vec::Vec<super::MonitorEvent>, ::std::string::String>,
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>,
seq: ::std::result::Result<::std::num::NonZeroU64, ::std::string::String>,
subscription_id: ::std::result::Result<super::PayloadSubscriptionId, ::std::string::String>,
}
impl ::std::default::Default for Payload {
fn default() -> Self {
Self {
dropped: Err("no value supplied for dropped".to_string()),
events: Err("no value supplied for events".to_string()),
expires_at: Err("no value supplied for expires_at".to_string()),
ext: Ok(Default::default()),
seq: Err("no value supplied for seq".to_string()),
subscription_id: Err("no value supplied for subscription_id".to_string()),
}
}
}
impl Payload {
pub fn dropped<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<u64>,
T::Error: ::std::fmt::Display,
{
self.dropped = value
.try_into()
.map_err(|e| format!("error converting supplied value for dropped: {e}"));
self
}
pub fn events<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::vec::Vec<super::MonitorEvent>>,
T::Error: ::std::fmt::Display,
{
self.events = value
.try_into()
.map_err(|e| format!("error converting supplied value for events: {e}"));
self
}
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 seq<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::num::NonZeroU64>,
T::Error: ::std::fmt::Display,
{
self.seq = value
.try_into()
.map_err(|e| format!("error converting supplied value for seq: {e}"));
self
}
pub fn subscription_id<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<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 {
dropped: value.dropped?,
events: value.events?,
expires_at: value.expires_at?,
ext: value.ext?,
seq: value.seq?,
subscription_id: value.subscription_id?,
})
}
}
impl ::std::convert::From<super::Payload> for Payload {
fn from(value: super::Payload) -> Self {
Self {
dropped: Ok(value.dropped),
events: Ok(value.events),
expires_at: Ok(value.expires_at),
ext: Ok(value.ext),
seq: Ok(value.seq),
subscription_id: Ok(value.subscription_id),
}
}
}
#[derive(Clone, Debug)]
pub struct TrafficOutcome {
code: ::std::result::Result<super::TrafficOutcomeCode, ::std::string::String>,
detail: ::std::result::Result<
::std::option::Option<super::TrafficOutcomeDetail>,
::std::string::String,
>,
}
impl ::std::default::Default for TrafficOutcome {
fn default() -> Self {
Self {
code: Err("no value supplied for code".to_string()),
detail: Ok(Default::default()),
}
}
}
impl TrafficOutcome {
pub fn code<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::TrafficOutcomeCode>,
T::Error: ::std::fmt::Display,
{
self.code = value
.try_into()
.map_err(|e| format!("error converting supplied value for code: {e}"));
self
}
pub fn detail<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::TrafficOutcomeDetail>>,
T::Error: ::std::fmt::Display,
{
self.detail = value
.try_into()
.map_err(|e| format!("error converting supplied value for detail: {e}"));
self
}
}
impl ::std::convert::TryFrom<TrafficOutcome> for super::TrafficOutcome {
type Error = super::error::ConversionError;
fn try_from(
value: TrafficOutcome,
) -> ::std::result::Result<Self, super::error::ConversionError> {
Ok(Self {
code: value.code?,
detail: value.detail?,
})
}
}
impl ::std::convert::From<super::TrafficOutcome> for TrafficOutcome {
fn from(value: super::TrafficOutcome) -> Self {
Self {
code: Ok(value.code),
detail: Ok(value.detail),
}
}
}
}
impl crate::Payload for Payload {
const TYPE_URI: &'static str = "https://trusttasks.org/spec/messaging/monitor/event/0.1";
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 \"MonitorEvent\": {\n \"additionalProperties\": false,\n \"description\": \"One observed step in the life of one message at the mediator. Carries metadata only — never a message body.\",\n \"properties\": {\n \"at\": {\n \"description\": \"When the step happened, with sub-second precision where the mediator has it.\",\n \"format\": \"date-time\",\n \"type\": \"string\"\n },\n \"channel\": {\n \"$ref\": \"#/$defs/TrafficChannel\"\n },\n \"direction\": {\n \"$ref\": \"#/$defs/TrafficDirection\"\n },\n \"from\": {\n \"$ref\": \"#/$defs/Vid\",\n \"description\": \"The sender, where the mediator knows it.\"\n },\n \"latencyMs\": {\n \"description\": \"For `delivered` and `forwarded`: milliseconds since the message was stored.\",\n \"minimum\": 0,\n \"type\": \"integer\"\n },\n \"messageType\": {\n \"description\": \"The plaintext message type, present only when the mediator itself was the addressee and read it (a routing forward, a pickup request, a trust-task type URI, a trust ping). Absent for end-to-end-encrypted traffic the mediator only relays.\",\n \"maxLength\": 512,\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"msgId\": {\n \"description\": \"The stored message's identifier, once it has one; correlates the events of one message and matches MessageMeta.msgId.\",\n \"maxLength\": 256,\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"outcome\": {\n \"$ref\": \"#/$defs/TrafficOutcome\",\n \"description\": \"Present when stage is `refused`, and on any other stage that failed.\"\n },\n \"protocol\": {\n \"$ref\": \"#/$defs/WireProtocol\"\n },\n \"size\": {\n \"description\": \"Frame size in bytes.\",\n \"minimum\": 0,\n \"type\": \"integer\"\n },\n \"stage\": {\n \"$ref\": \"#/$defs/TrafficStage\"\n },\n \"to\": {\n \"$ref\": \"#/$defs/Vid\",\n \"description\": \"The recipient, where the mediator knows it.\"\n }\n },\n \"required\": [\n \"at\",\n \"direction\",\n \"stage\",\n \"channel\",\n \"protocol\"\n ],\n \"title\": \"MonitorEvent\",\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 \"TrafficOutcome\": {\n \"additionalProperties\": false,\n \"description\": \"Why a frame was refused or failed.\",\n \"properties\": {\n \"code\": {\n \"description\": \"The stable error code the mediator returned to the sender (a trust-task-error or problem-report code).\",\n \"maxLength\": 256,\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"detail\": {\n \"description\": \"Short human-readable explanation. Not machine-parsed.\",\n \"maxLength\": 1024,\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"code\"\n ],\n \"title\": \"TrafficOutcome\",\n \"type\": \"object\"\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/event/0.1\",\n \"$schema\": \"https://json-schema.org/draft/2020-12/schema\",\n \"additionalProperties\": false,\n \"properties\": {\n \"dropped\": {\n \"description\": \"Events that matched the filter but were discarded since the previous batch — rate ceiling exceeded or subscriber not connected.\",\n \"minimum\": 0,\n \"type\": \"integer\"\n },\n \"events\": {\n \"description\": \"Events in the order the mediator observed them. May be empty on a heartbeat batch.\",\n \"items\": {\n \"$ref\": \"#/$defs/MonitorEvent\"\n },\n \"maxItems\": 500,\n \"type\": \"array\"\n },\n \"expiresAt\": {\n \"description\": \"The subscription's current expiry, so the subscriber can renew before it lapses.\",\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 \"seq\": {\n \"description\": \"Batch sequence number, starting at 1 and increasing by exactly 1 per batch within a subscription. A gap means batches were lost in transit.\",\n \"minimum\": 1,\n \"type\": \"integer\"\n },\n \"subscriptionId\": {\n \"minLength\": 1,\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"subscriptionId\",\n \"seq\",\n \"events\",\n \"dropped\",\n \"expiresAt\"\n ],\n \"title\": \"Messaging — Traffic Monitor Event — payload\",\n \"type\": \"object\"\n}\n",
);
}
/// The extended error codes this specification declares (SPEC §7.3 item 9,
/// §8.5), in declaration order. Empty when it declares none.
pub const ERROR_CODES: &[crate::DeclaredErrorCode] = &[];
#[cfg(test)]
mod conformance {
//! Round-trip tests harvested from the spec's `spec.md`,
//! plus a `rejects_invalid_examples` test for any fixtures
//! in `payload.invalid-examples.json` (validate feature).
#[test]
fn request_example_1() {
const JSON: &str = "{\n \"id\": \"urn:uuid:5c6d7e8f-9a0b-4c1d-8e2f-3a4b5c6d7e01\",\n \"type\": \"https://trusttasks.org/spec/messaging/monitor/event/0.1\",\n \"issuer\": \"did:web:mediator.example\",\n \"recipient\": \"did:web:admin.example\",\n \"issuedAt\": \"2026-09-21T11:02:14Z\",\n \"payload\": {\n \"subscriptionId\": \"mon_8f3a2c1e9b7d4a60\",\n \"seq\": 42,\n \"events\": [\n {\n \"at\": \"2026-09-21T11:02:13.418Z\",\n \"direction\": \"inbound\",\n \"stage\": \"refused\",\n \"channel\": \"websocket\",\n \"protocol\": \"tsp\",\n \"from\": \"did:web:bob.example\",\n \"to\": \"did:web:alice.example\",\n \"size\": 912,\n \"outcome\": {\n \"code\": \"authorization.acl.denied\",\n \"detail\": \"alice's access list does not admit bob\"\n }\n },\n {\n \"at\": \"2026-09-21T11:02:13.902Z\",\n \"direction\": \"outbound\",\n \"stage\": \"delivered\",\n \"channel\": \"websocket\",\n \"protocol\": \"didcomm\",\n \"msgId\": \"1726916533000-0\",\n \"to\": \"did:web:alice.example\",\n \"size\": 1843,\n \"latencyMs\": 4210\n }\n ],\n \"dropped\": 0,\n \"expiresAt\": \"2026-09-21T11:10:00Z\"\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 request_example_2() {
const JSON: &str = "{\n \"id\": \"urn:uuid:5c6d7e8f-9a0b-4c1d-8e2f-3a4b5c6d7e02\",\n \"type\": \"https://trusttasks.org/spec/messaging/monitor/event/0.1\",\n \"issuer\": \"did:web:mediator.example\",\n \"recipient\": \"did:web:admin.example\",\n \"issuedAt\": \"2026-09-21T11:02:44Z\",\n \"payload\": {\n \"subscriptionId\": \"mon_8f3a2c1e9b7d4a60\",\n \"seq\": 43,\n \"events\": [],\n \"dropped\": 0,\n \"expiresAt\": \"2026-09-21T11:10:00Z\"\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");
}
}