Skip to main content

jmap_metadata_types/
capability.rs

1//! draft-ietf-jmap-metadata-04 §1.2.1 — capability registration and
2//! per-data-type metadata info.
3//!
4//! Provides [`DataTypeMetadataInfo`] 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-04 §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
14/// (value: an object with a `dataTypes` field mapping type names to
15/// [`DataTypeMetadataInfo`]).
16///
17/// The URI is unchanged from -01 through -04.
18pub const JMAP_METADATA_URI: &str = "urn:ietf:params:jmap:metadata";
19
20/// Per-data-type metadata capability advertisement
21/// (draft-ietf-jmap-metadata-04 §1.2.1).
22///
23/// Appears as the value in the `dataTypes` map within the account-level
24/// `urn:ietf:params:jmap:metadata` capability object. A type that does not
25/// appear in `dataTypes` does not gain the `metadata` or `privateMetadata`
26/// properties in that account.
27///
28/// # Wire example (from §6.1)
29///
30/// ```json
31/// {
32///   "namespaces": ["photography"],
33///   "supportsVendorNamespaces": false,
34///   "supportsPrivate": false,
35///   "maxDepth": 3
36/// }
37/// ```
38#[non_exhaustive]
39#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
40#[serde(rename_all = "camelCase")]
41pub struct DataTypeMetadataInfo {
42    /// IANA-registered metadata namespace names supported on this data type
43    /// (§1.2.1). Each value is a registered name (lowercase US-ASCII letters,
44    /// digits, hyphens, underscores — no dot). Vendor domain-name namespaces MUST
45    /// NOT appear in this list; their support is signalled by
46    /// [`supports_vendor_namespaces`](Self::supports_vendor_namespaces).
47    #[serde(default)]
48    pub namespaces: Vec<String>,
49
50    /// Whether the server accepts vendor (domain-name) namespaces on this
51    /// data type (§1.2.1). Default `false`.
52    #[serde(default)]
53    pub supports_vendor_namespaces: bool,
54
55    /// Whether this account supports per-user `privateMetadata` on this
56    /// data type (§1.2.1). Default `false`.
57    ///
58    /// When `false`, the `privateMetadata` property MUST be absent from
59    /// response objects of this type, all `privateMetadata*` filter
60    /// conditions MUST be rejected with `unsupportedFilter`, and any `/set`
61    /// targeting `privateMetadata` MUST be rejected with
62    /// `invalidProperties`.
63    #[serde(default)]
64    pub supports_private: bool,
65
66    /// Maximum depth of a namespace value (§1.2.1, §2.1). `null` means
67    /// no server-enforced limit; otherwise draft-ietf-jmap-metadata-04
68    /// §1.2.1 says "the value MUST be at least 1."
69    ///
70    /// Per -04 §2.1, a scalar has depth 0, an array has the maximum depth
71    /// of its elements (0 if empty), and an object has depth 1 plus the
72    /// maximum depth of its member values (1 if empty). So depth 1 allows
73    /// a flat namespace object and depth 2 one level of nested objects.
74    pub max_depth: Option<u64>,
75}