jmap_types/backend.rs
1//! Backend marker traits shared across all JMAP server crates.
2//!
3//! These traits are defined here in `jmap-types` so that implementations can
4//! go in the type crates (`jmap-mail-types`, `jmap-chat-types`) without
5//! violating the orphan rule.
6
7// ---------------------------------------------------------------------------
8// Marker traits
9// ---------------------------------------------------------------------------
10
11/// Marker trait for all JMAP object types.
12///
13/// Implement this in the *types* crate for each first-class JMAP object (e.g.
14/// `Mailbox`, `Email`, `Chat`). The [`TYPE_NAME`](JmapObject::TYPE_NAME) constant
15/// is used in error messages and capability checks in the server crates.
16pub trait JmapObject:
17 serde::Serialize + for<'de> serde::Deserialize<'de> + Send + Sync + 'static
18{
19 /// The JMAP type name string (e.g. `"Email"`, `"Mailbox"`, `"Chat"`).
20 const TYPE_NAME: &'static str;
21 /// The property selector enum for this type (server-side only, no serde).
22 type Property: Send + Sync + 'static;
23}
24
25/// Marker for object types that support `get` and `changes` operations.
26pub trait GetObject: JmapObject {}
27
28/// Marker for object types that support `set` (create/update/destroy) operations.
29pub trait SetObject: JmapObject {
30 /// The patch type for update operations.
31 ///
32 /// Typically [`serde_json::Value`] for open-ended JSON Merge Patch, or a
33 /// typed struct if the backend wants structured patching.
34 type Patch: serde::Serialize + serde::de::DeserializeOwned + Send + Sync + 'static;
35}
36
37/// Marker for object types that support `query` and `queryChanges` operations.
38pub trait QueryObject: JmapObject {
39 /// The filter condition type.
40 ///
41 /// Must implement both `Serialize` and `DeserializeOwned` so that backends
42 /// can inspect or forward the filter.
43 type Filter: serde::Serialize + serde::de::DeserializeOwned + Send + Sync + 'static;
44 /// The comparator type for sort operations.
45 type Comparator: serde::Serialize + serde::de::DeserializeOwned + Send + Sync + 'static;
46}