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/// Wall-clock milliseconds since the Unix epoch, the one clock this crate
46/// reads for every timestamp it records. `wasm32-unknown-unknown` runs in a JS
47/// host where `SystemTime::now()` panics, so that target reads the host clock.
48#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
49pub(crate) fn wall_clock_ms() -> i64 {
50    js_sys::Date::now() as i64
51}
52
53/// Wall-clock milliseconds since the Unix epoch, the one clock this crate
54/// reads for every timestamp it records. A host clock set before 1970 is a
55/// broken host, not a value to clamp.
56#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
57pub(crate) fn wall_clock_ms() -> i64 {
58    std::time::SystemTime::now()
59        .duration_since(std::time::UNIX_EPOCH)
60        .expect("system clock predates Unix epoch")
61        .as_millis() as i64
62}
63
64pub use api::{
65    creation_time_bucket, last, AuthorityReadDeclaration, ClientChangeBatch, ClientDiagnosticsHost,
66    ClientDiagnosticsLease, ClientDiagnosticsReplica, ClientDiagnosticsRequest,
67    ClientDiagnosticsSchema, ClientDiagnosticsSnapshot, ClientDiagnosticsStorage, ClientError,
68    ClientLimits, CommandEffects, CommitDelivery, CommitOperation, CommitOperationOutcome,
69    CommitOutcome, CommitOutcomeQuery, CommitOutcomeResolution, CommitOutcomeStatus,
70    ConflictRecord, CoverageSnapshot, DiagnosticLastChange, DiagnosticLastRound,
71    DiagnosticQueryFailure, DiagnosticRoundCounters, DiagnosticSubscription,
72    ExpectedDiagnosticSubscription, FetchedBlob, LocalDataPurgeInput, LocalDataPurgeResult,
73    LocalDataPurgeTarget, LocalDataRebootstrapInput, LocalDataRebootstrapResult, Mutation,
74    PresencePeer, QueryOwner, QueryReadFailure, QueryRow, QuerySnapshot, QueryValue,
75    RealtimePolicy, RealtimeState, RejectionRecord, ResolveCommitOutcomeInput, RetainedCommitRow,
76    RetainedUniqueConflict, RowState, SchemaFloor, SnapshotRead, SubscriptionCatchup,
77    SubscriptionRequest, SubscriptionStateView, SyncIntent, SyncOutcome, SyncReport,
78    SyncStatusSnapshot, TableChange, TimeBucketUnit, WindowBase, WindowChange, WindowCoverage,
79    WindowState, WindowUnitRef, CLIENT_DIAGNOSTICS_VERSION, MAX_DIAGNOSTIC_EXPECTED_SUBSCRIPTIONS,
80    MAX_DIAGNOSTIC_QUERY_FAILURES, REALTIME_LOST_CODE, REALTIME_UNAVAILABLE_CODE,
81};
82pub use client::{
83    FileQuerySnapshotReader, SnapshotReadRequest, SnapshotStatement, SyncClient,
84    SECURITY_PREFLIGHT_REQUIRED_CODE,
85};
86pub use schema::{compile_schema, parse_schema_json, ClientSchema};
87pub use transport::{BlobDownload, BlobUploadGrant, SegmentRequest, Transport, TransportError};
88
89// Re-export the SSP2 stream scanner (§8.7 round-response reassembly) so the
90// native transports (FFI + Tauri plugin) reach it through their existing
91// `syncular-client` dependency, without each adding a direct `ssp2` path dep.
92pub use realtime_round::{RealtimeRound, RoundInbound, REALTIME_TAG_DELTA, REALTIME_TAG_ROUND};
93pub use remote::{
94    PreparedRemoteCommit, RemoteBytes, RemoteClientError, RemoteCommandResult, RemoteCommitInput,
95    RemoteCommitResult, RemoteQueryResult, SyncRemoteClient,
96};
97pub use ssp2::{MessageStreamScanner, ScannedMessage};