jmap_metadata_types/capability.rs
1//! draft-ietf-jmap-metadata-01 §1.2.1 — capability registration and
2//! account-level capability object.
3//!
4//! Provides [`MetadataCapability`] and the capability URI constant
5//! [`JMAP_METADATA_URI`].
6
7use serde::{Deserialize, Serialize};
8
9/// The JMAP capability URI for the Metadata extension
10/// (draft-ietf-jmap-metadata-01 §1.2.1).
11///
12/// Present as a key in both the session-level `capabilities` object (value:
13/// empty object) and in each account's `accountCapabilities` object (value:
14/// a [`MetadataCapability`]).
15pub const JMAP_METADATA_URI: &str = "urn:ietf:params:jmap:metadata";
16
17/// Account-level capability for the JMAP Metadata extension
18/// (draft-ietf-jmap-metadata-01 §1.2.1).
19///
20/// The value of the `urn:ietf:params:jmap:metadata` key in
21/// `accountCapabilities`.
22///
23/// ## Nullable fields
24///
25/// Fields typed `Option<T>` with no `skip_serializing_if` are
26/// **required-and-nullable**: they MUST appear in the wire JSON even when
27/// the value is `null`. For [`data_types`](Self::data_types) and
28/// [`max_depth`](Self::max_depth) a `null` wire value carries spec-defined
29/// semantics ("all data types" / "no nesting limit"), so the `null` cannot
30/// be elided.
31///
32/// ## `maySetPrivate` default
33///
34/// Per §1.2.1 the default is `true`. This crate represents the field as
35/// `Option<bool>` so callers can distinguish an explicit `false` from
36/// "absent" if needed; deserialising a JSON document without the key
37/// leaves the field as `None`. A `None` value is wire-equivalent to the
38/// spec default of `true`.
39#[non_exhaustive]
40#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
41#[serde(rename_all = "camelCase")]
42pub struct MetadataCapability {
43 /// List of JMAP data types for which the server supports metadata
44 /// operations. A `null` wire value means all data types are
45 /// supported (§1.2.1).
46 ///
47 /// Always serialised (as `null` when `None`).
48 pub data_types: Option<Vec<String>>,
49
50 /// List of metadata type identifiers (`@type` values) for which the
51 /// server supports metadata operations (§1.2.1). Only listed
52 /// metadata types can be created or retrieved.
53 pub metadata_types: Vec<String>,
54
55 /// Maximum depth of nested vendor-specific metadata properties that
56 /// can be set or retrieved (§1.2.1). A depth of `1` indicates only
57 /// flat properties; `2` allows one level of nesting, and so forth.
58 /// A `null` wire value means no server-enforced limit.
59 ///
60 /// Always serialised (as `null` when `None`).
61 pub max_depth: Option<u64>,
62
63 /// Whether the authenticated user has permission to create private
64 /// Metadata objects (`isPrivate: true`) in this account (§1.2.1).
65 /// Default `true` when absent on the wire.
66 ///
67 /// If `false`, the server MUST reject creation of private metadata
68 /// with a `forbidden` SetError.
69 #[serde(skip_serializing_if = "Option::is_none")]
70 pub may_set_private: Option<bool>,
71}