Skip to content

feat: bump mongosh APIs to latest VSCODE-240 #301

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 9 commits into from
Jun 21, 2021
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 azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ steps:

- bash: |
npm i -g vsce;
vsce package
env NODE_OPTIONS="--require ./scripts/no-npm-list-fail.js" vsce package
displayName: 'Build .vsix'
env:
SEGMENT_KEY: $(segmentKey)
Expand Down
2,993 changes: 817 additions & 2,176 deletions package-lock.json

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"vscode:prepublish": "npm run clean && npm run compile:keyfile && npm run compile:resources && webpack --mode production",
"check": "npm run lint && npm run check-dependencies",
"check-dependencies": "depcheck --ignores='vscode,keytar,@types/jest,mocha-junit-reporter,mocha-multi,pre-commit,webpack-cli,vscode-languageserver-textdocument'",
"package": "npm list --production --parseable --depth=99999 --loglevel=info || true && vsce package",
"package": "npm list --production --parseable --depth=99999 --loglevel=info || true && cross-env NODE_OPTIONS=\"--require ./scripts/no-npm-list-fail.js\" vsce package",
"local-install": "npm run package && code --install-extension ./mongodb-vscode-*.vsix"
},
"engines": {
Expand Down Expand Up @@ -867,20 +867,20 @@
"@iconify-icons/codicon": "^1.1.5",
"@iconify/react": "^1.1.3",
"@leafygreen-ui/toggle": "3.0.1",
"@mongosh/browser-runtime-electron": "^0.6.1",
"@mongosh/i18n": "^0.8.0",
"@mongosh/service-provider-server": "^0.6.1",
"@mongosh/shell-api": "^0.6.1",
"@mongosh/browser-runtime-electron": "^0.15.0",
"@mongosh/i18n": "^0.15.0",
"@mongosh/service-provider-server": "^0.15.0",
"@mongosh/shell-api": "^0.15.0",
"analytics-node": "^3.5.0",
"bson": "^4.2.0",
"classnames": "^2.2.6",
"debug": "^4.1.1",
"dotenv": "^8.2.0",
"micromatch": "^4.0.2",
"mongodb": "^3.6.3",
"mongodb": "4.0.0-beta.5",
"mongodb-cloud-info": "^1.1.2",
"mongodb-connection-model": "^19.0.2",
"mongodb-data-service": "^19.0.0",
"mongodb-connection-model": "^21.0.0",
"mongodb-data-service": "^21.0.0",
"mongodb-ns": "^2.2.0",
"mongodb-schema": "^8.2.5",
"numeral": "^2.0.6",
Expand Down
16 changes: 16 additions & 0 deletions scripts/no-npm-list-fail.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';
// Monkey-patch child_process so that the `npm list` command run by
// `vsce package` does not fail because of `mongodb` being a 4.x prerelease
// rather than a "proper" version number.
const child_process = require('child_process');
const origExec = child_process.exec;
child_process.exec = (cmd, options, cb) => {
if (cmd === 'npm list --production --parseable --depth=99999 --loglevel=error') {
origExec(cmd, options, (err, stdout, stderr) => {
cb(null, stdout, stderr);
});
} else {
origExec(cmd, options, cb);
}
};

2 changes: 1 addition & 1 deletion src/editors/mongoDBDocumentService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export default class MongoDBDocumentService {
},
newDocument,
{
returnOriginal: false
returnDocument: 'after'
}
);

