//! Generated by `trust-tasks-codegen` — do not edit by hand.
//!
//! Spec slug: `webvh/sync/batch`. 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())
}
}
}
///`EntryResult`
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "EntryResult",
/// "type": "object",
/// "required": [
/// "mnemonic",
/// "status"
/// ],
/// "properties": {
/// "code": {
/// "description": "Present if and only if `status` is `refused`: the webvh/sync/update/0.2 error code the entry would have received on its own (e.g. `webvh/sync/update:historyRewrite`).",
/// "type": "string",
/// "minLength": 1
/// },
/// "mnemonic": {
/// "type": "string",
/// "minLength": 1
/// },
/// "status": {
/// "description": "`applied` and `unchanged` as in webvh/sync/update/0.2. `refused` — the entry was permanently refused; see `code`.",
/// "type": "string",
/// "enum": [
/// "applied",
/// "unchanged",
/// "refused"
/// ]
/// }
/// },
/// "additionalProperties": false
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct EntryResult {
///Present if and only if `status` is `refused`: the webvh/sync/update/0.2 error code the entry would have received on its own (e.g. `webvh/sync/update:historyRewrite`).
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub code: ::std::option::Option<EntryResultCode>,
pub mnemonic: EntryResultMnemonic,
///`applied` and `unchanged` as in webvh/sync/update/0.2. `refused` — the entry was permanently refused; see `code`.
pub status: EntryResultStatus,
}
impl EntryResult {
pub fn builder() -> builder::EntryResult {
Default::default()
}
}
///Present if and only if `status` is `refused`: the webvh/sync/update/0.2 error code the entry would have received on its own (e.g. `webvh/sync/update:historyRewrite`).
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "Present if and only if `status` is `refused`: the webvh/sync/update/0.2 error code the entry would have received on its own (e.g. `webvh/sync/update:historyRewrite`).",
/// "type": "string",
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct EntryResultCode(::std::string::String);
impl ::std::ops::Deref for EntryResultCode {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<EntryResultCode> for ::std::string::String {
fn from(value: EntryResultCode) -> Self {
value.0
}
}
impl ::std::str::FromStr for EntryResultCode {
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 EntryResultCode {
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 EntryResultCode {
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 EntryResultCode {
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 EntryResultCode {
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())
})
}
}
///`EntryResultMnemonic`
///
/// <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 EntryResultMnemonic(::std::string::String);
impl ::std::ops::Deref for EntryResultMnemonic {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<EntryResultMnemonic> for ::std::string::String {
fn from(value: EntryResultMnemonic) -> Self {
value.0
}
}
impl ::std::str::FromStr for EntryResultMnemonic {
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 EntryResultMnemonic {
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 EntryResultMnemonic {
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 EntryResultMnemonic {
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 EntryResultMnemonic {
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())
})
}
}
///`applied` and `unchanged` as in webvh/sync/update/0.2. `refused` — the entry was permanently refused; see `code`.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "`applied` and `unchanged` as in webvh/sync/update/0.2. `refused` — the entry was permanently refused; see `code`.",
/// "type": "string",
/// "enum": [
/// "applied",
/// "unchanged",
/// "refused"
/// ]
///}
/// ```
/// </details>
#[derive(
::serde::Deserialize,
::serde::Serialize,
Clone,
Copy,
Debug,
Eq,
Hash,
Ord,
PartialEq,
PartialOrd,
)]
#[non_exhaustive]
pub enum EntryResultStatus {
#[serde(rename = "applied")]
Applied,
#[serde(rename = "unchanged")]
Unchanged,
#[serde(rename = "refused")]
Refused,
}
impl ::std::fmt::Display for EntryResultStatus {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
match *self {
Self::Applied => f.write_str("applied"),
Self::Unchanged => f.write_str("unchanged"),
Self::Refused => f.write_str("refused"),
}
}
}
impl ::std::str::FromStr for EntryResultStatus {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
match value {
"applied" => Ok(Self::Applied),
"unchanged" => Ok(Self::Unchanged),
"refused" => Ok(Self::Refused),
_ => Err("invalid value".into()),
}
}
}
impl ::std::convert::TryFrom<&str> for EntryResultStatus {
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 EntryResultStatus {
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 EntryResultStatus {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
///Vendor-namespaced extension object per SPEC.md §4.5.1. Each immediate key MUST be a reverse-DNS namespace; structure under each namespace is opaque to the framework.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "Ext",
/// "description": "Vendor-namespaced extension object per SPEC.md §4.5.1. Each immediate key MUST be a reverse-DNS namespace; structure under each namespace is opaque to the framework.",
/// "type": "object",
/// "minProperties": 1,
/// "additionalProperties": true,
/// "propertyNames": {
/// "pattern": "^[a-z][a-z0-9-]*(\\.[a-z0-9-]+)+$"
/// }
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(transparent)]
pub struct Ext(pub ::std::collections::HashMap<ExtKey, ::serde_json::Value>);
impl ::std::ops::Deref for Ext {
type Target = ::std::collections::HashMap<ExtKey, ::serde_json::Value>;
fn deref(&self) -> &::std::collections::HashMap<ExtKey, ::serde_json::Value> {
&self.0
}
}
impl ::std::convert::From<Ext> for ::std::collections::HashMap<ExtKey, ::serde_json::Value> {
fn from(value: Ext) -> Self {
value.0
}
}
impl ::std::convert::From<::std::collections::HashMap<ExtKey, ::serde_json::Value>> for Ext {
fn from(value: ::std::collections::HashMap<ExtKey, ::serde_json::Value>) -> Self {
Self(value)
}
}
///`ExtKey`
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "type": "string",
/// "pattern": "^[a-z][a-z0-9-]*(\\.[a-z0-9-]+)+$"
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct ExtKey(::std::string::String);
impl ::std::ops::Deref for ExtKey {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<ExtKey> for ::std::string::String {
fn from(value: ExtKey) -> Self {
value.0
}
}
impl ::std::str::FromStr for ExtKey {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
static PATTERN: ::std::sync::LazyLock<::regress::Regex> =
::std::sync::LazyLock::new(|| {
::regress::Regex::new("^[a-z][a-z0-9-]*(\\.[a-z0-9-]+)+$").unwrap()
});
if PATTERN.find(value).is_none() {
return Err("doesn't match pattern \"^[a-z][a-z0-9-]*(\\.[a-z0-9-]+)+$\"".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for ExtKey {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for ExtKey {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for ExtKey {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl<'de> ::serde::Deserialize<'de> for ExtKey {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
::std::string::String::deserialize(deserializer)?
.parse()
.map_err(|e: self::error::ConversionError| {
<D::Error as ::serde::de::Error>::custom(e.to_string())
})
}
}
///`Payload`
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "$id": "https://trusttasks.org/spec/webvh/sync/batch/0.1",
/// "title": "Payload",
/// "type": "object",
/// "required": [
/// "updates"
/// ],
/// "properties": {
/// "ext": {
/// "$ref": "#/definitions/Ext"
/// },
/// "updates": {
/// "description": "Complete slot states, each applied exactly as a webvh/sync/update/0.2 carrying it would be. A mnemonic appears at most once.",
/// "type": "array",
/// "items": {
/// "$ref": "#/definitions/SyncUpdate"
/// },
/// "maxItems": 50,
/// "minItems": 1
/// }
/// },
/// "additionalProperties": false
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct Payload {
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub ext: ::std::option::Option<Ext>,
///Complete slot states, each applied exactly as a webvh/sync/update/0.2 carrying it would be. A mnemonic appears at most once.
pub updates: ::std::vec::Vec<SyncUpdate>,
}
impl Payload {
pub fn builder() -> builder::Payload {
Default::default()
}
}
///`Response`
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "Response",
/// "type": "object",
/// "required": [
/// "results"
/// ],
/// "properties": {
/// "ext": {
/// "$ref": "#/definitions/Ext"
/// },
/// "results": {
/// "description": "One result per entry of `updates`, in request order.",
/// "type": "array",
/// "items": {
/// "$ref": "#/definitions/EntryResult"
/// }
/// }
/// },
/// "additionalProperties": false,
/// "$anchor": "response"
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct Response {
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub ext: ::std::option::Option<Ext>,
///One result per entry of `updates`, in request order.
pub results: ::std::vec::Vec<EntryResult>,
}
impl Response {
pub fn builder() -> builder::Response {
Default::default()
}
}
///`SyncUpdate`
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "SyncUpdate",
/// "type": "object",
/// "required": [
/// "didId",
/// "disabled",
/// "logContent",
/// "mnemonic",
/// "versionCount"
/// ],
/// "properties": {
/// "didId": {
/// "description": "The DID the log establishes. A replica MUST refuse a log that does not establish exactly this DID.",
/// "type": "string",
/// "minLength": 1
/// },
/// "disabled": {
/// "description": "Whether the source has disabled the slot. A replica MUST stop serving a disabled slot and MUST resume only on an update carrying `false`.",
/// "type": "boolean"
/// },
/// "ext": {
/// "$ref": "#/definitions/Ext"
/// },
/// "logContent": {
/// "description": "The slot's complete did.jsonl — one log entry per line — not a delta.",
/// "type": "string",
/// "minLength": 1
/// },
/// "mnemonic": {
/// "description": "The slot path on its hosting domain (e.g. `alice`, `people/alice`, or `.well-known` for a root DID).",
/// "type": "string",
/// "minLength": 1
/// },
/// "versionCount": {
/// "description": "Number of entries in `logContent`, as the source counts them. A replica MUST refuse an update whose `logContent` does not contain exactly this many entries.",
/// "type": "integer",
/// "minimum": 1.0
/// },
/// "witnessContent": {
/// "description": "The slot's did-witness.json. ABSENT means the slot holds no witness proofs: the replica MUST drop any witness proofs it holds for the slot. Absence never means \"unchanged\".",
/// "type": "string",
/// "minLength": 1
/// }
/// },
/// "additionalProperties": false
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct SyncUpdate {
///The DID the log establishes. A replica MUST refuse a log that does not establish exactly this DID.
#[serde(rename = "didId")]
pub did_id: SyncUpdateDidId,
///Whether the source has disabled the slot. A replica MUST stop serving a disabled slot and MUST resume only on an update carrying `false`.
pub disabled: bool,
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub ext: ::std::option::Option<Ext>,
///The slot's complete did.jsonl — one log entry per line — not a delta.
#[serde(rename = "logContent")]
pub log_content: SyncUpdateLogContent,
///The slot path on its hosting domain (e.g. `alice`, `people/alice`, or `.well-known` for a root DID).
pub mnemonic: SyncUpdateMnemonic,
///Number of entries in `logContent`, as the source counts them. A replica MUST refuse an update whose `logContent` does not contain exactly this many entries.
#[serde(rename = "versionCount")]
pub version_count: ::std::num::NonZeroU64,
///The slot's did-witness.json. ABSENT means the slot holds no witness proofs: the replica MUST drop any witness proofs it holds for the slot. Absence never means "unchanged".
#[serde(
rename = "witnessContent",
default,
skip_serializing_if = "::std::option::Option::is_none"
)]
pub witness_content: ::std::option::Option<SyncUpdateWitnessContent>,
}
impl SyncUpdate {
pub fn builder() -> builder::SyncUpdate {
Default::default()
}
}
///The DID the log establishes. A replica MUST refuse a log that does not establish exactly this DID.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "The DID the log establishes. A replica MUST refuse a log that does not establish exactly this DID.",
/// "type": "string",
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct SyncUpdateDidId(::std::string::String);
impl ::std::ops::Deref for SyncUpdateDidId {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<SyncUpdateDidId> for ::std::string::String {
fn from(value: SyncUpdateDidId) -> Self {
value.0
}
}
impl ::std::str::FromStr for SyncUpdateDidId {
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 SyncUpdateDidId {
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 SyncUpdateDidId {
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 SyncUpdateDidId {
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 SyncUpdateDidId {
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 slot's complete did.jsonl — one log entry per line — not a delta.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "The slot's complete did.jsonl — one log entry per line — not a delta.",
/// "type": "string",
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct SyncUpdateLogContent(::std::string::String);
impl ::std::ops::Deref for SyncUpdateLogContent {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<SyncUpdateLogContent> for ::std::string::String {
fn from(value: SyncUpdateLogContent) -> Self {
value.0
}
}
impl ::std::str::FromStr for SyncUpdateLogContent {
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 SyncUpdateLogContent {
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 SyncUpdateLogContent {
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 SyncUpdateLogContent {
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 SyncUpdateLogContent {
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 slot path on its hosting domain (e.g. `alice`, `people/alice`, or `.well-known` for a root DID).
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "The slot path on its hosting domain (e.g. `alice`, `people/alice`, or `.well-known` for a root DID).",
/// "type": "string",
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct SyncUpdateMnemonic(::std::string::String);
impl ::std::ops::Deref for SyncUpdateMnemonic {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<SyncUpdateMnemonic> for ::std::string::String {
fn from(value: SyncUpdateMnemonic) -> Self {
value.0
}
}
impl ::std::str::FromStr for SyncUpdateMnemonic {
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 SyncUpdateMnemonic {
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 SyncUpdateMnemonic {
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 SyncUpdateMnemonic {
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 SyncUpdateMnemonic {
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 slot's did-witness.json. ABSENT means the slot holds no witness proofs: the replica MUST drop any witness proofs it holds for the slot. Absence never means "unchanged".
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "The slot's did-witness.json. ABSENT means the slot holds no witness proofs: the replica MUST drop any witness proofs it holds for the slot. Absence never means \"unchanged\".",
/// "type": "string",
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct SyncUpdateWitnessContent(::std::string::String);
impl ::std::ops::Deref for SyncUpdateWitnessContent {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<SyncUpdateWitnessContent> for ::std::string::String {
fn from(value: SyncUpdateWitnessContent) -> Self {
value.0
}
}
impl ::std::str::FromStr for SyncUpdateWitnessContent {
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 SyncUpdateWitnessContent {
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 SyncUpdateWitnessContent {
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 SyncUpdateWitnessContent {
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 SyncUpdateWitnessContent {
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 EntryResult {
code: ::std::result::Result<
::std::option::Option<super::EntryResultCode>,
::std::string::String,
>,
mnemonic: ::std::result::Result<super::EntryResultMnemonic, ::std::string::String>,
status: ::std::result::Result<super::EntryResultStatus, ::std::string::String>,
}
impl ::std::default::Default for EntryResult {
fn default() -> Self {
Self {
code: Ok(Default::default()),
mnemonic: Err("no value supplied for mnemonic".to_string()),
status: Err("no value supplied for status".to_string()),
}
}
}
impl EntryResult {
pub fn code<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::EntryResultCode>>,
T::Error: ::std::fmt::Display,
{
self.code = value
.try_into()
.map_err(|e| format!("error converting supplied value for code: {e}"));
self
}
pub fn mnemonic<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::EntryResultMnemonic>,
T::Error: ::std::fmt::Display,
{
self.mnemonic = value
.try_into()
.map_err(|e| format!("error converting supplied value for mnemonic: {e}"));
self
}
pub fn status<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::EntryResultStatus>,
T::Error: ::std::fmt::Display,
{
self.status = value
.try_into()
.map_err(|e| format!("error converting supplied value for status: {e}"));
self
}
}
impl ::std::convert::TryFrom<EntryResult> for super::EntryResult {
type Error = super::error::ConversionError;
fn try_from(
value: EntryResult,
) -> ::std::result::Result<Self, super::error::ConversionError> {
Ok(Self {
code: value.code?,
mnemonic: value.mnemonic?,
status: value.status?,
})
}
}
impl ::std::convert::From<super::EntryResult> for EntryResult {
fn from(value: super::EntryResult) -> Self {
Self {
code: Ok(value.code),
mnemonic: Ok(value.mnemonic),
status: Ok(value.status),
}
}
}
#[derive(Clone, Debug)]
pub struct Payload {
ext: ::std::result::Result<::std::option::Option<super::Ext>, ::std::string::String>,
updates: ::std::result::Result<::std::vec::Vec<super::SyncUpdate>, ::std::string::String>,
}
impl ::std::default::Default for Payload {
fn default() -> Self {
Self {
ext: Ok(Default::default()),
updates: Err("no value supplied for updates".to_string()),
}
}
}
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 updates<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::vec::Vec<super::SyncUpdate>>,
T::Error: ::std::fmt::Display,
{
self.updates = value
.try_into()
.map_err(|e| format!("error converting supplied value for updates: {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?,
updates: value.updates?,
})
}
}
impl ::std::convert::From<super::Payload> for Payload {
fn from(value: super::Payload) -> Self {
Self {
ext: Ok(value.ext),
updates: Ok(value.updates),
}
}
}
#[derive(Clone, Debug)]
pub struct Response {
ext: ::std::result::Result<::std::option::Option<super::Ext>, ::std::string::String>,
results: ::std::result::Result<::std::vec::Vec<super::EntryResult>, ::std::string::String>,
}
impl ::std::default::Default for Response {
fn default() -> Self {
Self {
ext: Ok(Default::default()),
results: Err("no value supplied for results".to_string()),
}
}
}
impl Response {
pub fn ext<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::Ext>>,
T::Error: ::std::fmt::Display,
{
self.ext = value
.try_into()
.map_err(|e| format!("error converting supplied value for ext: {e}"));
self
}
pub fn results<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::vec::Vec<super::EntryResult>>,
T::Error: ::std::fmt::Display,
{
self.results = value
.try_into()
.map_err(|e| format!("error converting supplied value for results: {e}"));
self
}
}
impl ::std::convert::TryFrom<Response> for super::Response {
type Error = super::error::ConversionError;
fn try_from(value: Response) -> ::std::result::Result<Self, super::error::ConversionError> {
Ok(Self {
ext: value.ext?,
results: value.results?,
})
}
}
impl ::std::convert::From<super::Response> for Response {
fn from(value: super::Response) -> Self {
Self {
ext: Ok(value.ext),
results: Ok(value.results),
}
}
}
#[derive(Clone, Debug)]
pub struct SyncUpdate {
did_id: ::std::result::Result<super::SyncUpdateDidId, ::std::string::String>,
disabled: ::std::result::Result<bool, ::std::string::String>,
ext: ::std::result::Result<::std::option::Option<super::Ext>, ::std::string::String>,
log_content: ::std::result::Result<super::SyncUpdateLogContent, ::std::string::String>,
mnemonic: ::std::result::Result<super::SyncUpdateMnemonic, ::std::string::String>,
version_count: ::std::result::Result<::std::num::NonZeroU64, ::std::string::String>,
witness_content: ::std::result::Result<
::std::option::Option<super::SyncUpdateWitnessContent>,
::std::string::String,
>,
}
impl ::std::default::Default for SyncUpdate {
fn default() -> Self {
Self {
did_id: Err("no value supplied for did_id".to_string()),
disabled: Err("no value supplied for disabled".to_string()),
ext: Ok(Default::default()),
log_content: Err("no value supplied for log_content".to_string()),
mnemonic: Err("no value supplied for mnemonic".to_string()),
version_count: Err("no value supplied for version_count".to_string()),
witness_content: Ok(Default::default()),
}
}
}
impl SyncUpdate {
pub fn did_id<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::SyncUpdateDidId>,
T::Error: ::std::fmt::Display,
{
self.did_id = value
.try_into()
.map_err(|e| format!("error converting supplied value for did_id: {e}"));
self
}
pub fn disabled<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<bool>,
T::Error: ::std::fmt::Display,
{
self.disabled = value
.try_into()
.map_err(|e| format!("error converting supplied value for disabled: {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 log_content<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::SyncUpdateLogContent>,
T::Error: ::std::fmt::Display,
{
self.log_content = value
.try_into()
.map_err(|e| format!("error converting supplied value for log_content: {e}"));
self
}
pub fn mnemonic<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::SyncUpdateMnemonic>,
T::Error: ::std::fmt::Display,
{
self.mnemonic = value
.try_into()
.map_err(|e| format!("error converting supplied value for mnemonic: {e}"));
self
}
pub fn version_count<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::num::NonZeroU64>,
T::Error: ::std::fmt::Display,
{
self.version_count = value
.try_into()
.map_err(|e| format!("error converting supplied value for version_count: {e}"));
self
}
pub fn witness_content<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::SyncUpdateWitnessContent>>,
T::Error: ::std::fmt::Display,
{
self.witness_content = value
.try_into()
.map_err(|e| format!("error converting supplied value for witness_content: {e}"));
self
}
}
impl ::std::convert::TryFrom<SyncUpdate> for super::SyncUpdate {
type Error = super::error::ConversionError;
fn try_from(
value: SyncUpdate,
) -> ::std::result::Result<Self, super::error::ConversionError> {
Ok(Self {
did_id: value.did_id?,
disabled: value.disabled?,
ext: value.ext?,
log_content: value.log_content?,
mnemonic: value.mnemonic?,
version_count: value.version_count?,
witness_content: value.witness_content?,
})
}
}
impl ::std::convert::From<super::SyncUpdate> for SyncUpdate {
fn from(value: super::SyncUpdate) -> Self {
Self {
did_id: Ok(value.did_id),
disabled: Ok(value.disabled),
ext: Ok(value.ext),
log_content: Ok(value.log_content),
mnemonic: Ok(value.mnemonic),
version_count: Ok(value.version_count),
witness_content: Ok(value.witness_content),
}
}
}
}
impl crate::Payload for Payload {
const TYPE_URI: &'static str = "https://trusttasks.org/spec/webvh/sync/batch/0.1";
const IS_PROOF_REQUIRED: bool = true;
const IS_ISSUED_AT_REQUIRED: bool = true;
const IS_RECIPIENT_REQUIRED: bool = true;
const PAYLOAD_SCHEMA: Option<&'static str> = Some(
"{\n \"$defs\": {\n \"EntryResult\": {\n \"additionalProperties\": false,\n \"properties\": {\n \"code\": {\n \"description\": \"Present if and only if `status` is `refused`: the webvh/sync/update/0.2 error code the entry would have received on its own (e.g. `webvh/sync/update:historyRewrite`).\",\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"mnemonic\": {\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"status\": {\n \"description\": \"`applied` and `unchanged` as in webvh/sync/update/0.2. `refused` — the entry was permanently refused; see `code`.\",\n \"enum\": [\n \"applied\",\n \"unchanged\",\n \"refused\"\n ],\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"mnemonic\",\n \"status\"\n ],\n \"title\": \"EntryResult\",\n \"type\": \"object\"\n },\n \"Ext\": {\n \"additionalProperties\": true,\n \"description\": \"Vendor-namespaced extension object per SPEC.md §4.5.1. Each immediate key MUST be a reverse-DNS namespace; structure under each namespace is opaque to the framework.\",\n \"minProperties\": 1,\n \"propertyNames\": {\n \"pattern\": \"^[a-z][a-z0-9-]*(\\\\.[a-z0-9-]+)+$\"\n },\n \"title\": \"Ext\",\n \"type\": \"object\"\n },\n \"Response\": {\n \"$anchor\": \"response\",\n \"additionalProperties\": false,\n \"properties\": {\n \"ext\": {\n \"$ref\": \"#/$defs/Ext\"\n },\n \"results\": {\n \"description\": \"One result per entry of `updates`, in request order.\",\n \"items\": {\n \"$ref\": \"#/$defs/EntryResult\"\n },\n \"type\": \"array\"\n }\n },\n \"required\": [\n \"results\"\n ],\n \"title\": \"WebVH Sync Batch — response payload\",\n \"type\": \"object\"\n },\n \"SyncUpdate\": {\n \"additionalProperties\": false,\n \"properties\": {\n \"didId\": {\n \"description\": \"The DID the log establishes. A replica MUST refuse a log that does not establish exactly this DID.\",\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"disabled\": {\n \"description\": \"Whether the source has disabled the slot. A replica MUST stop serving a disabled slot and MUST resume only on an update carrying `false`.\",\n \"type\": \"boolean\"\n },\n \"ext\": {\n \"$ref\": \"#/$defs/Ext\"\n },\n \"logContent\": {\n \"description\": \"The slot's complete did.jsonl — one log entry per line — not a delta.\",\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"mnemonic\": {\n \"description\": \"The slot path on its hosting domain (e.g. `alice`, `people/alice`, or `.well-known` for a root DID).\",\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"versionCount\": {\n \"description\": \"Number of entries in `logContent`, as the source counts them. A replica MUST refuse an update whose `logContent` does not contain exactly this many entries.\",\n \"minimum\": 1,\n \"type\": \"integer\"\n },\n \"witnessContent\": {\n \"description\": \"The slot's did-witness.json. ABSENT means the slot holds no witness proofs: the replica MUST drop any witness proofs it holds for the slot. Absence never means \\\"unchanged\\\".\",\n \"minLength\": 1,\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"mnemonic\",\n \"didId\",\n \"logContent\",\n \"versionCount\",\n \"disabled\"\n ],\n \"title\": \"SyncUpdate\",\n \"type\": \"object\"\n }\n },\n \"$id\": \"https://trusttasks.org/spec/webvh/sync/batch/0.1\",\n \"$schema\": \"https://json-schema.org/draft/2020-12/schema\",\n \"additionalProperties\": false,\n \"properties\": {\n \"ext\": {\n \"$ref\": \"#/$defs/Ext\"\n },\n \"updates\": {\n \"description\": \"Complete slot states, each applied exactly as a webvh/sync/update/0.2 carrying it would be. A mnemonic appears at most once.\",\n \"items\": {\n \"$ref\": \"#/$defs/SyncUpdate\"\n },\n \"maxItems\": 50,\n \"minItems\": 1,\n \"type\": \"array\"\n }\n },\n \"required\": [\n \"updates\"\n ],\n \"title\": \"WebVH Sync Batch — payload\",\n \"type\": \"object\"\n}\n",
);
}
impl crate::Payload for Response {
const TYPE_URI: &'static str = "https://trusttasks.org/spec/webvh/sync/batch/0.1#response";
const IS_PROOF_REQUIRED: bool = true;
const IS_ISSUED_AT_REQUIRED: bool = true;
const IS_RECIPIENT_REQUIRED: bool = true;
const PAYLOAD_SCHEMA: Option<&'static str> = Some(
"{\n \"$defs\": {\n \"EntryResult\": {\n \"additionalProperties\": false,\n \"properties\": {\n \"code\": {\n \"description\": \"Present if and only if `status` is `refused`: the webvh/sync/update/0.2 error code the entry would have received on its own (e.g. `webvh/sync/update:historyRewrite`).\",\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"mnemonic\": {\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"status\": {\n \"description\": \"`applied` and `unchanged` as in webvh/sync/update/0.2. `refused` — the entry was permanently refused; see `code`.\",\n \"enum\": [\n \"applied\",\n \"unchanged\",\n \"refused\"\n ],\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"mnemonic\",\n \"status\"\n ],\n \"title\": \"EntryResult\",\n \"type\": \"object\"\n },\n \"Ext\": {\n \"additionalProperties\": true,\n \"description\": \"Vendor-namespaced extension object per SPEC.md §4.5.1. Each immediate key MUST be a reverse-DNS namespace; structure under each namespace is opaque to the framework.\",\n \"minProperties\": 1,\n \"propertyNames\": {\n \"pattern\": \"^[a-z][a-z0-9-]*(\\\\.[a-z0-9-]+)+$\"\n },\n \"title\": \"Ext\",\n \"type\": \"object\"\n },\n \"Response\": {\n \"$anchor\": \"response\",\n \"additionalProperties\": false,\n \"properties\": {\n \"ext\": {\n \"$ref\": \"#/$defs/Ext\"\n },\n \"results\": {\n \"description\": \"One result per entry of `updates`, in request order.\",\n \"items\": {\n \"$ref\": \"#/$defs/EntryResult\"\n },\n \"type\": \"array\"\n }\n },\n \"required\": [\n \"results\"\n ],\n \"title\": \"WebVH Sync Batch — response payload\",\n \"type\": \"object\"\n },\n \"SyncUpdate\": {\n \"additionalProperties\": false,\n \"properties\": {\n \"didId\": {\n \"description\": \"The DID the log establishes. A replica MUST refuse a log that does not establish exactly this DID.\",\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"disabled\": {\n \"description\": \"Whether the source has disabled the slot. A replica MUST stop serving a disabled slot and MUST resume only on an update carrying `false`.\",\n \"type\": \"boolean\"\n },\n \"ext\": {\n \"$ref\": \"#/$defs/Ext\"\n },\n \"logContent\": {\n \"description\": \"The slot's complete did.jsonl — one log entry per line — not a delta.\",\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"mnemonic\": {\n \"description\": \"The slot path on its hosting domain (e.g. `alice`, `people/alice`, or `.well-known` for a root DID).\",\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"versionCount\": {\n \"description\": \"Number of entries in `logContent`, as the source counts them. A replica MUST refuse an update whose `logContent` does not contain exactly this many entries.\",\n \"minimum\": 1,\n \"type\": \"integer\"\n },\n \"witnessContent\": {\n \"description\": \"The slot's did-witness.json. ABSENT means the slot holds no witness proofs: the replica MUST drop any witness proofs it holds for the slot. Absence never means \\\"unchanged\\\".\",\n \"minLength\": 1,\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"mnemonic\",\n \"didId\",\n \"logContent\",\n \"versionCount\",\n \"disabled\"\n ],\n \"title\": \"SyncUpdate\",\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::NOT_AUTHORIZED];
/// 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 {
/// `webvh/sync/batch:notAuthorized`
///
/// The document's proven issuer is not a configured source of this replica. The whole batch is refused.
///
/// Declared `retryable: false`.
pub const NOT_AUTHORIZED: crate::DeclaredErrorCode = crate::DeclaredErrorCode {
code: "webvh/sync/batch:notAuthorized",
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:c4b2a190-7e3d-4a1f-8c2b-6d5e4f3a2b01\",\n \"type\": \"https://trusttasks.org/spec/webvh/sync/batch/0.1\",\n \"issuer\": \"did:webvh:QmControlScid2:control.example.com\",\n \"recipient\": \"did:webvh:QmNodeScid3:node1.example.com\",\n \"issuedAt\": \"2026-09-27T09:20:00Z\",\n \"payload\": {\n \"updates\": [\n {\n \"mnemonic\": \"alice\",\n \"didId\": \"did:webvh:QmAliceScid4:did.example.com:alice\",\n \"logContent\": \"{\\\"versionId\\\":\\\"1-QmA\\\",\\\"versionTime\\\":\\\"2026-09-01T10:00:00Z\\\"}\",\n \"versionCount\": 1,\n \"disabled\": false\n },\n {\n \"mnemonic\": \"bob\",\n \"didId\": \"did:webvh:QmBobScid5:did.example.com:bob\",\n \"logContent\": \"{\\\"versionId\\\":\\\"1-QmC\\\",\\\"versionTime\\\":\\\"2026-09-02T10:00:00Z\\\"}\",\n \"versionCount\": 1,\n \"disabled\": true\n }\n ]\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:c4b2a190-7e3d-4a1f-8c2b-6d5e4f3a2b02\",\n \"type\": \"https://trusttasks.org/spec/webvh/sync/batch/0.1#response\",\n \"threadId\": \"urn:uuid:c4b2a190-7e3d-4a1f-8c2b-6d5e4f3a2b01\",\n \"issuer\": \"did:webvh:QmNodeScid3:node1.example.com\",\n \"recipient\": \"did:webvh:QmControlScid2:control.example.com\",\n \"issuedAt\": \"2026-09-27T09:20:02Z\",\n \"payload\": {\n \"results\": [\n { \"mnemonic\": \"alice\", \"status\": \"unchanged\" },\n { \"mnemonic\": \"bob\", \"status\": \"refused\", \"code\": \"webvh/sync/update:historyRewrite\" }\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)] = &[
("Missing updates.", "{}"),
(
"Empty updates — a batch carries at least one entry.",
"{\n \"updates\": []\n}",
),
(
"Entry missing disabled.",
"{\n \"updates\": [\n {\n \"didId\": \"did:webvh:QmA:did.example.com:alice\",\n \"logContent\": \"{}\",\n \"mnemonic\": \"alice\",\n \"versionCount\": 1\n }\n ]\n}",
),
(
"Entry uses 0.1's snake_case members.",
"{\n \"updates\": [\n {\n \"did_id\": \"did:webvh:QmA:did.example.com:alice\",\n \"disabled\": false,\n \"log_content\": \"{}\",\n \"mnemonic\": \"alice\",\n \"version_count\": 1\n }\n ]\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
);
}
}
}