Sync / API

foldkit-sync/journal

foldkit-sync/journal — the server's side of an exchange, over a foldkit-durable journal. Every Sync server needs the same loop: append what a replica sends, refuse what cannot be taken, and read back what committed since the replica's cursor. Written by hand three times, it failed the same way: an operation that did not decode failed the whole exchange, so the replica sent it again on every one and the edits behind it never went. Here, refused operations are reported by id, and the replica drops them.

Functions

documentHostOne document's Sync host, for any runtime that upgrades a request to a socket: a Durable Object (foldkit-sync/do), or Node's ws. Each upgrade is answered…
editsJournalThe table as the journal's read model: settle applies each committed edit through apply, as a recovery intent, and absorb records in the journal what the…
journalChanges
journalChangesScopedScope-managed version of journalChanges: forks the document commit listener into the caller's Scope via Effect.forkScoped so cleanup is automatic when the…
journalExchangeOne replica's exchanges with the journal, as the replica's transport speaks them (Sync.transport.fromPromise, or behind Sync.transport.serve on a socket).…
reactionDeclares a reaction of a contract from Sync.forApplication(App).make: after each committed Message in on, in journal order, run is called once at least, and…
serveJournalServes one accepted socket over the journal: each exchange frame answered by journalExchange with the connection's principal, and a notice sent after each…
serverJournalThe server's side of one document: appendAsServer, and the declared reactions with what runs them. Registers each reaction's cursor at the journal's current…

Classes

TableAheadOfJournalErrorThe table holds revisions past every sequence the journal has: it outlived a reset of the journal, or was built from another. New edits commit at sequences…

Interfaces

AcceptedAn upgrade documentHost accepted. Exactly one of the two must follow: serve once the runtime has opened the socket, or abandon when it never will (the…
DocumentHostOptionsWhat documentHost needs: one document, who may open it, and what they may do.
EditsJournalOptions
HostDefectA document host broke on its own side: the upgrade was answered 500 "Internal error", the socket closed with 1011, or a notice went unsent. The replica is…
HostSocketA server socket a host serves on: Sync's socket, and a close with a code the replica reads.
JournalExchangeOptions
ParkedA run set aside: it failed for good, or too often. Its reaction went on without it.
ReactionOne declared reaction of one document: what it runs on, what it may append, and what its handler needs. Made by reaction, given to serverJournal.
ReactionOptions
ServerJournal
ServerJournalOptions
TriggerA committed operation, as a reaction is given it.

Types

DocumentHostOptionsLayerWhat the resolver needs (a session store), required exactly when it needs something. Built per upgrade and kept until the socket closes, since revalidate…
HostStageWhere a document host broke.
RequiresThe services a list of reactions needs: none for none.