ThroughDBProviderclass

new ThroughDBProvider<I, T>(source: DBProvider<I, T>)
ParamType
sourceDBProvider<I, T>
The provider to delegate all operations to. required
Return
ThroughDBProvider<I, T>
Database provider that passes every operation straight through to a wrapped source provider.
PropertyType
.sourceDBProvider<I, T>
The wrapped source provider that every operation is delegated to. required readonly

Database provider that passes every operation straight through to a wrapped source provider.

  • Base for the layered Through*Provider family (validation, caching, logging, change tracking); subclasses override individual methods to add behaviour and call super to delegate.
  • Exposes source and implements Sourceable, so wrapped providers can be discovered with getSource() / requireSource().

The identity pass-through base for wrapping providers. ThroughDBProvider takes a source provider and delegates every method to it. Extend it to intercept only the methods you care about — timing, metrics, access control — without reimplementing the rest.

ValidationDBProvider, DebugDBProvider, and ChangesDBProvider are all ThroughDBProvider subclasses.

Usage

Override only the methods you need and call super to delegate the rest:

ts
import { ThroughDBProvider } from "shelving/db";

class TimingDBProvider extends ThroughDBProvider {
  override async getItem(collection, id) {
    const t = performance.now();
    const result = await super.getItem(collection, id);
    console.log(`getItem took ${performance.now() - t}ms`);
    return result;
  }
}

Examples

const provider = new ValidationDBProvider(new MemoryDBProvider());

Methods

Go

ThroughDBProvider.getItem()method

Get an item from a collection by its id, or undefined if it doesn't exist.

getItem(collection: Collection<string, II, TT>, id: II): Promise<OptionalItem<II, TT>>
Go

ThroughDBProvider.requireItem()method

Get an item from a collection by its id, or throw if it doesn't exist.

requireItem(collection: Collection<string, II, TT>, id: II): Promise<Item<II, TT>>
Go

ThroughDBProvider.getItemSequence()method

Subscribe to live changes for a single item by its id.

getItemSequence(collection: Collection<string, II, TT>, id: II): OptionalItemSequence<II, TT>
Go

ThroughDBProvider.addItem()method

Add a new item to a collection and return its generated id.

addItem(collection: Collection<string, II, TT>, data: TT): Promise<II>
Go

ThroughDBProvider.setItem()method

Set (insert or overwrite) the data for an item by its id.

setItem(collection: Collection<string, II, TT>, id: II, data: TT): Promise<void>
Go

ThroughDBProvider.updateItem()method

Apply partial updates to an existing item by its id.

updateItem(collection: Collection<string, II, TT>, id: II, updates: Updates<Item<II, TT>>): Promise<void>
Go

ThroughDBProvider.deleteItem()method

Delete an item from a collection by its id.

deleteItem(collection: Collection<string, II, TT>, id: II): Promise<void>
Go

ThroughDBProvider.countQuery()method

Count the items in a collection matching an optional query.

countQuery(collection: Collection<string, II, TT>, query?: Query<Item<II, TT>>): Promise<number>
Go

ThroughDBProvider.getQuery()method

Get the items in a collection matching an optional query.

getQuery(collection: Collection<string, II, TT>, query?: Query<Item<II, TT>>): Promise<Items<II, TT>>
Go

ThroughDBProvider.getQuerySequence()method

Subscribe to live changes for the result of a query.

getQuerySequence(collection: Collection<string, II, TT>, query?: Query<Item<II, TT>>): ItemsSequence<II, TT>
Go

ThroughDBProvider.setQuery()method

Set (overwrite) the data for every item matching a query.

setQuery(collection: Collection<string, II, TT>, query: Query<Item<II, TT>>, data: TT): Promise<void>
Go

ThroughDBProvider.updateQuery()method

Apply partial updates to every item matching a query.

updateQuery(collection: Collection<string, II, TT>, query: Query<Item<II, TT>>, updates: Updates<TT>): Promise<void>
Go

ThroughDBProvider.deleteQuery()method

Delete every item matching a query.

deleteQuery(collection: Collection<string, II, TT>, query: Query<Item<II, TT>>): Promise<void>
Go

ThroughDBProvider.getFirst()method

Get the first item matching a query, or undefined if there are none.

getFirst(collection: Collection<string, II, TT>, query: Query<Item<II, TT>>): Promise<OptionalItem<II, TT>>
Go

ThroughDBProvider.requireFirst()method

Get the first item matching a query, or throw if there are none.

requireFirst(collection: Collection<string, II, TT>, query: Query<Item<II, TT>>): Promise<Item<II, TT>>