IndexedDB log

IndexedDBLog is the browser-persistent sync log: one object store, seq as an auto-incremented key. It is the local half of the architecture — the client's cached working set — not a stand-in for the server. When the service-compris transport lands, this store keeps the replayed log so the board opens instantly and keeps working read-only if the service is down.

close() is terminal: every operation after it rejects with ClosedLogError (the name is on every message, so an error log is self-explanatory). When another tab deletes or upgrades the database, this log's connection is closed the same way (onversionchange) — the board above it treats that as a withdrawn replica and rebuilds, never as an outage.

import { IndexedDBLog, VirtaStore } from 'tosijs-virta'

const log = new IndexedDBLog('virta-doc-demo')
await log.clear()
const store = new VirtaStore({ log, identity: 'demo' })
await store.load()
await store.create({ title: 'persisted across reloads', tags: ['demo'] })

// A second store over the same database sees the event after replay.
const again = new VirtaStore({ log: new IndexedDBLog('virta-doc-demo'), identity: 'demo' })
await again.load()
preview.textContent = again.tasks.map((t) => `#${t.num} ${t.title}`).join('\n')
test('a fresh store replays what the first one wrote', () => {
  expect(preview.textContent).toBe('#1 persisted across reloads')
})