Skip to content

Commit 7f0b1b3

Browse files
authored
feat: update mongosh to 2.0.0 and driver to 6.0.0 VSCODE-453 (#592)
1 parent c5c6b70 commit 7f0b1b3

File tree

7 files changed

+1037
-3316
lines changed

7 files changed

+1037
-3316
lines changed

.depcheckrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ ignores:
2323
- postcss-loader
2424
- style-loader
2525
- ts-loader
26+
- mongodb-runner

package-lock.json

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

package.json

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@
4747
"watch": "npm run compile && npm-run-all -p watch:*",
4848
"watch:extension": "npm run compile:extension -- -watch",
4949
"watch:extension-bundles": "webpack --mode development --watch",
50-
"pretest": "npm run compile && mongodb-runner start --port=27018",
50+
"pretest": "npm run compile && mongodb-runner start --id=vscode -- --port 27018",
5151
"test": "npm run test-webview && npm run test-extension",
5252
"test-extension": "cross-env NODE_OPTIONS=--no-force-async-hooks-checks xvfb-maybe node ./out/test/runTest.js",
5353
"test-webview": "jest",
54-
"posttest": "mongodb-runner stop --port=27018",
54+
"posttest": "mongodb-runner stop --id=vscode",
5555
"analyze-bundle": "webpack --mode production --analyze",
5656
"vscode:prepublish": "npm run clean && npm run compile:keyfile && npm run compile:resources && webpack --mode production",
5757
"check": "npm run lint && npm run depcheck",
@@ -980,24 +980,25 @@
980980
"@iconify-icons/codicon": "^1.2.25",
981981
"@iconify/react": "^1.1.4",
982982
"@leafygreen-ui/logo": "^8.0.4",
983-
"@mongodb-js/mongodb-constants": "^0.6.5",
984-
"@mongosh/browser-runtime-electron": "^1.10.4",
985-
"@mongosh/i18n": "^1.10.4",
986-
"@mongosh/service-provider-server": "^1.10.4",
987-
"@mongosh/shell-api": "^1.10.4",
983+
"@mongodb-js/mongodb-constants": "^0.7.0",
984+
"@mongosh/browser-runtime-electron": "^2.0.0",
985+
"@mongosh/i18n": "^2.0.0",
986+
"@mongosh/service-provider-server": "^2.0.0",
987+
"@mongosh/shell-api": "^2.0.0",
988988
"analytics-node": "^6.2.0",
989989
"bson": "^5.3.0",
990990
"bson-transpilers": "^2.0.4",
991991
"classnames": "^2.3.2",
992992
"debug": "^4.3.4",
993993
"dotenv": "^16.3.1",
994994
"micromatch": "^4.0.5",
995-
"mongodb": "^5.8.1",
996-
"mongodb-build-info": "^1.5.0",
995+
"mongodb": "^6.0.0",
996+
"mongodb-build-info": "^1.6.2",
997997
"mongodb-cloud-info": "^2.1.0",
998998
"mongodb-connection-string-url": "^2.6.0",
999-
"mongodb-data-service": "^22.8.0",
1000-
"mongodb-query-parser": "^2.5.0",
999+
"mongodb-data-service": "^22.10.0",
1000+
"mongodb-data-service-legacy": "npm:[email protected]",
1001+
"mongodb-query-parser": "^3.1.3",
10011002
"mongodb-schema": "^11.2.2",
10021003
"numeral": "^2.0.6",
10031004
"react": "^17.0.2",
@@ -1012,10 +1013,10 @@
10121013
},
10131014
"devDependencies": {
10141015
"@babel/preset-typescript": "^7.22.5",
1015-
"@mongodb-js/oidc-plugin": "^0.2.4",
1016+
"@mongodb-js/oidc-plugin": "^0.3.0",
10161017
"@mongodb-js/prettier-config-compass": "^1.0.0",
10171018
"@mongodb-js/sbom-tools": "^0.5.4",
1018-
"@mongosh/service-provider-core": "^1.10.4",
1019+
"@mongosh/service-provider-core": "^2.0.0",
10191020
"@types/analytics-node": "^3.1.11",
10201021
"@types/babel__core": "^7.20.1",
10211022
"@types/babel__traverse": "^7.20.1",
@@ -1064,8 +1065,8 @@
10641065
"mocha": "^8.4.0",
10651066
"mocha-junit-reporter": "^2.2.0",
10661067
"mocha-multi": "^1.1.7",
1067-
"mongodb-client-encryption": "^2.8.0",
1068-
"mongodb-runner": "^4.10.0",
1068+
"mongodb-client-encryption": "^6.0.0",
1069+
"mongodb-runner": "^5.4.4",
10691070
"node-loader": "^0.6.0",
10701071
"npm-run-all": "^4.1.5",
10711072
"ora": "^5.4.1",
@@ -1089,6 +1090,11 @@
10891090
"xvfb-maybe": "^0.2.1",
10901091
"yargs-parser": "^20.2.9"
10911092
},
1093+
"overrides": {
1094+
"mongodb-connection-model": {
1095+
"@mongodb-js/compass-utils": "0.3.4"
1096+
}
1097+
},
10921098
"precommit": [
10931099
"check"
10941100
]

