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

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>( &self, account_id: &Id, ) -> impl Future<Output = Result<State, Self::Error>> + Send
where O: JmapObject + Send + Sync,

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

Source

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

Return changes since since_state, up to max_changes entries.

Source

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

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

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§