@prisma-next/mongo-query-builder 0.0.1

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,51 @@
1
+ export type {
2
+ DeleteResult,
3
+ InsertManyResult,
4
+ InsertOneResult,
5
+ UpdateResult,
6
+ } from '@prisma-next/mongo-query-ast/execution';
7
+ export { acc } from '../accumulator-helpers';
8
+ export { PipelineChain } from '../builder';
9
+ export { fn } from '../expression-helpers';
10
+ export type {
11
+ Expression,
12
+ FieldAccessor,
13
+ LeafExpression,
14
+ ObjectExpression,
15
+ } from '../field-accessor';
16
+ export { createFieldAccessor } from '../field-accessor';
17
+ export type { FindAndModifyEnabled, UpdateEnabled } from '../markers';
18
+ export type { QueryRoot } from '../query';
19
+ export { mongoQuery } from '../query';
20
+ export type {
21
+ ModelNestedShape,
22
+ NestedDocShape,
23
+ ObjectField,
24
+ PathCompletions,
25
+ ResolvePath,
26
+ ValidPaths,
27
+ } from '../resolve-path';
28
+ export { CollectionHandle, FilteredCollection } from '../state-classes';
29
+ export type {
30
+ ArrayField,
31
+ BooleanField,
32
+ DateField,
33
+ DocField,
34
+ DocShape,
35
+ ExtractDocShape,
36
+ GroupedDocShape,
37
+ GroupSpec,
38
+ LiteralValue,
39
+ ModelToDocShape,
40
+ NullableDocField,
41
+ NullableNumericField,
42
+ NumericField,
43
+ ProjectedShape,
44
+ ResolveRow,
45
+ SortSpec,
46
+ StringField,
47
+ TypedAccumulatorExpr,
48
+ TypedAggExpr,
49
+ UnwoundShape,
50
+ } from '../types';
51
+ export type { TypedUpdateOp, UpdaterResult } from '../update-ops';
@@ -0,0 +1,519 @@
1
+ import type { MongoAggExpr } from '@prisma-next/mongo-query-ast/execution';
2
+ import {
3
+ MongoAggCond,
4
+ MongoAggLiteral,
5
+ MongoAggOperator,
6
+ } from '@prisma-next/mongo-query-ast/execution';
7
+ import type {
8
+ ArrayField,
9
+ BooleanField,
10
+ DateField,
11
+ DocField,
12
+ LiteralValue,
13
+ NullableDocField,
14
+ NumericField,
15
+ StringField,
16
+ TypedAggExpr,
17
+ } from './types';
18
+
19
+ // ---------------------------------------------------------------------------
20
+ // Internal factory helpers
21
+ // ---------------------------------------------------------------------------
22
+
23
+ function numericExpr(op: string, args: TypedAggExpr<DocField>[]): TypedAggExpr<NumericField> {
24
+ return {
25
+ _field: { codecId: 'mongo/double@1', nullable: false } as NumericField,
26
+ node: MongoAggOperator.of(
27
+ op,
28
+ args.map((a) => a.node),
29
+ ),
30
+ };
31
+ }
32
+
33
+ function numericUnaryExpr(op: string, arg: TypedAggExpr<DocField>): TypedAggExpr<NumericField> {
34
+ return {
35
+ _field: { codecId: 'mongo/double@1', nullable: false } as NumericField,
36
+ node: MongoAggOperator.of(op, arg.node),
37
+ };
38
+ }
39
+
40
+ function stringExpr(op: string, args: TypedAggExpr<DocField>[]): TypedAggExpr<StringField> {
41
+ return {
42
+ _field: { codecId: 'mongo/string@1', nullable: false } as StringField,
43
+ node: MongoAggOperator.of(
44
+ op,
45
+ args.map((a) => a.node),
46
+ ),
47
+ };
48
+ }
49
+
50
+ function stringUnaryExpr(op: string, arg: TypedAggExpr<DocField>): TypedAggExpr<StringField> {
51
+ return {
52
+ _field: { codecId: 'mongo/string@1', nullable: false } as StringField,
53
+ node: MongoAggOperator.of(op, arg.node),
54
+ };
55
+ }
56
+
57
+ function booleanExpr(op: string, args: TypedAggExpr<DocField>[]): TypedAggExpr<BooleanField> {
58
+ return {
59
+ _field: { codecId: 'mongo/bool@1', nullable: false } as BooleanField,
60
+ node: MongoAggOperator.of(
61
+ op,
62
+ args.map((a) => a.node),
63
+ ),
64
+ };
65
+ }
66
+
67
+ function booleanUnaryExpr(op: string, arg: TypedAggExpr<DocField>): TypedAggExpr<BooleanField> {
68
+ return {
69
+ _field: { codecId: 'mongo/bool@1', nullable: false } as BooleanField,
70
+ node: MongoAggOperator.of(op, arg.node),
71
+ };
72
+ }
73
+
74
+ function dateUnaryExpr(op: string, arg: TypedAggExpr<DocField>): TypedAggExpr<DateField> {
75
+ return {
76
+ _field: { codecId: 'mongo/date@1', nullable: false } as DateField,
77
+ node: MongoAggOperator.of(op, arg.node),
78
+ };
79
+ }
80
+
81
+ function arrayExpr(op: string, args: TypedAggExpr<DocField>[]): TypedAggExpr<ArrayField> {
82
+ return {
83
+ _field: { codecId: 'mongo/array@1', nullable: false } as ArrayField,
84
+ node: MongoAggOperator.of(
85
+ op,
86
+ args.map((a) => a.node),
87
+ ),
88
+ };
89
+ }
90
+
91
+ function arrayUnaryExpr(op: string, arg: TypedAggExpr<DocField>): TypedAggExpr<ArrayField> {
92
+ return {
93
+ _field: { codecId: 'mongo/array@1', nullable: false } as ArrayField,
94
+ node: MongoAggOperator.of(op, arg.node),
95
+ };
96
+ }
97
+
98
+ function docUnaryExpr(op: string, arg: TypedAggExpr<DocField>): TypedAggExpr<DocField> {
99
+ return {
100
+ _field: { codecId: arg._field.codecId, nullable: false },
101
+ node: MongoAggOperator.of(op, arg.node),
102
+ };
103
+ }
104
+
105
+ function namedArgsExpr<F extends DocField>(
106
+ op: string,
107
+ args: Readonly<Record<string, TypedAggExpr<DocField> | undefined>>,
108
+ _field: F,
109
+ ): TypedAggExpr<F> {
110
+ const nodeArgs: Record<string, MongoAggExpr> = {};
111
+ for (const [key, val] of Object.entries(args)) {
112
+ if (val !== undefined) {
113
+ nodeArgs[key] = val.node;
114
+ }
115
+ }
116
+ return { _field, node: MongoAggOperator.of(op, nodeArgs) };
117
+ }
118
+
119
+ const NUMERIC: NumericField = { codecId: 'mongo/double@1', nullable: false } as NumericField;
120
+ const STRING: StringField = { codecId: 'mongo/string@1', nullable: false } as StringField;
121
+ const BOOLEAN: BooleanField = { codecId: 'mongo/bool@1', nullable: false } as BooleanField;
122
+ const DATE: DateField = { codecId: 'mongo/date@1', nullable: false } as DateField;
123
+ const ARRAY: ArrayField = { codecId: 'mongo/array@1', nullable: false } as ArrayField;
124
+ const DOC: DocField = { codecId: 'mongo/document@1', nullable: false };
125
+
126
+ function literal(value: string): TypedAggExpr<StringField>;
127
+ function literal(value: number): TypedAggExpr<NumericField>;
128
+ function literal(value: boolean): TypedAggExpr<BooleanField>;
129
+ function literal(value: Date): TypedAggExpr<DateField>;
130
+ function literal<F extends DocField>(value: LiteralValue<F>): TypedAggExpr<F>;
131
+ function literal(value: unknown): TypedAggExpr<DocField> {
132
+ return { _field: undefined as never, node: MongoAggLiteral.of(value) };
133
+ }
134
+
135
+ // ---------------------------------------------------------------------------
136
+ // Public helpers
137
+ // ---------------------------------------------------------------------------
138
+
139
+ export const fn = {
140
+ // -- Arithmetic (existing) ------------------------------------------------
141
+
142
+ add(...args: TypedAggExpr<DocField>[]): TypedAggExpr<NumericField> {
143
+ return numericExpr('$add', args);
144
+ },
145
+
146
+ subtract(a: TypedAggExpr<DocField>, b: TypedAggExpr<DocField>): TypedAggExpr<NumericField> {
147
+ return numericExpr('$subtract', [a, b]);
148
+ },
149
+
150
+ multiply(...args: TypedAggExpr<DocField>[]): TypedAggExpr<NumericField> {
151
+ return numericExpr('$multiply', args);
152
+ },
153
+
154
+ divide(a: TypedAggExpr<DocField>, b: TypedAggExpr<DocField>): TypedAggExpr<NumericField> {
155
+ return numericExpr('$divide', [a, b]);
156
+ },
157
+
158
+ // -- String (existing) ----------------------------------------------------
159
+
160
+ concat(...args: TypedAggExpr<DocField>[]): TypedAggExpr<StringField> {
161
+ return stringExpr('$concat', args);
162
+ },
163
+
164
+ toLower(a: TypedAggExpr<DocField>): TypedAggExpr<StringField> {
165
+ return stringUnaryExpr('$toLower', a);
166
+ },
167
+
168
+ toUpper(a: TypedAggExpr<DocField>): TypedAggExpr<StringField> {
169
+ return stringUnaryExpr('$toUpper', a);
170
+ },
171
+
172
+ // -- Size (existing) ------------------------------------------------------
173
+
174
+ size(a: TypedAggExpr<DocField>): TypedAggExpr<NumericField> {
175
+ return numericUnaryExpr('$size', a);
176
+ },
177
+
178
+ // -- Control flow (existing) ----------------------------------------------
179
+
180
+ cond<F extends DocField>(
181
+ condition: MongoAggExpr,
182
+ thenExpr: TypedAggExpr<F>,
183
+ elseExpr: TypedAggExpr<DocField>,
184
+ ): TypedAggExpr<F> {
185
+ return {
186
+ _field: thenExpr._field,
187
+ node: new MongoAggCond(condition, thenExpr.node, elseExpr.node),
188
+ };
189
+ },
190
+
191
+ literal,
192
+
193
+ // -- Date helpers ---------------------------------------------------------
194
+
195
+ year(a: TypedAggExpr<DocField>): TypedAggExpr<NumericField> {
196
+ return numericUnaryExpr('$year', a);
197
+ },
198
+ month(a: TypedAggExpr<DocField>): TypedAggExpr<NumericField> {
199
+ return numericUnaryExpr('$month', a);
200
+ },
201
+ dayOfMonth(a: TypedAggExpr<DocField>): TypedAggExpr<NumericField> {
202
+ return numericUnaryExpr('$dayOfMonth', a);
203
+ },
204
+ hour(a: TypedAggExpr<DocField>): TypedAggExpr<NumericField> {
205
+ return numericUnaryExpr('$hour', a);
206
+ },
207
+ minute(a: TypedAggExpr<DocField>): TypedAggExpr<NumericField> {
208
+ return numericUnaryExpr('$minute', a);
209
+ },
210
+ second(a: TypedAggExpr<DocField>): TypedAggExpr<NumericField> {
211
+ return numericUnaryExpr('$second', a);
212
+ },
213
+ millisecond(a: TypedAggExpr<DocField>): TypedAggExpr<NumericField> {
214
+ return numericUnaryExpr('$millisecond', a);
215
+ },
216
+ dateToString(args: {
217
+ date: TypedAggExpr<DateField>;
218
+ format?: TypedAggExpr<StringField>;
219
+ timezone?: TypedAggExpr<StringField>;
220
+ onNull?: TypedAggExpr<DocField>;
221
+ }): TypedAggExpr<StringField> {
222
+ return namedArgsExpr('$dateToString', args, STRING);
223
+ },
224
+ dateFromString(args: {
225
+ dateString: TypedAggExpr<StringField>;
226
+ format?: TypedAggExpr<StringField>;
227
+ timezone?: TypedAggExpr<StringField>;
228
+ onError?: TypedAggExpr<DocField>;
229
+ onNull?: TypedAggExpr<DocField>;
230
+ }): TypedAggExpr<DateField> {
231
+ return namedArgsExpr('$dateFromString', args, DATE);
232
+ },
233
+ dateDiff(args: {
234
+ startDate: TypedAggExpr<DateField>;
235
+ endDate: TypedAggExpr<DateField>;
236
+ unit: TypedAggExpr<StringField>;
237
+ timezone?: TypedAggExpr<StringField>;
238
+ startOfWeek?: TypedAggExpr<StringField>;
239
+ }): TypedAggExpr<NumericField> {
240
+ return namedArgsExpr('$dateDiff', args, NUMERIC);
241
+ },
242
+ dateAdd(args: {
243
+ startDate: TypedAggExpr<DateField>;
244
+ unit: TypedAggExpr<StringField>;
245
+ amount: TypedAggExpr<NumericField>;
246
+ timezone?: TypedAggExpr<StringField>;
247
+ }): TypedAggExpr<DateField> {
248
+ return namedArgsExpr('$dateAdd', args, DATE);
249
+ },
250
+ dateSubtract(args: {
251
+ startDate: TypedAggExpr<DateField>;
252
+ unit: TypedAggExpr<StringField>;
253
+ amount: TypedAggExpr<NumericField>;
254
+ timezone?: TypedAggExpr<StringField>;
255
+ }): TypedAggExpr<DateField> {
256
+ return namedArgsExpr('$dateSubtract', args, DATE);
257
+ },
258
+ dateTrunc(args: {
259
+ date: TypedAggExpr<DateField>;
260
+ unit: TypedAggExpr<StringField>;
261
+ binSize?: TypedAggExpr<NumericField>;
262
+ timezone?: TypedAggExpr<StringField>;
263
+ startOfWeek?: TypedAggExpr<StringField>;
264
+ }): TypedAggExpr<DateField> {
265
+ return namedArgsExpr('$dateTrunc', args, DATE);
266
+ },
267
+
268
+ // -- String helpers -------------------------------------------------------
269
+
270
+ substr(
271
+ str: TypedAggExpr<DocField>,
272
+ start: TypedAggExpr<DocField>,
273
+ length: TypedAggExpr<DocField>,
274
+ ): TypedAggExpr<StringField> {
275
+ return stringExpr('$substr', [str, start, length]);
276
+ },
277
+ substrBytes(
278
+ str: TypedAggExpr<DocField>,
279
+ start: TypedAggExpr<DocField>,
280
+ count: TypedAggExpr<DocField>,
281
+ ): TypedAggExpr<StringField> {
282
+ return stringExpr('$substrBytes', [str, start, count]);
283
+ },
284
+ trim(args: {
285
+ input: TypedAggExpr<StringField>;
286
+ chars?: TypedAggExpr<StringField>;
287
+ }): TypedAggExpr<StringField> {
288
+ return namedArgsExpr('$trim', args, STRING);
289
+ },
290
+ ltrim(args: {
291
+ input: TypedAggExpr<StringField>;
292
+ chars?: TypedAggExpr<StringField>;
293
+ }): TypedAggExpr<StringField> {
294
+ return namedArgsExpr('$ltrim', args, STRING);
295
+ },
296
+ rtrim(args: {
297
+ input: TypedAggExpr<StringField>;
298
+ chars?: TypedAggExpr<StringField>;
299
+ }): TypedAggExpr<StringField> {
300
+ return namedArgsExpr('$rtrim', args, STRING);
301
+ },
302
+ split(str: TypedAggExpr<DocField>, delimiter: TypedAggExpr<DocField>): TypedAggExpr<ArrayField> {
303
+ return arrayExpr('$split', [str, delimiter]);
304
+ },
305
+ strLenCP(a: TypedAggExpr<DocField>): TypedAggExpr<NumericField> {
306
+ return numericUnaryExpr('$strLenCP', a);
307
+ },
308
+ strLenBytes(a: TypedAggExpr<DocField>): TypedAggExpr<NumericField> {
309
+ return numericUnaryExpr('$strLenBytes', a);
310
+ },
311
+ regexMatch(args: {
312
+ input: TypedAggExpr<StringField>;
313
+ regex: TypedAggExpr<StringField>;
314
+ options?: TypedAggExpr<StringField>;
315
+ }): TypedAggExpr<BooleanField> {
316
+ return namedArgsExpr('$regexMatch', args, BOOLEAN);
317
+ },
318
+ regexFind(args: {
319
+ input: TypedAggExpr<StringField>;
320
+ regex: TypedAggExpr<StringField>;
321
+ options?: TypedAggExpr<StringField>;
322
+ }): TypedAggExpr<DocField> {
323
+ return namedArgsExpr('$regexFind', args, DOC);
324
+ },
325
+ regexFindAll(args: {
326
+ input: TypedAggExpr<StringField>;
327
+ regex: TypedAggExpr<StringField>;
328
+ options?: TypedAggExpr<StringField>;
329
+ }): TypedAggExpr<ArrayField> {
330
+ return namedArgsExpr('$regexFindAll', args, ARRAY);
331
+ },
332
+ replaceOne(args: {
333
+ input: TypedAggExpr<StringField>;
334
+ find: TypedAggExpr<StringField>;
335
+ replacement: TypedAggExpr<StringField>;
336
+ }): TypedAggExpr<StringField> {
337
+ return namedArgsExpr('$replaceOne', args, STRING);
338
+ },
339
+ replaceAll(args: {
340
+ input: TypedAggExpr<StringField>;
341
+ find: TypedAggExpr<StringField>;
342
+ replacement: TypedAggExpr<StringField>;
343
+ }): TypedAggExpr<StringField> {
344
+ return namedArgsExpr('$replaceAll', args, STRING);
345
+ },
346
+
347
+ // -- Comparison helpers ---------------------------------------------------
348
+
349
+ cmp(a: TypedAggExpr<DocField>, b: TypedAggExpr<DocField>): TypedAggExpr<NumericField> {
350
+ return numericExpr('$cmp', [a, b]);
351
+ },
352
+ eq(a: TypedAggExpr<DocField>, b: TypedAggExpr<DocField>): TypedAggExpr<BooleanField> {
353
+ return booleanExpr('$eq', [a, b]);
354
+ },
355
+ ne(a: TypedAggExpr<DocField>, b: TypedAggExpr<DocField>): TypedAggExpr<BooleanField> {
356
+ return booleanExpr('$ne', [a, b]);
357
+ },
358
+ gt(a: TypedAggExpr<DocField>, b: TypedAggExpr<DocField>): TypedAggExpr<BooleanField> {
359
+ return booleanExpr('$gt', [a, b]);
360
+ },
361
+ gte(a: TypedAggExpr<DocField>, b: TypedAggExpr<DocField>): TypedAggExpr<BooleanField> {
362
+ return booleanExpr('$gte', [a, b]);
363
+ },
364
+ lt(a: TypedAggExpr<DocField>, b: TypedAggExpr<DocField>): TypedAggExpr<BooleanField> {
365
+ return booleanExpr('$lt', [a, b]);
366
+ },
367
+ lte(a: TypedAggExpr<DocField>, b: TypedAggExpr<DocField>): TypedAggExpr<BooleanField> {
368
+ return booleanExpr('$lte', [a, b]);
369
+ },
370
+
371
+ // -- Array helpers --------------------------------------------------------
372
+
373
+ arrayElemAt(
374
+ arr: TypedAggExpr<DocField>,
375
+ idx: TypedAggExpr<DocField>,
376
+ ): TypedAggExpr<NullableDocField> {
377
+ return {
378
+ _field: { codecId: DOC.codecId, nullable: true },
379
+ node: MongoAggOperator.of('$arrayElemAt', [arr.node, idx.node]),
380
+ };
381
+ },
382
+ concatArrays(...args: TypedAggExpr<DocField>[]): TypedAggExpr<ArrayField> {
383
+ return arrayExpr('$concatArrays', args);
384
+ },
385
+ firstElem(a: TypedAggExpr<DocField>): TypedAggExpr<NullableDocField> {
386
+ return {
387
+ _field: { codecId: DOC.codecId, nullable: true },
388
+ node: MongoAggOperator.of('$first', a.node),
389
+ };
390
+ },
391
+ lastElem(a: TypedAggExpr<DocField>): TypedAggExpr<NullableDocField> {
392
+ return {
393
+ _field: { codecId: DOC.codecId, nullable: true },
394
+ node: MongoAggOperator.of('$last', a.node),
395
+ };
396
+ },
397
+ isIn(elem: TypedAggExpr<DocField>, arr: TypedAggExpr<DocField>): TypedAggExpr<BooleanField> {
398
+ return booleanExpr('$in', [elem, arr]);
399
+ },
400
+ indexOfArray(
401
+ arr: TypedAggExpr<DocField>,
402
+ value: TypedAggExpr<DocField>,
403
+ ...rest: TypedAggExpr<DocField>[]
404
+ ): TypedAggExpr<NumericField> {
405
+ return numericExpr('$indexOfArray', [arr, value, ...rest]);
406
+ },
407
+ isArray(a: TypedAggExpr<DocField>): TypedAggExpr<BooleanField> {
408
+ return booleanUnaryExpr('$isArray', a);
409
+ },
410
+ reverseArray(a: TypedAggExpr<DocField>): TypedAggExpr<ArrayField> {
411
+ return arrayUnaryExpr('$reverseArray', a);
412
+ },
413
+ slice(arr: TypedAggExpr<DocField>, ...rest: TypedAggExpr<DocField>[]): TypedAggExpr<ArrayField> {
414
+ return arrayExpr('$slice', [arr, ...rest]);
415
+ },
416
+ zip(args: {
417
+ inputs: TypedAggExpr<ArrayField>[];
418
+ useLongestLength?: TypedAggExpr<BooleanField>;
419
+ defaults?: TypedAggExpr<ArrayField>;
420
+ }): TypedAggExpr<ArrayField> {
421
+ const nodeArgs: Record<string, MongoAggExpr | ReadonlyArray<MongoAggExpr>> = {
422
+ inputs: args.inputs.map((a) => a.node),
423
+ };
424
+ if (args.useLongestLength) nodeArgs['useLongestLength'] = args.useLongestLength.node;
425
+ if (args.defaults) nodeArgs['defaults'] = args.defaults.node;
426
+ return { _field: ARRAY, node: MongoAggOperator.of('$zip', nodeArgs) };
427
+ },
428
+ range(
429
+ start: TypedAggExpr<DocField>,
430
+ end: TypedAggExpr<DocField>,
431
+ step: TypedAggExpr<DocField>,
432
+ ): TypedAggExpr<ArrayField> {
433
+ return arrayExpr('$range', [start, end, step]);
434
+ },
435
+
436
+ // -- Set helpers ----------------------------------------------------------
437
+
438
+ setUnion(...args: TypedAggExpr<DocField>[]): TypedAggExpr<ArrayField> {
439
+ return arrayExpr('$setUnion', args);
440
+ },
441
+ setIntersection(...args: TypedAggExpr<DocField>[]): TypedAggExpr<ArrayField> {
442
+ return arrayExpr('$setIntersection', args);
443
+ },
444
+ setDifference(a: TypedAggExpr<DocField>, b: TypedAggExpr<DocField>): TypedAggExpr<ArrayField> {
445
+ return arrayExpr('$setDifference', [a, b]);
446
+ },
447
+ setEquals(...args: TypedAggExpr<DocField>[]): TypedAggExpr<BooleanField> {
448
+ return booleanExpr('$setEquals', args);
449
+ },
450
+ setIsSubset(a: TypedAggExpr<DocField>, b: TypedAggExpr<DocField>): TypedAggExpr<BooleanField> {
451
+ return booleanExpr('$setIsSubset', [a, b]);
452
+ },
453
+ anyElementTrue(a: TypedAggExpr<DocField>): TypedAggExpr<BooleanField> {
454
+ return booleanUnaryExpr('$anyElementTrue', a);
455
+ },
456
+ allElementsTrue(a: TypedAggExpr<DocField>): TypedAggExpr<BooleanField> {
457
+ return booleanUnaryExpr('$allElementsTrue', a);
458
+ },
459
+
460
+ // -- Type helpers ---------------------------------------------------------
461
+
462
+ typeOf(a: TypedAggExpr<DocField>): TypedAggExpr<StringField> {
463
+ return stringUnaryExpr('$type', a);
464
+ },
465
+ convert(args: {
466
+ input: TypedAggExpr<DocField>;
467
+ to: TypedAggExpr<StringField | NumericField>;
468
+ onError?: TypedAggExpr<DocField>;
469
+ onNull?: TypedAggExpr<DocField>;
470
+ }): TypedAggExpr<DocField> {
471
+ return namedArgsExpr('$convert', args, DOC);
472
+ },
473
+ toInt(a: TypedAggExpr<DocField>): TypedAggExpr<NumericField> {
474
+ return numericUnaryExpr('$toInt', a);
475
+ },
476
+ toLong(a: TypedAggExpr<DocField>): TypedAggExpr<NumericField> {
477
+ return numericUnaryExpr('$toLong', a);
478
+ },
479
+ toDouble(a: TypedAggExpr<DocField>): TypedAggExpr<NumericField> {
480
+ return numericUnaryExpr('$toDouble', a);
481
+ },
482
+ toDecimal(a: TypedAggExpr<DocField>): TypedAggExpr<NumericField> {
483
+ return numericUnaryExpr('$toDecimal', a);
484
+ },
485
+ toString_(a: TypedAggExpr<DocField>): TypedAggExpr<StringField> {
486
+ return stringUnaryExpr('$toString', a);
487
+ },
488
+ toObjectId(a: TypedAggExpr<DocField>): TypedAggExpr<DocField> {
489
+ return docUnaryExpr('$toObjectId', a);
490
+ },
491
+ toBool(a: TypedAggExpr<DocField>): TypedAggExpr<BooleanField> {
492
+ return booleanUnaryExpr('$toBool', a);
493
+ },
494
+ toDate(a: TypedAggExpr<DocField>): TypedAggExpr<DateField> {
495
+ return dateUnaryExpr('$toDate', a);
496
+ },
497
+
498
+ // -- Object helpers -------------------------------------------------------
499
+
500
+ objectToArray(a: TypedAggExpr<DocField>): TypedAggExpr<ArrayField> {
501
+ return arrayUnaryExpr('$objectToArray', a);
502
+ },
503
+ arrayToObject(a: TypedAggExpr<DocField>): TypedAggExpr<DocField> {
504
+ return { _field: DOC, node: MongoAggOperator.of('$arrayToObject', a.node) };
505
+ },
506
+ getField(args: {
507
+ field: TypedAggExpr<StringField>;
508
+ input?: TypedAggExpr<DocField>;
509
+ }): TypedAggExpr<DocField> {
510
+ return namedArgsExpr('$getField', args, DOC);
511
+ },
512
+ setField(args: {
513
+ field: TypedAggExpr<StringField>;
514
+ input: TypedAggExpr<DocField>;
515
+ value: TypedAggExpr<DocField>;
516
+ }): TypedAggExpr<DocField> {
517
+ return namedArgsExpr('$setField', args, DOC);
518
+ },
519
+ };