RecordingDBProvider.replay()method
Replay every recorded operation onto another provider, in order.
replay(provider: DBProvider<I, T>): Promise<void>
new RecordingDBProvider<I, T>()
| Return | |
|---|---|
RecordingDBProvider<I, T> | Database provider that records every operation it performs to its operations log. |
| Property | Type | |
|---|---|---|
.operations | DBOperations<I, T> | The log of operations performed through this provider, in the order they happened. required readonly |
.writes | DBOperations<I, T> | The write operations from the operations log, in the order they happened. required readonly |
.reads | DBOperations<I, T> | The "get" read operations from the operations log, in the order they happened. required readonly |
Database provider that records every operation it performs to its operations log.
source provider, delegates each operation, then appends a DBOperation entry describing what happened.getItem() logs a "get" with the item it observed (or its confirmed absence), and getQuery() logs a "get" per item returned. Derived reads and two-step query writes are inherited, so everything they do is recorded per item too. Realtime sequences are not recorded.replay(), replayWrites(), or replayReads().UndoDBProvider), or assertions in tests.A wrapping provider that records every operation. RecordingDBProvider extends ThroughDBProvider and accumulates an operations log of every read and write that passes through it — useful for audit trails, change feeds, optimistic updates, and assertions in tests.
import { RecordingDBProvider, MemoryDBProvider } from "shelving/db";
const db = new RecordingDBProvider(new MemoryDBProvider());
await db.getItem(POSTS, "abc");
await db.setItem(POSTS, "abc", { title: "Hi", body: "", published: true });
console.log(db.operations);
// [{ action: "get", collection: POSTS, id: "abc", data: undefined },
// { action: "set", collection: POSTS, id: "abc", data: { … } }]Every operation is an explicit per-item DBOperation carrying the Collection object, the id, and the data or updates involved. Reads record what they observed — getItem() logs a "get" with the item (or undefined for confirmed absence), and getQuery() logs a "get" per item it returned. Query writes are inherited two-step from ThroughDBProvider, so they arrive in the log as their resolve reads plus the individual item writes. Realtime sequences are not recorded. Filter the log with the RecordingDBProvider.writes and RecordingDBProvider.reads getters.
replayOperations() re-issues a list of operations onto a provider in order, and three methods delegate to it:
RecordingDBProvider.replayWrites() — writes only. The right call for authoritative targets that hold their own truth (re-applying a log to a real database, audit replay, syncing a second source of truth): updates compose onto current state as deltas, and observed reads are never allowed to overwrite newer data.RecordingDBProvider.replay() — everything, in order. The right call for mirrors: reads apply what they observed (setting the item, or deleting it when the read confirmed absence), refreshing stale copies and giving update deltas their correct base.RecordingDBProvider.replayReads() — reads only, e.g. warming a cache from a recorded session.MemoryDBProvider.transact() is built on this: it records the callback's operations against a snapshot clone, then commits with RecordingDBProvider.replayWrites().
UndoDBProvider extends this provider to read each item before the first write that touches it, so the log always contains every touched item's original state — which UndoDBProvider.undo() restores, enabling optimistic local updates that roll back when a server call fails.
Replay every recorded operation onto another provider, in order.
replay(provider: DBProvider<I, T>): Promise<void>
Replay only the recorded write operations onto another provider, in order.
replayWrites(provider: DBProvider<I, T>): Promise<void>
Replay only the recorded "get" read operations onto another provider, in order.
replayReads(provider: DBProvider<I, T>): Promise<void>