Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
/* eslint new-cap: 0 */
import loki from 'lokijs';
import {EventEmitter} from 'events';
import objectPath from 'object-path';
const logger = new Logger('BaseCache');
const lokiEq = loki.LokiOps.$eq;
const lokiNe = loki.LokiOps.$ne;
loki.LokiOps.$eq = function(a, b) {
if (Array.isArray(a)) {
return a.indexOf(b) !== -1;
}
return lokiEq(a, b);
};
loki.LokiOps.$ne = function(a, b) {
if (Array.isArray(a)) {
return a.indexOf(b) === -1;
}
return lokiNe(a, b);
};
/* eslint new-cap: 0 */
import loki from 'lokijs';
import {EventEmitter} from 'events';
import objectPath from 'object-path';
const logger = new Logger('BaseCache');
const lokiEq = loki.LokiOps.$eq;
const lokiNe = loki.LokiOps.$ne;
loki.LokiOps.$eq = function(a, b) {
if (Array.isArray(a)) {
return a.indexOf(b) !== -1;
}
return lokiEq(a, b);
};
loki.LokiOps.$ne = function(a, b) {
if (Array.isArray(a)) {
return a.indexOf(b) === -1;
}
return lokiNe(a, b);
};
const lokiIn = loki.LokiOps.$in;
loki.LokiOps.$in = function(a, b) {
if (Array.isArray(a)) {
return !loki.LokiOps.$in(a, b);
};
loki.LokiOps.$all = function(a, b) {
return b.every(subB => a.includes(subB));
};
loki.LokiOps.$exists = function(a, b) {
if (b) {
return loki.LokiOps.$ne(a, undefined);
}
return loki.LokiOps.$eq(a, undefined);
};
loki.LokiOps.$elemMatch = function(a, b) {
return _.findWhere(a, b);
};
const ignore = [
'emit',
'load',
'on',
'addToAllIndexes'
];
function traceMethodCalls(target) {
target._stats = {};
for (const property in target) {
if (typeof target[property] === 'function' && ignore.indexOf(property) === -1) {
target._stats[property] = {
loki.LokiOps.$exists = function(a, b) {
if (b) {
return loki.LokiOps.$ne(a, undefined);
}
return loki.LokiOps.$eq(a, undefined);
};
import {EventEmitter} from 'events';
import objectPath from 'object-path';
const logger = new Logger('BaseCache');
const lokiEq = loki.LokiOps.$eq;
const lokiNe = loki.LokiOps.$ne;
loki.LokiOps.$eq = function(a, b) {
if (Array.isArray(a)) {
return a.indexOf(b) !== -1;
}
return lokiEq(a, b);
};
loki.LokiOps.$ne = function(a, b) {
if (Array.isArray(a)) {
return a.indexOf(b) === -1;
}
return lokiNe(a, b);
};
const lokiIn = loki.LokiOps.$in;
loki.LokiOps.$in = function(a, b) {
if (Array.isArray(a)) {
return a.some(subA => lokiIn(subA, b));
}
return lokiIn(a, b);
};
loki.LokiOps.$nin = function(a, b) {
return !loki.LokiOps.$in(a, b);
loki.LokiOps.$in = function(a, b) {
if (Array.isArray(a)) {
return a.some(subA => lokiIn(subA, b));
}
return lokiIn(a, b);
};
loki.LokiOps.$nin = function(a, b) {
return !loki.LokiOps.$in(a, b);
};
loki.LokiOps.$all = function(a, b) {
return b.every(subB => a.includes(subB));
};
loki.LokiOps.$exists = function(a, b) {
if (b) {
return loki.LokiOps.$ne(a, undefined);
}
return loki.LokiOps.$eq(a, undefined);
};
loki.LokiOps.$elemMatch = function(a, b) {
return _.findWhere(a, b);
};
const ignore = [
'emit',
'load',
'on',
'addToAllIndexes'
return lokiNe(a, b);
};
const lokiIn = loki.LokiOps.$in;
loki.LokiOps.$in = function(a, b) {
if (Array.isArray(a)) {
return a.some(subA => lokiIn(subA, b));
}
return lokiIn(a, b);
};
loki.LokiOps.$nin = function(a, b) {
return !loki.LokiOps.$in(a, b);
};
loki.LokiOps.$all = function(a, b) {
return b.every(subB => a.includes(subB));
};
loki.LokiOps.$exists = function(a, b) {
if (b) {
return loki.LokiOps.$ne(a, undefined);
}
return loki.LokiOps.$eq(a, undefined);
};
loki.LokiOps.$elemMatch = function(a, b) {
return _.findWhere(a, b);
};
const ignore = [
loki.LokiOps.$eq = function(a, b) {
if (Array.isArray(a)) {
return a.indexOf(b) !== -1;
}
return lokiEq(a, b);
};
loki.LokiOps.$ne = function(a, b) {
if (Array.isArray(a)) {
return a.indexOf(b) === -1;
}
return lokiNe(a, b);
};
const lokiIn = loki.LokiOps.$in;
loki.LokiOps.$in = function(a, b) {
if (Array.isArray(a)) {
return a.some(subA => lokiIn(subA, b));
}
return lokiIn(a, b);
};
loki.LokiOps.$nin = function(a, b) {
return !loki.LokiOps.$in(a, b);
};
loki.LokiOps.$all = function(a, b) {
return b.every(subB => a.includes(subB));
};
loki.LokiOps.$exists = function(a, b) {
if (b) {
loki.LokiOps.$ne = function(a, b) {
if (Array.isArray(a)) {
return a.indexOf(b) === -1;
}
return lokiNe(a, b);
};
const lokiIn = loki.LokiOps.$in;
loki.LokiOps.$in = function(a, b) {
if (Array.isArray(a)) {
return a.some(subA => lokiIn(subA, b));
}
return lokiIn(a, b);
};
loki.LokiOps.$nin = function(a, b) {
return !loki.LokiOps.$in(a, b);
};
loki.LokiOps.$all = function(a, b) {
return b.every(subB => a.includes(subB));
};
loki.LokiOps.$exists = function(a, b) {
if (b) {
return loki.LokiOps.$ne(a, undefined);
}
return loki.LokiOps.$eq(a, undefined);
};
loki.LokiOps.$elemMatch = function(a, b) {
const Loki = require('lokijs')
const autoBind = require('auto-bind')
const NodeIndex = require('./NodeIndex')
const EventEmitter = require('eventemitter3')
const { deprecate } = require('../utils/deprecate')
const { isArray, isPlainObject } = require('lodash')
const Collection = require('./Collection')
const { safeKey } = require('../utils')
const lokiOps = require('./lokiOps')
const { SyncWaterfallHook } = require('tapable')
const SyncBailWaterfallHook = require('../app/SyncBailWaterfallHook')
Object.assign(Loki.LokiOps, lokiOps)
class Store {
constructor (app) {
this.app = app
this.collections = {}
this.nodeIndex = new NodeIndex(app)
this._events = new EventEmitter()
this.lastUpdate = null
this.setUpdateTime()
autoBind(this)
this.metadata = new Loki.Collection('core/metadata', {
unique: ['key'],
autoupdate: true