@prisma/orm-family-mongo 0.16.0-dev.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (166) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +27 -0
  3. package/dist/authoring-entity-types-BGtkMyoN-D32kzx28.mjs +176 -0
  4. package/dist/authoring-entity-types-BGtkMyoN-D32kzx28.mjs.map +1 -0
  5. package/dist/canonicalization-hooks-DF3Z6sjO.mjs +22 -0
  6. package/dist/canonicalization-hooks-DF3Z6sjO.mjs.map +1 -0
  7. package/dist/codec.d.mts +2 -0
  8. package/dist/codec.mjs +2 -0
  9. package/dist/config-types-CFDf9ivE.mjs +37 -0
  10. package/dist/config-types-CFDf9ivE.mjs.map +1 -0
  11. package/dist/config-types-CQOf5N7R.d.mts +12 -0
  12. package/dist/config-types-CQOf5N7R.d.mts.map +1 -0
  13. package/dist/contract-builder-BFq0gOMV.mjs +634 -0
  14. package/dist/contract-builder-BFq0gOMV.mjs.map +1 -0
  15. package/dist/contract-builder-DB8nguDE.d.mts +445 -0
  16. package/dist/contract-builder-DB8nguDE.d.mts.map +1 -0
  17. package/dist/contract-errors-BCN6RVI5-kMurtAbI.mjs +9 -0
  18. package/dist/contract-errors-BCN6RVI5-kMurtAbI.mjs.map +1 -0
  19. package/dist/contract-psl.d.mts +45 -0
  20. package/dist/contract-psl.d.mts.map +1 -0
  21. package/dist/contract-psl.mjs +2 -0
  22. package/dist/contract-psl__provider.d.mts +15 -0
  23. package/dist/contract-psl__provider.d.mts.map +1 -0
  24. package/dist/contract-psl__provider.mjs +82 -0
  25. package/dist/contract-psl__provider.mjs.map +1 -0
  26. package/dist/contract-ts.d.mts +3 -0
  27. package/dist/contract-ts.mjs +3 -0
  28. package/dist/contract-ts__config-types.d.mts +2 -0
  29. package/dist/contract-ts__config-types.mjs +2 -0
  30. package/dist/contract-ts__contract-builder.d.mts +2 -0
  31. package/dist/contract-ts__contract-builder.mjs +2 -0
  32. package/dist/contract.d.mts +3 -0
  33. package/dist/contract.mjs +3 -0
  34. package/dist/contract__canonicalization-hooks.d.mts +9 -0
  35. package/dist/contract__canonicalization-hooks.d.mts.map +1 -0
  36. package/dist/contract__canonicalization-hooks.mjs +2 -0
  37. package/dist/contract__entity-kinds.d.mts +17 -0
  38. package/dist/contract__entity-kinds.d.mts.map +1 -0
  39. package/dist/contract__entity-kinds.mjs +2 -0
  40. package/dist/control-C7-kthr1.d.mts +193 -0
  41. package/dist/control-C7-kthr1.d.mts.map +1 -0
  42. package/dist/control-CClR5JMr.mjs +127 -0
  43. package/dist/control-CClR5JMr.mjs.map +1 -0
  44. package/dist/control-CFr3tYsg.mjs +398 -0
  45. package/dist/control-CFr3tYsg.mjs.map +1 -0
  46. package/dist/control-Cj81sPbj.d.mts +101 -0
  47. package/dist/control-Cj81sPbj.d.mts.map +1 -0
  48. package/dist/control-adapter-Db5pT77b.d.mts +83 -0
  49. package/dist/control-adapter-Db5pT77b.d.mts.map +1 -0
  50. package/dist/dist-C7Ykq48Q.mjs +19 -0
  51. package/dist/dist-C7Ykq48Q.mjs.map +1 -0
  52. package/dist/dist-Czwqx_i3.mjs +58 -0
  53. package/dist/dist-Czwqx_i3.mjs.map +1 -0
  54. package/dist/dist-DHrEJnhK.mjs +236 -0
  55. package/dist/dist-DHrEJnhK.mjs.map +1 -0
  56. package/dist/dist-Dyp05u64.mjs +1546 -0
  57. package/dist/dist-Dyp05u64.mjs.map +1 -0
  58. package/dist/emitter.d.mts +22 -0
  59. package/dist/emitter.d.mts.map +1 -0
  60. package/dist/emitter.mjs +2 -0
  61. package/dist/entity-kinds-B4KNTF8z-DPIuUuuB.mjs +603 -0
  62. package/dist/entity-kinds-B4KNTF8z-DPIuUuuB.mjs.map +1 -0
  63. package/dist/execution-CKnUiOfm.d.mts +48 -0
  64. package/dist/execution-CKnUiOfm.d.mts.map +1 -0
  65. package/dist/execution-D5XyZ5XS.mjs +1269 -0
  66. package/dist/execution-D5XyZ5XS.mjs.map +1 -0
  67. package/dist/exports-Bx-hlnZ3.mjs +209 -0
  68. package/dist/exports-Bx-hlnZ3.mjs.map +1 -0
  69. package/dist/exports-CJMh0VTU.mjs +156 -0
  70. package/dist/exports-CJMh0VTU.mjs.map +1 -0
  71. package/dist/family.d.mts +10 -0
  72. package/dist/family.mjs +9 -0
  73. package/dist/family__control-adapter.d.mts +2 -0
  74. package/dist/family__control-adapter.mjs +1 -0
  75. package/dist/family__control.d.mts +2 -0
  76. package/dist/family__control.mjs +3 -0
  77. package/dist/family__ir.d.mts +3 -0
  78. package/dist/family__ir.mjs +4 -0
  79. package/dist/family__migration.d.mts +2 -0
  80. package/dist/family__migration.mjs +2 -0
  81. package/dist/family__pack.d.mts +2 -0
  82. package/dist/family__pack.mjs +16 -0
  83. package/dist/family__pack.mjs.map +1 -0
  84. package/dist/family__runtime.d.mts +3 -0
  85. package/dist/family__runtime.mjs +2 -0
  86. package/dist/family__schema-verify.d.mts +2 -0
  87. package/dist/family__schema-verify.mjs +2 -0
  88. package/dist/field-accessor-0oUt6RZC-B_Z30uAA.mjs +234 -0
  89. package/dist/field-accessor-0oUt6RZC-B_Z30uAA.mjs.map +1 -0
  90. package/dist/field-accessor-DHsAPiW3-BdYCspQC.d.mts +588 -0
  91. package/dist/field-accessor-DHsAPiW3-BdYCspQC.d.mts.map +1 -0
  92. package/dist/filter-expressions-Uo8ZdzwB-53qnqceS.mjs +181 -0
  93. package/dist/filter-expressions-Uo8ZdzwB-53qnqceS.mjs.map +1 -0
  94. package/dist/index-BR0ue13b.d.mts +136 -0
  95. package/dist/index-BR0ue13b.d.mts.map +1 -0
  96. package/dist/index-Cd2zLiU6.d.mts +128 -0
  97. package/dist/index-Cd2zLiU6.d.mts.map +1 -0
  98. package/dist/index-DAOkcTCK.d.mts +151 -0
  99. package/dist/index-DAOkcTCK.d.mts.map +1 -0
  100. package/dist/index-Dv2PNMiG.d.mts +53 -0
  101. package/dist/index-Dv2PNMiG.d.mts.map +1 -0
  102. package/dist/index-DxoO-ywI.d.mts +178 -0
  103. package/dist/index-DxoO-ywI.d.mts.map +1 -0
  104. package/dist/index-wKMm41HC.d.mts +30 -0
  105. package/dist/index-wKMm41HC.d.mts.map +1 -0
  106. package/dist/interpreter-BxbUTQ3k-ClR98Ned.mjs +1091 -0
  107. package/dist/interpreter-BxbUTQ3k-ClR98Ned.mjs.map +1 -0
  108. package/dist/ir-CQrenTYt.d.mts +147 -0
  109. package/dist/ir-CQrenTYt.d.mts.map +1 -0
  110. package/dist/ir-Ch2aPr7a.mjs +62 -0
  111. package/dist/ir-Ch2aPr7a.mjs.map +1 -0
  112. package/dist/lowering.d.mts +2 -0
  113. package/dist/lowering.mjs +1 -0
  114. package/dist/migration-CNDQv5yB.d.mts +50 -0
  115. package/dist/migration-CNDQv5yB.d.mts.map +1 -0
  116. package/dist/migration-dcM7u4HG.mjs +52 -0
  117. package/dist/migration-dcM7u4HG.mjs.map +1 -0
  118. package/dist/mongo-contract-serializer-Cx7Fae8e-C8ZYPXpc.mjs +119 -0
  119. package/dist/mongo-contract-serializer-Cx7Fae8e-C8ZYPXpc.mjs.map +1 -0
  120. package/dist/mongo-contract-view-AnejqfrQ-BaCFT0xm.d.mts +27 -0
  121. package/dist/mongo-contract-view-AnejqfrQ-BaCFT0xm.d.mts.map +1 -0
  122. package/dist/mongo-contract-view-rcWzby6f-wRBCUnBt.mjs +17 -0
  123. package/dist/mongo-contract-view-rcWzby6f-wRBCUnBt.mjs.map +1 -0
  124. package/dist/mongo-value-set-tNn9-pun-dJYx_rVD.d.mts +536 -0
  125. package/dist/mongo-value-set-tNn9-pun-dJYx_rVD.d.mts.map +1 -0
  126. package/dist/mongodb-types-B4HmhF1S.d.mts +2 -0
  127. package/dist/orm.d.mts +311 -0
  128. package/dist/orm.d.mts.map +1 -0
  129. package/dist/orm.mjs +664 -0
  130. package/dist/orm.mjs.map +1 -0
  131. package/dist/pack-D9aLY50F.d.mts +44 -0
  132. package/dist/pack-D9aLY50F.d.mts.map +1 -0
  133. package/dist/query-ast.d.mts +5 -0
  134. package/dist/query-ast.mjs +4 -0
  135. package/dist/query-ast__control.d.mts +4 -0
  136. package/dist/query-ast__control.mjs +3 -0
  137. package/dist/query-ast__execution.d.mts +3 -0
  138. package/dist/query-ast__execution.mjs +3 -0
  139. package/dist/query-builder.d.mts +836 -0
  140. package/dist/query-builder.d.mts.map +1 -0
  141. package/dist/query-builder.mjs +3 -0
  142. package/dist/query-builder__contract-free.d.mts +83 -0
  143. package/dist/query-builder__contract-free.d.mts.map +1 -0
  144. package/dist/query-builder__contract-free.mjs +107 -0
  145. package/dist/query-builder__contract-free.mjs.map +1 -0
  146. package/dist/query-plan-C0-Yu8hf-DdilEdW6.d.mts +822 -0
  147. package/dist/query-plan-C0-Yu8hf-DdilEdW6.d.mts.map +1 -0
  148. package/dist/runtime-DPkRW4iu.d.mts +1 -0
  149. package/dist/runtime.d.mts +286 -0
  150. package/dist/runtime.d.mts.map +1 -0
  151. package/dist/runtime.mjs +532 -0
  152. package/dist/runtime.mjs.map +1 -0
  153. package/dist/schema-ir.d.mts +2 -0
  154. package/dist/schema-ir.mjs +2 -0
  155. package/dist/schema-verify-DJGr28XW.d.mts +23 -0
  156. package/dist/schema-verify-DJGr28XW.d.mts.map +1 -0
  157. package/dist/value.d.mts +2 -0
  158. package/dist/value.mjs +2 -0
  159. package/dist/value__mongodb-types.d.mts +2 -0
  160. package/dist/value__mongodb-types.mjs +1 -0
  161. package/dist/verify-mongo-schema-De0FG2Rm-CCzwnNPY.mjs +447 -0
  162. package/dist/verify-mongo-schema-De0FG2Rm-CCzwnNPY.mjs.map +1 -0
  163. package/dist/wire.d.mts +3 -0
  164. package/dist/wire.mjs +190 -0
  165. package/dist/wire.mjs.map +1 -0
  166. package/package.json +89 -0
