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

orbit-db-feedstore

Package Overview
Dependencies
Maintainers
1
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

orbit-db-feedstore - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

8

package.json
{
"name": "orbit-db-feedstore",
"version": "0.0.1",
"version": "0.0.2",
"description": "Feed store for orbit-db",

@@ -10,3 +10,7 @@ "main": "src/FeedStore.js",

"author": "Haad",
"license": "MIT"
"license": "MIT",
"dependencies": {
"lazy.js": "^0.4.2",
"orbit-db-eventstore": "0.0.4"
}
}
'use strict';
class FeedIndex {
constructor() {
this._index = {};
}
const EventIndex = require('orbit-db-eventstore/src/EventIndex');
get() {
return Object.keys(this._index).map((f) => this._index[f]);
}
class FeedIndex extends EventIndex {
updateIndex(oplog, added) {

@@ -13,0 +7,0 @@ added.reduce((handled, item) => {

'use strict';
const Lazy = require('lazy.js');
const Store = require('orbit-db-store');
const EventIndex = require('./FeedIndex');
const EventStore = require('orbit-db-eventstore');
const FeedIndex = require('./FeedIndex');
class FeedStore extends Store {
class FeedStore extends EventStore {
constructor(ipfs, id, dbname, options) {
Object.assign(options || {}, { Index: EventIndex });
Object.assign(options || {}, { Index: FeedIndex });
super(ipfs, id, dbname, options)
}
add(data) {
const operation = {
op: 'ADD',
key: null,
value: data,
meta: {
ts: new Date().getTime()
}
};
return this._addOperation(operation);
}
remove(hash) {

@@ -36,52 +24,4 @@ const operation = {

}
iterator(options) {
const messages = this._query(this.dbname, options);
let currentIndex = 0;
let iterator = {
[Symbol.iterator]() {
return this;
},
next() {
let item = { value: null, done: true };
if(currentIndex < messages.length) {
item = { value: messages[currentIndex], done: false };
currentIndex ++;
}
return item;
},
collect: () => messages
}
return iterator;
}
_query(dbname, 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 operations = this._index.get();
let result = [];
if(opts.gt || opts.gte) {
// Greater than case
result = this._read(operations, opts.gt ? opts.gt : opts.gte, amount, opts.gte ? true : false)
} else {
// Lower than and lastN case, search latest first by reversing the sequence
result = this._read(operations.reverse(), opts.lt ? opts.lt : opts.lte, amount, opts.lte || !opts.lt).reverse()
}
if(opts.reverse) result.reverse();
return result.toArray();
}
_read(ops, hash, amount, inclusive) {
return Lazy(ops)
.skipWhile((f) => hash && f.hash !== hash)
.drop(inclusive ? 0 : 1)
.take(amount);
}
}
module.exports = FeedStore;
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