giantdb
Version:
Large object database in native JavaScript, with encryption support
60 lines (59 loc) • 1.97 kB
TypeScript
import { Adapter } from 'fs-adapters';
import { Middleware } from './middleware/middleware.js';
import { Change } from './change.js';
import { Item } from './item.js';
/**
* A GiantDB database.
*/
export declare class GiantDB {
private readonly _adapter;
private readonly _middlewareManager;
private readonly _ioManager;
private readonly _idSet;
/**
* Construct a new database. The source can either be a file system adapter or
* a directory path. If no source is given, a volatile in-memory store is used.
*
* @param source An adapter or directory path.
*/
constructor(source?: Adapter | string);
private _commit;
private _destroy;
/**
* Register the given middleware.
*
* @param middleware The middleware object.
*/
use(middleware: Middleware): void;
/**
* Prepare a new item. This constructs a new Change object that can be written
* to and then committed, making the item available.
*
* @param options Middleware options.
* @returns A Promise that resolves to a new Change object.
*/
create(options?: object): Promise<Change>;
/**
* Remove an item from this database.
*
* @param id The item's id.
* @returns A Promise that is resolved when removal is complete.
*/
remove(id: string): Promise<void>;
/**
* Retrieve an item in this database by id.
*
* @param id The item's id.
* @returns A Promise that resolves to the item if found.
*/
get(id: string): Promise<Item>;
/**
* Iterate over all items in this database. Iteration happens sequentially. If
* the callback returns a Promise or thenable, it is awaited before continuing
* with the next item.
*
* @param callbackFn The function to execute for each item.
* @returns A Promise that is resolved when iteration is finished.
*/
each(callbackFn: (item: Item) => any): Promise<void>;
}