@prisma-next/mongo-query-ast 0.0.1 → 0.3.0-dev.147

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.
@@ -0,0 +1,763 @@
1
+ import { Document, MongoValue } from "@prisma-next/mongo-value";
2
+ import { PlanMeta } from "@prisma-next/contract/types";
3
+
4
+ //#region src/ast-node.d.ts
5
+ declare abstract class MongoAstNode {
6
+ abstract readonly kind: string;
7
+ protected freeze(): void;
8
+ }
9
+ //#endregion
10
+ //#region src/filter-expressions.d.ts
11
+ declare abstract class MongoFilterExpression extends MongoAstNode {
12
+ abstract accept<R>(visitor: MongoFilterVisitor<R>): R;
13
+ abstract rewrite(rewriter: MongoFilterRewriter): MongoFilterExpr;
14
+ not(this: MongoFilterExpr): MongoNotExpr;
15
+ }
16
+ declare class MongoFieldFilter extends MongoFilterExpression {
17
+ readonly kind: "field";
18
+ readonly field: string;
19
+ readonly op: string;
20
+ readonly value: MongoValue;
21
+ constructor(field: string, op: string, value: MongoValue);
22
+ static of(field: string, op: string, value: MongoValue): MongoFieldFilter;
23
+ static eq(field: string, value: MongoValue): MongoFieldFilter;
24
+ static neq(field: string, value: MongoValue): MongoFieldFilter;
25
+ static gt(field: string, value: MongoValue): MongoFieldFilter;
26
+ static lt(field: string, value: MongoValue): MongoFieldFilter;
27
+ static gte(field: string, value: MongoValue): MongoFieldFilter;
28
+ static lte(field: string, value: MongoValue): MongoFieldFilter;
29
+ static in(field: string, values: ReadonlyArray<MongoValue>): MongoFieldFilter;
30
+ static isNull(field: string): MongoFieldFilter;
31
+ static isNotNull(field: string): MongoFieldFilter;
32
+ accept<R>(visitor: MongoFilterVisitor<R>): R;
33
+ rewrite(rewriter: MongoFilterRewriter): MongoFilterExpr;
34
+ }
35
+ declare class MongoAndExpr extends MongoFilterExpression {
36
+ readonly kind: "and";
37
+ readonly exprs: ReadonlyArray<MongoFilterExpr>;
38
+ constructor(exprs: ReadonlyArray<MongoFilterExpr>);
39
+ static of(exprs: ReadonlyArray<MongoFilterExpr>): MongoAndExpr;
40
+ accept<R>(visitor: MongoFilterVisitor<R>): R;
41
+ rewrite(rewriter: MongoFilterRewriter): MongoFilterExpr;
42
+ }
43
+ declare class MongoOrExpr extends MongoFilterExpression {
44
+ readonly kind: "or";
45
+ readonly exprs: ReadonlyArray<MongoFilterExpr>;
46
+ constructor(exprs: ReadonlyArray<MongoFilterExpr>);
47
+ static of(exprs: ReadonlyArray<MongoFilterExpr>): MongoOrExpr;
48
+ accept<R>(visitor: MongoFilterVisitor<R>): R;
49
+ rewrite(rewriter: MongoFilterRewriter): MongoFilterExpr;
50
+ }
51
+ declare class MongoNotExpr extends MongoFilterExpression {
52
+ readonly kind: "not";
53
+ readonly expr: MongoFilterExpr;
54
+ constructor(expr: MongoFilterExpr);
55
+ accept<R>(visitor: MongoFilterVisitor<R>): R;
56
+ rewrite(rewriter: MongoFilterRewriter): MongoFilterExpr;
57
+ }
58
+ declare class MongoExistsExpr extends MongoFilterExpression {
59
+ readonly kind: "exists";
60
+ readonly field: string;
61
+ readonly exists: boolean;
62
+ constructor(field: string, exists: boolean);
63
+ static exists(field: string): MongoExistsExpr;
64
+ static notExists(field: string): MongoExistsExpr;
65
+ accept<R>(visitor: MongoFilterVisitor<R>): R;
66
+ rewrite(rewriter: MongoFilterRewriter): MongoFilterExpr;
67
+ }
68
+ declare class MongoExprFilter extends MongoFilterExpression {
69
+ readonly kind: "expr";
70
+ readonly aggExpr: MongoAggExpr;
71
+ constructor(aggExpr: MongoAggExpr);
72
+ static of(aggExpr: MongoAggExpr): MongoExprFilter;
73
+ accept<R>(visitor: MongoFilterVisitor<R>): R;
74
+ rewrite(rewriter: MongoFilterRewriter): MongoFilterExpr;
75
+ }
76
+ type MongoFilterExpr = MongoFieldFilter | MongoAndExpr | MongoOrExpr | MongoNotExpr | MongoExistsExpr | MongoExprFilter;
77
+ //#endregion
78
+ //#region src/stages.d.ts
79
+ type MongoGroupId = null | MongoAggExpr | Readonly<Record<string, MongoAggExpr>>;
80
+ type MongoProjectionValue = 0 | 1 | MongoAggExpr;
81
+ declare abstract class MongoStageNode extends MongoAstNode {
82
+ abstract accept<R>(visitor: MongoStageVisitor<R>): R;
83
+ abstract rewrite(context: MongoStageRewriterContext): MongoPipelineStage;
84
+ }
85
+ declare class MongoMatchStage extends MongoStageNode {
86
+ readonly kind: "match";
87
+ readonly filter: MongoFilterExpr;
88
+ constructor(filter: MongoFilterExpr);
89
+ accept<R>(visitor: MongoStageVisitor<R>): R;
90
+ rewrite(context: MongoStageRewriterContext): MongoPipelineStage;
91
+ }
92
+ declare class MongoProjectStage extends MongoStageNode {
93
+ readonly kind: "project";
94
+ readonly projection: Readonly<Record<string, MongoProjectionValue>>;
95
+ constructor(projection: Record<string, MongoProjectionValue>);
96
+ accept<R>(visitor: MongoStageVisitor<R>): R;
97
+ rewrite(context: MongoStageRewriterContext): MongoPipelineStage;
98
+ }
99
+ declare class MongoSortStage extends MongoStageNode {
100
+ readonly kind: "sort";
101
+ readonly sort: Readonly<Record<string, 1 | -1>>;
102
+ constructor(sort: Record<string, 1 | -1>);
103
+ accept<R>(visitor: MongoStageVisitor<R>): R;
104
+ rewrite(_context: MongoStageRewriterContext): MongoPipelineStage;
105
+ }
106
+ declare class MongoLimitStage extends MongoStageNode {
107
+ readonly kind: "limit";
108
+ readonly limit: number;
109
+ constructor(limit: number);
110
+ accept<R>(visitor: MongoStageVisitor<R>): R;
111
+ rewrite(_context: MongoStageRewriterContext): MongoPipelineStage;
112
+ }
113
+ declare class MongoSkipStage extends MongoStageNode {
114
+ readonly kind: "skip";
115
+ readonly skip: number;
116
+ constructor(skip: number);
117
+ accept<R>(visitor: MongoStageVisitor<R>): R;
118
+ rewrite(_context: MongoStageRewriterContext): MongoPipelineStage;
119
+ }
120
+ declare class MongoLookupStage extends MongoStageNode {
121
+ readonly kind: "lookup";
122
+ readonly from: string;
123
+ readonly localField: string | undefined;
124
+ readonly foreignField: string | undefined;
125
+ readonly as: string;
126
+ readonly pipeline: ReadonlyArray<MongoPipelineStage> | undefined;
127
+ readonly let_: Readonly<Record<string, MongoAggExpr>> | undefined;
128
+ constructor(options: {
129
+ from: string;
130
+ localField?: string;
131
+ foreignField?: string;
132
+ as: string;
133
+ pipeline?: ReadonlyArray<MongoPipelineStage>;
134
+ let_?: Record<string, MongoAggExpr>;
135
+ });
136
+ accept<R>(visitor: MongoStageVisitor<R>): R;
137
+ rewrite(context: MongoStageRewriterContext): MongoPipelineStage;
138
+ }
139
+ declare class MongoUnwindStage extends MongoStageNode {
140
+ readonly kind: "unwind";
141
+ readonly path: string;
142
+ readonly preserveNullAndEmptyArrays: boolean;
143
+ readonly includeArrayIndex: string | undefined;
144
+ constructor(path: string, preserveNullAndEmptyArrays: boolean, includeArrayIndex?: string);
145
+ accept<R>(visitor: MongoStageVisitor<R>): R;
146
+ rewrite(_context: MongoStageRewriterContext): MongoPipelineStage;
147
+ }
148
+ declare class MongoGroupStage extends MongoStageNode {
149
+ readonly kind: "group";
150
+ readonly groupId: MongoGroupId;
151
+ readonly accumulators: Readonly<Record<string, MongoAggAccumulator>>;
152
+ constructor(groupId: MongoGroupId, accumulators: Record<string, MongoAggAccumulator>);
153
+ accept<R>(visitor: MongoStageVisitor<R>): R;
154
+ rewrite(context: MongoStageRewriterContext): MongoPipelineStage;
155
+ }
156
+ declare class MongoAddFieldsStage extends MongoStageNode {
157
+ readonly kind: "addFields";
158
+ readonly fields: Readonly<Record<string, MongoAggExpr>>;
159
+ constructor(fields: Record<string, MongoAggExpr>);
160
+ accept<R>(visitor: MongoStageVisitor<R>): R;
161
+ rewrite(context: MongoStageRewriterContext): MongoPipelineStage;
162
+ }
163
+ declare class MongoReplaceRootStage extends MongoStageNode {
164
+ readonly kind: "replaceRoot";
165
+ readonly newRoot: MongoAggExpr;
166
+ constructor(newRoot: MongoAggExpr);
167
+ accept<R>(visitor: MongoStageVisitor<R>): R;
168
+ rewrite(context: MongoStageRewriterContext): MongoPipelineStage;
169
+ }
170
+ declare class MongoCountStage extends MongoStageNode {
171
+ readonly kind: "count";
172
+ readonly field: string;
173
+ constructor(field: string);
174
+ accept<R>(visitor: MongoStageVisitor<R>): R;
175
+ rewrite(_context: MongoStageRewriterContext): MongoPipelineStage;
176
+ }
177
+ declare class MongoSortByCountStage extends MongoStageNode {
178
+ readonly kind: "sortByCount";
179
+ readonly expr: MongoAggExpr;
180
+ constructor(expr: MongoAggExpr);
181
+ accept<R>(visitor: MongoStageVisitor<R>): R;
182
+ rewrite(context: MongoStageRewriterContext): MongoPipelineStage;
183
+ }
184
+ declare class MongoSampleStage extends MongoStageNode {
185
+ readonly kind: "sample";
186
+ readonly size: number;
187
+ constructor(size: number);
188
+ accept<R>(visitor: MongoStageVisitor<R>): R;
189
+ rewrite(_context: MongoStageRewriterContext): MongoPipelineStage;
190
+ }
191
+ declare class MongoRedactStage extends MongoStageNode {
192
+ readonly kind: "redact";
193
+ readonly expr: MongoAggExpr;
194
+ constructor(expr: MongoAggExpr);
195
+ accept<R>(visitor: MongoStageVisitor<R>): R;
196
+ rewrite(context: MongoStageRewriterContext): MongoPipelineStage;
197
+ }
198
+ declare class MongoOutStage extends MongoStageNode {
199
+ readonly kind: "out";
200
+ readonly collection: string;
201
+ readonly db: string | undefined;
202
+ constructor(collection: string, db?: string);
203
+ accept<R>(visitor: MongoStageVisitor<R>): R;
204
+ rewrite(_context: MongoStageRewriterContext): MongoPipelineStage;
205
+ }
206
+ declare class MongoUnionWithStage extends MongoStageNode {
207
+ readonly kind: "unionWith";
208
+ readonly collection: string;
209
+ readonly pipeline: ReadonlyArray<MongoPipelineStage> | undefined;
210
+ constructor(collection: string, pipeline?: ReadonlyArray<MongoPipelineStage>);
211
+ accept<R>(visitor: MongoStageVisitor<R>): R;
212
+ rewrite(context: MongoStageRewriterContext): MongoPipelineStage;
213
+ }
214
+ declare class MongoBucketStage extends MongoStageNode {
215
+ readonly kind: "bucket";
216
+ readonly groupBy: MongoAggExpr;
217
+ readonly boundaries: ReadonlyArray<unknown>;
218
+ readonly default_: unknown;
219
+ readonly output: Readonly<Record<string, MongoAggAccumulator>> | undefined;
220
+ constructor(options: {
221
+ groupBy: MongoAggExpr;
222
+ boundaries: ReadonlyArray<unknown>;
223
+ default_?: unknown;
224
+ output?: Record<string, MongoAggAccumulator>;
225
+ });
226
+ accept<R>(visitor: MongoStageVisitor<R>): R;
227
+ rewrite(context: MongoStageRewriterContext): MongoPipelineStage;
228
+ }
229
+ declare class MongoBucketAutoStage extends MongoStageNode {
230
+ readonly kind: "bucketAuto";
231
+ readonly groupBy: MongoAggExpr;
232
+ readonly buckets: number;
233
+ readonly output: Readonly<Record<string, MongoAggAccumulator>> | undefined;
234
+ readonly granularity: string | undefined;
235
+ constructor(options: {
236
+ groupBy: MongoAggExpr;
237
+ buckets: number;
238
+ output?: Record<string, MongoAggAccumulator>;
239
+ granularity?: string;
240
+ });
241
+ accept<R>(visitor: MongoStageVisitor<R>): R;
242
+ rewrite(context: MongoStageRewriterContext): MongoPipelineStage;
243
+ }
244
+ declare class MongoGeoNearStage extends MongoStageNode {
245
+ readonly kind: "geoNear";
246
+ readonly near: unknown;
247
+ readonly distanceField: string;
248
+ readonly spherical: boolean | undefined;
249
+ readonly maxDistance: number | undefined;
250
+ readonly minDistance: number | undefined;
251
+ readonly query: MongoFilterExpr | undefined;
252
+ readonly key: string | undefined;
253
+ readonly distanceMultiplier: number | undefined;
254
+ readonly includeLocs: string | undefined;
255
+ constructor(options: {
256
+ near: unknown;
257
+ distanceField: string;
258
+ spherical?: boolean;
259
+ maxDistance?: number;
260
+ minDistance?: number;
261
+ query?: MongoFilterExpr;
262
+ key?: string;
263
+ distanceMultiplier?: number;
264
+ includeLocs?: string;
265
+ });
266
+ accept<R>(visitor: MongoStageVisitor<R>): R;
267
+ rewrite(context: MongoStageRewriterContext): MongoPipelineStage;
268
+ }
269
+ declare class MongoFacetStage extends MongoStageNode {
270
+ readonly kind: "facet";
271
+ readonly facets: Readonly<Record<string, ReadonlyArray<MongoPipelineStage>>>;
272
+ constructor(facets: Record<string, ReadonlyArray<MongoPipelineStage>>);
273
+ accept<R>(visitor: MongoStageVisitor<R>): R;
274
+ rewrite(context: MongoStageRewriterContext): MongoPipelineStage;
275
+ }
276
+ declare class MongoGraphLookupStage extends MongoStageNode {
277
+ readonly kind: "graphLookup";
278
+ readonly from: string;
279
+ readonly startWith: MongoAggExpr;
280
+ readonly connectFromField: string;
281
+ readonly connectToField: string;
282
+ readonly as: string;
283
+ readonly maxDepth: number | undefined;
284
+ readonly depthField: string | undefined;
285
+ readonly restrictSearchWithMatch: MongoFilterExpr | undefined;
286
+ constructor(options: {
287
+ from: string;
288
+ startWith: MongoAggExpr;
289
+ connectFromField: string;
290
+ connectToField: string;
291
+ as: string;
292
+ maxDepth?: number;
293
+ depthField?: string;
294
+ restrictSearchWithMatch?: MongoFilterExpr;
295
+ });
296
+ accept<R>(visitor: MongoStageVisitor<R>): R;
297
+ rewrite(context: MongoStageRewriterContext): MongoPipelineStage;
298
+ }
299
+ declare class MongoMergeStage extends MongoStageNode {
300
+ readonly kind: "merge";
301
+ readonly into: string | {
302
+ readonly db: string;
303
+ readonly coll: string;
304
+ };
305
+ readonly on: string | ReadonlyArray<string> | undefined;
306
+ readonly whenMatched: string | ReadonlyArray<MongoUpdatePipelineStage> | undefined;
307
+ readonly whenNotMatched: string | undefined;
308
+ constructor(options: {
309
+ into: string | {
310
+ db: string;
311
+ coll: string;
312
+ };
313
+ on?: string | ReadonlyArray<string>;
314
+ whenMatched?: string | ReadonlyArray<MongoUpdatePipelineStage>;
315
+ whenNotMatched?: string;
316
+ });
317
+ accept<R>(visitor: MongoStageVisitor<R>): R;
318
+ rewrite(context: MongoStageRewriterContext): MongoPipelineStage;
319
+ }
320
+ interface MongoWindowField {
321
+ readonly operator: MongoAggExpr;
322
+ readonly window?: {
323
+ readonly documents?: readonly [number, number];
324
+ readonly range?: {
325
+ readonly start: unknown;
326
+ readonly end: unknown;
327
+ readonly unit?: string;
328
+ };
329
+ };
330
+ }
331
+ declare class MongoSetWindowFieldsStage extends MongoStageNode {
332
+ readonly kind: "setWindowFields";
333
+ readonly partitionBy: MongoAggExpr | undefined;
334
+ readonly sortBy: Readonly<Record<string, 1 | -1>> | undefined;
335
+ readonly output: Readonly<Record<string, MongoWindowField>>;
336
+ constructor(options: {
337
+ partitionBy?: MongoAggExpr;
338
+ sortBy?: Record<string, 1 | -1>;
339
+ output: Record<string, MongoWindowField>;
340
+ });
341
+ accept<R>(visitor: MongoStageVisitor<R>): R;
342
+ rewrite(context: MongoStageRewriterContext): MongoPipelineStage;
343
+ }
344
+ interface MongoDensifyRange {
345
+ readonly step: number;
346
+ readonly unit?: string;
347
+ readonly bounds: 'full' | 'partition' | readonly [unknown, unknown];
348
+ }
349
+ declare class MongoDensifyStage extends MongoStageNode {
350
+ readonly kind: "densify";
351
+ readonly field: string;
352
+ readonly partitionByFields: ReadonlyArray<string> | undefined;
353
+ readonly range: MongoDensifyRange;
354
+ constructor(options: {
355
+ field: string;
356
+ partitionByFields?: ReadonlyArray<string>;
357
+ range: MongoDensifyRange;
358
+ });
359
+ accept<R>(visitor: MongoStageVisitor<R>): R;
360
+ rewrite(_context: MongoStageRewriterContext): MongoPipelineStage;
361
+ }
362
+ interface MongoFillOutput {
363
+ readonly method?: string;
364
+ readonly value?: MongoAggExpr;
365
+ }
366
+ declare class MongoFillStage extends MongoStageNode {
367
+ readonly kind: "fill";
368
+ readonly partitionBy: MongoAggExpr | undefined;
369
+ readonly partitionByFields: ReadonlyArray<string> | undefined;
370
+ readonly sortBy: Readonly<Record<string, 1 | -1>> | undefined;
371
+ readonly output: Readonly<Record<string, MongoFillOutput>>;
372
+ constructor(options: {
373
+ partitionBy?: MongoAggExpr;
374
+ partitionByFields?: ReadonlyArray<string>;
375
+ sortBy?: Record<string, 1 | -1>;
376
+ output: Record<string, MongoFillOutput>;
377
+ });
378
+ accept<R>(visitor: MongoStageVisitor<R>): R;
379
+ rewrite(context: MongoStageRewriterContext): MongoPipelineStage;
380
+ }
381
+ declare class MongoSearchStage extends MongoStageNode {
382
+ readonly kind: "search";
383
+ readonly index: string | undefined;
384
+ readonly config: Readonly<Record<string, unknown>>;
385
+ constructor(config: Record<string, unknown>, index?: string);
386
+ accept<R>(visitor: MongoStageVisitor<R>): R;
387
+ rewrite(_context: MongoStageRewriterContext): MongoPipelineStage;
388
+ }
389
+ declare class MongoSearchMetaStage extends MongoStageNode {
390
+ readonly kind: "searchMeta";
391
+ readonly index: string | undefined;
392
+ readonly config: Readonly<Record<string, unknown>>;
393
+ constructor(config: Record<string, unknown>, index?: string);
394
+ accept<R>(visitor: MongoStageVisitor<R>): R;
395
+ rewrite(_context: MongoStageRewriterContext): MongoPipelineStage;
396
+ }
397
+ declare class MongoVectorSearchStage extends MongoStageNode {
398
+ readonly kind: "vectorSearch";
399
+ readonly index: string;
400
+ readonly path: string;
401
+ readonly queryVector: ReadonlyArray<number>;
402
+ readonly numCandidates: number;
403
+ readonly limit: number;
404
+ readonly filter: Readonly<Record<string, unknown>> | undefined;
405
+ constructor(options: {
406
+ index: string;
407
+ path: string;
408
+ queryVector: ReadonlyArray<number>;
409
+ numCandidates: number;
410
+ limit: number;
411
+ filter?: Record<string, unknown>;
412
+ });
413
+ accept<R>(visitor: MongoStageVisitor<R>): R;
414
+ rewrite(_context: MongoStageRewriterContext): MongoPipelineStage;
415
+ }
416
+ type MongoUpdatePipelineStage = MongoAddFieldsStage | MongoProjectStage | MongoReplaceRootStage;
417
+ type MongoPipelineStage = MongoMatchStage | MongoProjectStage | MongoSortStage | MongoLimitStage | MongoSkipStage | MongoLookupStage | MongoUnwindStage | MongoGroupStage | MongoAddFieldsStage | MongoReplaceRootStage | MongoCountStage | MongoSortByCountStage | MongoSampleStage | MongoRedactStage | MongoOutStage | MongoUnionWithStage | MongoBucketStage | MongoBucketAutoStage | MongoGeoNearStage | MongoFacetStage | MongoGraphLookupStage | MongoMergeStage | MongoSetWindowFieldsStage | MongoDensifyStage | MongoFillStage | MongoSearchStage | MongoSearchMetaStage | MongoVectorSearchStage;
418
+ //#endregion
419
+ //#region src/visitors.d.ts
420
+ interface MongoAggExprVisitor<R> {
421
+ fieldRef(expr: MongoAggFieldRef): R;
422
+ literal(expr: MongoAggLiteral): R;
423
+ operator(expr: MongoAggOperator): R;
424
+ accumulator(expr: MongoAggAccumulator): R;
425
+ cond(expr: MongoAggCond): R;
426
+ switch_(expr: MongoAggSwitch): R;
427
+ filter(expr: MongoAggArrayFilter): R;
428
+ map(expr: MongoAggMap): R;
429
+ reduce(expr: MongoAggReduce): R;
430
+ let_(expr: MongoAggLet): R;
431
+ mergeObjects(expr: MongoAggMergeObjects): R;
432
+ }
433
+ interface MongoAggExprRewriter {
434
+ fieldRef?(expr: MongoAggFieldRef): MongoAggExpr;
435
+ literal?(expr: MongoAggLiteral): MongoAggExpr;
436
+ operator?(expr: MongoAggOperator): MongoAggExpr;
437
+ accumulator?(expr: MongoAggAccumulator): MongoAggExpr;
438
+ cond?(expr: MongoAggCond): MongoAggExpr;
439
+ switch_?(expr: MongoAggSwitch): MongoAggExpr;
440
+ filter?(expr: MongoAggArrayFilter): MongoAggExpr;
441
+ map?(expr: MongoAggMap): MongoAggExpr;
442
+ reduce?(expr: MongoAggReduce): MongoAggExpr;
443
+ let_?(expr: MongoAggLet): MongoAggExpr;
444
+ mergeObjects?(expr: MongoAggMergeObjects): MongoAggExpr;
445
+ }
446
+ interface MongoFilterVisitor<R> {
447
+ field(expr: MongoFieldFilter): R;
448
+ and(expr: MongoAndExpr): R;
449
+ or(expr: MongoOrExpr): R;
450
+ not(expr: MongoNotExpr): R;
451
+ exists(expr: MongoExistsExpr): R;
452
+ expr(expr: MongoExprFilter): R;
453
+ }
454
+ interface MongoFilterRewriter {
455
+ field?(expr: MongoFieldFilter): MongoFilterExpr;
456
+ and?(expr: MongoAndExpr): MongoFilterExpr;
457
+ or?(expr: MongoOrExpr): MongoFilterExpr;
458
+ not?(expr: MongoNotExpr): MongoFilterExpr;
459
+ exists?(expr: MongoExistsExpr): MongoFilterExpr;
460
+ expr?(expr: MongoExprFilter): MongoFilterExpr;
461
+ }
462
+ interface MongoStageRewriterContext {
463
+ filter?: MongoFilterRewriter;
464
+ aggExpr?: MongoAggExprRewriter;
465
+ }
466
+ interface MongoStageVisitor<R> {
467
+ match(stage: MongoMatchStage): R;
468
+ project(stage: MongoProjectStage): R;
469
+ sort(stage: MongoSortStage): R;
470
+ limit(stage: MongoLimitStage): R;
471
+ skip(stage: MongoSkipStage): R;
472
+ lookup(stage: MongoLookupStage): R;
473
+ unwind(stage: MongoUnwindStage): R;
474
+ group(stage: MongoGroupStage): R;
475
+ addFields(stage: MongoAddFieldsStage): R;
476
+ replaceRoot(stage: MongoReplaceRootStage): R;
477
+ count(stage: MongoCountStage): R;
478
+ sortByCount(stage: MongoSortByCountStage): R;
479
+ sample(stage: MongoSampleStage): R;
480
+ redact(stage: MongoRedactStage): R;
481
+ out(stage: MongoOutStage): R;
482
+ unionWith(stage: MongoUnionWithStage): R;
483
+ bucket(stage: MongoBucketStage): R;
484
+ bucketAuto(stage: MongoBucketAutoStage): R;
485
+ geoNear(stage: MongoGeoNearStage): R;
486
+ facet(stage: MongoFacetStage): R;
487
+ graphLookup(stage: MongoGraphLookupStage): R;
488
+ merge(stage: MongoMergeStage): R;
489
+ setWindowFields(stage: MongoSetWindowFieldsStage): R;
490
+ densify(stage: MongoDensifyStage): R;
491
+ fill(stage: MongoFillStage): R;
492
+ search(stage: MongoSearchStage): R;
493
+ searchMeta(stage: MongoSearchMetaStage): R;
494
+ vectorSearch(stage: MongoVectorSearchStage): R;
495
+ }
496
+ //#endregion
497
+ //#region src/aggregation-expressions.d.ts
498
+ type AggRecordArgs = Readonly<Record<string, MongoAggExpr | ReadonlyArray<MongoAggExpr>>>;
499
+ declare function isExprArray(args: MongoAggExpr | ReadonlyArray<MongoAggExpr> | AggRecordArgs): args is ReadonlyArray<MongoAggExpr>;
500
+ declare function isRecordArgs(args: MongoAggExpr | ReadonlyArray<MongoAggExpr> | AggRecordArgs): args is AggRecordArgs;
501
+ declare abstract class MongoAggExprNode extends MongoAstNode {
502
+ abstract accept<R>(visitor: MongoAggExprVisitor<R>): R;
503
+ abstract rewrite(rewriter: MongoAggExprRewriter): MongoAggExpr;
504
+ }
505
+ declare class MongoAggFieldRef extends MongoAggExprNode {
506
+ readonly kind: "fieldRef";
507
+ readonly path: string;
508
+ constructor(path: string);
509
+ static of(path: string): MongoAggFieldRef;
510
+ accept<R>(visitor: MongoAggExprVisitor<R>): R;
511
+ rewrite(rewriter: MongoAggExprRewriter): MongoAggExpr;
512
+ }
513
+ declare class MongoAggLiteral extends MongoAggExprNode {
514
+ readonly kind: "literal";
515
+ readonly value: unknown;
516
+ constructor(value: unknown);
517
+ static of(value: unknown): MongoAggLiteral;
518
+ accept<R>(visitor: MongoAggExprVisitor<R>): R;
519
+ rewrite(rewriter: MongoAggExprRewriter): MongoAggExpr;
520
+ }
521
+ declare class MongoAggOperator extends MongoAggExprNode {
522
+ readonly kind: "operator";
523
+ readonly op: string;
524
+ readonly args: MongoAggExpr | ReadonlyArray<MongoAggExpr> | AggRecordArgs;
525
+ constructor(op: string, args: MongoAggExpr | ReadonlyArray<MongoAggExpr> | AggRecordArgs);
526
+ static of(op: string, args: MongoAggExpr | ReadonlyArray<MongoAggExpr> | AggRecordArgs): MongoAggOperator;
527
+ static add(...args: ReadonlyArray<MongoAggExpr>): MongoAggOperator;
528
+ static subtract(left: MongoAggExpr, right: MongoAggExpr): MongoAggOperator;
529
+ static multiply(...args: ReadonlyArray<MongoAggExpr>): MongoAggOperator;
530
+ static divide(dividend: MongoAggExpr, divisor: MongoAggExpr): MongoAggOperator;
531
+ static concat(...args: ReadonlyArray<MongoAggExpr>): MongoAggOperator;
532
+ static toLower(expr: MongoAggExpr): MongoAggOperator;
533
+ static toUpper(expr: MongoAggExpr): MongoAggOperator;
534
+ static size(expr: MongoAggExpr): MongoAggOperator;
535
+ accept<R>(visitor: MongoAggExprVisitor<R>): R;
536
+ rewrite(rewriter: MongoAggExprRewriter): MongoAggExpr;
537
+ }
538
+ declare class MongoAggAccumulator extends MongoAggExprNode {
539
+ readonly kind: "accumulator";
540
+ readonly op: string;
541
+ readonly arg: MongoAggExpr | AggRecordArgs | null;
542
+ constructor(op: string, arg: MongoAggExpr | AggRecordArgs | null);
543
+ static of(op: string, arg: MongoAggExpr | AggRecordArgs | null): MongoAggAccumulator;
544
+ static sum(expr: MongoAggExpr): MongoAggAccumulator;
545
+ static avg(expr: MongoAggExpr): MongoAggAccumulator;
546
+ static min(expr: MongoAggExpr): MongoAggAccumulator;
547
+ static max(expr: MongoAggExpr): MongoAggAccumulator;
548
+ static first(expr: MongoAggExpr): MongoAggAccumulator;
549
+ static last(expr: MongoAggExpr): MongoAggAccumulator;
550
+ static push(expr: MongoAggExpr): MongoAggAccumulator;
551
+ static addToSet(expr: MongoAggExpr): MongoAggAccumulator;
552
+ static count(): MongoAggAccumulator;
553
+ static stdDevPop(expr: MongoAggExpr): MongoAggAccumulator;
554
+ static stdDevSamp(expr: MongoAggExpr): MongoAggAccumulator;
555
+ accept<R>(visitor: MongoAggExprVisitor<R>): R;
556
+ rewrite(rewriter: MongoAggExprRewriter): MongoAggExpr;
557
+ }
558
+ declare class MongoAggCond extends MongoAggExprNode {
559
+ readonly kind: "cond";
560
+ readonly condition: MongoAggExpr;
561
+ readonly then_: MongoAggExpr;
562
+ readonly else_: MongoAggExpr;
563
+ constructor(condition: MongoAggExpr, then_: MongoAggExpr, else_: MongoAggExpr);
564
+ static of(condition: MongoAggExpr, then_: MongoAggExpr, else_: MongoAggExpr): MongoAggCond;
565
+ accept<R>(visitor: MongoAggExprVisitor<R>): R;
566
+ rewrite(rewriter: MongoAggExprRewriter): MongoAggExpr;
567
+ }
568
+ interface MongoAggSwitchBranch {
569
+ readonly case_: MongoAggExpr;
570
+ readonly then_: MongoAggExpr;
571
+ }
572
+ declare class MongoAggSwitch extends MongoAggExprNode {
573
+ readonly kind: "switch";
574
+ readonly branches: ReadonlyArray<MongoAggSwitchBranch>;
575
+ readonly default_: MongoAggExpr;
576
+ constructor(branches: ReadonlyArray<MongoAggSwitchBranch>, default_: MongoAggExpr);
577
+ static of(branches: ReadonlyArray<MongoAggSwitchBranch>, default_: MongoAggExpr): MongoAggSwitch;
578
+ accept<R>(visitor: MongoAggExprVisitor<R>): R;
579
+ rewrite(rewriter: MongoAggExprRewriter): MongoAggExpr;
580
+ }
581
+ declare class MongoAggArrayFilter extends MongoAggExprNode {
582
+ readonly kind: "filter";
583
+ readonly input: MongoAggExpr;
584
+ readonly cond: MongoAggExpr;
585
+ readonly as: string;
586
+ constructor(input: MongoAggExpr, cond: MongoAggExpr, as: string);
587
+ static of(input: MongoAggExpr, cond: MongoAggExpr, as: string): MongoAggArrayFilter;
588
+ accept<R>(visitor: MongoAggExprVisitor<R>): R;
589
+ rewrite(rewriter: MongoAggExprRewriter): MongoAggExpr;
590
+ }
591
+ declare class MongoAggMap extends MongoAggExprNode {
592
+ readonly kind: "map";
593
+ readonly input: MongoAggExpr;
594
+ readonly in_: MongoAggExpr;
595
+ readonly as: string;
596
+ constructor(input: MongoAggExpr, in_: MongoAggExpr, as: string);
597
+ static of(input: MongoAggExpr, in_: MongoAggExpr, as: string): MongoAggMap;
598
+ accept<R>(visitor: MongoAggExprVisitor<R>): R;
599
+ rewrite(rewriter: MongoAggExprRewriter): MongoAggExpr;
600
+ }
601
+ declare class MongoAggReduce extends MongoAggExprNode {
602
+ readonly kind: "reduce";
603
+ readonly input: MongoAggExpr;
604
+ readonly initialValue: MongoAggExpr;
605
+ readonly in_: MongoAggExpr;
606
+ constructor(input: MongoAggExpr, initialValue: MongoAggExpr, in_: MongoAggExpr);
607
+ static of(input: MongoAggExpr, initialValue: MongoAggExpr, in_: MongoAggExpr): MongoAggReduce;
608
+ accept<R>(visitor: MongoAggExprVisitor<R>): R;
609
+ rewrite(rewriter: MongoAggExprRewriter): MongoAggExpr;
610
+ }
611
+ declare class MongoAggLet extends MongoAggExprNode {
612
+ readonly kind: "let";
613
+ readonly vars: Readonly<Record<string, MongoAggExpr>>;
614
+ readonly in_: MongoAggExpr;
615
+ constructor(vars: Record<string, MongoAggExpr>, in_: MongoAggExpr);
616
+ static of(vars: Record<string, MongoAggExpr>, in_: MongoAggExpr): MongoAggLet;
617
+ accept<R>(visitor: MongoAggExprVisitor<R>): R;
618
+ rewrite(rewriter: MongoAggExprRewriter): MongoAggExpr;
619
+ }
620
+ declare class MongoAggMergeObjects extends MongoAggExprNode {
621
+ readonly kind: "mergeObjects";
622
+ readonly exprs: ReadonlyArray<MongoAggExpr>;
623
+ constructor(exprs: ReadonlyArray<MongoAggExpr>);
624
+ static of(exprs: ReadonlyArray<MongoAggExpr>): MongoAggMergeObjects;
625
+ accept<R>(visitor: MongoAggExprVisitor<R>): R;
626
+ rewrite(rewriter: MongoAggExprRewriter): MongoAggExpr;
627
+ }
628
+ type MongoAggExpr = MongoAggFieldRef | MongoAggLiteral | MongoAggOperator | MongoAggAccumulator | MongoAggCond | MongoAggSwitch | MongoAggArrayFilter | MongoAggMap | MongoAggReduce | MongoAggLet | MongoAggMergeObjects;
629
+ //#endregion
630
+ //#region src/raw-commands.d.ts
631
+ declare class RawAggregateCommand extends MongoAstNode {
632
+ readonly kind: "rawAggregate";
633
+ readonly collection: string;
634
+ readonly pipeline: ReadonlyArray<Document>;
635
+ constructor(collection: string, pipeline: ReadonlyArray<Document>);
636
+ }
637
+ declare class RawInsertOneCommand extends MongoAstNode {
638
+ readonly kind: "rawInsertOne";
639
+ readonly collection: string;
640
+ readonly document: Document;
641
+ constructor(collection: string, document: Document);
642
+ }
643
+ declare class RawInsertManyCommand extends MongoAstNode {
644
+ readonly kind: "rawInsertMany";
645
+ readonly collection: string;
646
+ readonly documents: ReadonlyArray<Document>;
647
+ constructor(collection: string, documents: ReadonlyArray<Document>);
648
+ }
649
+ declare class RawUpdateOneCommand extends MongoAstNode {
650
+ readonly kind: "rawUpdateOne";
651
+ readonly collection: string;
652
+ readonly filter: Document;
653
+ readonly update: Document | ReadonlyArray<Document>;
654
+ constructor(collection: string, filter: Document, update: Document | ReadonlyArray<Document>);
655
+ }
656
+ declare class RawUpdateManyCommand extends MongoAstNode {
657
+ readonly kind: "rawUpdateMany";
658
+ readonly collection: string;
659
+ readonly filter: Document;
660
+ readonly update: Document | ReadonlyArray<Document>;
661
+ constructor(collection: string, filter: Document, update: Document | ReadonlyArray<Document>);
662
+ }
663
+ declare class RawDeleteOneCommand extends MongoAstNode {
664
+ readonly kind: "rawDeleteOne";
665
+ readonly collection: string;
666
+ readonly filter: Document;
667
+ constructor(collection: string, filter: Document);
668
+ }
669
+ declare class RawDeleteManyCommand extends MongoAstNode {
670
+ readonly kind: "rawDeleteMany";
671
+ readonly collection: string;
672
+ readonly filter: Document;
673
+ constructor(collection: string, filter: Document);
674
+ }
675
+ declare class RawFindOneAndUpdateCommand extends MongoAstNode {
676
+ readonly kind: "rawFindOneAndUpdate";
677
+ readonly collection: string;
678
+ readonly filter: Document;
679
+ readonly update: Document | ReadonlyArray<Document>;
680
+ readonly upsert: boolean;
681
+ constructor(collection: string, filter: Document, update: Document | ReadonlyArray<Document>, upsert: boolean);
682
+ }
683
+ declare class RawFindOneAndDeleteCommand extends MongoAstNode {
684
+ readonly kind: "rawFindOneAndDelete";
685
+ readonly collection: string;
686
+ readonly filter: Document;
687
+ constructor(collection: string, filter: Document);
688
+ }
689
+ type RawMongoCommand = RawAggregateCommand | RawInsertOneCommand | RawInsertManyCommand | RawUpdateOneCommand | RawUpdateManyCommand | RawDeleteOneCommand | RawDeleteManyCommand | RawFindOneAndUpdateCommand | RawFindOneAndDeleteCommand;
690
+ //#endregion
691
+ //#region src/commands.d.ts
692
+ type MongoUpdateSpec = Record<string, MongoValue> | ReadonlyArray<MongoUpdatePipelineStage>;
693
+ declare class InsertOneCommand extends MongoAstNode {
694
+ readonly kind: "insertOne";
695
+ readonly collection: string;
696
+ readonly document: Record<string, MongoValue>;
697
+ constructor(collection: string, document: Record<string, MongoValue>);
698
+ }
699
+ declare class UpdateOneCommand extends MongoAstNode {
700
+ readonly kind: "updateOne";
701
+ readonly collection: string;
702
+ readonly filter: MongoFilterExpr;
703
+ readonly update: MongoUpdateSpec;
704
+ constructor(collection: string, filter: MongoFilterExpr, update: MongoUpdateSpec);
705
+ }
706
+ declare class DeleteOneCommand extends MongoAstNode {
707
+ readonly kind: "deleteOne";
708
+ readonly collection: string;
709
+ readonly filter: MongoFilterExpr;
710
+ constructor(collection: string, filter: MongoFilterExpr);
711
+ }
712
+ declare class InsertManyCommand extends MongoAstNode {
713
+ readonly kind: "insertMany";
714
+ readonly collection: string;
715
+ readonly documents: ReadonlyArray<Record<string, MongoValue>>;
716
+ constructor(collection: string, documents: ReadonlyArray<Record<string, MongoValue>>);
717
+ }
718
+ declare class UpdateManyCommand extends MongoAstNode {
719
+ readonly kind: "updateMany";
720
+ readonly collection: string;
721
+ readonly filter: MongoFilterExpr;
722
+ readonly update: MongoUpdateSpec;
723
+ constructor(collection: string, filter: MongoFilterExpr, update: MongoUpdateSpec);
724
+ }
725
+ declare class DeleteManyCommand extends MongoAstNode {
726
+ readonly kind: "deleteMany";
727
+ readonly collection: string;
728
+ readonly filter: MongoFilterExpr;
729
+ constructor(collection: string, filter: MongoFilterExpr);
730
+ }
731
+ declare class FindOneAndUpdateCommand extends MongoAstNode {
732
+ readonly kind: "findOneAndUpdate";
733
+ readonly collection: string;
734
+ readonly filter: MongoFilterExpr;
735
+ readonly update: MongoUpdateSpec;
736
+ readonly upsert: boolean;
737
+ constructor(collection: string, filter: MongoFilterExpr, update: MongoUpdateSpec, upsert: boolean);
738
+ }
739
+ declare class FindOneAndDeleteCommand extends MongoAstNode {
740
+ readonly kind: "findOneAndDelete";
741
+ readonly collection: string;
742
+ readonly filter: MongoFilterExpr;
743
+ constructor(collection: string, filter: MongoFilterExpr);
744
+ }
745
+ declare class AggregateCommand extends MongoAstNode {
746
+ readonly kind: "aggregate";
747
+ readonly collection: string;
748
+ readonly pipeline: ReadonlyArray<MongoPipelineStage>;
749
+ constructor(collection: string, pipeline: ReadonlyArray<MongoPipelineStage>);
750
+ }
751
+ type AnyMongoCommand = InsertOneCommand | InsertManyCommand | UpdateOneCommand | UpdateManyCommand | DeleteOneCommand | DeleteManyCommand | FindOneAndUpdateCommand | FindOneAndDeleteCommand | AggregateCommand | RawMongoCommand;
752
+ //#endregion
753
+ //#region src/query-plan.d.ts
754
+ declare const __mongoQueryPlanRow: unique symbol;
755
+ interface MongoQueryPlan<Row = unknown> {
756
+ readonly collection: string;
757
+ readonly command: AnyMongoCommand;
758
+ readonly meta: PlanMeta;
759
+ readonly [__mongoQueryPlanRow]?: Row;
760
+ }
761
+ //#endregion
762
+ export { type AggRecordArgs, AggregateCommand, type AnyMongoCommand, DeleteManyCommand, DeleteOneCommand, FindOneAndDeleteCommand, FindOneAndUpdateCommand, InsertManyCommand, InsertOneCommand, MongoAddFieldsStage, MongoAggAccumulator, MongoAggArrayFilter, MongoAggCond, type MongoAggExpr, type MongoAggExprRewriter, type MongoAggExprVisitor, MongoAggFieldRef, MongoAggLet, MongoAggLiteral, MongoAggMap, MongoAggMergeObjects, MongoAggOperator, MongoAggReduce, MongoAggSwitch, type MongoAggSwitchBranch, MongoAndExpr, MongoBucketAutoStage, MongoBucketStage, MongoCountStage, type MongoDensifyRange, MongoDensifyStage, MongoExistsExpr, MongoExprFilter, MongoFacetStage, MongoFieldFilter, type MongoFillOutput, MongoFillStage, type MongoFilterExpr, type MongoFilterRewriter, type MongoFilterVisitor, MongoGeoNearStage, MongoGraphLookupStage, type MongoGroupId, MongoGroupStage, MongoLimitStage, MongoLookupStage, MongoMatchStage, MongoMergeStage, MongoNotExpr, MongoOrExpr, MongoOutStage, type MongoPipelineStage, MongoProjectStage, type MongoProjectionValue, type MongoQueryPlan, MongoRedactStage, MongoReplaceRootStage, MongoSampleStage, MongoSearchMetaStage, MongoSearchStage, MongoSetWindowFieldsStage, MongoSkipStage, MongoSortByCountStage, MongoSortStage, type MongoStageRewriterContext, type MongoStageVisitor, MongoUnionWithStage, MongoUnwindStage, type MongoUpdatePipelineStage, type MongoUpdateSpec, MongoVectorSearchStage, type MongoWindowField, RawAggregateCommand, RawDeleteManyCommand, RawDeleteOneCommand, RawFindOneAndDeleteCommand, RawFindOneAndUpdateCommand, RawInsertManyCommand, RawInsertOneCommand, type RawMongoCommand, RawUpdateManyCommand, RawUpdateOneCommand, UpdateManyCommand, UpdateOneCommand, isExprArray, isRecordArgs };
763
+ //# sourceMappingURL=index.d.mts.map