Comparing version 2.7.3 to 2.8.0
25
index.js
@@ -348,3 +348,3 @@ const codecs = require('codecs') | ||
const ite = new RangeIterator(new Batch(this, this.feed.snapshot(), null, false, opts), null, opts) | ||
const ite = new RangeIterator(new Batch(this, this._makeSnapshot(), null, false, opts), null, opts) | ||
return ite | ||
@@ -358,3 +358,3 @@ } | ||
createHistoryStream (opts) { | ||
const session = (opts && opts.live) ? this.feed.session() : this.feed.snapshot() | ||
const session = (opts && opts.live) ? this.feed.session() : this._makeSnapshot() | ||
return iteratorToStream(new HistoryIterator(new Batch(this, session, null, false, opts), opts)) | ||
@@ -365,3 +365,3 @@ } | ||
if (typeof right === 'number') right = this.checkout(Math.max(1, right)) | ||
const snapshot = right.version > this.version ? right.feed.snapshot() : this.feed.snapshot() | ||
const snapshot = right.version > this.version ? right._makeSnapshot() : this._makeSnapshot() | ||
@@ -375,3 +375,3 @@ const keyEncoding = opts && opts.keyEncoding ? codecs(opts.keyEncoding) : this.keyEncoding | ||
get (key, opts) { | ||
const b = new Batch(this, this.feed.snapshot(), null, true, opts) | ||
const b = new Batch(this, this._makeSnapshot(), null, true, opts) | ||
return b.get(key) | ||
@@ -404,4 +404,12 @@ } | ||
_makeSnapshot () { | ||
// TODO: better if we could encapsulate this in hypercore in the future | ||
return this._checkout <= this.feed.length ? this.feed.snapshot() : this.feed.session() | ||
} | ||
checkout (version, opts = {}) { | ||
return new Hyperbee(this.feed.snapshot(), { | ||
// same as above, just checkout isn't set yet... | ||
const snap = version <= this.feed.length ? this.feed.snapshot() : this.feed.session() | ||
return new Hyperbee(snap, { | ||
_ready: this.ready(), | ||
@@ -877,2 +885,3 @@ _sub: false, | ||
this.range = range | ||
this.map = opts.map || defaultWatchMap | ||
@@ -954,3 +963,3 @@ this.current = null | ||
for await (const data of this.stream) { // eslint-disable-line | ||
return { done: false, value: [this.current, this.previous] } | ||
return { done: false, value: [this.map(this.current), this.map(this.previous)] } | ||
} | ||
@@ -1016,2 +1025,6 @@ } finally { | ||
function defaultWatchMap (snapshot) { | ||
return snapshot | ||
} | ||
async function leafSize (node, goLeft) { | ||
@@ -1018,0 +1031,0 @@ while (node.children.length) node = await node.getChildNode(goLeft ? 0 : node.children.length - 1) |
{ | ||
"name": "hyperbee", | ||
"version": "2.7.3", | ||
"version": "2.8.0", | ||
"description": "An append-only B-tree running on a Hypercore.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -131,2 +131,4 @@ # Hyperbee 🐝 | ||
A batch is atomic: it is either processed fully or not at all. | ||
#### `await batch.put(key, [value], [options])` | ||
@@ -133,0 +135,0 @@ |
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
83445
2339
314