export type DBObject = { [key: string]: string | string[] | number } export type BatchDBOp< TKey extends Uint8Array | string | number = Uint8Array, TValue extends Uint8Array | string | DBObject = Uint8Array > = PutBatch | DelBatch export enum KeyEncoding { String = 'string', Bytes = 'view', Number = 'number', } export enum ValueEncoding { String = 'string', Bytes = 'view', JSON = 'json', } export type EncodingOpts = { keyEncoding?: KeyEncoding valueEncoding?: ValueEncoding } export interface PutBatch< TKey extends Uint8Array | string | number = Uint8Array, TValue extends Uint8Array | string | DBObject = Uint8Array > { type: 'put' key: TKey value: TValue opts?: EncodingOpts } export interface DelBatch { type: 'del' key: TKey opts?: EncodingOpts } export interface DB< TKey extends Uint8Array | string | number = Uint8Array, TValue extends Uint8Array | string | DBObject = Uint8Array > { /** * Retrieves a raw value from db. * @param key * @returns A Promise that resolves to `Uint8Array` if a value is found or `undefined` if no value is found. */ get(key: TKey, opts?: EncodingOpts): Promise /** * Writes a value directly to db. * @param key The key as a `TValue` * @param value The value to be stored */ put(key: TKey, val: TValue, opts?: EncodingOpts): Promise /** * Removes a raw value in the underlying db. * @param keys */ del(key: TKey, opts?: EncodingOpts): Promise /** * Performs a batch operation on db. * @param opStack A stack of levelup operations */ batch(opStack: BatchDBOp[]): Promise /** * Returns a copy of the DB instance, with a reference * to the **same** underlying db instance. */ shallowCopy(): DB /** * Opens the database -- if applicable */ open(): Promise // TODO - decide if we actually need open/close - it's not required for maps and Level automatically opens the DB when you instantiate it }