sluice-orm 0.1.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/LICENSE.txt +373 -0
- package/README.md +191 -0
- package/dist/index.cjs +977 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +2444 -0
- package/dist/index.d.ts +2444 -0
- package/dist/index.js +911 -0
- package/dist/index.js.map +1 -0
- package/package.json +86 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,911 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
+
|
|
5
|
+
// src/accumulator-utils.ts
|
|
6
|
+
var functionToString = (fn) => {
|
|
7
|
+
const fnStr = fn.toString();
|
|
8
|
+
if (!fnStr.includes("=>")) return fnStr;
|
|
9
|
+
const paramMatch = /^(?:\(([^)]*)\)|(\w+))\s*=>/.exec(fnStr);
|
|
10
|
+
if (!paramMatch) throw new Error(`Cannot parse arrow function parameters: ${fnStr}`);
|
|
11
|
+
const params = paramMatch[1] ?? paramMatch[2];
|
|
12
|
+
const arrowIndex = fnStr.indexOf("=>");
|
|
13
|
+
const body = fnStr.slice(arrowIndex + 2).trim();
|
|
14
|
+
const hasBlock = body.startsWith("{");
|
|
15
|
+
return hasBlock ? `function(${params}) ${body}` : `function(${params}) { return ${body}; }`;
|
|
16
|
+
};
|
|
17
|
+
var resolveAccumulator = (config) => {
|
|
18
|
+
const result = {
|
|
19
|
+
init: functionToString(config.init),
|
|
20
|
+
initArgs: config.initArgs,
|
|
21
|
+
accumulate: functionToString(config.accumulate),
|
|
22
|
+
accumulateArgs: config.accumulateArgs,
|
|
23
|
+
merge: functionToString(config.merge),
|
|
24
|
+
lang: config.lang
|
|
25
|
+
};
|
|
26
|
+
return config.finalize ? { ...result, finalize: functionToString(config.finalize) } : result;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// src/builder.ts
|
|
30
|
+
import { ObjectId } from "mongodb";
|
|
31
|
+
var Ret = class {
|
|
32
|
+
constructor(__fn, __minVersion = "") {
|
|
33
|
+
this.__fn = __fn;
|
|
34
|
+
this.__minVersion = __minVersion;
|
|
35
|
+
__publicField(this, "__context");
|
|
36
|
+
__publicField(this, "__type");
|
|
37
|
+
__publicField(this, "__tag", "Ret");
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
var BaseBuilder = class {
|
|
41
|
+
constructor() {
|
|
42
|
+
// Identity: single argument passed through
|
|
43
|
+
__publicField(this, "id", (op) => (arg) => new Ret({ [`$${op}`]: this._resolve(arg) }));
|
|
44
|
+
// Varargs: multiple arguments as array
|
|
45
|
+
__publicField(this, "varargs", (op) => (...args) => new Ret({ [`$${op}`]: args.map((arg) => this._resolve(arg)) }));
|
|
46
|
+
// Flexible: 1 arg -> raw value, >1 args -> array (for operators that are both unary accumulators and variadic expressions)
|
|
47
|
+
__publicField(this, "flexible", (op) => (...args) => new Ret({
|
|
48
|
+
[`$${op}`]: args.length === 1 ? this._resolve(args[0]) : args.map(this._resolve.bind(this))
|
|
49
|
+
}));
|
|
50
|
+
// Options: single object argument
|
|
51
|
+
__publicField(this, "options", (op) => (options) => new Ret({ [`$${op}`]: this._resolve(options) }));
|
|
52
|
+
// Nullary: no arguments
|
|
53
|
+
__publicField(this, "nullary", (op) => () => new Ret({ [`$${op}`]: {} }));
|
|
54
|
+
// Pipeline builder for $facet and sub-pipelines
|
|
55
|
+
__publicField(this, "pipe", ((...stages) => stages.reduce((agg, stageFn) => stageFn(agg), {
|
|
56
|
+
stages: []
|
|
57
|
+
})));
|
|
58
|
+
// Query helper for $match array element filters
|
|
59
|
+
__publicField(this, "elemMatch", (filter) => ({
|
|
60
|
+
$elemMatch: filter(new ExprBuilder())
|
|
61
|
+
}));
|
|
62
|
+
// ==========================================
|
|
63
|
+
// Arithmetic Operators
|
|
64
|
+
// ==========================================
|
|
65
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/add/
|
|
66
|
+
__publicField(this, "add", this.varargs("add"));
|
|
67
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/subtract/
|
|
68
|
+
__publicField(this, "subtract", this.varargs("subtract"));
|
|
69
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/multiply/
|
|
70
|
+
__publicField(this, "multiply", this.varargs("multiply"));
|
|
71
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/divide/
|
|
72
|
+
__publicField(this, "divide", this.varargs("divide"));
|
|
73
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/mod/
|
|
74
|
+
__publicField(this, "mod", this.varargs("mod"));
|
|
75
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/abs/
|
|
76
|
+
__publicField(this, "abs", this.id("abs"));
|
|
77
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/ceil/
|
|
78
|
+
__publicField(this, "ceil", this.id("ceil"));
|
|
79
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/floor/
|
|
80
|
+
__publicField(this, "floor", this.id("floor"));
|
|
81
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/ln/
|
|
82
|
+
__publicField(this, "ln", this.id("ln"));
|
|
83
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/log/
|
|
84
|
+
__publicField(this, "log", this.varargs("log"));
|
|
85
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/log10/
|
|
86
|
+
__publicField(this, "log10", this.id("log10"));
|
|
87
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/pow/
|
|
88
|
+
__publicField(this, "pow", this.varargs("pow"));
|
|
89
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/sqrt/
|
|
90
|
+
__publicField(this, "sqrt", this.id("sqrt"));
|
|
91
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/trunc/
|
|
92
|
+
__publicField(this, "trunc", (num, place) => place !== void 0 ? this.varargs("trunc")(num, place) : this.options("trunc")(num));
|
|
93
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/round/
|
|
94
|
+
__publicField(this, "round", (num, place) => place !== void 0 ? this.varargs("round")(num, place) : this.options("round")(num));
|
|
95
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/exp/
|
|
96
|
+
__publicField(this, "exp", this.id("exp"));
|
|
97
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/rand/
|
|
98
|
+
__publicField(this, "rand", this.nullary("rand"));
|
|
99
|
+
// ==========================================
|
|
100
|
+
// Array Operators
|
|
101
|
+
// ==========================================
|
|
102
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/arrayElemAt/
|
|
103
|
+
__publicField(this, "arrayElemAt", this.varargs("arrayElemAt"));
|
|
104
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/arrayToObject/
|
|
105
|
+
__publicField(this, "arrayToObject", this.id("arrayToObject"));
|
|
106
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/concatArrays/
|
|
107
|
+
__publicField(this, "concatArrays", this.varargs("concatArrays"));
|
|
108
|
+
/** Selects a subset of array elements that match a condition.
|
|
109
|
+
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/filter/ */
|
|
110
|
+
__publicField(this, "filter", this.options("filter"));
|
|
111
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/first/
|
|
112
|
+
__publicField(this, "first", this.id("first"));
|
|
113
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/in/
|
|
114
|
+
__publicField(this, "in", this.varargs("in"));
|
|
115
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/indexOfArray/
|
|
116
|
+
__publicField(this, "indexOfArray", this.options("indexOfArray"));
|
|
117
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/isArray/
|
|
118
|
+
__publicField(this, "isArray", this.id("isArray"));
|
|
119
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/last/
|
|
120
|
+
__publicField(this, "last", this.id("last"));
|
|
121
|
+
/** Applies an expression to each element of an array and returns the results.
|
|
122
|
+
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/map/ */
|
|
123
|
+
__publicField(this, "map", this.options("map"));
|
|
124
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/maxN/
|
|
125
|
+
__publicField(this, "maxN", this.options("maxN"));
|
|
126
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/minN/
|
|
127
|
+
__publicField(this, "minN", this.options("minN"));
|
|
128
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/firstN/
|
|
129
|
+
__publicField(this, "firstN", this.options("firstN"));
|
|
130
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/lastN/
|
|
131
|
+
__publicField(this, "lastN", this.options("lastN"));
|
|
132
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/objectToArray/
|
|
133
|
+
__publicField(this, "objectToArray", this.id("objectToArray"));
|
|
134
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/range/
|
|
135
|
+
__publicField(this, "range", (start, end, step) => step !== void 0 ? this.varargs("range")(start, end, step) : this.varargs("range")(start, end));
|
|
136
|
+
/** Applies an expression to each element of an array, accumulating into a single value.
|
|
137
|
+
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/reduce/ */
|
|
138
|
+
__publicField(this, "reduce", this.options("reduce"));
|
|
139
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/reverseArray/
|
|
140
|
+
__publicField(this, "reverseArray", this.id("reverseArray"));
|
|
141
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/size/
|
|
142
|
+
__publicField(this, "size", this.id("size"));
|
|
143
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/slice/
|
|
144
|
+
__publicField(this, "slice", (array, n, position) => position !== void 0 ? this.varargs("slice")(array, n, position) : this.varargs("slice")(array, n));
|
|
145
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/sortArray/
|
|
146
|
+
__publicField(this, "sortArray", this.options("sortArray"));
|
|
147
|
+
// zip with proper tuple typing
|
|
148
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/zip/
|
|
149
|
+
__publicField(this, "zip", this.options("zip"));
|
|
150
|
+
// ==========================================
|
|
151
|
+
// Comparison Operators
|
|
152
|
+
// ==========================================
|
|
153
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/cmp/
|
|
154
|
+
__publicField(this, "cmp", this.varargs("cmp"));
|
|
155
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/eq/
|
|
156
|
+
__publicField(this, "eq", this.varargs("eq"));
|
|
157
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/gt/
|
|
158
|
+
__publicField(this, "gt", this.varargs("gt"));
|
|
159
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/gte/
|
|
160
|
+
__publicField(this, "gte", this.varargs("gte"));
|
|
161
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/lt/
|
|
162
|
+
__publicField(this, "lt", this.varargs("lt"));
|
|
163
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/lte/
|
|
164
|
+
__publicField(this, "lte", this.varargs("lte"));
|
|
165
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/ne/
|
|
166
|
+
__publicField(this, "ne", this.varargs("ne"));
|
|
167
|
+
// Boolean operators (fully typed from ExprBuilder)
|
|
168
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/and/
|
|
169
|
+
__publicField(this, "and", this.varargs("and"));
|
|
170
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/or/
|
|
171
|
+
__publicField(this, "or", this.varargs("or"));
|
|
172
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/nor/
|
|
173
|
+
__publicField(this, "nor", this.varargs("nor"));
|
|
174
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/not/
|
|
175
|
+
__publicField(this, "not", this.id("not"));
|
|
176
|
+
// Conditional operators (fully typed from ExprBuilder)
|
|
177
|
+
/** Evaluates a boolean expression and returns one of two values.
|
|
178
|
+
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/cond/ */
|
|
179
|
+
__publicField(this, "cond", this.options("cond"));
|
|
180
|
+
/** Returns the first non-null/non-missing expression (null coalescing).
|
|
181
|
+
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/ifNull/ */
|
|
182
|
+
__publicField(this, "ifNull", this.varargs("ifNull"));
|
|
183
|
+
/** Evaluates a series of case expressions, returning the value of the first match.
|
|
184
|
+
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/switch/ */
|
|
185
|
+
__publicField(this, "switch", this.options("switch"));
|
|
186
|
+
// String operators (fully typed from ExprBuilder)
|
|
187
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/concat/
|
|
188
|
+
__publicField(this, "concat", this.varargs("concat"));
|
|
189
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/indexOfBytes/
|
|
190
|
+
__publicField(this, "indexOfBytes", (string, substring, start, end) => {
|
|
191
|
+
const args = [string, substring];
|
|
192
|
+
if (start !== void 0) args.push(start);
|
|
193
|
+
if (end !== void 0) args.push(end);
|
|
194
|
+
return this.varargs("indexOfBytes")(...args);
|
|
195
|
+
});
|
|
196
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/indexOfCP/
|
|
197
|
+
__publicField(this, "indexOfCP", (string, substring, start, end) => {
|
|
198
|
+
const args = [string, substring];
|
|
199
|
+
if (start !== void 0) args.push(start);
|
|
200
|
+
if (end !== void 0) args.push(end);
|
|
201
|
+
return this.varargs("indexOfCP")(...args);
|
|
202
|
+
});
|
|
203
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/ltrim/
|
|
204
|
+
__publicField(this, "ltrim", this.options("ltrim"));
|
|
205
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/regexFind/
|
|
206
|
+
__publicField(this, "regexFind", this.options("regexFind"));
|
|
207
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/regexFindAll/
|
|
208
|
+
__publicField(this, "regexFindAll", this.options("regexFindAll"));
|
|
209
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/regexMatch/
|
|
210
|
+
__publicField(this, "regexMatch", this.options("regexMatch"));
|
|
211
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceAll/
|
|
212
|
+
__publicField(this, "replaceAll", this.options("replaceAll"));
|
|
213
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceOne/
|
|
214
|
+
__publicField(this, "replaceOne", this.options("replaceOne"));
|
|
215
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/rtrim/
|
|
216
|
+
__publicField(this, "rtrim", this.options("rtrim"));
|
|
217
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/split/
|
|
218
|
+
__publicField(this, "split", this.varargs("split"));
|
|
219
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/strcasecmp/
|
|
220
|
+
__publicField(this, "strcasecmp", this.varargs("strcasecmp"));
|
|
221
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/strLenBytes/
|
|
222
|
+
__publicField(this, "strLenBytes", this.id("strLenBytes"));
|
|
223
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/strLenCP/
|
|
224
|
+
__publicField(this, "strLenCP", this.id("strLenCP"));
|
|
225
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/substr/
|
|
226
|
+
__publicField(this, "substr", this.varargs("substr"));
|
|
227
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/substrBytes/
|
|
228
|
+
__publicField(this, "substrBytes", this.varargs("substrBytes"));
|
|
229
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/substrCP/
|
|
230
|
+
__publicField(this, "substrCP", this.varargs("substrCP"));
|
|
231
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/toLower/
|
|
232
|
+
__publicField(this, "toLower", this.id("toLower"));
|
|
233
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/toUpper/
|
|
234
|
+
__publicField(this, "toUpper", this.id("toUpper"));
|
|
235
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/trim/
|
|
236
|
+
__publicField(this, "trim", this.options("trim"));
|
|
237
|
+
// Set operators (fully typed from ExprBuilder)
|
|
238
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/allElementsTrue/
|
|
239
|
+
__publicField(this, "allElementsTrue", this.id("allElementsTrue"));
|
|
240
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/anyElementTrue/
|
|
241
|
+
__publicField(this, "anyElementTrue", this.id("anyElementTrue"));
|
|
242
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/setDifference/
|
|
243
|
+
__publicField(this, "setDifference", this.varargs("setDifference"));
|
|
244
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/setEquals/
|
|
245
|
+
__publicField(this, "setEquals", this.varargs("setEquals"));
|
|
246
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/setIntersection/
|
|
247
|
+
__publicField(this, "setIntersection", this.varargs("setIntersection"));
|
|
248
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/setIsSubset/
|
|
249
|
+
__publicField(this, "setIsSubset", this.varargs("setIsSubset"));
|
|
250
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/setUnion/
|
|
251
|
+
__publicField(this, "setUnion", this.varargs("setUnion"));
|
|
252
|
+
// Date operators (fully typed from ExprBuilder)
|
|
253
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateAdd/
|
|
254
|
+
__publicField(this, "dateAdd", this.options("dateAdd"));
|
|
255
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateDiff/
|
|
256
|
+
__publicField(this, "dateDiff", this.options("dateDiff"));
|
|
257
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateFromParts/
|
|
258
|
+
__publicField(this, "dateFromParts", this.options("dateFromParts"));
|
|
259
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateFromString/
|
|
260
|
+
__publicField(this, "dateFromString", this.options("dateFromString"));
|
|
261
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateSubtract/
|
|
262
|
+
__publicField(this, "dateSubtract", this.options("dateSubtract"));
|
|
263
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateToParts/
|
|
264
|
+
__publicField(this, "dateToParts", this.options("dateToParts"));
|
|
265
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateToString/
|
|
266
|
+
__publicField(this, "dateToString", this.options("dateToString"));
|
|
267
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateTrunc/
|
|
268
|
+
__publicField(this, "dateTrunc", this.options("dateTrunc"));
|
|
269
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/dayOfMonth/
|
|
270
|
+
__publicField(this, "dayOfMonth", this.id("dayOfMonth"));
|
|
271
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/dayOfWeek/
|
|
272
|
+
__publicField(this, "dayOfWeek", this.id("dayOfWeek"));
|
|
273
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/dayOfYear/
|
|
274
|
+
__publicField(this, "dayOfYear", this.id("dayOfYear"));
|
|
275
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/hour/
|
|
276
|
+
__publicField(this, "hour", this.id("hour"));
|
|
277
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/isoDayOfWeek/
|
|
278
|
+
__publicField(this, "isoDayOfWeek", this.id("isoDayOfWeek"));
|
|
279
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/isoWeek/
|
|
280
|
+
__publicField(this, "isoWeek", this.id("isoWeek"));
|
|
281
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/isoWeekYear/
|
|
282
|
+
__publicField(this, "isoWeekYear", this.id("isoWeekYear"));
|
|
283
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/millisecond/
|
|
284
|
+
__publicField(this, "millisecond", this.id("millisecond"));
|
|
285
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/minute/
|
|
286
|
+
__publicField(this, "minute", this.id("minute"));
|
|
287
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/month/
|
|
288
|
+
__publicField(this, "month", this.id("month"));
|
|
289
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/second/
|
|
290
|
+
__publicField(this, "second", this.id("second"));
|
|
291
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/week/
|
|
292
|
+
__publicField(this, "week", this.id("week"));
|
|
293
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/year/
|
|
294
|
+
__publicField(this, "year", this.id("year"));
|
|
295
|
+
// Type conversion operators (fully typed from ExprBuilder)
|
|
296
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/convert/
|
|
297
|
+
__publicField(this, "convert", this.options("convert"));
|
|
298
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/isNumber/
|
|
299
|
+
__publicField(this, "isNumber", this.id("isNumber"));
|
|
300
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/toBool/
|
|
301
|
+
__publicField(this, "toBool", this.id("toBool"));
|
|
302
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/toDate/
|
|
303
|
+
__publicField(this, "toDate", this.id("toDate"));
|
|
304
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/toDecimal/
|
|
305
|
+
__publicField(this, "toDecimal", this.id("toDecimal"));
|
|
306
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/toDouble/
|
|
307
|
+
__publicField(this, "toDouble", this.id("toDouble"));
|
|
308
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/toInt/
|
|
309
|
+
__publicField(this, "toInt", this.id("toInt"));
|
|
310
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/toLong/
|
|
311
|
+
__publicField(this, "toLong", this.id("toLong"));
|
|
312
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/toObjectId/
|
|
313
|
+
__publicField(this, "toObjectId", this.id("toObjectId"));
|
|
314
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/toString/
|
|
315
|
+
__publicField(this, "toString", this.id("toString"));
|
|
316
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/type/
|
|
317
|
+
__publicField(this, "type", this.id("type"));
|
|
318
|
+
// Object operators (properly typed from ExprBuilder)
|
|
319
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/getField/
|
|
320
|
+
__publicField(this, "getField", (options) => typeof options === "string" ? this.id("getField")(options) : this.options("getField")(options));
|
|
321
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/mergeObjects/
|
|
322
|
+
__publicField(this, "mergeObjects", this.flexible("mergeObjects"));
|
|
323
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/setField/
|
|
324
|
+
__publicField(this, "setField", this.options("setField"));
|
|
325
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/unsetField/
|
|
326
|
+
__publicField(this, "unsetField", this.options("unsetField"));
|
|
327
|
+
// Variable operators (fully typed from ExprBuilder)
|
|
328
|
+
/** Binds variables for use within a scoped expression.
|
|
329
|
+
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/let/ */
|
|
330
|
+
__publicField(this, "let", this.options("let"));
|
|
331
|
+
// Literal operator (fully typed from ExprBuilder)
|
|
332
|
+
/** Returns a value without parsing — prevents field path or operator interpretation.
|
|
333
|
+
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/literal/ */
|
|
334
|
+
__publicField(this, "literal", this.id("literal"));
|
|
335
|
+
// Misc operators (fully typed from ExprBuilder)
|
|
336
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/meta/
|
|
337
|
+
__publicField(this, "meta", this.id("meta"));
|
|
338
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/sampleRate/
|
|
339
|
+
__publicField(this, "sampleRate", this.id("sampleRate"));
|
|
340
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/binarySize/
|
|
341
|
+
__publicField(this, "binarySize", this.id("binarySize"));
|
|
342
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/bsonSize/
|
|
343
|
+
__publicField(this, "bsonSize", this.id("bsonSize"));
|
|
344
|
+
// Bitwise operators (fully typed from ExprBuilder)
|
|
345
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/bitAnd/
|
|
346
|
+
__publicField(this, "bitAnd", this.varargs("bitAnd"));
|
|
347
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/bitOr/
|
|
348
|
+
__publicField(this, "bitOr", this.varargs("bitOr"));
|
|
349
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/bitXor/
|
|
350
|
+
__publicField(this, "bitXor", this.varargs("bitXor"));
|
|
351
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/bitNot/
|
|
352
|
+
__publicField(this, "bitNot", this.id("bitNot"));
|
|
353
|
+
// Trigonometric operators (fully typed from ExprBuilder)
|
|
354
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/sin/
|
|
355
|
+
__publicField(this, "sin", this.id("sin"));
|
|
356
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/cos/
|
|
357
|
+
__publicField(this, "cos", this.id("cos"));
|
|
358
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/tan/
|
|
359
|
+
__publicField(this, "tan", this.id("tan"));
|
|
360
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/asin/
|
|
361
|
+
__publicField(this, "asin", this.id("asin"));
|
|
362
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/acos/
|
|
363
|
+
__publicField(this, "acos", this.id("acos"));
|
|
364
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/atan/
|
|
365
|
+
__publicField(this, "atan", this.id("atan"));
|
|
366
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/atan2/
|
|
367
|
+
__publicField(this, "atan2", this.varargs("atan2"));
|
|
368
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/asinh/
|
|
369
|
+
__publicField(this, "asinh", this.id("asinh"));
|
|
370
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/acosh/
|
|
371
|
+
__publicField(this, "acosh", this.id("acosh"));
|
|
372
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/atanh/
|
|
373
|
+
__publicField(this, "atanh", this.id("atanh"));
|
|
374
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/sinh/
|
|
375
|
+
__publicField(this, "sinh", this.id("sinh"));
|
|
376
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/cosh/
|
|
377
|
+
__publicField(this, "cosh", this.id("cosh"));
|
|
378
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/tanh/
|
|
379
|
+
__publicField(this, "tanh", this.id("tanh"));
|
|
380
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/degreesToRadians/
|
|
381
|
+
__publicField(this, "degreesToRadians", this.id("degreesToRadians"));
|
|
382
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/radiansToDegrees/
|
|
383
|
+
__publicField(this, "radiansToDegrees", this.id("radiansToDegrees"));
|
|
384
|
+
// Dual-context operators (work as both expressions and accumulators)
|
|
385
|
+
// These use AccumulatorExprArg to reject bare strings — use "$field" not "field"
|
|
386
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/sum/
|
|
387
|
+
__publicField(this, "sum", this.flexible("sum"));
|
|
388
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/avg/
|
|
389
|
+
__publicField(this, "avg", this.flexible("avg"));
|
|
390
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/max/
|
|
391
|
+
__publicField(this, "max", this.flexible("max"));
|
|
392
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/min/
|
|
393
|
+
__publicField(this, "min", this.flexible("min"));
|
|
394
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/stdDevPop/
|
|
395
|
+
__publicField(this, "stdDevPop", this.flexible("stdDevPop"));
|
|
396
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/stdDevSamp/
|
|
397
|
+
__publicField(this, "stdDevSamp", this.flexible("stdDevSamp"));
|
|
398
|
+
}
|
|
399
|
+
// Helper to resolve nested callbacks and values
|
|
400
|
+
_resolve(value) {
|
|
401
|
+
const _foo = value;
|
|
402
|
+
if (_foo instanceof Ret) return this._resolve(_foo.__fn);
|
|
403
|
+
if (typeof _foo === "function") return this._resolve(_foo(this));
|
|
404
|
+
if (Array.isArray(_foo)) return _foo.map((item) => this._resolve(item));
|
|
405
|
+
if (_foo instanceof Date) return _foo;
|
|
406
|
+
if (_foo instanceof ObjectId) return _foo;
|
|
407
|
+
if (_foo instanceof RegExp) return _foo;
|
|
408
|
+
if (typeof _foo !== "object" || _foo === null) return _foo;
|
|
409
|
+
return Object.entries(_foo).reduce((acc, [k, v]) => ({ ...acc, [k]: this._resolve(v) }), {});
|
|
410
|
+
}
|
|
411
|
+
};
|
|
412
|
+
var ExprBuilder = class extends BaseBuilder {
|
|
413
|
+
constructor() {
|
|
414
|
+
super(...arguments);
|
|
415
|
+
/** Include this field in `$project` output (equivalent to `1`). */
|
|
416
|
+
__publicField(this, "include", 1);
|
|
417
|
+
/** Exclude this field from `$project` output (equivalent to `0`). */
|
|
418
|
+
__publicField(this, "exclude", 0);
|
|
419
|
+
}
|
|
420
|
+
};
|
|
421
|
+
var AccumulatorBuilder = class extends BaseBuilder {
|
|
422
|
+
constructor() {
|
|
423
|
+
super(...arguments);
|
|
424
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/addToSet/
|
|
425
|
+
__publicField(this, "addToSet", this.id("addToSet"));
|
|
426
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/count-accumulator/
|
|
427
|
+
__publicField(this, "count", this.options("count"));
|
|
428
|
+
// push with overloads for object literal vs single expression
|
|
429
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/push/
|
|
430
|
+
__publicField(this, "push", this.id("push"));
|
|
431
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/bottom/
|
|
432
|
+
__publicField(this, "bottom", this.options("bottom"));
|
|
433
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/bottomN/
|
|
434
|
+
__publicField(this, "bottomN", this.options("bottomN"));
|
|
435
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/top/
|
|
436
|
+
__publicField(this, "top", this.options("top"));
|
|
437
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/topN/
|
|
438
|
+
__publicField(this, "topN", this.options("topN"));
|
|
439
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/accumulator/
|
|
440
|
+
__publicField(this, "accumulator", (options) => this.options("accumulator")(resolveAccumulator(options)));
|
|
441
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/median/
|
|
442
|
+
__publicField(this, "median", this.options("median"));
|
|
443
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/percentile/
|
|
444
|
+
__publicField(this, "percentile", this.options("percentile"));
|
|
445
|
+
}
|
|
446
|
+
};
|
|
447
|
+
var WindowBuilder = class extends AccumulatorBuilder {
|
|
448
|
+
constructor() {
|
|
449
|
+
super(...arguments);
|
|
450
|
+
// Window-specific operators (properly typed from ExprBuilder)
|
|
451
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/denseRank/
|
|
452
|
+
__publicField(this, "denseRank", this.nullary("denseRank"));
|
|
453
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/covariancePop/
|
|
454
|
+
__publicField(this, "covariancePop", this.varargs("covariancePop"));
|
|
455
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/covarianceSamp/
|
|
456
|
+
__publicField(this, "covarianceSamp", this.varargs("covarianceSamp"));
|
|
457
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/derivative/
|
|
458
|
+
__publicField(this, "derivative", (options) => {
|
|
459
|
+
const resolved = this._resolve(options);
|
|
460
|
+
if ("window" in resolved) {
|
|
461
|
+
const { window, ...operatorArgs } = resolved;
|
|
462
|
+
return new Ret({ $derivative: operatorArgs, window });
|
|
463
|
+
}
|
|
464
|
+
return new Ret({ $derivative: resolved });
|
|
465
|
+
});
|
|
466
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/documentNumber/
|
|
467
|
+
__publicField(this, "documentNumber", this.nullary("documentNumber"));
|
|
468
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/expMovingAvg/
|
|
469
|
+
__publicField(this, "expMovingAvg", (options) => {
|
|
470
|
+
const resolved = this._resolve(options);
|
|
471
|
+
if ("window" in resolved) {
|
|
472
|
+
const { window, ...operatorArgs } = resolved;
|
|
473
|
+
return new Ret({ $expMovingAvg: operatorArgs, window });
|
|
474
|
+
}
|
|
475
|
+
return new Ret({ $expMovingAvg: resolved });
|
|
476
|
+
});
|
|
477
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/integral/
|
|
478
|
+
__publicField(this, "integral", (options) => {
|
|
479
|
+
const resolved = this._resolve(options);
|
|
480
|
+
if ("window" in resolved) {
|
|
481
|
+
const { window, ...operatorArgs } = resolved;
|
|
482
|
+
return new Ret({ $integral: operatorArgs, window });
|
|
483
|
+
}
|
|
484
|
+
return new Ret({ $integral: resolved });
|
|
485
|
+
});
|
|
486
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/linearFill/
|
|
487
|
+
__publicField(this, "linearFill", this.id("linearFill"));
|
|
488
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/locf/
|
|
489
|
+
__publicField(this, "locf", this.id("locf"));
|
|
490
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/percentRank/
|
|
491
|
+
__publicField(this, "percentRank", this.nullary("percentRank"));
|
|
492
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/rank/
|
|
493
|
+
__publicField(this, "rank", this.nullary("rank"));
|
|
494
|
+
// https://www.mongodb.com/docs/manual/reference/operator/aggregation/shift/
|
|
495
|
+
__publicField(this, "shift", this.options("shift"));
|
|
496
|
+
}
|
|
497
|
+
};
|
|
498
|
+
|
|
499
|
+
// src/migrate.ts
|
|
500
|
+
var migrate = () => {
|
|
501
|
+
const pipe = (...stages) => {
|
|
502
|
+
const fakeAgg = {
|
|
503
|
+
_in: void 0,
|
|
504
|
+
_current: void 0,
|
|
505
|
+
stages: [],
|
|
506
|
+
pipe: void 0,
|
|
507
|
+
toList: void 0,
|
|
508
|
+
toMQL: void 0
|
|
509
|
+
};
|
|
510
|
+
const result = stages.reduce((agg, stage) => stage(agg), fakeAgg);
|
|
511
|
+
return {
|
|
512
|
+
__pipelineIn: void 0,
|
|
513
|
+
__pipelineOut: void 0,
|
|
514
|
+
stages: result.stages
|
|
515
|
+
};
|
|
516
|
+
};
|
|
517
|
+
return {
|
|
518
|
+
pipe
|
|
519
|
+
};
|
|
520
|
+
};
|
|
521
|
+
|
|
522
|
+
// src/runtime-utils.ts
|
|
523
|
+
import { ObjectId as ObjectId2 } from "mongodb";
|
|
524
|
+
var unwrapRet = (value) => {
|
|
525
|
+
const _foo = value;
|
|
526
|
+
if (_foo instanceof Ret) return unwrapRet(_foo.__fn);
|
|
527
|
+
if (Array.isArray(_foo)) return _foo.map(unwrapRet);
|
|
528
|
+
if (_foo instanceof Date) return _foo;
|
|
529
|
+
if (_foo instanceof ObjectId2) return _foo;
|
|
530
|
+
if (_foo instanceof RegExp) return _foo;
|
|
531
|
+
if (typeof _foo !== "object" || _foo === null) return _foo;
|
|
532
|
+
return Object.entries(_foo).reduce((acc, [k, v]) => ({ ...acc, [k]: unwrapRet(v) }), {});
|
|
533
|
+
};
|
|
534
|
+
var resolveStage = (stage) => unwrapRet(typeof stage === "function" ? stage(new ExprBuilder()) : stage);
|
|
535
|
+
var pushStage = (fn) => (options) => (agg) => ({ ...agg, stages: [...agg.stages ?? [], fn(options)] });
|
|
536
|
+
|
|
537
|
+
// src/sluice-stages.ts
|
|
538
|
+
var $addFields = pushStage((fieldsBuilder) => ({
|
|
539
|
+
$addFields: resolveStage(fieldsBuilder)
|
|
540
|
+
}));
|
|
541
|
+
var $bucket = pushStage((options) => {
|
|
542
|
+
const resolved = resolveStage(options);
|
|
543
|
+
if (resolved.output && typeof options.output === "function") {
|
|
544
|
+
resolved.output = resolveStage(options.output);
|
|
545
|
+
}
|
|
546
|
+
return { $bucket: resolved };
|
|
547
|
+
});
|
|
548
|
+
var $bucketAuto = pushStage((options) => ({
|
|
549
|
+
$bucketAuto: resolveStage(options)
|
|
550
|
+
}));
|
|
551
|
+
var $collStats = pushStage((options) => ({
|
|
552
|
+
$collStats: resolveStage(options)
|
|
553
|
+
}));
|
|
554
|
+
var $count = pushStage((field) => ({ $count: field }));
|
|
555
|
+
var $densify = pushStage((options) => ({ $densify: resolveStage(options) }));
|
|
556
|
+
var $documents = ((documents) => ({
|
|
557
|
+
stages: [{ $documents: documents }]
|
|
558
|
+
}));
|
|
559
|
+
var $facet = pushStage((pipelines) => {
|
|
560
|
+
const facetSpec = resolveStage(pipelines);
|
|
561
|
+
const transformedSpec = {};
|
|
562
|
+
for (const [key, val] of Object.entries(facetSpec)) {
|
|
563
|
+
if (val.stages) {
|
|
564
|
+
transformedSpec[key] = val.stages;
|
|
565
|
+
} else if (Array.isArray(val)) {
|
|
566
|
+
transformedSpec[key] = val;
|
|
567
|
+
} else {
|
|
568
|
+
transformedSpec[key] = val;
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
return { $facet: transformedSpec };
|
|
572
|
+
});
|
|
573
|
+
var $fill = pushStage((options) => ({ $fill: resolveStage(options) }));
|
|
574
|
+
var $geoNear = pushStage((options) => ({ $geoNear: resolveStage(options) }));
|
|
575
|
+
var $graphLookup = pushStage(
|
|
576
|
+
(options) => ({
|
|
577
|
+
$graphLookup: {
|
|
578
|
+
...resolveStage(options),
|
|
579
|
+
from: options.from.__collectionName
|
|
580
|
+
}
|
|
581
|
+
})
|
|
582
|
+
);
|
|
583
|
+
var $group = pushStage((spec) => ({
|
|
584
|
+
$group: unwrapRet(typeof spec === "function" ? spec(new AccumulatorBuilder()) : spec)
|
|
585
|
+
}));
|
|
586
|
+
var $indexStats = pushStage(() => ({ $indexStats: {} }));
|
|
587
|
+
var $limit = pushStage((n) => ({ $limit: n }));
|
|
588
|
+
var $lookup = pushStage((options) => {
|
|
589
|
+
const spec = {
|
|
590
|
+
...options,
|
|
591
|
+
from: options.from.__collectionName
|
|
592
|
+
};
|
|
593
|
+
if (typeof spec.pipeline === "function") {
|
|
594
|
+
spec.pipeline = resolveStage(spec.pipeline);
|
|
595
|
+
}
|
|
596
|
+
if (spec.pipeline && typeof spec.pipeline === "object" && "stages" in spec.pipeline) {
|
|
597
|
+
const pipeline = spec.pipeline;
|
|
598
|
+
if (typeof pipeline.stages !== "undefined") {
|
|
599
|
+
spec.pipeline = pipeline.stages;
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
return { $lookup: spec };
|
|
603
|
+
});
|
|
604
|
+
var $match = pushStage((filter) => ({ $match: resolveStage(filter) }));
|
|
605
|
+
var $merge = pushStage((options) => ({
|
|
606
|
+
$merge: {
|
|
607
|
+
...resolveStage(options),
|
|
608
|
+
into: options.into.__collectionName
|
|
609
|
+
}
|
|
610
|
+
}));
|
|
611
|
+
var $out = pushStage((options) => {
|
|
612
|
+
const resolved = resolveStage(options);
|
|
613
|
+
if ("coll" in resolved) {
|
|
614
|
+
return { $out: { db: resolved.db, coll: resolved.coll.__collectionName } };
|
|
615
|
+
}
|
|
616
|
+
return { $out: resolved.__collectionName };
|
|
617
|
+
});
|
|
618
|
+
var $project = pushStage((spec) => ({ $project: resolveStage(spec) }));
|
|
619
|
+
var $redact = pushStage((expression) => ({
|
|
620
|
+
$redact: resolveStage(expression)
|
|
621
|
+
}));
|
|
622
|
+
var $replaceRoot = pushStage((options) => {
|
|
623
|
+
const resolved = resolveStage(options);
|
|
624
|
+
const spec = resolved !== null && typeof resolved === "object" && "newRoot" in resolved ? resolved : { newRoot: resolved };
|
|
625
|
+
return { $replaceRoot: spec };
|
|
626
|
+
});
|
|
627
|
+
var $replaceWith = pushStage((expression) => ({
|
|
628
|
+
$replaceWith: resolveStage(expression)
|
|
629
|
+
}));
|
|
630
|
+
var $sample = pushStage((options) => ({ $sample: resolveStage(options) }));
|
|
631
|
+
var $set = pushStage((fields) => ({ $set: resolveStage(fields) }));
|
|
632
|
+
var $setWindowFields = pushStage((options) => ({
|
|
633
|
+
$setWindowFields: unwrapRet(
|
|
634
|
+
typeof options === "function" ? options(new WindowBuilder()) : options
|
|
635
|
+
)
|
|
636
|
+
}));
|
|
637
|
+
var $skip = pushStage((n) => ({ $skip: n }));
|
|
638
|
+
var $sort = pushStage((spec) => ({ $sort: resolveStage(spec) }));
|
|
639
|
+
var $sortByCount = pushStage((expression) => ({
|
|
640
|
+
$sortByCount: resolveStage(expression)
|
|
641
|
+
}));
|
|
642
|
+
var $unionWith = pushStage((options) => {
|
|
643
|
+
const spec = {
|
|
644
|
+
...options,
|
|
645
|
+
coll: options.coll.__collectionName
|
|
646
|
+
};
|
|
647
|
+
if (typeof spec.pipeline === "function") {
|
|
648
|
+
spec.pipeline = resolveStage(spec.pipeline);
|
|
649
|
+
}
|
|
650
|
+
if (spec.pipeline && typeof spec.pipeline === "object" && "stages" in spec.pipeline) {
|
|
651
|
+
const pipeline = spec.pipeline;
|
|
652
|
+
if (typeof pipeline.stages !== "undefined") {
|
|
653
|
+
spec.pipeline = pipeline.stages;
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
return { $unionWith: spec };
|
|
657
|
+
});
|
|
658
|
+
var $unset = ((...fields) => (agg) => ({
|
|
659
|
+
...agg,
|
|
660
|
+
stages: [...agg.stages ?? [], { $unset: fields.length === 1 ? fields[0] : fields }]
|
|
661
|
+
}));
|
|
662
|
+
var $unwind = pushStage((pathOrOptions) => ({
|
|
663
|
+
$unwind: resolveStage(pathOrOptions)
|
|
664
|
+
}));
|
|
665
|
+
var $changeStream = pushStage((options) => ({
|
|
666
|
+
$changeStream: resolveStage(options)
|
|
667
|
+
}));
|
|
668
|
+
var $currentOp = pushStage((options) => ({
|
|
669
|
+
$currentOp: resolveStage(options)
|
|
670
|
+
}));
|
|
671
|
+
|
|
672
|
+
// src/crud/updates/stages/index.ts
|
|
673
|
+
var update = () => {
|
|
674
|
+
const pipe = (...stages) => {
|
|
675
|
+
const fakeAgg = {
|
|
676
|
+
_in: void 0,
|
|
677
|
+
_current: void 0,
|
|
678
|
+
stages: [],
|
|
679
|
+
pipe: void 0,
|
|
680
|
+
toList: void 0,
|
|
681
|
+
toMQL: void 0
|
|
682
|
+
};
|
|
683
|
+
const result = stages.reduce((agg, stage) => stage(agg), fakeAgg);
|
|
684
|
+
return {
|
|
685
|
+
__pipelineIn: void 0,
|
|
686
|
+
__pipelineOut: void 0,
|
|
687
|
+
stages: result.stages
|
|
688
|
+
};
|
|
689
|
+
};
|
|
690
|
+
return {
|
|
691
|
+
set: $set,
|
|
692
|
+
unset: $unset,
|
|
693
|
+
replaceRoot: $replaceRoot,
|
|
694
|
+
replaceWith: $replaceWith,
|
|
695
|
+
addFields: $addFields,
|
|
696
|
+
project: $project,
|
|
697
|
+
pipe
|
|
698
|
+
};
|
|
699
|
+
};
|
|
700
|
+
|
|
701
|
+
// src/registry.ts
|
|
702
|
+
function createCrudMethods(mongoCol) {
|
|
703
|
+
const extractFilter = (filterFn) => {
|
|
704
|
+
if (!filterFn) return {};
|
|
705
|
+
return filterFn({});
|
|
706
|
+
};
|
|
707
|
+
return {
|
|
708
|
+
find: ((filterFn, options) => ({
|
|
709
|
+
_filter: filterFn ? extractFilter(filterFn) : void 0,
|
|
710
|
+
_options: options,
|
|
711
|
+
toList: () => {
|
|
712
|
+
const filter = filterFn ? extractFilter(filterFn) : {};
|
|
713
|
+
let cursor = mongoCol.find(filter);
|
|
714
|
+
if (options?.sort) cursor = cursor.sort(options.sort);
|
|
715
|
+
if (options?.skip) cursor = cursor.skip(options.skip);
|
|
716
|
+
if (options?.limit) cursor = cursor.limit(options.limit);
|
|
717
|
+
if (options?.projection) cursor = cursor.project(options.projection);
|
|
718
|
+
if (options?.hint) cursor = cursor.hint(options.hint);
|
|
719
|
+
if (options?.maxTimeMS) cursor = cursor.maxTimeMS(options.maxTimeMS);
|
|
720
|
+
if (options?.collation) cursor = cursor.collation(options.collation);
|
|
721
|
+
if (options?.comment) cursor = cursor.comment(options.comment);
|
|
722
|
+
return cursor.toArray();
|
|
723
|
+
},
|
|
724
|
+
toOne: async () => {
|
|
725
|
+
const filter = filterFn ? extractFilter(filterFn) : {};
|
|
726
|
+
return mongoCol.findOne(
|
|
727
|
+
filter,
|
|
728
|
+
options
|
|
729
|
+
);
|
|
730
|
+
}
|
|
731
|
+
})),
|
|
732
|
+
findOne: ((filterFn, options) => ({
|
|
733
|
+
_filter: filterFn ? extractFilter(filterFn) : void 0,
|
|
734
|
+
_options: options,
|
|
735
|
+
toList: async () => {
|
|
736
|
+
const doc = await mongoCol.findOne(
|
|
737
|
+
filterFn ? extractFilter(filterFn) : {},
|
|
738
|
+
options
|
|
739
|
+
);
|
|
740
|
+
return doc ? [doc] : [];
|
|
741
|
+
},
|
|
742
|
+
toOne: () => mongoCol.findOne(
|
|
743
|
+
filterFn ? extractFilter(filterFn) : {},
|
|
744
|
+
options
|
|
745
|
+
)
|
|
746
|
+
})),
|
|
747
|
+
insertOne: (doc) => ({
|
|
748
|
+
_doc: doc,
|
|
749
|
+
execute: () => mongoCol.insertOne(doc)
|
|
750
|
+
}),
|
|
751
|
+
insertMany: (docs) => ({
|
|
752
|
+
_docs: docs,
|
|
753
|
+
execute: () => mongoCol.insertMany(docs)
|
|
754
|
+
}),
|
|
755
|
+
updateOne: ((filterFn, updateArg, options) => {
|
|
756
|
+
const filter = extractFilter(filterFn);
|
|
757
|
+
const updateDoc = typeof updateArg === "function" ? (
|
|
758
|
+
// Callback form: invoke with operators, get stages from TypedPipeline
|
|
759
|
+
updateArg(update()).stages
|
|
760
|
+
) : updateArg;
|
|
761
|
+
return {
|
|
762
|
+
_filter: filter,
|
|
763
|
+
_update: updateDoc,
|
|
764
|
+
_options: options,
|
|
765
|
+
execute: () => mongoCol.updateOne(filter, updateDoc, options)
|
|
766
|
+
};
|
|
767
|
+
}),
|
|
768
|
+
updateMany: ((filterFn, updateArg, options) => {
|
|
769
|
+
const filter = extractFilter(filterFn);
|
|
770
|
+
const updateDoc = typeof updateArg === "function" ? (
|
|
771
|
+
// Callback form: invoke with operators, get stages from TypedPipeline
|
|
772
|
+
updateArg(update()).stages
|
|
773
|
+
) : updateArg;
|
|
774
|
+
return {
|
|
775
|
+
_filter: filter,
|
|
776
|
+
_update: updateDoc,
|
|
777
|
+
_options: options,
|
|
778
|
+
execute: () => mongoCol.updateMany(filter, updateDoc, options)
|
|
779
|
+
};
|
|
780
|
+
}),
|
|
781
|
+
replaceOne: ((filterFn, replacement, options) => ({
|
|
782
|
+
_filter: extractFilter(filterFn),
|
|
783
|
+
_replacement: replacement,
|
|
784
|
+
_options: options,
|
|
785
|
+
execute: () => mongoCol.replaceOne(
|
|
786
|
+
extractFilter(filterFn),
|
|
787
|
+
replacement,
|
|
788
|
+
options
|
|
789
|
+
)
|
|
790
|
+
})),
|
|
791
|
+
deleteOne: ((filterFn) => ({
|
|
792
|
+
_filter: extractFilter(filterFn),
|
|
793
|
+
execute: () => mongoCol.deleteOne(extractFilter(filterFn))
|
|
794
|
+
})),
|
|
795
|
+
deleteMany: ((filterFn) => ({
|
|
796
|
+
_filter: extractFilter(filterFn),
|
|
797
|
+
execute: () => mongoCol.deleteMany(extractFilter(filterFn))
|
|
798
|
+
})),
|
|
799
|
+
findOneAndDelete: ((filterFn, options) => ({
|
|
800
|
+
_filter: extractFilter(filterFn),
|
|
801
|
+
execute: () => mongoCol.findOneAndDelete(extractFilter(filterFn), options).then((r) => r)
|
|
802
|
+
})),
|
|
803
|
+
findOneAndReplace: ((filterFn, replacement, options) => ({
|
|
804
|
+
_filter: extractFilter(filterFn),
|
|
805
|
+
_replacement: replacement,
|
|
806
|
+
execute: () => mongoCol.findOneAndReplace(
|
|
807
|
+
extractFilter(filterFn),
|
|
808
|
+
replacement,
|
|
809
|
+
options
|
|
810
|
+
).then((r) => r)
|
|
811
|
+
})),
|
|
812
|
+
findOneAndUpdate: ((filterFn, updateArg, options) => ({
|
|
813
|
+
_filter: extractFilter(filterFn),
|
|
814
|
+
_update: updateArg,
|
|
815
|
+
execute: () => mongoCol.findOneAndUpdate(
|
|
816
|
+
extractFilter(filterFn),
|
|
817
|
+
updateArg,
|
|
818
|
+
options
|
|
819
|
+
).then((r) => r)
|
|
820
|
+
})),
|
|
821
|
+
countDocuments: ((filterFn, options) => ({
|
|
822
|
+
execute: () => mongoCol.countDocuments(
|
|
823
|
+
filterFn ? extractFilter(filterFn) : {},
|
|
824
|
+
options
|
|
825
|
+
)
|
|
826
|
+
})),
|
|
827
|
+
estimatedDocumentCount: () => ({
|
|
828
|
+
execute: () => mongoCol.estimatedDocumentCount()
|
|
829
|
+
}),
|
|
830
|
+
distinct: ((field, filterFn) => ({
|
|
831
|
+
execute: () => mongoCol.distinct(field, filterFn ? extractFilter(filterFn) : {})
|
|
832
|
+
})),
|
|
833
|
+
bulkWrite: ((operations, options) => ({
|
|
834
|
+
_operations: operations,
|
|
835
|
+
execute: () => mongoCol.bulkWrite(operations, options)
|
|
836
|
+
}))
|
|
837
|
+
};
|
|
838
|
+
}
|
|
839
|
+
var collection = (name, _schema, mongoCol) => {
|
|
840
|
+
const col = {
|
|
841
|
+
__collectionName: name,
|
|
842
|
+
__collectionType: {}
|
|
843
|
+
};
|
|
844
|
+
const crud = createCrudMethods(mongoCol);
|
|
845
|
+
return Object.assign(col, {
|
|
846
|
+
aggregate: ((...stages) => {
|
|
847
|
+
let agg = { collectionName: name, stages: [] };
|
|
848
|
+
for (const s of stages) {
|
|
849
|
+
agg = s(agg);
|
|
850
|
+
}
|
|
851
|
+
return {
|
|
852
|
+
...agg,
|
|
853
|
+
// eslint-disable-next-line custom/aggregate-must-tolist
|
|
854
|
+
toList: () => mongoCol.aggregate(agg.stages).toArray(),
|
|
855
|
+
toMQL: () => JSON.stringify(agg.stages, null, 2)
|
|
856
|
+
};
|
|
857
|
+
}),
|
|
858
|
+
...crud
|
|
859
|
+
});
|
|
860
|
+
};
|
|
861
|
+
var registry = (version, schemas) => (client) => {
|
|
862
|
+
const bind = (name, schema) => collection(name, schema, client.collection(name));
|
|
863
|
+
return Object.fromEntries(
|
|
864
|
+
Object.entries(schemas).map(([name, schema]) => [name, bind(name, schema)])
|
|
865
|
+
);
|
|
866
|
+
};
|
|
867
|
+
export {
|
|
868
|
+
$addFields,
|
|
869
|
+
$bucket,
|
|
870
|
+
$bucketAuto,
|
|
871
|
+
$changeStream,
|
|
872
|
+
$collStats,
|
|
873
|
+
$count,
|
|
874
|
+
$currentOp,
|
|
875
|
+
$densify,
|
|
876
|
+
$documents,
|
|
877
|
+
$facet,
|
|
878
|
+
$fill,
|
|
879
|
+
$geoNear,
|
|
880
|
+
$graphLookup,
|
|
881
|
+
$group,
|
|
882
|
+
$indexStats,
|
|
883
|
+
$limit,
|
|
884
|
+
$lookup,
|
|
885
|
+
$match,
|
|
886
|
+
$merge,
|
|
887
|
+
$out,
|
|
888
|
+
$project,
|
|
889
|
+
$redact,
|
|
890
|
+
$replaceRoot,
|
|
891
|
+
$replaceWith,
|
|
892
|
+
$sample,
|
|
893
|
+
$set,
|
|
894
|
+
$setWindowFields,
|
|
895
|
+
$skip,
|
|
896
|
+
$sort,
|
|
897
|
+
$sortByCount,
|
|
898
|
+
$unionWith,
|
|
899
|
+
$unset,
|
|
900
|
+
$unwind,
|
|
901
|
+
AccumulatorBuilder,
|
|
902
|
+
ExprBuilder,
|
|
903
|
+
Ret,
|
|
904
|
+
WindowBuilder,
|
|
905
|
+
collection,
|
|
906
|
+
functionToString,
|
|
907
|
+
migrate,
|
|
908
|
+
registry,
|
|
909
|
+
resolveAccumulator
|
|
910
|
+
};
|
|
911
|
+
//# sourceMappingURL=index.js.map
|