Sync / foldkit-sync

Ownership and responsibilities

foldkit-sync owns the replication contract (shared slice, durable and server-only Message sets, replay, codecs, journalContract), the replica (outbox, base, cursor, optimistic projection, status), reconciliation, transports, server-side appends and reactions (serverJournal), and the optional presence and LWW helpers.

A reaction's cursor and parked runs live in foldkit-durable beside its effect ledger, while Sync schedules runs and appends their results; the external provider owns whether a call executed. Sync applies durable Message migrations whenever reading operations, while your application defines the version history itself.

Local Model fields belong to your Foldkit app, server-derived read caches belong to foldkit-remote, authoritative commit ordering and SQLite storage belong to foldkit-durable, and shared-slice Schema migrations stay yours.

Limits

  • IndexedDB is the only built-in browser storage; custom Storage requires implementing three methods (load, save, close).
  • One server order per document; use a CRDT if you need peer-to-peer collaborative text merging.
  • Binding the socket transport to a platform WebSocket server uses thin glue (ws in Node, or foldkit-sync/do and Sync.transport.workerSocket on Cloudflare Workers).

Older spellings

Sync groups the exports and wraps nothing; every name is also exported on its own with the same signature: defineSync is Sync.define, syncMetrics is Sync.metrics, layerSocket/layerLoopback/layerFromPromise/toPromise/serveSocket/nativeSocket/workerSocket are Sync.transport.*, createPresence/createPresenceHub/servePresence/socketPresenceChannel/loopbackPresenceChannel are Sync.presence.*, and lwwRegister/openLwwClock are Sync.lww.*. documentId('todos') and DocumentId.make('todos') make the same branded value, as do the other id constructors.

Next