Sync / foldkit-durable
Reading history
const history = Effect.gen(function* () {
const { snapshot, cursor } = yield* journal.load(key) // the state, and where it is
const later = yield* journal.read(key, cursor, { limit: 500 }) // what came after
return { snapshot, later }
})read returns up to limit operations for paginated catch-up (Sync maps this to more). cursor(key) reads the latest sequence without decoding a snapshot. Sequence and Cursor have distinct brands so a commit sequence cannot be passed accidentally as a read cursor.
Compaction and checkpoints. compact(key, through) removes committed payloads up to through, advancing floor(key). Reading from below floor fails with CompactedCursorError, signaling the server to send a load checkpoint instead. Identity rows remain so old retries are still recognized.
Reset and epoch. epoch(key) identifies one linear history and changes after reset(key) or on a new database file. Return the epoch with every server reply; when a client presents an old epoch, answer from cursor 0. reset clears the snapshot and operations while keeping replica bindings and effect records.
Change notification. journal.subscribe is a sliding Stream of document keys changed by commits—use it as a wake-up signal and catch up with read. Slow subscribers drop intermediate notifications without slowing or failing commits.