UNPKG

1.63 kBTypeScriptView Raw
1/// <reference types="node" />
2import type { LevelUp } from 'levelup';
3export declare const ENCODING_OPTS: {
4 keyEncoding: string;
5 valueEncoding: string;
6};
7export declare type BatchDBOp = PutBatch | DelBatch;
8export interface PutBatch {
9 type: 'put';
10 key: Buffer;
11 value: Buffer;
12}
13export interface DelBatch {
14 type: 'del';
15 key: Buffer;
16}
17/**
18 * DB is a thin wrapper around the underlying levelup db,
19 * which validates inputs and sets encoding type.
20 */
21export declare class DB {
22 _leveldb: LevelUp;
23 /**
24 * Initialize a DB instance. If `leveldb` is not provided, DB
25 * defaults to an [in-memory store](https://github.com/Level/memdown).
26 * @param leveldb - An abstract-leveldown compliant store
27 */
28 constructor(leveldb?: LevelUp);
29 /**
30 * Retrieves a raw value from leveldb.
31 * @param key
32 * @returns A Promise that resolves to `Buffer` if a value is found or `null` if no value is found.
33 */
34 get(key: Buffer): Promise<Buffer | null>;
35 /**
36 * Writes a value directly to leveldb.
37 * @param key The key as a `Buffer`
38 * @param value The value to be stored
39 */
40 put(key: Buffer, val: Buffer): Promise<void>;
41 /**
42 * Removes a raw value in the underlying leveldb.
43 * @param keys
44 */
45 del(key: Buffer): Promise<void>;
46 /**
47 * Performs a batch operation on db.
48 * @param opStack A stack of levelup operations
49 */
50 batch(opStack: BatchDBOp[]): Promise<void>;
51 /**
52 * Returns a copy of the DB instance, with a reference
53 * to the **same** underlying leveldb instance.
54 */
55 copy(): DB;
56}