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

orbit-db-eventstore

Package Overview
Dependencies
Maintainers
1
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

orbit-db-eventstore - npm Package Compare versions

Comparing version 0.1.1 to 0.1.2

README.md

6

package.json
{
"name": "orbit-db-eventstore",
"version": "0.1.1",
"version": "0.1.2",
"description": "Eventlog for orbit-db",

@@ -12,5 +12,7 @@ "main": "src/EventStore.js",

"dependencies": {
"lazy.js": "^0.4.2",
"lodash.findindex": "^4.6.0",
"lodash.slice": "^4.2.0",
"lodash.take": "^4.1.1",
"orbit-db-store": "0.1.3"
}
}

@@ -1,10 +0,10 @@

'use strict';
'use strict'
class EventIndex {
constructor() {
this._index = {};
this._index = {}
}
get() {
return Object.keys(this._index).map((f) => this._index[f]);
return Object.keys(this._index).map((f) => this._index[f])
}

@@ -14,12 +14,12 @@

added.reduce((handled, item) => {
if(handled.indexOf(item.hash) === -1) {
handled.push(item.hash);
if(!handled.includes(item.hash)) {
handled.push(item.hash)
if(item.payload.op === 'ADD')
this._index[item.hash] = item
}
return handled;
}, []);
return handled
}, [])
}
}
module.exports = EventIndex;
module.exports = EventIndex

@@ -1,11 +0,12 @@

'use strict';
'use strict'
const Lazy = require('lazy.js');
const Store = require('orbit-db-store');
const EventIndex = require('./EventIndex');
const slice = require('lodash.slice')
const take = require('lodash.take')
const findIndex = require('lodash.findIndex')
const Store = require('orbit-db-store')
const EventIndex = require('./EventIndex')
class EventStore extends Store {
constructor(ipfs, id, dbname, options) {
if(!options) options = {};
if(options.Index === undefined) Object.assign(options, { Index: EventIndex });
constructor(ipfs, id, dbname, options = {}) {
if(options.Index === undefined) Object.assign(options, { Index: EventIndex })
super(ipfs, id, dbname, options)

@@ -22,23 +23,23 @@ }

}
});
})
}
get(hash) {
return this.iterator({ gte: hash, limit: 1 }).collect()[0];
return this.iterator({ gte: hash, limit: 1 }).collect()[0]
}
iterator(options) {
const messages = this._query(this.dbname, options);
let currentIndex = 0;
const messages = this._query(this.dbname, options)
let currentIndex = 0
let iterator = {
[Symbol.iterator]() {
return this;
return this
},
next() {
let item = { value: null, done: true };
let item = { value: null, done: true }
if(currentIndex < messages.length) {
item = { value: messages[currentIndex], done: false };
currentIndex ++;
item = { value: messages[currentIndex], done: false }
currentIndex ++
}
return item;
return item
},

@@ -48,11 +49,11 @@ collect: () => messages

return iterator;
return iterator
}
_query(dbname, opts) {
if(!opts) opts = {};
if(!opts) opts = {}
const amount = opts.limit ? (opts.limit > -1 ? opts.limit : this._index.get().length) : 1; // Return 1 if no limit is provided
const events = this._index.get();
let result = [];
const amount = opts.limit ? (opts.limit > -1 ? opts.limit : this._index.get().length) : 1 // Return 1 if no limit is provided
const events = this._index.get()
let result = []

@@ -67,15 +68,15 @@ if(opts.gt || opts.gte) {

if(opts.reverse) result.reverse();
return result.toArray();
return result
}
_read(ops, hash, amount, inclusive) {
return Lazy(ops)
.skipWhile((f) => hash && f.hash !== hash)
.drop(inclusive ? 0 : 1)
.take(amount);
// Find the index of the gt/lt hash, or start from the beginning of the array if not found
let startIndex = Math.max(findIndex(ops, (e) => e.hash === hash), 0)
// If gte/lte is set, we include the given hash, if not, start from the next element
startIndex += (inclusive ? 0 : 1)
// Slice the array to its requested size
return take(ops.slice(startIndex), amount)
}
}
module.exports = EventStore;
module.exports = EventStore
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