import { LevelUp } from 'levelup' ; const level = require ( 'level-mem' ) ; export const ENCODING_OPTS = { keyEncoding : 'binary' , valueEncoding : 'binary' } ; export type BatchDBOp = PutBatch | DelBatch ; export interface PutBatch { type : 'put' ; key : Buffer ; value : Buffer ; } export interface DelBatch { type : 'del' ; key : Buffer ; } /**
 * DB is a thin wrapper around the underlying levelup db,
 * which validates inputs and sets encoding type.
 */ export class DB { _leveldb : LevelUp ; param leveldb constructor ( leveldb ? ) { this . _leveldb = leveldb || level ( ) ; } param key returns async get ( key ) { let value = null ; try { value = await this . _leveldb . get ( key , ENCODING_OPTS ) ; } catch ( error ) { if ( error . notFound ) { } else { throw error ; } } return value ; } param key param value async put ( key , val ) { await this . _leveldb . put ( key , val , ENCODING_OPTS ) ; } param keys async del ( key ) { await this . _leveldb . del ( key , ENCODING_OPTS ) ; } param opStack async batch ( opStack ) { await this . _leveldb . batch ( opStack , ENCODING_OPTS ) ; } /**
     * Returns a copy of the DB instance, with a reference
     * to the **same** underlying leveldb instance.
     */ copy ( ) { return new DB ( this . _leveldb ) ; } }