Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hyperbee

Package Overview
Dependencies
Maintainers
2
Versions
111
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hyperbee - npm Package Compare versions

Comparing version 1.5.5 to 1.6.0

48

index.js

@@ -400,3 +400,3 @@ const codecs = require('codecs')

const ite = new RangeIterator(new Batch(this, false, false, opts), opts)
const ite = new RangeIterator(new Batch(this, null, false, opts), opts)
return ite

@@ -412,3 +412,3 @@ }

opts = { active, ...opts }
return iteratorToStream(new HistoryIterator(new Batch(this, false, false, opts), opts), active)
return iteratorToStream(new HistoryIterator(new Batch(this, null, false, opts), opts), active)
}

@@ -421,7 +421,7 @@

else opts = { ...opts, active }
return iteratorToStream(new DiffIterator(new Batch(this, false, false, opts), new Batch(right, false, false, opts), opts), active)
return iteratorToStream(new DiffIterator(new Batch(this, null, false, opts), new Batch(right, null, false, opts), opts), active)
}
get (key, opts) {
const b = new Batch(this, false, true, { ...opts })
const b = new Batch(this, null, true, { ...opts })
return b.get(key)

@@ -431,3 +431,3 @@ }

put (key, value, opts) {
const b = new Batch(this, true, true, opts)
const b = new Batch(this, null, true, opts)
return b.put(key, value)

@@ -437,7 +437,7 @@ }

batch (opts) {
return new Batch(this, false, true, opts)
return new Batch(this, mutexify(), true, opts)
}
del (key, opts) {
const b = new Batch(this, true, true, opts)
const b = new Batch(this, null, true, opts)
return b.del(key)

@@ -484,3 +484,3 @@ }

class Batch {
constructor (tree, autoFlush, cache, options = {}) {
constructor (tree, batchLock, cache, options = {}) {
this.tree = tree

@@ -490,3 +490,3 @@ this.keyEncoding = tree.keyEncoding

this.blocks = cache ? new Map() : null
this.autoFlush = autoFlush
this.autoFlush = !batchLock
this.rootSeq = 0

@@ -498,2 +498,3 @@ this.root = null

this.locked = null
this.batchLock = batchLock
this.onseq = this.options.onseq || noop

@@ -578,4 +579,15 @@ }

async put (key, value) {
const release = this.batchLock ? await this.batchLock() : null
if (!this.locked) await this.lock()
if (!release) return this._put(key, value)
try {
return await this._put(key, value)
} finally {
release()
}
}
async _put (key, value) {
key = enc(this.keyEncoding, key)

@@ -642,4 +654,15 @@ value = enc(this.valueEncoding, value)

async del (key) {
const release = this.batchLock ? await this.batchLock() : null
if (!this.locked) await this.lock()
if (!release) return this._del(key)
try {
return await this._del(key)
} finally {
release()
}
}
async _del (key) {
key = enc(this.keyEncoding, key)

@@ -684,2 +707,9 @@

destroy () {
this.root = null
this.blocks.clear()
this.length = 0
this._unlock()
}
flush () {

@@ -686,0 +716,0 @@ if (!this.length) return Promise.resolve()

2

package.json
{
"name": "hyperbee",
"version": "1.5.5",
"version": "1.6.0",
"description": "An append-only Btree running on a Hypercore.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -41,7 +41,7 @@ # Hyperbee 🐝

Some of the internals are still being tweaked but overall the API and feature set is pretty
stable if you want to try it out.
Some of the internals are still being tweaked, but overall the API and feature set is pretty
stable, if you want to try it out.
All of the above methods work with sparse feeds, meaning only a small subset of the full
feed is downloaded to satisfy you queries.
feed is downloaded to satisfy your queries.

@@ -100,2 +100,7 @@ ## API

#### `batch.destroy()`
Destroy a batch and releases any locks it has aquired on the db.
Call this if you want to abort a batch without flushing it.
#### `stream = db.createReadStream([options])`

@@ -102,0 +107,0 @@

@@ -80,1 +80,25 @@ const { create, collect } = require('./helpers')

})
tape('batches can survive parallel ops', async function (t) {
const db = create()
const a = db.batch()
const expected = []
const p = []
for (let i = 0; i < 100; i++) {
const key = 'i-' + i
const value = key
expected.push({ seq: 1 + i, key, value })
p.push(a.put(key, value))
}
expected.sort((a, b) => a.key < b.key ? -1 : a.key > b.key ? 1 : 0)
await Promise.all(p)
await a.flush()
const all = await collect(db.createReadStream())
t.same(all, expected)
t.end()
})
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc