Skip to content

Commit 833a24f

Browse files
feat: update to latest mongosh, driver, and segment analytics VSCODE-366 (#494)
* feat: update to latest mongosh, driver, and segment analytics VSCODE-366 * refactor: rename and reformat * build: bump mongodb-schema * build: use vscode engine v1.76.2 * refactor: use _id as any * refactor: use any type for _id
1 parent c31a9c5 commit 833a24f

16 files changed

+1677
-2229
lines changed

package-lock.json

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

package.json

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
"reformat": "prettier --write ."
6363
},
6464
"engines": {
65-
"vscode": "^1.75.1",
65+
"vscode": "^1.76.2",
6666
"node": "^16.16.0",
6767
"npm": "^8.15.1"
6868
},
@@ -964,52 +964,52 @@
964964
}
965965
},
966966
"dependencies": {
967-
"@babel/parser": "^7.19.1",
968-
"@babel/traverse": "^7.19.1",
969-
"@fortawesome/fontawesome-svg-core": "^6.2.0",
970-
"@fortawesome/free-solid-svg-icons": "^6.2.0",
967+
"@babel/parser": "^7.21.3",
968+
"@babel/traverse": "^7.21.3",
969+
"@fortawesome/fontawesome-svg-core": "^6.3.0",
970+
"@fortawesome/free-solid-svg-icons": "^6.3.0",
971971
"@fortawesome/react-fontawesome": "^0.2.0",
972-
"@iconify-icons/codicon": "^1.2.16",
972+
"@iconify-icons/codicon": "^1.2.23",
973973
"@iconify/react": "^1.1.4",
974-
"@leafygreen-ui/logo": "^6.1.3",
974+
"@leafygreen-ui/logo": "^6.3.0",
975975
"@leafygreen-ui/toggle": "^7.0.5",
976-
"@mongodb-js/mongodb-constants": "^0.2.1",
977-
"@mongosh/browser-runtime-electron": "^1.6.2",
978-
"@mongosh/i18n": "^1.6.2",
979-
"@mongosh/service-provider-server": "^1.6.2",
980-
"@mongosh/shell-api": "^1.6.2",
981-
"analytics-node": "^5.1.2",
982-
"bson": "^4.7.0",
983-
"bson-transpilers": "^2.0.0",
976+
"@mongodb-js/mongodb-constants": "^0.2.2",
977+
"@mongosh/browser-runtime-electron": "^1.8.0",
978+
"@mongosh/i18n": "^1.8.0",
979+
"@mongosh/service-provider-server": "^1.8.0",
980+
"@mongosh/shell-api": "^1.8.0",
981+
"analytics-node": "^6.2.0",
982+
"bson": "^5.0.1",
983+
"bson-transpilers": "^2.0.3",
984984
"classnames": "^2.3.2",
985985
"debug": "^4.3.4",
986-
"dotenv": "^16.0.2",
986+
"dotenv": "^16.0.3",
987987
"micromatch": "^4.0.5",
988-
"mongodb": "^4.13.0",
988+
"mongodb": "^5.1.0",
989989
"mongodb-build-info": "^1.5.0",
990990
"mongodb-cloud-info": "^1.1.3",
991-
"mongodb-connection-string-url": "^2.5.3",
992-
"mongodb-data-service": "^22.4.1",
993-
"mongodb-query-parser": "^2.4.6",
994-
"mongodb-schema": "^10.0.0",
991+
"mongodb-connection-string-url": "^2.6.0",
992+
"mongodb-data-service": "^22.5.1",
993+
"mongodb-query-parser": "^2.4.11",
994+
"mongodb-schema": "^10.0.1",
995995
"numeral": "^2.0.6",
996996
"react": "^17.0.2",
997997
"react-dom": "^17.0.2",
998998
"react-redux": "^8.0.5",
999-
"redux": "^4.2.0",
999+
"redux": "^4.2.1",
10001000
"ts-log": "^2.2.5",
10011001
"uuid": "^8.3.2",
1002-
"vscode-languageclient": "^8.0.2",
1003-
"vscode-languageserver": "^8.0.2",
1004-
"vscode-languageserver-textdocument": "^1.0.7"
1002+
"vscode-languageclient": "^8.1.0",
1003+
"vscode-languageserver": "^8.1.0",
1004+
"vscode-languageserver-textdocument": "^1.0.9"
10051005
},
10061006
"devDependencies": {
10071007
"@mongodb-js/prettier-config-compass": "^1.0.0",
10081008
"@mongosh/service-provider-core": "^1.8.0",
1009-
"@types/analytics-node": "^3.1.9",
1010-
"@types/babel__core": "^7.1.19",
1011-
"@types/babel__traverse": "^7.18.1",
1012-
"@types/chai": "^4.3.3",
1009+
"@types/analytics-node": "^3.1.11",
1010+
"@types/babel__core": "^7.20.0",
1011+
"@types/babel__traverse": "^7.18.3",
1012+
"@types/chai": "^4.3.4",
10131013
"@types/chai-fs": "^2.0.2",
10141014
"@types/chai-json-schema": "^1.4.6",
10151015
"@types/debug": "^4.1.7",
@@ -1019,20 +1019,20 @@
10191019
"@types/micromatch": "^4.0.2",
10201020
"@types/mkdirp": "^2.0.0",
10211021
"@types/mocha": "^8.2.3",
1022-
"@types/node": "^14.18.29",
1023-
"@types/react": "^17.0.50",
1024-
"@types/react-dom": "^17.0.17",
1022+
"@types/node": "^14.18.38",
1023+
"@types/react": "^17.0.53",
1024+
"@types/react-dom": "^17.0.19",
10251025
"@types/sinon": "^9.0.11",
10261026
"@types/uuid": "^8.3.4",
1027-
"@types/vscode": "^1.74.0",
1028-
"@typescript-eslint/eslint-plugin": "^5.38.0",
1029-
"@typescript-eslint/parser": "^5.38.0",
1030-
"@vscode/test-electron": "^2.1.5",
1031-
"@vscode/vsce": "^2.16.0",
1027+
"@types/vscode": "^1.76.0",
1028+
"@typescript-eslint/eslint-plugin": "^5.55.0",
1029+
"@typescript-eslint/parser": "^5.55.0",
1030+
"@vscode/test-electron": "^2.3.0",
1031+
"@vscode/vsce": "^2.18.0",
10321032
"@wojtekmaj/enzyme-adapter-react-17": "^0.8.0",
10331033
"autoprefixer": "^9.8.8",
10341034
"buffer": "^6.0.3",
1035-
"chai": "^4.3.6",
1035+
"chai": "^4.3.7",
10361036
"chai-as-promised": "^7.1.1",
10371037
"chai-fs": "^2.0.0",
10381038
"chai-json-schema": "^1.5.1",
@@ -1045,7 +1045,7 @@
10451045
"download": "^8.0.0",
10461046
"electron": "^23.0.0",
10471047
"enzyme": "^3.11.0",
1048-
"eslint": "^8.23.1",
1048+
"eslint": "^8.36.0",
10491049
"eslint-config-mongodb-js": "^5.0.3",
10501050
"eslint-plugin-mocha": "^10.1.0",
10511051
"execa": "^1.0.0",
@@ -1057,26 +1057,26 @@
10571057
"less-loader": "^5.0.0",
10581058
"mkdirp": "^1.0.4",
10591059
"mocha": "^8.4.0",
1060-
"mocha-junit-reporter": "^2.0.2",
1061-
"mocha-multi": "^1.1.6",
1062-
"mongodb-client-encryption": "^2.4.0",
1063-
"mongodb-runner": "^4.9.0",
1060+
"mocha-junit-reporter": "^2.2.0",
1061+
"mocha-multi": "^1.1.7",
1062+
"mongodb-client-encryption": "^2.6.0",
1063+
"mongodb-runner": "^4.10.0",
10641064
"node-loader": "^0.6.0",
10651065
"npm-run-all": "^4.1.5",
10661066
"ora": "^5.4.1",
10671067
"postcss-loader": "^3.0.0",
10681068
"pre-commit": "^1.2.2",
1069-
"prettier": "^2.7.1",
1069+
"prettier": "^2.8.5",
10701070
"process": "^0.11.10",
1071-
"semver": "^7.3.7",
1071+
"semver": "^7.3.8",
10721072
"sinon": "^9.2.4",
10731073
"sinon-chai": "^3.7.0",
10741074
"stream-browserify": "^3.0.0",
10751075
"style-loader": "^1.3.0",
10761076
"ts-jest": "^26.5.6",
1077-
"ts-loader": "^9.4.1",
1077+
"ts-loader": "^9.4.2",
10781078
"ts-node": "^10.9.1",
1079-
"typescript": "^4.8.3",
1079+
"typescript": "^4.9.5",
10801080
"webpack": "^5.74.0",
10811081
"webpack-cli": "^4.10.0",
10821082
"xvfb-maybe": "^0.2.1",

src/editors/documentIdStore.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { EJSON } from 'bson';
21
import { v4 as uuidv4 } from 'uuid';
32

43
// In order to provide opening documents with various _id types we need
@@ -8,10 +7,10 @@ import { v4 as uuidv4 } from 'uuid';
87
export default class DocumentIdStore {
98
_documents: {
109
documentIdReference: string;
11-
documentId: EJSON.SerializableTypes;
10+
documentId: any;
1211
}[] = [];
1312

14-
add(documentId: EJSON.SerializableTypes): string {
13+
add(documentId: any): string {
1514
const existingDocument = this._documents.find(
1615
(item) => item.documentId === documentId
1716
);
@@ -22,7 +21,7 @@ export default class DocumentIdStore {
2221

2322
const newDocument: {
2423
documentIdReference: string;
25-
documentId: EJSON.SerializableTypes;
24+
documentId: any;
2625
} = {
2726
documentIdReference: uuidv4(),
2827
documentId,
@@ -33,7 +32,7 @@ export default class DocumentIdStore {
3332
return newDocument.documentIdReference;
3433
}
3534

36-
get(documentIdReference: string): EJSON.SerializableTypes | undefined {
35+
get(documentIdReference: string) {
3736
const existingDocument = this._documents.find(
3837
(item) => item.documentIdReference === documentIdReference
3938
);

src/editors/editDocumentCodeLensProvider.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as vscode from 'vscode';
22
import { EJSON } from 'bson';
3+
import type { Document } from 'bson';
34

45
import ConnectionController from '../connectionController';
56
import { DocumentSource } from '../documentSource';
@@ -29,7 +30,7 @@ export default class EditDocumentCodeLensProvider
2930
}
3031

3132
updateCodeLensesForCollection(data: {
32-
content: EJSON.SerializableTypes;
33+
content: Document;
3334
namespace: string | null;
3435
uri: vscode.Uri;
3536
}) {

src/editors/editorsController.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as vscode from 'vscode';
22
import { EJSON } from 'bson';
3+
import type { Document } from 'bson';
34

45
import ActiveConnectionCodeLensProvider from './activeConnectionCodeLensProvider';
56
import ExportToLanguageCodeLensProvider from './exportToLanguageCodeLensProvider';
@@ -36,7 +37,7 @@ import TelemetryService from '../telemetry/telemetryService';
3637
const log = createLogger('editors controller');
3738

3839
export function getFileDisplayNameForDocument(
39-
documentId: EJSON.SerializableTypes,
40+
documentId: any,
4041
namespace: string
4142
) {
4243
let displayName = `${namespace}:${EJSON.stringify(documentId)}`;
@@ -160,11 +161,11 @@ export default class EditorsController {
160161

161162
async openMongoDBDocument(data: EditDocumentInfo): Promise<boolean> {
162163
try {
163-
const mdbDocument = (await this._mongoDBDocumentService.fetchDocument(
164+
const mdbDocument = await this._mongoDBDocumentService.fetchDocument(
164165
data
165-
)) as EJSON.SerializableTypes;
166+
);
166167

167-
if (mdbDocument === null) {
168+
if (!mdbDocument) {
168169
void vscode.window.showErrorMessage(`
169170
Unable to open mongodb document: document ${JSON.stringify(
170171
data.documentId
@@ -346,7 +347,7 @@ export default class EditorsController {
346347

347348
_saveDocumentToMemoryFileSystem(
348349
fileUri: vscode.Uri,
349-
document: EJSON.SerializableTypes
350+
document: Document
350351
): void {
351352
this._memoryFileSystemProvider.writeFile(
352353
fileUri,

src/editors/mongoDBDocumentService.ts

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as util from 'util';
22
import * as vscode from 'vscode';
3-
import { EJSON, Document } from 'bson';
3+
import { EJSON } from 'bson';
4+
import type { Document } from 'bson';
45

56
import ConnectionController from '../connectionController';
67
import { createLogger } from '../logging';
@@ -54,10 +55,10 @@ export default class MongoDBDocumentService {
5455
}
5556

5657
async replaceDocument(data: {
57-
documentId: EJSON.SerializableTypes;
58+
documentId: any;
5859
namespace: string;
5960
connectionId: string;
60-
newDocument: EJSON.SerializableTypes;
61+
newDocument: Document;
6162
source: DocumentSource;
6263
}): Promise<void> {
6364
log.info('Replace document in MongoDB', data);
@@ -88,12 +89,9 @@ export default class MongoDBDocumentService {
8889
const findOneAndReplace = util.promisify(
8990
dataservice.findOneAndReplace.bind(dataservice)
9091
);
91-
await findOneAndReplace(
92-
namespace,
93-
{ _id: documentId },
94-
newDocument as Document,
95-
{ returnDocument: 'after' }
96-
);
92+
await findOneAndReplace(namespace, { _id: documentId }, newDocument, {
93+
returnDocument: 'after',
94+
});
9795

9896
this._statusView.hideMessage();
9997
this._telemetryService.trackDocumentUpdated(source, true);
@@ -104,9 +102,7 @@ export default class MongoDBDocumentService {
104102
}
105103
}
106104

107-
async fetchDocument(
108-
data: EditDocumentInfo
109-
): Promise<EJSON.SerializableTypes | void> {
105+
async fetchDocument(data: EditDocumentInfo): Promise<Document | void> {
110106
log.info('Fetch document from MongoDB', data);
111107

112108
const { documentId, namespace, connectionId } = data;
@@ -142,12 +138,10 @@ export default class MongoDBDocumentService {
142138
this._statusView.hideMessage();
143139

144140
if (!documents || documents.length === 0) {
145-
return null;
141+
return;
146142
}
147143

148-
return JSON.parse(
149-
EJSON.stringify(documents[0])
150-
) as EJSON.SerializableTypes;
144+
return JSON.parse(EJSON.stringify(documents[0]));
151145
} catch (error) {
152146
this._statusView.hideMessage();
153147

src/explorer/documentTreeItem.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { EJSON } from 'bson';
21
import * as vscode from 'vscode';
3-
import type { Document } from 'mongodb';
2+
import { EJSON } from 'bson';
3+
import type { Document } from 'bson';
44
import type { DataService } from 'mongodb-data-service';
55
import { promisify } from 'util';
66
import { toJSString } from 'mongodb-query-parser';
@@ -18,7 +18,7 @@ export default class DocumentTreeItem
1818
namespace: string;
1919
dataService: DataService;
2020
document: Document;
21-
documentId: EJSON.SerializableTypes;
21+
documentId: any;
2222
resetDocumentListCache: () => Promise<void>;
2323

2424
constructor(

src/storage/storageController.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,26 +73,24 @@ export default class StorageController {
7373
}
7474

7575
getUserIdentity() {
76-
const globalAnonymousId = this.get(StorageVariables.GLOBAL_ANONYMOUS_ID);
77-
const globalUserId = this.get(StorageVariables.GLOBAL_USER_ID);
76+
const userId = this.get(StorageVariables.GLOBAL_USER_ID);
77+
let anonymousId = this.get(StorageVariables.GLOBAL_ANONYMOUS_ID);
78+
79+
if (!anonymousId) {
80+
anonymousId = uuidv4();
81+
void this.update(StorageVariables.GLOBAL_ANONYMOUS_ID, anonymousId);
82+
}
7883

7984
// Initially, we used `userId` as Segment user identifier, but this usage is being deprecated.
8085
// The `anonymousId` should be used instead.
8186
// We keep sending `userId` to Segment for old users though to preserve their analytics.
82-
if (globalUserId && typeof globalUserId === 'string') {
83-
return {
84-
userId: globalUserId,
85-
};
86-
}
87-
88-
if (globalAnonymousId && typeof globalAnonymousId === 'string') {
87+
if (userId && typeof userId === 'string') {
8988
return {
90-
anonymousId: globalAnonymousId,
89+
userId,
90+
anonymousId, // The anonymousId becomes required with analytics-node v6.
9191
};
9292
}
9393

94-
const anonymousId = uuidv4();
95-
void this.update(StorageVariables.GLOBAL_ANONYMOUS_ID, anonymousId);
9694
return { anonymousId };
9795
}
9896

0 commit comments

Comments
 (0)