Comparing version 4.0.1 to 4.2.0
@@ -40,2 +40,3 @@ const Node = require('./lib/node') | ||
this.metadata = opts.metadata || null | ||
this.hash = opts.hash || null | ||
this.valueEncoding = opts.valueEncoding ? codecs(opts.valueEncoding) : null | ||
@@ -238,3 +239,3 @@ this.alwaysUpdate = !!opts.alwaysUpdate | ||
if (err) return cb(err) | ||
const node = Node.decode(val, seq, self.valueEncoding) | ||
const node = Node.decode(val, seq, self.valueEncoding, self.hash) | ||
// early exit for the key: '' nodes we write to reset the db | ||
@@ -241,0 +242,0 @@ if (!node.value && !node.key) return cb(null, null) |
@@ -14,3 +14,3 @@ const Put = require('./put') | ||
this._condition = condition | ||
this._node = new Node({key, flags: hidden ? Node.Flags.HIDDEN : 0}) | ||
this._node = new Node({key, flags: hidden ? Node.Flags.HIDDEN : 0}, null, null, db.hash) | ||
this._length = this._node.length | ||
@@ -17,0 +17,0 @@ this._returnClosest = closest |
@@ -7,3 +7,3 @@ const Node = require('./node') | ||
this._db = db | ||
this._node = new Node({key, flags: (opts && opts.hidden) ? Node.Flags.HIDDEN : 0}, 0, null) | ||
this._node = new Node({key, flags: (opts && opts.hidden) ? Node.Flags.HIDDEN : 0}, 0, null, db.hash) | ||
this._callback = cb | ||
@@ -10,0 +10,0 @@ this._prefix = !!(opts && opts.prefix) |
@@ -14,3 +14,3 @@ const sodium = require('sodium-universal') | ||
function Node (data, seq, enc) { | ||
function Node (data, seq, enc, userHash) { | ||
this.seq = seq || 0 | ||
@@ -21,3 +21,3 @@ this.key = normalizeKey(data.key) | ||
this.flags = data.flags || 0 | ||
this.hash = hash(this.keySplit) | ||
this.hash = userHash ? userHash(this.key) : hash(this.keySplit) | ||
this.trie = data.trieBuffer ? trie.decode(data.trieBuffer) : (data.trie || []) | ||
@@ -79,4 +79,4 @@ this.trieBuffer = null | ||
Node.decode = function (buf, seq, enc) { | ||
return new Node(messages.Node.decode(buf), seq, enc) | ||
Node.decode = function (buf, seq, enc, hash) { | ||
return new Node(messages.Node.decode(buf), seq, enc, hash) | ||
} | ||
@@ -83,0 +83,0 @@ |
@@ -23,3 +23,3 @@ const Node = require('./node') | ||
this._node = new Node({key, value, valueBuffer, flags}, 0, db.valueEncoding) | ||
this._node = new Node({key, value, valueBuffer, flags}, 0, db.valueEncoding, db.hash) | ||
this._callback = cb | ||
@@ -26,0 +26,0 @@ this._release = null |
{ | ||
"name": "hypertrie", | ||
"version": "4.0.1", | ||
"version": "4.2.0", | ||
"description": "Distributed single writer key/value store", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -511,1 +511,48 @@ const tape = require('tape') | ||
}) | ||
tape('can support a custom hash function', function (t) { | ||
const db = create(null, { | ||
valueEncoding: 'utf-8', | ||
hash: function (key) { | ||
return Buffer.from(key) | ||
} | ||
}) | ||
db.ready(function (err) { | ||
t.error(err, 'no error') | ||
db.put('hello', 'world', function (err) { | ||
t.error(err, 'no error') | ||
db.get('hello', function (err, node) { | ||
t.error(err, 'no error') | ||
t.same(node.value, 'world') | ||
t.end() | ||
}) | ||
}) | ||
}) | ||
}) | ||
tape('can delete with a custom hash function', function (t) { | ||
const db = create(null, { | ||
valueEncoding: 'utf-8', | ||
hash: function (key) { | ||
return Buffer.from(key) | ||
} | ||
}) | ||
db.ready(function (err) { | ||
t.error(err, 'no error') | ||
db.put('hello', 'world', function (err) { | ||
t.error(err, 'no error') | ||
db.get('hello', function (err, node) { | ||
t.error(err, 'no error') | ||
t.same(node.value, 'world') | ||
db.del('hello', function (err) { | ||
t.error(err, 'no error') | ||
db.get('hello', function (err, node) { | ||
t.error(err, 'no error') | ||
t.false(node) | ||
t.end() | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) |
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
102059
3178