Skip to content

Commit

Permalink
chore(webview): remove old form VSCODE-491 (#636)
Browse files Browse the repository at this point in the history
  • Loading branch information
Anemy authored Jan 10, 2024
1 parent 6f2017f commit 74dd970
Show file tree
Hide file tree
Showing 103 changed files with 314 additions and 9,123 deletions.
1 change: 0 additions & 1 deletion .depcheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ ignores:
- "@types/jest"
- "buffer"
- "eslint-config-mongodb-js"
- "electron"
- "mocha-junit-reporter"
- "mocha-multi"
- "mongodb-client-encryption"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/actions/test-and-build/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ runs:

- name: Build .vsix
env:
NODE_OPTIONS: "--require ./scripts/no-npm-list-fail.js --max_old_space_size=4096"
NODE_OPTIONS: "--require ./scripts/no-npm-list-fail.js"
# NOTE: --githubBranch is "The GitHub branch used to infer relative links in README.md."
run: |
npx vsce package --githubBranch main
Expand Down
2,134 changes: 228 additions & 1,906 deletions package-lock.json

Large diffs are not rendered by default.

19 changes: 2 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1036,13 +1036,9 @@
"dependencies": {
"@babel/parser": "^7.22.6",
"@babel/traverse": "^7.23.2",
"@fortawesome/fontawesome-svg-core": "^6.4.0",
"@fortawesome/free-solid-svg-icons": "^6.4.0",
"@fortawesome/react-fontawesome": "^0.2.0",
"@iconify-icons/codicon": "^1.2.25",
"@iconify/react": "^1.1.4",
"@mongodb-js/compass-components": "^1.20.0",
"@mongodb-js/connection-form": "^1.20.4",
"@mongodb-js/connection-info": "^0.1.1",
"@mongodb-js/mongodb-constants": "^0.7.1",
"@mongosh/browser-runtime-electron": "^2.0.2",
"@mongosh/i18n": "^2.0.2",
Expand All @@ -1051,7 +1047,6 @@
"@segment/analytics-node": "^1.1.4",
"bson": "^6.1.0",
"bson-transpilers": "^2.0.4",
"classnames": "^2.3.2",
"debug": "^4.3.4",
"dotenv": "^16.3.1",
"lodash": "^4.17.21",
Expand All @@ -1060,16 +1055,13 @@
"mongodb-build-info": "^1.6.2",
"mongodb-cloud-info": "^2.1.0",
"mongodb-connection-string-url": "^2.6.0",
"mongodb-data-service": "^22.17.1",
"mongodb-data-service-legacy": "npm:[email protected]",
"mongodb-data-service": "^22.17.0",
"mongodb-log-writer": "^1.4.0",
"mongodb-query-parser": "^3.1.3",
"mongodb-schema": "^11.2.2",
"numeral": "^2.0.6",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-redux": "^8.1.1",
"redux": "^4.2.1",
"resolve-mongodb-srv": "^1.1.2",
"ts-log": "^2.2.5",
"uuid": "^8.3.2",
Expand All @@ -1088,7 +1080,6 @@
"@types/babel__traverse": "^7.20.1",
"@types/chai": "^4.3.5",
"@types/debug": "^4.1.8",
"@types/enzyme": "^3.10.13",
"@types/glob": "^7.2.0",
"@types/jest": "^26.0.24",
"@types/micromatch": "^4.0.2",
Expand All @@ -1114,7 +1105,6 @@
"css-loader": "^6.8.1",
"depcheck": "^1.4.3",
"duplicate-package-checker-webpack-plugin": "^3.0.0",
"electron": "^23.3.9",
"enzyme": "^3.11.0",
"eslint": "^8.44.0",
"eslint-config-mongodb-js": "^5.0.3",
Expand Down Expand Up @@ -1154,11 +1144,6 @@
"webpack-merge": "^5.9.0",
"xvfb-maybe": "^0.2.1"
},
"overrides": {
"mongodb-connection-model": {
"@mongodb-js/compass-utils": "0.3.4"
}
},
"precommit": [
"check"
]
Expand Down
2 changes: 1 addition & 1 deletion scripts/check-vsix-size.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const vsixFileName = path.resolve(
);
const size = fs.statSync(vsixFileName).size;

const maxSize = 8_500_000; // 8.5 MB
const maxSize = 8_000_000;

if (size >= maxSize) {
throw new Error(
Expand Down
41 changes: 9 additions & 32 deletions src/connectionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,20 @@ import { connect, createConnectionAttempt } from 'mongodb-data-service';
import type {
DataService,
ConnectionAttempt,
ConnectionOptions as ConnectionOptionsFromCurrentDS,
ConnectionOptions,
} from 'mongodb-data-service';
import ConnectionString from 'mongodb-connection-string-url';
import { EventEmitter } from 'events';
import type { MongoClientOptions } from 'mongodb';
import { v4 as uuidv4 } from 'uuid';
import { cloneDeep, merge } from 'lodash';
import { mongoLogId } from 'mongodb-log-writer';
import type {
ConnectionInfo as ConnectionInfoFromLegacyDS,
ConnectionOptions as ConnectionOptionsFromLegacyDS,
} from 'mongodb-data-service-legacy';
import {
extractSecrets,
convertConnectionModelToInfo,
} from 'mongodb-data-service-legacy';
import { extractSecrets } from '@mongodb-js/connection-info';
import { adjustConnectionOptionsBeforeConnect } from '@mongodb-js/connection-form';

import { CONNECTION_STATUS } from './views/webview-app/extension-app-message-constants';
import { createLogger } from './logging';
import formatError from './utils/formatError';
import type LegacyConnectionModel from './views/webview-app/legacy/connection-model/legacy-connection-model';
import type { StorageController } from './storage';
import type { StatusView } from './views';
import type TelemetryService from './telemetry/telemetryService';
Expand Down Expand Up @@ -75,13 +67,6 @@ type RecursivePartial<T> = {
: T[P];
};

export function launderConnectionOptionTypeFromLegacyToCurrent(
opts: ConnectionOptionsFromLegacyDS
): ConnectionOptionsFromCurrentDS {
// Ensure that, at most, the types for OIDC mismatch here.
return opts as Omit<typeof opts, 'oidc'>;
}

export default class ConnectionController {
// This is a map of connection ids to their configurations.
// These connections can be saved on the session (runtime),
Expand Down Expand Up @@ -244,25 +229,19 @@ export default class ConnectionController {
);
}

parseNewConnection(
rawConnectionModel: LegacyConnectionModel
): ConnectionInfoFromLegacyDS {
return convertConnectionModelToInfo({
...rawConnectionModel,
appname: `${packageJSON.name} ${packageJSON.version}`, // Override the default connection appname.
});
}

async saveNewConnectionAndConnect(
originalConnectionInfo: ConnectionInfoFromLegacyDS,
connection: {
connectionOptions: ConnectionOptions;
id: string;
},
connectionType: ConnectionTypes
): Promise<ConnectionAttemptResult> {
const savedConnectionWithoutSecrets =
await this._connectionStorage.saveNewConnection(originalConnectionInfo);
await this._connectionStorage.saveNewConnection(connection);

this._connections[savedConnectionWithoutSecrets.id] = {
...savedConnectionWithoutSecrets,
connectionOptions: originalConnectionInfo.connectionOptions, // The connection options with secrets.
connectionOptions: connection.connectionOptions, // The connection options with secrets.
};

log.info(
Expand Down Expand Up @@ -326,9 +305,7 @@ export default class ConnectionController {
let dataService;
try {
const connectionOptions = adjustConnectionOptionsBeforeConnect({
connectionOptions: launderConnectionOptionTypeFromLegacyToCurrent(
connectionInfo.connectionOptions
),
connectionOptions: connectionInfo.connectionOptions,
defaultAppName: packageJSON.name,
notifyDeviceFlow: undefined,
preferences: {
Expand Down
22 changes: 11 additions & 11 deletions src/storage/connectionStorage.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import * as vscode from 'vscode';
import type {
ConnectionInfo as ConnectionInfoFromLegacyDS,
ConnectionOptions as ConnectionOptionsFromLegacyDS,
} from 'mongodb-data-service-legacy';
import {
getConnectionTitle,
extractSecrets,
mergeSecrets,
} from 'mongodb-data-service-legacy';
} from '@mongodb-js/connection-info';
import type { ConnectionOptions } from 'mongodb-data-service';

import { createLogger } from '../logging';
import type StorageController from './storageController';
Expand All @@ -26,7 +23,7 @@ export interface StoreConnectionInfo {
name: string; // Possibly user given name, not unique.
storageLocation: StorageLocation;
secretStorageLocation?: SecretStorageLocationType;
connectionOptions?: ConnectionOptionsFromLegacyDS;
connectionOptions?: ConnectionOptions;
}

type StoreConnectionInfoWithConnectionOptions = StoreConnectionInfo &
Expand All @@ -46,16 +43,19 @@ export class ConnectionStorage {
}

// Returns the saved connection (without secrets).
async saveNewConnection(originalConnectionInfo: ConnectionInfoFromLegacyDS) {
const name = getConnectionTitle(originalConnectionInfo);
async saveNewConnection(connection: {
connectionOptions: ConnectionOptions;
id: string;
}): Promise<LoadedConnection> {
const name = getConnectionTitle(connection);
const newConnectionInfo = {
id: originalConnectionInfo.id,
id: connection.id,
name,
// To begin we just store it on the session, the storage controller
// handles changing this based on user preference.
storageLocation: StorageLocation.NONE,
secretStorageLocation: SecretStorageLocation.SecretStorage,
connectionOptions: originalConnectionInfo.connectionOptions,
connectionOptions: connection.connectionOptions,
};

return await this.saveConnectionWithSecrets(newConnectionInfo);
Expand Down Expand Up @@ -147,7 +147,7 @@ export class ConnectionStorage {
): Promise<LoadedConnection> {
// We don't want to store secrets to disc.
const { connectionInfo: safeConnectionInfo, secrets } = extractSecrets(
newStoreConnectionInfoWithSecrets as ConnectionInfoFromLegacyDS
newStoreConnectionInfoWithSecrets
);
const savedConnectionInfo = await this.saveConnection({
...newStoreConnectionInfoWithSecrets,
Expand Down
42 changes: 1 addition & 41 deletions src/test/suite/connectionController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ import { afterEach, beforeEach } from 'mocha';
import assert from 'assert';
import * as mongodbDataService from 'mongodb-data-service';

import AUTH_STRATEGY_VALUES from '../../views/webview-app/legacy/connection-model/constants/auth-strategies';
import ConnectionController, {
DataServiceEventTypes,
launderConnectionOptionTypeFromLegacyToCurrent,
} from '../../connectionController';
import formatError from '../../utils/formatError';
import { StorageController, StorageVariables } from '../../storage';
Expand All @@ -18,9 +16,6 @@ import {
DefaultSavingLocations,
SecretStorageLocation,
} from '../../storage/storageController';
import READ_PREFERENCES from '../../views/webview-app/legacy/connection-model/constants/read-preferences';
import SSH_TUNNEL_TYPES from '../../views/webview-app/legacy/connection-model/constants/ssh-tunnel-types';
import SSL_METHODS from '../../views/webview-app/legacy/connection-model/constants/ssl-methods';
import { StatusView } from '../../views';
import TelemetryService from '../../telemetry/telemetryService';
import { ExtensionContextStub } from './stubs';
Expand Down Expand Up @@ -762,9 +757,7 @@ suite('Connection Controller Test Suite', function () {
await sleep(50);

return mongodbDataService.connect({
connectionOptions: launderConnectionOptionTypeFromLegacyToCurrent(
connectionOptions.connectionOptions
),
connectionOptions: connectionOptions.connectionOptions,
});
}
);
Expand Down Expand Up @@ -868,39 +861,6 @@ suite('Connection Controller Test Suite', function () {
);
});

test('parseNewConnection converts a connection model to a connection info and overrides a default appname', () => {
const connectionInfo = testConnectionController.parseNewConnection({
_id: 'c4871b21-92c4-40e2-a2c2-fdd551cff114',
isFavorite: false,
name: 'Local',
isSrvRecord: true,
hostname: 'host.u88dd.test.test',
port: 27017,
hosts: [
{ host: 'host-shard-00-00.u88dd.test.test', port: 27017 },
{ host: 'host-shard-00-01.u88dd.test.test', port: 27017 },
{ host: 'host-shard-00-02.u88dd.test.test', port: 27017 },
],
extraOptions: {},
readPreference: READ_PREFERENCES.PRIMARY,
authStrategy: AUTH_STRATEGY_VALUES.MONGODB,
kerberosCanonicalizeHostname: false,
sslMethod: SSL_METHODS.SYSTEMCA,
sshTunnel: SSH_TUNNEL_TYPES.NONE,
sshTunnelPort: 22,
mongodbUsername: 'username',
mongodbPassword: 'somepassword',
mongodbDatabaseName: 'admin',
});

assert.deepStrictEqual(connectionInfo, {
id: 'c4871b21-92c4-40e2-a2c2-fdd551cff114',
connectionOptions: {
connectionString: `mongodb+srv://username:[email protected]/?authSource=admin&readPreference=primary&appname=mongodb-vscode+${version}&ssl=true`,
},
});
});

test('getMongoClientConnectionOptions returns url and options properties', async () => {
await testConnectionController.addNewConnectionStringAndConnect(
TEST_DATABASE_URI
Expand Down
4 changes: 1 addition & 3 deletions src/test/suite/language/mongoDBService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import MongoDBService, {
} from '../../../language/mongoDBService';
import { mdbTestExtension } from '../stubbableMdbExtension';
import { StreamStub } from '../stubs';
import READ_PREFERENCES from '../../../views/webview-app/legacy/connection-model/constants/read-preferences';
import DIAGNOSTIC_CODES from '../../../language/diagnosticCodes';
import { ServerCommands } from '../../../language/serverCommands';
import LINKS from '../../../utils/links';
Expand All @@ -35,7 +34,6 @@ suite('MongoDBService Test Suite', () => {
connectionId: 'pineapple',
connectionString: 'mongodb://localhost:27088',
connectionOptions: {
readPreference: READ_PREFERENCES.PRIMARY,
productDocsLink: LINKS.extensionDocs(),
productName: 'MongoDB for VS Code',
},
Expand Down Expand Up @@ -2565,7 +2563,7 @@ suite('MongoDBService Test Suite', () => {
this.timeout(INCREASED_TEST_TIMEOUT);

const mongoClient = new MongoClient(params.connectionString, {
readPreference: params.connectionOptions.readPreference,
readPreference: 'primary',
});
const up = new StreamStub();
const down = new StreamStub();
Expand Down
12 changes: 4 additions & 8 deletions src/test/suite/storage/connectionStorage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,12 @@ import * as vscode from 'vscode';
import { afterEach, beforeEach } from 'mocha';
import { expect } from 'chai';

import AUTH_STRATEGY_VALUES from '../../../views/webview-app/legacy/connection-model/constants/auth-strategies';
import { StorageController, StorageVariables } from '../../../storage';
import {
StorageLocation,
DefaultSavingLocations,
SecretStorageLocation,
} from '../../../storage/storageController';
import READ_PREFERENCES from '../../../views/webview-app/legacy/connection-model/constants/read-preferences';
import SSH_TUNNEL_TYPES from '../../../views/webview-app/legacy/connection-model/constants/ssh-tunnel-types';
import SSL_METHODS from '../../../views/webview-app/legacy/connection-model/constants/ssl-methods';
import { ExtensionContextStub } from '../stubs';
import {
TEST_DATABASE_URI,
Expand Down Expand Up @@ -260,11 +256,11 @@ suite('Connection Storage Test Suite', function () {
hosts: [{ host: 'localhost', port: 27017 }],
extraOptions: {},
connectionType: 'NODE_DRIVER',
authStrategy: AUTH_STRATEGY_VALUES.NONE,
readPreference: READ_PREFERENCES.PRIMARY,
authStrategy: 'NONE',
readPreference: 'primary',
kerberosCanonicalizeHostname: false,
sslMethod: SSL_METHODS.NONE,
sshTunnel: SSH_TUNNEL_TYPES.NONE,
sslMethod: 'NONE',
sshTunnel: 'NONE',
sshTunnelPort: 22,
},
};
Expand Down
3 changes: 0 additions & 3 deletions src/test/suite/views/webview-app/jest-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ const { TextEncoder, TextDecoder } = require('util');
chai.use(require('sinon-chai'));
Enzyme.configure({ adapter: new Adapter() });

// eslint-disable-next-line no-undef
jest.mock('@iconify-icons/codicon/book', () => {});

// Note applied with js dom so we do manually. (Required by node_modules/mongodb-connection-string-url/node_modules/whatwg-url/lib/encoding.js)
Object.assign(global, { TextDecoder, TextEncoder });

Expand Down
Loading

0 comments on commit 74dd970

Please sign in to comment.