Skip to content

Commit b968371

Browse files
committed
add stage tests
1 parent 3aa4977 commit b968371

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+4297
-21
lines changed

packages/mql-typescript/out/schema-export.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/mql-typescript/out/schema.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ type AlternativeType<T> =
1111
T extends ReadonlyArray<infer U> ? T | RegExpOrString<U> : RegExpOrString<T>;
1212
type RegExpOrString<T> = T extends string ? Regex | T : T;
1313
type KeysOfAType<T, Type> = {
14-
[k in keyof T]: NonNullable<T[k]> extends Type ? k : never;
14+
[k in keyof T]: Extract<T[k], Type> extends never ? never : k;
1515
}[keyof T];
1616
type RecordWithStaticFields<T extends Record<string, any>, TValue> = T & {
1717
[key: string]: TValue | T[keyof T];
@@ -4944,7 +4944,7 @@ export namespace Aggregation.Stage {
49444944
* The pipeline cannot include the $out stage or the $merge stage. Starting in v6.0, the pipeline can contain the Atlas Search $search stage as the first stage inside the pipeline.
49454945
* The pipeline cannot directly access the joined document fields. Instead, define variables for the joined document fields using the let option and then reference the variables in the pipeline stages.
49464946
*/
4947-
pipeline?: Pipeline<S>;
4947+
pipeline?: UntypedPipeline;
49484948

49494949
/**
49504950
* Specifies the name of the new array field to add to the input documents. The new array field contains the matching documents from the from collection. If the specified name already exists in the input document, the existing field is overwritten.
@@ -4994,7 +4994,7 @@ export namespace Aggregation.Stage {
49944994
/**
49954995
* The behavior of $merge if a result document and an existing document in the collection have the same value for the specified on field(s).
49964996
*/
4997-
whenMatched?: WhenMatched | Pipeline<S>;
4997+
whenMatched?: WhenMatched | UntypedPipeline;
49984998

49994999
/**
50005000
* The behavior of $merge if a result document does not match an existing document in the out collection.
@@ -5036,7 +5036,9 @@ export namespace Aggregation.Stage {
50365036
* Reshapes each document in the stream, such as by adding new fields or removing existing fields. For each input document, outputs one document.
50375037
* @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/project/}
50385038
*/
5039-
$project: {} & { [specification: string]: Expression<S> };
5039+
$project: {} & {
5040+
[specification: string]: Expression<S> | ExpressionMap<S>;
5041+
};
50405042
}
50415043

50425044
/**
@@ -5292,7 +5294,7 @@ export namespace Aggregation.Stage {
52925294
* An aggregation pipeline to apply to the specified coll.
52935295
* The pipeline cannot include the $out and $merge stages. Starting in v6.0, the pipeline can contain the Atlas Search $search stage as the first stage inside the pipeline.
52945296
*/
5295-
pipeline?: Pipeline<S>;
5297+
pipeline?: UntypedPipeline;
52965298
};
52975299
}
52985300

@@ -5452,7 +5454,9 @@ export type Expression<S> =
54525454
| BsonPrimitive
54535455
| FieldExpression<S>
54545456
| FieldPath<S>[];
5455-
export type ExpressionMap<S> = { [k: string]: Expression<S> };
5457+
export type ExpressionMap<S> = {
5458+
[k: string]: Expression<S> | ExpressionMap<S>;
5459+
};
54565460
export type Stage<S> =
54575461
| StageOperator<S>
54585462
| Aggregation.Stage.$addFields<S>
@@ -5499,6 +5503,7 @@ export type Stage<S> =
54995503
| Aggregation.Stage.$unwind<S>
55005504
| Aggregation.Stage.$vectorSearch<S>;
55015505
export type Pipeline<S> = Stage<S>[];
5506+
export type UntypedPipeline = Pipeline<any>;
55025507
export type Query<S> =
55035508
| QueryOperator<S>
55045509
| Partial<{ [k in keyof S]: Condition<S[k]> }>

packages/mql-typescript/src/driverSchema/static-schemas.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1619,6 +1619,9 @@ const staticSchemas: SchemaMap = {
16191619
searchMeta: mflixMoviesSchema,
16201620
shardedDataDistribution: dummySchema,
16211621
skip: dummySchema,
1622+
vectorSearch: {
1623+
'ANN Filter': mflixMoviesSchema,
1624+
},
16221625
},
16231626
};
16241627

