Skip to main content

CrdtAdapter

Trait CrdtAdapter 

Source
pub trait CrdtAdapter:
    Debug
    + Send
    + Sync {
    // Required methods
    fn get_updates<'life0, 'life1, 'async_trait>(
        &'life0 self,
        tn_id: TnId,
        doc_id: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = ClResult<Vec<CrdtUpdate>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn store_update<'life0, 'life1, 'async_trait>(
        &'life0 self,
        tn_id: TnId,
        doc_id: &'life1 str,
        update: CrdtUpdate,
    ) -> Pin<Box<dyn Future<Output = ClResult<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn subscribe<'life0, 'async_trait>(
        &'life0 self,
        tn_id: TnId,
        opts: CrdtSubscriptionOptions,
    ) -> Pin<Box<dyn Future<Output = ClResult<Pin<Box<dyn Stream<Item = CrdtChangeEvent> + Send>>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn delete_doc<'life0, 'life1, 'async_trait>(
        &'life0 self,
        tn_id: TnId,
        doc_id: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = ClResult<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn list_docs<'life0, 'async_trait>(
        &'life0 self,
        tn_id: TnId,
    ) -> Pin<Box<dyn Future<Output = ClResult<Vec<Box<str>>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided methods
    fn stats<'life0, 'life1, 'async_trait>(
        &'life0 self,
        tn_id: TnId,
        doc_id: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = ClResult<CrdtDocStats>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn close_doc<'life0, 'life1, 'async_trait>(
        &'life0 self,
        _tn_id: TnId,
        _doc_id: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = ClResult<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
}
Expand description

CRDT Adapter trait.

Unified interface for CRDT document backends. Handles persistence of binary updates and real-time subscriptions.

§Multi-Tenancy

All operations are tenant-aware (tn_id parameter). Adapters must ensure:

  • Updates from different tenants are stored separately
  • Subscriptions only receive updates for the subscribing tenant

Required Methods§

Source

fn get_updates<'life0, 'life1, 'async_trait>( &'life0 self, tn_id: TnId, doc_id: &'life1 str, ) -> Pin<Box<dyn Future<Output = ClResult<Vec<CrdtUpdate>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get all stored updates for a document.

Returns updates in the order they were stored. These can be applied to a fresh Y.Doc to reconstruct the current state.

Returns empty vec if document doesn’t exist (safe to treat as new doc).

Source

fn store_update<'life0, 'life1, 'async_trait>( &'life0 self, tn_id: TnId, doc_id: &'life1 str, update: CrdtUpdate, ) -> Pin<Box<dyn Future<Output = ClResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Store a new update for a document.

The update is persisted immediately. For high-frequency updates, implementations may batch or compress updates.

If the document doesn’t exist, it’s implicitly created.

Source

fn subscribe<'life0, 'async_trait>( &'life0 self, tn_id: TnId, opts: CrdtSubscriptionOptions, ) -> Pin<Box<dyn Future<Output = ClResult<Pin<Box<dyn Stream<Item = CrdtChangeEvent> + Send>>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Subscribe to updates for a document.

Returns a stream of updates. Depending on subscription options, may include a snapshot of existing updates followed by new updates.

Source

fn delete_doc<'life0, 'life1, 'async_trait>( &'life0 self, tn_id: TnId, doc_id: &'life1 str, ) -> Pin<Box<dyn Future<Output = ClResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Delete a document and all its updates.

This removes all stored data for the document. Use with caution.

Source

fn list_docs<'life0, 'async_trait>( &'life0 self, tn_id: TnId, ) -> Pin<Box<dyn Future<Output = ClResult<Vec<Box<str>>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

List all document IDs for a tenant.

Useful for administrative tasks and migrations.

Provided Methods§

Source

fn stats<'life0, 'life1, 'async_trait>( &'life0 self, tn_id: TnId, doc_id: &'life1 str, ) -> Pin<Box<dyn Future<Output = ClResult<CrdtDocStats>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get statistics for a document.

Source

fn close_doc<'life0, 'life1, 'async_trait>( &'life0 self, _tn_id: TnId, _doc_id: &'life1 str, ) -> Pin<Box<dyn Future<Output = ClResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Close/flush a document instance, ensuring all updates are persisted.

Some implementations may keep documents in-memory and need explicit flush before shutdown. Others may be no-op.

Implementors§