Comparing version 0.0.0 to 0.0.1
58
index.js
const codecs = require('codecs') | ||
const { Readable } = require('streamx') | ||
const RangeIterator = require('./iterators/range') | ||
const HistoryIterator = require('./iterators/history') | ||
const Extension = require('./lib/extension') | ||
const { YoloIndex, Node } = require('./messages') | ||
const { YoloIndex, Node, Header } = require('./lib/messages') | ||
@@ -230,3 +231,3 @@ const T = 5 | ||
class BTree { | ||
class HyperBee { | ||
constructor (feed, opts = {}) { | ||
@@ -254,3 +255,3 @@ this.feed = feed | ||
if (this.feed.length > 0 || !this.feed.writable) return resolve() | ||
this.feed.append('header', (err) => { | ||
this.feed.append(Header.encode({ protocol: 'hyperbee' }), (err) => { | ||
if (err) return reject(err) | ||
@@ -290,3 +291,3 @@ resolve() | ||
if (this.keyEncoding) entry.key = this.keyEncoding.decode(entry.key) | ||
if (this.valueEncoding) entry.value = this.valueEncoding.decode(entry.value) | ||
if (this.valueEncoding && entry.value) entry.value = this.valueEncoding.decode(entry.value) | ||
resolve(new BlockEntry(seq, batch, entry)) | ||
@@ -301,23 +302,4 @@ }) | ||
createHistoryStream () { | ||
let seq = 1 | ||
const tree = this | ||
return new Readable({ | ||
open (cb) { | ||
tree.feed.ready(cb) | ||
}, | ||
read (cb) { | ||
if (seq >= tree.feed.length) { | ||
this.push(null) | ||
return cb(null) | ||
} | ||
tree.feed.get(seq, { valueEncoding: Node }, (err, data) => { | ||
if (err) return cb(err) | ||
this.push(new BlockEntry(seq++, tree, data)) | ||
cb(null) | ||
}) | ||
} | ||
}) | ||
createHistoryStream (opts) { | ||
return iteratorToStream(new HistoryIterator(new Batch(this, false, false, opts), opts)) | ||
} | ||
@@ -345,3 +327,3 @@ | ||
checkout (version) { | ||
return new BTree(this.feed, { | ||
return new HyperBee(this.feed, { | ||
checkout: version, | ||
@@ -357,17 +339,2 @@ extension: this.extension, | ||
} | ||
async debugToString () { | ||
return require('tree-to-string')(await load(await this.getRoot())) | ||
async function load (node) { | ||
const res = { values: [], children: [] } | ||
for (let i = 0; i < node.keys.length; i++) { | ||
res.values.push((await node.getKey(i)).toString()) | ||
} | ||
for (let i = 0; i < node.children.length; i++) { | ||
res.children.push(await load(await node.getChildNode(i))) | ||
} | ||
return res | ||
} | ||
} | ||
} | ||
@@ -391,2 +358,6 @@ | ||
get version () { | ||
return this.tree.version + this.length | ||
} | ||
getRoot () { | ||
@@ -455,2 +426,3 @@ if (this.root !== null) return this.root | ||
if (typeof key === 'string') key = Buffer.from(key) | ||
if (value && this.valueEncoding) value = this.valueEncoding.encode(value) | ||
@@ -607,3 +579,3 @@ const stack = [] | ||
key: this.tree.keyEncoding ? this.tree.keyEncoding.encode(key) : key, | ||
value: this.tree.valueEncoding ? this.tree.valueEncoding.encode(value) : value, | ||
value, | ||
index: deflate(index) | ||
@@ -729,2 +701,2 @@ })) | ||
module.exports = BTree | ||
module.exports = HyperBee |
@@ -1,2 +0,2 @@ | ||
const { Extension } = require('../messages') | ||
const { Extension } = require('./messages') | ||
@@ -3,0 +3,0 @@ class Batch { |
{ | ||
"name": "hyperbee", | ||
"version": "0.0.0", | ||
"description": "", | ||
"version": "0.0.1", | ||
"description": "An append-only Btree running on a Hypercore.", | ||
"main": "index.js", | ||
@@ -9,15 +9,26 @@ "dependencies": { | ||
"protocol-buffers-encodings": "^1.1.0", | ||
"streamx": "^2.6.6", | ||
"tree-to-string": "^1.1.1" | ||
"streamx": "^2.6.6" | ||
}, | ||
"devDependencies": { | ||
"hypercore": "^9.5.0", | ||
"protocol-buffers": "^4.2.0", | ||
"random-access-memory": "^3.1.1", | ||
"tape": "^5.0.1" | ||
"standard": "^14.3.4", | ||
"tape": "^5.0.1", | ||
"tree-to-string": "^1.1.1" | ||
}, | ||
"scripts": { | ||
"test": "tape test/*.js" | ||
"test": "standard && tape test/*.js", | ||
"protobuf": "protocol-buffers schema.proto -o ./lib/messages.js" | ||
}, | ||
"author": "", | ||
"license": "ISC" | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/mafintosh/hyperbee.git" | ||
}, | ||
"author": "Mathias Buus (@mafintosh)", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/mafintosh/hyperbee/issues" | ||
}, | ||
"homepage": "https://github.com/mafintosh/hyperbee" | ||
} |
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
Mixed license
License(Experimental) Package contains multiple licenses.
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
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
52606
3
2223
15
1646
0
1
0
40
1
6
1
- Removedtree-to-string@^1.1.1
- Removedtree-to-string@1.1.1(transitive)