packages/mql-typescript/src/metaschema.ts

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/mql-typescript/src/schema-generator.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,12 @@ export class SchemaGenerator extends GeneratorBase {
119119
'FieldExpression<S>',
120120
'FieldPath<S>[]',
121121
],
122-
expressionMap_S: [`{ [k: string]: ${this.toTypeName('Expression<S>')} }`],
122+
expressionMap_S: [
123+
`{ [k: string]: ${this.toTypeName('Expression<S>')} | ${this.toTypeName('ExpressionMap<S>')} }`,
124+
],
123125
stage_S: [this.toTypeName('StageOperator<S>')],
124126
pipeline_S: [this.toTypeName('stage<S>[]')],
127+
untypedPipeline: [this.toTypeName('Pipeline<any>')],
125128
query_S: [
126129
this.toTypeName('QueryOperator<S>'),
127130
'Partial<{ [k in keyof S]: Condition<S[k]> }>',
@@ -266,8 +269,8 @@ export class SchemaGenerator extends GeneratorBase {
266269
T extends ReadonlyArray<infer U> ? T | RegExpOrString<U> : RegExpOrString<T>;
267270
type RegExpOrString<T> = T extends string ? Regex | T : T;
268271
type KeysOfAType<T, Type> = {
269-
[k in keyof T]: NonNullable<T[k]> extends Type ? k : never;
270-
}[keyof T];
272+
[k in keyof T]: Extract<T[k], Type> extends never ? never : k;
273+
}[keyof T]
271274
type RecordWithStaticFields<T extends Record<string, any>, TValue> = T & {
272275
[key: string]: TValue | T[keyof T];
273276
};
@@ -293,6 +296,7 @@ export class SchemaGenerator extends GeneratorBase {
293296

294297
if (this.typeMappings[`${type}_S`]) {
295298
let genericArg = 'S';
299+
296300
if (syntheticVariables) {
297301
// If we have synthetic variables for this argument, we need to construct a temporary type and merge it with S
298302
const syntheticFields = syntheticVariables

packages/mql-typescript/src/testGenerator/test-generator.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -183,16 +183,6 @@ export class TestGenerator extends GeneratorBase {
183183

184184
protected override async generateImpl(yamlFiles: YamlFiles): Promise<void> {
185185
for await (const file of yamlFiles) {
186-
if (
187-
file.category !== 'query' &&
188-
file.category !== 'expression' &&
189-
file.category !== 'accumulator' &&
190-
file.category !== 'search'
191-
) {
192-
// TODO: enable for others
193-
continue;
194-
}
195-
196186
const namespace = `${capitalize(file.category)}Operators`;
197187

198188
const basePath = path.resolve(

packages/mql-typescript/src/testGenerator/unsupported-aggregations.ts

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,4 +179,90 @@ export const unsupportedAggregations: {
179179
},
180180
},
181181
},
182+
stage: {
183+
addFields: {
184+
'Using Two $addFields Stages': {
185+
stage: 1,
186+
},
187+
},
188+
bucket: {
189+
'Bucket by Year and Filter by Bucket Results': {
190+
stage: 1,
191+
comment:
192+
'the output field of the $bucket stage generates new fields that are not available statically',
193+
},
194+
},
195+
currentOp: {
196+
'Inactive Sessions': {
197+
stage: 1,
198+
comment:
199+
'$currentOp emits new fields that are not available statically',
200+
},
201+
'Sampled Queries': {
202+
stage: 1,
203+
comment:
204+
'$currentOp emits new fields that are not available statically',
205+
},
206+
},
207+
group: {
208+
'Group by Item Having': {
209+
stage: 1,
210+
},
211+
'Group Documents by author': {
212+
stage: 1,
213+
},
214+
},
215+
planCacheStats: {
216+
'Find Cache Entry Details for a Query Hash': {
217+
stage: 1,
218+
comment:
219+
'$planCacheStats emits new fields that are not available statically',
220+
},
221+
},
222+
replaceRoot: {
223+
'with a Document Nested in an Array': {
224+
stage: 1,
225+
comment: nestedFieldsExplanation,
226+
},
227+
},
228+
replaceWith: {
229+
'a Document Nested in an Array': {
230+
stage: 1,
231+
comment: nestedFieldsExplanation,
232+
},
233+
},
234+
search: {
235+
Example: {
236+
stage: 3,
237+
comment:
238+
'$search emits new fields that are not available statically, such as $$SEARCH_META',
239+
},
240+
'Number Search and Sort': {
241+
stage: 0,
242+
comment: nestedFieldsExplanation,
243+
},
244+
'Return Stored Source Fields': {
245+
stage: 1,
246+
comment: nestedFieldsExplanation,
247+
},
248+
},
249+
set: {
250+
'Using Two $set Stages': {
251+
stage: 1,
252+
comment: 'second $set stage references fields created in the first',
253+
},
254+
},
255+
unset: {
256+
'Remove Embedded Fields': {
257+
stage: 0,
258+
comment: nestedFieldsExplanation,
259+
},
260+
},
261+
unwind: {
262+
'Unwind Embedded Arrays': {
263+
stage: 1,
264+
comment: nestedFieldsExplanation,
265+
},
266+
},
267+
},
182268
};

packages/mql-typescript/tests/stage/addFields.spec.ts

Lines changed: 89 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)