pub struct DocReplicator { /* private fields */ }Expand description
Document Replicator - manages CRDT documents with dual storage
Implementations§
Source§impl DocReplicator
impl DocReplicator
Sourcepub async fn new(config: DocReplicatorConfig) -> Result<Self>
pub async fn new(config: DocReplicatorConfig) -> Result<Self>
Create new DocReplicator
Sourcepub async fn create_document(
&self,
name: &str,
storage_mode: StorageMode,
) -> Result<DocumentId>
pub async fn create_document( &self, name: &str, storage_mode: StorageMode, ) -> Result<DocumentId>
Create a new document
Sourcepub async fn create_document_with_key(
&self,
name: &str,
storage_mode: StorageMode,
encryption_key: &[u8; 32],
) -> Result<DocumentId>
pub async fn create_document_with_key( &self, name: &str, storage_mode: StorageMode, encryption_key: &[u8; 32], ) -> Result<DocumentId>
Create a new document with specific encryption key
If name looks like a UUID, it will be used as the document ID directly.
Otherwise, a new UUID will be generated for the ID.
Sourcepub async fn get_document(
&self,
doc_id: &str,
) -> Result<Option<Arc<Mutex<Doc>>>>
pub async fn get_document( &self, doc_id: &str, ) -> Result<Option<Arc<Mutex<Doc>>>>
Get document (returns None if not found)
Sourcepub async fn document_exists_in_files(&self, doc_id: &str) -> Result<bool>
pub async fn document_exists_in_files(&self, doc_id: &str) -> Result<bool>
Check if document exists in Files storage
Sourcepub async fn document_exists_in_web(&self, doc_id: &str) -> Result<bool>
pub async fn document_exists_in_web(&self, doc_id: &str) -> Result<bool>
Check if document exists in Web storage
Sourcepub async fn insert_text(
&self,
doc_id: &str,
index: usize,
text: &str,
) -> Result<()>
pub async fn insert_text( &self, doc_id: &str, index: usize, text: &str, ) -> Result<()>
Insert text at position
Sourcepub async fn delete_text(
&self,
doc_id: &str,
index: usize,
len: usize,
) -> Result<()>
pub async fn delete_text( &self, doc_id: &str, index: usize, len: usize, ) -> Result<()>
Delete text in range
Sourcepub async fn get_crdt_update(&self, doc_id: &str) -> Result<Vec<u8>>
pub async fn get_crdt_update(&self, doc_id: &str) -> Result<Vec<u8>>
Get CRDT update (full state from beginning)
This encodes ALL changes from the document’s creation, suitable for syncing to a new peer that doesn’t have any prior state.
Sourcepub async fn apply_crdt_update(&self, doc_id: &str, update: &[u8]) -> Result<()>
pub async fn apply_crdt_update(&self, doc_id: &str, update: &[u8]) -> Result<()>
Apply CRDT update from peer
Sourcepub async fn get_files_blob(&self, doc_id: &str) -> Result<Option<Vec<u8>>>
pub async fn get_files_blob(&self, doc_id: &str) -> Result<Option<Vec<u8>>>
Get encrypted blob from Files storage
Sourcepub async fn get_web_blob(&self, doc_id: &str) -> Result<Option<Vec<u8>>>
pub async fn get_web_blob(&self, doc_id: &str) -> Result<Option<Vec<u8>>>
Get plaintext blob from Web storage
Sourcepub async fn get_encryption_key(&self, doc_id: &str) -> Result<[u8; 32]>
pub async fn get_encryption_key(&self, doc_id: &str) -> Result<[u8; 32]>
Get encryption key for document (fails for Web-only docs)
Sourcepub async fn decrypt_with_key(
&self,
doc_id: &str,
key: &[u8; 32],
) -> Result<Vec<u8>>
pub async fn decrypt_with_key( &self, doc_id: &str, key: &[u8; 32], ) -> Result<Vec<u8>>
Decrypt document with specific key (for testing wrong key scenarios)
Sourcepub async fn list_documents(&self) -> Result<Vec<String>>
pub async fn list_documents(&self) -> Result<Vec<String>>
List all document IDs
Sourcepub async fn delete_document(&self, doc_id: &str) -> Result<()>
pub async fn delete_document(&self, doc_id: &str) -> Result<()>
Delete a document and all associated data