Skip to main content

syncular_client/
lib.rs

1//! # syncular-client — Syncular v2 Rust client core (POC stage 2)
2//!
3//! A clean-room client implementation of the SPEC.md client-behavior
4//! contract on rusqlite local storage, consuming the committed `ssp2`
5//! codec as its wire layer. Built without reading the v1 Rust tree or the
6//! v2 TypeScript client — the conformance catalog (packages/conformance)
7//! is the proof that both cores implement one written protocol.
8//!
9//! Blocking hosts drive `sync()` / `sync_until_idle()`. Mailbox hosts prepare
10//! a round on the owner, run `PreparedSyncRound::exchange` on an I/O executor,
11//! and apply the result on the owner. An upload continuation repeats that
12//! exchange/apply cycle before the captured metadata request. The owner can
13//! serve local commands throughout; it queues inbound realtime traffic until
14//! the round completes. Scheduling is host policy (§8.4).
15
16pub mod api;
17#[cfg(feature = "bench-internals")]
18mod bench;
19pub mod client;
20/// §5.10.5 native CRDT helpers (the `crdt-yjs` feature) — the Rust face of the
21/// Yjs binding, mirroring `@syncular/crdt-yjs`. Off by default (dependency-lean).
22#[cfg(feature = "crdt-yjs")]
23pub mod crdt;
24/// Shared blocking HTTP/WebSocket host transport for Rust-backed bindings.
25/// The network stack is feature-gated; its no-network shape remains available
26/// in dependency-lean builds so host code needs only one transport type.
27pub mod native_transport;
28mod progress;
29mod round;
30pub use progress::{
31    ProgressObserver, ProgressPhase, ProgressState, ProgressSubscription, SyncProgress,
32    SyncProgressListener,
33};
34pub use round::{AppliedSyncRound, CompletedSyncRound, PreparedSyncRound};
35/// RFC 0005 previous-version context: the persisted schema descriptor, the
36/// bounded capture, and the sibling container FILE beside the replica.
37pub mod previous_version;
38pub mod query_guard;
39pub mod realtime_round;
40pub mod remote;
41pub mod schema;
42pub mod transport;
43pub mod values;
44
45/// Browser-worker crash recovery for the installed OPFS VFS.
46#[cfg(any(test, all(target_arch = "wasm32", target_os = "unknown")))]
47mod wasm_vfs;
48
49/// Wall-clock milliseconds since the Unix epoch, the one clock this crate
50/// reads for every timestamp it records. `wasm32-unknown-unknown` runs in a JS
51/// host where `SystemTime::now()` panics, so that target reads the host clock.
52#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
53pub(crate) fn wall_clock_ms() -> i64 {
54    js_sys::Date::now() as i64
55}
56
57/// Wall-clock milliseconds since the Unix epoch, the one clock this crate
58/// reads for every timestamp it records. A host clock set before 1970 is a
59/// broken host, not a value to clamp.
60#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
61pub(crate) fn wall_clock_ms() -> i64 {
62    std::time::SystemTime::now()
63        .duration_since(std::time::UNIX_EPOCH)
64        .expect("system clock predates Unix epoch")
65        .as_millis() as i64
66}
67
68pub use api::{
69    creation_time_bucket, last, AuthorityReadDeclaration, ClientChangeBatch, ClientDiagnosticsHost,
70    ClientDiagnosticsLease, ClientDiagnosticsReplica, ClientDiagnosticsRequest,
71    ClientDiagnosticsSchema, ClientDiagnosticsSnapshot, ClientDiagnosticsStorage, ClientError,
72    ClientLimits, CommandEffects, CommitDelivery, CommitOperation, CommitOperationOutcome,
73    CommitOutcome, CommitOutcomeQuery, CommitOutcomeResolution, CommitOutcomeStatus,
74    ConflictRecord, CoverageSnapshot, DiagnosticLastChange, DiagnosticLastRound,
75    DiagnosticQueryFailure, DiagnosticRoundCounters, DiagnosticSubscription,
76    ExpectedDiagnosticSubscription, FetchedBlob, LocalDataPurgeInput, LocalDataPurgeResult,
77    LocalDataPurgeTarget, LocalDataRebootstrapInput, LocalDataRebootstrapResult, Mutation,
78    PresencePeer, QueryOwner, QueryReadFailure, QueryRow, QuerySnapshot, QueryValue,
79    RealtimePolicy, RealtimeState, RejectionRecord, ResolveCommitOutcomeInput, RetainedCommitRow,
80    RetainedUniqueConflict, RowState, SchemaFloor, SnapshotRead, SubscriptionCatchup,
81    SubscriptionRequest, SubscriptionStateView, SyncIntent, SyncOutcome, SyncReport,
82    SyncStatusSnapshot, TableChange, TimeBucketUnit, WindowBase, WindowChange, WindowCoverage,
83    WindowState, WindowUnitRef, CLIENT_DIAGNOSTICS_VERSION, MAX_DIAGNOSTIC_EXPECTED_SUBSCRIPTIONS,
84    MAX_DIAGNOSTIC_QUERY_FAILURES, REALTIME_LOST_CODE, REALTIME_UNAVAILABLE_CODE,
85};
86pub use client::{
87    FileQuerySnapshotReader, SnapshotReadRequest, SnapshotStatement, SyncClient,
88    SECURITY_PREFLIGHT_REQUIRED_CODE,
89};
90pub use schema::{compile_schema, parse_schema_json, ClientSchema};
91pub use transport::{
92    BlobDownload, BlobUploadGrant, SegmentFetch, SegmentRequest, Transport, TransportError,
93};
94
95// Re-export the SSP2 stream scanner (§8.7 round-response reassembly) so the
96// native transports (FFI + Tauri plugin) reach it through their existing
97// `syncular-client` dependency, without each adding a direct `ssp2` path dep.
98pub use realtime_round::{RealtimeRound, RoundInbound, REALTIME_TAG_DELTA, REALTIME_TAG_ROUND};
99pub use remote::{
100    PreparedRemoteCommit, RemoteBytes, RemoteClientError, RemoteCommandResult, RemoteCommitInput,
101    RemoteCommitResult, RemoteQueryResult, SyncRemoteClient,
102};
103pub use ssp2::{MessageStreamScanner, ScannedMessage};