ChangesDBProviderclass
new ChangesDBProvider<I, T>()
| Return | |
|---|---|
ChangesDBProvider<I, T> | Database provider that records every write it performs to its changes log. |
| Property | Type | |
|---|---|---|
.changes | ReadonlyArray<DBChange<I>> | The log of writes performed through this provider, in the order they happened. required readonly |
Database provider that records every write it performs to its changes log.
- Wraps a
sourceprovider, delegates each write, then appends aDBChangeentry describing what happened. - Useful for building audit logging, change feeds, or assertions in tests; reads are passed straight through and not logged.
A wrapping provider that records every write. ChangesDBProvider extends ThroughDBProvider and accumulates a .changes log of each set, update, and delete that passes through it — useful for audit trails, change feeds, and assertions in tests.
Usage
import { ChangesDBProvider, MemoryDBProvider } from "shelving/db";
const db = new ChangesDBProvider(new MemoryDBProvider());
await db.setItem(POSTS, "abc", { title: "Hi", body: "", published: true });
console.log(db.changes);
// [{ action: "set", collection: "posts", id: "abc", data: { … } }]Examples
const provider = new ChangesDBProvider(new MemoryDBProvider());
await provider.addItem(users, { name: "Dave" });
provider.changes; // [{ action: "add", collection: "users", id: 123, data: { name: "Dave" } }]