sub-encoder
Advanced tools
Comparing version 2.1.1 to 2.1.2
13
index.js
@@ -18,8 +18,9 @@ const codecs = require('codecs') | ||
return { | ||
gt: r.gt && this.userEncoding.encode(r.gt), | ||
gte: r.gte && this.userEncoding.encode(r.gte), | ||
lte: r.lte && this.userEncoding.encode(r.lte), | ||
lt: r.lt && this.userEncoding.encode(r.lt) | ||
} | ||
const res = {} | ||
if (r.gt !== undefined) res.gt = this.userEncoding.encode(r.gt) | ||
if (r.gte !== undefined) res.gte = this.userEncoding.encode(r.gte) | ||
if (r.lte !== undefined) res.lte = this.userEncoding.encode(r.lte) | ||
if (r.lt !== undefined) res.lt = this.userEncoding.encode(r.lt) | ||
return res | ||
} | ||
@@ -26,0 +27,0 @@ |
{ | ||
"name": "sub-encoder", | ||
"version": "2.1.1", | ||
"version": "2.1.2", | ||
"description": "Generate sub encodings for key/value stores", | ||
@@ -26,2 +26,3 @@ "main": "index.js", | ||
"brittle": "^3.1.1", | ||
"compact-encoding": "^2.12.0", | ||
"hyperbee": "^2.11.0", | ||
@@ -28,0 +29,0 @@ "hypercore": "^10.3.2", |
@@ -8,2 +8,3 @@ const test = require('brittle') | ||
const b = require('b4a') | ||
const cenc = require('compact-encoding') | ||
@@ -89,2 +90,47 @@ const SEP = b.alloc(1) | ||
test('sub range encoding encodes non-undefined falsy values', async t => { | ||
const bee = new Hyperbee(new Hypercore(ram), { valueEncoding: 'utf-8' }) | ||
const enc = new SubEncoder() | ||
const preSub = enc.sub('sub-a') | ||
const keyEncoding = enc.sub('sub-b', cenc.lexint) | ||
const postSub = enc.sub('sub-c') | ||
await bee.put('what', 'ever', { keyEncoding: preSub }) | ||
await bee.put('what', 'ever', { keyEncoding: postSub }) | ||
await bee.put(0, 'entry0', { keyEncoding }) | ||
await bee.put(1, 'entry1', { keyEncoding }) | ||
{ | ||
const range = { gt: 0 } | ||
const nodes = await collect(bee.createReadStream(range, { keyEncoding })) | ||
t.is(nodes.length, 1, 'gt works') | ||
t.is(nodes[0].key, 1) | ||
} | ||
{ | ||
const range = { lt: 0 } | ||
const nodes = await collect(bee.createReadStream(range, { keyEncoding })) | ||
t.is(nodes.length, 0, 'lt works') | ||
} | ||
{ | ||
const range = { lte: 0 } | ||
const nodes = await collect(bee.createReadStream(range, { keyEncoding })) | ||
t.is(nodes.length, 1, 'lte works') | ||
t.is(nodes[0].key, 0) | ||
} | ||
{ | ||
// Note: also passes when processed as falsy value | ||
// would ideally have a value below 0 in the bee, but lexint does not support that | ||
const range = { gte: 0 } | ||
const nodes = await collect(bee.createReadStream(range, { keyEncoding })) | ||
t.is(nodes.length, 2, 'gte works') | ||
t.is(nodes[0].key, 0) | ||
} | ||
}) | ||
test('sub range diff encoding with hyperbee', async t => { | ||
@@ -91,0 +137,0 @@ const bee = new Hyperbee(new Hypercore(ram), { valueEncoding: 'utf-8' }) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
24971
279
7