Expand Down
3 changes: 1 addition & 2 deletions src/language/mongoDBService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { CompletionItemKind, CancellationToken, Connection, CompletionItem, Mark
import fs from 'fs';
import path from 'path';
import { signatures } from '@mongosh/shell-api';
import Translator from '@mongosh/i18n/lib/translator';
import translator from '@mongosh/i18n';
import { Worker as WorkerThreads } from 'worker_threads';

import { CollectionItem } from '../types/collectionItemType';
Expand Down Expand Up @@ -399,7 +399,6 @@ export default class MongoDBService {
// Get shell API symbols/methods completion from mongosh.
_getShellCompletionItems(): ShellCompletionItem {
const shellSymbols = {};
const translator = new Translator();

Object.keys(signatures).map((symbol) => {
shellSymbols[symbol] = Object.keys(
Expand Down
12 changes: 7 additions & 5 deletions src/language/worker.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
CliServiceProvider,
NodeOptions
MongoClientOptions
} from '@mongosh/service-provider-server';
import { CompletionItemKind } from 'vscode-languageserver';
import { EJSON } from 'bson';
Expand All @@ -21,7 +21,7 @@ type WorkerError = any | null;
const executeAll = async (
codeToEvaluate: string,
connectionString: string,
connectionOptions: NodeOptions
connectionOptions: MongoClientOptions
): Promise<[WorkerError, WorkerResult?]> => {
try {
// Instantiate a data service provider.
Expand Down Expand Up @@ -53,9 +53,11 @@ const executeAll = async (
? `${source.namespace.db}.${source.namespace.collection}`
: null;
const content =
typeof printable === 'string'
? printable
: JSON.parse(EJSON.stringify(printable));
type === 'Cursor' || type === 'AggregationCursor' ?
JSON.parse(EJSON.stringify(printable.documents)) :
typeof printable === 'string'
? printable
: JSON.parse(EJSON.stringify(printable));
const result: PlaygroundResult = {
namespace,
type: type ? type : typeof printable,
Expand Down
2 changes: 1 addition & 1 deletion src/telemetry/connectionTelemetry.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Document, MongoClient } from 'mongodb';
import type { Document, MongoClient } from 'mongodb';
import { getCloudInfo } from 'mongodb-cloud-info';
import mongoDBBuildInfo from 'mongodb-build-info';

Expand Down
2 changes: 1 addition & 1 deletion src/telemetry/telemetryService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as vscode from 'vscode';
import { config } from 'dotenv';
import fs from 'fs';
import SegmentAnalytics from 'analytics-node';
import { MongoClient } from 'mongodb';
import type { MongoClient } from 'mongodb';

import { ConnectionModel } from '../types/connectionModelType';
import { ConnectionTypes } from '../connectionController';
Expand Down
27 changes: 6 additions & 21 deletions src/test/suite/commands/launchMongoShell.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,7 @@ suite('Commands Test Suite', () => {

const shellCommandText = fakeSendTerminalText.firstCall.args[0];

assert(
shellCommandText === 'mongo $MDB_CONNECTION_STRING;',
'Expected sendText to terminal to be equal mongo $MDB_CONNECTION_STRING;'
);
assert.strictEqual(shellCommandText, 'mongo $MDB_CONNECTION_STRING;');
});

test('openMongoDBShell should open a terminal with ssh tunnel port injected', async () => {
Expand Down Expand Up @@ -126,10 +123,7 @@ suite('Commands Test Suite', () => {

const shellCommandText = fakeSendTerminalText.firstCall.args[0];

assert(
shellCommandText === 'mongo $MDB_CONNECTION_STRING;',
'Expected sendText to terminal to be equal mongo $MDB_CONNECTION_STRING;'
);
assert.strictEqual(shellCommandText, 'mongo $MDB_CONNECTION_STRING;');
});

test('openMongoDBShell should open a terminal with ssl config injected', async () => {
Expand Down Expand Up @@ -160,10 +154,7 @@ suite('Commands Test Suite', () => {

const shellCommandText = fakeSendTerminalText.firstCall.args[0];

assert(
shellCommandText === 'mongo --tls --tlsAllowInvalidHostnames --tlsCAFile="./path_to_some_file" $MDB_CONNECTION_STRING;',
'Expected sendText to terminal to iclude tls options and ssl connection string'
);
assert.strictEqual(shellCommandText, 'mongo --tls --tlsAllowInvalidHostnames --tlsCAFile="./path_to_some_file" $MDB_CONNECTION_STRING;');
});

test('openMongoDBShell should open a terminal with x509 config injected', async () => {
Expand All @@ -189,17 +180,11 @@ suite('Commands Test Suite', () => {
const terminalOptions: vscode.TerminalOptions =
createTerminalStub.firstCall.args[0];

assert(
terminalOptions.env?.MDB_CONNECTION_STRING === driverUri,
`Expected open terminal to set shell arg as driver url "${driverUri}" found "${terminalOptions.env?.MDB_CONNECTION_STRING}"`
);
assert.strictEqual(terminalOptions.env?.MDB_CONNECTION_STRING, driverUri);

const shellCommandText = fakeSendTerminalText.firstCall.args[0];

assert(
shellCommandText === 'mongo --tls --tlsAllowInvalidHostnames --tlsCAFile="./path_to_ca" --tlsCertificateKeyFile="./path_to_cert" $MDB_CONNECTION_STRING;',
'Expected sendText to terminal to iclude tls options and x509 connection string'
);
assert.strictEqual(shellCommandText, 'mongo --tls --tlsAllowInvalidHostnames --tlsCAFile="./path_to_ca" --tlsCertificateKeyFile="./path_to_cert" $MDB_CONNECTION_STRING;');
});
});

Expand Down Expand Up @@ -235,7 +220,7 @@ suite('Commands Test Suite', () => {
const shellCommandText = fakeSendTerminalText.firstCall.args[0];
assert(
shellCommandText.includes('$Env:MDB_CONNECTION_STRING'),
'Expected sendText to terminal to use powershell env variable syntax'
`Expected sendText to terminal (${shellCommandText}) to use powershell env variable syntax`
);
});

Expand Down
2 changes: 1 addition & 1 deletion src/test/suite/explorer/databaseTreeItem.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ suite('DatabaseTreeItem Test Suite', () => {
testDatabaseTreeItem
.getChildren()
.then((newCollectionTreeItems) => {
dataService.disconnect();
dataService.disconnect(() => {});

const postCollapseSchemaTreeItem = newCollectionTreeItems[0].getSchemaChild();
assert(
Expand Down
8 changes: 4 additions & 4 deletions src/test/suite/explorer/fieldTreeItem.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ suite('FieldTreeItem Test Suite', function () {
testSchemaTreeItem
.getChildren()
.then((schemaFields) => {
dataService.disconnect();
dataService.disconnect(() => {});

assert(
schemaFields[0].label === '_id',
Expand Down Expand Up @@ -210,7 +210,7 @@ suite('FieldTreeItem Test Suite', function () {
testSchemaTreeItem.onDidExpand();

testSchemaTreeItem.getChildren().then((schemaFields) => {
dataService.disconnect();
dataService.disconnect(() => {});
assert(
schemaFields.length === 2,
`Expected 2 schema tree items to be returned, recieved ${schemaFields.length}`
Expand Down Expand Up @@ -274,7 +274,7 @@ suite('FieldTreeItem Test Suite', function () {
testSchemaTreeItem.onDidExpand();

testSchemaTreeItem.getChildren().then((schemaFields) => {
dataService.disconnect();
dataService.disconnect(() => {});
assert(
schemaFields.length === 2,
`Expected 2 schema tree items to be returned, recieved ${schemaFields.length}`
Expand Down Expand Up @@ -334,7 +334,7 @@ suite('FieldTreeItem Test Suite', function () {
testSchemaTreeItem.onDidExpand();

testSchemaTreeItem.getChildren().then((schemaFields) => {
dataService.disconnect();
dataService.disconnect(() => {});

schemaFields[1].getChildren().then((nestedSubDocuments) => {
assert(
Expand Down
6 changes: 3 additions & 3 deletions src/test/suite/explorer/schemaTreeItem.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ suite('SchemaTreeItem Test Suite', function () {
testSchemaTreeItem
.getChildren()
.then((schemaFields) => {
dataService.disconnect();
dataService.disconnect(() => {});

assert(
schemaFields.length === 0,
Expand Down Expand Up @@ -285,7 +285,7 @@ suite('SchemaTreeItem Test Suite', function () {
testSchemaTreeItem
.getChildren()
.then((schemaFields) => {
dataService.disconnect();
dataService.disconnect(() => {});
assert(
schemaFields.length === 2,
`Expected 2 schema tree items to be returned, recieved ${schemaFields.length}`
Expand Down Expand Up @@ -338,7 +338,7 @@ suite('SchemaTreeItem Test Suite', function () {
testSchemaTreeItem
.getChildren()
.then((schemaFields) => {
dataService.disconnect();
dataService.disconnect(() => {});
assert(
schemaFields.length === 3,
`Expected 3 schema tree items to be returned, recieved ${schemaFields.length}: ${inspect(schemaFields)}`
Expand Down
2 changes: 1 addition & 1 deletion src/test/suite/telemetry/connectionTelemetry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { ConnectionTypes } from '../../../connectionController';

suite('ConnectionTelemetry Controller Test Suite', () => {
suite('with mock client', () => {
const mockClient = {
const mockClient: any = {
db: () => ({
command: () => ({})
})
Expand Down
1 change: 0 additions & 1 deletion src/types/connectionOptionsType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export type ConnectionOptions = {
password: string;
};
useUnifiedTopology?: boolean;
connectWithNoPrimary?: boolean;
useNewUrlParser?: boolean;
port?: number;
authSource?: string;
Expand Down