Skip to content

Commit 7cd7cde

Browse files
committed
Remove ejson syntax support
1 parent ce8e7bd commit 7cd7cde

File tree

19 files changed

+97
-662
lines changed

19 files changed

+97
-662
lines changed

package-lock.json

Lines changed: 26 additions & 614 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
tests/**/*.spec.ts linguist-generated=true
22
src/metaschema.ts linguist-generated=true
3+
out/*.ts linguist-generated=true
4+
out/*.js linguist-generated=true

packages/mql-typescript/out/schema.ts

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

packages/mql-typescript/src/driverSchema/docs-crawler.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ export class DocsCrawler {
2929
// Insert commas between array elements
3030
json = json.replace(/\}\s*\{/g, '},{');
3131

32+
// There are a few cases in the docs examples where we construct a NumberDecimal
33+
// from a js number rather than a string, which is deprecated (due to being imprecise).
34+
// See https://jira.mongodb.org/browse/DOCSP-50657
35+
json = json.replace(
36+
/NumberDecimal\((?<number>[\d.]*)\)/g,
37+
'NumberDecimal("$<number>")',
38+
);
39+
3240
try {
3341
let result = parse(json, { mode: ParseMode.Loose });
3442

packages/mql-typescript/src/generator.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,24 @@ export abstract class GeneratorBase {
171171
);
172172
},
173173
}),
174+
new yaml.Type('!bson_int64', {
175+
kind: 'scalar',
176+
construct(data: string) {
177+
return bson.Long.fromString(data);
178+
},
179+
predicate(data) {
180+
return data instanceof bson.Long;
181+
},
182+
represent(data) {
183+
if (data instanceof bson.Long) {
184+
return data.toString();
185+
}
186+
187+
throw new Error(
188+
`Expected bson.Long, but got ${data.constructor.name}`,
189+
);
190+
},
191+
}),
174192
]),
175193
};
176194

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,18 @@ export class TestGenerator extends GeneratorBase {
106106
return `bson.ObjectId.createFromHexString('${stage.toHexString()}')`;
107107
}
108108

109+
if (stage instanceof bson.Long) {
110+
return `new bson.Long('${stage.toString()}')`;
111+
}
112+
109113
if (stage instanceof Date) {
110114
return `new Date('${stage.toISOString()}')`;
111115
}
112116

117+
if (stage instanceof bson.BSONRegExp) {
118+
return `new bson.BSONRegExp('${stage.pattern}', '${stage.options}')`;
119+
}
120+
113121
if ('$code' in stage && typeof stage.$code === 'string') {
114122
return JSON.stringify(removeNewlines(stage.$code));
115123
}

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

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/tests/expression/bitOr.spec.ts

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/tests/expression/regexFind.spec.ts

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

0 commit comments

Comments
 (0)