//! Generated by `trust-tasks-codegen` — do not edit by hand.
//!
//! Spec slug: `vta/services/report`. 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())
})
}
}
///`MediatorStats`
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "type": "object",
/// "required": [
/// "firstSeen",
/// "inboundCount",
/// "lastSeen",
/// "mediatorDid"
/// ],
/// "properties": {
/// "firstSeen": {
/// "description": "The first arrival through it in the window.",
/// "type": "string",
/// "format": "date-time"
/// },
/// "inboundCount": {
/// "description": "Messages that arrived through it in the window, over every mediated transport.",
/// "type": "integer",
/// "minimum": 0.0
/// },
/// "lastSeen": {
/// "description": "The last arrival through it in the window.",
/// "type": "string",
/// "format": "date-time"
/// },
/// "mediatorDid": {
/// "description": "The mediator the traffic arrived through.",
/// "type": "string",
/// "maxLength": 1000,
/// "minLength": 1
/// }
/// },
/// "additionalProperties": false
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct MediatorStats {
///The first arrival through it in the window.
#[serde(rename = "firstSeen")]
pub first_seen: ::chrono::DateTime<::chrono::offset::Utc>,
///Messages that arrived through it in the window, over every mediated transport.
#[serde(rename = "inboundCount")]
pub inbound_count: u64,
///The last arrival through it in the window.
#[serde(rename = "lastSeen")]
pub last_seen: ::chrono::DateTime<::chrono::offset::Utc>,
///The mediator the traffic arrived through.
#[serde(rename = "mediatorDid")]
pub mediator_did: MediatorStatsMediatorDid,
}
impl MediatorStats {
pub fn builder() -> builder::MediatorStats {
Default::default()
}
}
///The mediator the traffic arrived through.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "The mediator the traffic arrived through.",
/// "type": "string",
/// "maxLength": 1000,
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct MediatorStatsMediatorDid(::std::string::String);
impl ::std::ops::Deref for MediatorStatsMediatorDid {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<MediatorStatsMediatorDid> for ::std::string::String {
fn from(value: MediatorStatsMediatorDid) -> Self {
value.0
}
}
impl ::std::str::FromStr for MediatorStatsMediatorDid {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() > 1000usize {
return Err("longer than 1000 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 MediatorStatsMediatorDid {
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 MediatorStatsMediatorDid {
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 MediatorStatsMediatorDid {
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 MediatorStatsMediatorDid {
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())
})
}
}
///Asks an agent for its per-mediator inbound counts and each sender's last-seen mediator over a time window. The outer document members (id, type, issuer, recipient, issuedAt, expiresAt, proof) are owned by the framework — SPEC §6.3.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "$id": "https://trusttasks.org/spec/vta/services/report/0.1",
/// "title": "Payload",
/// "description": "Asks an agent for its per-mediator inbound counts and each sender's last-seen mediator over a time window. The outer document members (id, type, issuer, recipient, issuedAt, expiresAt, proof) are owned by the framework — SPEC §6.3.",
/// "type": "object",
/// "properties": {
/// "ext": {
/// "description": "Ecosystem-defined extension members per SPEC.md §4.5.1.",
/// "$ref": "#/definitions/Ext"
/// },
/// "since": {
/// "description": "Lower bound, RFC 3339. Absent means as far back as the agent's telemetry goes.",
/// "type": "string",
/// "format": "date-time"
/// },
/// "until": {
/// "description": "Upper bound, RFC 3339. Absent means now.",
/// "type": "string",
/// "format": "date-time"
/// }
/// },
/// "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>,
///Lower bound, RFC 3339. Absent means as far back as the agent's telemetry goes.
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub since: ::std::option::Option<::chrono::DateTime<::chrono::offset::Utc>>,
///Upper bound, RFC 3339. Absent means now.
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub until: ::std::option::Option<::chrono::DateTime<::chrono::offset::Utc>>,
}
impl ::std::default::Default for Payload {
fn default() -> Self {
Self {
ext: Default::default(),
since: Default::default(),
until: Default::default(),
}
}
}
impl Payload {
pub fn builder() -> builder::Payload {
Default::default()
}
}
///`Response`
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "Response",
/// "type": "object",
/// "required": [
/// "mediators",
/// "senders",
/// "until"
/// ],
/// "properties": {
/// "ext": {
/// "description": "Ecosystem-defined extension members per SPEC.md §4.5.1.",
/// "$ref": "#/definitions/Ext"
/// },
/// "mediators": {
/// "description": "One entry per mediator that carried inbound traffic in the window.",
/// "type": "array",
/// "items": {
/// "$ref": "#/definitions/MediatorStats"
/// },
/// "maxItems": 1000
/// },
/// "senders": {
/// "description": "One entry per sender that reached the agent in the window.",
/// "type": "array",
/// "items": {
/// "$ref": "#/definitions/SenderLastSeen"
/// },
/// "maxItems": 100000
/// },
/// "since": {
/// "description": "The lower bound applied, when the request gave one.",
/// "type": "string",
/// "format": "date-time"
/// },
/// "until": {
/// "description": "The upper bound applied — now, when the request gave none.",
/// "type": "string",
/// "format": "date-time"
/// }
/// },
/// "additionalProperties": false,
/// "$anchor": "response"
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct Response {
///Ecosystem-defined extension members per SPEC.md §4.5.1.
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub ext: ::std::option::Option<Ext>,
///One entry per mediator that carried inbound traffic in the window.
pub mediators: ::std::vec::Vec<MediatorStats>,
///One entry per sender that reached the agent in the window.
pub senders: ::std::vec::Vec<SenderLastSeen>,
///The lower bound applied, when the request gave one.
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub since: ::std::option::Option<::chrono::DateTime<::chrono::offset::Utc>>,
///The upper bound applied — now, when the request gave none.
pub until: ::chrono::DateTime<::chrono::offset::Utc>,
}
impl Response {
pub fn builder() -> builder::Response {
Default::default()
}
}
///`SenderLastSeen`
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "type": "object",
/// "required": [
/// "lastSeenAt",
/// "lastSeenMediator",
/// "senderDid"
/// ],
/// "properties": {
/// "lastSeenAt": {
/// "description": "When that message arrived.",
/// "type": "string",
/// "format": "date-time"
/// },
/// "lastSeenMediator": {
/// "description": "The mediator its most recent message arrived through.",
/// "type": "string",
/// "maxLength": 1000,
/// "minLength": 1
/// },
/// "lastSeenTransport": {
/// "description": "The mediated transport the sender's most recent message arrived by. Absent when the agent's telemetry did not record it.",
/// "type": "string",
/// "enum": [
/// "didcomm",
/// "tsp"
/// ]
/// },
/// "senderDid": {
/// "description": "A sender that reached the agent in the window.",
/// "type": "string",
/// "maxLength": 1000,
/// "minLength": 1
/// }
/// },
/// "additionalProperties": false
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct SenderLastSeen {
///When that message arrived.
#[serde(rename = "lastSeenAt")]
pub last_seen_at: ::chrono::DateTime<::chrono::offset::Utc>,
///The mediator its most recent message arrived through.
#[serde(rename = "lastSeenMediator")]
pub last_seen_mediator: SenderLastSeenLastSeenMediator,
///The mediated transport the sender's most recent message arrived by. Absent when the agent's telemetry did not record it.
#[serde(
rename = "lastSeenTransport",
default,
skip_serializing_if = "::std::option::Option::is_none"
)]
pub last_seen_transport: ::std::option::Option<SenderLastSeenLastSeenTransport>,
///A sender that reached the agent in the window.
#[serde(rename = "senderDid")]
pub sender_did: SenderLastSeenSenderDid,
}
impl SenderLastSeen {
pub fn builder() -> builder::SenderLastSeen {
Default::default()
}
}
///The mediator its most recent message arrived through.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "The mediator its most recent message arrived through.",
/// "type": "string",
/// "maxLength": 1000,
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct SenderLastSeenLastSeenMediator(::std::string::String);
impl ::std::ops::Deref for SenderLastSeenLastSeenMediator {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<SenderLastSeenLastSeenMediator> for ::std::string::String {
fn from(value: SenderLastSeenLastSeenMediator) -> Self {
value.0
}
}
impl ::std::str::FromStr for SenderLastSeenLastSeenMediator {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() > 1000usize {
return Err("longer than 1000 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 SenderLastSeenLastSeenMediator {
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 SenderLastSeenLastSeenMediator {
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 SenderLastSeenLastSeenMediator {
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 SenderLastSeenLastSeenMediator {
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 mediated transport the sender's most recent message arrived by. Absent when the agent's telemetry did not record it.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "The mediated transport the sender's most recent message arrived by. Absent when the agent's telemetry did not record it.",
/// "type": "string",
/// "enum": [
/// "didcomm",
/// "tsp"
/// ]
///}
/// ```
/// </details>
#[derive(
::serde::Deserialize,
::serde::Serialize,
Clone,
Copy,
Debug,
Eq,
Hash,
Ord,
PartialEq,
PartialOrd,
)]
#[non_exhaustive]
pub enum SenderLastSeenLastSeenTransport {
#[serde(rename = "didcomm")]
Didcomm,
#[serde(rename = "tsp")]
Tsp,
}
impl ::std::fmt::Display for SenderLastSeenLastSeenTransport {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
match *self {
Self::Didcomm => f.write_str("didcomm"),
Self::Tsp => f.write_str("tsp"),
}
}
}
impl ::std::str::FromStr for SenderLastSeenLastSeenTransport {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
match value {
"didcomm" => Ok(Self::Didcomm),
"tsp" => Ok(Self::Tsp),
_ => Err("invalid value".into()),
}
}
}
impl ::std::convert::TryFrom<&str> for SenderLastSeenLastSeenTransport {
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 SenderLastSeenLastSeenTransport {
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 SenderLastSeenLastSeenTransport {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
///A sender that reached the agent in the window.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "A sender that reached the agent in the window.",
/// "type": "string",
/// "maxLength": 1000,
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct SenderLastSeenSenderDid(::std::string::String);
impl ::std::ops::Deref for SenderLastSeenSenderDid {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<SenderLastSeenSenderDid> for ::std::string::String {
fn from(value: SenderLastSeenSenderDid) -> Self {
value.0
}
}
impl ::std::str::FromStr for SenderLastSeenSenderDid {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() > 1000usize {
return Err("longer than 1000 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 SenderLastSeenSenderDid {
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 SenderLastSeenSenderDid {
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 SenderLastSeenSenderDid {
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 SenderLastSeenSenderDid {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
::std::string::String::deserialize(deserializer)?
.parse()
.map_err(|e: self::error::ConversionError| {
<D::Error as ::serde::de::Error>::custom(e.to_string())
})
}
}
/// Types for composing complex structures.
pub mod builder {
#[derive(Clone, Debug)]
pub struct MediatorStats {
first_seen:
::std::result::Result<::chrono::DateTime<::chrono::offset::Utc>, ::std::string::String>,
inbound_count: ::std::result::Result<u64, ::std::string::String>,
last_seen:
::std::result::Result<::chrono::DateTime<::chrono::offset::Utc>, ::std::string::String>,
mediator_did: ::std::result::Result<super::MediatorStatsMediatorDid, ::std::string::String>,
}
impl ::std::default::Default for MediatorStats {
fn default() -> Self {
Self {
first_seen: Err("no value supplied for first_seen".to_string()),
inbound_count: Err("no value supplied for inbound_count".to_string()),
last_seen: Err("no value supplied for last_seen".to_string()),
mediator_did: Err("no value supplied for mediator_did".to_string()),
}
}
}
impl MediatorStats {
pub fn first_seen<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::chrono::DateTime<::chrono::offset::Utc>>,
T::Error: ::std::fmt::Display,
{
self.first_seen = value
.try_into()
.map_err(|e| format!("error converting supplied value for first_seen: {e}"));
self
}
pub fn inbound_count<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<u64>,
T::Error: ::std::fmt::Display,
{
self.inbound_count = value
.try_into()
.map_err(|e| format!("error converting supplied value for inbound_count: {e}"));
self
}
pub fn last_seen<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::chrono::DateTime<::chrono::offset::Utc>>,
T::Error: ::std::fmt::Display,
{
self.last_seen = value
.try_into()
.map_err(|e| format!("error converting supplied value for last_seen: {e}"));
self
}
pub fn mediator_did<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::MediatorStatsMediatorDid>,
T::Error: ::std::fmt::Display,
{
self.mediator_did = value
.try_into()
.map_err(|e| format!("error converting supplied value for mediator_did: {e}"));
self
}
}
impl ::std::convert::TryFrom<MediatorStats> for super::MediatorStats {
type Error = super::error::ConversionError;
fn try_from(
value: MediatorStats,
) -> ::std::result::Result<Self, super::error::ConversionError> {
Ok(Self {
first_seen: value.first_seen?,
inbound_count: value.inbound_count?,
last_seen: value.last_seen?,
mediator_did: value.mediator_did?,
})
}
}
impl ::std::convert::From<super::MediatorStats> for MediatorStats {
fn from(value: super::MediatorStats) -> Self {
Self {
first_seen: Ok(value.first_seen),
inbound_count: Ok(value.inbound_count),
last_seen: Ok(value.last_seen),
mediator_did: Ok(value.mediator_did),
}
}
}
#[derive(Clone, Debug)]
pub struct Payload {
ext: ::std::result::Result<::std::option::Option<super::Ext>, ::std::string::String>,
since: ::std::result::Result<
::std::option::Option<::chrono::DateTime<::chrono::offset::Utc>>,
::std::string::String,
>,
until: ::std::result::Result<
::std::option::Option<::chrono::DateTime<::chrono::offset::Utc>>,
::std::string::String,
>,
}
impl ::std::default::Default for Payload {
fn default() -> Self {
Self {
ext: Ok(Default::default()),
since: Ok(Default::default()),
until: 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 since<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<
::std::option::Option<::chrono::DateTime<::chrono::offset::Utc>>,
>,
T::Error: ::std::fmt::Display,
{
self.since = value
.try_into()
.map_err(|e| format!("error converting supplied value for since: {e}"));
self
}
pub fn until<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<
::std::option::Option<::chrono::DateTime<::chrono::offset::Utc>>,
>,
T::Error: ::std::fmt::Display,
{
self.until = value
.try_into()
.map_err(|e| format!("error converting supplied value for until: {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?,
since: value.since?,
until: value.until?,
})
}
}
impl ::std::convert::From<super::Payload> for Payload {
fn from(value: super::Payload) -> Self {
Self {
ext: Ok(value.ext),
since: Ok(value.since),
until: Ok(value.until),
}
}
}
#[derive(Clone, Debug)]
pub struct Response {
ext: ::std::result::Result<::std::option::Option<super::Ext>, ::std::string::String>,
mediators:
::std::result::Result<::std::vec::Vec<super::MediatorStats>, ::std::string::String>,
senders:
::std::result::Result<::std::vec::Vec<super::SenderLastSeen>, ::std::string::String>,
since: ::std::result::Result<
::std::option::Option<::chrono::DateTime<::chrono::offset::Utc>>,
::std::string::String,
>,
until:
::std::result::Result<::chrono::DateTime<::chrono::offset::Utc>, ::std::string::String>,
}
impl ::std::default::Default for Response {
fn default() -> Self {
Self {
ext: Ok(Default::default()),
mediators: Err("no value supplied for mediators".to_string()),
senders: Err("no value supplied for senders".to_string()),
since: Ok(Default::default()),
until: Err("no value supplied for until".to_string()),
}
}
}
impl Response {
pub fn ext<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::Ext>>,
T::Error: ::std::fmt::Display,
{
self.ext = value
.try_into()
.map_err(|e| format!("error converting supplied value for ext: {e}"));
self
}
pub fn mediators<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::vec::Vec<super::MediatorStats>>,
T::Error: ::std::fmt::Display,
{
self.mediators = value
.try_into()
.map_err(|e| format!("error converting supplied value for mediators: {e}"));
self
}
pub fn senders<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::vec::Vec<super::SenderLastSeen>>,
T::Error: ::std::fmt::Display,
{
self.senders = value
.try_into()
.map_err(|e| format!("error converting supplied value for senders: {e}"));
self
}
pub fn since<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<
::std::option::Option<::chrono::DateTime<::chrono::offset::Utc>>,
>,
T::Error: ::std::fmt::Display,
{
self.since = value
.try_into()
.map_err(|e| format!("error converting supplied value for since: {e}"));
self
}
pub fn until<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::chrono::DateTime<::chrono::offset::Utc>>,
T::Error: ::std::fmt::Display,
{
self.until = value
.try_into()
.map_err(|e| format!("error converting supplied value for until: {e}"));
self
}
}
impl ::std::convert::TryFrom<Response> for super::Response {
type Error = super::error::ConversionError;
fn try_from(value: Response) -> ::std::result::Result<Self, super::error::ConversionError> {
Ok(Self {
ext: value.ext?,
mediators: value.mediators?,
senders: value.senders?,
since: value.since?,
until: value.until?,
})
}
}
impl ::std::convert::From<super::Response> for Response {
fn from(value: super::Response) -> Self {
Self {
ext: Ok(value.ext),
mediators: Ok(value.mediators),
senders: Ok(value.senders),
since: Ok(value.since),
until: Ok(value.until),
}
}
}
#[derive(Clone, Debug)]
pub struct SenderLastSeen {
last_seen_at:
::std::result::Result<::chrono::DateTime<::chrono::offset::Utc>, ::std::string::String>,
last_seen_mediator:
::std::result::Result<super::SenderLastSeenLastSeenMediator, ::std::string::String>,
last_seen_transport: ::std::result::Result<
::std::option::Option<super::SenderLastSeenLastSeenTransport>,
::std::string::String,
>,
sender_did: ::std::result::Result<super::SenderLastSeenSenderDid, ::std::string::String>,
}
impl ::std::default::Default for SenderLastSeen {
fn default() -> Self {
Self {
last_seen_at: Err("no value supplied for last_seen_at".to_string()),
last_seen_mediator: Err("no value supplied for last_seen_mediator".to_string()),
last_seen_transport: Ok(Default::default()),
sender_did: Err("no value supplied for sender_did".to_string()),
}
}
}
impl SenderLastSeen {
pub fn last_seen_at<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::chrono::DateTime<::chrono::offset::Utc>>,
T::Error: ::std::fmt::Display,
{
self.last_seen_at = value
.try_into()
.map_err(|e| format!("error converting supplied value for last_seen_at: {e}"));
self
}
pub fn last_seen_mediator<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::SenderLastSeenLastSeenMediator>,
T::Error: ::std::fmt::Display,
{
self.last_seen_mediator = value.try_into().map_err(|e| {
format!("error converting supplied value for last_seen_mediator: {e}")
});
self
}
pub fn last_seen_transport<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<
::std::option::Option<super::SenderLastSeenLastSeenTransport>,
>,
T::Error: ::std::fmt::Display,
{
self.last_seen_transport = value.try_into().map_err(|e| {
format!("error converting supplied value for last_seen_transport: {e}")
});
self
}
pub fn sender_did<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::SenderLastSeenSenderDid>,
T::Error: ::std::fmt::Display,
{
self.sender_did = value
.try_into()
.map_err(|e| format!("error converting supplied value for sender_did: {e}"));
self
}
}
impl ::std::convert::TryFrom<SenderLastSeen> for super::SenderLastSeen {
type Error = super::error::ConversionError;
fn try_from(
value: SenderLastSeen,
) -> ::std::result::Result<Self, super::error::ConversionError> {
Ok(Self {
last_seen_at: value.last_seen_at?,
last_seen_mediator: value.last_seen_mediator?,
last_seen_transport: value.last_seen_transport?,
sender_did: value.sender_did?,
})
}
}
impl ::std::convert::From<super::SenderLastSeen> for SenderLastSeen {
fn from(value: super::SenderLastSeen) -> Self {
Self {
last_seen_at: Ok(value.last_seen_at),
last_seen_mediator: Ok(value.last_seen_mediator),
last_seen_transport: Ok(value.last_seen_transport),
sender_did: Ok(value.sender_did),
}
}
}
}
impl crate::Payload for Payload {
const TYPE_URI: &'static str = "https://trusttasks.org/spec/vta/services/report/0.1";
const IS_PROOF_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 \"MediatorStats\": {\n \"additionalProperties\": false,\n \"properties\": {\n \"firstSeen\": {\n \"description\": \"The first arrival through it in the window.\",\n \"format\": \"date-time\",\n \"type\": \"string\"\n },\n \"inboundCount\": {\n \"description\": \"Messages that arrived through it in the window, over every mediated transport.\",\n \"minimum\": 0,\n \"type\": \"integer\"\n },\n \"lastSeen\": {\n \"description\": \"The last arrival through it in the window.\",\n \"format\": \"date-time\",\n \"type\": \"string\"\n },\n \"mediatorDid\": {\n \"description\": \"The mediator the traffic arrived through.\",\n \"maxLength\": 1000,\n \"minLength\": 1,\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"mediatorDid\",\n \"inboundCount\",\n \"firstSeen\",\n \"lastSeen\"\n ],\n \"type\": \"object\"\n },\n \"Response\": {\n \"$anchor\": \"response\",\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 \"mediators\": {\n \"description\": \"One entry per mediator that carried inbound traffic in the window.\",\n \"items\": {\n \"$ref\": \"#/$defs/MediatorStats\"\n },\n \"maxItems\": 1000,\n \"type\": \"array\"\n },\n \"senders\": {\n \"description\": \"One entry per sender that reached the agent in the window.\",\n \"items\": {\n \"$ref\": \"#/$defs/SenderLastSeen\"\n },\n \"maxItems\": 100000,\n \"type\": \"array\"\n },\n \"since\": {\n \"description\": \"The lower bound applied, when the request gave one.\",\n \"format\": \"date-time\",\n \"type\": \"string\"\n },\n \"until\": {\n \"description\": \"The upper bound applied — now, when the request gave none.\",\n \"format\": \"date-time\",\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"until\",\n \"mediators\",\n \"senders\"\n ],\n \"title\": \"VTA Services Report — response payload\",\n \"type\": \"object\"\n },\n \"SenderLastSeen\": {\n \"additionalProperties\": false,\n \"properties\": {\n \"lastSeenAt\": {\n \"description\": \"When that message arrived.\",\n \"format\": \"date-time\",\n \"type\": \"string\"\n },\n \"lastSeenMediator\": {\n \"description\": \"The mediator its most recent message arrived through.\",\n \"maxLength\": 1000,\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"lastSeenTransport\": {\n \"description\": \"The mediated transport the sender's most recent message arrived by. Absent when the agent's telemetry did not record it.\",\n \"enum\": [\n \"didcomm\",\n \"tsp\"\n ],\n \"type\": \"string\"\n },\n \"senderDid\": {\n \"description\": \"A sender that reached the agent in the window.\",\n \"maxLength\": 1000,\n \"minLength\": 1,\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"senderDid\",\n \"lastSeenMediator\",\n \"lastSeenAt\"\n ],\n \"type\": \"object\"\n }\n },\n \"$id\": \"https://trusttasks.org/spec/vta/services/report/0.1\",\n \"$schema\": \"https://json-schema.org/draft/2020-12/schema\",\n \"additionalProperties\": false,\n \"description\": \"Asks an agent for its per-mediator inbound counts and each sender's last-seen mediator over a time window. The outer document members (id, type, issuer, recipient, issuedAt, expiresAt, proof) are owned by the framework — SPEC §6.3.\",\n \"properties\": {\n \"ext\": {\n \"$ref\": \"#/$defs/Ext\",\n \"description\": \"Ecosystem-defined extension members per SPEC.md §4.5.1.\"\n },\n \"since\": {\n \"description\": \"Lower bound, RFC 3339. Absent means as far back as the agent's telemetry goes.\",\n \"format\": \"date-time\",\n \"type\": \"string\"\n },\n \"until\": {\n \"description\": \"Upper bound, RFC 3339. Absent means now.\",\n \"format\": \"date-time\",\n \"type\": \"string\"\n }\n },\n \"title\": \"VTA Services — Report — payload\",\n \"type\": \"object\"\n}\n",
);
}
impl crate::Payload for Response {
const TYPE_URI: &'static str = "https://trusttasks.org/spec/vta/services/report/0.1#response";
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 \"MediatorStats\": {\n \"additionalProperties\": false,\n \"properties\": {\n \"firstSeen\": {\n \"description\": \"The first arrival through it in the window.\",\n \"format\": \"date-time\",\n \"type\": \"string\"\n },\n \"inboundCount\": {\n \"description\": \"Messages that arrived through it in the window, over every mediated transport.\",\n \"minimum\": 0,\n \"type\": \"integer\"\n },\n \"lastSeen\": {\n \"description\": \"The last arrival through it in the window.\",\n \"format\": \"date-time\",\n \"type\": \"string\"\n },\n \"mediatorDid\": {\n \"description\": \"The mediator the traffic arrived through.\",\n \"maxLength\": 1000,\n \"minLength\": 1,\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"mediatorDid\",\n \"inboundCount\",\n \"firstSeen\",\n \"lastSeen\"\n ],\n \"type\": \"object\"\n },\n \"Response\": {\n \"$anchor\": \"response\",\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 \"mediators\": {\n \"description\": \"One entry per mediator that carried inbound traffic in the window.\",\n \"items\": {\n \"$ref\": \"#/$defs/MediatorStats\"\n },\n \"maxItems\": 1000,\n \"type\": \"array\"\n },\n \"senders\": {\n \"description\": \"One entry per sender that reached the agent in the window.\",\n \"items\": {\n \"$ref\": \"#/$defs/SenderLastSeen\"\n },\n \"maxItems\": 100000,\n \"type\": \"array\"\n },\n \"since\": {\n \"description\": \"The lower bound applied, when the request gave one.\",\n \"format\": \"date-time\",\n \"type\": \"string\"\n },\n \"until\": {\n \"description\": \"The upper bound applied — now, when the request gave none.\",\n \"format\": \"date-time\",\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"until\",\n \"mediators\",\n \"senders\"\n ],\n \"title\": \"VTA Services Report — response payload\",\n \"type\": \"object\"\n },\n \"SenderLastSeen\": {\n \"additionalProperties\": false,\n \"properties\": {\n \"lastSeenAt\": {\n \"description\": \"When that message arrived.\",\n \"format\": \"date-time\",\n \"type\": \"string\"\n },\n \"lastSeenMediator\": {\n \"description\": \"The mediator its most recent message arrived through.\",\n \"maxLength\": 1000,\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"lastSeenTransport\": {\n \"description\": \"The mediated transport the sender's most recent message arrived by. Absent when the agent's telemetry did not record it.\",\n \"enum\": [\n \"didcomm\",\n \"tsp\"\n ],\n \"type\": \"string\"\n },\n \"senderDid\": {\n \"description\": \"A sender that reached the agent in the window.\",\n \"maxLength\": 1000,\n \"minLength\": 1,\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"senderDid\",\n \"lastSeenMediator\",\n \"lastSeenAt\"\n ],\n \"type\": \"object\"\n }\n },\n \"$ref\": \"#/$defs/Response\",\n \"$schema\": \"https://json-schema.org/draft/2020-12/schema\"\n}\n",
);
}
impl crate::RequestPayload for Payload {
type Response = Response;
}
/// The extended error codes this specification declares (SPEC §7.3 item 9,
/// §8.5), in declaration order. Empty when it declares none.
pub const ERROR_CODES: &[crate::DeclaredErrorCode] = &[error_codes::INVALID_WINDOW];
/// 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 {
/// `vta/services/report:invalidWindow`
///
/// `since` is after `until`.
///
/// Declared `retryable: false`.
pub const INVALID_WINDOW: crate::DeclaredErrorCode = crate::DeclaredErrorCode {
code: "vta/services/report:invalidWindow",
retryable: false,
};
}
#[cfg(test)]
mod conformance {
//! Round-trip tests harvested from the spec's `spec.md`,
//! plus a `rejects_invalid_examples` test for any fixtures
//! in `payload.invalid-examples.json` (validate feature).
#[test]
fn request_example_1() {
const JSON: &str = "{\n \"id\": \"urn:uuid:3e4f5a6b-7c8d-4e9f-8a0b-1c2d3e4f5a6b\",\n \"type\": \"https://trusttasks.org/spec/vta/services/report/0.1\",\n \"issuer\": \"did:key:z6MkOperatorExampleKey\",\n \"recipient\": \"did:webvh:QmExampleScid:vta.example.com\",\n \"issuedAt\": \"2026-09-26T12:00:00Z\",\n \"payload\": {\n \"since\": \"2026-09-19T00:00: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 response_example_1() {
const JSON: &str = "{\n \"id\": \"urn:uuid:8f9a0b1c-2d3e-4f4a-8b5c-6d7e8f9a0b1c\",\n \"threadId\": \"urn:uuid:3e4f5a6b-7c8d-4e9f-8a0b-1c2d3e4f5a6b\",\n \"type\": \"https://trusttasks.org/spec/vta/services/report/0.1#response\",\n \"issuer\": \"did:webvh:QmExampleScid:vta.example.com\",\n \"issuedAt\": \"2026-09-26T12:00:01Z\",\n \"payload\": {\n \"since\": \"2026-09-19T00:00:00Z\",\n \"until\": \"2026-09-26T12:00:01Z\",\n \"mediators\": [\n {\n \"mediatorDid\": \"did:web:old-mediator.example.com\",\n \"inboundCount\": 12,\n \"firstSeen\": \"2026-09-19T08:12:00Z\",\n \"lastSeen\": \"2026-09-24T17:40:00Z\"\n },\n {\n \"mediatorDid\": \"did:web:new-mediator.example.com\",\n \"inboundCount\": 431,\n \"firstSeen\": \"2026-09-20T09:00:00Z\",\n \"lastSeen\": \"2026-09-26T11:59:30Z\"\n }\n ],\n \"senders\": [\n {\n \"senderDid\": \"did:key:z6MkLaggingSenderKey\",\n \"lastSeenMediator\": \"did:web:old-mediator.example.com\",\n \"lastSeenTransport\": \"tsp\",\n \"lastSeenAt\": \"2026-09-24T17:40:00Z\"\n }\n ]\n }\n}\n";
let doc: crate::TrustTask<super::Response> =
serde_json::from_str(JSON).expect("deserialize response example");
let rendered = serde_json::to_value(&doc).expect("re-serialize");
let expected: serde_json::Value = serde_json::from_str(JSON).expect("re-parse expected");
assert_eq!(rendered, expected, "response example failed round-trip");
}
/// Each fixture in `payload.invalid-examples.json` MUST be
/// rejected by at least one of: serde deserialization, or
/// JSON-Schema validation under the `validate` feature. The
/// fixture file documents the producer-side bug class that
/// each payload exemplifies; this generated test pins it.
#[cfg(feature = "validate")]
#[test]
fn rejects_invalid_examples() {
use crate::validate::ValidatedPayload;
let fixtures: &[(&str, &str)] = &[
(
"`since` must be an RFC 3339 timestamp.",
"{\n \"since\": \"last tuesday\"\n}",
),
(
"Unknown top-level member is rejected (additionalProperties: false).",
"{\n \"mediator\": \"did:web:old-mediator.example.com\"\n}",
),
];
for (i, (note, raw)) in fixtures.iter().enumerate() {
let value: serde_json::Value = match serde_json::from_str(raw) {
Ok(v) => v,
Err(_) => continue,
};
let serde_ok = serde_json::from_value::<super::Payload>(value.clone()).is_ok();
let schema_ok = super::Payload::validate_value(&value).is_ok();
assert!(
!(serde_ok && schema_ok),
"invalid-example #{} ({:?}) was accepted by both serde and JSON Schema; \
the fixture's stated failure class is no longer caught:\n{}",
i + 1,
note,
raw
);
}
}
}