1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//! CRDT-based synchronization for Diaryx workspaces.
//!
//! This module provides conflict-free replicated data types (CRDTs) for
//! synchronizing workspace metadata and document content across multiple
//! clients. It uses the [yrs](https://docs.rs/yrs) crate (Rust port of Yjs)
//! for CRDT operations.
//!
//! # Architecture
//!
//! The CRDT system has several layers:
//!
//! 1. **Types** ([`types`]): Core data structures like [`FileMetadata`] and [`BinaryRef`]
//! 2. **Storage** ([`storage`]): Abstraction for persisting CRDT state to SQLite/memory
//! 3. **Workspace CRDT** ([`WorkspaceCrdt`]): Y.Doc for workspace file hierarchy
//! 4. **Body CRDT** ([`BodyDoc`]): Per-file Y.Doc for document content
//! 5. **Sync Protocol** ([`SyncProtocol`]): Y-sync for Hocuspocus server communication
//! 6. **History** ([`HistoryManager`]): Version history and time-travel
//!
//! # Feature Flag
//!
//! This module is only available when the `crdt` feature is enabled:
//!
//! ```toml
//! [dependencies]
//! diaryx_core = { version = "...", features = ["crdt"] }
//! ```
//!
//! # Example
//!
//! ```ignore
//! use diaryx_core::crdt::{MemoryStorage, CrdtStorage, FileMetadata};
//!
//! let storage = MemoryStorage::new();
//!
//! // Save some CRDT state
//! storage.save_doc("workspace", b"binary crdt state")?;
//!
//! // Track an update
//! let update_id = storage.append_update(
//! "workspace",
//! b"incremental update",
//! UpdateOrigin::Local,
//! )?;
//! ```
pub use BodyDoc;
pub use BodyDocManager;
pub use ;
pub use MemoryStorage;
pub use SqliteStorage;
pub use ;
pub use ;
pub use ;
pub use WorkspaceCrdt;