@@ -0,0 +1,1269 @@
1
+ import { l as ormError, n as MongoAstNode } from "./filter-expressions-Uo8ZdzwB-53qnqceS.mjs";
2
+ //#region ../../../2-mongo-family/4-query/query-ast/dist/exports/execution.mjs
3
+ function isExprArray(args) {
4
+ return Array.isArray(args);
5
+ }
6
+ function isRecordArgs(args) {
7
+ return !Array.isArray(args) && typeof args === "object" && !("accept" in args);
8
+ }
9
+ function freezeRecordArgs(record) {
10
+ const frozen = {};
11
+ for (const [key, val] of Object.entries(record)) frozen[key] = Array.isArray(val) ? Object.freeze([...val]) : val;
12
+ return Object.freeze(frozen);
13
+ }
14
+ function rewriteRecordArgs(record, rewriter) {
15
+ const result = {};
16
+ for (const [key, val] of Object.entries(record)) if (Array.isArray(val)) result[key] = val.map((v) => v.rewrite(rewriter));
17
+ else result[key] = val.rewrite(rewriter);
18
+ return result;
19
+ }
20
+ var MongoAggExprNode = class extends MongoAstNode {};
21
+ var MongoAggFieldRef = class MongoAggFieldRef extends MongoAggExprNode {
22
+ kind = "fieldRef";
23
+ path;
24
+ constructor(path) {
25
+ super();
26
+ if (!path) throw ormError("ORM.ARGUMENT_INVALID", "Field path must not be empty");
27
+ this.path = path;
28
+ this.freeze();
29
+ }
30
+ static of(path) {
31
+ return new MongoAggFieldRef(path);
32
+ }
33
+ accept(visitor) {
34
+ return visitor.fieldRef(this);
35
+ }
36
+ rewrite(rewriter) {
37
+ return rewriter.fieldRef ? rewriter.fieldRef(this) : this;
38
+ }
39
+ };
40
+ var MongoAggLiteral = class MongoAggLiteral extends MongoAggExprNode {
41
+ kind = "literal";
42
+ value;
43
+ constructor(value) {
44
+ super();
45
+ this.value = value;
46
+ this.freeze();
47
+ }
48
+ static of(value) {
49
+ return new MongoAggLiteral(value);
50
+ }
51
+ accept(visitor) {
52
+ return visitor.literal(this);
53
+ }
54
+ rewrite(rewriter) {
55
+ return rewriter.literal ? rewriter.literal(this) : this;
56
+ }
57
+ };
58
+ var MongoAggOperator = class MongoAggOperator extends MongoAggExprNode {
59
+ kind = "operator";
60
+ op;
61
+ args;
62
+ constructor(op, args) {
63
+ super();
64
+ this.op = op;
65
+ if (Array.isArray(args)) this.args = Object.freeze([...args]);
66
+ else if (isRecordArgs(args)) this.args = freezeRecordArgs(args);
67
+ else this.args = args;
68
+ this.freeze();
69
+ }
70
+ static of(op, args) {
71
+ return new MongoAggOperator(op, args);
72
+ }
73
+ static add(...args) {
74
+ return new MongoAggOperator("$add", args);
75
+ }
76
+ static subtract(left, right) {
77
+ return new MongoAggOperator("$subtract", [left, right]);
78
+ }
79
+ static multiply(...args) {
80
+ return new MongoAggOperator("$multiply", args);
81
+ }
82
+ static divide(dividend, divisor) {
83
+ return new MongoAggOperator("$divide", [dividend, divisor]);
84
+ }
85
+ static concat(...args) {
86
+ return new MongoAggOperator("$concat", args);
87
+ }
88
+ static toLower(expr) {
89
+ return new MongoAggOperator("$toLower", expr);
90
+ }
91
+ static toUpper(expr) {
92
+ return new MongoAggOperator("$toUpper", expr);
93
+ }
94
+ static size(expr) {
95
+ return new MongoAggOperator("$size", expr);
96
+ }
97
+ accept(visitor) {
98
+ return visitor.operator(this);
99
+ }
100
+ rewrite(rewriter) {
101
+ const { args } = this;
102
+ let rewrittenArgs;
103
+ if (isExprArray(args)) rewrittenArgs = args.map((a) => a.rewrite(rewriter));
104
+ else if (isRecordArgs(args)) rewrittenArgs = rewriteRecordArgs(args, rewriter);
105
+ else rewrittenArgs = args.rewrite(rewriter);
106
+ const rebuilt = new MongoAggOperator(this.op, rewrittenArgs);
107
+ return rewriter.operator ? rewriter.operator(rebuilt) : rebuilt;
108
+ }
109
+ };
110
+ var MongoAggAccumulator = class MongoAggAccumulator extends MongoAggExprNode {
111
+ kind = "accumulator";
112
+ op;
113
+ arg;
114
+ constructor(op, arg) {
115
+ super();
116
+ this.op = op;
117
+ if (arg !== null && isRecordArgs(arg)) this.arg = freezeRecordArgs(arg);
118
+ else this.arg = arg;
119
+ this.freeze();
120
+ }
121
+ static of(op, arg) {
122
+ return new MongoAggAccumulator(op, arg);
123
+ }
124
+ static sum(expr) {
125
+ return new MongoAggAccumulator("$sum", expr);
126
+ }
127
+ static avg(expr) {
128
+ return new MongoAggAccumulator("$avg", expr);
129
+ }
130
+ static min(expr) {
131
+ return new MongoAggAccumulator("$min", expr);
132
+ }
133
+ static max(expr) {
134
+ return new MongoAggAccumulator("$max", expr);
135
+ }
136
+ static first(expr) {
137
+ return new MongoAggAccumulator("$first", expr);
138
+ }
139
+ static last(expr) {
140
+ return new MongoAggAccumulator("$last", expr);
141
+ }
142
+ static push(expr) {
143
+ return new MongoAggAccumulator("$push", expr);
144
+ }
145
+ static addToSet(expr) {
146
+ return new MongoAggAccumulator("$addToSet", expr);
147
+ }
148
+ static count() {
149
+ return new MongoAggAccumulator("$count", null);
150
+ }
151
+ static stdDevPop(expr) {
152
+ return new MongoAggAccumulator("$stdDevPop", expr);
153
+ }
154
+ static stdDevSamp(expr) {
155
+ return new MongoAggAccumulator("$stdDevSamp", expr);
156
+ }
157
+ accept(visitor) {
158
+ return visitor.accumulator(this);
159
+ }
160
+ rewrite(rewriter) {
161
+ let rewrittenArg;
162
+ if (this.arg === null) rewrittenArg = null;
163
+ else if (isRecordArgs(this.arg)) rewrittenArg = rewriteRecordArgs(this.arg, rewriter);
164
+ else rewrittenArg = this.arg.rewrite(rewriter);
165
+ const rebuilt = new MongoAggAccumulator(this.op, rewrittenArg);
166
+ return rewriter.accumulator ? rewriter.accumulator(rebuilt) : rebuilt;
167
+ }
168
+ };
169
+ var MongoAggCond = class MongoAggCond extends MongoAggExprNode {
170
+ kind = "cond";
171
+ condition;
172
+ then_;
173
+ else_;
174
+ constructor(condition, then_, else_) {
175
+ super();
176
+ this.condition = condition;
177
+ this.then_ = then_;
178
+ this.else_ = else_;
179
+ this.freeze();
180
+ }
181
+ static of(condition, then_, else_) {
182
+ return new MongoAggCond(condition, then_, else_);
183
+ }
184
+ accept(visitor) {
185
+ return visitor.cond(this);
186
+ }
187
+ rewrite(rewriter) {
188
+ const rebuilt = new MongoAggCond(this.condition.rewrite(rewriter), this.then_.rewrite(rewriter), this.else_.rewrite(rewriter));
189
+ return rewriter.cond ? rewriter.cond(rebuilt) : rebuilt;
190
+ }
191
+ };
192
+ var MongoAggSwitch = class MongoAggSwitch extends MongoAggExprNode {
193
+ kind = "switch";
194
+ branches;
195
+ default_;
196
+ constructor(branches, default_) {
197
+ super();
198
+ this.branches = Object.freeze(branches.map((b) => Object.freeze({
199
+ case_: b.case_,
200
+ then_: b.then_
201
+ })));
202
+ this.default_ = default_;
203
+ this.freeze();
204
+ }
205
+ static of(branches, default_) {
206
+ return new MongoAggSwitch(branches, default_);
207
+ }
208
+ accept(visitor) {
209
+ return visitor.switch_(this);
210
+ }
211
+ rewrite(rewriter) {
212
+ const rebuilt = new MongoAggSwitch(this.branches.map((b) => ({
213
+ case_: b.case_.rewrite(rewriter),
214
+ then_: b.then_.rewrite(rewriter)
215
+ })), this.default_.rewrite(rewriter));
216
+ return rewriter.switch_ ? rewriter.switch_(rebuilt) : rebuilt;
217
+ }
218
+ };
219
+ var MongoAggArrayFilter = class MongoAggArrayFilter extends MongoAggExprNode {
220
+ kind = "filter";
221
+ input;
222
+ cond;
223
+ as;
224
+ constructor(input, cond, as) {
225
+ super();
226
+ this.input = input;
227
+ this.cond = cond;
228
+ this.as = as;
229
+ this.freeze();
230
+ }
231
+ static of(input, cond, as) {
232
+ return new MongoAggArrayFilter(input, cond, as);
233
+ }
234
+ accept(visitor) {
235
+ return visitor.filter(this);
236
+ }
237
+ rewrite(rewriter) {
238
+ const rebuilt = new MongoAggArrayFilter(this.input.rewrite(rewriter), this.cond.rewrite(rewriter), this.as);
239
+ return rewriter.filter ? rewriter.filter(rebuilt) : rebuilt;
240
+ }
241
+ };
242
+ var MongoAggMap = class MongoAggMap extends MongoAggExprNode {
243
+ kind = "map";
244
+ input;
245
+ in_;
246
+ as;
247
+ constructor(input, in_, as) {
248
+ super();
249
+ this.input = input;
250
+ this.in_ = in_;
251
+ this.as = as;
252
+ this.freeze();
253
+ }
254
+ static of(input, in_, as) {
255
+ return new MongoAggMap(input, in_, as);
256
+ }
257
+ accept(visitor) {
258
+ return visitor.map(this);
259
+ }
260
+ rewrite(rewriter) {
261
+ const rebuilt = new MongoAggMap(this.input.rewrite(rewriter), this.in_.rewrite(rewriter), this.as);
262
+ return rewriter.map ? rewriter.map(rebuilt) : rebuilt;
263
+ }
264
+ };
265
+ var MongoAggReduce = class MongoAggReduce extends MongoAggExprNode {
266
+ kind = "reduce";
267
+ input;
268
+ initialValue;
269
+ in_;
270
+ constructor(input, initialValue, in_) {
271
+ super();
272
+ this.input = input;
273
+ this.initialValue = initialValue;
274
+ this.in_ = in_;
275
+ this.freeze();
276
+ }
277
+ static of(input, initialValue, in_) {
278
+ return new MongoAggReduce(input, initialValue, in_);
279
+ }
280
+ accept(visitor) {
281
+ return visitor.reduce(this);
282
+ }
283
+ rewrite(rewriter) {
284
+ const rebuilt = new MongoAggReduce(this.input.rewrite(rewriter), this.initialValue.rewrite(rewriter), this.in_.rewrite(rewriter));
285
+ return rewriter.reduce ? rewriter.reduce(rebuilt) : rebuilt;
286
+ }
287
+ };
288
+ var MongoAggLet = class MongoAggLet extends MongoAggExprNode {
289
+ kind = "let";
290
+ vars;
291
+ in_;
292
+ constructor(vars, in_) {
293
+ super();
294
+ this.vars = Object.freeze({ ...vars });
295
+ this.in_ = in_;
296
+ this.freeze();
297
+ }
298
+ static of(vars, in_) {
299
+ return new MongoAggLet(vars, in_);
300
+ }
301
+ accept(visitor) {
302
+ return visitor.let_(this);
303
+ }
304
+ rewrite(rewriter) {
305
+ const rewrittenVars = {};
306
+ for (const [key, val] of Object.entries(this.vars)) rewrittenVars[key] = val.rewrite(rewriter);
307
+ const rebuilt = new MongoAggLet(rewrittenVars, this.in_.rewrite(rewriter));
308
+ return rewriter.let_ ? rewriter.let_(rebuilt) : rebuilt;
309
+ }
310
+ };
311
+ var MongoAggMergeObjects = class MongoAggMergeObjects extends MongoAggExprNode {
312
+ kind = "mergeObjects";
313
+ exprs;
314
+ constructor(exprs) {
315
+ super();
316
+ this.exprs = Object.freeze([...exprs]);
317
+ this.freeze();
318
+ }
319
+ static of(exprs) {
320
+ return new MongoAggMergeObjects(exprs);
321
+ }
322
+ accept(visitor) {
323
+ return visitor.mergeObjects(this);
324
+ }
325
+ rewrite(rewriter) {
326
+ const rebuilt = new MongoAggMergeObjects(this.exprs.map((e) => e.rewrite(rewriter)));
327
+ return rewriter.mergeObjects ? rewriter.mergeObjects(rebuilt) : rebuilt;
328
+ }
329
+ };
330
+ var InsertOneCommand = class extends MongoAstNode {
331
+ kind = "insertOne";
332
+ collection;
333
+ document;
334
+ constructor(collection, document) {
335
+ super();
336
+ this.collection = collection;
337
+ this.document = document;
338
+ this.freeze();
339
+ }
340
+ };
341
+ var UpdateOneCommand = class extends MongoAstNode {
342
+ kind = "updateOne";
343
+ collection;
344
+ filter;
345
+ update;
346
+ /**
347
+ * When true, the wire command becomes an upsert: if no document matches
348
+ * `filter`, a new document is inserted, derived from the filter's
349
+ * equality fields plus the update spec. Defaults to false.
350
+ */
351
+ upsert;
352
+ constructor(collection, filter, update, upsert = false) {
353
+ super();
354
+ this.collection = collection;
355
+ this.filter = filter;
356
+ this.update = update;
357
+ this.upsert = upsert;
358
+ this.freeze();
359
+ }
360
+ };
361
+ var DeleteOneCommand = class extends MongoAstNode {
362
+ kind = "deleteOne";
363
+ collection;
364
+ filter;
365
+ constructor(collection, filter) {
366
+ super();
367
+ this.collection = collection;
368
+ this.filter = filter;
369
+ this.freeze();
370
+ }
371
+ };
372
+ var InsertManyCommand = class extends MongoAstNode {
373
+ kind = "insertMany";
374
+ collection;
375
+ documents;
376
+ constructor(collection, documents) {
377
+ super();
378
+ this.collection = collection;
379
+ this.documents = documents;
380
+ this.freeze();
381
+ }
382
+ };
383
+ var UpdateManyCommand = class extends MongoAstNode {
384
+ kind = "updateMany";
385
+ collection;
386
+ filter;
387
+ update;
388
+ /**
389
+ * Upsert flag — see `UpdateOneCommand.upsert`. For `updateMany`, Mongo
390
+ * inserts at most one document when no match exists (driver-side
391
+ * constraint).
392
+ */
393
+ upsert;
394
+ constructor(collection, filter, update, upsert = false) {
395
+ super();
396
+ this.collection = collection;
397
+ this.filter = filter;
398
+ this.update = update;
399
+ this.upsert = upsert;
400
+ this.freeze();
401
+ }
402
+ };
403
+ var DeleteManyCommand = class extends MongoAstNode {
404
+ kind = "deleteMany";
405
+ collection;
406
+ filter;
407
+ constructor(collection, filter) {
408
+ super();
409
+ this.collection = collection;
410
+ this.filter = filter;
411
+ this.freeze();
412
+ }
413
+ };
414
+ var FindOneAndUpdateCommand = class extends MongoAstNode {
415
+ kind = "findOneAndUpdate";
416
+ collection;
417
+ filter;
418
+ update;
419
+ upsert;
420
+ sort;
421
+ returnDocument;
422
+ constructor(collection, filter, update, upsert = false, sort, returnDocument = "after") {
423
+ super();
424
+ this.collection = collection;
425
+ this.filter = filter;
426
+ this.update = update;
427
+ this.upsert = upsert;
428
+ this.sort = sort;
429
+ this.returnDocument = returnDocument;
430
+ this.freeze();
431
+ }
432
+ };
433
+ var FindOneAndDeleteCommand = class extends MongoAstNode {
434
+ kind = "findOneAndDelete";
435
+ collection;
436
+ filter;
437
+ sort;
438
+ constructor(collection, filter, sort) {
439
+ super();
440
+ this.collection = collection;
441
+ this.filter = filter;
442
+ this.sort = sort;
443
+ this.freeze();
444
+ }
445
+ };
446
+ var AggregateCommand = class extends MongoAstNode {
447
+ kind = "aggregate";
448
+ collection;
449
+ pipeline;
450
+ constructor(collection, pipeline) {
451
+ super();
452
+ this.collection = collection;
453
+ this.pipeline = pipeline;
454
+ this.freeze();
455
+ }
456
+ };
457
+ var RawAggregateCommand = class extends MongoAstNode {
458
+ kind = "rawAggregate";
459
+ collection;
460
+ pipeline;
461
+ constructor(collection, pipeline) {
462
+ super();
463
+ this.collection = collection;
464
+ this.pipeline = pipeline;
465
+ this.freeze();
466
+ }
467
+ };
468
+ var RawInsertOneCommand = class extends MongoAstNode {
469
+ kind = "rawInsertOne";
470
+ collection;
471
+ document;
472
+ constructor(collection, document) {
473
+ super();
474
+ this.collection = collection;
475
+ this.document = document;
476
+ this.freeze();
477
+ }
478
+ };
479
+ var RawInsertManyCommand = class extends MongoAstNode {
480
+ kind = "rawInsertMany";
481
+ collection;
482
+ documents;
483
+ constructor(collection, documents) {
484
+ super();
485
+ this.collection = collection;
486
+ this.documents = documents;
487
+ this.freeze();
488
+ }
489
+ };
490
+ var RawUpdateOneCommand = class extends MongoAstNode {
491
+ kind = "rawUpdateOne";
492
+ collection;
493
+ filter;
494
+ update;
495
+ constructor(collection, filter, update) {
496
+ super();
497
+ this.collection = collection;
498
+ this.filter = filter;
499
+ this.update = update;
500
+ this.freeze();
501
+ }
502
+ };
503
+ var RawUpdateManyCommand = class extends MongoAstNode {
504
+ kind = "rawUpdateMany";
505
+ collection;
506
+ filter;
507
+ update;
508
+ constructor(collection, filter, update) {
509
+ super();
510
+ this.collection = collection;
511
+ this.filter = filter;
512
+ this.update = update;
513
+ this.freeze();
514
+ }
515
+ };
516
+ var RawDeleteOneCommand = class extends MongoAstNode {
517
+ kind = "rawDeleteOne";
518
+ collection;
519
+ filter;
520
+ constructor(collection, filter) {
521
+ super();
522
+ this.collection = collection;
523
+ this.filter = filter;
524
+ this.freeze();
525
+ }
526
+ };
527
+ var RawDeleteManyCommand = class extends MongoAstNode {
528
+ kind = "rawDeleteMany";
529
+ collection;
530
+ filter;
531
+ constructor(collection, filter) {
532
+ super();
533
+ this.collection = collection;
534
+ this.filter = filter;
535
+ this.freeze();
536
+ }
537
+ };
538
+ var RawFindOneAndUpdateCommand = class extends MongoAstNode {
539
+ kind = "rawFindOneAndUpdate";
540
+ collection;
541
+ filter;
542
+ update;
543
+ upsert;
544
+ sort;
545
+ /**
546
+ * When `undefined`, the option is omitted from the wire command and the
547
+ * MongoDB driver applies its documented default (return the pre-image
548
+ * document). Set explicitly to `'before'` or `'after'` to override.
549
+ */
550
+ returnDocument;
551
+ constructor(collection, filter, update, upsert = false, sort, returnDocument) {
552
+ super();
553
+ this.collection = collection;
554
+ this.filter = filter;
555
+ this.update = update;
556
+ this.upsert = upsert;
557
+ this.sort = sort;
558
+ this.returnDocument = returnDocument;
559
+ this.freeze();
560
+ }
561
+ };
562
+ var RawFindOneAndDeleteCommand = class extends MongoAstNode {
563
+ kind = "rawFindOneAndDelete";
564
+ collection;
565
+ filter;
566
+ sort;
567
+ constructor(collection, filter, sort) {
568
+ super();
569
+ this.collection = collection;
570
+ this.filter = filter;
571
+ this.sort = sort;
572
+ this.freeze();
573
+ }
574
+ };
575
+ function freezeMongoFieldShape(shape) {
576
+ switch (shape.kind) {
577
+ case "unknown": return Object.freeze({ kind: "unknown" });
578
+ case "leaf": return Object.freeze({
579
+ kind: "leaf",
580
+ codecId: shape.codecId,
581
+ nullable: shape.nullable
582
+ });
583
+ case "document": {
584
+ const fields = {};
585
+ for (const [k, v] of Object.entries(shape.fields)) fields[k] = freezeMongoFieldShape(v);
586
+ return Object.freeze({
587
+ kind: "document",
588
+ nullable: shape.nullable,
589
+ fields: Object.freeze(fields)
590
+ });
591
+ }
592
+ case "array": return Object.freeze({
593
+ kind: "array",
594
+ nullable: shape.nullable,
595
+ element: freezeMongoFieldShape(shape.element)
596
+ });
597
+ default: return shape;
598
+ }
599
+ }
600
+ function freezeMongoResultShape(shape) {
601
+ if (shape.kind === "unknown") return Object.freeze({ kind: "unknown" });
602
+ const fields = {};
603
+ for (const [k, v] of Object.entries(shape.fields)) fields[k] = freezeMongoFieldShape(v);
604
+ return Object.freeze({
605
+ kind: "document",
606
+ fields: Object.freeze(fields)
607
+ });
608
+ }
609
+ function isAggExpr(value) {
610
+ return typeof value === "object" && value !== null && "kind" in value;
611
+ }
612
+ function isAggExprNode(value) {
613
+ return "accept" in value && typeof value.accept === "function";
614
+ }
615
+ function rewriteGroupId(groupId, rewriter) {
616
+ if (groupId === null) return null;
617
+ if (isAggExprNode(groupId)) return groupId.rewrite(rewriter);
618
+ const result = {};
619
+ for (const [key, val] of Object.entries(groupId)) result[key] = val.rewrite(rewriter);
620
+ return result;
621
+ }
622
+ function rewriteExprRecord(fields, rewriter) {
623
+ const result = {};
624
+ for (const [key, val] of Object.entries(fields)) result[key] = val.rewrite(rewriter);
625
+ return result;
626
+ }
627
+ function rewriteAccumulatorRecord(accumulators, rewriter) {
628
+ const result = {};
629
+ for (const [key, acc] of Object.entries(accumulators)) result[key] = acc.rewrite(rewriter);
630
+ return result;
631
+ }
632
+ var MongoStageNode = class extends MongoAstNode {};
633
+ var MongoMatchStage = class MongoMatchStage extends MongoStageNode {
634
+ kind = "match";
635
+ filter;
636
+ constructor(filter) {
637
+ super();
638
+ this.filter = filter;
639
+ this.freeze();
640
+ }
641
+ accept(visitor) {
642
+ return visitor.match(this);
643
+ }
644
+ rewrite(context) {
645
+ return new MongoMatchStage(this.filter.rewrite(context.filter ?? {}));
646
+ }
647
+ };
648
+ var MongoProjectStage = class MongoProjectStage extends MongoStageNode {
649
+ kind = "project";
650
+ projection;
651
+ constructor(projection) {
652
+ super();
653
+ this.projection = Object.freeze({ ...projection });
654
+ this.freeze();
655
+ }
656
+ accept(visitor) {
657
+ return visitor.project(this);
658
+ }
659
+ rewrite(context) {
660
+ const rewriter = context.aggExpr;
661
+ if (!rewriter) return this;
662
+ let hasExpr = false;
663
+ for (const val of Object.values(this.projection)) if (isAggExpr(val)) {
664
+ hasExpr = true;
665
+ break;
666
+ }
667
+ if (!hasExpr) return this;
668
+ const newProjection = {};
669
+ for (const [key, val] of Object.entries(this.projection)) newProjection[key] = isAggExpr(val) ? val.rewrite(rewriter) : val;
670
+ return new MongoProjectStage(newProjection);
671
+ }
672
+ };
673
+ var MongoSortStage = class extends MongoStageNode {
674
+ kind = "sort";
675
+ sort;
676
+ constructor(sort) {
677
+ super();
678
+ this.sort = Object.freeze({ ...sort });
679
+ this.freeze();
680
+ }
681
+ accept(visitor) {
682
+ return visitor.sort(this);
683
+ }
684
+ rewrite(_context) {
685
+ return this;
686
+ }
687
+ };
688
+ var MongoLimitStage = class extends MongoStageNode {
689
+ kind = "limit";
690
+ limit;
691
+ constructor(limit) {
692
+ super();
693
+ if (!Number.isInteger(limit) || limit < 0) throw ormError("ORM.ARGUMENT_INVALID", "limit must be a non-negative integer");
694
+ this.limit = limit;
695
+ this.freeze();
696
+ }
697
+ accept(visitor) {
698
+ return visitor.limit(this);
699
+ }
700
+ rewrite(_context) {
701
+ return this;
702
+ }
703
+ };
704
+ var MongoSkipStage = class extends MongoStageNode {
705
+ kind = "skip";
706
+ skip;
707
+ constructor(skip) {
708
+ super();
709
+ if (!Number.isInteger(skip) || skip < 0) throw ormError("ORM.ARGUMENT_INVALID", "skip must be a non-negative integer");
710
+ this.skip = skip;
711
+ this.freeze();
712
+ }
713
+ accept(visitor) {
714
+ return visitor.skip(this);
715
+ }
716
+ rewrite(_context) {
717
+ return this;
718
+ }
719
+ };
720
+ var MongoLookupStage = class MongoLookupStage extends MongoStageNode {
721
+ kind = "lookup";
722
+ from;
723
+ localField;
724
+ foreignField;
725
+ as;
726
+ pipeline;
727
+ let_;
728
+ constructor(options) {
729
+ super();
730
+ const hasLocalField = options.localField !== void 0;
731
+ const hasForeignField = options.foreignField !== void 0;
732
+ const hasPipeline = !!options.pipeline;
733
+ if (hasLocalField !== hasForeignField) throw ormError("ORM.ARGUMENT_INVALID", "MongoLookupStage requires both localField and foreignField together");
734
+ if (!hasLocalField && !hasPipeline) throw ormError("ORM.ARGUMENT_INVALID", "MongoLookupStage requires either equality fields (localField/foreignField) or a pipeline");
735
+ if (options.let_ && !hasPipeline) throw ormError("ORM.ARGUMENT_INVALID", "MongoLookupStage let_ requires a pipeline");
736
+ this.from = options.from;
737
+ this.localField = options.localField;
738
+ this.foreignField = options.foreignField;
739
+ this.as = options.as;
740
+ this.pipeline = options.pipeline ? Object.freeze([...options.pipeline]) : void 0;
741
+ this.let_ = options.let_ ? Object.freeze({ ...options.let_ }) : void 0;
742
+ this.freeze();
743
+ }
744
+ accept(visitor) {
745
+ return visitor.lookup(this);
746
+ }
747
+ rewrite(context) {
748
+ if (!this.pipeline && !this.let_) return this;
749
+ const rewrittenLet = this.let_ && context.aggExpr ? rewriteExprRecord(this.let_, context.aggExpr) : this.let_;
750
+ const options = {
751
+ from: this.from,
752
+ as: this.as
753
+ };
754
+ if (this.localField !== void 0) options.localField = this.localField;
755
+ if (this.foreignField !== void 0) options.foreignField = this.foreignField;
756
+ if (this.pipeline) options.pipeline = this.pipeline.map((stage) => stage.rewrite(context));
757
+ if (rewrittenLet) options.let_ = { ...rewrittenLet };
758
+ return new MongoLookupStage(options);
759
+ }
760
+ };
761
+ var MongoUnwindStage = class extends MongoStageNode {
762
+ kind = "unwind";
763
+ path;
764
+ preserveNullAndEmptyArrays;
765
+ includeArrayIndex;
766
+ constructor(path, preserveNullAndEmptyArrays, includeArrayIndex) {
767
+ super();
768
+ this.path = path;
769
+ this.preserveNullAndEmptyArrays = preserveNullAndEmptyArrays;
770
+ this.includeArrayIndex = includeArrayIndex;
771
+ this.freeze();
772
+ }
773
+ accept(visitor) {
774
+ return visitor.unwind(this);
775
+ }
776
+ rewrite(_context) {
777
+ return this;
778
+ }
779
+ };
780
+ var MongoGroupStage = class MongoGroupStage extends MongoStageNode {
781
+ kind = "group";
782
+ groupId;
783
+ accumulators;
784
+ constructor(groupId, accumulators) {
785
+ super();
786
+ this.groupId = groupId;
787
+ this.accumulators = Object.freeze({ ...accumulators });
788
+ this.freeze();
789
+ }
790
+ accept(visitor) {
791
+ return visitor.group(this);
792
+ }
793
+ rewrite(context) {
794
+ const rewriter = context.aggExpr;
795
+ if (!rewriter) return this;
796
+ const newAccumulators = {};
797
+ for (const [key, acc] of Object.entries(this.accumulators)) newAccumulators[key] = acc.rewrite(rewriter);
798
+ return new MongoGroupStage(rewriteGroupId(this.groupId, rewriter), newAccumulators);
799
+ }
800
+ };
801
+ var MongoAddFieldsStage = class MongoAddFieldsStage extends MongoStageNode {
802
+ kind = "addFields";
803
+ fields;
804
+ constructor(fields) {
805
+ super();
806
+ this.fields = Object.freeze({ ...fields });
807
+ this.freeze();
808
+ }
809
+ accept(visitor) {
810
+ return visitor.addFields(this);
811
+ }
812
+ rewrite(context) {
813
+ const rewriter = context.aggExpr;
814
+ if (!rewriter) return this;
815
+ return new MongoAddFieldsStage(rewriteExprRecord(this.fields, rewriter));
816
+ }
817
+ };
818
+ var MongoReplaceRootStage = class MongoReplaceRootStage extends MongoStageNode {
819
+ kind = "replaceRoot";
820
+ newRoot;
821
+ constructor(newRoot) {
822
+ super();
823
+ this.newRoot = newRoot;
824
+ this.freeze();
825
+ }
826
+ accept(visitor) {
827
+ return visitor.replaceRoot(this);
828
+ }
829
+ rewrite(context) {
830
+ const rewriter = context.aggExpr;
831
+ if (!rewriter) return this;
832
+ return new MongoReplaceRootStage(this.newRoot.rewrite(rewriter));
833
+ }
834
+ };
835
+ var MongoCountStage = class extends MongoStageNode {
836
+ kind = "count";
837
+ field;
838
+ constructor(field) {
839
+ super();
840
+ this.field = field;
841
+ this.freeze();
842
+ }
843
+ accept(visitor) {
844
+ return visitor.count(this);
845
+ }
846
+ rewrite(_context) {
847
+ return this;
848
+ }
849
+ };
850
+ var MongoSortByCountStage = class MongoSortByCountStage extends MongoStageNode {
851
+ kind = "sortByCount";
852
+ expr;
853
+ constructor(expr) {
854
+ super();
855
+ this.expr = expr;
856
+ this.freeze();
857
+ }
858
+ accept(visitor) {
859
+ return visitor.sortByCount(this);
860
+ }
861
+ rewrite(context) {
862
+ const rewriter = context.aggExpr;
863
+ if (!rewriter) return this;
864
+ return new MongoSortByCountStage(this.expr.rewrite(rewriter));
865
+ }
866
+ };
867
+ var MongoSampleStage = class extends MongoStageNode {
868
+ kind = "sample";
869
+ size;
870
+ constructor(size) {
871
+ super();
872
+ if (!Number.isInteger(size) || size < 0) throw ormError("ORM.ARGUMENT_INVALID", "size must be a non-negative integer");
873
+ this.size = size;
874
+ this.freeze();
875
+ }
876
+ accept(visitor) {
877
+ return visitor.sample(this);
878
+ }
879
+ rewrite(_context) {
880
+ return this;
881
+ }
882
+ };
883
+ var MongoRedactStage = class MongoRedactStage extends MongoStageNode {
884
+ kind = "redact";
885
+ expr;
886
+ constructor(expr) {
887
+ super();
888
+ this.expr = expr;
889
+ this.freeze();
890
+ }
891
+ accept(visitor) {
892
+ return visitor.redact(this);
893
+ }
894
+ rewrite(context) {
895
+ const rewriter = context.aggExpr;
896
+ if (!rewriter) return this;
897
+ return new MongoRedactStage(this.expr.rewrite(rewriter));
898
+ }
899
+ };
900
+ var MongoOutStage = class extends MongoStageNode {
901
+ kind = "out";
902
+ collection;
903
+ db;
904
+ constructor(collection, db) {
905
+ super();
906
+ this.collection = collection;
907
+ this.db = db;
908
+ this.freeze();
909
+ }
910
+ accept(visitor) {
911
+ return visitor.out(this);
912
+ }
913
+ rewrite(_context) {
914
+ return this;
915
+ }
916
+ };
917
+ var MongoUnionWithStage = class MongoUnionWithStage extends MongoStageNode {
918
+ kind = "unionWith";
919
+ collection;
920
+ pipeline;
921
+ constructor(collection, pipeline) {
922
+ super();
923
+ this.collection = collection;
924
+ this.pipeline = pipeline ? Object.freeze([...pipeline]) : void 0;
925
+ this.freeze();
926
+ }
927
+ accept(visitor) {
928
+ return visitor.unionWith(this);
929
+ }
930
+ rewrite(context) {
931
+ if (!this.pipeline) return this;
932
+ return new MongoUnionWithStage(this.collection, this.pipeline.map((stage) => stage.rewrite(context)));
933
+ }
934
+ };
935
+ var MongoBucketStage = class MongoBucketStage extends MongoStageNode {
936
+ kind = "bucket";
937
+ groupBy;
938
+ boundaries;
939
+ default_;
940
+ output;
941
+ constructor(options) {
942
+ super();
943
+ if (options.boundaries.length < 2) throw ormError("ORM.ARGUMENT_INVALID", "boundaries must contain at least 2 values");
944
+ this.groupBy = options.groupBy;
945
+ this.boundaries = Object.freeze([...options.boundaries]);
946
+ this.default_ = options.default_;
947
+ this.output = options.output ? Object.freeze({ ...options.output }) : void 0;
948
+ this.freeze();
949
+ }
950
+ accept(visitor) {
951
+ return visitor.bucket(this);
952
+ }
953
+ rewrite(context) {
954
+ const rewriter = context.aggExpr;
955
+ if (!rewriter) return this;
956
+ const opts = {
957
+ groupBy: this.groupBy.rewrite(rewriter),
958
+ boundaries: this.boundaries
959
+ };
960
+ if (this.default_ !== void 0) opts.default_ = this.default_;
961
+ if (this.output) opts.output = rewriteAccumulatorRecord(this.output, rewriter);
962
+ return new MongoBucketStage(opts);
963
+ }
964
+ };
965
+ var MongoBucketAutoStage = class MongoBucketAutoStage extends MongoStageNode {
966
+ kind = "bucketAuto";
967
+ groupBy;
968
+ buckets;
969
+ output;
970
+ granularity;
971
+ constructor(options) {
972
+ super();
973
+ if (!Number.isInteger(options.buckets) || options.buckets < 1) throw ormError("ORM.ARGUMENT_INVALID", "buckets must be a positive integer");
974
+ this.groupBy = options.groupBy;
975
+ this.buckets = options.buckets;
976
+ this.output = options.output ? Object.freeze({ ...options.output }) : void 0;
977
+ this.granularity = options.granularity;
978
+ this.freeze();
979
+ }
980
+ accept(visitor) {
981
+ return visitor.bucketAuto(this);
982
+ }
983
+ rewrite(context) {
984
+ const rewriter = context.aggExpr;
985
+ if (!rewriter) return this;
986
+ const opts = {
987
+ groupBy: this.groupBy.rewrite(rewriter),
988
+ buckets: this.buckets
989
+ };
990
+ if (this.output) opts.output = rewriteAccumulatorRecord(this.output, rewriter);
991
+ if (this.granularity !== void 0) opts.granularity = this.granularity;
992
+ return new MongoBucketAutoStage(opts);
993
+ }
994
+ };
995
+ var MongoGeoNearStage = class MongoGeoNearStage extends MongoStageNode {
996
+ kind = "geoNear";
997
+ near;
998
+ distanceField;
999
+ spherical;
1000
+ maxDistance;
1001
+ minDistance;
1002
+ query;
1003
+ key;
1004
+ distanceMultiplier;
1005
+ includeLocs;
1006
+ constructor(options) {
1007
+ super();
1008
+ this.near = options.near;
1009
+ this.distanceField = options.distanceField;
1010
+ this.spherical = options.spherical;
1011
+ this.maxDistance = options.maxDistance;
1012
+ this.minDistance = options.minDistance;
1013
+ this.query = options.query;
1014
+ this.key = options.key;
1015
+ this.distanceMultiplier = options.distanceMultiplier;
1016
+ this.includeLocs = options.includeLocs;
1017
+ this.freeze();
1018
+ }
1019
+ accept(visitor) {
1020
+ return visitor.geoNear(this);
1021
+ }
1022
+ rewrite(context) {
1023
+ if (!this.query || !context.filter) return this;
1024
+ const opts = {
1025
+ near: this.near,
1026
+ distanceField: this.distanceField
1027
+ };
1028
+ if (this.spherical !== void 0) opts.spherical = this.spherical;
1029
+ if (this.maxDistance !== void 0) opts.maxDistance = this.maxDistance;
1030
+ if (this.minDistance !== void 0) opts.minDistance = this.minDistance;
1031
+ opts.query = this.query.rewrite(context.filter);
1032
+ if (this.key !== void 0) opts.key = this.key;
1033
+ if (this.distanceMultiplier !== void 0) opts.distanceMultiplier = this.distanceMultiplier;
1034
+ if (this.includeLocs !== void 0) opts.includeLocs = this.includeLocs;
1035
+ return new MongoGeoNearStage(opts);
1036
+ }
1037
+ };
1038
+ var MongoFacetStage = class MongoFacetStage extends MongoStageNode {
1039
+ kind = "facet";
1040
+ facets;
1041
+ constructor(facets) {
1042
+ super();
1043
+ const frozen = {};
1044
+ for (const [key, pipeline] of Object.entries(facets)) frozen[key] = Object.freeze([...pipeline]);
1045
+ this.facets = Object.freeze(frozen);
1046
+ this.freeze();
1047
+ }
1048
+ accept(visitor) {
1049
+ return visitor.facet(this);
1050
+ }
1051
+ rewrite(context) {
1052
+ const newFacets = {};
1053
+ for (const [key, pipeline] of Object.entries(this.facets)) newFacets[key] = pipeline.map((stage) => stage.rewrite(context));
1054
+ return new MongoFacetStage(newFacets);
1055
+ }
1056
+ };
1057
+ var MongoGraphLookupStage = class MongoGraphLookupStage extends MongoStageNode {
1058
+ kind = "graphLookup";
1059
+ from;
1060
+ startWith;
1061
+ connectFromField;
1062
+ connectToField;
1063
+ as;
1064
+ maxDepth;
1065
+ depthField;
1066
+ restrictSearchWithMatch;
1067
+ constructor(options) {
1068
+ super();
1069
+ this.from = options.from;
1070
+ this.startWith = options.startWith;
1071
+ this.connectFromField = options.connectFromField;
1072
+ this.connectToField = options.connectToField;
1073
+ this.as = options.as;
1074
+ this.maxDepth = options.maxDepth;
1075
+ this.depthField = options.depthField;
1076
+ this.restrictSearchWithMatch = options.restrictSearchWithMatch;
1077
+ this.freeze();
1078
+ }
1079
+ accept(visitor) {
1080
+ return visitor.graphLookup(this);
1081
+ }
1082
+ rewrite(context) {
1083
+ const rewrittenStartWith = context.aggExpr ? this.startWith.rewrite(context.aggExpr) : this.startWith;
1084
+ const rewrittenMatch = this.restrictSearchWithMatch && context.filter ? this.restrictSearchWithMatch.rewrite(context.filter) : this.restrictSearchWithMatch;
1085
+ if (rewrittenStartWith === this.startWith && rewrittenMatch === this.restrictSearchWithMatch) return this;
1086
+ const opts = {
1087
+ from: this.from,
1088
+ startWith: rewrittenStartWith,
1089
+ connectFromField: this.connectFromField,
1090
+ connectToField: this.connectToField,
1091
+ as: this.as
1092
+ };
1093
+ if (this.maxDepth !== void 0) opts.maxDepth = this.maxDepth;
1094
+ if (this.depthField !== void 0) opts.depthField = this.depthField;
1095
+ if (rewrittenMatch) opts.restrictSearchWithMatch = rewrittenMatch;
1096
+ return new MongoGraphLookupStage(opts);
1097
+ }
1098
+ };
1099
+ var MongoMergeStage = class MongoMergeStage extends MongoStageNode {
1100
+ kind = "merge";
1101
+ into;
1102
+ on;
1103
+ whenMatched;
1104
+ whenNotMatched;
1105
+ constructor(options) {
1106
+ super();
1107
+ this.into = typeof options.into === "string" ? options.into : Object.freeze({ ...options.into });
1108
+ this.on = options.on === void 0 ? void 0 : typeof options.on === "string" ? options.on : Object.freeze([...options.on]);
1109
+ this.whenMatched = options.whenMatched === void 0 ? void 0 : typeof options.whenMatched === "string" ? options.whenMatched : Object.freeze([...options.whenMatched]);
1110
+ this.whenNotMatched = options.whenNotMatched;
1111
+ this.freeze();
1112
+ }
1113
+ accept(visitor) {
1114
+ return visitor.merge(this);
1115
+ }
1116
+ rewrite(context) {
1117
+ if (!Array.isArray(this.whenMatched)) return this;
1118
+ const opts = { into: this.into };
1119
+ if (this.on !== void 0) opts.on = this.on;
1120
+ opts.whenMatched = this.whenMatched.map((stage) => stage.rewrite(context));
1121
+ if (this.whenNotMatched !== void 0) opts.whenNotMatched = this.whenNotMatched;
1122
+ return new MongoMergeStage(opts);
1123
+ }
1124
+ };
1125
+ var MongoSetWindowFieldsStage = class MongoSetWindowFieldsStage extends MongoStageNode {
1126
+ kind = "setWindowFields";
1127
+ partitionBy;
1128
+ sortBy;
1129
+ output;
1130
+ constructor(options) {
1131
+ super();
1132
+ this.partitionBy = options.partitionBy;
1133
+ this.sortBy = options.sortBy ? Object.freeze({ ...options.sortBy }) : void 0;
1134
+ this.output = Object.freeze({ ...options.output });
1135
+ this.freeze();
1136
+ }
1137
+ accept(visitor) {
1138
+ return visitor.setWindowFields(this);
1139
+ }
1140
+ rewrite(context) {
1141
+ const rewriter = context.aggExpr;
1142
+ if (!rewriter) return this;
1143
+ const newOutput = {};
1144
+ for (const [key, wf] of Object.entries(this.output)) newOutput[key] = {
1145
+ ...wf,
1146
+ operator: wf.operator.rewrite(rewriter)
1147
+ };
1148
+ const opts = { output: newOutput };
1149
+ if (this.partitionBy) opts.partitionBy = this.partitionBy.rewrite(rewriter);
1150
+ if (this.sortBy) opts.sortBy = { ...this.sortBy };
1151
+ return new MongoSetWindowFieldsStage(opts);
1152
+ }
1153
+ };
1154
+ var MongoDensifyStage = class extends MongoStageNode {
1155
+ kind = "densify";
1156
+ field;
1157
+ partitionByFields;
1158
+ range;
1159
+ constructor(options) {
1160
+ super();
1161
+ this.field = options.field;
1162
+ this.partitionByFields = options.partitionByFields ? Object.freeze([...options.partitionByFields]) : void 0;
1163
+ this.range = Object.freeze({ ...options.range });
1164
+ this.freeze();
1165
+ }
1166
+ accept(visitor) {
1167
+ return visitor.densify(this);
1168
+ }
1169
+ rewrite(_context) {
1170
+ return this;
1171
+ }
1172
+ };
1173
+ var MongoFillStage = class MongoFillStage extends MongoStageNode {
1174
+ kind = "fill";
1175
+ partitionBy;
1176
+ partitionByFields;
1177
+ sortBy;
1178
+ output;
1179
+ constructor(options) {
1180
+ super();
1181
+ this.partitionBy = options.partitionBy;
1182
+ this.partitionByFields = options.partitionByFields ? Object.freeze([...options.partitionByFields]) : void 0;
1183
+ this.sortBy = options.sortBy ? Object.freeze({ ...options.sortBy }) : void 0;
1184
+ this.output = Object.freeze({ ...options.output });
1185
+ this.freeze();
1186
+ }
1187
+ accept(visitor) {
1188
+ return visitor.fill(this);
1189
+ }
1190
+ rewrite(context) {
1191
+ const rewriter = context.aggExpr;
1192
+ if (!rewriter) return this;
1193
+ const newOutput = {};
1194
+ for (const [key, fo] of Object.entries(this.output)) newOutput[key] = fo.value ? {
1195
+ ...fo,
1196
+ value: fo.value.rewrite(rewriter)
1197
+ } : fo;
1198
+ const opts = { output: newOutput };
1199
+ if (this.partitionBy) opts.partitionBy = this.partitionBy.rewrite(rewriter);
1200
+ if (this.partitionByFields) opts.partitionByFields = [...this.partitionByFields];
1201
+ if (this.sortBy) opts.sortBy = { ...this.sortBy };
1202
+ return new MongoFillStage(opts);
1203
+ }
1204
+ };
1205
+ var MongoSearchStage = class extends MongoStageNode {
1206
+ kind = "search";
1207
+ index;
1208
+ config;
1209
+ constructor(config, index) {
1210
+ super();
1211
+ this.config = Object.freeze({ ...config });
1212
+ this.index = index;
1213
+ this.freeze();
1214
+ }
1215
+ accept(visitor) {
1216
+ return visitor.search(this);
1217
+ }
1218
+ rewrite(_context) {
1219
+ return this;
1220
+ }
1221
+ };
1222
+ var MongoSearchMetaStage = class extends MongoStageNode {
1223
+ kind = "searchMeta";
1224
+ index;
1225
+ config;
1226
+ constructor(config, index) {
1227
+ super();
1228
+ this.config = Object.freeze({ ...config });
1229
+ this.index = index;
1230
+ this.freeze();
1231
+ }
1232
+ accept(visitor) {
1233
+ return visitor.searchMeta(this);
1234
+ }
1235
+ rewrite(_context) {
1236
+ return this;
1237
+ }
1238
+ };
1239
+ var MongoVectorSearchStage = class extends MongoStageNode {
1240
+ kind = "vectorSearch";
1241
+ index;
1242
+ path;
1243
+ queryVector;
1244
+ numCandidates;
1245
+ limit;
1246
+ filter;
1247
+ constructor(options) {
1248
+ super();
1249
+ if (!Number.isInteger(options.limit) || options.limit < 1) throw ormError("ORM.ARGUMENT_INVALID", "limit must be a positive integer");
1250
+ if (!Number.isInteger(options.numCandidates) || options.numCandidates < options.limit) throw ormError("ORM.ARGUMENT_INVALID", "numCandidates must be an integer >= limit");
1251
+ this.index = options.index;
1252
+ this.path = options.path;
1253
+ this.queryVector = Object.freeze([...options.queryVector]);
1254
+ this.numCandidates = options.numCandidates;
1255
+ this.limit = options.limit;
1256
+ this.filter = options.filter ? Object.freeze({ ...options.filter }) : void 0;
1257
+ this.freeze();
1258
+ }
1259
+ accept(visitor) {
1260
+ return visitor.vectorSearch(this);
1261
+ }
1262
+ rewrite(_context) {
1263
+ return this;
1264
+ }
1265
+ };
1266
+ //#endregion
1267
+ export { RawInsertOneCommand as $, MongoLookupStage as A, MongoSetWindowFieldsStage as B, MongoDensifyStage as C, MongoGraphLookupStage as D, MongoGeoNearStage as E, MongoRedactStage as F, MongoUnwindStage as G, MongoSortByCountStage as H, MongoReplaceRootStage as I, RawDeleteManyCommand as J, MongoVectorSearchStage as K, MongoSampleStage as L, MongoMergeStage as M, MongoOutStage as N, MongoGroupStage as O, MongoProjectStage as P, RawInsertManyCommand as Q, MongoSearchMetaStage as R, MongoCountStage as S, MongoFillStage as T, MongoSortStage as U, MongoSkipStage as V, MongoUnionWithStage as W, RawFindOneAndDeleteCommand as X, RawDeleteOneCommand as Y, RawFindOneAndUpdateCommand as Z, MongoAggOperator as _, FindOneAndUpdateCommand as a, freezeMongoResultShape as at, MongoBucketAutoStage as b, MongoAddFieldsStage as c, MongoAggCond as d, RawUpdateManyCommand as et, MongoAggFieldRef as f, MongoAggMergeObjects as g, MongoAggMap as h, FindOneAndDeleteCommand as i, freezeMongoFieldShape as it, MongoMatchStage as j, MongoLimitStage as k, MongoAggAccumulator as l, MongoAggLiteral as m, DeleteManyCommand as n, UpdateManyCommand as nt, InsertManyCommand as o, isExprArray as ot, MongoAggLet as p, RawAggregateCommand as q, DeleteOneCommand as r, UpdateOneCommand as rt, InsertOneCommand as s, isRecordArgs as st, AggregateCommand as t, RawUpdateOneCommand as tt, MongoAggArrayFilter as u, MongoAggReduce as v, MongoFacetStage as w, MongoBucketStage as x, MongoAggSwitch as y, MongoSearchStage as z };
1268
+
1269
+ //# sourceMappingURL=execution-D5XyZ5XS.mjs.map