Skip to content

Commit c8512e2

Browse files
committed
Removed compatibility with defalting to prefix operation
1 parent 21f5555 commit c8512e2

File tree

3 files changed

+11
-56
lines changed

3 files changed

+11
-56
lines changed

lib/database.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,6 @@ export default class Database<KeyIn = NativeValue, KeyOut = Buffer, ValIn = Nati
2222
this.subspace = subspace//new Subspace<KeyIn, KeyOut, ValIn, ValOut>(prefix, keyXf, valueXf)
2323
}
2424

25-
/**
26-
* Switch to a new mode of handling ranges.
27-
*
28-
* @see Subspace.noDefaultPrefix
29-
*/
30-
noDefaultPrefix() {
31-
return new Database(this._db, this.subspace.noDefaultPrefix())
32-
}
33-
3425
setNativeOptions(opts: DatabaseOptions) {
3526
eachOption(databaseOptionData, opts, (code, val) => this._db.setOption(code, val))
3627
}

lib/subspace.ts

Lines changed: 7 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,7 @@ export default class Subspace<KeyIn = NativeValue, KeyOut = Buffer, ValIn = Nati
2929

3030
_bakedKeyXf: Transformer<KeyIn, KeyOut> // This is cached from _prefix + keyXf.
3131

32-
_noDefaultPrefix: boolean
33-
34-
constructor(
35-
rawPrefix: string | Buffer | null,
36-
keyXf?: Transformer<KeyIn, KeyOut>,
37-
valueXf?: Transformer<ValIn, ValOut>,
38-
noDefaultPrefix: boolean = false
39-
) {
32+
constructor(rawPrefix: string | Buffer | null, keyXf?: Transformer<KeyIn, KeyOut>, valueXf?: Transformer<ValIn, ValOut>) {
4033
this.prefix = rawPrefix != null ? Buffer.from(rawPrefix) : EMPTY_BUF
4134

4235
// Ugh typing this is a mess. Usually this will be fine since if you say new
@@ -45,24 +38,6 @@ export default class Subspace<KeyIn = NativeValue, KeyOut = Buffer, ValIn = Nati
4538
this.valueXf = valueXf || (defaultTransformer as Transformer<any, any>)
4639

4740
this._bakedKeyXf = rawPrefix ? prefixTransformer(rawPrefix, this.keyXf) : this.keyXf
48-
49-
this._noDefaultPrefix = noDefaultPrefix
50-
}
51-
52-
/**
53-
* Switch to a new mode of handling ranges. By default, the range operations (`getRange` family
54-
* and `clearRange`) treat calls with missing end key as operations on prefix ranges. That means
55-
* that a call like `tn.at('a').getRange('x')` acts on prefix `ax`, ie key range `[ax, ay)`. In
56-
* the new mode, the missing end key defaults to a subspace end (inclusive), ie that call would
57-
* act on a range `[ax, b)`. This enabled specifying key ranges not possible before.
58-
*
59-
* To specifiy range as a prefix, use `StartsWith` version of those methods (eg
60-
* `getRangeAllStartsWith`).
61-
*
62-
* @see Subspace.packRange
63-
*/
64-
noDefaultPrefix() {
65-
return new Subspace(this.prefix, this.keyXf, this.valueXf, true)
6641
}
6742

6843
// All these template parameters make me question my life choices, but this is
@@ -76,21 +51,21 @@ export default class Subspace<KeyIn = NativeValue, KeyOut = Buffer, ValIn = Nati
7651
// ***
7752
at(prefix: KeyIn | null, keyXf: Transformer<any, any> = this.keyXf, valueXf: Transformer<any, any> = this.valueXf) {
7853
const _prefix = prefix == null ? null : this.keyXf.pack(prefix)
79-
return new Subspace(concatPrefix(this.prefix, _prefix), keyXf, valueXf, this._noDefaultPrefix)
54+
return new Subspace(concatPrefix(this.prefix, _prefix), keyXf, valueXf)
8055
}
8156

8257
/** At a child prefix thats specified without reference to the key transformer */
8358
atRaw(prefix: Buffer) {
84-
return new Subspace(concatPrefix(this.prefix, prefix), this.keyXf, this.valueXf, this._noDefaultPrefix)
59+
return new Subspace(concatPrefix(this.prefix, prefix), this.keyXf, this.valueXf)
8560
}
8661

8762

8863
withKeyEncoding<CKI, CKO>(keyXf: Transformer<CKI, CKO>): Subspace<CKI, CKO, ValIn, ValOut> {
89-
return new Subspace(this.prefix, keyXf, this.valueXf, this._noDefaultPrefix)
64+
return new Subspace(this.prefix, keyXf, this.valueXf)
9065
}
9166

9267
withValueEncoding<CVI, CVO>(valXf: Transformer<CVI, CVO>): Subspace<KeyIn, KeyOut, CVI, CVO> {
93-
return new Subspace(this.prefix, this.keyXf, valXf, this._noDefaultPrefix)
68+
return new Subspace(this.prefix, this.keyXf, valXf)
9469
}
9570

9671
// GetSubspace implementation
@@ -128,21 +103,10 @@ export default class Subspace<KeyIn = NativeValue, KeyOut = Buffer, ValIn = Nati
128103
* Encodes a range specified by `start`/`end` pair using configured key encoder.
129104
*
130105
* @param start Start of the key range. If undefined, the start of the subspace is assumed.
131-
* @param end End of the key range. If undefined, the end of the subspace is assumed, unless
132-
* `noDefaultPrefix` flag is set or enabled for this subspace, in which case, start key is treated
133-
* as a prefix.
134-
* @param noDefaultPrefix Disable treating start key as a prefix if end key is not specified.
106+
* @param end End of the key range. If undefined, the end of the subspace is assumed.
135107
* @returns Encoded range as a `{ begin, end }` record.
136108
*/
137-
packRange(
138-
start?: KeyIn,
139-
end?: KeyIn,
140-
noDefaultPrefix: boolean = false
141-
): {begin: NativeValue, end: NativeValue} {
142-
if (start !== undefined && end === undefined && !this._noDefaultPrefix && !noDefaultPrefix) {
143-
return this.packRangeStartsWith(start)
144-
}
145-
109+
packRange(start?: KeyIn, end?: KeyIn): {begin: NativeValue, end: NativeValue} {
146110
return {
147111
begin: start !== undefined ? this._bakedKeyXf.pack(start) : this.prefix,
148112
end: end !== undefined ? this._bakedKeyXf.pack(end) : strInc(this.prefix)

lib/transaction.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -352,13 +352,13 @@ export default class Transaction<KeyIn = NativeValue, KeyOut = Buffer, ValIn = N
352352
}
353353

354354
getEstimatedRangeSizeBytes(start?: KeyIn, end?: KeyIn): Promise<number> {
355-
const range = this.subspace.packRange(start, end, true)
355+
const range = this.subspace.packRange(start, end)
356356

357357
return this._tn.getEstimatedRangeSizeBytes(range.begin, range.end)
358358
}
359359

360360
getRangeSplitPoints(start: KeyIn | undefined, end: KeyIn | undefined, chunkSize: number): Promise<KeyOut[]> {
361-
const range = this.subspace.packRange(start, end, true)
361+
const range = this.subspace.packRange(start, end)
362362

363363
return this._tn.getRangeSplitPoints(range.begin, range.end, chunkSize).then(results => (
364364
results.map(r => this.subspace.unpackKey(r))
@@ -595,7 +595,7 @@ export default class Transaction<KeyIn = NativeValue, KeyOut = Buffer, ValIn = N
595595
}
596596

597597
addReadConflictRange(start?: KeyIn, end?: KeyIn) {
598-
const range = this.subspace.packRange(start, end, true)
598+
const range = this.subspace.packRange(start, end)
599599
this._tn.addReadConflictRange(range.begin, range.end)
600600
}
601601
addReadConflictRangeStartsWith(prefix: KeyIn) {
@@ -608,7 +608,7 @@ export default class Transaction<KeyIn = NativeValue, KeyOut = Buffer, ValIn = N
608608
}
609609

610610
addWriteConflictRange(start?: KeyIn, end?: KeyIn) {
611-
const range = this.subspace.packRange(start, end, true)
611+
const range = this.subspace.packRange(start, end)
612612
this._tn.addWriteConflictRange(range.begin, range.end)
613613
}
614614
addWriteConflictRangeStartsWith(prefix: KeyIn) {

0 commit comments

Comments
 (0)