sift.csp.min.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  3. typeof define === 'function' && define.amd ? define(['exports'], factory) :
  4. (global = global || self, factory(global.sift = {}));
  5. }(this, (function (exports) { 'use strict';
  6. /*! *****************************************************************************
  7. Copyright (c) Microsoft Corporation.
  8. Permission to use, copy, modify, and/or distribute this software for any
  9. purpose with or without fee is hereby granted.
  10. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
  11. REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  12. AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
  13. INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  14. LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  15. OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  16. PERFORMANCE OF THIS SOFTWARE.
  17. ***************************************************************************** */
  18. /* global Reflect, Promise */
  19. var extendStatics = function(d, b) {
  20. extendStatics = Object.setPrototypeOf ||
  21. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  22. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  23. return extendStatics(d, b);
  24. };
  25. function __extends(d, b) {
  26. extendStatics(d, b);
  27. function __() { this.constructor = d; }
  28. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  29. }
  30. var typeChecker = function (type) {
  31. var typeString = "[object " + type + "]";
  32. return function (value) {
  33. return getClassName(value) === typeString;
  34. };
  35. };
  36. var getClassName = function (value) { return Object.prototype.toString.call(value); };
  37. var comparable = function (value) {
  38. if (value instanceof Date) {
  39. return value.getTime();
  40. }
  41. else if (isArray(value)) {
  42. return value.map(comparable);
  43. }
  44. else if (value && typeof value.toJSON === "function") {
  45. return value.toJSON();
  46. }
  47. return value;
  48. };
  49. var isArray = typeChecker("Array");
  50. var isObject = typeChecker("Object");
  51. var isFunction = typeChecker("Function");
  52. var isVanillaObject = function (value) {
  53. return (value &&
  54. (value.constructor === Object ||
  55. value.constructor === Array ||
  56. value.constructor.toString() === "function Object() { [native code] }" ||
  57. value.constructor.toString() === "function Array() { [native code] }") &&
  58. !value.toJSON);
  59. };
  60. var equals = function (a, b) {
  61. if (a == null && a == b) {
  62. return true;
  63. }
  64. if (a === b) {
  65. return true;
  66. }
  67. if (Object.prototype.toString.call(a) !== Object.prototype.toString.call(b)) {
  68. return false;
  69. }
  70. if (isArray(a)) {
  71. if (a.length !== b.length) {
  72. return false;
  73. }
  74. for (var i = 0, length_1 = a.length; i < length_1; i++) {
  75. if (!equals(a[i], b[i]))
  76. return false;
  77. }
  78. return true;
  79. }
  80. else if (isObject(a)) {
  81. if (Object.keys(a).length !== Object.keys(b).length) {
  82. return false;
  83. }
  84. for (var key in a) {
  85. if (!equals(a[key], b[key]))
  86. return false;
  87. }
  88. return true;
  89. }
  90. return false;
  91. };
  92. /**
  93. * Walks through each value given the context - used for nested operations. E.g:
  94. * { "person.address": { $eq: "blarg" }}
  95. */
  96. var walkKeyPathValues = function (item, keyPath, next, depth, key, owner) {
  97. var currentKey = keyPath[depth];
  98. // if array, then try matching. Might fall through for cases like:
  99. // { $eq: [1, 2, 3] }, [ 1, 2, 3 ].
  100. if (isArray(item) && isNaN(Number(currentKey))) {
  101. for (var i = 0, length_1 = item.length; i < length_1; i++) {
  102. // if FALSE is returned, then terminate walker. For operations, this simply
  103. // means that the search critera was met.
  104. if (!walkKeyPathValues(item[i], keyPath, next, depth, i, item)) {
  105. return false;
  106. }
  107. }
  108. }
  109. if (depth === keyPath.length || item == null) {
  110. return next(item, key, owner);
  111. }
  112. return walkKeyPathValues(item[currentKey], keyPath, next, depth + 1, currentKey, item);
  113. };
  114. var BaseOperation = /** @class */ (function () {
  115. function BaseOperation(params, owneryQuery, options) {
  116. this.params = params;
  117. this.owneryQuery = owneryQuery;
  118. this.options = options;
  119. this.init();
  120. }
  121. BaseOperation.prototype.init = function () { };
  122. BaseOperation.prototype.reset = function () {
  123. this.done = false;
  124. this.keep = false;
  125. };
  126. return BaseOperation;
  127. }());
  128. var NamedBaseOperation = /** @class */ (function (_super) {
  129. __extends(NamedBaseOperation, _super);
  130. function NamedBaseOperation(params, owneryQuery, options, name) {
  131. var _this = _super.call(this, params, owneryQuery, options) || this;
  132. _this.name = name;
  133. return _this;
  134. }
  135. return NamedBaseOperation;
  136. }(BaseOperation));
  137. var GroupOperation = /** @class */ (function (_super) {
  138. __extends(GroupOperation, _super);
  139. function GroupOperation(params, owneryQuery, options, children) {
  140. var _this = _super.call(this, params, owneryQuery, options) || this;
  141. _this.children = children;
  142. return _this;
  143. }
  144. /**
  145. */
  146. GroupOperation.prototype.reset = function () {
  147. this.keep = false;
  148. this.done = false;
  149. for (var i = 0, length_2 = this.children.length; i < length_2; i++) {
  150. this.children[i].reset();
  151. }
  152. };
  153. /**
  154. */
  155. GroupOperation.prototype.childrenNext = function (item, key, owner) {
  156. var done = true;
  157. var keep = true;
  158. for (var i = 0, length_3 = this.children.length; i < length_3; i++) {
  159. var childOperation = this.children[i];
  160. childOperation.next(item, key, owner);
  161. if (!childOperation.keep) {
  162. keep = false;
  163. }
  164. if (childOperation.done) {
  165. if (!childOperation.keep) {
  166. break;
  167. }
  168. }
  169. else {
  170. done = false;
  171. }
  172. }
  173. this.done = done;
  174. this.keep = keep;
  175. };
  176. return GroupOperation;
  177. }(BaseOperation));
  178. var NamedGroupOperation = /** @class */ (function (_super) {
  179. __extends(NamedGroupOperation, _super);
  180. function NamedGroupOperation(params, owneryQuery, options, children, name) {
  181. var _this = _super.call(this, params, owneryQuery, options, children) || this;
  182. _this.name = name;
  183. return _this;
  184. }
  185. return NamedGroupOperation;
  186. }(GroupOperation));
  187. var QueryOperation = /** @class */ (function (_super) {
  188. __extends(QueryOperation, _super);
  189. function QueryOperation() {
  190. return _super !== null && _super.apply(this, arguments) || this;
  191. }
  192. /**
  193. */
  194. QueryOperation.prototype.next = function (item, key, parent) {
  195. this.childrenNext(item, key, parent);
  196. };
  197. return QueryOperation;
  198. }(GroupOperation));
  199. var NestedOperation = /** @class */ (function (_super) {
  200. __extends(NestedOperation, _super);
  201. function NestedOperation(keyPath, params, owneryQuery, options, children) {
  202. var _this = _super.call(this, params, owneryQuery, options, children) || this;
  203. _this.keyPath = keyPath;
  204. /**
  205. */
  206. _this._nextNestedValue = function (value, key, owner) {
  207. _this.childrenNext(value, key, owner);
  208. return !_this.done;
  209. };
  210. return _this;
  211. }
  212. /**
  213. */
  214. NestedOperation.prototype.next = function (item, key, parent) {
  215. walkKeyPathValues(item, this.keyPath, this._nextNestedValue, 0, key, parent);
  216. };
  217. return NestedOperation;
  218. }(GroupOperation));
  219. var createTester = function (a, compare) {
  220. if (a instanceof Function) {
  221. return a;
  222. }
  223. if (a instanceof RegExp) {
  224. return function (b) {
  225. var result = typeof b === "string" && a.test(b);
  226. a.lastIndex = 0;
  227. return result;
  228. };
  229. }
  230. var comparableA = comparable(a);
  231. return function (b) { return compare(comparableA, comparable(b)); };
  232. };
  233. var EqualsOperation = /** @class */ (function (_super) {
  234. __extends(EqualsOperation, _super);
  235. function EqualsOperation() {
  236. return _super !== null && _super.apply(this, arguments) || this;
  237. }
  238. EqualsOperation.prototype.init = function () {
  239. this._test = createTester(this.params, this.options.compare);
  240. };
  241. EqualsOperation.prototype.next = function (item, key, parent) {
  242. if (!Array.isArray(parent) || parent.hasOwnProperty(key)) {
  243. if (this._test(item, key, parent)) {
  244. this.done = true;
  245. this.keep = true;
  246. }
  247. }
  248. };
  249. return EqualsOperation;
  250. }(BaseOperation));
  251. var createEqualsOperation = function (params, owneryQuery, options) { return new EqualsOperation(params, owneryQuery, options); };
  252. var NopeOperation = /** @class */ (function (_super) {
  253. __extends(NopeOperation, _super);
  254. function NopeOperation() {
  255. return _super !== null && _super.apply(this, arguments) || this;
  256. }
  257. NopeOperation.prototype.next = function () {
  258. this.done = true;
  259. this.keep = false;
  260. };
  261. return NopeOperation;
  262. }(BaseOperation));
  263. var numericalOperationCreator = function (createNumericalOperation) { return function (params, owneryQuery, options, name) {
  264. if (params == null) {
  265. return new NopeOperation(params, owneryQuery, options);
  266. }
  267. return createNumericalOperation(params, owneryQuery, options, name);
  268. }; };
  269. var numericalOperation = function (createTester) {
  270. return numericalOperationCreator(function (params, owneryQuery, options) {
  271. var typeofParams = typeof comparable(params);
  272. var test = createTester(params);
  273. return new EqualsOperation(function (b) {
  274. return typeof comparable(b) === typeofParams && test(b);
  275. }, owneryQuery, options);
  276. });
  277. };
  278. var createNamedOperation = function (name, params, parentQuery, options) {
  279. var operationCreator = options.operations[name];
  280. if (!operationCreator) {
  281. throw new Error("Unsupported operation: " + name);
  282. }
  283. return operationCreator(params, parentQuery, options, name);
  284. };
  285. var containsOperation = function (query) {
  286. for (var key in query) {
  287. if (key.charAt(0) === "$")
  288. return true;
  289. }
  290. return false;
  291. };
  292. var createNestedOperation = function (keyPath, nestedQuery, owneryQuery, options) {
  293. if (containsOperation(nestedQuery)) {
  294. var _a = createQueryOperations(nestedQuery, options), selfOperations = _a[0], nestedOperations = _a[1];
  295. if (nestedOperations.length) {
  296. throw new Error("Property queries must contain only operations, or exact objects.");
  297. }
  298. return new NestedOperation(keyPath, nestedQuery, owneryQuery, options, selfOperations);
  299. }
  300. return new NestedOperation(keyPath, nestedQuery, owneryQuery, options, [
  301. new EqualsOperation(nestedQuery, owneryQuery, options)
  302. ]);
  303. };
  304. var createQueryOperation = function (query, owneryQuery, _a) {
  305. if (owneryQuery === void 0) { owneryQuery = null; }
  306. var _b = _a === void 0 ? {} : _a, compare = _b.compare, operations = _b.operations;
  307. var options = {
  308. compare: compare || equals,
  309. operations: Object.assign({}, operations || {})
  310. };
  311. var _c = createQueryOperations(query, options), selfOperations = _c[0], nestedOperations = _c[1];
  312. var ops = [];
  313. if (selfOperations.length) {
  314. ops.push(new NestedOperation([], query, owneryQuery, options, selfOperations));
  315. }
  316. ops.push.apply(ops, nestedOperations);
  317. if (ops.length === 1) {
  318. return ops[0];
  319. }
  320. return new QueryOperation(query, owneryQuery, options, ops);
  321. };
  322. var createQueryOperations = function (query, options) {
  323. var selfOperations = [];
  324. var nestedOperations = [];
  325. if (!isVanillaObject(query)) {
  326. selfOperations.push(new EqualsOperation(query, query, options));
  327. return [selfOperations, nestedOperations];
  328. }
  329. for (var key in query) {
  330. if (key.charAt(0) === "$") {
  331. var op = createNamedOperation(key, query[key], query, options);
  332. // probably just a flag for another operation (like $options)
  333. if (op != null) {
  334. selfOperations.push(op);
  335. }
  336. }
  337. else {
  338. nestedOperations.push(createNestedOperation(key.split("."), query[key], query, options));
  339. }
  340. }
  341. return [selfOperations, nestedOperations];
  342. };
  343. var createOperationTester = function (operation) { return function (item, key, owner) {
  344. operation.reset();
  345. operation.next(item, key, owner);
  346. return operation.keep;
  347. }; };
  348. var createQueryTester = function (query, options) {
  349. if (options === void 0) { options = {}; }
  350. return createOperationTester(createQueryOperation(query, null, options));
  351. };
  352. var $Ne = /** @class */ (function (_super) {
  353. __extends($Ne, _super);
  354. function $Ne() {
  355. return _super !== null && _super.apply(this, arguments) || this;
  356. }
  357. $Ne.prototype.init = function () {
  358. this._test = createTester(this.params, this.options.compare);
  359. };
  360. $Ne.prototype.reset = function () {
  361. _super.prototype.reset.call(this);
  362. this.keep = true;
  363. };
  364. $Ne.prototype.next = function (item) {
  365. if (this._test(item)) {
  366. this.done = true;
  367. this.keep = false;
  368. }
  369. };
  370. return $Ne;
  371. }(NamedBaseOperation));
  372. // https://docs.mongodb.com/manual/reference/operator/query/elemMatch/
  373. var $ElemMatch = /** @class */ (function (_super) {
  374. __extends($ElemMatch, _super);
  375. function $ElemMatch() {
  376. return _super !== null && _super.apply(this, arguments) || this;
  377. }
  378. $ElemMatch.prototype.init = function () {
  379. this._queryOperation = createQueryOperation(this.params, this.owneryQuery, this.options);
  380. };
  381. $ElemMatch.prototype.reset = function () {
  382. _super.prototype.reset.call(this);
  383. this._queryOperation.reset();
  384. };
  385. $ElemMatch.prototype.next = function (item) {
  386. if (isArray(item)) {
  387. for (var i = 0, length_1 = item.length; i < length_1; i++) {
  388. // reset query operation since item being tested needs to pass _all_ query
  389. // operations for it to be a success
  390. this._queryOperation.reset();
  391. // check item
  392. this._queryOperation.next(item[i], i, item);
  393. this.keep = this.keep || this._queryOperation.keep;
  394. }
  395. this.done = true;
  396. }
  397. else {
  398. this.done = false;
  399. this.keep = false;
  400. }
  401. };
  402. return $ElemMatch;
  403. }(NamedBaseOperation));
  404. var $Not = /** @class */ (function (_super) {
  405. __extends($Not, _super);
  406. function $Not() {
  407. return _super !== null && _super.apply(this, arguments) || this;
  408. }
  409. $Not.prototype.init = function () {
  410. this._queryOperation = createQueryOperation(this.params, this.owneryQuery, this.options);
  411. };
  412. $Not.prototype.reset = function () {
  413. this._queryOperation.reset();
  414. };
  415. $Not.prototype.next = function (item, key, owner) {
  416. this._queryOperation.next(item, key, owner);
  417. this.done = this._queryOperation.done;
  418. this.keep = !this._queryOperation.keep;
  419. };
  420. return $Not;
  421. }(NamedBaseOperation));
  422. var $Size = /** @class */ (function (_super) {
  423. __extends($Size, _super);
  424. function $Size() {
  425. return _super !== null && _super.apply(this, arguments) || this;
  426. }
  427. $Size.prototype.init = function () { };
  428. $Size.prototype.next = function (item) {
  429. if (isArray(item) && item.length === this.params) {
  430. this.done = true;
  431. this.keep = true;
  432. }
  433. // if (parent && parent.length === this.params) {
  434. // this.done = true;
  435. // this.keep = true;
  436. // }
  437. };
  438. return $Size;
  439. }(NamedBaseOperation));
  440. var $Or = /** @class */ (function (_super) {
  441. __extends($Or, _super);
  442. function $Or() {
  443. return _super !== null && _super.apply(this, arguments) || this;
  444. }
  445. $Or.prototype.init = function () {
  446. var _this = this;
  447. this._ops = this.params.map(function (op) {
  448. return createQueryOperation(op, null, _this.options);
  449. });
  450. };
  451. $Or.prototype.reset = function () {
  452. this.done = false;
  453. this.keep = false;
  454. for (var i = 0, length_2 = this._ops.length; i < length_2; i++) {
  455. this._ops[i].reset();
  456. }
  457. };
  458. $Or.prototype.next = function (item, key, owner) {
  459. var done = false;
  460. var success = false;
  461. for (var i = 0, length_3 = this._ops.length; i < length_3; i++) {
  462. var op = this._ops[i];
  463. op.next(item, key, owner);
  464. if (op.keep) {
  465. done = true;
  466. success = op.keep;
  467. break;
  468. }
  469. }
  470. this.keep = success;
  471. this.done = done;
  472. };
  473. return $Or;
  474. }(NamedBaseOperation));
  475. var $Nor = /** @class */ (function (_super) {
  476. __extends($Nor, _super);
  477. function $Nor() {
  478. return _super !== null && _super.apply(this, arguments) || this;
  479. }
  480. $Nor.prototype.next = function (item, key, owner) {
  481. _super.prototype.next.call(this, item, key, owner);
  482. this.keep = !this.keep;
  483. };
  484. return $Nor;
  485. }($Or));
  486. var $In = /** @class */ (function (_super) {
  487. __extends($In, _super);
  488. function $In() {
  489. return _super !== null && _super.apply(this, arguments) || this;
  490. }
  491. $In.prototype.init = function () {
  492. var _this = this;
  493. this._testers = this.params.map(function (value) {
  494. if (containsOperation(value)) {
  495. throw new Error("cannot nest $ under " + _this.constructor.name.toLowerCase());
  496. }
  497. return createTester(value, _this.options.compare);
  498. });
  499. };
  500. $In.prototype.next = function (item, key, owner) {
  501. var done = false;
  502. var success = false;
  503. for (var i = 0, length_4 = this._testers.length; i < length_4; i++) {
  504. var test = this._testers[i];
  505. if (test(item)) {
  506. done = true;
  507. success = true;
  508. break;
  509. }
  510. }
  511. this.keep = success;
  512. this.done = done;
  513. };
  514. return $In;
  515. }(NamedBaseOperation));
  516. var $Nin = /** @class */ (function (_super) {
  517. __extends($Nin, _super);
  518. function $Nin() {
  519. return _super !== null && _super.apply(this, arguments) || this;
  520. }
  521. $Nin.prototype.next = function (item, key, owner) {
  522. _super.prototype.next.call(this, item, key, owner);
  523. this.keep = !this.keep;
  524. };
  525. return $Nin;
  526. }($In));
  527. var $Exists = /** @class */ (function (_super) {
  528. __extends($Exists, _super);
  529. function $Exists() {
  530. return _super !== null && _super.apply(this, arguments) || this;
  531. }
  532. $Exists.prototype.next = function (item, key, owner) {
  533. if (owner.hasOwnProperty(key) === this.params) {
  534. this.done = true;
  535. this.keep = true;
  536. }
  537. };
  538. return $Exists;
  539. }(NamedBaseOperation));
  540. var $And = /** @class */ (function (_super) {
  541. __extends($And, _super);
  542. function $And(params, owneryQuery, options, name) {
  543. return _super.call(this, params, owneryQuery, options, params.map(function (query) { return createQueryOperation(query, owneryQuery, options); }), name) || this;
  544. }
  545. $And.prototype.next = function (item, key, owner) {
  546. this.childrenNext(item, key, owner);
  547. };
  548. return $And;
  549. }(NamedGroupOperation));
  550. var $eq = function (params, owneryQuery, options) {
  551. return new EqualsOperation(params, owneryQuery, options);
  552. };
  553. var $ne = function (params, owneryQuery, options, name) { return new $Ne(params, owneryQuery, options, name); };
  554. var $or = function (params, owneryQuery, options, name) { return new $Or(params, owneryQuery, options, name); };
  555. var $nor = function (params, owneryQuery, options, name) { return new $Nor(params, owneryQuery, options, name); };
  556. var $elemMatch = function (params, owneryQuery, options, name) { return new $ElemMatch(params, owneryQuery, options, name); };
  557. var $nin = function (params, owneryQuery, options, name) { return new $Nin(params, owneryQuery, options, name); };
  558. var $in = function (params, owneryQuery, options, name) { return new $In(params, owneryQuery, options, name); };
  559. var $lt = numericalOperation(function (params) { return function (b) { return b < params; }; });
  560. var $lte = numericalOperation(function (params) { return function (b) { return b <= params; }; });
  561. var $gt = numericalOperation(function (params) { return function (b) { return b > params; }; });
  562. var $gte = numericalOperation(function (params) { return function (b) { return b >= params; }; });
  563. var $mod = function (_a, owneryQuery, options) {
  564. var mod = _a[0], equalsValue = _a[1];
  565. return new EqualsOperation(function (b) { return comparable(b) % mod === equalsValue; }, owneryQuery, options);
  566. };
  567. var $exists = function (params, owneryQuery, options, name) { return new $Exists(params, owneryQuery, options, name); };
  568. var $regex = function (pattern, owneryQuery, options) {
  569. return new EqualsOperation(new RegExp(pattern, owneryQuery.$options), owneryQuery, options);
  570. };
  571. var $not = function (params, owneryQuery, options, name) { return new $Not(params, owneryQuery, options, name); };
  572. var typeAliases = {
  573. number: function (v) { return typeof v === "number"; },
  574. string: function (v) { return typeof v === "string"; },
  575. bool: function (v) { return typeof v === "boolean"; },
  576. array: function (v) { return Array.isArray(v); },
  577. null: function (v) { return v === null; },
  578. timestamp: function (v) { return v instanceof Date; }
  579. };
  580. var $type = function (clazz, owneryQuery, options) {
  581. return new EqualsOperation(function (b) {
  582. if (typeof clazz === "string") {
  583. if (!typeAliases[clazz]) {
  584. throw new Error("Type alias does not exist");
  585. }
  586. return typeAliases[clazz](b);
  587. }
  588. return b != null ? b instanceof clazz || b.constructor === clazz : false;
  589. }, owneryQuery, options);
  590. };
  591. var $and = function (params, ownerQuery, options, name) { return new $And(params, ownerQuery, options, name); };
  592. var $all = $and;
  593. var $size = function (params, ownerQuery, options) { return new $Size(params, ownerQuery, options, "$size"); };
  594. var $options = function () { return null; };
  595. var $where = function (params, ownerQuery, options) {
  596. var test;
  597. if (isFunction(params)) {
  598. test = params;
  599. }
  600. else {
  601. throw new Error("In CSP mode, sift does not support strings in \"$where\" condition");
  602. }
  603. return new EqualsOperation(function (b) { return test.bind(b)(b); }, ownerQuery, options);
  604. };
  605. var defaultOperations = /*#__PURE__*/Object.freeze({
  606. __proto__: null,
  607. $Size: $Size,
  608. $eq: $eq,
  609. $ne: $ne,
  610. $or: $or,
  611. $nor: $nor,
  612. $elemMatch: $elemMatch,
  613. $nin: $nin,
  614. $in: $in,
  615. $lt: $lt,
  616. $lte: $lte,
  617. $gt: $gt,
  618. $gte: $gte,
  619. $mod: $mod,
  620. $exists: $exists,
  621. $regex: $regex,
  622. $not: $not,
  623. $type: $type,
  624. $and: $and,
  625. $all: $all,
  626. $size: $size,
  627. $options: $options,
  628. $where: $where
  629. });
  630. var createDefaultQueryOperation = function (query, ownerQuery, _a) {
  631. var _b = _a === void 0 ? {} : _a, compare = _b.compare, operations = _b.operations;
  632. return createQueryOperation(query, ownerQuery, {
  633. compare: compare,
  634. operations: Object.assign({}, defaultOperations, operations || {})
  635. });
  636. };
  637. var createDefaultQueryTester = function (query, options) {
  638. if (options === void 0) { options = {}; }
  639. var op = createDefaultQueryOperation(query, null, options);
  640. return createOperationTester(op);
  641. };
  642. exports.$Size = $Size;
  643. exports.$all = $all;
  644. exports.$and = $and;
  645. exports.$elemMatch = $elemMatch;
  646. exports.$eq = $eq;
  647. exports.$exists = $exists;
  648. exports.$gt = $gt;
  649. exports.$gte = $gte;
  650. exports.$in = $in;
  651. exports.$lt = $lt;
  652. exports.$lte = $lte;
  653. exports.$mod = $mod;
  654. exports.$ne = $ne;
  655. exports.$nin = $nin;
  656. exports.$nor = $nor;
  657. exports.$not = $not;
  658. exports.$options = $options;
  659. exports.$or = $or;
  660. exports.$regex = $regex;
  661. exports.$size = $size;
  662. exports.$type = $type;
  663. exports.$where = $where;
  664. exports.EqualsOperation = EqualsOperation;
  665. exports.createDefaultQueryOperation = createDefaultQueryOperation;
  666. exports.createEqualsOperation = createEqualsOperation;
  667. exports.createOperationTester = createOperationTester;
  668. exports.createQueryOperation = createQueryOperation;
  669. exports.createQueryTester = createQueryTester;
  670. exports.default = createDefaultQueryTester;
  671. Object.defineProperty(exports, '__esModule', { value: true });
  672. })));
  673. //# sourceMappingURL=sift.csp.min.js.map