UNPKG

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