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// Protocol types (wasm-compatible, no tokio)
61#[cfg(feature = "protocol")]
62pub mod protocol_types;
63
64// Platform-agnostic document manager (wasm-compatible)
65#[cfg(feature = "doc-server")]
66mod doc_manager;
67#[cfg(feature = "doc-server")]
68pub use doc_manager::SyncDocManager;
69
70// Server infrastructure (siphonophore hooks, axum WebSocket)
71#[cfg(feature = "server")]
72pub mod hooks;
73#[cfg(feature = "server")]
74pub mod local;
75#[cfg(feature = "server")]
76pub mod protocol;
77#[cfg(feature = "server")]
78pub mod server;
79#[cfg(feature = "server")]
80pub mod storage;
81
82// ==================== Re-exports ====================
83
84// Core types — FileMetadata and BinaryRef from diaryx_core, CRDT storage types from local modules
85pub use crdt_storage::{CrdtStorage, CrdtUpdate, StorageResult, UpdateOrigin};
86pub use diaryx_core::types::{BinaryRef, FileMetadata};
87
88// Body documents
89pub use body_doc::BodyDoc;
90pub use body_doc_manager::BodyDocManager;
91
92// Workspace CRDT
93pub use workspace_doc::WorkspaceCrdt;
94
95// Storage implementations
96// SqliteStorage lives in diaryx_sync (local implementation)
97pub use memory_storage::MemoryStorage;
98#[cfg(all(not(target_arch = "wasm32"), feature = "sqlite"))]
99pub use sqlite_storage::SqliteStorage;
100
101// Sync protocol
102pub use sync_protocol::{
103    BodySyncProtocol, DocIdKind, SyncMessage, SyncProtocol, format_body_doc_id,
104    format_workspace_doc_id, frame_body_message, frame_message_v2, parse_doc_id,
105    unframe_body_message, unframe_message_v2,
106};
107
108// Sync handler + manager
109pub use sync_handler::{GuestConfig, SyncHandler};
110pub use sync_manager::{BodySyncResult, RustSyncManager, SyncMessageResult};
111
112// History, materialization, validation, self-healing
113pub use history::{ChangeType, FileDiff, HistoryEntry, HistoryManager};
114pub use materialize::{
115    MaterializationResult, MaterializedFile, materialize_workspace, parse_snapshot_markdown,
116};
117pub use sanity::{IssueKind, SanityIssue, SanityReport, validate_workspace};
118pub use self_healing::{HealingAction, HealthTracker};
119
120// Shared sync types (all platforms)
121pub use attachment_sync::AttachmentSyncClient;
122pub use control_message::ControlMessage;
123pub use share_session::{
124    HttpClient, HttpResponse, SessionCreatedResponse, SessionInfoResponse, ShareSessionClient,
125};
126pub use sync_session::{IncomingEvent, SessionAction, SyncSession};
127pub use sync_types::{SyncEvent, SyncSessionConfig, SyncStatus};
128
129// CrdtFs and decorator stack
130pub use crdt_fs::CrdtFs;
131pub use decorator_stack::{DecoratedFs, DecoratedFsBuilder, EventOnlyFs};
132
133// Plugin
134pub use sync_plugin::SyncPlugin;
135
136// Native sync client re-exports
137#[cfg(all(not(target_arch = "wasm32"), feature = "native-sync"))]
138pub use sync_client::{ReconnectConfig, SyncClient, SyncClientConfig, SyncEventHandler, SyncStats};
139#[cfg(all(not(target_arch = "wasm32"), feature = "native-sync"))]
140pub use tokio_transport::{TokioConnector, TokioTransport};
141#[cfg(all(not(target_arch = "wasm32"), feature = "native-sync"))]
142pub use transport::{SyncTransport, TransportConnector, TransportError, WsMessage};