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

@theledger/couchdb-query-engine

Package Overview
Dependencies
Maintainers
2
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@theledger/couchdb-query-engine - npm Package Compare versions

Comparing version 1.5.0 to 1.5.1

288

lib/engine.js

@@ -18,236 +18,122 @@ "use strict";

function _sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
function _slicedToArray(arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return _sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
var Engine =
/*#__PURE__*/
function () {
function Engine() {
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
_ref$virtuals = _ref.virtuals,
virtuals = _ref$virtuals === void 0 ? [] : _ref$virtuals,
_ref$conditions = _ref.conditions,
conditions = _ref$conditions === void 0 ? [] : _ref$conditions,
_ref$expansions = _ref.expansions,
expansions = _ref$expansions === void 0 ? [] : _ref$expansions;
_classCallCheck(this, Engine);
class Engine {
constructor({
virtuals = [],
conditions = [],
expansions = []
} = {}) {
this.registry = {
virtuals: virtuals,
conditions: conditions,
expansions: expansions
virtuals,
conditions,
expansions
};
}
_createClass(Engine, [{
key: "clone",
value: function clone() {
return new Engine({
virtuals: this.registry.virtuals.slice(),
conditions: this.registry.conditions.slice(),
expansions: this.registry.expansions.slice()
});
}
}, {
key: "append2",
value: function append2(d) {
for (var t in d) {
if (t === 'expansions' || t === 'virtuals' || t === 'conditions') {
for (var k in d[t]) {
var f = d[t][k];
this.append(t, k, f);
}
clone() {
return new Engine({
virtuals: this.registry.virtuals.slice(),
conditions: this.registry.conditions.slice(),
expansions: this.registry.expansions.slice()
});
}
append2(d) {
for (const t in d) {
if (t === 'expansions' || t === 'virtuals' || t === 'conditions') {
for (let k in d[t]) {
let f = d[t][k];
this.append(t, k, f);
}
}
}
}, {
key: "append",
value: function append(t, k, f) {
this.registry[t].push([k, f]);
}
}, {
key: "prepend",
value: function prepend(t, k, f) {
this.registry[t].shift([k, f]);
}
}, {
key: "replace",
value: function replace(t, k, f) {
var _rule = this.rule(k),
_rule2 = _slicedToArray(_rule, 1),
tk = _rule2[0];
}
if (tk) {
this.registry[tk][k] = f;
} else {
this.append(t, k, f);
}
} // Find rule with k name.
append(t, k, f) {
this.registry[t].push([k, f]);
}
}, {
key: "rule",
value: function rule(k) {
var r = [undefined, undefined];
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
prepend(t, k, f) {
this.registry[t].shift([k, f]);
}
try {
for (var _iterator = (0, _utils.kvs)(this.registry)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var _ref4 = _step.value;
replace(t, k, f) {
const [tk] = this.rule(k);
var _ref3 = _slicedToArray(_ref4, 2);
if (tk) {
this.registry[tk][k] = f;
} else {
this.append(t, k, f);
}
} // Find rule with k name.
var _tk = _ref3[0];
var _tv = _ref3[1];
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
try {
for (var _iterator2 = _tv[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var _ref7 = _step2.value;
rule(k) {
let r = [undefined, undefined];
var _ref6 = _slicedToArray(_ref7, 2);
var _rk = _ref6[0];
var _rf = _ref6[1];
if (k === _rk) {
r = [_tk, _rf];
break;
}
}
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
_iterator2.return();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
}
}
for (const [tk, tv] of (0, _utils.kvs)(this.registry)) {
for (const [rk, rf] of tv) {
if (k === rk) {
r = [tk, rf];
break;
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
return r;
}
}, {
key: "test",
value: function test(d) {
var q = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var r = true;
if (is.leaf(q)) {
// Implicit equality.
r = r && (0, _same.default)(d, q);
} else {
var _iteratorNormalCompletion3 = true;
var _didIteratorError3 = false;
var _iteratorError3 = undefined;
return r;
}
try {
for (var _iterator3 = (0, _utils.kvs)(q)[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
var _ref10 = _step3.value;
test(d, q = {}) {
let r = true;
var _ref9 = _slicedToArray(_ref10, 2);
if (is.leaf(q)) {
// Implicit equality.
r = r && (0, _same.default)(d, q);
} else {
for (const [qk, qv] of (0, _utils.kvs)(q)) {
if (qk[0] === '$') {
const [t, f] = this.rule(qk);
var _qk = _ref9[0];
var _qv = _ref9[1];
switch (t) {
case 'expansions':
r = r && this.test(d, f);
break;
if (_qk[0] === '$') {
var _rule3 = this.rule(_qk),
_rule4 = _slicedToArray(_rule3, 2),
t = _rule4[0],
f = _rule4[1];
case 'virtuals':
r = r && this.test(f.bind(this)(d, qv), qv);
break;
switch (t) {
case 'expansions':
r = r && this.test(d, f);
break;
case 'conditions':
r = r && f.bind(this)(d, qv, q);
break;
case 'virtuals':
r = r && this.test(f.bind(this)(d, _qv), _qv);
break;
default:
throw new Error(`Unknown rule ${qk}`);
}
case 'conditions':
r = r && f.bind(this)(d, _qv, q);
break;
if (r === false) {
break;
}
} else {
// Allow " $foo" to reference "$foo" attributes.
const tqk = (0, _utils.decoded)(qk);
const [dvp, dk] = (0, _utils.resolve)(d, tqk) || [];
default:
throw new Error("Unknown rule ".concat(_qk));
}
if (r === false) {
break;
}
} else {
// Allow " $foo" to reference "$foo" attributes.
var tqk = (0, _utils.decoded)(_qk);
var _ref11 = (0, _utils.resolve)(d, tqk) || [],
_ref12 = _slicedToArray(_ref11, 2),
dvp = _ref12[0],
dk = _ref12[1];
if (dvp !== null && dk.length === 1) {
// ...it's resolved.
r = r && this.test(dvp[dk[0]], _qv);
} else {
// We can still match `{ $exists: false }`, possibly in nested
// `{ $or: [] }`.
r = r && this.test(undefined, _qv);
}
}
if (dvp !== null && dk.length === 1) {
// ...it's resolved.
r = r && this.test(dvp[dk[0]], qv);
} else {
// We can still match `{ $exists: false }`, possibly in nested
// `{ $or: [] }`.
r = r && this.test(undefined, qv);
}
} catch (err) {
_didIteratorError3 = true;
_iteratorError3 = err;
} finally {
try {
if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
_iterator3.return();
}
} finally {
if (_didIteratorError3) {
throw _iteratorError3;
}
}
}
}
return r;
}
}]);
return Engine;
}();
return r;
}
}
exports.default = Engine;
module.exports = exports["default"];

@@ -13,7 +13,7 @@ "use strict";

var mongo = new _engine.default(); // Comparision
const mongo = new _engine.default(); // Comparision
var rules = ['eq', 'ne', 'gt', 'gte', 'lt', 'lte', 'in', 'nin', 'or', 'and', 'nor', 'not', 'exists', 'type', 'mod', 'regex', 'all', 'elem-match', 'size'];
rules.forEach(function (rule) {
mongo.append2(require("../rules/".concat(rule)));
const rules = ['eq', 'ne', 'gt', 'gte', 'lt', 'lte', 'in', 'nin', 'or', 'and', 'nor', 'not', 'exists', 'type', 'mod', 'regex', 'all', 'elem-match', 'size'];
rules.forEach(rule => {
mongo.append2(require(`../rules/${rule}`));
});

@@ -45,12 +45,12 @@ /**

var result = [];
const result = [];
for (var key in data) {
var value = data[key];
var positive = mongo.test(value, query.selector);
for (const key in data) {
const value = data[key];
const positive = mongo.test(value, query.selector);
if (positive) {
result.push({
key: key,
value: value
key,
value
});

@@ -60,5 +60,5 @@ }

var skip = query.skip || 0;
var limit = query.limit || result.length;
const skip = query.skip || 0;
const limit = query.limit || result.length;
return result.slice(skip, limit);
}

@@ -12,16 +12,12 @@ "use strict";

function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function array(a) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
function array(a, options = {}) {
if (is.array(a)) {
if (options.length !== undefined) {
if (options.length !== a.length) {
throw new TypeError("Expected array with length ".concat(options.length, ", got length ").concat(a.length, "."));
throw new TypeError(`Expected array with length ${options.length}, got length ${a.length}.`);
}
}
} else {
throw new TypeError("Expected array, got ".concat(_typeof(a), "."));
throw new TypeError(`Expected array, got ${typeof a}.`);
}
}

@@ -8,3 +8,3 @@ "use strict";

enumerable: true,
get: function get() {
get: function () {
return _mongo.parseQuery;

@@ -15,3 +15,3 @@ }

enumerable: true,
get: function get() {
get: function () {
return _mongo.test;

@@ -18,0 +18,0 @@ }

@@ -20,4 +20,2 @@ "use strict";

function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function rep(a, b) {

@@ -36,3 +34,3 @@ return Object.prototype.toString.call(a) === b;

function object(a) {
return _typeof(a) === 'object' && a !== null;
return typeof a === 'object' && a !== null;
}

@@ -50,5 +48,3 @@

function strings(a) {
return array(a) && a.every(function (e) {
return string(e);
});
return array(a) && a.every(e => string(e));
}

@@ -78,3 +74,3 @@

function leaf(a) {
var r = true;
let r = true;

@@ -81,0 +77,0 @@ switch (true) {

@@ -14,6 +14,4 @@ "use strict";

conditions: {
$all: function $all(d, q) {
return is.array(d) && is.array(q) && q.every(function (e) {
return d.indexOf(e) >= 0;
});
$all: function (d, q) {
return is.array(d) && is.array(q) && q.every(e => d.indexOf(e) >= 0);
}

@@ -20,0 +18,0 @@ }

@@ -14,9 +14,5 @@ "use strict";

conditions: {
$and: function $and(d, q) {
var _this = this;
$and: function (d, q) {
ensure.array(q);
return q.reduce(function (p, c) {
return p && _this.test(d, c);
}, true);
return q.reduce((p, c) => p && this.test(d, c), true);
}

@@ -23,0 +19,0 @@ }

@@ -15,3 +15,3 @@ "use strict";

// Evaluates to true if all conditions are not met, false otherwise.
$array: function $array(d, q) {
$array: function (d, q) {
return _is.default.array(d) ^ q;

@@ -18,0 +18,0 @@ }

@@ -14,8 +14,4 @@ "use strict";

conditions: {
$elemMatch: function $elemMatch(d, q) {
var _this = this;
return is.array(d) && d.some(function (e) {
return _this.test(e, q);
});
$elemMatch: function (d, q) {
return is.array(d) && d.some(e => this.test(e, q));
}

@@ -22,0 +18,0 @@ }

@@ -14,3 +14,3 @@ "use strict";

conditions: {
$eq: function $eq(d, q) {
$eq: function (d, q) {
return (0, _same.default)(d, q);

@@ -17,0 +17,0 @@ }

@@ -15,8 +15,4 @@ "use strict";

// Evaluates to true if all conditions are met, false otherwise.
$none: function $none(d, q) {
var _this = this;
return _is.default.array(d) && d.every(function (e) {
return _this.test(e, q);
});
$none: function (d, q) {
return _is.default.array(d) && d.every(e => this.test(e, q));
}

@@ -23,0 +19,0 @@ }

@@ -14,3 +14,3 @@ "use strict";

conditions: {
$exists: function $exists(d, q) {
$exists: function (d, q) {
return !(!!q ^ !is.none(d));

@@ -17,0 +17,0 @@ }

@@ -9,3 +9,3 @@ "use strict";

conditions: {
$gt: function $gt(d, q) {
$gt: function (d, q) {
return d > q;

@@ -12,0 +12,0 @@ }

@@ -9,3 +9,3 @@ "use strict";

conditions: {
$gte: function $gte(d, q) {
$gte: function (d, q) {
return d >= q;

@@ -12,0 +12,0 @@ }

@@ -13,4 +13,4 @@ "use strict";

// Evaluates to true if provided value is in array document.
$in: function $in(d, q) {
var ad = (0, _utils.arrize)(d);
$in: function (d, q) {
let ad = (0, _utils.arrize)(d);
return (0, _utils.arrize)(q).some(function (e) {

@@ -17,0 +17,0 @@ return ad.indexOf(e) >= 0;

@@ -12,9 +12,7 @@ "use strict";

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
var _default = {
conditions: {
// Evaluates to true if provided rule name prefixed with $ evaluates to true.
$is: function $is(d, q) {
var r = false;
$is: function (d, q) {
let r = false;

@@ -24,3 +22,5 @@ switch (true) {

case is.string(q):
r = this.test(d, _defineProperty({}, "$".concat(q), true));
r = this.test(d, {
[`$${q}`]: true
});
break;

@@ -32,3 +32,5 @@ // Any of provided rules, ie: { foo: { $is: [ 'number', 'string' ] } }

$or: q.map(function (e) {
return _defineProperty({}, "$".concat(e), true);
return {
[`$${e}`]: true
};
})

@@ -35,0 +37,0 @@ });

@@ -15,4 +15,4 @@ "use strict";

// Returns keys of values.
$keys: function $keys(d) {
var r = undefined;
$keys: function (d) {
let r = undefined;

@@ -19,0 +19,0 @@ try {

@@ -10,4 +10,4 @@ "use strict";

// Returns length of arrays, strings and all objects with .length property.
$length: function $length(d) {
var r = undefined;
$length: function (d) {
let r = undefined;

@@ -14,0 +14,0 @@ if (d != null && d.hasOwnProperty('length')) {

@@ -9,3 +9,3 @@ "use strict";

conditions: {
$lt: function $lt(d, q) {
$lt: function (d, q) {
return d < q;

@@ -12,0 +12,0 @@ }

@@ -9,3 +9,3 @@ "use strict";

conditions: {
$lte: function $lte(d, q) {
$lte: function (d, q) {
return d <= q;

@@ -12,0 +12,0 @@ }

@@ -14,3 +14,3 @@ "use strict";

conditions: {
$mod: function $mod(d, q) {
$mod: function (d, q) {
ensure.array(q, {

@@ -17,0 +17,0 @@ length: 2

@@ -14,3 +14,3 @@ "use strict";

conditions: {
$ne: function $ne(d, q) {
$ne: function (d, q) {
return !(0, _same.default)(d, q);

@@ -17,0 +17,0 @@ }

@@ -13,4 +13,4 @@ "use strict";

// Evaluates to true if provided value is not in array document.
$nin: function $nin(d, q) {
var da = (0, _utils.arrize)(d);
$nin: function (d, q) {
let da = (0, _utils.arrize)(d);
return (0, _utils.arrize)(q).every(function (e) {

@@ -17,0 +17,0 @@ return da.indexOf(e) < 0;

@@ -15,8 +15,4 @@ "use strict";

// Evaluates to true if all conditions are not met, false otherwise.
$none: function $none(d, q) {
var _this = this;
return _is.default.array(d) && !d.every(function (e) {
return _this.test(e, q);
});
$none: function (d, q) {
return _is.default.array(d) && !d.every(e => this.test(e, q));
}

@@ -23,0 +19,0 @@ }

@@ -14,9 +14,5 @@ "use strict";

conditions: {
$nor: function $nor(d, q) {
var _this = this;
$nor: function (d, q) {
ensure.array(q);
return q.reduce(function (p, c) {
return p && !_this.test(d, c);
}, true);
return q.reduce((p, c) => p && !this.test(d, c), true);
}

@@ -23,0 +19,0 @@ }

@@ -14,3 +14,3 @@ "use strict";

conditions: {
$not: function $not(d, q) {
$not: function (d, q) {
return !this.test(d, q);

@@ -17,0 +17,0 @@ }

@@ -15,4 +15,4 @@ "use strict";

// HACK: To support $regex's $options.
$options: function $options(d, q, p) {
var r = false;
$options: function (d, q, p) {
let r = false;

@@ -22,3 +22,3 @@ if (!is.none(p.$regex)) {

} else {
throw new TypeError("$options reserved for $regex.");
throw new TypeError(`$options reserved for $regex.`);
}

@@ -25,0 +25,0 @@

@@ -14,9 +14,5 @@ "use strict";

conditions: {
$or: function $or(d, q) {
var _this = this;
$or: function (d, q) {
ensure.array(q);
return q.reduce(function (p, c) {
return p || _this.test(d, c);
}, false);
return q.reduce((p, c) => p || this.test(d, c), false);
}

@@ -23,0 +19,0 @@ }

@@ -14,3 +14,3 @@ "use strict";

conditions: {
$regex: function $regex(d, q, p) {
$regex: function (d, q, p) {
return !!d.match(new RegExp(q, p.$options));

@@ -17,0 +17,0 @@ }

@@ -14,3 +14,3 @@ "use strict";

conditions: {
$size: function $size(d, q) {
$size: function (d, q) {
return q === (is.array(d) ? d.length : 0);

@@ -17,0 +17,0 @@ }

@@ -15,8 +15,4 @@ "use strict";

// Evaluates to true if at least one condition is met, false otherwise.
$none: function $none(d, q) {
var _this = this;
return _is.default.array(d) && d.some(function (e) {
return _this.test(e, q);
});
$none: function (d, q) {
return _is.default.array(d) && d.some(e => this.test(e, q));
}

@@ -23,0 +19,0 @@ }

@@ -17,10 +17,10 @@ "use strict";

// TODO: q true, false, 1, -1
$sorted: function $sorted(d, q) {
var r = false; // Comparision direction.
$sorted: function (d, q) {
let r = false; // Comparision direction.
var cmp = undefined;
let cmp = undefined;
switch (q) {
case -1:
cmp = function cmp(a, b) {
cmp = function (a, b) {
return a >= b;

@@ -32,3 +32,3 @@ };

default:
cmp = function cmp(a, b) {
cmp = function (a, b) {
return a <= b;

@@ -41,7 +41,7 @@ };

var rm = undefined;
let rm = undefined;
switch (q) {
case false:
rm = function rm(r) {
rm = function (r) {
return !r;

@@ -53,3 +53,3 @@ };

default:
rm = function rm(r) {
rm = function (r) {
return r;

@@ -63,5 +63,5 @@ };

r = true;
var n = d.length;
let n = d.length;
for (var i = 1; i < n; i++) {
for (let i = 1; i < n; i++) {
if (!cmp(d[i - 1], d[i])) {

@@ -68,0 +68,0 @@ r = false;

@@ -15,3 +15,3 @@ "use strict";

// Matches strings with specified date-time format.
$strftime: function $strftime(d, q) {
$strftime: function (d, q) {
return strftime.test(q, d);

@@ -18,0 +18,0 @@ }

@@ -7,9 +7,6 @@ "use strict";

exports.default = void 0;
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
var _default = {
conditions: {
$type: function $type(d, q) {
return _typeof(d) === q;
$type: function (d, q) {
return typeof d === q;
}

@@ -16,0 +13,0 @@ }

@@ -15,3 +15,3 @@ "use strict";

// Evaluates to true if value is an array with unique values.
$unique: function $unique(d, q) {
$unique: function (d, q) {
throw new Error('TODO');

@@ -18,0 +18,0 @@ return false;

@@ -9,3 +9,3 @@ "use strict";

conditions: {
$where: function $where(d, q) {
$where: function (d, q) {
return q(d);

@@ -12,0 +12,0 @@ }

@@ -14,7 +14,6 @@ "use strict";

// Return true if arrays are the same.
function arrays(a, b) {
var sort = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
var r = true;
var an = a.length;
var bn = b.length;
function arrays(a, b, sort = false) {
let r = true;
let an = a.length;
let bn = b.length;

@@ -27,3 +26,3 @@ if (an === bn) {

for (var i = 0; i < an; i++) {
for (let i = 0; i < an; i++) {
if (a[i] !== b[i]) {

@@ -43,3 +42,3 @@ r = false;

function same(a, b) {
var r = false;
let r = false;

@@ -74,9 +73,7 @@ switch (true) {

default:
var aks = Object.keys(a);
var bks = Object.keys(b);
let aks = Object.keys(a);
let bks = Object.keys(b);
if (arrays(aks, bks, true)) {
r = aks.every(function (k) {
return same(a[k], b[k]);
});
r = aks.every(k => same(a[k], b[k]));
}

@@ -83,0 +80,0 @@

@@ -8,6 +8,2 @@ "use strict";

function _sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
function _slicedToArray(arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return _sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }
function strsplice(a, i, n, b) {

@@ -17,3 +13,3 @@ return a.slice(0, i) + (b || '') + str.slice(i + n);

var fmt = {
let fmt = {
// Day

@@ -87,9 +83,9 @@ '%a': /(Sun|Mon|Tue|Wed|Thu|Fri|Sat)/,

};
var max = 1023;
let max = 1023;
function test_(f, d) {
var r = false;
var i = 0;
var j = 0;
var err = null;
let r = false;
let i = 0;
let j = 0;
let err = null;

@@ -101,5 +97,5 @@ if (typeof f === 'string' && typeof d === 'string' && f.length < max) {

if (f[i] === '%') {
var t = f.substr(i, 2); // console.log('t', t, f, i)
let t = f.substr(i, 2); // console.log('t', t, f, i)
var u = fmt[t];
let u = fmt[t];

@@ -111,3 +107,3 @@ if (u) {

} else {
var m = d.substr(j).match(fmt[t]);
let m = d.substr(j).match(fmt[t]);

@@ -119,9 +115,7 @@ if (m) {

} else {
err = new Error("invalid input for ".concat(t));
r = false;
[err, r] = [new Error(`invalid input for ${t}`), false];
}
}
} else {
err = new Error("unknown token ".concat(t));
r = false;
[err, r] = [new Error(`unknown token ${t}`), false];
}

@@ -134,4 +128,3 @@ } else {

} else {
err = new Error("direct match failed ".concat(f[i], " != ").concat(d[j]));
r = false;
[err, r] = [new Error(`direct match failed ${f[i]} != ${d[j]}`), false];
}

@@ -143,9 +136,7 @@ }

if (i !== f.length) {
err = new Error("invalid extras");
r = false;
[err, r] = [new Error(`invalid extras`), false];
}
if (j !== d.length) {
err = new Error("not fully matched");
r = false;
[err, r] = [new Error(`not fully matched`), false];
}

@@ -159,10 +150,4 @@ }

function test(a, b) {
var _test_ = test_(a, b),
_test_2 = _slicedToArray(_test_, 4),
err = _test_2[0],
r = _test_2[1],
i = _test_2[2],
j = _test_2[3];
let [err, r, i, j] = test_(a, b);
return r;
}

@@ -25,10 +25,2 @@ "use strict";

var _marked =
/*#__PURE__*/
regeneratorRuntime.mark(kvs);
function _sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
function _slicedToArray(arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return _sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }
// S.R. Petrick, "A Direct Determination of the Irredundant Forms of a Boolean Function from the Set of Prime Implicants"

@@ -38,40 +30,20 @@ // Technical Report AFCRC-TR-56-110, Air Force Cambridge Research Center, Cambridge, Mass., Apr. 1956.

// Get prime implicants.
var F = {};
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
let F = {};
try {
for (var _iterator = minterms[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var _minterm = _step.value;
if (_minterm[2] !== 'v') {
if (!F[_minterm[0]]) {
F[_minterm[0]] = _minterm[3];
}
for (let minterm of minterms) {
if (minterm[2] !== 'v') {
if (!F[minterm[0]]) {
F[minterm[0]] = minterm[3];
}
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
var P = [];
var PO = {};
var alpha = 'abcdefghijklmnopqrstuvwxy';
var ALPHA = 'ABCDEFGHIJKLMNOPQRSTUVWXY';
let P = [];
let PO = {};
let alpha = 'abcdefghijklmnopqrstuvwxy';
let ALPHA = 'ABCDEFGHIJKLMNOPQRSTUVWXY';
for (var k in F) {
var v = F[k];
var pk = k.split('').map(function (e, i) {
for (let k in F) {
let v = F[k];
let pk = k.split('').map(function (e, i) {
return {

@@ -82,34 +54,11 @@ '0': ALPHA[i],

}[e];
}).filter(function (e) {
return e;
}).join('');
}).filter(e => e).join('');
P.push([pk, v]);
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
try {
for (var _iterator2 = v[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var _pi = _step2.value;
PO[_pi] = true;
}
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
_iterator2.return();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
}
for (let pi of v) {
PO[pi] = true;
}
}
var PI = Object.keys(PO).map(function (e) {
return parseInt(e);
}).sort(); // console.log('P:')
let PI = Object.keys(PO).map(e => parseInt(e)).sort(); // console.log('P:')
// P.forEach(function (p, i) {

@@ -123,4 +72,4 @@ // console.log(`P${i}`, p[0], p[1].join(', '))

var PR = PI.map(function (pi) {
var r = [];
let PR = PI.map(function (pi) {
let r = [];
P.forEach(function (e, i) {

@@ -131,19 +80,13 @@ if (e[1].indexOf(pi) !== -1) {

});
return r.map(function (e) {
return "P".concat(e);
});
return r.map(e => `P${e}`);
}); // console.log('PR:', PR.map((e) => `(${e.join(' + ')})`).join(' '))
var PM = PR.map(function (e) {
return e.map(function (f) {
return [f];
});
});
let PM = PR.map(e => e.map(f => [f]));
while (PM.length > 1) {
var p = PM.pop();
p.forEach(function (e) {
e.forEach(function (e2) {
PM.forEach(function (f) {
f.forEach(function (g) {
let p = PM.pop();
p.forEach(e => {
e.forEach(e2 => {
PM.forEach(f => {
f.forEach(g => {
if (g.indexOf(e2) === -1) {

@@ -160,4 +103,4 @@ g.push(e2);

return PM[0].map(function (e) {
return e.map(function (f) {
return PM[0].map(e => {
return e.map(f => {
return P[parseInt(f.substr(1))][0];

@@ -169,17 +112,9 @@ }).join('');

function patrics2(minterms) {
var P = patrics(minterms);
var alpha = 'abcdefghijklmnopqrstuvwxy';
var ALPHA = 'ABCDEFGHIJKLMNOPQRSTUVWXY';
var or = P.split('+').map(function (p) {
var and = p.split('').map(function (e) {
return alpha.indexOf(e);
}).filter(function (e) {
return e !== -1;
});
var nor = p.split('').map(function (e) {
return ALPHA.indexOf(e);
}).filter(function (e) {
return e !== -1;
});
var r = {};
let P = patrics(minterms);
let alpha = 'abcdefghijklmnopqrstuvwxy';
let ALPHA = 'ABCDEFGHIJKLMNOPQRSTUVWXY';
let or = P.split('+').map(function (p) {
let and = p.split('').map(e => alpha.indexOf(e)).filter(e => e !== -1);
let nor = p.split('').map(e => ALPHA.indexOf(e)).filter(e => e !== -1);
let r = {};

@@ -217,7 +152,7 @@ if (and.length > 0) {

function diff(a, b) {
var r = [];
var n = 0;
var f = false;
let r = [];
let n = 0;
let f = false;
for (var i = 0; i < a.length; i++) {
for (let i = 0; i < a.length; i++) {
if (a[i] === '0' && b[i] === '1' || a[i] === '1' && b[i] === '0') {

@@ -248,9 +183,9 @@ r.push('-');

function combine1(i) {
var r = [];
let r = [];
for (; i < minterms.length; i++) {
var o = minterms[i][1];
let o = minterms[i][1];
for (var j = i + 1; j < minterms.length; j++) {
var od = minterms[j][1] - o;
for (let j = i + 1; j < minterms.length; j++) {
let od = minterms[j][1] - o;

@@ -262,40 +197,15 @@ if (od === 0) {

if (od === 1) {
var d = diff(minterms[i][0], minterms[j][0]);
let d = diff(minterms[i][0], minterms[j][0]);
if (d) {
var _1s = d.split('').filter(function (e) {
return e === '1';
}).length;
let _1s = d.split('').filter(e => e === '1').length;
minterms[i][2] = 'v';
minterms[j][2] = 'v';
var k = [];
var _arr = [minterms[i][3], minterms[j][3]];
let k = [];
for (var _i = 0; _i < _arr.length; _i++) {
var z = _arr[_i];
var _iteratorNormalCompletion3 = true;
var _didIteratorError3 = false;
var _iteratorError3 = undefined;
try {
for (var _iterator3 = z[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
var _l = _step3.value;
if (k.indexOf(_l) === -1) {
k.push(_l);
}
for (let z of [minterms[i][3], minterms[j][3]]) {
for (let l of z) {
if (k.indexOf(l) === -1) {
k.push(l);
}
} catch (err) {
_didIteratorError3 = true;
_iteratorError3 = err;
} finally {
try {
if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
_iterator3.return();
}
} finally {
if (_didIteratorError3) {
throw _iteratorError3;
}
}
}

@@ -313,4 +223,3 @@ }

for (var _i2 = 0; _i2 < r.length; _i2++) {
var e = r[_i2];
for (let e of r) {
minterms.push(e);

@@ -323,6 +232,6 @@ }

{
var i = 0;
let i = 0;
while (true) {
var j = combine1(i);
let j = combine1(i);

@@ -340,13 +249,9 @@ if (i == j) {

function minterms(q, n) {
var r = [];
let r = [];
var _loop = function _loop(i) {
for (let i = 0; i < 2 ** n; i++) {
// String binary representation.
var s = new Array(n).fill('0').map(function (e, j) {
return 1 << j & i ? '1' : '0';
}).join(''); // Number of 1s.
let s = new Array(n).fill('0').map((e, j) => 1 << j & i ? '1' : '0').join(''); // Number of 1s.
var _1s = s.split('').filter(function (e) {
return e === '1';
}).length;
let _1s = s.split('').filter(e => e === '1').length;

@@ -356,12 +261,6 @@ if (itest(q, i)) {

}
};
for (var i = 0; i < Math.pow(2, n); i++) {
_loop(i);
} // Sort by count of 1s.
r.sort(function (a, b) {
return a[1] - b[1];
});
r.sort((a, b) => a[1] - b[1]);
return r;

@@ -371,22 +270,14 @@ }

function itest2(qa, qb, n) {
var r = true;
let r = true;
var _loop2 = function _loop2(i) {
var ra = itest(qa, i);
var rb = itest(qb, i);
for (let i = 0; i < 2 ** n; i++) {
let ra = itest(qa, i);
let rb = itest(qb, i);
if (ra !== rb) {
var s = new Array(n).fill('0').map(function (e, j) {
return 1 << j & i ? '1' : '0';
}).join('');
console.error("".concat(ra, " !== ").concat(rb, " for ").concat(s));
let s = new Array(n).fill('0').map((e, j) => 1 << j & i ? '1' : '0').join('');
console.error(`${ra} !== ${rb} for ${s}`);
r = false;
return "break";
break;
}
};
for (var i = 0; i < Math.pow(2, n); i++) {
var _ret = _loop2(i);
if (_ret === "break") break;
}

@@ -403,3 +294,3 @@

function itest(q, i) {
var r = false;
let r = false;

@@ -410,3 +301,3 @@ if (is.number(q)) {

r = ['$and', '$or', '$nor', '$not'].every(function (k) {
var r = true;
let r = true;

@@ -418,17 +309,11 @@ if (is.none(q[k])) {

case '$and':
r = q[k].every(function (e) {
return itest(e, i);
});
r = q[k].every(e => itest(e, i));
break;
case '$or':
r = q[k].some(function (e) {
return itest(e, i);
});
r = q[k].some(e => itest(e, i));
break;
case '$nor':
r = q[k].every(function (e) {
return !itest(e, i);
});
r = q[k].every(e => !itest(e, i));
break;

@@ -451,44 +336,18 @@

function map(q, f) {
var r = null;
let r = null;
if (is.plain(q)) {
r = {};
var d = {}; // Split fragment and query parts.
let d = {}; // Split fragment and query parts.
var _iteratorNormalCompletion4 = true;
var _didIteratorError4 = false;
var _iteratorError4 = undefined;
try {
for (var _iterator4 = kvs(q)[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
var _ref3 = _step4.value;
var _ref2 = _slicedToArray(_ref3, 2);
var _k = _ref2[0];
var _v = _ref2[1];
if (['$and', '$or', '$nor'].indexOf(_k) !== -1) {
r[_k] = map(_v, f);
} else {
d[_k] = _v;
}
for (let [k, v] of kvs(q)) {
if (['$and', '$or', '$nor'].indexOf(k) !== -1) {
r[k] = map(v, f);
} else {
d[k] = v;
}
} catch (err) {
_didIteratorError4 = true;
_iteratorError4 = err;
} finally {
try {
if (!_iteratorNormalCompletion4 && _iterator4.return != null) {
_iterator4.return();
}
} finally {
if (_didIteratorError4) {
throw _iteratorError4;
}
}
}
if (!is.leaf(d)) {
var fd = f(d);
let fd = f(d);

@@ -505,5 +364,3 @@ if (is.leaf(r)) {

if (is.array(q)) {
r = q.map(function (e) {
return map(e, f);
});
r = q.map(e => map(e, f));
} else {

@@ -518,39 +375,13 @@ r = f(q);

function unmap(q, fs) {
var r = null;
let r = null;
if (is.plain(q)) {
r = {};
var _iteratorNormalCompletion5 = true;
var _didIteratorError5 = false;
var _iteratorError5 = undefined;
try {
for (var _iterator5 = kvs(q)[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) {
var _ref6 = _step5.value;
var _ref5 = _slicedToArray(_ref6, 2);
var _k2 = _ref5[0];
var _v2 = _ref5[1];
r[_k2] = unmap(_v2, fs);
}
} catch (err) {
_didIteratorError5 = true;
_iteratorError5 = err;
} finally {
try {
if (!_iteratorNormalCompletion5 && _iterator5.return != null) {
_iterator5.return();
}
} finally {
if (_didIteratorError5) {
throw _iteratorError5;
}
}
for (let [k, v] of kvs(q)) {
r[k] = unmap(v, fs);
}
} else {
if (is.array(q)) {
r = q.map(function (e) {
return unmap(e, fs);
});
r = q.map(e => unmap(e, fs));
} else {

@@ -571,6 +402,6 @@ r = fs[q][1];

function decoded(qk) {
var r = qk;
var trim = false;
let r = qk;
let trim = false;
loop: for (var i = 0; i < qk.length; i++) {
loop: for (let i = 0; i < qk.length; i++) {
switch (qk[i]) {

@@ -599,3 +430,3 @@ case ' ':

function split(a) {
var r = undefined;
let r = undefined;

@@ -613,4 +444,4 @@ if (a[0] === ' ') {

function resolve(a, path) {
var stack = split(path);
var last = [];
let stack = split(path);
let last = [];

@@ -621,4 +452,4 @@ if (stack.length > 0) {

var k = undefined;
var e = a;
let k = undefined;
let e = a;

@@ -648,44 +479,10 @@ if (!is.none(e)) {

function kvs(a) {
var _arr2, _i3, k;
return regeneratorRuntime.wrap(function kvs$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
if (!is.object(a)) {
_context.next = 11;
break;
}
_arr2 = Object.keys(a);
_i3 = 0;
case 3:
if (!(_i3 < _arr2.length)) {
_context.next = 11;
break;
}
k = _arr2[_i3];
if (!a.hasOwnProperty(k)) {
_context.next = 8;
break;
}
_context.next = 8;
return [k, a[k]];
case 8:
_i3++;
_context.next = 3;
break;
case 11:
case "end":
return _context.stop();
function* kvs(a) {
if (is.object(a)) {
for (let k of Object.keys(a)) {
if (a.hasOwnProperty(k)) {
yield [k, a[k]];
}
}
}, _marked, this);
}
}
{
"name": "@theledger/couchdb-query-engine",
"version": "1.5.0",
"version": "1.5.1",
"description": "Evaluate and filters criteria queries on JSON objects MongoDB style",

@@ -10,3 +10,3 @@ "main": "./lib/index.js",

"test:prod": "cross-env BABEL_ENV=production npm run test",
"test:only": "mocha --require @babel/register --require babel-polyfill --recursive",
"test:only": "mocha --require @babel/register --require @babel/polyfill --recursive",
"test:watch": "npm test -- --watch",

@@ -13,0 +13,0 @@ "cover": "istanbul cover _mocha -- --require @babel/register --require @babel/polyfill --recursive",

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