Skip to main content

JmapBackend

Trait JmapBackend 

Source
pub trait JmapBackend:
    Send
    + Sync
    + 'static {
    type Error: Error + Send + Sync + 'static;

    // Required methods
    fn get_objects<O: GetObject + Send + Sync>(
        &self,
        account_id: &Id,
        ids: Option<&[Id]>,
        properties: Option<&[String]>,
    ) -> impl Future<Output = Result<(Vec<O>, Vec<Id>), Self::Error>> + Send;
    fn get_state<O: JmapObject + Send + Sync>(
        &self,
        account_id: &Id,
    ) -> impl Future<Output = Result<State, Self::Error>> + Send;
    fn get_changes<O: JmapObject + Send + Sync>(
        &self,
        account_id: &Id,
        since_state: &State,
        max_changes: Option<u64>,
    ) -> impl Future<Output = Result<ChangesResult, BackendChangesError<Self::Error>>> + Send;
    fn query_objects<O: QueryObject + Send + Sync>(
        &self,
        account_id: &Id,
        filter: Option<&O::Filter>,
        sort: Option<&[O::Comparator]>,
        limit: Option<u64>,
        position: i64,
    ) -> impl Future<Output = Result<QueryResult, Self::Error>> + Send;
    fn query_changes<O: QueryObject + Send + Sync>(
        &self,
        account_id: &Id,
        since_query_state: &State,
        filter: Option<&O::Filter>,
        sort: Option<&[O::Comparator]>,
        max_changes: Option<u64>,
        up_to_id: Option<&Id>,
        collapse_threads: bool,
    ) -> impl Future<Output = Result<QueryChangesResult, BackendChangesError<Self::Error>>> + Send;
}
Expand description

Read-side backend supertrait shared by all JMAP server crates.

Domain-specific backend traits (MailBackend, ChatBackend, etc.) require this trait as a supertrait and add write-side methods on top.

Only the read operations that have an identical signature across all JMAP object types belong here. Write operations (create_object, update_object, destroy_object) and domain-specific operations remain in the domain crate.

The collapse_threads parameter on query_changes is included for Email/queryChanges (RFC 8621 §4.5). Non-mail backends should pass false and may ignore the parameter.

This trait is not object-safe by design (generic methods). Use Arc<impl JmapBackend> when sharing across tasks.

Required Associated Types§

Source

type Error: Error + Send + Sync + 'static

The error type returned by storage operations.

Required Methods§

Source

fn get_objects<O: GetObject + Send + Sync>( &self, account_id: &Id, ids: Option<&[Id]>, properties: Option<&[String]>, ) -> impl Future<Output = Result<(Vec<O>, Vec<Id>), Self::Error>> + Send

Fetch objects by id (or all objects when ids is None).

properties is the list of property names requested by the client (RFC 8620 §5.1). None means the client did not send a properties field; the backend should return all properties. When Some, the backend MAY filter the response to only the named properties, but is not required to — implementations that always return all properties are correct.

Returns (found, not_found) — objects that exist and ids that do not.

Source

fn get_state<O: JmapObject + Send + Sync>( &self, account_id: &Id, ) -> impl Future<Output = Result<State, Self::Error>> + Send

Return the current state token for an object type in the given account.

Source

fn get_changes<O: JmapObject + Send + Sync>( &self, account_id: &Id, since_state: &State, max_changes: Option<u64>, ) -> impl Future<Output = Result<ChangesResult, BackendChangesError<Self::Error>>> + Send

Return changes since since_state, up to max_changes entries.

Source

fn query_objects<O: QueryObject + Send + Sync>( &self, account_id: &Id, filter: Option<&O::Filter>, sort: Option<&[O::Comparator]>, limit: Option<u64>, position: i64, ) -> impl Future<Output = Result<QueryResult, Self::Error>> + Send

Execute a /query and return a page of matching ids.

position may be negative — negative values are relative to the end of the result set per RFC 8620 §5.5 (e.g. -1 means the last result).

Source

fn query_changes<O: QueryObject + Send + Sync>( &self, account_id: &Id, since_query_state: &State, filter: Option<&O::Filter>, sort: Option<&[O::Comparator]>, max_changes: Option<u64>, up_to_id: Option<&Id>, collapse_threads: bool, ) -> impl Future<Output = Result<QueryChangesResult, BackendChangesError<Self::Error>>> + Send

Execute a /queryChanges and return deltas since since_query_state.

collapse_threads is only meaningful for Email/queryChanges (RFC 8621 §4.5). Pass false for all other object types.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§