Skip to main content

diaryx_sync/
lib.rs

1//! # Diaryx Sync Engine
2//!
3//! Sync engine for Diaryx, providing CRDT types, sync protocol, and server infrastructure.
4//!
5//! ## Feature flags
6//!
7//! - **default** — CRDT types and protocol only (WASM-compatible)
8//! - **sqlite** — SQLite-backed CRDT storage
9//! - **server** — Siphonophore hooks, axum WebSocket server, StorageCache
10//! - **native-sync** — Native sync transport (tokio-tungstenite)
11//! - **git** — Git-backed version history
12
13// ==================== CRDT core (always available, WASM-compatible) ====================
14
15pub mod attachment_sync;
16mod body_doc;
17mod body_doc_manager;
18pub mod control_message;
19mod history;
20pub mod materialize;
21mod memory_storage;
22pub mod sanity;
23pub mod self_healing;
24pub mod share_session;
25mod sync_handler;
26mod sync_manager;
27mod sync_protocol;
28mod sync_session;
29mod sync_types;
30mod time;
31mod workspace_doc;
32
33// CRDT storage types and trait
34mod crdt_storage;
35
36// Filesystem decorators (CRDT-aware FS layer)
37mod crdt_fs;
38mod decorator_stack;
39
40// Plugin
41mod sync_plugin;
42
43// ==================== Feature-gated modules ====================
44
45// SqliteStorage implementation (native only, sqlite feature)
46#[cfg(all(not(target_arch = "wasm32"), feature = "sqlite"))]
47mod sqlite_storage;
48
49#[cfg(all(not(target_arch = "wasm32"), feature = "git"))]
50pub mod git;
51
52// Native sync client (CLI, Tauri) — not available on WASM
53#[cfg(all(not(target_arch = "wasm32"), feature = "native-sync"))]
54mod sync_client;
55#[cfg(all(not(target_arch = "wasm32"), feature = "native-sync"))]
56mod tokio_transport;
57#[cfg(all(not(target_arch = "wasm32"), feature = "native-sync"))]
58mod transport;
59
60// Server infrastructure (siphonophore hooks, axum WebSocket)
61#[cfg(feature = "server")]
62pub mod hooks;
63#[cfg(feature = "server")]
64pub mod local;
65#[cfg(feature = "server")]
66pub mod protocol;
67#[cfg(feature = "server")]
68pub mod server;
69#[cfg(feature = "server")]
70pub mod storage;
71
72// ==================== Re-exports ====================
73
74// Core types — FileMetadata and BinaryRef from diaryx_core, CRDT storage types from local modules
75pub use crdt_storage::{CrdtStorage, CrdtUpdate, StorageResult, UpdateOrigin};
76pub use diaryx_core::types::{BinaryRef, FileMetadata};
77
78// Body documents
79pub use body_doc::BodyDoc;
80pub use body_doc_manager::BodyDocManager;
81
82// Workspace CRDT
83pub use workspace_doc::WorkspaceCrdt;
84
85// Storage implementations
86// SqliteStorage lives in diaryx_sync (local implementation)
87pub use memory_storage::MemoryStorage;
88#[cfg(all(not(target_arch = "wasm32"), feature = "sqlite"))]
89pub use sqlite_storage::SqliteStorage;
90
91// Sync protocol
92pub use sync_protocol::{
93    BodySyncProtocol, DocIdKind, SyncMessage, SyncProtocol, format_body_doc_id,
94    format_workspace_doc_id, frame_body_message, frame_message_v2, parse_doc_id,
95    unframe_body_message, unframe_message_v2,
96};
97
98// Sync handler + manager
99pub use sync_handler::{GuestConfig, SyncHandler};
100pub use sync_manager::{BodySyncResult, RustSyncManager, SyncMessageResult};
101
102// History, materialization, validation, self-healing
103pub use history::{ChangeType, FileDiff, HistoryEntry, HistoryManager};
104pub use materialize::{
105    MaterializationResult, MaterializedFile, materialize_workspace, parse_snapshot_markdown,
106};
107pub use sanity::{IssueKind, SanityIssue, SanityReport, validate_workspace};
108pub use self_healing::{HealingAction, HealthTracker};
109
110// Shared sync types (all platforms)
111pub use attachment_sync::AttachmentSyncClient;
112pub use control_message::ControlMessage;
113pub use share_session::{
114    HttpClient, HttpResponse, SessionCreatedResponse, SessionInfoResponse, ShareSessionClient,
115};
116pub use sync_session::{IncomingEvent, SessionAction, SyncSession};
117pub use sync_types::{SyncEvent, SyncSessionConfig, SyncStatus};
118
119// CrdtFs and decorator stack
120pub use crdt_fs::CrdtFs;
121pub use decorator_stack::{DecoratedFs, DecoratedFsBuilder, EventOnlyFs};
122
123// Plugin
124pub use sync_plugin::SyncPlugin;
125
126// Native sync client re-exports
127#[cfg(all(not(target_arch = "wasm32"), feature = "native-sync"))]
128pub use sync_client::{ReconnectConfig, SyncClient, SyncClientConfig, SyncEventHandler, SyncStats};
129#[cfg(all(not(target_arch = "wasm32"), feature = "native-sync"))]
130pub use tokio_transport::{TokioConnector, TokioTransport};
131#[cfg(all(not(target_arch = "wasm32"), feature = "native-sync"))]
132pub use transport::{SyncTransport, TransportConnector, TransportError, WsMessage};