@valkey/valkey-glide-darwin-arm64 1.3.0-rc2 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/node_modules/glide-rs/glide-rs.darwin-arm64.node +0 -0
  2. package/package.json +1 -1
  3. package/rust-client/node_modules/mingo/README.md +81 -42
  4. package/rust-client/node_modules/mingo/dist/cjs/aggregator.js +10 -14
  5. package/rust-client/node_modules/mingo/dist/cjs/core.js +8 -13
  6. package/rust-client/node_modules/mingo/dist/cjs/cursor.js +24 -12
  7. package/rust-client/node_modules/mingo/dist/cjs/operators/_predicates.js +0 -1
  8. package/rust-client/node_modules/mingo/dist/cjs/operators/accumulator/bottomN.js +3 -2
  9. package/rust-client/node_modules/mingo/dist/cjs/operators/accumulator/topN.js +3 -4
  10. package/rust-client/node_modules/mingo/dist/cjs/operators/expression/array/sortArray.js +3 -2
  11. package/rust-client/node_modules/mingo/dist/cjs/operators/pipeline/fill.js +1 -1
  12. package/rust-client/node_modules/mingo/dist/cjs/operators/pipeline/lookup.js +3 -4
  13. package/rust-client/node_modules/mingo/dist/cjs/operators/pipeline/project.js +78 -85
  14. package/rust-client/node_modules/mingo/dist/cjs/operators/update/_internal.js +22 -0
  15. package/rust-client/node_modules/mingo/dist/cjs/operators/update/addToSet.js +1 -1
  16. package/rust-client/node_modules/mingo/dist/cjs/operators/update/bit.js +1 -1
  17. package/rust-client/node_modules/mingo/dist/cjs/operators/update/currentDate.js +1 -1
  18. package/rust-client/node_modules/mingo/dist/cjs/operators/update/inc.js +1 -1
  19. package/rust-client/node_modules/mingo/dist/cjs/operators/update/max.js +1 -1
  20. package/rust-client/node_modules/mingo/dist/cjs/operators/update/min.js +1 -1
  21. package/rust-client/node_modules/mingo/dist/cjs/operators/update/mul.js +1 -1
  22. package/rust-client/node_modules/mingo/dist/cjs/operators/update/pop.js +1 -1
  23. package/rust-client/node_modules/mingo/dist/cjs/operators/update/pull.js +1 -1
  24. package/rust-client/node_modules/mingo/dist/cjs/operators/update/pullAll.js +2 -1
  25. package/rust-client/node_modules/mingo/dist/cjs/operators/update/push.js +1 -1
  26. package/rust-client/node_modules/mingo/dist/cjs/operators/update/rename.js +1 -1
  27. package/rust-client/node_modules/mingo/dist/cjs/operators/update/set.js +1 -1
  28. package/rust-client/node_modules/mingo/dist/cjs/operators/update/unset.js +1 -1
  29. package/rust-client/node_modules/mingo/dist/cjs/query.js +10 -14
  30. package/rust-client/node_modules/mingo/dist/cjs/updater.js +5 -19
  31. package/rust-client/node_modules/mingo/dist/cjs/util.js +30 -18
  32. package/rust-client/node_modules/mingo/dist/esm/aggregator.js +11 -15
  33. package/rust-client/node_modules/mingo/dist/esm/core.js +8 -13
  34. package/rust-client/node_modules/mingo/dist/esm/cursor.js +27 -13
  35. package/rust-client/node_modules/mingo/dist/esm/operators/_predicates.js +0 -1
  36. package/rust-client/node_modules/mingo/dist/esm/operators/accumulator/bottomN.js +3 -2
  37. package/rust-client/node_modules/mingo/dist/esm/operators/accumulator/topN.js +3 -4
  38. package/rust-client/node_modules/mingo/dist/esm/operators/expression/array/sortArray.js +3 -2
  39. package/rust-client/node_modules/mingo/dist/esm/operators/pipeline/fill.js +1 -1
  40. package/rust-client/node_modules/mingo/dist/esm/operators/pipeline/lookup.js +3 -4
  41. package/rust-client/node_modules/mingo/dist/esm/operators/pipeline/project.js +80 -87
  42. package/rust-client/node_modules/mingo/dist/esm/operators/update/_internal.js +11 -0
  43. package/rust-client/node_modules/mingo/dist/esm/operators/update/addToSet.js +7 -2
  44. package/rust-client/node_modules/mingo/dist/esm/operators/update/bit.js +6 -2
  45. package/rust-client/node_modules/mingo/dist/esm/operators/update/currentDate.js +6 -2
  46. package/rust-client/node_modules/mingo/dist/esm/operators/update/inc.js +2 -2
  47. package/rust-client/node_modules/mingo/dist/esm/operators/update/max.js +6 -2
  48. package/rust-client/node_modules/mingo/dist/esm/operators/update/min.js +6 -2
  49. package/rust-client/node_modules/mingo/dist/esm/operators/update/mul.js +6 -2
  50. package/rust-client/node_modules/mingo/dist/esm/operators/update/pop.js +6 -2
  51. package/rust-client/node_modules/mingo/dist/esm/operators/update/pull.js +6 -2
  52. package/rust-client/node_modules/mingo/dist/esm/operators/update/pullAll.js +2 -1
  53. package/rust-client/node_modules/mingo/dist/esm/operators/update/push.js +7 -2
  54. package/rust-client/node_modules/mingo/dist/esm/operators/update/rename.js +6 -2
  55. package/rust-client/node_modules/mingo/dist/esm/operators/update/set.js +7 -2
  56. package/rust-client/node_modules/mingo/dist/esm/operators/update/unset.js +2 -2
  57. package/rust-client/node_modules/mingo/dist/esm/query.js +11 -15
  58. package/rust-client/node_modules/mingo/dist/esm/updater.js +5 -19
  59. package/rust-client/node_modules/mingo/dist/esm/util.js +30 -18
  60. package/rust-client/node_modules/mingo/dist/types/aggregator.d.ts +1 -1
  61. package/rust-client/node_modules/mingo/dist/types/core.d.ts +10 -35
  62. package/rust-client/node_modules/mingo/dist/types/operators/pipeline/project.d.ts +2 -1
  63. package/rust-client/node_modules/mingo/dist/types/operators/update/_internal.d.ts +1 -0
  64. package/rust-client/node_modules/mingo/dist/types/query.d.ts +1 -1
  65. package/rust-client/node_modules/mingo/dist/types/util.d.ts +3 -3
  66. package/rust-client/node_modules/mingo/package.json +1 -1
