Skip to content
This repository was archived by the owner on Dec 20, 2024. It is now read-only.

Commit 73b19b4

Browse files
committed
Remove legacy range options (Level/community#86)
1 parent 607dd3d commit 73b19b4

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,15 @@ Codec.prototype.encodeBatch = function (ops, opts) {
6262
})
6363
}
6464

65-
const ltgtKeys = ['lt', 'gt', 'lte', 'gte', 'start', 'end']
65+
const ltgtKeys = ['lt', 'gt', 'lte', 'gte']
6666

6767
Codec.prototype.encodeLtgt = function (ltgt) {
6868
const ret = {}
6969
Object.keys(ltgt).forEach((key) => {
70+
if (key === 'start' || key === 'end') {
71+
throw new Error('Legacy range options ("start" and "end") have been removed')
72+
}
73+
7074
ret[key] = ltgtKeys.indexOf(key) > -1
7175
? this.encodeKey(ltgt[key], ltgt)
7276
: ltgt[key]

test/ltgt.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,35 @@ test('encode ltgt', function (t) {
55
const codec = new Codec({ keyEncoding: 'hex' })
66

77
let ltgt = {
8-
start: '686579',
8+
gte: '686579',
99
lte: '686579'
1010
}
1111
let encoded = codec.encodeLtgt(ltgt)
12-
t.equal(encoded.start.toString(), 'hey')
12+
t.equal(encoded.gte.toString(), 'hey')
1313
t.equal(encoded.lte.toString(), 'hey')
1414

1515
ltgt = {
16-
start: '686579',
16+
gte: '686579',
1717
lte: '686579',
1818
keyEncoding: 'json'
1919
}
2020
encoded = codec.encodeLtgt(ltgt)
21-
t.equal(encoded.start, '"686579"')
21+
t.equal(encoded.gte, '"686579"')
2222
t.equal(encoded.lte, '"686579"')
2323

2424
t.end()
2525
})
26+
27+
test('rejects legacy range options', function (t) {
28+
t.plan(2)
29+
30+
const codec = new Codec()
31+
32+
for (const k of ['start', 'end']) {
33+
try {
34+
codec.encodeLtgt({ [k]: 123 })
35+
} catch (err) {
36+
t.is(err.message, 'Legacy range options ("start" and "end") have been removed')
37+
}
38+
}
39+
})

0 commit comments

Comments
 (0)