Skip to content

fix: distinguish JavascriptWithScope COMPASS-8291 #223

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
".esm-wrapper.mjs"
],
"scripts": {
"test": "nyc mocha --timeout 5000 --colors -r ts-node/register test/**/*.ts src/**/*.test.ts",
"test": "nyc mocha --timeout 5000 --colors -r ts-node/register test/*.ts test/**/*.ts src/**/*.test.ts",
"test-example-parse-from-file": "ts-node examples/parse-from-file.ts",
"test-example-parse-schema": "ts-node examples/parse-schema.ts",
"test-time": "ts-node ./test/time-testing.ts",
Expand Down
4 changes: 4 additions & 0 deletions src/schema-analyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type TypeCastMap = {
Binary: Binary;
Boolean: boolean;
Code: Code;
CodeWScope: Code;
Date: Date;
Decimal128: Decimal128;
Double: Double;
Expand Down Expand Up @@ -215,6 +216,9 @@ function getBSONType(value: any): SchemaBSONType {
// In the resulting schema we rename `Object` to `Document`.
return 'Document';
}
if (bsonType === 'Code' && (value as Code).scope) {
return 'CodeWScope';
}
return bsonType;
}

Expand Down
8 changes: 4 additions & 4 deletions src/schema-convertors/internalToMongoDB.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -573,12 +573,12 @@ describe('internalSchemaToMongoDB', async function() {
'javascriptWithScope'
],
count: 1,
type: 'Code',
type: 'CodeWScope',
probability: 0.8,
hasDuplicates: false,
types: [
{
name: 'Code',
name: 'CodeWScope',
path: [
'javascriptWithScope'
],
Expand All @@ -595,7 +595,7 @@ describe('internalSchemaToMongoDB', async function() {
}
}
],
bsonType: 'Code'
bsonType: 'CodeWScope'
}
]
},
Expand Down Expand Up @@ -964,7 +964,7 @@ describe('internalSchemaToMongoDB', async function() {
bsonType: 'javascript'
},
javascriptWithScope: {
bsonType: 'javascript'
bsonType: 'javascriptWithScope'
},
long: {
bsonType: 'long'
Expand Down
1 change: 1 addition & 0 deletions src/schema-convertors/internalToMongoDB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const InternalTypeToBsonTypeMap: Record<
BSONSymbol: 'symbol',
Symbol: 'symbol',
Code: 'javascript',
CodeWScope: 'javascriptWithScope',
Int32: 'int',
Timestamp: 'timestamp',
Long: 'long',
Expand Down
8 changes: 4 additions & 4 deletions src/schema-convertors/internalToStandard.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -576,12 +576,12 @@ describe('internalSchemaToStandard', async function() {
'javascriptWithScope'
],
count: 1,
type: 'Code',
type: 'CodeWScope',
probability: 0.8,
hasDuplicates: false,
types: [
{
name: 'Code',
name: 'CodeWScope',
path: [
'javascriptWithScope'
],
Expand All @@ -598,7 +598,7 @@ describe('internalSchemaToStandard', async function() {
}
}
],
bsonType: 'Code'
bsonType: 'CodeWScope'
}
]
},
Expand Down Expand Up @@ -970,7 +970,7 @@ describe('internalSchemaToStandard', async function() {
$ref: '#/$defs/Code'
},
javascriptWithScope: {
$ref: '#/$defs/Code'
$ref: '#/$defs/CodeWScope'
},
long: {
type: 'integer'
Expand Down
2 changes: 1 addition & 1 deletion src/schema-convertors/internalToStandard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const InternalTypeToStandardTypeMap: Record<
DBPointer: { $ref: '#/$defs/DBPointer' },
BSONSymbol: { $ref: '#/$defs/BSONSymbol' },
Code: { $ref: '#/$defs/Code' },
CodeWScope: { $ref: '#/$defs/Code' },
CodeWScope: { $ref: '#/$defs/CodeWScope' },
Int32: { type: 'integer' },
Timestamp: { $ref: '#/$defs/Timestamp' },
Long: { type: 'integer' },
Expand Down
1 change: 1 addition & 0 deletions test/all-bson-types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ describe('using a document with all bson types', function() {
'Binary',
'Boolean',
'Code',
'CodeWScope',
'Date',
'Decimal128',
'Double',
Expand Down
2 changes: 1 addition & 1 deletion test/simplified-schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ const expected = {
},
javascriptWithScope: {
types: [{
bsonType: 'Code'
bsonType: 'CodeWScope'
}]
},
int: {
Expand Down
Loading