src/connectionController.ts

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
import * as vscode from 'vscode';
2-
import {
3-
convertConnectionModelToInfo,
4-
getConnectionTitle,
5-
extractSecrets,
6-
mergeSecrets,
7-
connect,
8-
} from 'mongodb-data-service';
2+
import { connect } from 'mongodb-data-service';
93
import type {
104
DataService,
11-
ConnectionInfo,
12-
ConnectionOptions,
5+
ConnectionOptions as ConnectionOptionsFromCurrentDS,
136
} from 'mongodb-data-service';
147
import ConnectionString from 'mongodb-connection-string-url';
158
import { EventEmitter } from 'events';
@@ -31,6 +24,24 @@ import { StorageVariables } from './storage';
3124
import type { StatusView } from './views';
3225
import type TelemetryService from './telemetry/telemetryService';
3326
import LINKS from './utils/links';
27+
import type {
28+
ConnectionInfo as ConnectionInfoFromLegacyDS,
29+
ConnectionOptions as ConnectionOptionsFromLegacyDS,
30+
} from 'mongodb-data-service-legacy';
31+
import {
32+
getConnectionTitle,
33+
extractSecrets,
34+
mergeSecrets,
35+
convertConnectionModelToInfo,
36+
} from 'mongodb-data-service-legacy';
37+
38+
export function launderConnectionOptionTypeFromLegacyToCurrent(
39+
opts: ConnectionOptionsFromLegacyDS
40+
): ConnectionOptionsFromCurrentDS {
41+
// Ensure that, at most, the types for OIDC mismatch here.
42+
return opts as Omit<typeof opts, 'oidc'>;
43+
}
44+
3445
// eslint-disable-next-line @typescript-eslint/no-var-requires
3546
const packageJSON = require('../package.json');
3647

@@ -54,7 +65,7 @@ export interface StoreConnectionInfo {
5465
name: string; // Possibly user given name, not unique.
5566
storageLocation: StorageLocation;
5667
secretStorageLocation?: SecretStorageLocationType;
57-
connectionOptions?: ConnectionOptions;
68+
connectionOptions?: ConnectionOptionsFromLegacyDS;
5869
connectionModel?: LegacyConnectionModel;
5970
}
6071

