Skip to content

Commit

Permalink
feat: update to latest mongosh, driver, and segment analytics VSCODE-366
Browse files Browse the repository at this point in the history
 (#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
  • Loading branch information
alenakhineika authored Mar 21, 2023
1 parent c31a9c5 commit 833a24f
Show file tree
Hide file tree
Showing 16 changed files with 1,677 additions and 2,229 deletions.
3,674 changes: 1,564 additions & 2,110 deletions package-lock.json

Large diffs are not rendered by default.

94 changes: 47 additions & 47 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"reformat": "prettier --write ."
},
"engines": {
"vscode": "^1.75.1",
"vscode": "^1.76.2",
"node": "^16.16.0",
"npm": "^8.15.1"
},
Expand Down Expand Up @@ -964,52 +964,52 @@
}
},
"dependencies": {
"@babel/parser": "^7.19.1",
"@babel/traverse": "^7.19.1",
"@fortawesome/fontawesome-svg-core": "^6.2.0",
"@fortawesome/free-solid-svg-icons": "^6.2.0",
"@babel/parser": "^7.21.3",
"@babel/traverse": "^7.21.3",
"@fortawesome/fontawesome-svg-core": "^6.3.0",
"@fortawesome/free-solid-svg-icons": "^6.3.0",
"@fortawesome/react-fontawesome": "^0.2.0",
"@iconify-icons/codicon": "^1.2.16",
"@iconify-icons/codicon": "^1.2.23",
"@iconify/react": "^1.1.4",
"@leafygreen-ui/logo": "^6.1.3",
"@leafygreen-ui/logo": "^6.3.0",
"@leafygreen-ui/toggle": "^7.0.5",
"@mongodb-js/mongodb-constants": "^0.2.1",
"@mongosh/browser-runtime-electron": "^1.6.2",
"@mongosh/i18n": "^1.6.2",
"@mongosh/service-provider-server": "^1.6.2",
"@mongosh/shell-api": "^1.6.2",
"analytics-node": "^5.1.2",
"bson": "^4.7.0",
"bson-transpilers": "^2.0.0",
"@mongodb-js/mongodb-constants": "^0.2.2",
"@mongosh/browser-runtime-electron": "^1.8.0",
"@mongosh/i18n": "^1.8.0",
"@mongosh/service-provider-server": "^1.8.0",
"@mongosh/shell-api": "^1.8.0",
"analytics-node": "^6.2.0",
"bson": "^5.0.1",
"bson-transpilers": "^2.0.3",
"classnames": "^2.3.2",
"debug": "^4.3.4",
"dotenv": "^16.0.2",
"dotenv": "^16.0.3",
"micromatch": "^4.0.5",
"mongodb": "^4.13.0",
"mongodb": "^5.1.0",
"mongodb-build-info": "^1.5.0",
"mongodb-cloud-info": "^1.1.3",
"mongodb-connection-string-url": "^2.5.3",
"mongodb-data-service": "^22.4.1",
"mongodb-query-parser": "^2.4.6",
"mongodb-schema": "^10.0.0",
"mongodb-connection-string-url": "^2.6.0",
"mongodb-data-service": "^22.5.1",
"mongodb-query-parser": "^2.4.11",
"mongodb-schema": "^10.0.1",
"numeral": "^2.0.6",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-redux": "^8.0.5",
"redux": "^4.2.0",
"redux": "^4.2.1",
"ts-log": "^2.2.5",
"uuid": "^8.3.2",
"vscode-languageclient": "^8.0.2",
"vscode-languageserver": "^8.0.2",
"vscode-languageserver-textdocument": "^1.0.7"
"vscode-languageclient": "^8.1.0",
"vscode-languageserver": "^8.1.0",
"vscode-languageserver-textdocument": "^1.0.9"
},
"devDependencies": {
"@mongodb-js/prettier-config-compass": "^1.0.0",
"@mongosh/service-provider-core": "^1.8.0",
"@types/analytics-node": "^3.1.9",
"@types/babel__core": "^7.1.19",
"@types/babel__traverse": "^7.18.1",
"@types/chai": "^4.3.3",
"@types/analytics-node": "^3.1.11",
"@types/babel__core": "^7.20.0",
"@types/babel__traverse": "^7.18.3",
"@types/chai": "^4.3.4",
"@types/chai-fs": "^2.0.2",
"@types/chai-json-schema": "^1.4.6",
"@types/debug": "^4.1.7",
Expand All @@ -1019,20 +1019,20 @@
"@types/micromatch": "^4.0.2",
"@types/mkdirp": "^2.0.0",
"@types/mocha": "^8.2.3",
"@types/node": "^14.18.29",
"@types/react": "^17.0.50",
"@types/react-dom": "^17.0.17",
"@types/node": "^14.18.38",
"@types/react": "^17.0.53",
"@types/react-dom": "^17.0.19",
"@types/sinon": "^9.0.11",
"@types/uuid": "^8.3.4",
"@types/vscode": "^1.74.0",
"@typescript-eslint/eslint-plugin": "^5.38.0",
"@typescript-eslint/parser": "^5.38.0",
"@vscode/test-electron": "^2.1.5",
"@vscode/vsce": "^2.16.0",
"@types/vscode": "^1.76.0",
"@typescript-eslint/eslint-plugin": "^5.55.0",
"@typescript-eslint/parser": "^5.55.0",
"@vscode/test-electron": "^2.3.0",
"@vscode/vsce": "^2.18.0",
"@wojtekmaj/enzyme-adapter-react-17": "^0.8.0",
"autoprefixer": "^9.8.8",
"buffer": "^6.0.3",
"chai": "^4.3.6",
"chai": "^4.3.7",
"chai-as-promised": "^7.1.1",
"chai-fs": "^2.0.0",
"chai-json-schema": "^1.5.1",
Expand All @@ -1045,7 +1045,7 @@
"download": "^8.0.0",
"electron": "^23.0.0",
"enzyme": "^3.11.0",
"eslint": "^8.23.1",
"eslint": "^8.36.0",
"eslint-config-mongodb-js": "^5.0.3",
"eslint-plugin-mocha": "^10.1.0",
"execa": "^1.0.0",
Expand All @@ -1057,26 +1057,26 @@
"less-loader": "^5.0.0",
"mkdirp": "^1.0.4",
"mocha": "^8.4.0",
"mocha-junit-reporter": "^2.0.2",
"mocha-multi": "^1.1.6",
"mongodb-client-encryption": "^2.4.0",
"mongodb-runner": "^4.9.0",
"mocha-junit-reporter": "^2.2.0",
"mocha-multi": "^1.1.7",
"mongodb-client-encryption": "^2.6.0",
"mongodb-runner": "^4.10.0",
"node-loader": "^0.6.0",
"npm-run-all": "^4.1.5",
"ora": "^5.4.1",
"postcss-loader": "^3.0.0",
"pre-commit": "^1.2.2",
"prettier": "^2.7.1",
"prettier": "^2.8.5",
"process": "^0.11.10",
"semver": "^7.3.7",
"semver": "^7.3.8",
"sinon": "^9.2.4",
"sinon-chai": "^3.7.0",
"stream-browserify": "^3.0.0",
"style-loader": "^1.3.0",
"ts-jest": "^26.5.6",
"ts-loader": "^9.4.1",
"ts-loader": "^9.4.2",
"ts-node": "^10.9.1",
"typescript": "^4.8.3",
"typescript": "^4.9.5",
"webpack": "^5.74.0",
"webpack-cli": "^4.10.0",
"xvfb-maybe": "^0.2.1",
Expand Down
9 changes: 4 additions & 5 deletions src/editors/documentIdStore.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { EJSON } from 'bson';
import { v4 as uuidv4 } from 'uuid';

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

add(documentId: EJSON.SerializableTypes): string {
add(documentId: any): string {
const existingDocument = this._documents.find(
(item) => item.documentId === documentId
);
Expand All @@ -22,7 +21,7 @@ export default class DocumentIdStore {

const newDocument: {
documentIdReference: string;
documentId: EJSON.SerializableTypes;
documentId: any;
} = {
documentIdReference: uuidv4(),
documentId,
Expand All @@ -33,7 +32,7 @@ export default class DocumentIdStore {
return newDocument.documentIdReference;
}

get(documentIdReference: string): EJSON.SerializableTypes | undefined {
get(documentIdReference: string) {
const existingDocument = this._documents.find(
(item) => item.documentIdReference === documentIdReference
);
Expand Down
3 changes: 2 additions & 1 deletion src/editors/editDocumentCodeLensProvider.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as vscode from 'vscode';
import { EJSON } from 'bson';
import type { Document } from 'bson';

import ConnectionController from '../connectionController';
import { DocumentSource } from '../documentSource';
Expand Down Expand Up @@ -29,7 +30,7 @@ export default class EditDocumentCodeLensProvider
}

updateCodeLensesForCollection(data: {
content: EJSON.SerializableTypes;
content: Document;
namespace: string | null;
uri: vscode.Uri;
}) {
Expand Down
11 changes: 6 additions & 5 deletions src/editors/editorsController.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as vscode from 'vscode';
import { EJSON } from 'bson';
import type { Document } from 'bson';

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

export function getFileDisplayNameForDocument(
documentId: EJSON.SerializableTypes,
documentId: any,
namespace: string
) {
let displayName = `${namespace}:${EJSON.stringify(documentId)}`;
Expand Down Expand Up @@ -160,11 +161,11 @@ export default class EditorsController {

async openMongoDBDocument(data: EditDocumentInfo): Promise<boolean> {
try {
const mdbDocument = (await this._mongoDBDocumentService.fetchDocument(
const mdbDocument = await this._mongoDBDocumentService.fetchDocument(
data
)) as EJSON.SerializableTypes;
);

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

_saveDocumentToMemoryFileSystem(
fileUri: vscode.Uri,
document: EJSON.SerializableTypes
document: Document
): void {
this._memoryFileSystemProvider.writeFile(
fileUri,
Expand Down
26 changes: 10 additions & 16 deletions src/editors/mongoDBDocumentService.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as util from 'util';
import * as vscode from 'vscode';
import { EJSON, Document } from 'bson';
import { EJSON } from 'bson';
import type { Document } from 'bson';

import ConnectionController from '../connectionController';
import { createLogger } from '../logging';
Expand Down Expand Up @@ -54,10 +55,10 @@ export default class MongoDBDocumentService {
}

async replaceDocument(data: {
documentId: EJSON.SerializableTypes;
documentId: any;
namespace: string;
connectionId: string;
newDocument: EJSON.SerializableTypes;
newDocument: Document;
source: DocumentSource;
}): Promise<void> {
log.info('Replace document in MongoDB', data);
Expand Down Expand Up @@ -88,12 +89,9 @@ export default class MongoDBDocumentService {
const findOneAndReplace = util.promisify(
dataservice.findOneAndReplace.bind(dataservice)
);
await findOneAndReplace(
namespace,
{ _id: documentId },
newDocument as Document,
{ returnDocument: 'after' }
);
await findOneAndReplace(namespace, { _id: documentId }, newDocument, {
returnDocument: 'after',
});

this._statusView.hideMessage();
this._telemetryService.trackDocumentUpdated(source, true);
Expand All @@ -104,9 +102,7 @@ export default class MongoDBDocumentService {
}
}

async fetchDocument(
data: EditDocumentInfo
): Promise<EJSON.SerializableTypes | void> {
async fetchDocument(data: EditDocumentInfo): Promise<Document | void> {
log.info('Fetch document from MongoDB', data);

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

if (!documents || documents.length === 0) {
return null;
return;
}

return JSON.parse(
EJSON.stringify(documents[0])
) as EJSON.SerializableTypes;
return JSON.parse(EJSON.stringify(documents[0]));
} catch (error) {
this._statusView.hideMessage();

Expand Down
6 changes: 3 additions & 3 deletions src/explorer/documentTreeItem.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { EJSON } from 'bson';
import * as vscode from 'vscode';
import type { Document } from 'mongodb';
import { EJSON } from 'bson';
import type { Document } from 'bson';
import type { DataService } from 'mongodb-data-service';
import { promisify } from 'util';
import { toJSString } from 'mongodb-query-parser';
Expand All @@ -18,7 +18,7 @@ export default class DocumentTreeItem
namespace: string;
dataService: DataService;
document: Document;
documentId: EJSON.SerializableTypes;
documentId: any;
resetDocumentListCache: () => Promise<void>;

constructor(
Expand Down
22 changes: 10 additions & 12 deletions src/storage/storageController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,26 +73,24 @@ export default class StorageController {
}

getUserIdentity() {
const globalAnonymousId = this.get(StorageVariables.GLOBAL_ANONYMOUS_ID);
const globalUserId = this.get(StorageVariables.GLOBAL_USER_ID);
const userId = this.get(StorageVariables.GLOBAL_USER_ID);
let anonymousId = this.get(StorageVariables.GLOBAL_ANONYMOUS_ID);

if (!anonymousId) {
anonymousId = uuidv4();
void this.update(StorageVariables.GLOBAL_ANONYMOUS_ID, anonymousId);
}

// Initially, we used `userId` as Segment user identifier, but this usage is being deprecated.
// The `anonymousId` should be used instead.
// We keep sending `userId` to Segment for old users though to preserve their analytics.
if (globalUserId && typeof globalUserId === 'string') {
return {
userId: globalUserId,
};
}

if (globalAnonymousId && typeof globalAnonymousId === 'string') {
if (userId && typeof userId === 'string') {
return {
anonymousId: globalAnonymousId,
userId,
anonymousId, // The anonymousId becomes required with analytics-node v6.
};
}

const anonymousId = uuidv4();
void this.update(StorageVariables.GLOBAL_ANONYMOUS_ID, anonymousId);
return { anonymousId };
}

Expand Down
Loading

0 comments on commit 833a24f

Please sign in to comment.