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

hyperbee

Package Overview
Dependencies
Maintainers
1
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 0.0.7 to 0.0.8

test/history.js

35

iterators/history.js

@@ -6,6 +6,9 @@ module.exports = class HistoryIterator {

this.live = !!opts.live
this.since = opts.since || 0
this.end = 0
this.gte = 0
this.lt = 0
this.reverse = !!opts.reverse
this.limit = typeof opts.limit === 'number' ? opts.limit : -1
if (this.live && this.reverse) {
throw new Error('Cannot have both live and reverse enabled')
}
}

@@ -15,6 +18,4 @@

await this.db.getRoot() // does the update dance
this.end = this.live ? Infinity : this.db.version
if (this.since) return
if (this.reverse) this.since = this.end - 1
else this.since = 1
this.gte = gte(this.options, this.db.version)
this.lt = this.live ? Infinity : lt(this.options, this.db.version)
}

@@ -26,10 +27,24 @@

if (this.gte >= this.lt) return null
if (this.reverse) {
if (this.since < 1) return null
return (await this.db.getBlock(this.since--, this.options)).final()
if (this.lt <= 1) return null
return (await this.db.getBlock(--this.lt, this.options)).final()
}
if (this.since >= this.end) return null
return (await this.db.getBlock(this.since++, this.options)).final()
return (await this.db.getBlock(this.gte++, this.options)).final()
}
}
function gte (opts, version) {
if (opts.gt) return (opts.gt < 0 ? (opts.gt + version) : opts.gt) + 1
const gte = opts.gte || opts.since || 1
return gte < 0 ? gte + version : gte
}
function lt (opts, version) {
if (opts.lte === 0 || opts.lt === 0 || opts.end === 0) return 0
if (opts.lte) return (opts.lte < 0 ? (opts.lte + version) : opts.lte) + 1
const lt = opts.lt || opts.end || version
return lt < 0 ? lt + version : lt
}
{
"name": "hyperbee",
"version": "0.0.7",
"version": "0.0.8",
"description": "An append-only Btree running on a Hypercore.",

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

@@ -129,4 +129,8 @@ # Hyperbee 🐝

{
live: false, // if true the stream will wait for new data and never end
reverse: false, // if true get from the newest to the oldest
since: seq // start with this seq,
gte: seq, // start with this seq (inclusive)
gt: seq, // start after this index
lte: seq, // stop after this index
lt: seq, // stop before this index
limit: -1 // set to the max number of entries you want

@@ -136,2 +140,6 @@ }

If any of the gte, gt, lte, lt arguments are `< 0` then
they'll implicitly be added with the version before starting so
doing `{ gte: -1 }` makes a stream starting at the last index.
#### `stream = db.createDiffStream(otherVersion, [options])`

@@ -138,0 +146,0 @@

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