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