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 compact_updates<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
tn_id: TnId,
doc_id: &'life1 str,
remove_seqs: &'life2 [u64],
replacement: CrdtUpdate,
) -> Pin<Box<dyn Future<Output = ClResult<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: '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;
fn delete_tenant_documents<'life0, 'async_trait>(
&'life0 self,
tn_id: TnId,
) -> Pin<Box<dyn Future<Output = ClResult<()>> + 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§
Sourcefn 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 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).
Sourcefn 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 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.
Sourcefn 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 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.
Sourcefn compact_updates<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
tn_id: TnId,
doc_id: &'life1 str,
remove_seqs: &'life2 [u64],
replacement: CrdtUpdate,
) -> Pin<Box<dyn Future<Output = ClResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn compact_updates<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
tn_id: TnId,
doc_id: &'life1 str,
remove_seqs: &'life2 [u64],
replacement: CrdtUpdate,
) -> Pin<Box<dyn Future<Output = ClResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Atomically replace specific updates with a single compacted update.
Deletes the updates identified by remove_seqs and inserts the
replacement update, all in a single transaction. Updates not listed
in remove_seqs (e.g., ones that failed to decode) are preserved.
Non-existent seqs in remove_seqs are silently ignored.
Important: This method does not broadcast a change event. It should only be called when no active subscribers exist (e.g., after the last connection to the document has closed).
Sourcefn 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 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.
Sourcefn 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,
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.
Sourcefn delete_tenant_documents<'life0, 'async_trait>(
&'life0 self,
tn_id: TnId,
) -> Pin<Box<dyn Future<Output = ClResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn delete_tenant_documents<'life0, 'async_trait>(
&'life0 self,
tn_id: TnId,
) -> Pin<Box<dyn Future<Output = ClResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Delete every CRDT document owned by the tenant.
Used by tenant purge orchestration. Implementations should treat a missing tenant store as success.
Provided Methods§
Sourcefn 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 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.
Sourcefn 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,
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.