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

Commit

Permalink
Remove legacy range options (Level/community#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
vweevers committed Apr 4, 2021
1 parent a42db03 commit 24b44b8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,15 @@ Codec.prototype.encodeBatch = function (ops, opts) {
})
}

const ltgtKeys = ['lt', 'gt', 'lte', 'gte', 'start', 'end']
const ltgtKeys = ['lt', 'gt', 'lte', 'gte']

Codec.prototype.encodeLtgt = function (ltgt) {
const ret = {}
Object.keys(ltgt).forEach((key) => {
if (key === 'start' || key === 'end') {
throw new Error('Legacy range options ("start" and "end") have been removed')
}

ret[key] = ltgtKeys.indexOf(key) > -1
? this.encodeKey(ltgt[key], ltgt)
: ltgt[key]
Expand Down
22 changes: 18 additions & 4 deletions test/ltgt.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,35 @@ test('encode ltgt', function (t) {
const codec = new Codec({ keyEncoding: 'hex' })

let ltgt = {
start: '686579',
gte: '686579',
lte: '686579'
}
let encoded = codec.encodeLtgt(ltgt)
t.equal(encoded.start.toString(), 'hey')
t.equal(encoded.gte.toString(), 'hey')
t.equal(encoded.lte.toString(), 'hey')

ltgt = {
start: '686579',
gte: '686579',
lte: '686579',
keyEncoding: 'json'
}
encoded = codec.encodeLtgt(ltgt)
t.equal(encoded.start, '"686579"')
t.equal(encoded.gte, '"686579"')
t.equal(encoded.lte, '"686579"')

t.end()
})

test('rejects legacy range options', function (t) {
t.plan(2)

const codec = new Codec()

for (const k of ['start', 'end']) {
try {
codec.encodeLtgt({ [k]: 123 })
} catch (err) {
t.is(err.message, 'Legacy range options ("start" and "end") have been removed')
}
}
})

0 comments on commit 24b44b8

Please sign in to comment.