orbit-db-eventstore
Advanced tools
Comparing version 0.1.1 to 0.1.2
{ | ||
"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 |
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
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
5162
6
87
1
50
4
+ Addedlodash.findindex@^4.6.0
+ Addedlodash.slice@^4.2.0
+ Addedlodash.take@^4.1.1
+ Addedlodash.findindex@4.6.0(transitive)
+ Addedlodash.slice@4.2.0(transitive)
- Removedlazy.js@^0.4.2
- Removedlazy.js@0.4.3(transitive)