Sync / foldkit-sync/journal
journalExchange
function · packages/sync/src/journal.ts:230
function journalExchange<Message, Shared, Principal>(
options: JournalExchangeOptions<Message, Shared, Principal>,
): TransportClientOne replica's exchanges with the journal, as the replica's transport
speaks them (Sync.transport.fromPromise, or behind
Sync.transport.serve on a socket). Each pending operation is appended in
order, as received, and acknowledged once committed, or already
committed. Every hook (admit, and the journal's validate, authorize,
reduce and stamp) sees its Message upcast to the current version. One
is rejected by its id when its message does not decode, it names another
document, the journal refuses it (authorize, validate), or it was
written at an older version no step reads (Unreadable); the replica drops
it, or keeps an unreadable one in refused, rather than send it again. An
entry written at a version newer than this server's fails the exchange
before anything is appended, so its replica waits with its outbox whole; so
do an entry with no id at all, a cursor ahead of the journal's, a
connection opens refuses, admit or the journal failing, and a stored
operation that will not read (UnreadableHistoryError). The reply carries what committed
after the replica's cursor, a checkpoint when that history was compacted,
and the journal's epoch, so a replica of a reset journal starts again.