/**
 * Modified from bcoin's bdb (https://github.com/bcoin-org/bdb) (MIT LICENSE).
 * Credit to the original author, Christopher Jeffrey (https://github.com/chjj).
 */ import { RangeBucket , Batch , Bucket , DB , Iterator , IteratorOptions , K , V , } from '../types' ; /**
 * Simple bucket implementation that forwards all
 * calls up to the database but appends a prefix.
 */ export class BaseBucket implements Bucket { constructor ( readonly db , readonly prefix ) { } param key returns public async get ( key ) { return this . db . get ( this . addPrefix ( key ) ) ; } param key param value public async put ( key , value ) { return this . db . put ( this . addPrefix ( key ) , value ) ; } param key public async del ( key ) { return this . db . del ( this . addPrefix ( key ) ) ; } param key returns public async has ( key ) { return this . db . has ( this . addPrefix ( key ) ) ; } param operations public async batch ( operations ) { return this . db . batch ( operations . map ( ( op ) => { return { ... op , key : this . addPrefix ( op . key ) , } ; } ) ) ; } param options returns public iterator ( options ? ) { return this . db . iterator ( { ... options , prefix : this . addPrefix ( options . prefix ) , } ) ; } param prefix returns public bucket ( prefix ) { return this . db . bucket ( this . addPrefix ( prefix ) ) ; } param prefix returns public rangeBucket ( prefix ) { return this . db . rangeBucket ( this . addPrefix ( prefix ) ) ; } param value returns private addPrefix ( value ) { return value !== undefined ? Buffer . concat ( [ this . prefix , value ] ) : this . prefix ; } }