@@ -22,125 +22,118 @@ __export(project_exports, {
22
22
  module.exports = __toCommonJS(project_exports);
23
23
  var import_core = require("../../core");
24
24
  var import_util = require("../../util");
25
- const DESCRIPTORS = new Set(Array.from([0, 1, false, true]));
26
25
  const $project = (collection, expr, options) => {
27
26
  if ((0, import_util.isEmpty)(expr)) return collection;
28
- const expressionKeys = Object.keys(expr);
29
27
  validateExpression(expr, options);
30
- const ID_KEY = options.idKey;
31
- if (!expressionKeys.includes(ID_KEY)) {
32
- expressionKeys.push(ID_KEY);
33
- }
34
- const copts = import_core.ComputeOptions.init(options);
35
- return collection.map((obj) => processObject(obj, expr, copts.update(obj), expressionKeys));
28
+ return collection.map(createHandler(expr, import_core.ComputeOptions.init(options)));
36
29
  };
37
- function processObject(obj, expr, options, expressionKeys) {
38
- let newObj = {};
39
- let foundSlice = false;
40
- let foundExclusion = false;
41
- const idOnlyExcluded = expr[options.idKey] === 0 && expressionKeys.length === 1;
42
- const dropKeys = [];
43
- if (idOnlyExcluded) {
44
- dropKeys.push(options.idKey);
45
- }
30
+ function createHandler(expr, options, isRoot = true) {
31
+ const idKey = options.idKey;
32
+ const expressionKeys = Object.keys(expr);
33
+ const excludedKeys = new Array();
34
+ const includedKeys = new Array();
35
+ const handlers = {};
46
36
  for (const key of expressionKeys) {
47
- let value = void 0;
48
37
  const subExpr = expr[key];
49
- if (key !== options.idKey && (subExpr === 0 || subExpr === false)) {
50
- foundExclusion = true;
51
- }
52
- if (key === options.idKey && (0, import_util.isEmpty)(subExpr)) {
53
- value = obj[key];
54
- } else if ((0, import_util.isString)(subExpr)) {
55
- value = (0, import_core.computeValue)(obj, subExpr, key, options);
56
- } else if (subExpr === 1 || subExpr === true) {
38
+ if ((0, import_util.isNumber)(subExpr) || (0, import_util.isBoolean)(subExpr)) {
39
+ if (subExpr) {
40
+ includedKeys.push(key);
41
+ } else {
42
+ excludedKeys.push(key);
43
+ }
57
44
  } else if ((0, import_util.isArray)(subExpr)) {
58
- value = subExpr.map((v) => {
59
- const r = (0, import_core.computeValue)(obj, v, null, options);
60
- if ((0, import_util.isNil)(r)) return null;
61
- return r;
62
- });
45
+ handlers[key] = (o) => subExpr.map((v) => (0, import_core.computeValue)(o, v, null, options.update(o)) ?? null);
63
46
  } else if ((0, import_util.isObject)(subExpr)) {
64
- const subExprObj = subExpr;
65
47
  const subExprKeys = Object.keys(subExpr);
66
48
  const operator = subExprKeys.length == 1 ? subExprKeys[0] : "";
67
- const call = (0, import_core.getOperator)(
49
+ const projectFn = (0, import_core.getOperator)(
68
50
  "projection",
69
51
  operator,
70
52
  options
71
53
  );
72
- if (call) {
73
- if (operator === "$slice") {
74
- if ((0, import_util.ensureArray)(subExprObj[operator]).every(import_util.isNumber)) {
75
- value = call(obj, subExprObj[operator], key, options);
76
- foundSlice = true;
77
- } else {
78
- value = (0, import_core.computeValue)(obj, subExprObj, key, options);
79
- }
54
+ if (projectFn) {
55
+ const foundSlice = operator === "$slice";
56
+ if (foundSlice && !(0, import_util.ensureArray)(subExpr[operator]).every(import_util.isNumber)) {
57
+ handlers[key] = (o) => (0, import_core.computeValue)(o, subExpr, key, options.update(o));
80
58
  } else {
81
- value = call(obj, subExprObj[operator], key, options);
59
+ handlers[key] = (o) => projectFn(o, subExpr[operator], key, options.update(o));
82
60
  }
83
61
  } else if ((0, import_util.isOperator)(operator)) {
84
- value = (0, import_core.computeValue)(obj, subExprObj[operator], operator, options);
85
- } else if ((0, import_util.has)(obj, key)) {
86
- validateExpression(subExprObj, options);
87
- let target = obj[key];
88
- if ((0, import_util.isArray)(target)) {
89
- value = target.map(
90
- (o) => processObject(o, subExprObj, options, subExprKeys)
91
- );
92
- } else {
93
- target = (0, import_util.isObject)(target) ? target : obj;
94
- value = processObject(
95
- target,
96
- subExprObj,
97
- options,
98
- subExprKeys
99
- );
100
- }
62
+ handlers[key] = (o) => (0, import_core.computeValue)(o, subExpr[operator], operator, options);
101
63
  } else {
102
- value = (0, import_core.computeValue)(obj, subExpr, null, options);
64
+ validateExpression(subExpr, options);
65
+ handlers[key] = (o) => {
66
+ if (!(0, import_util.has)(o, key)) return (0, import_core.computeValue)(o, subExpr, null, options);
67
+ if (isRoot) options.update(o);
68
+ const target = (0, import_util.resolve)(o, key);
69
+ const fn = createHandler(subExpr, options, false);
70
+ if ((0, import_util.isArray)(target)) return target.map(fn);
71
+ if ((0, import_util.isObject)(target)) return fn(target);
72
+ return fn(o);
73
+ };
103
74
  }
104
75
  } else {
105
- dropKeys.push(key);
106
- continue;
76
+ handlers[key] = (0, import_util.isString)(subExpr) && subExpr[0] === "$" ? (o) => (0, import_core.computeValue)(o, subExpr, key, options) : (_) => subExpr;
107
77
  }
108
- const objPathGraph = (0, import_util.resolveGraph)(obj, key, {
109
- preserveMissing: true
110
- });
111
- if ((0, import_util.isObject)(objPathGraph)) {
112
- (0, import_util.merge)(newObj, objPathGraph);
78
+ }
79
+ const handlerKeys = Object.keys(handlers);
80
+ const idKeyExcluded = excludedKeys.includes(idKey);
81
+ const idKeyOnlyExcluded = isRoot && idKeyExcluded && excludedKeys.length === 1 && !includedKeys.length && !handlerKeys.length;
82
+ if (idKeyOnlyExcluded) {
83
+ return (o) => {
84
+ const newObj = { ...o };
85
+ delete newObj[idKey];
86
+ return newObj;
87
+ };
88
+ }
89
+ const idKeyImplicit = isRoot && !idKeyExcluded && !includedKeys.includes(idKey);
90
+ const opts = {
91
+ preserveMissing: true
92
+ };
93
+ return (o) => {
94
+ const newObj = {};
95
+ if (excludedKeys.length && !includedKeys.length) {
96
+ (0, import_util.merge)(newObj, o);
97
+ for (const k of excludedKeys) {
98
+ (0, import_util.removeValue)(newObj, k, { descendArray: true });
99
+ }
100
+ }
101
+ for (const k of includedKeys) {
102
+ const pathObj = (0, import_util.resolveGraph)(o, k, opts) ?? {};
103
+ (0, import_util.merge)(newObj, pathObj);
113
104
  }
114
- if (!DESCRIPTORS.has(subExpr)) {
105
+ if (includedKeys.length) (0, import_util.filterMissing)(newObj);
106
+ for (const k of handlerKeys) {
107
+ const value = handlers[k](o);
115
108
  if (value === void 0) {
116
- (0, import_util.removeValue)(newObj, key, { descendArray: true });
109
+ (0, import_util.removeValue)(newObj, k, { descendArray: true });
117
110
  } else {
118
- (0, import_util.setValue)(newObj, key, value);
111
+ (0, import_util.setValue)(newObj, k, value);
119
112
  }
120
113
  }
121
- }
122
- (0, import_util.filterMissing)(newObj);
123
- if (foundSlice || foundExclusion || idOnlyExcluded) {
124
- newObj = (0, import_util.into)({}, obj, newObj);
125
- if (dropKeys.length > 0) {
126
- for (const k of dropKeys) {
127
- (0, import_util.removeValue)(newObj, k, { descendArray: true });
128
- }
114
+ if (idKeyImplicit && (0, import_util.has)(o, idKey)) {
115
+ newObj[idKey] = (0, import_util.resolve)(o, idKey);
129
116
  }
130
- }
131
- return newObj;
117
+ return newObj;
118
+ };
132
119
  }
133
120
  function validateExpression(expr, options) {
134
- const check = [false, false];
121
+ let exclusions = false;
122
+ let inclusions = false;
135
123
  for (const [k, v] of Object.entries(expr)) {
136
- if (k === options?.idKey) return;
124
+ (0, import_util.assert)(!k.startsWith("$"), "Field names may not start with '$'.");
125
+ (0, import_util.assert)(
126
+ !k.endsWith(".$"),
127
+ "Positional projection operator '$' is not supported."
128
+ );
129
+ if (k === options?.idKey) continue;
137
130
  if (v === 0 || v === false) {
138
- check[0] = true;
131
+ exclusions = true;
139
132
  } else if (v === 1 || v === true) {
140
- check[1] = true;
133
+ inclusions = true;
141
134
  }
142
135
  (0, import_util.assert)(
143
- !(check[0] && check[1]),
136
+ !(exclusions && inclusions),
144
137
  "Projection cannot have a mix of inclusion and exclusion."
145
138
  );
146
139
  }
@@ -1,6 +1,8 @@
1
+ var __create = Object.create;
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
4
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
7
  var __export = (target, all) => {
6
8
  for (var name in all)
@@ -14,17 +16,36 @@ var __copyProps = (to, from, except, desc) => {
14
16
  }
15
17
  return to;
16
18
  };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
17
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
28
  var internal_exports = {};
19
29
  __export(internal_exports, {
30
+ UPDATE_OPTIONS: () => UPDATE_OPTIONS,
20
31
  applyUpdate: () => applyUpdate,
21
32
  clone: () => clone,
22
33
  tokenizePath: () => tokenizePath,
23
34
  walkExpression: () => walkExpression
24
35
  });
25
36
  module.exports = __toCommonJS(internal_exports);
37
+ var import_core = require("../../core");
38
+ var booleanOperators = __toESM(require("../../operators/expression/boolean"));
39
+ var comparisonOperators = __toESM(require("../../operators/expression/comparison"));
40
+ var queryOperators = __toESM(require("../../operators/query"));
26
41
  var import_query = require("../../query");
27
42
  var import_util = require("../../util");
43
+ const UPDATE_OPTIONS = {
44
+ cloneMode: "copy",
45
+ queryOptions: (0, import_core.initOptions)({
46
+ context: import_core.Context.init().addQueryOps(queryOperators).addExpressionOps(booleanOperators).addExpressionOps(comparisonOperators)
47
+ })
48
+ };
28
49
  const clone = (mode, val) => {
29
50
  switch (mode) {
30
51
  case "deep":
@@ -104,6 +125,7 @@ function walkExpression(expr, arrayFilter, options, callback) {
104
125
  }
105
126
  // Annotate the CommonJS export names for ESM import in node:
106
127
  0 && (module.exports = {
128
+ UPDATE_OPTIONS,
107
129
  applyUpdate,
108
130
  clone,
109
131
  tokenizePath,
@@ -22,7 +22,7 @@ __export(addToSet_exports, {
22
22
  module.exports = __toCommonJS(addToSet_exports);
23
23
  var import_util = require("../../util");
24
24
  var import_internal = require("./_internal");
25
- const $addToSet = (obj, expr, arrayFilters = [], options = {}) => {
25
+ const $addToSet = (obj, expr, arrayFilters = [], options = import_internal.UPDATE_OPTIONS) => {
26
26
  return (0, import_internal.walkExpression)(expr, arrayFilters, options, (val, node, queries) => {
27
27
  const args = { $each: [val] };
28
28
  if ((0, import_util.isObject)(val) && (0, import_util.has)(val, "$each")) {
@@ -23,7 +23,7 @@ module.exports = __toCommonJS(bit_exports);
23
23
  var import_util = require("../../util");
24
24
  var import_internal = require("./_internal");
25
25
  const BIT_OPS = /* @__PURE__ */ new Set(["and", "or", "xor"]);
26
- const $bit = (obj, expr, arrayFilters = [], options = {}) => {
26
+ const $bit = (obj, expr, arrayFilters = [], options = import_internal.UPDATE_OPTIONS) => {
27
27
  return (0, import_internal.walkExpression)(expr, arrayFilters, options, (val, node, queries) => {
28
28
  const op = Object.keys(val);
29
29
  (0, import_util.assert)(
@@ -21,7 +21,7 @@ __export(currentDate_exports, {
21
21
  });
22
22
  module.exports = __toCommonJS(currentDate_exports);
23
23
  var import_internal = require("./_internal");
24
- const $currentDate = (obj, expr, arrayFilters = [], options = {}) => {
24
+ const $currentDate = (obj, expr, arrayFilters = [], options = import_internal.UPDATE_OPTIONS) => {
25
25
  const now = Date.now();
26
26
  return (0, import_internal.walkExpression)(expr, arrayFilters, options, (_, node, queries) => {
27
27
  return (0, import_internal.applyUpdate)(
@@ -22,7 +22,7 @@ __export(inc_exports, {
22
22
  module.exports = __toCommonJS(inc_exports);
23
23
  var import_util = require("../../util");
24
24
  var import_internal = require("./_internal");
25
- const $inc = (obj, expr, arrayFilters = [], options = {}) => {
25
+ const $inc = (obj, expr, arrayFilters = [], options = import_internal.UPDATE_OPTIONS) => {
26
26
  return (0, import_internal.walkExpression)(expr, arrayFilters, options, (val, node, queries) => {
27
27
  if (!node.child) {
28
28
  const n = (0, import_util.resolve)(obj, node.parent);
@@ -22,7 +22,7 @@ __export(max_exports, {
22
22
  module.exports = __toCommonJS(max_exports);
23
23
  var import_util = require("../../util");
24
24
  var import_internal = require("./_internal");
25
- const $max = (obj, expr, arrayFilters = [], options = {}) => {
25
+ const $max = (obj, expr, arrayFilters = [], options = import_internal.UPDATE_OPTIONS) => {
26
26
  return (0, import_internal.walkExpression)(expr, arrayFilters, options, (val, node, queries) => {
27
27
  return (0, import_internal.applyUpdate)(
28
28
  obj,
@@ -22,7 +22,7 @@ __export(min_exports, {
22
22
  module.exports = __toCommonJS(min_exports);
23
23
  var import_util = require("../../util");
24
24
  var import_internal = require("./_internal");
25
- const $min = (obj, expr, arrayFilters = [], options = {}) => {
25
+ const $min = (obj, expr, arrayFilters = [], options = import_internal.UPDATE_OPTIONS) => {
26
26
  return (0, import_internal.walkExpression)(expr, arrayFilters, options, (val, node, queries) => {
27
27
  return (0, import_internal.applyUpdate)(
28
28
  obj,
@@ -21,7 +21,7 @@ __export(mul_exports, {
21
21
  });
22
22
  module.exports = __toCommonJS(mul_exports);
23
23
  var import_internal = require("./_internal");
24
- const $mul = (obj, expr, arrayFilters = [], options = {}) => {
24
+ const $mul = (obj, expr, arrayFilters = [], options = import_internal.UPDATE_OPTIONS) => {
25
25
  return (0, import_internal.walkExpression)(expr, arrayFilters, options, (val, node, queries) => {
26
26
  return (0, import_internal.applyUpdate)(
27
27
  obj,
@@ -22,7 +22,7 @@ __export(pop_exports, {
22
22
  module.exports = __toCommonJS(pop_exports);
23
23
  var import_util = require("../../util");
24
24
  var import_internal = require("./_internal");
25
- const $pop = (obj, expr, arrayFilters = [], options = {}) => {
25
+ const $pop = (obj, expr, arrayFilters = [], options = import_internal.UPDATE_OPTIONS) => {
26
26
  return (0, import_internal.walkExpression)(expr, arrayFilters, options, (val, node, queries) => {
27
27
  return (0, import_internal.applyUpdate)(obj, node, queries, (o, k) => {
28
28
  const arr = o[k];
@@ -23,7 +23,7 @@ module.exports = __toCommonJS(pull_exports);
23
23
  var import_query = require("../../query");
24
24
  var import_util = require("../../util");
25
25
  var import_internal = require("./_internal");
26
- const $pull = (obj, expr, arrayFilters = [], options = {}) => {
26
+ const $pull = (obj, expr, arrayFilters = [], options = import_internal.UPDATE_OPTIONS) => {
27
27
  return (0, import_internal.walkExpression)(expr, arrayFilters, options, (val, node, queries) => {
28
28
  const wrap = !(0, import_util.isObject)(val) || Object.keys(val).some(import_util.isOperator);
29
29
  const query = new import_query.Query(
@@ -20,8 +20,9 @@ __export(pullAll_exports, {
20
20
  $pullAll: () => $pullAll
21
21
  });
22
22
  module.exports = __toCommonJS(pullAll_exports);
23
+ var import_internal = require("./_internal");
23
24
  var import_pull = require("./pull");
24
- const $pullAll = (obj, expr, arrayFilters = [], options = {}) => {
25
+ const $pullAll = (obj, expr, arrayFilters = [], options = import_internal.UPDATE_OPTIONS) => {
25
26
  const pullExpr = {};
26
27
  Object.entries(expr).forEach(([k, v]) => {
27
28
  pullExpr[k] = { $in: v };
@@ -28,7 +28,7 @@ const OPERATOR_MODIFIERS = Object.freeze([
28
28
  "$sort",
29
29
  "$position"
30
30
  ]);
31
- const $push = (obj, expr, arrayFilters = [], options = {}) => {
31
+ const $push = (obj, expr, arrayFilters = [], options = import_internal.UPDATE_OPTIONS) => {
32
32
  return (0, import_internal.walkExpression)(expr, arrayFilters, options, (val, node, queries) => {
33
33
  const args = {
34
34
  $each: [val]
@@ -23,7 +23,7 @@ module.exports = __toCommonJS(rename_exports);
23
23
  var import_util = require("../../util");
24
24
  var import_internal = require("./_internal");
25
25
  var import_set = require("./set");
26
- const $rename = (obj, expr, arrayFilters = [], options = {}) => {
26
+ const $rename = (obj, expr, arrayFilters = [], options = import_internal.UPDATE_OPTIONS) => {
27
27
  const res = [];
28
28
  const changed = (0, import_internal.walkExpression)(expr, arrayFilters, options, (val, node, queries) => {
29
29
  return (0, import_internal.applyUpdate)(obj, node, queries, (o, k) => {
@@ -22,7 +22,7 @@ __export(set_exports, {
22
22
  module.exports = __toCommonJS(set_exports);
23
23
  var import_util = require("../../util");
24
24
  var import_internal = require("./_internal");
25
- const $set = (obj, expr, arrayFilters = [], options = {}) => {
25
+ const $set = (obj, expr, arrayFilters = [], options = import_internal.UPDATE_OPTIONS) => {
26
26
  return (0, import_internal.walkExpression)(expr, arrayFilters, options, (val, node, queries) => {
27
27
  return (0, import_internal.applyUpdate)(
28
28
  obj,
@@ -22,7 +22,7 @@ __export(unset_exports, {
22
22
  module.exports = __toCommonJS(unset_exports);
23
23
  var import_util = require("../../util");
24
24
  var import_internal = require("./_internal");
25
- const $unset = (obj, expr, arrayFilters = [], options = {}) => {
25
+ const $unset = (obj, expr, arrayFilters = [], options = import_internal.UPDATE_OPTIONS) => {
26
26
  return (0, import_internal.walkExpression)(expr, arrayFilters, options, (_, node, queries) => {
27
27
  return (0, import_internal.applyUpdate)(obj, node, queries, (o, k) => {
28
28
  if (!(0, import_util.has)(o, k)) return false;
@@ -31,7 +31,7 @@ class Query {
31
31
  #options;
32
32
  #condition;
33
33
  constructor(condition, options) {
34
- this.#condition = condition;
34
+ this.#condition = (0, import_util.cloneDeep)(condition);
35
35
  this.#options = (0, import_core.initOptions)(options);
36
36
  this.#compiled = [];
37
37
  this.compile();
@@ -44,6 +44,10 @@ class Query {
44
44
  const whereOperator = {};
45
45
  for (const [field, expr] of Object.entries(this.#condition)) {
46
46
  if ("$where" === field) {
47
+ (0, import_util.assert)(
48
+ this.#options.scriptEnabled,
49
+ "$where operator requires 'scriptEnabled' option to be true."
50
+ );
47
51
  Object.assign(whereOperator, { field, expr });
48
52
  } else if (TOP_LEVEL_OPS.has(field)) {
49
53
  this.processOperator(field, field, expr);
@@ -66,25 +70,17 @@ class Query {
66
70
  }
67
71
  processOperator(field, operator, value) {
68
72
  const call = (0, import_core.getOperator)("query", operator, this.#options);
69
- if (!call) {
70
- throw new import_util.MingoError(`unknown query operator ${operator}`);
71
- }
72
- const fn = call(field, value, this.#options);
73
- this.#compiled.push(fn);
73
+ (0, import_util.assert)(!!call, `unknown query operator ${operator}`);
74
+ this.#compiled.push(call(field, value, this.#options));
74
75
  }
75
76
  /**
76
77
  * Checks if the object passes the query criteria. Returns true if so, false otherwise.
77
78
  *
78
79
  * @param obj The object to test
79
- * @returns {boolean} True or false
80
+ * @returns {boolean}
80
81
  */
81
82
  test(obj) {
82
- for (let i = 0, len = this.#compiled.length; i < len; i++) {
83
- if (!this.#compiled[i](obj)) {
84
- return false;
85
- }
86
- }
87
- return true;
83
+ return this.#compiled.every((p) => p(obj));
88
84
  }
89
85
  /**
90
86
  * Returns a cursor to select matching documents from the input source.
@@ -96,7 +92,7 @@ class Query {
96
92
  find(collection, projection) {
97
93
  return new import_cursor.Cursor(
98
94
  collection,
99
- (x) => this.test(x),
95
+ (o) => this.test(o),
100
96
  projection || {},
101
97
  this.#options
102
98
  );
@@ -32,27 +32,13 @@ __export(updater_exports, {
32
32
  updateObject: () => updateObject
33
33
  });
34
34
  module.exports = __toCommonJS(updater_exports);
35
- var import_core = require("./core");
36
- var booleanOperators = __toESM(require("./operators/expression/boolean"));
37
- var comparisonOperators = __toESM(require("./operators/expression/comparison"));
38
- var queryOperators = __toESM(require("./operators/query"));
39
35
  var UPDATE_OPERATORS = __toESM(require("./operators/update"));
36
+ var import_internal = require("./operators/update/_internal");
40
37
  var import_query = require("./query");
41
38
  var import_util = require("./util");
42
39
  function createUpdater(defaultOptions) {
43
- defaultOptions = defaultOptions || {};
44
- defaultOptions = {
45
- ...defaultOptions,
46
- queryOptions: (0, import_core.initOptions)(defaultOptions.queryOptions)
47
- };
48
- defaultOptions.queryOptions.context.addQueryOps(queryOperators).addExpressionOps(booleanOperators).addExpressionOps(comparisonOperators);
49
- return (obj, expr, arrayFilters = [], condition = {}, options = {}) => {
50
- const opts = Object.assign({ cloneMode: "copy" }, defaultOptions, options);
51
- Object.assign(opts, {
52
- queryOptions: (0, import_core.initOptions)(
53
- Object.assign({ useStrictMode: false }, opts?.queryOptions)
54
- )
55
- });
40
+ defaultOptions = defaultOptions ?? import_internal.UPDATE_OPTIONS;
41
+ return (obj, expr, arrayFilters = [], condition = {}, options = defaultOptions) => {
56
42
  const entry = Object.entries(expr);
57
43
  (0, import_util.assert)(
58
44
  entry.length === 1,
@@ -65,10 +51,10 @@ function createUpdater(defaultOptions) {
65
51
  );
66
52
  const mutate = UPDATE_OPERATORS[op];
67
53
  if (Object.keys(condition).length) {
68
- const q = condition instanceof import_query.Query ? condition : new import_query.Query(condition, opts.queryOptions);
54
+ const q = new import_query.Query(condition, options.queryOptions);
69
55
  if (!q.test(obj)) return [];
70
56
  }
71
- return mutate(obj, args, arrayFilters, opts);
57
+ return mutate(obj, args, arrayFilters, options);
72
58
  };
73
59
  }
74
60
  const update = createUpdater();
@@ -72,9 +72,6 @@ const DEFAULT_HASH_FUNCTION = (value) => {
72
72
  while (i) hash = (hash << 5) - hash ^ s.charCodeAt(--i);
73
73
  return hash >>> 0;
74
74
  };
75
- const objectProto = Object.prototype;
76
- const arrayProto = Array.prototype;
77
- const getPrototypeOf = Object.getPrototypeOf;
78
75
  const isPrimitive = (v) => typeof v !== "object" && typeof v !== "function" || v === null;
79
76
  const isScalar = (v) => isPrimitive(v) || isDate(v) || isRegExp(v);
80
77
  const SORT_ORDER = {
@@ -184,7 +181,7 @@ function assert(condition, message) {
184
181
  if (!condition) throw new MingoError(message);
185
182
  }
186
183
  const typeOf = (v) => {
187
- const s = objectProto.toString.call(v);
184
+ const s = Object.prototype.toString.call(v);
188
185
  const t = s.substring(8, s.length - 1).toLowerCase();
189
186
  if (t !== "object") return t;
190
187
  const ctor = v.constructor;
@@ -209,7 +206,7 @@ const isNil = (v) => v === null || v === void 0;
209
206
  const truthy = (arg, strict = true) => !!arg || strict && arg === "";
210
207
  const isEmpty = (x) => isNil(x) || isString(x) && !x || isArray(x) && x.length === 0 || isObject(x) && Object.keys(x).length === 0;
211
208
  const ensureArray = (x) => isArray(x) ? x : [x];
212
- const has = (obj, prop) => !!obj && objectProto.hasOwnProperty.call(obj, prop);
209
+ const has = (obj, prop) => !!obj && Object.prototype.hasOwnProperty.call(obj, prop);
213
210
  const isTypedArray = (v) => typeof ArrayBuffer !== "undefined" && ArrayBuffer.isView(v);
214
211
  const cloneDeep = (v, refs) => {
215
212
  if (isNil(v) || isBoolean(v) || isNumber(v) || isString(v)) return v;
@@ -284,23 +281,39 @@ function flatten(xs, depth = 1) {
284
281
  flatten2(xs, depth);
285
282
  return arr;
286
283
  }
284
+ const objToString = Object.prototype.toString;
285
+ function hasCustomToString(o) {
286
+ if (isTypedArray(o)) return true;
287
+ if (typeof o.toString === "function") {
288
+ let proto = Object.getPrototypeOf(o);
289
+ while (proto !== null) {
290
+ if (has(proto, "toString") && proto.toString !== objToString) {
291
+ return true;
292
+ }
293
+ proto = Object.getPrototypeOf(proto);
294
+ }
295
+ }
296
+ return false;
297
+ }
287
298
  function isEqual(a, b) {
288
299
  if (a === b || Object.is(a, b)) return true;
289
- const ctor = !!a && a.constructor || a;
290
- if (a === null || b === null || a === void 0 || b === void 0 || ctor !== b.constructor || ctor === Function) {
291
- return false;
292
- }
300
+ if (a === null || b === null) return false;
301
+ if (typeof a !== typeof b) return false;
302
+ if (typeof a !== "object") return false;
303
+ if (a.constructor !== b.constructor) return false;
304
+ if (a instanceof Date) return +a === +b;
305
+ if (a instanceof RegExp) return a.toString() === b.toString();
306
+ const ctor = a.constructor;
293
307
  if (ctor === Array || ctor === Object) {
294
- const aKeys = Object.keys(a);
295
- const bKeys = Object.keys(b);
308
+ const aKeys = Object.keys(a).sort();
309
+ const bKeys = Object.keys(b).sort();
296
310
  if (aKeys.length !== bKeys.length) return false;
297
- if ((/* @__PURE__ */ new Set([...aKeys, ...bKeys])).size != aKeys.length) return false;
298
- for (const k of aKeys) if (!isEqual(a[k], b[k])) return false;
311
+ for (let i = 0, k = aKeys[i]; i < aKeys.length; k = aKeys[++i]) {
312
+ if (k !== bKeys[i] || !isEqual(a[k], b[k])) return false;
313
+ }
299
314
  return true;
300
315
  }
301
- const proto = getPrototypeOf(a);
302
- const cmp = isTypedArray(a) || proto !== objectProto && proto !== arrayProto && has(proto, "toString");
303
- return cmp && a.toString() === b.toString();
316
+ return hasCustomToString(a) && a.toString() === b.toString();
304
317
  }
305
318
  function unique(input, hashFunction = DEFAULT_HASH_FUNCTION) {
306
319
  const m = ValueMap.init(hashFunction);
@@ -325,8 +338,7 @@ const stringify = (v, refs) => {
325
338
  const keys = Object.keys(v).sort();
326
339
  return "{" + keys.map((k) => `${k}:${stringify(v[k], refs)}`).join() + "}";
327
340
  }
328
- const proto = Object.getPrototypeOf(v);
329
- if (proto !== objectProto && proto !== arrayProto && has(proto, "toString")) {
341
+ if (hasCustomToString(v)) {
330
342
  return typeOf(v) + "(" + JSON.stringify(v.toString()) + ")";
331
343
  }
332
344
  throw new Error(
@@ -4,7 +4,7 @@ import {
4
4
  ProcessingMode
5
5
  } from "./core";
6
6
  import { Lazy } from "./lazy";
7
- import { assert, cloneDeep, intersection, isEmpty } from "./util";
7
+ import { assert, cloneDeep, isEmpty } from "./util";
8
8
  class Aggregator {
9
9
  #pipeline;
10
10
  #options;
@@ -15,34 +15,30 @@ class Aggregator {
15
15
  /**
16
16
  * Returns an {@link Iterator} for lazy evaluation of the pipeline.
17
17
  *
18
- * @param {*} collection An array or iterator object
18
+ * @param collection An array or iterator object
19
19
  * @returns {Iterator} an iterator object
20
20
  */
21
21
  stream(collection, options) {
22
- let iterator = Lazy(collection);
22
+ let iter = Lazy(collection);
23
23
  const opts = options ?? this.#options;
24
24
  const mode = opts.processingMode;
25
- if (mode == ProcessingMode.CLONE_ALL || mode == ProcessingMode.CLONE_INPUT) {
26
- iterator.map(cloneDeep);
27
- }
25
+ if (mode & ProcessingMode.CLONE_INPUT) iter.map(cloneDeep);
28
26
  const stages = new Array();
29
27
  if (!isEmpty(this.#pipeline)) {
30
- for (const operator of this.#pipeline) {
31
- const operatorKeys = Object.keys(operator);
32
- const opName = operatorKeys[0];
28
+ for (const opExpr of this.#pipeline) {
29
+ const opKeys = Object.keys(opExpr);
30
+ const opName = opKeys[0];
33
31
  const call = getOperator("pipeline", opName, opts);
34
32
  assert(
35
- operatorKeys.length === 1 && !!call,
33
+ opKeys.length === 1 && !!call,
36
34
  `invalid pipeline operator ${opName}`
37
35
  );
38
36
  stages.push(opName);
39
- iterator = call(iterator, operator[opName], opts);
37
+ iter = call(iter, opExpr[opName], opts);
40
38
  }
41
39
  }
42
- if (mode == ProcessingMode.CLONE_OUTPUT || mode == ProcessingMode.CLONE_ALL && !!intersection([["$group", "$unwind"], stages]).length) {
43
- iterator.map(cloneDeep);
44
- }
45
- return iterator;
40
+ if (mode & ProcessingMode.CLONE_OUTPUT) iter.map(cloneDeep);
41
+ return iter;
46
42
  }
47
43
  /**
48
44
  * Return the results of the aggregation as an array.