diff --git a/index.js b/index.js index f2814fb..2601c44 100644 --- a/index.js +++ b/index.js @@ -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] diff --git a/test/ltgt.js b/test/ltgt.js index c109352..b0168b3 100644 --- a/test/ltgt.js +++ b/test/ltgt.js @@ -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') + } + } +})