Comparing version 2.10.6 to 2.11.0
71
index.js
@@ -325,7 +325,10 @@ const codecs = require('codecs') | ||
peek (opts) { | ||
return iteratorPeek(this.createRangeIterator({ ...opts, limit: 1 })) | ||
peek (range, opts) { | ||
return iteratorPeek(this.createRangeIterator(range, { ...opts, limit: 1 })) | ||
} | ||
createRangeIterator (opts = {}) { | ||
createRangeIterator (range, opts = {}) { | ||
// backwards compat range arg | ||
opts = opts ? { ...opts, ...range } : range | ||
const extension = (opts.extension === false && opts.limit !== 0) ? null : this.extension | ||
@@ -363,4 +366,4 @@ const keyEncoding = opts.keyEncoding ? codecs(opts.keyEncoding) : this.keyEncoding | ||
createReadStream (opts) { | ||
return iteratorToStream(this.createRangeIterator(opts)) | ||
createReadStream (range, opts) { | ||
return iteratorToStream(this.createRangeIterator(range, opts)) | ||
} | ||
@@ -373,4 +376,8 @@ | ||
createDiffStream (right, opts) { | ||
createDiffStream (right, range, opts) { | ||
if (typeof right === 'number') right = this.checkout(Math.max(1, right)) | ||
// backwards compat range arg | ||
opts = opts ? { ...opts, ...range } : range | ||
const snapshot = right.version > this.version ? right._makeSnapshot() : this._makeSnapshot() | ||
@@ -616,7 +623,10 @@ | ||
peek (opts) { | ||
return iteratorPeek(this.createRangeIterator({ ...opts, limit: 1 })) | ||
peek (range, opts) { | ||
return iteratorPeek(this.createRangeIterator(range, { ...opts, limit: 1 })) | ||
} | ||
createRangeIterator (opts = {}) { | ||
createRangeIterator (range, opts = {}) { | ||
// backwards compat range arg | ||
opts = opts ? { ...opts, ...range } : range | ||
const encoding = this._getEncoding(opts) | ||
@@ -626,4 +636,4 @@ return new RangeIterator(this, encoding, encRange(encoding.key, { ...opts, sub: this.tree._sub })) | ||
createReadStream (opts) { | ||
return iteratorToStream(this.createRangeIterator(opts)) | ||
createReadStream (range, opts) { | ||
return iteratorToStream(this.createRangeIterator(range, opts)) | ||
} | ||
@@ -1016,2 +1026,4 @@ | ||
this.previous = null | ||
this.currentMapped = null | ||
this.previousMapped = null | ||
this.stream = null | ||
@@ -1029,2 +1041,3 @@ | ||
await this.bee.ready() | ||
// Point from which to start watching | ||
@@ -1049,2 +1062,3 @@ this.current = this.bee.snapshot({ | ||
if (!this.core.isAutobase && (!this.core.core || this.core.core.tree.length !== this.core.length)) return | ||
const resolve = this._resolveOnChange | ||
@@ -1086,6 +1100,6 @@ this._resolveOnChange = null | ||
if (this.previous) await this.previous.close() | ||
await this._closePrevious() | ||
this.previous = this.current.snapshot() | ||
if (this.current) await this.current.close() | ||
await this._closeCurrent() | ||
this.current = this.bee.snapshot({ | ||
@@ -1100,3 +1114,5 @@ keyEncoding: this.keyEncoding, | ||
for await (const data of this.stream) { // eslint-disable-line | ||
return { done: false, value: [this.map(this.current), this.map(this.previous)] } | ||
this.currentMapped = this.map(this.current) | ||
this.previousMapped = this.map(this.previous) | ||
return { done: false, value: [this.currentMapped, this.previousMapped] } | ||
} | ||
@@ -1130,3 +1146,4 @@ } finally { | ||
await this._closeSnapshots() | ||
await this._closeCurrent().catch(safetyCatch) | ||
await this._closePrevious().catch(safetyCatch) | ||
@@ -1141,18 +1158,12 @@ const release = await this._lock() | ||
_closeSnapshots () { | ||
const closing = [] | ||
async _closeCurrent () { | ||
if (this.currentMapped) await this.currentMapped.close() | ||
if (this.current) await this.current.close() | ||
this.current = this.currentMapped = null | ||
} | ||
if (this.previous) { | ||
const previous = this.previous | ||
this.previous = null | ||
closing.push(previous.close()) | ||
} | ||
if (this.current) { | ||
const current = this.current | ||
this.current = null | ||
closing.push(current.close()) | ||
} | ||
return Promise.all(closing) | ||
async _closePrevious () { | ||
if (this.previousMapped) await this.previousMapped.close() | ||
if (this.previous) await this.previous.close() | ||
this.previous = this.previousMapped = null | ||
} | ||
@@ -1159,0 +1170,0 @@ } |
{ | ||
"name": "hyperbee", | ||
"version": "2.10.6", | ||
"version": "2.11.0", | ||
"description": "An append-only B-tree running on a Hypercore.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -197,3 +197,3 @@ # Hyperbee 🐝 | ||
#### `const stream = db.createReadStream([options])` | ||
#### `const stream = db.createReadStream([range], [options])` | ||
@@ -204,3 +204,4 @@ Make a read stream. Sort order is based on the binary value of the keys. | ||
`options` include: | ||
`range` should specify the range you want to read and looks like this: | ||
```js | ||
@@ -211,3 +212,10 @@ { | ||
lt: 'only return keys < than this', | ||
lte: 'only return keys <= than this', | ||
lte: 'only return keys <= than this' | ||
} | ||
``` | ||
`options` include: | ||
```js | ||
{ | ||
reverse: false // Set to true to get them in reverse order, | ||
@@ -218,3 +226,3 @@ limit: -1 // Set to the max number of entries you want | ||
#### `const { seq, key, value } = await db.peek([options])` | ||
#### `const { seq, key, value } = await db.peek([range], [options])` | ||
@@ -221,0 +229,0 @@ Similar to doing a read stream and returning the first value, but a bit faster than that. |
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
89192
2466
360