import { NotFoundError } from '../error' ; import { Database } from './types' ; export class PrefixStore { private readonly _db : Database ; private readonly _prefix : Buffer ; public constructor ( db , prefix ) { this . _db = db ; this . _prefix = prefix ; } public async get ( key ) { try { const value = await this . _db . get ( Buffer . concat ( [ this . _prefix , key ] ) ) ; return value ; } catch ( error ) { if ( error instanceof NotFoundError ) { return undefined ; } throw error ; } } public async set ( key , value ) { await this . _db . set ( Buffer . concat ( [ this . _prefix , key ] ) , value ) ; } }