@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.
- package/node_modules/glide-rs/glide-rs.darwin-arm64.node +0 -0
- package/package.json +1 -1
- package/rust-client/node_modules/mingo/README.md +81 -42
- package/rust-client/node_modules/mingo/dist/cjs/aggregator.js +10 -14
- package/rust-client/node_modules/mingo/dist/cjs/core.js +8 -13
- package/rust-client/node_modules/mingo/dist/cjs/cursor.js +24 -12
- package/rust-client/node_modules/mingo/dist/cjs/operators/_predicates.js +0 -1
- package/rust-client/node_modules/mingo/dist/cjs/operators/accumulator/bottomN.js +3 -2
- package/rust-client/node_modules/mingo/dist/cjs/operators/accumulator/topN.js +3 -4
- package/rust-client/node_modules/mingo/dist/cjs/operators/expression/array/sortArray.js +3 -2
- package/rust-client/node_modules/mingo/dist/cjs/operators/pipeline/fill.js +1 -1
- package/rust-client/node_modules/mingo/dist/cjs/operators/pipeline/lookup.js +3 -4
- package/rust-client/node_modules/mingo/dist/cjs/operators/pipeline/project.js +78 -85
- package/rust-client/node_modules/mingo/dist/cjs/operators/update/_internal.js +22 -0
- package/rust-client/node_modules/mingo/dist/cjs/operators/update/addToSet.js +1 -1
- package/rust-client/node_modules/mingo/dist/cjs/operators/update/bit.js +1 -1
- package/rust-client/node_modules/mingo/dist/cjs/operators/update/currentDate.js +1 -1
- package/rust-client/node_modules/mingo/dist/cjs/operators/update/inc.js +1 -1
- package/rust-client/node_modules/mingo/dist/cjs/operators/update/max.js +1 -1
- package/rust-client/node_modules/mingo/dist/cjs/operators/update/min.js +1 -1
- package/rust-client/node_modules/mingo/dist/cjs/operators/update/mul.js +1 -1
- package/rust-client/node_modules/mingo/dist/cjs/operators/update/pop.js +1 -1
- package/rust-client/node_modules/mingo/dist/cjs/operators/update/pull.js +1 -1
- package/rust-client/node_modules/mingo/dist/cjs/operators/update/pullAll.js +2 -1
- package/rust-client/node_modules/mingo/dist/cjs/operators/update/push.js +1 -1
- package/rust-client/node_modules/mingo/dist/cjs/operators/update/rename.js +1 -1
- package/rust-client/node_modules/mingo/dist/cjs/operators/update/set.js +1 -1
- package/rust-client/node_modules/mingo/dist/cjs/operators/update/unset.js +1 -1
- package/rust-client/node_modules/mingo/dist/cjs/query.js +10 -14
- package/rust-client/node_modules/mingo/dist/cjs/updater.js +5 -19
- package/rust-client/node_modules/mingo/dist/cjs/util.js +30 -18
- package/rust-client/node_modules/mingo/dist/esm/aggregator.js +11 -15
- package/rust-client/node_modules/mingo/dist/esm/core.js +8 -13
- package/rust-client/node_modules/mingo/dist/esm/cursor.js +27 -13
- package/rust-client/node_modules/mingo/dist/esm/operators/_predicates.js +0 -1
- package/rust-client/node_modules/mingo/dist/esm/operators/accumulator/bottomN.js +3 -2
- package/rust-client/node_modules/mingo/dist/esm/operators/accumulator/topN.js +3 -4
- package/rust-client/node_modules/mingo/dist/esm/operators/expression/array/sortArray.js +3 -2
- package/rust-client/node_modules/mingo/dist/esm/operators/pipeline/fill.js +1 -1
- package/rust-client/node_modules/mingo/dist/esm/operators/pipeline/lookup.js +3 -4
- package/rust-client/node_modules/mingo/dist/esm/operators/pipeline/project.js +80 -87
- package/rust-client/node_modules/mingo/dist/esm/operators/update/_internal.js +11 -0
- package/rust-client/node_modules/mingo/dist/esm/operators/update/addToSet.js +7 -2
- package/rust-client/node_modules/mingo/dist/esm/operators/update/bit.js +6 -2
- package/rust-client/node_modules/mingo/dist/esm/operators/update/currentDate.js +6 -2
- package/rust-client/node_modules/mingo/dist/esm/operators/update/inc.js +2 -2
- package/rust-client/node_modules/mingo/dist/esm/operators/update/max.js +6 -2
- package/rust-client/node_modules/mingo/dist/esm/operators/update/min.js +6 -2
- package/rust-client/node_modules/mingo/dist/esm/operators/update/mul.js +6 -2
- package/rust-client/node_modules/mingo/dist/esm/operators/update/pop.js +6 -2
- package/rust-client/node_modules/mingo/dist/esm/operators/update/pull.js +6 -2
- package/rust-client/node_modules/mingo/dist/esm/operators/update/pullAll.js +2 -1
- package/rust-client/node_modules/mingo/dist/esm/operators/update/push.js +7 -2
- package/rust-client/node_modules/mingo/dist/esm/operators/update/rename.js +6 -2
- package/rust-client/node_modules/mingo/dist/esm/operators/update/set.js +7 -2
- package/rust-client/node_modules/mingo/dist/esm/operators/update/unset.js +2 -2
- package/rust-client/node_modules/mingo/dist/esm/query.js +11 -15
- package/rust-client/node_modules/mingo/dist/esm/updater.js +5 -19
- package/rust-client/node_modules/mingo/dist/esm/util.js +30 -18
- package/rust-client/node_modules/mingo/dist/types/aggregator.d.ts +1 -1
- package/rust-client/node_modules/mingo/dist/types/core.d.ts +10 -35
- package/rust-client/node_modules/mingo/dist/types/operators/pipeline/project.d.ts +2 -1
- package/rust-client/node_modules/mingo/dist/types/operators/update/_internal.d.ts +1 -0
- package/rust-client/node_modules/mingo/dist/types/query.d.ts +1 -1
- package/rust-client/node_modules/mingo/dist/types/util.d.ts +3 -3
- package/rust-client/node_modules/mingo/package.json +1 -1
|
Binary file
|
package/package.json
CHANGED
|
@@ -29,7 +29,7 @@ MongoDB query language for in-memory objects
|
|
|
29
29
|
|
|
30
30
|
For more documentation on how to use operators see [mongodb](http://docs.mongodb.org/manual/reference/operator/).
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
[API Documentation](http://kofrasa.github.io/mingo/).
|
|
33
33
|
|
|
34
34
|
## Usage
|
|
35
35
|
|
|
@@ -41,14 +41,14 @@ import mingo from "mingo";
|
|
|
41
41
|
const mingo = require("mingo");
|
|
42
42
|
```
|
|
43
43
|
|
|
44
|
-
The main module exports `
|
|
44
|
+
The main module exports functions `aggregate`, `find`, `remove`, and `update`, and the objects `Aggregator` and `Query`. [Query and Projection](https://docs.mongodb.com/manual/reference/operator/query/) operators are loaded by default by the root through the side-effect module [init/basic](https://github.com/kofrasa/mingo/blob/main/src/init/basic.ts). This also automatically includes pipeline operators; `$project`, `$skip`, `$limit`, and `$sort`.
|
|
45
45
|
|
|
46
46
|
## Loading Operators
|
|
47
47
|
|
|
48
|
-
MongoDB query library is huge and you may not need all the operators.
|
|
48
|
+
MongoDB query library is huge and you may not need all the operators. When using this library on the server-side where bundle size is not a concern, you can load all operators as shown below.
|
|
49
49
|
|
|
50
50
|
```js
|
|
51
|
-
//
|
|
51
|
+
// This effectively imports the entire library into your bundle.
|
|
52
52
|
import "mingo/init/system";
|
|
53
53
|
```
|
|
54
54
|
|
|
@@ -64,8 +64,8 @@ To support tree-shaking for client side bundles, you can import and register spe
|
|
|
64
64
|
|
|
65
65
|
```js
|
|
66
66
|
import { useOperators } from "mingo/core";
|
|
67
|
-
import { $trunc } from "mingo/operators/expression";
|
|
68
|
-
import { $bucket } from "mingo/operators/pipeline";
|
|
67
|
+
import { $trunc } from "mingo/operators/expression/trunc";
|
|
68
|
+
import { $bucket } from "mingo/operators/pipeline/bucket";
|
|
69
69
|
|
|
70
70
|
useOperators("expression", { $trunc });
|
|
71
71
|
useOperators("pipeline", { $bucket });
|
|
@@ -75,12 +75,11 @@ useOperators("pipeline", { $bucket });
|
|
|
75
75
|
|
|
76
76
|
```js
|
|
77
77
|
const core = require("mingo/core");
|
|
78
|
-
const $trunc = require("mingo/operators/expression").$trunc;
|
|
79
|
-
const $bucket = require("mingo/operators/pipeline").$bucket;
|
|
80
|
-
const useOperators = core.useOperators;
|
|
78
|
+
const $trunc = require("mingo/operators/expression/trunc").$trunc;
|
|
79
|
+
const $bucket = require("mingo/operators/pipeline/bucket").$bucket;
|
|
81
80
|
|
|
82
|
-
useOperators("expression", { $trunc: $trunc });
|
|
83
|
-
useOperators("pipeline", { $bucket: $bucket });
|
|
81
|
+
core.useOperators("expression", { $trunc: $trunc });
|
|
82
|
+
core.useOperators("pipeline", { $bucket: $bucket });
|
|
84
83
|
```
|
|
85
84
|
|
|
86
85
|
## Using query to test objects
|
|
@@ -143,8 +142,9 @@ No default implementation is provided out of the box so users can use a library
|
|
|
143
142
|
The example below uses [Ajv](https://www.npmjs.com/package/ajv) to implement schema validation.
|
|
144
143
|
|
|
145
144
|
```js
|
|
146
|
-
import
|
|
147
|
-
import {
|
|
145
|
+
import * as mingo from "mingo"
|
|
146
|
+
import type { AnyObject } from "mingo/types"
|
|
147
|
+
import type { JsonSchemaValidator } from "mingo/core"
|
|
148
148
|
import Ajv, { Schema } from "ajv"
|
|
149
149
|
|
|
150
150
|
const jsonSchemaValidator: JsonSchemaValidator = (s: AnyObject) => {
|
|
@@ -173,7 +173,7 @@ const schema = {
|
|
|
173
173
|
};
|
|
174
174
|
|
|
175
175
|
// queries documents using schema validation
|
|
176
|
-
find(docs, { $jsonSchema: schema }, {}, { jsonSchemaValidator }).all();
|
|
176
|
+
mingo.find(docs, { $jsonSchema: schema }, {}, { jsonSchemaValidator }).all();
|
|
177
177
|
```
|
|
178
178
|
|
|
179
179
|
**Note:** An error is thrown when the `$jsonSchema` operator is used without a the `jsonSchemaValidator` configured.
|
|
@@ -207,27 +207,27 @@ let result = agg.run(collection);
|
|
|
207
207
|
|
|
208
208
|
Query and aggregation operations can be configured with options to enabled different features or customize how documents are processed. Some options are only relevant to specific operators and need not be specified if not required.
|
|
209
209
|
|
|
210
|
-
| Name
|
|
211
|
-
|
|
|
212
|
-
|
|
|
213
|
-
|
|
|
214
|
-
|
|
|
215
|
-
|
|
|
216
|
-
|
|
|
217
|
-
|
|
|
218
|
-
|
|
|
219
|
-
|
|
|
220
|
-
|
|
|
221
|
-
|
|
|
222
|
-
|
|
|
210
|
+
| Name | Default | Description |
|
|
211
|
+
| -----| --------| ----------- |
|
|
212
|
+
| collation | _none_ | [Collation](http://kofrasa.github.io/mingo/interfaces/core.CollationSpec.html) specification for string sorting operations. See [Intl.Collator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Collator) |
|
|
213
|
+
| collectionResolver | _none_ | <p>Function to resolve strings to arrays for use with operators that reference other collections such as; `$lookup`, `$out` and `$merge`.</p>Expects: `(string) => AnyObject[]`. |
|
|
214
|
+
| context | _none_ | <p>An object that defines which operators should be used.</p>This option allow users to load only desired operators or register custom operators which need not be available globally. |
|
|
215
|
+
| hashFunction | _default_ | <p>Custom hash function to replace the default based on "Effective Java" hashCode.</p>Expects: `(Any) => number`. |
|
|
216
|
+
| idKey | `"_id"` | <p>The key that is used to lookup the ID value of a document.</p> |
|
|
217
|
+
| jsonSchemaValidator | _none_ | <p>JSON schema validator to use for the `$jsonSchema` operator.</p>Expects: `(schema: AnyObject) => (document: AnyObject) => boolean`.<br>The `$jsonSchema` operation would fail if a validator is not provided. |
|
|
218
|
+
| processingMode | [CLONE_OFF](http://kofrasa.github.io/mingo/enums/core.ProcessingMode.html) | <p>Specifies the degree of mutation for inputs and outputs. By default the input collection is modified as needed and returned output objects may share references.</p> Immutable intermediate results may be collected in a pipeline using the `$out` operator. |
|
|
219
|
+
| scriptEnabled | `true` | <p>Enable or disable using custom script execution.</p>When disabled, operators that execute custom code are disallowed such as; `$where`, `$accumulator`, and `$function`. |
|
|
220
|
+
| useGlobalContext | `true`| <p>Fallback to the global context if an operator is missing from the user-supplied context.</p>This is provided to allow users to strictly enforce which operators may be used. |
|
|
221
|
+
| useStrictMode | `true` | <p>Enforces strict MongoDB compatibilty.</p>When disabled the behaviour changes as follows. <ul><li>`$elemMatch` returns all matching nested documents instead of only the first.</li><li>Empty string `""` is coerced to false during boolean checking in supported operators which is consistent with Javascript semantics.</li><li>`$type` returns JS native type names as follows. <table><thead><tr><td>MongoDB</td><td>JavaScript</td></tr></thead><tr><td><code>"missing"</code></td><td><code>"undefined"</code></td></tr><tr><td><code>"bool"</code></td><td><code>"boolean"</code></td></tr><tr><td><code>"int"|"long"|"double"</code></td><td><code>"number"</code></td></tr><tr><td><code>"regex"</code></td><td><code>"regexp"</code></td></tr></table> |
|
|
222
|
+
| variables | `{}` | Global variables to pass to all operators |
|
|
223
223
|
|
|
224
|
-
##
|
|
224
|
+
## Custom Operators
|
|
225
225
|
|
|
226
|
-
Custom operators can be registered using `Context` via the `context` option which is the recommended way
|
|
226
|
+
Custom operators can be registered using a `Context` object via the `context` option which is the recommended way since `6.4.2`. `Context` provides a container for operators, that the execution engine will use to process queries. To register an operator globally, the [useOperators(...)](https://kofrasa.github.io/mingo/functions/core.useOperators.html) function is available. Globally registered operators cannot be overwritten whereas a new context may be created and used at anytime.
|
|
227
227
|
|
|
228
|
-
**NB: Note that the execution engine will first try to find the operator in the context and fallback to the global context when not found
|
|
228
|
+
**NB: Note that the execution engine will first try to find the operator in the context and fallback to the global context when not found if the `useGlobalContext` option is `true`.**
|
|
229
229
|
|
|
230
|
-
|
|
230
|
+
Custom operators must conform to the signatures of their types.
|
|
231
231
|
|
|
232
232
|
- [AccumulatorOperator](http://kofrasa.github.io/mingo/types/core.AccumulatorOperator.html)
|
|
233
233
|
- [ExpressionOperator](http://kofrasa.github.io/mingo/types/core.ExpressionOperator.html)
|
|
@@ -236,14 +236,57 @@ Each operator type has a specific interface to which an implementation must conf
|
|
|
236
236
|
- [WindowOperator](http://kofrasa.github.io/mingo/types/core.WindowOperator.html)
|
|
237
237
|
- [QueryOperator](http://kofrasa.github.io/mingo/types/core.QueryOperator.html)
|
|
238
238
|
|
|
239
|
-
|
|
239
|
+
To define custom operators, the following imports are useful.
|
|
240
240
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
241
|
+
```js
|
|
242
|
+
const mingo = require("mingo")
|
|
243
|
+
const core = require("mingo/core");
|
|
244
|
+
const util = require("mingo/util");
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
### Custom Operator Examples
|
|
248
|
+
```js
|
|
249
|
+
// this example creates a query operator that checks is a value is between a boundary.
|
|
250
|
+
const $between = (selector, args, options) => {
|
|
251
|
+
return (obj) => {
|
|
252
|
+
const value = util.resolve(obj, selector, { unwrapArray: true });
|
|
253
|
+
return value >= args[0] && value <= args[1];
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
// a test collection
|
|
257
|
+
const collection = [
|
|
258
|
+
{ a: 1, b: 1 },
|
|
259
|
+
{ a: 7, b: 1 },
|
|
260
|
+
{ a: 10, b: 6 },
|
|
261
|
+
{ a: 20, b: 10 }
|
|
262
|
+
];
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
#### Register csutom operator using the context option.
|
|
266
|
+
The custom operator is registerd with a user-provided context object that is passed an option to the query. The context will be searched for operators used in a query and fallback to the global context when not found.
|
|
245
267
|
|
|
246
|
-
|
|
268
|
+
```ts
|
|
269
|
+
const context = core.Context.init().addQueryOps({ $between })
|
|
270
|
+
// must specify context option to make operator available
|
|
271
|
+
const result = mingo.find(collection, { a: { $between: [5, 10] } }, {}, { context }).all()
|
|
272
|
+
console.log(result) // output => [ { a: 7, b: 1 }, { a: 10, b: 6 } ]
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
#### Register custom operator globally using useOperators.
|
|
276
|
+
|
|
277
|
+
The custom operator is registered to be available globally.
|
|
278
|
+
|
|
279
|
+
```ts
|
|
280
|
+
// register the operator for global use.
|
|
281
|
+
try {
|
|
282
|
+
core.useOperators("query", { $between })
|
|
283
|
+
} catch {
|
|
284
|
+
// error thrown if an operator with name "$between" is already registered.
|
|
285
|
+
}
|
|
286
|
+
// query with new operator
|
|
287
|
+
const result = mingo.find(collection, { a: { $between: [5, 10] }}).all()
|
|
288
|
+
console.log(result) // output => [ { a: 7, b: 1 }, { a: 10, b: 6 } ]
|
|
289
|
+
```
|
|
247
290
|
|
|
248
291
|
## Updating Documents
|
|
249
292
|
|
|
@@ -306,17 +349,13 @@ Below is a description of how this library differs from the full MongoDB query e
|
|
|
306
349
|
|
|
307
350
|
1. There is no concept of a collection. Input is an array, generator or iterable of objects.
|
|
308
351
|
1. Support a single numeric type `number`.
|
|
309
|
-
1. When `useStrictMode` is `false`, replace MongoDB [types](https://www.mongodb.com/docs/manual/reference/operator/aggregation/type/#available-types) with JS native types as follows;
|
|
310
|
-
- `"bool"` -> `"boolean"`.
|
|
311
|
-
- `"int"|"long"|"double"|"decimal"` -> `"number"`.
|
|
312
|
-
- `"missing"` -> `"undefined"`.
|
|
313
352
|
1. Does not support [types](https://www.mongodb.com/docs/manual/reference/operator/aggregation/type/#available-types) `"minKey"`, `"maxKey"`, `"timestamp"`, or `"binData"`.
|
|
314
353
|
1. Does not support server specific operators. E.g. `$collStat`, `$planCacheStats`, `$listSessions`.
|
|
315
354
|
1. Does not support geometry query operators.
|
|
316
355
|
1. Does not support query operators dependent on persistent storage; `$comment`, `$meta`, `$text`.
|
|
317
356
|
1. Does not support positional query or update operator `$`.
|
|
318
357
|
1. Does not support server specific expression operators; `$toObjectId`, `$binarySize`, `bsonSize`.
|
|
319
|
-
1.
|
|
358
|
+
1. Aggregation pipeline operator `$merge` enforces unique constraint on the lookup field during input processing.
|
|
320
359
|
1. Custom function evaluation operators; `$where`, `$function`, and `$accumulator`, do not accept strings as the function body.
|
|
321
360
|
1. Custom function evaluation operators are enabled by default. They can be disabled with the `scriptEnabled` option.
|
|
322
361
|
1. Custom function evaluation operator [$accumulator](https://docs.mongodb.com/manual/reference/operator/aggregation/accumulator/) does not support the `merge` option.
|
|
@@ -33,34 +33,30 @@ class Aggregator {
|
|
|
33
33
|
/**
|
|
34
34
|
* Returns an {@link Iterator} for lazy evaluation of the pipeline.
|
|
35
35
|
*
|
|
36
|
-
* @param
|
|
36
|
+
* @param collection An array or iterator object
|
|
37
37
|
* @returns {Iterator} an iterator object
|
|
38
38
|
*/
|
|
39
39
|
stream(collection, options) {
|
|
40
|
-
let
|
|
40
|
+
let iter = (0, import_lazy.Lazy)(collection);
|
|
41
41
|
const opts = options ?? this.#options;
|
|
42
42
|
const mode = opts.processingMode;
|
|
43
|
-
if (mode
|
|
44
|
-
iterator.map(import_util.cloneDeep);
|
|
45
|
-
}
|
|
43
|
+
if (mode & import_core.ProcessingMode.CLONE_INPUT) iter.map(import_util.cloneDeep);
|
|
46
44
|
const stages = new Array();
|
|
47
45
|
if (!(0, import_util.isEmpty)(this.#pipeline)) {
|
|
48
|
-
for (const
|
|
49
|
-
const
|
|
50
|
-
const opName =
|
|
46
|
+
for (const opExpr of this.#pipeline) {
|
|
47
|
+
const opKeys = Object.keys(opExpr);
|
|
48
|
+
const opName = opKeys[0];
|
|
51
49
|
const call = (0, import_core.getOperator)("pipeline", opName, opts);
|
|
52
50
|
(0, import_util.assert)(
|
|
53
|
-
|
|
51
|
+
opKeys.length === 1 && !!call,
|
|
54
52
|
`invalid pipeline operator ${opName}`
|
|
55
53
|
);
|
|
56
54
|
stages.push(opName);
|
|
57
|
-
|
|
55
|
+
iter = call(iter, opExpr[opName], opts);
|
|
58
56
|
}
|
|
59
57
|
}
|
|
60
|
-
if (mode
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
return iterator;
|
|
58
|
+
if (mode & import_core.ProcessingMode.CLONE_OUTPUT) iter.map(import_util.cloneDeep);
|
|
59
|
+
return iter;
|
|
64
60
|
}
|
|
65
61
|
/**
|
|
66
62
|
* Return the results of the aggregation as an array.
|
|
@@ -30,10 +30,10 @@ __export(core_exports, {
|
|
|
30
30
|
module.exports = __toCommonJS(core_exports);
|
|
31
31
|
var import_util = require("./util");
|
|
32
32
|
var ProcessingMode = /* @__PURE__ */ ((ProcessingMode2) => {
|
|
33
|
-
ProcessingMode2["
|
|
34
|
-
ProcessingMode2["CLONE_INPUT"] = "CLONE_INPUT";
|
|
35
|
-
ProcessingMode2["CLONE_OUTPUT"] = "CLONE_OUTPUT";
|
|
36
|
-
ProcessingMode2["
|
|
33
|
+
ProcessingMode2[ProcessingMode2["CLONE_OFF"] = 0] = "CLONE_OFF";
|
|
34
|
+
ProcessingMode2[ProcessingMode2["CLONE_INPUT"] = 1] = "CLONE_INPUT";
|
|
35
|
+
ProcessingMode2[ProcessingMode2["CLONE_OUTPUT"] = 2] = "CLONE_OUTPUT";
|
|
36
|
+
ProcessingMode2[ProcessingMode2["CLONE_ALL"] = 3] = "CLONE_ALL";
|
|
37
37
|
return ProcessingMode2;
|
|
38
38
|
})(ProcessingMode || {});
|
|
39
39
|
class ComputeOptions {
|
|
@@ -47,23 +47,18 @@ class ComputeOptions {
|
|
|
47
47
|
}
|
|
48
48
|
/**
|
|
49
49
|
* Initialize new ComputeOptions.
|
|
50
|
-
*
|
|
51
|
-
* @param options
|
|
52
|
-
* @param root
|
|
53
|
-
* @param local
|
|
54
50
|
* @returns {ComputeOptions}
|
|
55
51
|
*/
|
|
56
52
|
static init(options, root, local) {
|
|
57
|
-
return options instanceof ComputeOptions ? new ComputeOptions(options.#options, options.root ?? root, {
|
|
53
|
+
return !(options instanceof ComputeOptions) ? new ComputeOptions(options, root, local) : new ComputeOptions(options.#options, options.root ?? root, {
|
|
58
54
|
...options.#local,
|
|
59
55
|
...local,
|
|
60
|
-
// retain existing variables
|
|
61
56
|
variables: Object.assign(
|
|
62
57
|
{},
|
|
63
58
|
options.#local?.variables,
|
|
64
59
|
local?.variables
|
|
65
60
|
)
|
|
66
|
-
})
|
|
61
|
+
});
|
|
67
62
|
}
|
|
68
63
|
/**
|
|
69
64
|
* Updates the internal state.
|
|
@@ -105,7 +100,7 @@ class ComputeOptions {
|
|
|
105
100
|
return this.#options?.collation;
|
|
106
101
|
}
|
|
107
102
|
get processingMode() {
|
|
108
|
-
return this.#options?.processingMode ||
|
|
103
|
+
return this.#options?.processingMode || 0 /* CLONE_OFF */;
|
|
109
104
|
}
|
|
110
105
|
get useStrictMode() {
|
|
111
106
|
return this.#options?.useStrictMode;
|
|
@@ -138,7 +133,7 @@ function initOptions(options) {
|
|
|
138
133
|
scriptEnabled: true,
|
|
139
134
|
useStrictMode: true,
|
|
140
135
|
useGlobalContext: true,
|
|
141
|
-
processingMode:
|
|
136
|
+
processingMode: 0 /* CLONE_OFF */,
|
|
142
137
|
...options,
|
|
143
138
|
context: options?.context ? Context.from(options?.context) : Context.init()
|
|
144
139
|
});
|
|
@@ -20,15 +20,20 @@ __export(cursor_exports, {
|
|
|
20
20
|
Cursor: () => Cursor
|
|
21
21
|
});
|
|
22
22
|
module.exports = __toCommonJS(cursor_exports);
|
|
23
|
-
var
|
|
23
|
+
var import_core = require("./core");
|
|
24
24
|
var import_lazy = require("./lazy");
|
|
25
|
+
var import_limit = require("./operators/pipeline/limit");
|
|
26
|
+
var import_project = require("./operators/pipeline/project");
|
|
27
|
+
var import_skip = require("./operators/pipeline/skip");
|
|
28
|
+
var import_sort = require("./operators/pipeline/sort");
|
|
25
29
|
var import_util = require("./util");
|
|
30
|
+
const OPERATORS = { $sort: import_sort.$sort, $skip: import_skip.$skip, $limit: import_limit.$limit };
|
|
26
31
|
class Cursor {
|
|
27
32
|
#source;
|
|
28
33
|
#predicate;
|
|
29
34
|
#projection;
|
|
30
35
|
#options;
|
|
31
|
-
#operators =
|
|
36
|
+
#operators = {};
|
|
32
37
|
#result = null;
|
|
33
38
|
#buffer = [];
|
|
34
39
|
constructor(source, predicate, projection, options) {
|
|
@@ -40,15 +45,22 @@ class Cursor {
|
|
|
40
45
|
/** Returns the iterator from running the query */
|
|
41
46
|
fetch() {
|
|
42
47
|
if (this.#result) return this.#result;
|
|
43
|
-
if ((0, import_util.isObject)(this.#projection)) {
|
|
44
|
-
this.#operators.push({ $project: this.#projection });
|
|
45
|
-
}
|
|
46
48
|
this.#result = (0, import_lazy.Lazy)(this.#source).filter(this.#predicate);
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
)
|
|
49
|
+
const mode = this.#options.processingMode;
|
|
50
|
+
if (mode & import_core.ProcessingMode.CLONE_INPUT) this.#result.map(import_util.cloneDeep);
|
|
51
|
+
for (const op of ["$sort", "$skip", "$limit"]) {
|
|
52
|
+
if ((0, import_util.has)(this.#operators, op)) {
|
|
53
|
+
this.#result = OPERATORS[op](
|
|
54
|
+
this.#result,
|
|
55
|
+
this.#operators[op],
|
|
56
|
+
this.#options
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (Object.keys(this.#projection).length) {
|
|
61
|
+
this.#result = (0, import_project.$project)(this.#result, this.#projection, this.#options);
|
|
51
62
|
}
|
|
63
|
+
if (mode & import_core.ProcessingMode.CLONE_OUTPUT) this.#result.map(import_util.cloneDeep);
|
|
52
64
|
return this.#result;
|
|
53
65
|
}
|
|
54
66
|
/** Returns an iterator with the buffered data included */
|
|
@@ -77,7 +89,7 @@ class Cursor {
|
|
|
77
89
|
* @return {Cursor} Returns the cursor, so you can chain this call.
|
|
78
90
|
*/
|
|
79
91
|
skip(n) {
|
|
80
|
-
this.#operators
|
|
92
|
+
this.#operators["$skip"] = n;
|
|
81
93
|
return this;
|
|
82
94
|
}
|
|
83
95
|
/**
|
|
@@ -86,7 +98,7 @@ class Cursor {
|
|
|
86
98
|
* @return {Cursor} Returns the cursor, so you can chain this call.
|
|
87
99
|
*/
|
|
88
100
|
limit(n) {
|
|
89
|
-
this.#operators
|
|
101
|
+
this.#operators["$limit"] = n;
|
|
90
102
|
return this;
|
|
91
103
|
}
|
|
92
104
|
/**
|
|
@@ -95,7 +107,7 @@ class Cursor {
|
|
|
95
107
|
* @return {Cursor} Returns the cursor, so you can chain this call.
|
|
96
108
|
*/
|
|
97
109
|
sort(modifier) {
|
|
98
|
-
this.#operators
|
|
110
|
+
this.#operators["$sort"] = modifier;
|
|
99
111
|
return this;
|
|
100
112
|
}
|
|
101
113
|
/**
|
|
@@ -20,8 +20,9 @@ __export(bottomN_exports, {
|
|
|
20
20
|
$bottomN: () => $bottomN
|
|
21
21
|
});
|
|
22
22
|
module.exports = __toCommonJS(bottomN_exports);
|
|
23
|
-
var import_aggregator = require("../../aggregator");
|
|
24
23
|
var import_core = require("../../core");
|
|
24
|
+
var import_lazy = require("../../lazy");
|
|
25
|
+
var import_sort = require("../pipeline/sort");
|
|
25
26
|
var import_push = require("./push");
|
|
26
27
|
const $bottomN = (collection, expr, options) => {
|
|
27
28
|
const copts = import_core.ComputeOptions.init(options);
|
|
@@ -31,7 +32,7 @@ const $bottomN = (collection, expr, options) => {
|
|
|
31
32
|
null,
|
|
32
33
|
copts
|
|
33
34
|
);
|
|
34
|
-
const result =
|
|
35
|
+
const result = (0, import_sort.$sort)((0, import_lazy.Lazy)(collection), sortBy, options).value();
|
|
35
36
|
const m = result.length;
|
|
36
37
|
const p = n;
|
|
37
38
|
return (0, import_push.$push)(m <= p ? result : result.slice(m - p), expr.output, copts);
|
|
@@ -20,8 +20,9 @@ __export(topN_exports, {
|
|
|
20
20
|
$topN: () => $topN
|
|
21
21
|
});
|
|
22
22
|
module.exports = __toCommonJS(topN_exports);
|
|
23
|
-
var import_aggregator = require("../../aggregator");
|
|
24
23
|
var import_core = require("../../core");
|
|
24
|
+
var import_lazy = require("../../lazy");
|
|
25
|
+
var import_sort = require("../pipeline/sort");
|
|
25
26
|
var import_push = require("./push");
|
|
26
27
|
const $topN = (collection, expr, options) => {
|
|
27
28
|
const copts = import_core.ComputeOptions.init(options);
|
|
@@ -31,9 +32,7 @@ const $topN = (collection, expr, options) => {
|
|
|
31
32
|
null,
|
|
32
33
|
copts
|
|
33
34
|
);
|
|
34
|
-
const result =
|
|
35
|
-
collection
|
|
36
|
-
);
|
|
35
|
+
const result = (0, import_sort.$sort)((0, import_lazy.Lazy)(collection), sortBy, options).take(n).value();
|
|
37
36
|
return (0, import_push.$push)(result, expr.output, copts);
|
|
38
37
|
};
|
|
39
38
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -20,15 +20,16 @@ __export(sortArray_exports, {
|
|
|
20
20
|
$sortArray: () => $sortArray
|
|
21
21
|
});
|
|
22
22
|
module.exports = __toCommonJS(sortArray_exports);
|
|
23
|
-
var import_aggregator = require("../../../aggregator");
|
|
24
23
|
var import_core = require("../../../core");
|
|
24
|
+
var import_lazy = require("../../../lazy");
|
|
25
25
|
var import_util = require("../../../util");
|
|
26
|
+
var import_sort = require("../../pipeline/sort");
|
|
26
27
|
const $sortArray = (obj, expr, options) => {
|
|
27
28
|
const { input, sortBy } = (0, import_core.computeValue)(obj, expr, null, options);
|
|
28
29
|
if ((0, import_util.isNil)(input)) return null;
|
|
29
30
|
(0, import_util.assert)((0, import_util.isArray)(input), "$sortArray expression must resolve to an array");
|
|
30
31
|
if ((0, import_util.isObject)(sortBy)) {
|
|
31
|
-
return
|
|
32
|
+
return (0, import_sort.$sort)((0, import_lazy.Lazy)(input), sortBy, options).value();
|
|
32
33
|
}
|
|
33
34
|
const result = [...input];
|
|
34
35
|
result.sort(import_util.compare);
|
|
@@ -48,7 +48,7 @@ const $fill = (collection, expr, options) => {
|
|
|
48
48
|
options = (0, import_core.initOptions)(options);
|
|
49
49
|
options.context.addExpressionOps({ $ifNull: import_ifNull.$ifNull });
|
|
50
50
|
options.context.addWindowOps({ $locf: import_locf.$locf, $linearFill: import_linearFill.$linearFill });
|
|
51
|
-
const partitionExpr = expr.partitionBy || expr?.partitionByFields?.map((s) =>
|
|
51
|
+
const partitionExpr = expr.partitionBy || expr?.partitionByFields?.map((s) => "$" + s);
|
|
52
52
|
const valueExpr = {};
|
|
53
53
|
const methodExpr = {};
|
|
54
54
|
for (const [k, m] of Object.entries(expr.output)) {
|
|
@@ -62,11 +62,10 @@ const $lookup = (collection, expr, options) => {
|
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
const agg = new import_aggregator.Aggregator(subQueryPipeline, options);
|
|
65
|
+
const opts = { ...options };
|
|
65
66
|
return collection.map((obj) => {
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
variables: { ...options.variables, ...variables }
|
|
69
|
-
});
|
|
67
|
+
const vars = (0, import_core.computeValue)(obj, letExpr, null, options);
|
|
68
|
+
opts.variables = { ...options.variables, ...vars };
|
|
70
69
|
const [ok, res] = lookupEq(obj);
|
|
71
70
|
return {
|
|
72
71
|
...obj,
|