From 7b793d8110550627f3fcb9bd9d14058e2d6f7492 Mon Sep 17 00:00:00 2001 From: Keijo Kapp Date: Mon, 1 Jul 2024 21:40:57 +0300 Subject: [PATCH] Removed compatibility with defalting to prefix operation --- lib/database.ts | 9 --------- lib/subspace.ts | 50 +++++++--------------------------------------- lib/transaction.ts | 8 ++++---- 3 files changed, 11 insertions(+), 56 deletions(-) diff --git a/lib/database.ts b/lib/database.ts index f24b24f..5b78e1b 100644 --- a/lib/database.ts +++ b/lib/database.ts @@ -22,15 +22,6 @@ export default class Database(prefix, keyXf, valueXf) } - /** - * Switch to a new mode of handling ranges. - * - * @see Subspace.noDefaultPrefix - */ - noDefaultPrefix() { - return new Database(this._db, this.subspace.noDefaultPrefix()) - } - setNativeOptions(opts: DatabaseOptions) { eachOption(databaseOptionData, opts, (code, val) => this._db.setOption(code, val)) } diff --git a/lib/subspace.ts b/lib/subspace.ts index c291bae..4b572f3 100644 --- a/lib/subspace.ts +++ b/lib/subspace.ts @@ -29,14 +29,7 @@ export default class Subspace // This is cached from _prefix + keyXf. - _noDefaultPrefix: boolean - - constructor( - rawPrefix: string | Buffer | null, - keyXf?: Transformer, - valueXf?: Transformer, - noDefaultPrefix: boolean = false - ) { + constructor(rawPrefix: string | Buffer | null, keyXf?: Transformer, valueXf?: Transformer) { this.prefix = rawPrefix != null ? Buffer.from(rawPrefix) : EMPTY_BUF // Ugh typing this is a mess. Usually this will be fine since if you say new @@ -45,24 +38,6 @@ export default class Subspace) this._bakedKeyXf = rawPrefix ? prefixTransformer(rawPrefix, this.keyXf) : this.keyXf - - this._noDefaultPrefix = noDefaultPrefix - } - - /** - * Switch to a new mode of handling ranges. By default, the range operations (`getRange` family - * and `clearRange`) treat calls with missing end key as operations on prefix ranges. That means - * that a call like `tn.at('a').getRange('x')` acts on prefix `ax`, ie key range `[ax, ay)`. In - * the new mode, the missing end key defaults to a subspace end (inclusive), ie that call would - * act on a range `[ax, b)`. This enabled specifying key ranges not possible before. - * - * To specifiy range as a prefix, use `StartsWith` version of those methods (eg - * `getRangeAllStartsWith`). - * - * @see Subspace.packRange - */ - noDefaultPrefix() { - return new Subspace(this.prefix, this.keyXf, this.valueXf, true) } // All these template parameters make me question my life choices, but this is @@ -76,21 +51,21 @@ export default class Subspace = this.keyXf, valueXf: Transformer = this.valueXf) { const _prefix = prefix == null ? null : this.keyXf.pack(prefix) - return new Subspace(concatPrefix(this.prefix, _prefix), keyXf, valueXf, this._noDefaultPrefix) + return new Subspace(concatPrefix(this.prefix, _prefix), keyXf, valueXf) } /** At a child prefix thats specified without reference to the key transformer */ atRaw(prefix: Buffer) { - return new Subspace(concatPrefix(this.prefix, prefix), this.keyXf, this.valueXf, this._noDefaultPrefix) + return new Subspace(concatPrefix(this.prefix, prefix), this.keyXf, this.valueXf) } withKeyEncoding(keyXf: Transformer): Subspace { - return new Subspace(this.prefix, keyXf, this.valueXf, this._noDefaultPrefix) + return new Subspace(this.prefix, keyXf, this.valueXf) } withValueEncoding(valXf: Transformer): Subspace { - return new Subspace(this.prefix, this.keyXf, valXf, this._noDefaultPrefix) + return new Subspace(this.prefix, this.keyXf, valXf) } // GetSubspace implementation @@ -128,21 +103,10 @@ export default class Subspace { - const range = this.subspace.packRange(start, end, true) + const range = this.subspace.packRange(start, end) return this._tn.getEstimatedRangeSizeBytes(range.begin, range.end) } getRangeSplitPoints(start: KeyIn | undefined, end: KeyIn | undefined, chunkSize: number): Promise { - const range = this.subspace.packRange(start, end, true) + const range = this.subspace.packRange(start, end) return this._tn.getRangeSplitPoints(range.begin, range.end, chunkSize).then(results => ( results.map(r => this.subspace.unpackKey(r)) @@ -595,7 +595,7 @@ export default class Transaction