@@ -471,7 +482,7 @@ export default class ConnectionController {
471482

472483
parseNewConnection(
473484
rawConnectionModel: LegacyConnectionModel
474-
): ConnectionInfo {
485+
): ConnectionInfoFromLegacyDS {
475486
return convertConnectionModelToInfo({
476487
...rawConnectionModel,
477488
appname: `${packageJSON.name} ${packageJSON.version}`, // Override the default connection appname.
@@ -483,7 +494,7 @@ export default class ConnectionController {
483494
): Promise<MigratedStoreConnectionInfoWithConnectionOptions> {
484495
// We don't want to store secrets to disc.
485496
const { connectionInfo: safeConnectionInfo, secrets } = extractSecrets(
486-
newStoreConnectionInfoWithSecrets as ConnectionInfo
497+
newStoreConnectionInfoWithSecrets as ConnectionInfoFromLegacyDS
487498
);
488499
const savedConnectionInfo = await this._storageController.saveConnection({
489500
...newStoreConnectionInfoWithSecrets,
@@ -498,7 +509,7 @@ export default class ConnectionController {
498509
}
499510

500511
async saveNewConnectionFromFormAndConnect(
501-
originalConnectionInfo: ConnectionInfo,
512+
originalConnectionInfo: ConnectionInfoFromLegacyDS,
502513
connectionType: ConnectionTypes
503514
): Promise<ConnectionAttemptResult> {
504515
const name = getConnectionTitle(originalConnectionInfo);
@@ -526,9 +537,12 @@ export default class ConnectionController {
526537
return this._connect(savedConnectionInfo.id, connectionType);
527538
}
528539

529-
async _connectWithDataService(connectionOptions: ConnectionOptions) {
540+
async _connectWithDataService(
541+
connectionOptions: ConnectionOptionsFromLegacyDS
542+
) {
530543
return connect({
531-
connectionOptions,
544+
connectionOptions:
545+
launderConnectionOptionTypeFromLegacyToCurrent(connectionOptions),
532546
productName: packageJSON.name,
533547
productDocsLink: LINKS.extensionDocs(),
534548
});

src/language/mongoDBService.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -352,17 +352,19 @@ export default class MongoDBService {
352352
}
353353

354354
try {
355-
const documents = this._serviceProvider.find(
356-
databaseName,
357-
collectionName,
358-
{},
359-
// TODO: figure out if we need parseSchema for one field at all.
360-
// For one document we can simply get deep object keys,
361-
// or we could analyze the schema for at least 5-10 documents.
362-
// The current behaviour came from Compass when we do the same:
363-
// https://github.com/mongodb-js/compass/blob/main/packages/compass-field-store/src/stores/store.js#L193
364-
{ limit: 1 }
365-
);
355+
const documents = await this._serviceProvider
356+
.find(
357+
databaseName,
358+
collectionName,
359+
{},
360+
// TODO: figure out if we need parseSchema for one field at all.
361+
// For one document we can simply get deep object keys,
362+
// or we could analyze the schema for at least 5-10 documents.
363+
// The current behaviour came from Compass when we do the same:
364+
// https://github.com/mongodb-js/compass/blob/main/packages/compass-field-store/src/stores/store.js#L193
365+
{ limit: 1 }
366+
)
367+
.toArray();
366368

367369
const schema = await parseSchema(documents);
368370
result = schema?.fields ? schema.fields.map((item) => item.name) : [];

src/test/suite/connectionController.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import AUTH_STRATEGY_VALUES from '../../views/webview-app/connection-model/const
1010
import ConnectionController, {
1111
DataServiceEventTypes,
1212
keytarMigrationFailedMessage,
13+
launderConnectionOptionTypeFromLegacyToCurrent,
1314
} from '../../connectionController';
1415
import formatError from '../../utils/formatError';
1516
import { StorageController, StorageVariables } from '../../storage';
@@ -836,7 +837,8 @@ suite('Connection Controller Test Suite', function () {
836837
await sleep(50);
837838

838839
return connect({
839-
connectionOptions,
840+
connectionOptions:
841+
launderConnectionOptionTypeFromLegacyToCurrent(connectionOptions),
840842
});
841843
}
842844
);
@@ -1199,9 +1201,7 @@ suite('Connection Controller Test Suite', function () {
11991201
monitorCommands: true,
12001202
useSystemCA: undefined,
12011203
authMechanismProperties: {},
1202-
oidc: {
1203-
allowedFlows: ['auth-code'],
1204-
},
1204+
oidc: {},
12051205
productDocsLink:
12061206
'https://docs.mongodb.com/mongodb-vscode/?utm_source=vscode&utm_medium=product',
12071207
productName: 'mongodb-vscode',

syntaxes/mongodbInjection.tmLanguage.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1935,6 +1935,15 @@
19351935
}
19361936
}
19371937
},
1938+
{
1939+
"name": "meta.object.member.mongodb",
1940+
"match": "\\$vectorSearch\\b",
1941+
"captures": {
1942+
"0": {
1943+
"name": "keyword.other.$vectorSearch.mongodb"
1944+
}
1945+
}
1946+
},
19381947
{
19391948
"name": "meta.object.member.mongodb",
19401949
"match": "\\$set\\b",

0 commit comments

Comments
 (0)