Comparing version 3.8.0 to 4.0.0
16
index.js
@@ -41,2 +41,3 @@ const Node = require('./lib/node') | ||
this.valueEncoding = opts.valueEncoding ? codecs(opts.valueEncoding) : null | ||
this.alwaysUpdate = !!opts.alwaysUpdate | ||
@@ -113,4 +114,4 @@ const feedOpts = Object.assign({}, opts, { valueEncoding: 'binary' }) | ||
HyperTrie.prototype.replicate = function (opts) { | ||
return this.feed.replicate(opts) | ||
HyperTrie.prototype.replicate = function (isInitiator, opts) { | ||
return this.feed.replicate(isInitiator, opts) | ||
} | ||
@@ -132,6 +133,13 @@ | ||
HyperTrie.prototype.head = function (cb) { | ||
const self = this | ||
if (!this.opened) return readyAndHead(this, cb) | ||
if (this._checkout !== 0) return this.getBySeq(this._checkout - 1, cb) | ||
if (this.feed.length < 2) return process.nextTick(cb, null, null) | ||
this.getBySeq(this.feed.length - 1, cb) | ||
if (this.alwaysUpdate) this.feed.update({ hash: false, ifAvailable: true }, onupdated) | ||
else process.nextTick(onupdated) | ||
function onupdated () { | ||
if (self.feed.length < 2) return cb(null, null) | ||
self.getBySeq(self.feed.length - 1, cb) | ||
} | ||
} | ||
@@ -138,0 +146,0 @@ |
{ | ||
"name": "hypertrie", | ||
"version": "3.8.0", | ||
"version": "4.0.0", | ||
"description": "Distributed single writer key/value store", | ||
@@ -9,3 +9,3 @@ "main": "index.js", | ||
"codecs": "^2.0.0", | ||
"hypercore": "^7.0.0", | ||
"hypercore": "^8.0.0", | ||
"inherits": "^2.0.3", | ||
@@ -24,2 +24,3 @@ "inspect-custom-symbol": "^1.1.0", | ||
"compare": "^2.0.0", | ||
"hypercore-protocol": "^7.1.1", | ||
"protocol-buffers": "^4.0.4", | ||
@@ -26,0 +27,0 @@ "random-access-memory": "^3.0.0", |
@@ -35,3 +35,4 @@ # hypertrie | ||
feed: aHypercore, // use this feed instead of loading storage | ||
valueEncoding: 'json' // set value encoding | ||
valueEncoding: 'json', // set value encoding | ||
alwaysUpdate: true // perform an ifAvailable update prior to every head operation | ||
} | ||
@@ -128,6 +129,8 @@ ``` | ||
#### `stream = db.replicate([options])` | ||
#### `stream = db.replicate(isInitiator, [options])` | ||
Returns a hypercore replication stream for the db. Pipe this together with another hypertrie instance. | ||
Replicate takes an `isInitiator` boolean which is used to indicate if this replication stream is the passive/active replicator. | ||
All options are forwarded to hypercores replicate method. | ||
@@ -134,0 +137,0 @@ |
@@ -77,6 +77,6 @@ const tape = require('tape') | ||
const stream = db.replicate() | ||
stream.pipe(clone.replicate()).pipe(stream) | ||
const stream = db.replicate(true) | ||
stream.pipe(clone.replicate(false)).pipe(stream) | ||
}) | ||
}) | ||
}) |
Sorry, the diff of this file is not supported yet
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
99686
31
3102
221
7
+ Addedabstract-extension@3.1.1(transitive)
+ Addedbare-events@2.5.0(transitive)
+ Addedclone@2.1.2(transitive)
+ Addeddebug@4.3.7(transitive)
+ Addedfast-fifo@1.3.2(transitive)
+ Addedhmac-blake2b@0.2.0(transitive)
+ Addedhypercore@8.14.0(transitive)
+ Addedhypercore-cache@1.0.2(transitive)
+ Addedhypercore-protocol@7.10.0(transitive)
+ Addedms@2.1.3(transitive)
+ Addednanoresource@1.3.0(transitive)
+ Addednoise-protocol@1.0.0(transitive)
+ Addedsimple-handshake@1.3.1(transitive)
+ Addedsimple-hypercore-protocol@1.5.0(transitive)
+ Addedsimple-message-channels@1.2.1(transitive)
+ Addedstreamx@2.20.2(transitive)
+ Addedtext-decoder@1.2.1(transitive)
+ Addedtimeout-refresh@1.0.3(transitive)
- Removedarray-lru@1.1.1(transitive)
- Removedhypercore@7.7.1(transitive)
- Removedhypercore-protocol@6.12.0(transitive)
- Removedsorted-indexof@1.0.0(transitive)
Updatedhypercore@^8.0.0