Socket
Socket
Sign inDemoInstall

sift

Package Overview
Dependencies
Maintainers
2
Versions
155
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sift - npm Package Compare versions

Comparing version 13.0.2 to 13.0.3

es/index.js

595

es5m/index.js

@@ -1,3 +0,588 @@

import * as defaultOperations from "./operations";
import { createQueryTester, EqualsOperation, createEqualsOperation } from "./core";
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
/* global Reflect, Promise */
var extendStatics = function(d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
function __extends(d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}
var typeChecker = function (type) {
var typeString = "[object " + type + "]";
return function (value) {
return getClassName(value) === typeString;
};
};
var getClassName = function (value) { return Object.prototype.toString.call(value); };
var comparable = function (value) {
if (value instanceof Date) {
return value.getTime();
}
else if (isArray(value)) {
return value.map(comparable);
}
else if (value && typeof value.toJSON === "function") {
return value.toJSON();
}
return value;
};
var isArray = typeChecker("Array");
var isObject = typeChecker("Object");
var isFunction = typeChecker("Function");
var isVanillaObject = function (value) {
return (value &&
(value.constructor === Object ||
value.constructor === Array ||
value.constructor.toString() === "function Object() { [native code] }" ||
value.constructor.toString() === "function Array() { [native code] }") &&
!value.toJSON);
};
var equals = function (a, b) {
if (a == null && a == b) {
return true;
}
if (a === b) {
return true;
}
if (Object.prototype.toString.call(a) !== Object.prototype.toString.call(b)) {
return false;
}
if (isArray(a)) {
if (a.length !== b.length) {
return false;
}
for (var i = 0, length_1 = a.length; i < length_1; i++) {
if (!equals(a[i], b[i]))
return false;
}
return true;
}
else if (isObject(a)) {
if (Object.keys(a).length !== Object.keys(b).length) {
return false;
}
for (var key in a) {
if (!equals(a[key], b[key]))
return false;
}
return true;
}
return false;
};
/**
* Walks through each value given the context - used for nested operations. E.g:
* { "person.address": { $eq: "blarg" }}
*/
var walkKeyPathValues = function (item, keyPath, next, depth, key, owner) {
var currentKey = keyPath[depth];
// if array, then try matching. Might fall through for cases like:
// { $eq: [1, 2, 3] }, [ 1, 2, 3 ].
if (isArray(item) && isNaN(Number(currentKey))) {
for (var i = 0, length_1 = item.length; i < length_1; i++) {
// if FALSE is returned, then terminate walker. For operations, this simply
// means that the search critera was met.
if (!walkKeyPathValues(item[i], keyPath, next, depth, i, item)) {
return false;
}
}
}
if (depth === keyPath.length || item == null) {
return next(item, key, owner);
}
return walkKeyPathValues(item[currentKey], keyPath, next, depth + 1, currentKey, item);
};
var BaseOperation = /** @class */ (function () {
function BaseOperation(params, owneryQuery, options) {
this.params = params;
this.owneryQuery = owneryQuery;
this.options = options;
this.init();
}
BaseOperation.prototype.init = function () { };
BaseOperation.prototype.reset = function () {
this.done = false;
this.success = false;
};
return BaseOperation;
}());
var GroupOperation = /** @class */ (function (_super) {
__extends(GroupOperation, _super);
function GroupOperation(params, owneryQuery, options, _children) {
var _this = _super.call(this, params, owneryQuery, options) || this;
_this._children = _children;
return _this;
}
/**
*/
GroupOperation.prototype.reset = function () {
this.success = false;
this.done = false;
for (var i = 0, length_2 = this._children.length; i < length_2; i++) {
this._children[i].reset();
}
};
/**
*/
GroupOperation.prototype.childrenNext = function (item, key, owner) {
var done = true;
var success = true;
for (var i = 0, length_3 = this._children.length; i < length_3; i++) {
var childOperation = this._children[i];
childOperation.next(item, key, owner);
if (!childOperation.success) {
success = false;
}
if (childOperation.done) {
if (!childOperation.success) {
break;
}
}
else {
done = false;
}
}
// console.log("DONE", this.params, done, success);
this.done = done;
this.success = success;
};
return GroupOperation;
}(BaseOperation));
var QueryOperation = /** @class */ (function (_super) {
__extends(QueryOperation, _super);
function QueryOperation() {
return _super !== null && _super.apply(this, arguments) || this;
}
/**
*/
QueryOperation.prototype.next = function (item, key, parent) {
this.childrenNext(item, key, parent);
};
return QueryOperation;
}(GroupOperation));
var NestedOperation = /** @class */ (function (_super) {
__extends(NestedOperation, _super);
function NestedOperation(keyPath, params, owneryQuery, options, children) {
var _this = _super.call(this, params, owneryQuery, options, children) || this;
_this.keyPath = keyPath;
/**
*/
_this._nextNestedValue = function (value, key, owner) {
_this.childrenNext(value, key, owner);
return !_this.done;
};
return _this;
}
/**
*/
NestedOperation.prototype.next = function (item, key, parent) {
walkKeyPathValues(item, this.keyPath, this._nextNestedValue, 0, key, parent);
};
return NestedOperation;
}(GroupOperation));
var createTester = function (a, compare) {
if (a instanceof Function) {
return a;
}
if (a instanceof RegExp) {
return function (b) { return typeof b === "string" && a.test(b); };
}
var comparableA = comparable(a);
return function (b) { return compare(comparableA, comparable(b)); };
};
var EqualsOperation = /** @class */ (function (_super) {
__extends(EqualsOperation, _super);
function EqualsOperation() {
return _super !== null && _super.apply(this, arguments) || this;
}
EqualsOperation.prototype.init = function () {
this._test = createTester(this.params, this.options.compare);
};
EqualsOperation.prototype.next = function (item, key, parent) {
if (this._test(item, key, parent)) {
this.done = true;
this.success = true;
}
};
return EqualsOperation;
}(BaseOperation));
var createEqualsOperation = function (params, owneryQuery, options) { return new EqualsOperation(params, owneryQuery, options); };
var NopeOperation = /** @class */ (function (_super) {
__extends(NopeOperation, _super);
function NopeOperation() {
return _super !== null && _super.apply(this, arguments) || this;
}
NopeOperation.prototype.next = function () {
this.done = true;
this.success = false;
};
return NopeOperation;
}(BaseOperation));
var numericalOperationCreator = function (createNumericalOperation) { return function (params, owneryQuery, options) {
if (params == null) {
return new NopeOperation(params, owneryQuery, options);
}
return createNumericalOperation(params, owneryQuery, options);
}; };
var numericalOperation = function (createTester) {
return numericalOperationCreator(function (params, owneryQuery, options) {
var typeofParams = typeof comparable(params);
var test = createTester(params);
return new EqualsOperation(function (b) {
return typeof comparable(b) === typeofParams && test(b);
}, owneryQuery, options);
});
};
var createOperation = function (name, params, parentQuery, options) {
var operationCreator = options.operations[name];
if (!operationCreator) {
throw new Error("Unsupported operation: " + name);
}
return operationCreator(params, parentQuery, options);
};
var containsOperation = function (query) {
for (var key in query) {
if (key.charAt(0) === "$")
return true;
}
return false;
};
var createNestedOperation = function (keyPath, nestedQuery, owneryQuery, options) {
if (containsOperation(nestedQuery)) {
var _a = createQueryOperations(nestedQuery, options), selfOperations = _a[0], nestedOperations = _a[1];
if (nestedOperations.length) {
throw new Error("Property queries must contain only operations, or exact objects.");
}
return new NestedOperation(keyPath, nestedQuery, owneryQuery, options, selfOperations);
}
return new NestedOperation(keyPath, nestedQuery, owneryQuery, options, [
new EqualsOperation(nestedQuery, owneryQuery, options)
]);
};
var createQueryOperation = function (query, owneryQuery, options) {
var _a = createQueryOperations(query, options), selfOperations = _a[0], nestedOperations = _a[1];
var ops = [];
if (selfOperations.length) {
ops.push(new NestedOperation([], query, owneryQuery, options, selfOperations));
}
ops.push.apply(ops, nestedOperations);
if (ops.length === 1) {
return ops[0];
}
return new QueryOperation(query, owneryQuery, options, ops);
};
var createQueryOperations = function (query, options) {
var selfOperations = [];
var nestedOperations = [];
if (!isVanillaObject(query)) {
selfOperations.push(new EqualsOperation(query, query, options));
return [selfOperations, nestedOperations];
}
for (var key in query) {
if (key.charAt(0) === "$") {
var op = createOperation(key, query[key], query, options);
// probably just a flag for another operation (like $options)
if (op != null) {
selfOperations.push(op);
}
}
else {
nestedOperations.push(createNestedOperation(key.split("."), query[key], query, options));
}
}
return [selfOperations, nestedOperations];
};
var createQueryTester = function (query, _a) {
var _b = _a === void 0 ? {} : _a, compare = _b.compare, operations = _b.operations;
var operation = createQueryOperation(query, null, {
compare: compare || equals,
operations: Object.assign({}, operations || {})
});
return function (item, key, owner) {
operation.reset();
operation.next(item, key, owner);
return operation.success;
};
};
var $Ne = /** @class */ (function (_super) {
__extends($Ne, _super);
function $Ne() {
return _super !== null && _super.apply(this, arguments) || this;
}
$Ne.prototype.init = function () {
this._test = createTester(this.params, this.options.compare);
};
$Ne.prototype.reset = function () {
_super.prototype.reset.call(this);
this.success = true;
};
$Ne.prototype.next = function (item) {
if (this._test(item)) {
this.done = true;
this.success = false;
}
};
return $Ne;
}(BaseOperation));
// https://docs.mongodb.com/manual/reference/operator/query/elemMatch/
var $ElemMatch = /** @class */ (function (_super) {
__extends($ElemMatch, _super);
function $ElemMatch() {
return _super !== null && _super.apply(this, arguments) || this;
}
$ElemMatch.prototype.init = function () {
this._queryOperation = createQueryOperation(this.params, this.owneryQuery, this.options);
};
$ElemMatch.prototype.reset = function () {
this._queryOperation.reset();
};
$ElemMatch.prototype.next = function (item, key, owner) {
this._queryOperation.reset();
if (isArray(owner)) {
this._queryOperation.next(item, key, owner);
this.done = this._queryOperation.done || key === owner.length - 1;
this.success = this._queryOperation.success;
}
else {
this.done = true;
this.success = false;
}
};
return $ElemMatch;
}(BaseOperation));
var $Not = /** @class */ (function (_super) {
__extends($Not, _super);
function $Not() {
return _super !== null && _super.apply(this, arguments) || this;
}
$Not.prototype.init = function () {
this._queryOperation = createQueryOperation(this.params, this.owneryQuery, this.options);
};
$Not.prototype.reset = function () {
this._queryOperation.reset();
};
$Not.prototype.next = function (item, key, owner) {
this._queryOperation.next(item, key, owner);
this.done = this._queryOperation.done;
this.success = !this._queryOperation.success;
};
return $Not;
}(BaseOperation));
var $Or = /** @class */ (function (_super) {
__extends($Or, _super);
function $Or() {
return _super !== null && _super.apply(this, arguments) || this;
}
$Or.prototype.init = function () {
var _this = this;
this._ops = this.params.map(function (op) {
return createQueryOperation(op, null, _this.options);
});
};
$Or.prototype.reset = function () {
this.done = false;
this.success = false;
for (var i = 0, length_1 = this._ops.length; i < length_1; i++) {
this._ops[i].reset();
}
};
$Or.prototype.next = function (item, key, owner) {
var done = false;
var success = false;
for (var i = 0, length_2 = this._ops.length; i < length_2; i++) {
var op = this._ops[i];
op.next(item, key, owner);
if (op.success) {
done = true;
success = op.success;
break;
}
}
this.success = success;
this.done = done;
};
return $Or;
}(BaseOperation));
var $Nor = /** @class */ (function (_super) {
__extends($Nor, _super);
function $Nor() {
return _super !== null && _super.apply(this, arguments) || this;
}
$Nor.prototype.next = function (item, key, owner) {
_super.prototype.next.call(this, item, key, owner);
this.success = !this.success;
};
return $Nor;
}($Or));
var $In = /** @class */ (function (_super) {
__extends($In, _super);
function $In() {
return _super !== null && _super.apply(this, arguments) || this;
}
$In.prototype.init = function () {
var _this = this;
this._testers = this.params.map(function (value) {
if (containsOperation(value)) {
throw new Error("cannot nest $ under " + _this.constructor.name.toLowerCase());
}
return createTester(value, _this.options.compare);
});
};
$In.prototype.next = function (item, key, owner) {
var done = false;
var success = false;
for (var i = 0, length_3 = this._testers.length; i < length_3; i++) {
var test = this._testers[i];
if (test(item)) {
done = true;
success = true;
break;
}
}
this.success = success;
this.done = done;
};
return $In;
}(BaseOperation));
var $Nin = /** @class */ (function (_super) {
__extends($Nin, _super);
function $Nin() {
return _super !== null && _super.apply(this, arguments) || this;
}
$Nin.prototype.next = function (item, key, owner) {
_super.prototype.next.call(this, item, key, owner);
this.success = !this.success;
};
return $Nin;
}($In));
var $Exists = /** @class */ (function (_super) {
__extends($Exists, _super);
function $Exists() {
return _super !== null && _super.apply(this, arguments) || this;
}
$Exists.prototype.next = function (item, key, owner) {
if (owner.hasOwnProperty(key) === this.params) {
this.done = true;
this.success = true;
}
};
return $Exists;
}(BaseOperation));
var $And = /** @class */ (function (_super) {
__extends($And, _super);
function $And(params, owneryQuery, options) {
return _super.call(this, params, owneryQuery, options, params.map(function (query) { return createQueryOperation(query, owneryQuery, options); })) || this;
}
$And.prototype.next = function (item, key, owner) {
this.childrenNext(item, key, owner);
};
return $And;
}(GroupOperation));
var $eq = function (params, owneryQuery, options) {
return new EqualsOperation(params, owneryQuery, options);
};
var $ne = function (params, owneryQuery, options) {
return new $Ne(params, owneryQuery, options);
};
var $or = function (params, owneryQuery, options) {
return new $Or(params, owneryQuery, options);
};
var $nor = function (params, owneryQuery, options) {
return new $Nor(params, owneryQuery, options);
};
var $elemMatch = function (params, owneryQuery, options) {
return new $ElemMatch(params, owneryQuery, options);
};
var $nin = function (params, owneryQuery, options) {
return new $Nin(params, owneryQuery, options);
};
var $in = function (params, owneryQuery, options) {
return new $In(params, owneryQuery, options);
};
var $lt = numericalOperation(function (params) { return function (b) { return b < params; }; });
var $lte = numericalOperation(function (params) { return function (b) { return b <= params; }; });
var $gt = numericalOperation(function (params) { return function (b) { return b > params; }; });
var $gte = numericalOperation(function (params) { return function (b) { return b >= params; }; });
var $mod = function (_a, owneryQuery, options) {
var mod = _a[0], equalsValue = _a[1];
return new EqualsOperation(function (b) { return comparable(b) % mod === equalsValue; }, owneryQuery, options);
};
var $exists = function (params, owneryQuery, options) { return new $Exists(params, owneryQuery, options); };
var $regex = function (pattern, owneryQuery, options) {
return new EqualsOperation(new RegExp(pattern, owneryQuery.$options), owneryQuery, options);
};
var $not = function (params, owneryQuery, options) {
return new $Not(params, owneryQuery, options);
};
var $type = function (clazz, owneryQuery, options) {
return new EqualsOperation(function (b) { return (b != null ? b instanceof clazz || b.constructor === clazz : false); }, owneryQuery, options);
};
var $and = function (params, ownerQuery, options) {
return new $And(params, ownerQuery, options);
};
var $all = $and;
var $size = function (params, ownerQuery, options) {
return new EqualsOperation(function (b) { return b && b.length === params; }, ownerQuery, options);
};
var $options = function () { return null; };
var $where = function (params, ownerQuery, options) {
var test;
if (isFunction(params)) {
test = params;
}
else if (!process.env.CSP_ENABLED) {
test = new Function("obj", "return " + params);
}
else {
throw new Error("In CSP mode, sift does not support strings in \"$where\" condition");
}
return new EqualsOperation(function (b) { return test.bind(b)(b); }, ownerQuery, options);
};
var defaultOperations = /*#__PURE__*/Object.freeze({
__proto__: null,
$eq: $eq,
$ne: $ne,
$or: $or,
$nor: $nor,
$elemMatch: $elemMatch,
$nin: $nin,
$in: $in,
$lt: $lt,
$lte: $lte,
$gt: $gt,
$gte: $gte,
$mod: $mod,
$exists: $exists,
$regex: $regex,
$not: $not,
$type: $type,
$and: $and,
$all: $all,
$size: $size,
$options: $options,
$where: $where
});
var createDefaultQueryTester = function (query, _a) {

@@ -10,5 +595,5 @@ var _b = _a === void 0 ? {} : _a, compare = _b.compare, operations = _b.operations;

};
export { EqualsOperation, createQueryTester, createEqualsOperation };
export * from "./operations";
export default createDefaultQueryTester;
//# sourceMappingURL=index.js.map
export { $all, $and, $elemMatch, $eq, $exists, $gt, $gte, $in, $lt, $lte, $mod, $ne, $nin, $nor, $not, $options, $or, $regex, $size, $type, $where, EqualsOperation, createEqualsOperation, createQueryTester };
//# sourceMappingURL=index.js.map

2

lib/core.d.ts

@@ -86,2 +86,2 @@ import { Key, Comparator } from "./utils";

export declare const createQueryOperation: (query: any, owneryQuery: any, options: Options) => any;
export declare const createQueryTester: <TItem>(query: Query, { compare, operations }?: Partial<Options>) => (item: TItem, key?: Key, owner?: any) => any;
export declare const createQueryTester: <TItem>(query: Query, { compare, operations }?: Partial<Options>) => (item: TItem, key?: string | number, owner?: any) => any;
import { Query, Options, createQueryTester, EqualsOperation, createEqualsOperation } from "./core";
declare const createDefaultQueryTester: <TItem>(query: Query, { compare, operations }?: Partial<Options>) => (item: TItem, key?: import("./utils").Key, owner?: any) => any;
declare const createDefaultQueryTester: <TItem>(query: Query, { compare, operations }?: Partial<Options>) => (item: TItem, key?: string | number, owner?: any) => any;
export { Query, EqualsOperation, createQueryTester, createEqualsOperation };
export * from "./operations";
export default createDefaultQueryTester;

@@ -1,19 +0,631 @@

"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
const defaultOperations = require("./operations");
const core_1 = require("./core");
exports.createQueryTester = core_1.createQueryTester;
exports.EqualsOperation = core_1.EqualsOperation;
exports.createEqualsOperation = core_1.createEqualsOperation;
const createDefaultQueryTester = (query, { compare, operations } = {}) => {
return core_1.createQueryTester(query, {
compare: compare,
operations: Object.assign({}, defaultOperations, operations)
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(global = global || self, factory(global.sift = {}));
}(this, (function (exports) { 'use strict';
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
/* global Reflect, Promise */
var extendStatics = function(d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
function __extends(d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}
var typeChecker = function (type) {
var typeString = "[object " + type + "]";
return function (value) {
return getClassName(value) === typeString;
};
};
var getClassName = function (value) { return Object.prototype.toString.call(value); };
var comparable = function (value) {
if (value instanceof Date) {
return value.getTime();
}
else if (isArray(value)) {
return value.map(comparable);
}
else if (value && typeof value.toJSON === "function") {
return value.toJSON();
}
return value;
};
var isArray = typeChecker("Array");
var isObject = typeChecker("Object");
var isFunction = typeChecker("Function");
var isVanillaObject = function (value) {
return (value &&
(value.constructor === Object ||
value.constructor === Array ||
value.constructor.toString() === "function Object() { [native code] }" ||
value.constructor.toString() === "function Array() { [native code] }") &&
!value.toJSON);
};
var equals = function (a, b) {
if (a == null && a == b) {
return true;
}
if (a === b) {
return true;
}
if (Object.prototype.toString.call(a) !== Object.prototype.toString.call(b)) {
return false;
}
if (isArray(a)) {
if (a.length !== b.length) {
return false;
}
for (var i = 0, length_1 = a.length; i < length_1; i++) {
if (!equals(a[i], b[i]))
return false;
}
return true;
}
else if (isObject(a)) {
if (Object.keys(a).length !== Object.keys(b).length) {
return false;
}
for (var key in a) {
if (!equals(a[key], b[key]))
return false;
}
return true;
}
return false;
};
/**
* Walks through each value given the context - used for nested operations. E.g:
* { "person.address": { $eq: "blarg" }}
*/
var walkKeyPathValues = function (item, keyPath, next, depth, key, owner) {
var currentKey = keyPath[depth];
// if array, then try matching. Might fall through for cases like:
// { $eq: [1, 2, 3] }, [ 1, 2, 3 ].
if (isArray(item) && isNaN(Number(currentKey))) {
for (var i = 0, length_1 = item.length; i < length_1; i++) {
// if FALSE is returned, then terminate walker. For operations, this simply
// means that the search critera was met.
if (!walkKeyPathValues(item[i], keyPath, next, depth, i, item)) {
return false;
}
}
}
if (depth === keyPath.length || item == null) {
return next(item, key, owner);
}
return walkKeyPathValues(item[currentKey], keyPath, next, depth + 1, currentKey, item);
};
var BaseOperation = /** @class */ (function () {
function BaseOperation(params, owneryQuery, options) {
this.params = params;
this.owneryQuery = owneryQuery;
this.options = options;
this.init();
}
BaseOperation.prototype.init = function () { };
BaseOperation.prototype.reset = function () {
this.done = false;
this.success = false;
};
return BaseOperation;
}());
var GroupOperation = /** @class */ (function (_super) {
__extends(GroupOperation, _super);
function GroupOperation(params, owneryQuery, options, _children) {
var _this = _super.call(this, params, owneryQuery, options) || this;
_this._children = _children;
return _this;
}
/**
*/
GroupOperation.prototype.reset = function () {
this.success = false;
this.done = false;
for (var i = 0, length_2 = this._children.length; i < length_2; i++) {
this._children[i].reset();
}
};
/**
*/
GroupOperation.prototype.childrenNext = function (item, key, owner) {
var done = true;
var success = true;
for (var i = 0, length_3 = this._children.length; i < length_3; i++) {
var childOperation = this._children[i];
childOperation.next(item, key, owner);
if (!childOperation.success) {
success = false;
}
if (childOperation.done) {
if (!childOperation.success) {
break;
}
}
else {
done = false;
}
}
// console.log("DONE", this.params, done, success);
this.done = done;
this.success = success;
};
return GroupOperation;
}(BaseOperation));
var QueryOperation = /** @class */ (function (_super) {
__extends(QueryOperation, _super);
function QueryOperation() {
return _super !== null && _super.apply(this, arguments) || this;
}
/**
*/
QueryOperation.prototype.next = function (item, key, parent) {
this.childrenNext(item, key, parent);
};
return QueryOperation;
}(GroupOperation));
var NestedOperation = /** @class */ (function (_super) {
__extends(NestedOperation, _super);
function NestedOperation(keyPath, params, owneryQuery, options, children) {
var _this = _super.call(this, params, owneryQuery, options, children) || this;
_this.keyPath = keyPath;
/**
*/
_this._nextNestedValue = function (value, key, owner) {
_this.childrenNext(value, key, owner);
return !_this.done;
};
return _this;
}
/**
*/
NestedOperation.prototype.next = function (item, key, parent) {
walkKeyPathValues(item, this.keyPath, this._nextNestedValue, 0, key, parent);
};
return NestedOperation;
}(GroupOperation));
var createTester = function (a, compare) {
if (a instanceof Function) {
return a;
}
if (a instanceof RegExp) {
return function (b) { return typeof b === "string" && a.test(b); };
}
var comparableA = comparable(a);
return function (b) { return compare(comparableA, comparable(b)); };
};
var EqualsOperation = /** @class */ (function (_super) {
__extends(EqualsOperation, _super);
function EqualsOperation() {
return _super !== null && _super.apply(this, arguments) || this;
}
EqualsOperation.prototype.init = function () {
this._test = createTester(this.params, this.options.compare);
};
EqualsOperation.prototype.next = function (item, key, parent) {
if (this._test(item, key, parent)) {
this.done = true;
this.success = true;
}
};
return EqualsOperation;
}(BaseOperation));
var createEqualsOperation = function (params, owneryQuery, options) { return new EqualsOperation(params, owneryQuery, options); };
var NopeOperation = /** @class */ (function (_super) {
__extends(NopeOperation, _super);
function NopeOperation() {
return _super !== null && _super.apply(this, arguments) || this;
}
NopeOperation.prototype.next = function () {
this.done = true;
this.success = false;
};
return NopeOperation;
}(BaseOperation));
var numericalOperationCreator = function (createNumericalOperation) { return function (params, owneryQuery, options) {
if (params == null) {
return new NopeOperation(params, owneryQuery, options);
}
return createNumericalOperation(params, owneryQuery, options);
}; };
var numericalOperation = function (createTester) {
return numericalOperationCreator(function (params, owneryQuery, options) {
var typeofParams = typeof comparable(params);
var test = createTester(params);
return new EqualsOperation(function (b) {
return typeof comparable(b) === typeofParams && test(b);
}, owneryQuery, options);
});
};
var createOperation = function (name, params, parentQuery, options) {
var operationCreator = options.operations[name];
if (!operationCreator) {
throw new Error("Unsupported operation: " + name);
}
return operationCreator(params, parentQuery, options);
};
var containsOperation = function (query) {
for (var key in query) {
if (key.charAt(0) === "$")
return true;
}
return false;
};
var createNestedOperation = function (keyPath, nestedQuery, owneryQuery, options) {
if (containsOperation(nestedQuery)) {
var _a = createQueryOperations(nestedQuery, options), selfOperations = _a[0], nestedOperations = _a[1];
if (nestedOperations.length) {
throw new Error("Property queries must contain only operations, or exact objects.");
}
return new NestedOperation(keyPath, nestedQuery, owneryQuery, options, selfOperations);
}
return new NestedOperation(keyPath, nestedQuery, owneryQuery, options, [
new EqualsOperation(nestedQuery, owneryQuery, options)
]);
};
var createQueryOperation = function (query, owneryQuery, options) {
var _a = createQueryOperations(query, options), selfOperations = _a[0], nestedOperations = _a[1];
var ops = [];
if (selfOperations.length) {
ops.push(new NestedOperation([], query, owneryQuery, options, selfOperations));
}
ops.push.apply(ops, nestedOperations);
if (ops.length === 1) {
return ops[0];
}
return new QueryOperation(query, owneryQuery, options, ops);
};
var createQueryOperations = function (query, options) {
var selfOperations = [];
var nestedOperations = [];
if (!isVanillaObject(query)) {
selfOperations.push(new EqualsOperation(query, query, options));
return [selfOperations, nestedOperations];
}
for (var key in query) {
if (key.charAt(0) === "$") {
var op = createOperation(key, query[key], query, options);
// probably just a flag for another operation (like $options)
if (op != null) {
selfOperations.push(op);
}
}
else {
nestedOperations.push(createNestedOperation(key.split("."), query[key], query, options));
}
}
return [selfOperations, nestedOperations];
};
var createQueryTester = function (query, _a) {
var _b = _a === void 0 ? {} : _a, compare = _b.compare, operations = _b.operations;
var operation = createQueryOperation(query, null, {
compare: compare || equals,
operations: Object.assign({}, operations || {})
});
return function (item, key, owner) {
operation.reset();
operation.next(item, key, owner);
return operation.success;
};
};
var $Ne = /** @class */ (function (_super) {
__extends($Ne, _super);
function $Ne() {
return _super !== null && _super.apply(this, arguments) || this;
}
$Ne.prototype.init = function () {
this._test = createTester(this.params, this.options.compare);
};
$Ne.prototype.reset = function () {
_super.prototype.reset.call(this);
this.success = true;
};
$Ne.prototype.next = function (item) {
if (this._test(item)) {
this.done = true;
this.success = false;
}
};
return $Ne;
}(BaseOperation));
// https://docs.mongodb.com/manual/reference/operator/query/elemMatch/
var $ElemMatch = /** @class */ (function (_super) {
__extends($ElemMatch, _super);
function $ElemMatch() {
return _super !== null && _super.apply(this, arguments) || this;
}
$ElemMatch.prototype.init = function () {
this._queryOperation = createQueryOperation(this.params, this.owneryQuery, this.options);
};
$ElemMatch.prototype.reset = function () {
this._queryOperation.reset();
};
$ElemMatch.prototype.next = function (item, key, owner) {
this._queryOperation.reset();
if (isArray(owner)) {
this._queryOperation.next(item, key, owner);
this.done = this._queryOperation.done || key === owner.length - 1;
this.success = this._queryOperation.success;
}
else {
this.done = true;
this.success = false;
}
};
return $ElemMatch;
}(BaseOperation));
var $Not = /** @class */ (function (_super) {
__extends($Not, _super);
function $Not() {
return _super !== null && _super.apply(this, arguments) || this;
}
$Not.prototype.init = function () {
this._queryOperation = createQueryOperation(this.params, this.owneryQuery, this.options);
};
$Not.prototype.reset = function () {
this._queryOperation.reset();
};
$Not.prototype.next = function (item, key, owner) {
this._queryOperation.next(item, key, owner);
this.done = this._queryOperation.done;
this.success = !this._queryOperation.success;
};
return $Not;
}(BaseOperation));
var $Or = /** @class */ (function (_super) {
__extends($Or, _super);
function $Or() {
return _super !== null && _super.apply(this, arguments) || this;
}
$Or.prototype.init = function () {
var _this = this;
this._ops = this.params.map(function (op) {
return createQueryOperation(op, null, _this.options);
});
};
$Or.prototype.reset = function () {
this.done = false;
this.success = false;
for (var i = 0, length_1 = this._ops.length; i < length_1; i++) {
this._ops[i].reset();
}
};
$Or.prototype.next = function (item, key, owner) {
var done = false;
var success = false;
for (var i = 0, length_2 = this._ops.length; i < length_2; i++) {
var op = this._ops[i];
op.next(item, key, owner);
if (op.success) {
done = true;
success = op.success;
break;
}
}
this.success = success;
this.done = done;
};
return $Or;
}(BaseOperation));
var $Nor = /** @class */ (function (_super) {
__extends($Nor, _super);
function $Nor() {
return _super !== null && _super.apply(this, arguments) || this;
}
$Nor.prototype.next = function (item, key, owner) {
_super.prototype.next.call(this, item, key, owner);
this.success = !this.success;
};
return $Nor;
}($Or));
var $In = /** @class */ (function (_super) {
__extends($In, _super);
function $In() {
return _super !== null && _super.apply(this, arguments) || this;
}
$In.prototype.init = function () {
var _this = this;
this._testers = this.params.map(function (value) {
if (containsOperation(value)) {
throw new Error("cannot nest $ under " + _this.constructor.name.toLowerCase());
}
return createTester(value, _this.options.compare);
});
};
$In.prototype.next = function (item, key, owner) {
var done = false;
var success = false;
for (var i = 0, length_3 = this._testers.length; i < length_3; i++) {
var test = this._testers[i];
if (test(item)) {
done = true;
success = true;
break;
}
}
this.success = success;
this.done = done;
};
return $In;
}(BaseOperation));
var $Nin = /** @class */ (function (_super) {
__extends($Nin, _super);
function $Nin() {
return _super !== null && _super.apply(this, arguments) || this;
}
$Nin.prototype.next = function (item, key, owner) {
_super.prototype.next.call(this, item, key, owner);
this.success = !this.success;
};
return $Nin;
}($In));
var $Exists = /** @class */ (function (_super) {
__extends($Exists, _super);
function $Exists() {
return _super !== null && _super.apply(this, arguments) || this;
}
$Exists.prototype.next = function (item, key, owner) {
if (owner.hasOwnProperty(key) === this.params) {
this.done = true;
this.success = true;
}
};
return $Exists;
}(BaseOperation));
var $And = /** @class */ (function (_super) {
__extends($And, _super);
function $And(params, owneryQuery, options) {
return _super.call(this, params, owneryQuery, options, params.map(function (query) { return createQueryOperation(query, owneryQuery, options); })) || this;
}
$And.prototype.next = function (item, key, owner) {
this.childrenNext(item, key, owner);
};
return $And;
}(GroupOperation));
var $eq = function (params, owneryQuery, options) {
return new EqualsOperation(params, owneryQuery, options);
};
var $ne = function (params, owneryQuery, options) {
return new $Ne(params, owneryQuery, options);
};
var $or = function (params, owneryQuery, options) {
return new $Or(params, owneryQuery, options);
};
var $nor = function (params, owneryQuery, options) {
return new $Nor(params, owneryQuery, options);
};
var $elemMatch = function (params, owneryQuery, options) {
return new $ElemMatch(params, owneryQuery, options);
};
var $nin = function (params, owneryQuery, options) {
return new $Nin(params, owneryQuery, options);
};
var $in = function (params, owneryQuery, options) {
return new $In(params, owneryQuery, options);
};
var $lt = numericalOperation(function (params) { return function (b) { return b < params; }; });
var $lte = numericalOperation(function (params) { return function (b) { return b <= params; }; });
var $gt = numericalOperation(function (params) { return function (b) { return b > params; }; });
var $gte = numericalOperation(function (params) { return function (b) { return b >= params; }; });
var $mod = function (_a, owneryQuery, options) {
var mod = _a[0], equalsValue = _a[1];
return new EqualsOperation(function (b) { return comparable(b) % mod === equalsValue; }, owneryQuery, options);
};
var $exists = function (params, owneryQuery, options) { return new $Exists(params, owneryQuery, options); };
var $regex = function (pattern, owneryQuery, options) {
return new EqualsOperation(new RegExp(pattern, owneryQuery.$options), owneryQuery, options);
};
var $not = function (params, owneryQuery, options) {
return new $Not(params, owneryQuery, options);
};
var $type = function (clazz, owneryQuery, options) {
return new EqualsOperation(function (b) { return (b != null ? b instanceof clazz || b.constructor === clazz : false); }, owneryQuery, options);
};
var $and = function (params, ownerQuery, options) {
return new $And(params, ownerQuery, options);
};
var $all = $and;
var $size = function (params, ownerQuery, options) {
return new EqualsOperation(function (b) { return b && b.length === params; }, ownerQuery, options);
};
var $options = function () { return null; };
var $where = function (params, ownerQuery, options) {
var test;
if (isFunction(params)) {
test = params;
}
else if (!process.env.CSP_ENABLED) {
test = new Function("obj", "return " + params);
}
else {
throw new Error("In CSP mode, sift does not support strings in \"$where\" condition");
}
return new EqualsOperation(function (b) { return test.bind(b)(b); }, ownerQuery, options);
};
var defaultOperations = /*#__PURE__*/Object.freeze({
__proto__: null,
$eq: $eq,
$ne: $ne,
$or: $or,
$nor: $nor,
$elemMatch: $elemMatch,
$nin: $nin,
$in: $in,
$lt: $lt,
$lte: $lte,
$gt: $gt,
$gte: $gte,
$mod: $mod,
$exists: $exists,
$regex: $regex,
$not: $not,
$type: $type,
$and: $and,
$all: $all,
$size: $size,
$options: $options,
$where: $where
});
};
__export(require("./operations"));
exports.default = createDefaultQueryTester;
//# sourceMappingURL=index.js.map
var createDefaultQueryTester = function (query, _a) {
var _b = _a === void 0 ? {} : _a, compare = _b.compare, operations = _b.operations;
return createQueryTester(query, {
compare: compare,
operations: Object.assign({}, defaultOperations, operations)
});
};
exports.$all = $all;
exports.$and = $and;
exports.$elemMatch = $elemMatch;
exports.$eq = $eq;
exports.$exists = $exists;
exports.$gt = $gt;
exports.$gte = $gte;
exports.$in = $in;
exports.$lt = $lt;
exports.$lte = $lte;
exports.$mod = $mod;
exports.$ne = $ne;
exports.$nin = $nin;
exports.$nor = $nor;
exports.$not = $not;
exports.$options = $options;
exports.$or = $or;
exports.$regex = $regex;
exports.$size = $size;
exports.$type = $type;
exports.$where = $where;
exports.EqualsOperation = EqualsOperation;
exports.createEqualsOperation = createEqualsOperation;
exports.createQueryTester = createQueryTester;
exports.default = createDefaultQueryTester;
Object.defineProperty(exports, '__esModule', { value: true });
})));
//# sourceMappingURL=index.js.map

@@ -66,3 +66,3 @@ import { BaseOperation, EqualsOperation, Options, Operation, Query, GroupOperation } from "./core";

export declare const $options: () => any;
export declare const $where: (params: string | Function, ownerQuery: Query, options: Options) => EqualsOperation<(b: any) => any>;
export declare const $where: (params: TimerHandler, ownerQuery: Query, options: Options) => EqualsOperation<(b: any) => any>;
export {};
{
"name": "sift",
"description": "MongoDB query filtering in JavaScript",
"version": "13.0.2",
"version": "13.0.3",
"repository": "crcn/sift.js",

@@ -20,2 +20,4 @@ "sideEffects": false,

"devDependencies": {
"@rollup/plugin-replace": "^2.3.2",
"@rollup/plugin-typescript": "^4.1.1",
"@types/node": "^13.7.0",

@@ -30,22 +32,31 @@ "bson": "^4.0.3",

"pretty-quick": "^1.11.1",
"rimraf": "^3.0.2",
"rollup": "^2.7.2",
"ts-loader": "^6.2.1",
"typescript": "^3.8.3",
"@rollup/plugin-typescript": "^4.1.1",
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-sourcemaps": "^0.5.0",
"rollup-plugin-terser": "^5.3.0",
"rollup-plugin-typescript2": "^0.27.0"
"tslib": "^2.0.0",
"typescript": "^3.8.3"
},
"main": "./index.js",
"module": "./es5m/index.js",
"es2015": "./es/index.js",
"scripts": {
"build": "npm run build:lib && npm run build:lib:es5 && npm run build:min",
"build:lib": "tsc",
"build:lib:es5": "tsc --build tsconfig.es5.json",
"build:min": "rollup --config",
"clean": "rimraf lib es5m es",
"prebuild": "npm run clean && npm run build:types",
"build": "rollup -c",
"build:types": "tsc -p tsconfig.json --emitDeclarationOnly --outDir lib",
"build:watch": "tsc --watch",
"test": "mocha ./test -R spec",
"prepublishOnly": "npm run build && npm run test"
}
},
"files": [
"es",
"es5m",
"lib",
"*.d.ts",
"*.js.map",
"index.js",
"sift.csp.min.js",
"sift.min.js",
"MIT-LICENSE.txt"
]
}

@@ -1,1 +0,16 @@

const t=t=>{const s="[object "+t+"]";return function(t){return e(t)===s}},e=t=>Object.prototype.toString.call(t),s=t=>t instanceof Date?t.getTime():n(t)?t.map(s):t&&"function"==typeof t.toJSON?t.toJSON():t,n=t("Array"),r=t("Object"),i=t("Function"),o=(t,e)=>{if(null==t&&t==e)return!0;if(t===e)return!0;if(Object.prototype.toString.call(t)!==Object.prototype.toString.call(e))return!1;if(n(t)){if(t.length!==e.length)return!1;for(let s=0,{length:n}=t;s<n;s++)if(!o(t[s],e[s]))return!1;return!0}if(r(t)){if(Object.keys(t).length!==Object.keys(e).length)return!1;for(const s in t)if(!o(t[s],e[s]))return!1;return!0}return!1},c=(t,e,s,r,i,o)=>{const h=e[r];if(n(t)&&isNaN(Number(h)))for(let n=0,{length:i}=t;n<i;n++)if(!c(t[n],e,s,r,n,t))return!1;return r===e.length||null==t?s(t,i,o):c(t[h],e,s,r+1,h,t)};class h{constructor(t,e,s){this.params=t,this.owneryQuery=e,this.options=s,this.init()}init(){}reset(){this.done=!1,this.success=!1}}class u extends h{constructor(t,e,s,n){super(t,e,s),this._children=n}reset(){this.success=!1,this.done=!1;for(let t=0,{length:e}=this._children;t<e;t++)this._children[t].reset()}childrenNext(t,e,s){let n=!0,r=!0;for(let i=0,{length:o}=this._children;i<o;i++){const o=this._children[i];if(o.next(t,e,s),o.success||(r=!1),o.done){if(!o.success)break}else n=!1}this.done=n,this.success=r}}class a extends u{next(t,e,s){this.childrenNext(t,e,s)}}class l extends u{constructor(t,e,s,n,r){super(e,s,n,r),this.keyPath=t,this._nextNestedValue=(t,e,s)=>(this.childrenNext(t,e,s),!this.done)}next(t,e,s){c(t,this.keyPath,this._nextNestedValue,0,e,s)}}const p=(t,e)=>{if(t instanceof Function)return t;if(t instanceof RegExp)return e=>"string"==typeof e&&t.test(e);const n=s(t);return t=>e(n,s(t))};class d extends h{init(){this._test=p(this.params,this.options.compare)}next(t,e,s){this._test(t,e,s)&&(this.done=!0,this.success=!0)}}const f=(t,e,s)=>new d(t,e,s);class x extends h{next(){this.done=!0,this.success=!1}}const w=t=>{return e=(e,n,r)=>{const i=typeof s(e),o=t(e);return new d(t=>typeof s(t)===i&&o(t),n,r)},(t,s,n)=>null==t?new x(t,s,n):e(t,s,n);var e},y=(t,e,s,n)=>{const r=n.operations[t];if(!r)throw new Error("Unsupported operation: "+t);return r(e,s,n)},_=t=>{for(const e in t)if("$"===e.charAt(0))return!0;return!1},g=(t,e,s,n)=>{if(_(e)){const[r,i]=O(e,n);if(i.length)throw new Error("Property queries must contain only operations, or exact objects.");return new l(t,e,s,n,r)}return new l(t,e,s,n,[new d(e,s,n)])},m=(t,e,s)=>{const[n,r]=O(t,s),i=[];return n.length&&i.push(new l([],t,e,s,n)),i.push(...r),1===i.length?i[0]:new a(t,e,s,i)},O=(t,e)=>{const s=[],n=[];if(!(r=t)||r.constructor!==Object&&r.constructor!==Array&&"function Object() { [native code] }"!==r.constructor.toString()&&"function Array() { [native code] }"!==r.constructor.toString()||r.toJSON)return s.push(new d(t,t,e)),[s,n];var r;for(const r in t)if("$"===r.charAt(0)){const n=y(r,t[r],t,e);null!=n&&s.push(n)}else n.push(g(r.split("."),t[r],t,e));return[s,n]},$=(t,{compare:e,operations:s}={})=>{const n=m(t,null,{compare:e||o,operations:Object.assign({},s||{})});return(t,e,s)=>(n.reset(),n.next(t,e,s),n.success)};class b extends h{init(){this._test=p(this.params,this.options.compare)}reset(){super.reset(),this.success=!0}next(t){this._test(t)&&(this.done=!0,this.success=!1)}}class j extends h{init(){this._queryOperation=m(this.params,this.owneryQuery,this.options)}reset(){this._queryOperation.reset()}next(t,e,s){this._queryOperation.reset(),n(s)?(this._queryOperation.next(t,e,s),this.done=this._queryOperation.done||e===s.length-1,this.success=this._queryOperation.success):(this.done=!0,this.success=!1)}}class q extends h{init(){this._queryOperation=m(this.params,this.owneryQuery,this.options)}reset(){this._queryOperation.reset()}next(t,e,s){this._queryOperation.next(t,e,s),this.done=this._queryOperation.done,this.success=!this._queryOperation.success}}class N extends h{init(){this._ops=this.params.map(t=>m(t,null,this.options))}reset(){this.done=!1,this.success=!1;for(let t=0,{length:e}=this._ops;t<e;t++)this._ops[t].reset()}next(t,e,s){let n=!1,r=!1;for(let i=0,{length:o}=this._ops;i<o;i++){const o=this._ops[i];if(o.next(t,e,s),o.success){n=!0,r=o.success;break}}this.success=r,this.done=n}}class S extends N{next(t,e,s){super.next(t,e,s),this.success=!this.success}}class E extends h{init(){this._testers=this.params.map(t=>{if(_(t))throw new Error("cannot nest $ under "+this.constructor.name.toLowerCase());return p(t,this.options.compare)})}next(t,e,s){let n=!1,r=!1;for(let e=0,{length:s}=this._testers;e<s;e++){if((0,this._testers[e])(t)){n=!0,r=!0;break}}this.success=r,this.done=n}}class k extends E{next(t,e,s){super.next(t,e,s),this.success=!this.success}}class v extends h{next(t,e,s){s.hasOwnProperty(e)===this.params&&(this.done=!0,this.success=!0)}}class A extends u{constructor(t,e,s){super(t,e,s,t.map(t=>m(t,e,s)))}next(t,e,s){this.childrenNext(t,e,s)}}const P=(t,e,s)=>new d(t,e,s),C=(t,e,s)=>new b(t,e,s),F=(t,e,s)=>new N(t,e,s),J=(t,e,s)=>new S(t,e,s),Q=(t,e,s)=>new j(t,e,s),z=(t,e,s)=>new k(t,e,s),D=(t,e,s)=>new E(t,e,s),L=w(t=>e=>e<t),R=w(t=>e=>e<=t),V=w(t=>e=>e>t),B=w(t=>e=>e>=t),I=([t,e],n,r)=>new d(n=>s(n)%t===e,n,r),M=(t,e,s)=>new v(t,e,s),T=(t,e,s)=>new d(new RegExp(t,e.$options),e,s),U=(t,e,s)=>new q(t,e,s),G=(t,e,s)=>new d(e=>null!=e&&(e instanceof t||e.constructor===t),e,s),H=(t,e,s)=>new A(t,e,s),K=H,W=(t,e,s)=>new d(e=>e&&e.length===t,e,s),X=()=>null,Y=(t,e,s)=>{let n;if(i(t))n=t;else{if(process.env.CSP_ENABLED)throw new Error('In CSP mode, sift does not support strings in "$where" condition');n=new Function("obj","return "+t)}return new d(t=>n.bind(t)(t),e,s)};var Z=Object.freeze({__proto__:null,$eq:P,$ne:C,$or:F,$nor:J,$elemMatch:Q,$nin:z,$in:D,$lt:L,$lte:R,$gt:V,$gte:B,$mod:I,$exists:M,$regex:T,$not:U,$type:G,$and:H,$all:K,$size:W,$options:X,$where:Y});export default(t,{compare:e,operations:s}={})=>$(t,{compare:e,operations:Object.assign({},Z,s)});export{K as $all,H as $and,Q as $elemMatch,P as $eq,M as $exists,V as $gt,B as $gte,D as $in,L as $lt,R as $lte,I as $mod,C as $ne,z as $nin,J as $nor,U as $not,X as $options,F as $or,T as $regex,W as $size,G as $type,Y as $where,d as EqualsOperation,f as createEqualsOperation,$ as createQueryTester};
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((n=n||self).sift={})}(this,(function(n){"use strict";
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */var t=function(n,i){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,t){n.__proto__=t}||function(n,t){for(var i in t)t.hasOwnProperty(i)&&(n[i]=t[i])})(n,i)};function i(n,i){function r(){this.constructor=n}t(n,i),n.prototype=null===i?Object.create(i):(r.prototype=i.prototype,new r)}var r=function(n){var t="[object "+n+"]";return function(n){return u(n)===t}},u=function(n){return Object.prototype.toString.call(n)},e=function(n){return n instanceof Date?n.getTime():o(n)?n.map(e):n&&"function"==typeof n.toJSON?n.toJSON():n},o=r("Array"),f=r("Object"),c=r("Function"),s=function(n,t){if(null==n&&n==t)return!0;if(n===t)return!0;if(Object.prototype.toString.call(n)!==Object.prototype.toString.call(t))return!1;if(o(n)){if(n.length!==t.length)return!1;for(var i=0,r=n.length;i<r;i++)if(!s(n[i],t[i]))return!1;return!0}if(f(n)){if(Object.keys(n).length!==Object.keys(t).length)return!1;for(var u in n)if(!s(n[u],t[u]))return!1;return!0}return!1},h=function(n,t,i,r,u,e){var f=t[r];if(o(n)&&isNaN(Number(f)))for(var c=0,s=n.length;c<s;c++)if(!h(n[c],t,i,r,c,n))return!1;return r===t.length||null==n?i(n,u,e):h(n[f],t,i,r+1,f,n)},a=function(){function n(n,t,i){this.params=n,this.owneryQuery=t,this.options=i,this.init()}return n.prototype.init=function(){},n.prototype.reset=function(){this.done=!1,this.success=!1},n}(),l=function(n){function t(t,i,r,u){var e=n.call(this,t,i,r)||this;return e.t=u,e}return i(t,n),t.prototype.reset=function(){this.success=!1,this.done=!1;for(var n=0,t=this.t.length;n<t;n++)this.t[n].reset()},t.prototype.childrenNext=function(n,t,i){for(var r=!0,u=!0,e=0,o=this.t.length;e<o;e++){var f=this.t[e];if(f.next(n,t,i),f.success||(u=!1),f.done){if(!f.success)break}else r=!1}this.done=r,this.success=u},t}(a),v=function(n){function t(){return null!==n&&n.apply(this,arguments)||this}return i(t,n),t.prototype.next=function(n,t,i){this.childrenNext(n,t,i)},t}(l),w=function(n){function t(t,i,r,u,e){var o=n.call(this,i,r,u,e)||this;return o.keyPath=t,o.i=function(n,t,i){return o.childrenNext(n,t,i),!o.done},o}return i(t,n),t.prototype.next=function(n,t,i){h(n,this.keyPath,this.i,0,t,i)},t}(l),p=function(n,t){if(n instanceof Function)return n;if(n instanceof RegExp)return function(t){return"string"==typeof t&&n.test(t)};var i=e(n);return function(n){return t(i,e(n))}},$=function(n){function t(){return null!==n&&n.apply(this,arguments)||this}return i(t,n),t.prototype.init=function(){this.u=p(this.params,this.options.compare)},t.prototype.next=function(n,t,i){this.u(n,t,i)&&(this.done=!0,this.success=!0)},t}(a),b=function(n){function t(){return null!==n&&n.apply(this,arguments)||this}return i(t,n),t.prototype.next=function(){this.done=!0,this.success=!1},t}(a),d=function(n){return t=function(t,i,r){var u=typeof e(t),o=n(t);return new $((function(n){return typeof e(n)===u&&o(n)}),i,r)},function(n,i,r){return null==n?new b(n,i,r):t(n,i,r)};var t},j=function(n,t,i,r){var u=r.operations[n];if(!u)throw new Error("Unsupported operation: "+n);return u(t,i,r)},y=function(n){for(var t in n)if("$"===t.charAt(0))return!0;return!1},O=function(n,t,i,r){if(y(t)){var u=m(t,r),e=u[0];if(u[1].length)throw new Error("Property queries must contain only operations, or exact objects.");return new w(n,t,i,r,e)}return new w(n,t,i,r,[new $(t,i,r)])},_=function(n,t,i){var r=m(n,i),u=r[0],e=r[1],o=[];return u.length&&o.push(new w([],n,t,i,u)),o.push.apply(o,e),1===o.length?o[0]:new v(n,t,i,o)},m=function(n,t){var i,r=[],u=[];if(!(i=n)||i.constructor!==Object&&i.constructor!==Array&&"function Object() { [native code] }"!==i.constructor.toString()&&"function Array() { [native code] }"!==i.constructor.toString()||i.toJSON)return r.push(new $(n,n,t)),[r,u];for(var e in n)if("$"===e.charAt(0)){var o=j(e,n[e],n,t);null!=o&&r.push(o)}else u.push(O(e.split("."),n[e],n,t));return[r,u]},x=function(n,t){var i=void 0===t?{}:t,r=i.compare,u=i.operations,e=_(n,null,{compare:r||s,operations:Object.assign({},u||{})});return function(n,t,i){return e.reset(),e.next(n,t,i),e.success}},g=function(n){function t(){return null!==n&&n.apply(this,arguments)||this}return i(t,n),t.prototype.init=function(){this.u=p(this.params,this.options.compare)},t.prototype.reset=function(){n.prototype.reset.call(this),this.success=!0},t.prototype.next=function(n){this.u(n)&&(this.done=!0,this.success=!1)},t}(a),E=function(n){function t(){return null!==n&&n.apply(this,arguments)||this}return i(t,n),t.prototype.init=function(){this.o=_(this.params,this.owneryQuery,this.options)},t.prototype.reset=function(){this.o.reset()},t.prototype.next=function(n,t,i){this.o.reset(),o(i)?(this.o.next(n,t,i),this.done=this.o.done||t===i.length-1,this.success=this.o.success):(this.done=!0,this.success=!1)},t}(a),A=function(n){function t(){return null!==n&&n.apply(this,arguments)||this}return i(t,n),t.prototype.init=function(){this.o=_(this.params,this.owneryQuery,this.options)},t.prototype.reset=function(){this.o.reset()},t.prototype.next=function(n,t,i){this.o.next(n,t,i),this.done=this.o.done,this.success=!this.o.success},t}(a),k=function(n){function t(){return null!==n&&n.apply(this,arguments)||this}return i(t,n),t.prototype.init=function(){var n=this;this.s=this.params.map((function(t){return _(t,null,n.options)}))},t.prototype.reset=function(){this.done=!1,this.success=!1;for(var n=0,t=this.s.length;n<t;n++)this.s[n].reset()},t.prototype.next=function(n,t,i){for(var r=!1,u=!1,e=0,o=this.s.length;e<o;e++){var f=this.s[e];if(f.next(n,t,i),f.success){r=!0,u=f.success;break}}this.success=u,this.done=r},t}(a),F=function(n){function t(){return null!==n&&n.apply(this,arguments)||this}return i(t,n),t.prototype.next=function(t,i,r){n.prototype.next.call(this,t,i,r),this.success=!this.success},t}(k),N=function(n){function t(){return null!==n&&n.apply(this,arguments)||this}return i(t,n),t.prototype.init=function(){var n=this;this.h=this.params.map((function(t){if(y(t))throw new Error("cannot nest $ under "+n.constructor.name.toLowerCase());return p(t,n.options.compare)}))},t.prototype.next=function(n,t,i){for(var r=!1,u=!1,e=0,o=this.h.length;e<o;e++){if((0,this.h[e])(n)){r=!0,u=!0;break}}this.success=u,this.done=r},t}(a),q=function(n){function t(){return null!==n&&n.apply(this,arguments)||this}return i(t,n),t.prototype.next=function(t,i,r){n.prototype.next.call(this,t,i,r),this.success=!this.success},t}(N),M=function(n){function t(){return null!==n&&n.apply(this,arguments)||this}return i(t,n),t.prototype.next=function(n,t,i){i.hasOwnProperty(t)===this.params&&(this.done=!0,this.success=!0)},t}(a),P=function(n){function t(t,i,r){return n.call(this,t,i,r,t.map((function(n){return _(n,i,r)})))||this}return i(t,n),t.prototype.next=function(n,t,i){this.childrenNext(n,t,i)},t}(l),R=function(n,t,i){return new $(n,t,i)},z=function(n,t,i){return new g(n,t,i)},C=function(n,t,i){return new k(n,t,i)},D=function(n,t,i){return new F(n,t,i)},I=function(n,t,i){return new E(n,t,i)},S=function(n,t,i){return new q(n,t,i)},U=function(n,t,i){return new N(n,t,i)},B=d((function(n){return function(t){return t<n}})),G=d((function(n){return function(t){return t<=n}})),H=d((function(n){return function(t){return t>n}})),J=d((function(n){return function(t){return t>=n}})),K=function(n,t,i){var r=n[0],u=n[1];return new $((function(n){return e(n)%r===u}),t,i)},L=function(n,t,i){return new M(n,t,i)},Q=function(n,t,i){return new $(new RegExp(n,t.$options),t,i)},T=function(n,t,i){return new A(n,t,i)},V=function(n,t,i){return new $((function(t){return null!=t&&(t instanceof n||t.constructor===n)}),t,i)},W=function(n,t,i){return new P(n,t,i)},X=W,Y=function(n,t,i){return new $((function(t){return t&&t.length===n}),t,i)},Z=function(){return null},nn=function(n,t,i){var r;if(c(n))r=n;else{if(process.env.CSP_ENABLED)throw new Error('In CSP mode, sift does not support strings in "$where" condition');r=new Function("obj","return "+n)}return new $((function(n){return r.bind(n)(n)}),t,i)},tn=Object.freeze({__proto__:null,$eq:R,$ne:z,$or:C,$nor:D,$elemMatch:I,$nin:S,$in:U,$lt:B,$lte:G,$gt:H,$gte:J,$mod:K,$exists:L,$regex:Q,$not:T,$type:V,$and:W,$all:X,$size:Y,$options:Z,$where:nn});n.$all=X,n.$and=W,n.$elemMatch=I,n.$eq=R,n.$exists=L,n.$gt=H,n.$gte=J,n.$in=U,n.$lt=B,n.$lte=G,n.$mod=K,n.$ne=z,n.$nin=S,n.$nor=D,n.$not=T,n.$options=Z,n.$or=C,n.$regex=Q,n.$size=Y,n.$type=V,n.$where=nn,n.EqualsOperation=$,n.createEqualsOperation=function(n,t,i){return new $(n,t,i)},n.createQueryTester=x,n.default=function(n,t){var i=void 0===t?{}:t,r=i.compare,u=i.operations;return x(n,{compare:r,operations:Object.assign({},tn,u)})},Object.defineProperty(n,"l",{value:!0})}));
//# sourceMappingURL=sift.min.js.map

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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