Skip to content

Commit 3932406

Browse files
committed
add schemas for first/last
1 parent 9859784 commit 3932406

File tree

6 files changed

+36
-18
lines changed

6 files changed

+36
-18
lines changed

packages/mql-typescript/src/driverSchema/staticSchemas.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,6 +1468,22 @@ const staticSchemas: SchemaMap = {
14681468
},
14691469
},
14701470
},
1471+
first: {
1472+
collectionName: 'collection',
1473+
schema: {
1474+
items: {
1475+
types: [{ bsonType: 'Array', types: [{ bsonType: 'String' }] }],
1476+
},
1477+
},
1478+
},
1479+
last: {
1480+
collectionName: 'collection',
1481+
schema: {
1482+
items: {
1483+
types: [{ bsonType: 'Array', types: [{ bsonType: 'String' }] }],
1484+
},
1485+
},
1486+
},
14711487
},
14721488
query: {
14731489
and: inventorySchema,

packages/mql-typescript/src/schemaGenerator.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,7 @@ export class SchemaGenerator extends GeneratorBase {
464464
mergedArgs.push(arg);
465465
continue;
466466
}
467+
467468
if (arg.description) {
468469
this.emitComment(arg.description);
469470
}
@@ -555,11 +556,7 @@ export class SchemaGenerator extends GeneratorBase {
555556
this.emit(
556557
`\nexport type ${this.toTypeName(name)}${
557558
isTemplated ? '<S>' : ''
558-
} = |` +
559-
[...new Set(interfaces)]
560-
.map((i) => `(${i}${i.endsWith('_S') ? '<S>' : ''})`)
561-
.join('|') +
562-
';',
559+
} = ${[...new Set(interfaces)].join('|')};`,
563560
);
564561
}
565562
}

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

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,6 @@ export class TestGenerator extends GeneratorBase {
131131
operator: string,
132132
test: TestType,
133133
): Promise<void> {
134-
if (!test.link) {
135-
this.emit(
136-
`// TODO: No docs reference found for ${operator}.${test.name}\n`,
137-
);
138-
return;
139-
}
140-
141134
if (!test.pipeline) {
142135
this.emit(`// TODO: No pipeline found for ${operator}.${test.name}\n`);
143136
return;
@@ -189,9 +182,9 @@ export class TestGenerator extends GeneratorBase {
189182
protected override async generateImpl(yamlFiles: YamlFiles): Promise<void> {
190183
for await (const file of yamlFiles) {
191184
if (
192-
// file.category !== 'query' &&
193-
// file.category !== 'expression' &&
194-
// file.category !== 'accumulator' &&
185+
file.category !== 'query' &&
186+
file.category !== 'expression' &&
187+
file.category !== 'accumulator' &&
195188
file.category !== 'search'
196189
) {
197190
// TODO: enable for others

packages/mql-typescript/tests/expression/first.spec.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,11 @@ import * as bson from 'bson';
55
* Use in $addFields Stage
66
*/
77
function test0() {
8-
// TODO: No docs reference found for first.Use in $addFields Stage
8+
type collection = {
9+
items: Array<string>;
10+
};
11+
12+
const aggregation: schema.Pipeline<collection> = [
13+
{ $addFields: { firstItem: { $first: '$items' } } },
14+
];
915
}

packages/mql-typescript/tests/expression/last.spec.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,11 @@ import * as bson from 'bson';
55
* Use in $addFields Stage
66
*/
77
function test0() {
8-
// TODO: No docs reference found for last.Use in $addFields Stage
8+
type collection = {
9+
items: Array<string>;
10+
};
11+
12+
const aggregation: schema.Pipeline<collection> = [
13+
{ $addFields: { lastItem: { $last: '$items' } } },
14+
];
915
}

0 commit comments

Comments
 (0)