Remove typings and replace missing methods with vscodes (#8217)

* remove typings and replace missing methods with vscodes

* fix strict-null-checks

* fix tests
This commit is contained in:
Anthony Dresser
2019-11-05 13:03:20 -08:00
committed by GitHub
parent 4645a8ba6b
commit 22a427f934
184 changed files with 634 additions and 43388 deletions

View File

@@ -17,6 +17,8 @@ import { ConnectionWidget } from 'sql/workbench/services/connection/browser/conn
import { IServerGroupController } from 'sql/platform/serverGroup/common/serverGroupController';
import { ILogService } from 'vs/platform/log/common/log';
import { ConnectionProviderProperties } from 'sql/platform/capabilities/common/capabilitiesService';
import { assign } from 'vs/base/common/objects';
import { find } from 'vs/base/common/arrays';
export class ConnectionController implements IConnectionComponentController {
private _advancedController: AdvancedPropertiesController;
@@ -139,7 +141,7 @@ export class ConnectionController implements IConnectionComponentController {
} else {
defaultGroupId = Utils.defaultGroupId;
}
allGroups.push(Object.assign({}, this._connectionWidget.DefaultServerGroup, { id: defaultGroupId }));
allGroups.push(assign({}, this._connectionWidget.DefaultServerGroup, { id: defaultGroupId }));
allGroups.push(this._connectionWidget.NoneServerGroup);
connectionGroupRoot.forEach(cpg => cpg.dispose());
return allGroups;
@@ -149,7 +151,7 @@ export class ConnectionController implements IConnectionComponentController {
this._connectionWidget.updateServerGroup(this.getAllServerGroups(providers));
this._model = connectionInfo;
this._model.providerName = this._providerName;
let appNameOption = this._providerOptions.find(option => option.specialValueType === ConnectionOptionSpecialType.appName);
let appNameOption = find(this._providerOptions, option => option.specialValueType === ConnectionOptionSpecialType.appName);
if (appNameOption) {
let appNameKey = appNameOption.name;
this._model.options[appNameKey] = Constants.applicationName;

View File

@@ -14,7 +14,6 @@ import * as Constants from 'sql/platform/connection/common/constants';
import { IConnectionProfile } from 'sql/platform/connection/common/interfaces';
import { ICapabilitiesService } from 'sql/platform/capabilities/common/capabilitiesService';
import { ConnectionProfile } from 'sql/platform/connection/common/connectionProfile';
import { entries } from 'sql/base/common/objects';
import { Deferred } from 'sql/base/common/promise';
import { IErrorMessageService } from 'sql/platform/errorMessage/common/errorMessageService';
import { IConnectionDialogService } from 'sql/workbench/services/connection/common/connectionDialogService';
@@ -30,6 +29,8 @@ import { localize } from 'vs/nls';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IWorkbenchLayoutService } from 'vs/workbench/services/layout/browser/layoutService';
import { CmsConnectionController } from 'sql/workbench/services/connection/browser/cmsConnectionController';
import { entries } from 'sql/base/common/collections';
import { find } from 'vs/base/common/arrays';
export interface IConnectionValidateResult {
isValid: boolean;
@@ -136,7 +137,7 @@ export class ConnectionDialogService implements IConnectionDialogService {
if (keys && keys.length > 0) {
if (this._params && this._params.providers && this._params.providers.length > 0) {
//Filter providers from master keys.
filteredKeys = keys.filter(key => this._params.providers.includes(key));
filteredKeys = keys.filter(key => this._params.providers.some(x => x === key));
}
if (filteredKeys && filteredKeys.length > 0) {
defaultProvider = filteredKeys[0];
@@ -307,7 +308,7 @@ export class ConnectionDialogService implements IConnectionDialogService {
});
}
if (!isProviderInParams) {
this._currentProviderType = Object.keys(this._providerNameToDisplayNameMap).find((key) =>
this._currentProviderType = find(Object.keys(this._providerNameToDisplayNameMap), (key) =>
this._providerNameToDisplayNameMap[key] === input.selectedProviderDisplayName &&
key !== Constants.cmsProviderName
);
@@ -472,7 +473,7 @@ export class ConnectionDialogService implements IConnectionDialogService {
// this solves the most common "hard error" that we've noticed
const helpLink = 'https://aka.ms/sqlopskerberos';
let actions: IAction[] = [];
if (!platform.isWindows && types.isString(message) && message.toLowerCase().includes('kerberos') && message.toLowerCase().includes('kinit')) {
if (!platform.isWindows && types.isString(message) && message.toLowerCase().indexOf('kerberos') > -1 && message.toLowerCase().indexOf('kinit') > -1) {
message = [
localize('kerberosErrorStart', "Connection failed due to Kerberos error."),
localize('kerberosHelpLink', "Help configuring Kerberos is available at {0}", helpLink),

View File

@@ -121,7 +121,7 @@ export class ConnectionDialogWidget extends Modal {
if (this._newConnectionParams && this._newConnectionParams.providers) {
const validProviderNames = Object.keys(this.providerNameToDisplayNameMap).filter(x => this.includeProvider(x, this._newConnectionParams));
if (validProviderNames && validProviderNames.length > 0) {
filteredProviderDisplayNames = filteredProviderDisplayNames.filter(x => validProviderNames.find(
filteredProviderDisplayNames = filteredProviderDisplayNames.filter(x => validProviderNames.some(
v => this.providerNameToDisplayNameMap[v] === x) !== undefined
);
}
@@ -134,7 +134,7 @@ export class ConnectionDialogWidget extends Modal {
}
private includeProvider(providerName: string, params?: INewConnectionParams): Boolean {
return params === undefined || params.providers === undefined || params.providers.find(x => x === providerName) !== undefined;
return params === undefined || params.providers === undefined || params.providers.some(x => x === providerName);
}
protected renderBody(container: HTMLElement): void {

View File

@@ -26,7 +26,6 @@ import { IAngularEventingService, AngularEventType } from 'sql/platform/angularE
import * as QueryConstants from 'sql/workbench/parts/query/common/constants';
import { Deferred } from 'sql/base/common/promise';
import { ConnectionOptionSpecialType } from 'sql/workbench/api/common/sqlExtHostTypes';
import { values, entries } from 'sql/base/common/objects';
import { IConnectionProviderRegistry, Extensions as ConnectionProviderExtensions } from 'sql/workbench/parts/connection/common/connectionProviderExtension';
import { IAccountManagementService, AzureResource } from 'sql/platform/accounts/common/interfaces';
@@ -50,6 +49,10 @@ import { IStorageService, StorageScope } from 'vs/platform/storage/common/storag
import { Memento } from 'vs/workbench/common/memento';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { INotificationService } from 'vs/platform/notification/common/notification';
import { entries } from 'sql/base/common/collections';
import { find } from 'vs/base/common/arrays';
import { values } from 'vs/base/common/collections';
import { assign } from 'vs/base/common/objects';
export class ConnectionManagementService extends Disposable implements IConnectionManagementService {
@@ -713,7 +716,7 @@ export class ConnectionManagementService extends Disposable implements IConnecti
}
let accounts = await this._accountManagementService.getAccountsForProvider('azurePublicCloud');
if (accounts && accounts.length > 0) {
let account = accounts.find(account => account.key.accountId === connection.userName);
let account = find(accounts, account => account.key.accountId === connection.userName);
if (account) {
if (account.isStale) {
try {
@@ -729,11 +732,11 @@ export class ConnectionManagementService extends Disposable implements IConnecti
if (tenantId && tokensByTenant[tenantId]) {
token = tokensByTenant[tenantId].token;
} else {
let tokens = Object.values(tokensByTenant);
let tokens = values(tokensByTenant);
if (tokens.length === 0) {
return false;
}
token = Object.values(tokensByTenant)[0].token;
token = values(tokensByTenant)[0].token;
}
connection.options['azureAccountToken'] = token;
connection.options['password'] = '';
@@ -745,7 +748,7 @@ export class ConnectionManagementService extends Disposable implements IConnecti
// Request Senders
private async sendConnectRequest(connection: interfaces.IConnectionProfile, uri: string): Promise<boolean> {
let connectionInfo = Object.assign({}, {
let connectionInfo = assign({}, {
options: connection.options
});
@@ -985,7 +988,7 @@ export class ConnectionManagementService extends Disposable implements IConnecti
];
return this._quickInputService.pick(choices.map(x => x.key), { placeHolder: nls.localize('cancelConnectionConfirmation', "Are you sure you want to cancel this connection?"), ignoreFocusLost: true }).then((choice) => {
let confirm = choices.find(x => x.key === choice);
let confirm = find(choices, x => x.key === choice);
return confirm && confirm.value;
});
}
@@ -1239,13 +1242,13 @@ export class ConnectionManagementService extends Disposable implements IConnecti
}
public getActiveConnectionCredentials(profileId: string): { [name: string]: string } {
let profile = this.getActiveConnections().find(connectionProfile => connectionProfile.id === profileId);
let profile = find(this.getActiveConnections(), connectionProfile => connectionProfile.id === profileId);
if (!profile) {
return undefined;
}
// Find the password option for the connection provider
let passwordOption = this._capabilitiesService.getCapabilities(profile.providerName).connection.connectionOptions.find(
let passwordOption = find(this._capabilitiesService.getCapabilities(profile.providerName).connection.connectionOptions,
option => option.specialValueType === ConnectionOptionSpecialType.password);
if (!passwordOption) {
return undefined;
@@ -1326,7 +1329,7 @@ export class ConnectionManagementService extends Disposable implements IConnecti
const connections = this.getActiveConnections();
const connectionExists: (conn: ConnectionProfile) => boolean = (conn) => {
return connections.find(existingConnection => existingConnection.id === conn.id) !== undefined;
return find(connections, existingConnection => existingConnection.id === conn.id) !== undefined;
};
if (!activeConnectionsOnly) {

View File

@@ -35,6 +35,7 @@ import { endsWith, startsWith } from 'vs/base/common/strings';
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { ILogService } from 'vs/platform/log/common/log';
import { find } from 'vs/base/common/arrays';
export class ConnectionWidget extends lifecycle.Disposable {
private _previousGroupOption: string;
@@ -381,7 +382,7 @@ export class ConnectionWidget extends lifecycle.Disposable {
if (this._refreshCredentialsLink) {
this._register(DOM.addDisposableListener(this._refreshCredentialsLink, DOM.EventType.CLICK, async () => {
let account = this._azureAccountList.find(account => account.key.accountId === this._azureAccountDropdown.value);
let account = find(this._azureAccountList, account => account.key.accountId === this._azureAccountDropdown.value);
if (account) {
await this._accountManagementService.refreshAccount(account);
await this.fillInAzureAccountOptions();
@@ -470,7 +471,7 @@ export class ConnectionWidget extends lifecycle.Disposable {
}
private updateRefreshCredentialsLink(): void {
let chosenAccount = this._azureAccountList.find(account => account.key.accountId === this._azureAccountDropdown.value);
let chosenAccount = find(this._azureAccountList, account => account.key.accountId === this._azureAccountDropdown.value);
if (chosenAccount && chosenAccount.isStale) {
DOM.removeClass(this._tableContainer, 'hide-refresh-link');
} else {
@@ -491,7 +492,7 @@ export class ConnectionWidget extends lifecycle.Disposable {
await this.fillInAzureAccountOptions();
// If a new account was added find it and select it, otherwise select the first account
let newAccount = this._azureAccountList.find(option => !oldAccountIds.some(oldId => oldId === option.key.accountId));
let newAccount = find(this._azureAccountList, option => !oldAccountIds.some(oldId => oldId === option.key.accountId));
if (newAccount) {
this._azureAccountDropdown.selectWithOptionName(newAccount.key.accountId);
} else {
@@ -503,7 +504,7 @@ export class ConnectionWidget extends lifecycle.Disposable {
// Display the tenant select box if needed
const hideTenantsClassName = 'hide-azure-tenants';
let selectedAccount = this._azureAccountList.find(account => account.key.accountId === this._azureAccountDropdown.value);
let selectedAccount = find(this._azureAccountList, account => account.key.accountId === this._azureAccountDropdown.value);
if (selectedAccount && selectedAccount.properties.tenants && selectedAccount.properties.tenants.length > 1) {
// There are multiple tenants available so let the user select one
let options = selectedAccount.properties.tenants.map(tenant => tenant.displayName);
@@ -522,7 +523,7 @@ export class ConnectionWidget extends lifecycle.Disposable {
private onAzureTenantSelected(tenantIndex: number): void {
this._azureTenantId = undefined;
let account = this._azureAccountList.find(account => account.key.accountId === this._azureAccountDropdown.value);
let account = find(this._azureAccountList, account => account.key.accountId === this._azureAccountDropdown.value);
if (account && account.properties.tenants) {
let tenant = account.properties.tenants[tenantIndex];
if (tenant) {
@@ -533,7 +534,7 @@ export class ConnectionWidget extends lifecycle.Disposable {
private serverNameChanged(serverName: string) {
this.setConnectButton();
if (serverName.toLocaleLowerCase().includes('database.windows.net')) {
if (serverName.toLocaleLowerCase().indexOf('database.windows.net') > -1) {
this._callbacks.onSetAzureTimeOut();
}
}
@@ -637,7 +638,7 @@ export class ConnectionWidget extends lifecycle.Disposable {
this._azureAccountDropdown.selectWithOptionName(this.getModelValue(connectionInfo.userName));
await this.onAzureAccountSelected();
let tenantId = connectionInfo.azureTenantId;
let account = this._azureAccountList.find(account => account.key.accountId === this._azureAccountDropdown.value);
let account = find(this._azureAccountList, account => account.key.accountId === this._azureAccountDropdown.value);
if (account && account.properties.tenants.length > 1) {
let tenant = account.properties.tenants.find(tenant => tenant.id === tenantId);
if (tenant) {
@@ -834,19 +835,19 @@ export class ConnectionWidget extends lifecycle.Disposable {
private findGroupId(groupFullName: string): string {
let group: IConnectionProfileGroup;
if (ConnectionProfileGroup.isRoot(groupFullName)) {
group = this._serverGroupOptions.find(g => ConnectionProfileGroup.isRoot(g.name));
group = find(this._serverGroupOptions, g => ConnectionProfileGroup.isRoot(g.name));
if (group === undefined) {
group = this._serverGroupOptions.find(g => g.name === this.DefaultServerGroup.name);
group = find(this._serverGroupOptions, g => g.name === this.DefaultServerGroup.name);
}
} else {
group = this._serverGroupOptions.find(g => g.name === groupFullName);
group = find(this._serverGroupOptions, g => g.name === groupFullName);
}
return group ? group.id : undefined;
}
private getMatchingAuthType(displayName: string): AuthenticationType {
const authType = this._authTypeMap[this._providerName];
return authType ? authType.find(authType => this.getAuthTypeDisplayName(authType) === displayName) : undefined;
return authType ? find(authType, authType => this.getAuthTypeDisplayName(authType) === displayName) : undefined;
}
public closeDatabaseDropdown(): void {