Comparing version 2.0.0 to 2.0.1
@@ -1,21 +0,17 @@ | ||
const Hyperb = require('../../') | ||
const hypercore = require('hypercore') | ||
const Hyperbee = require('../../') | ||
const Hypercore = require('hypercore') | ||
const Hyperswarm = require('hyperswarm') | ||
const db = new Hyperb(hypercore('./db-clone', '95c4bff66d3faa78cf8c70bd070089e5e25b4c9bcbbf6ce5eb98e47b3129ca93', { sparse: true })) | ||
const db = new Hyperbee(new Hypercore('./db-clone', '95c4bff66d3faa78cf8c70bd070089e5e25b4c9bcbbf6ce5eb98e47b3129ca93')) | ||
const swarm = new Hyperswarm() | ||
const swarm = require('@hyperswarm/replicator')(db.feed, { | ||
announce: true, | ||
lookup: true, | ||
live: true | ||
}) | ||
swarm.on('connection', c => db.feed.replicate(c)) | ||
db.feed.timeouts.update = function (cb) { | ||
swarm.flush(function () { | ||
db.feed.timeouts.update = (cb) => cb() | ||
cb() | ||
}) | ||
} | ||
db.feed.ready(function () { | ||
console.log('Feed key: ' + db.feed.key.toString('hex')) | ||
const done = db.feed.findingPeers() | ||
swarm.join(db.feed.discoveryKey) | ||
swarm.flush().then(done, done) | ||
}) | ||
@@ -22,0 +18,0 @@ |
@@ -1,7 +0,7 @@ | ||
const Hyperb = require('../../') | ||
const hypercore = require('hypercore') | ||
const Hyperbee = require('../../') | ||
const Hypercore = require('hypercore') | ||
const split2 = require('split2') | ||
const fs = require('fs') | ||
const db = new Hyperb(hypercore('./db')) | ||
const db = new Hyperbee(new Hypercore('./db')) | ||
@@ -8,0 +8,0 @@ main() |
@@ -1,7 +0,7 @@ | ||
const Hyperb = require('../../') | ||
const hypercore = require('hypercore') | ||
const Hyperbee = require('../../') | ||
const Hypercore = require('hypercore') | ||
const split2 = require('split2') | ||
const fs = require('fs') | ||
const db = new Hyperb(hypercore('./db')) | ||
const db = new Hyperbee(new Hypercore('./db')) | ||
@@ -8,0 +8,0 @@ main() |
@@ -7,7 +7,6 @@ { | ||
"dependencies": { | ||
"@hyperswarm/replicator": "^1.7.2", | ||
"hypercore": "^9.5.0", | ||
"split2": "^3.1.1" | ||
"hypercore": "^10.0.0", | ||
"hyperswarm": "^4.2.0", | ||
"split2": "^4.1.0" | ||
}, | ||
"devDependencies": {}, | ||
"scripts": { | ||
@@ -14,0 +13,0 @@ "test": "echo \"Error: no test specified\" && exit 1" |
@@ -1,16 +0,15 @@ | ||
const Hyperb = require('../../') | ||
const hypercore = require('hypercore') | ||
const Hyperbee = require('../../') | ||
const Hypercore = require('hypercore') | ||
const Hyperswarm = require('hyperswarm') | ||
const db = new Hyperb(hypercore('./db', { sparse: true })) | ||
const db = new Hyperbee(new Hypercore('./db')) | ||
const swarm = new Hyperswarm() | ||
require('@hyperswarm/replicator')(db.feed, { | ||
announce: true, | ||
lookup: true, | ||
live: true | ||
}) | ||
swarm.on('connection', c => db.feed.replicate(c)) | ||
db.feed.ready(function () { | ||
db.feed.ready().then(function () { | ||
console.log('Feed key: ' + db.feed.key.toString('hex')) | ||
swarm.join(db.feed.discoveryKey) | ||
}) | ||
module.exports = db |
42
index.js
@@ -272,3 +272,3 @@ const codecs = require('codecs') | ||
class HyperBee { | ||
class Hyperbee { | ||
constructor (feed, opts = {}) { | ||
@@ -308,34 +308,2 @@ this.feed = feed | ||
async getRoot (ensureHeader, opts, batch = this) { | ||
await this.ready() | ||
if (ensureHeader) { | ||
if (this.feed.length === 0 && this.feed.writable && !this.readonly) { | ||
await this.feed.append(Header.encode({ | ||
protocol: 'hyperbee', | ||
metadata: this.metadata | ||
})) | ||
} | ||
} | ||
if (this._checkout === 0 && (opts && opts.update) !== false) await this.update() | ||
const len = this._checkout || this.feed.length | ||
if (len < 2) return null | ||
return (await batch.getBlock(len - 1, opts)).getTreeNode(0) | ||
} | ||
async getKey (seq) { | ||
return (await this.getBlock(seq)).key | ||
} | ||
async getBlock (seq, opts, batch = this) { | ||
const active = opts.active | ||
const request = this.feed.get(seq, { ...opts, valueEncoding: Node }) | ||
if (active) active.add(request) | ||
try { | ||
const entry = await request | ||
return new BlockEntry(seq, batch, entry) | ||
} finally { | ||
if (active) active.remove(request) | ||
} | ||
} | ||
async peek (opts) { | ||
@@ -423,3 +391,3 @@ // copied from the batch since we can then use the iterator warmup ext... | ||
checkout (version) { | ||
return new HyperBee(this.feed.snapshot(), { | ||
return new Hyperbee(this.feed.snapshot(), { | ||
_ready: this.ready(), | ||
@@ -449,3 +417,3 @@ _sub: false, | ||
return new HyperBee(this.feed, { | ||
return new Hyperbee(this.feed, { | ||
_ready: this.ready(), | ||
@@ -525,3 +493,3 @@ _sub: true, | ||
async getBlock (seq, opts) { | ||
async getBlock (seq, opts = this.options) { | ||
if (this.rootSeq === 0) this.rootSeq = seq | ||
@@ -962,2 +930,2 @@ let b = this.blocks && this.blocks.get(seq) | ||
module.exports = HyperBee | ||
module.exports = Hyperbee |
{ | ||
"name": "hyperbee", | ||
"version": "2.0.0", | ||
"description": "An append-only Btree running on a Hypercore.", | ||
"version": "2.0.1", | ||
"description": "An append-only B-tree running on a Hypercore.", | ||
"main": "index.js", | ||
@@ -14,6 +14,6 @@ "dependencies": { | ||
"devDependencies": { | ||
"brittle": "^3.0.4", | ||
"brittle": "^3.1.0", | ||
"hypercore": "^10.0.0", | ||
"protocol-buffers": "^4.2.0", | ||
"random-access-memory": "^5.0.0", | ||
"random-access-memory": "^6.0.0", | ||
"standard": "^17.0.0", | ||
@@ -28,3 +28,3 @@ "tree-to-string": "^1.1.1" | ||
"type": "git", | ||
"url": "https://github.com/mafintosh/hyperbee.git" | ||
"url": "https://github.com/hypercore-protocol/hyperbee.git" | ||
}, | ||
@@ -34,5 +34,5 @@ "author": "Mathias Buus (@mafintosh)", | ||
"bugs": { | ||
"url": "https://github.com/mafintosh/hyperbee/issues" | ||
"url": "https://github.com/hypercore-protocol/hyperbee/issues" | ||
}, | ||
"homepage": "https://github.com/mafintosh/hyperbee" | ||
"homepage": "https://github.com/hypercore-protocol/hyperbee" | ||
} |
# Hyperbee 🐝 | ||
An append-only Btree running on a Hypercore. | ||
An append-only B-tree running on a Hypercore. | ||
Allows sorted iteration and more. | ||
@@ -5,0 +5,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
116674
23
3442