import {LevelDbControllerMetrics} from "./metrics.js"; /** Shortcut for Uint8Array based DatabaseController */ export type Db = DatabaseController; export type DatabaseOptions = { name: string; }; export interface FilterOptions { gt?: K; gte?: K; lt?: K; lte?: K; reverse?: boolean; limit?: number; /** For metrics */ bucketId?: string; } export type DbReqOpts = { /** For metrics */ bucketId?: string; }; export interface KeyValue { key: K; value: V; } export type DbBatchOperation = {type: "del"; key: K} | {type: "put"; key: K; value: V}; export type DbBatch = DbBatchOperation[]; export interface DatabaseController { // service start / stop close(): Promise; /** To inject metrics after CLI initialization */ setMetrics(metrics: LevelDbControllerMetrics): void; // Core API get(key: K, opts?: DbReqOpts): Promise; getMany(key: K[], opts?: DbReqOpts): Promise<(V | undefined)[]>; put(key: K, value: V, opts?: DbReqOpts): Promise; delete(key: K, opts?: DbReqOpts): Promise; // Batch operations batchPut(items: KeyValue[], opts?: DbReqOpts): Promise; batchDelete(keys: K[], opts?: DbReqOpts): Promise; batch(batch: DbBatch, opts?: DbReqOpts): Promise; // Iterate over entries keysStream(opts?: FilterOptions): AsyncIterable; keys(opts?: FilterOptions): Promise; valuesStream(opts?: FilterOptions): AsyncIterable; values(opts?: FilterOptions): Promise; entriesStream(opts?: FilterOptions): AsyncIterable>; entries(opts?: FilterOptions): Promise[]>; }