mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-24 09:35:37 -05:00
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:
@@ -20,6 +20,8 @@ import { Deferred } from 'sql/base/common/promise';
|
||||
import { localize } from 'vs/nls';
|
||||
import { IOpenerService } from 'vs/platform/opener/common/opener';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { firstIndex } from 'vs/base/common/arrays';
|
||||
import { values } from 'vs/base/common/collections';
|
||||
|
||||
export class AccountManagementService implements IAccountManagementService {
|
||||
// CONSTANTS ///////////////////////////////////////////////////////////
|
||||
@@ -166,7 +168,7 @@ export class AccountManagementService implements IAccountManagementService {
|
||||
}
|
||||
if (result.accountModified) {
|
||||
// Find the updated account and splice the updated on in
|
||||
let indexToRemove: number = provider.accounts.findIndex(account => {
|
||||
let indexToRemove: number = firstIndex(provider.accounts, account => {
|
||||
return account.key.accountId === result.changedAccount.key.accountId;
|
||||
});
|
||||
if (indexToRemove >= 0) {
|
||||
@@ -184,7 +186,7 @@ export class AccountManagementService implements IAccountManagementService {
|
||||
* @returns Registered account providers
|
||||
*/
|
||||
public getAccountProviderMetadata(): Thenable<azdata.AccountProviderMetadata[]> {
|
||||
return Promise.resolve(Object.values(this._providers).map(provider => provider.metadata));
|
||||
return Promise.resolve(values(this._providers).map(provider => provider.metadata));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -241,7 +243,7 @@ export class AccountManagementService implements IAccountManagementService {
|
||||
return result;
|
||||
}
|
||||
|
||||
let indexToRemove: number = provider.accounts.findIndex(account => {
|
||||
let indexToRemove: number = firstIndex(provider.accounts, account => {
|
||||
return account.key.accountId === accountKey.accountId;
|
||||
});
|
||||
|
||||
@@ -423,7 +425,7 @@ export class AccountManagementService implements IAccountManagementService {
|
||||
|
||||
private spliceModifiedAccount(provider: AccountProviderWithMetadata, modifiedAccount: azdata.Account) {
|
||||
// Find the updated account and splice the updated one in
|
||||
let indexToRemove: number = provider.accounts.findIndex(account => {
|
||||
let indexToRemove: number = firstIndex(provider.accounts, account => {
|
||||
return account.key.accountId === modifiedAccount.key.accountId;
|
||||
});
|
||||
if (indexToRemove >= 0) {
|
||||
|
||||
@@ -17,6 +17,7 @@ import { BackupDialog } from 'sql/workbench/parts/backup/browser/backupDialog';
|
||||
import { OptionsDialog } from 'sql/workbench/browser/modal/optionsDialog';
|
||||
import { IBackupService, TaskExecutionMode } from 'sql/platform/backup/common/backupService';
|
||||
import { IBackupUiService } from 'sql/workbench/services/backup/common/backupUiService';
|
||||
import { find } from 'vs/base/common/arrays';
|
||||
|
||||
export class BackupUiService implements IBackupUiService {
|
||||
public _serviceBrand: undefined;
|
||||
@@ -50,7 +51,7 @@ export class BackupUiService implements IBackupUiService {
|
||||
}
|
||||
|
||||
private getOptions(provider: string): azdata.ServiceOption[] {
|
||||
let feature = this._capabilitiesService.getLegacyCapabilities(this._currentProvider).features.find(f => f.featureName === 'backup');
|
||||
let feature = find(this._capabilitiesService.getLegacyCapabilities(this._currentProvider).features, f => f.featureName === 'backup');
|
||||
if (feature) {
|
||||
return feature.optionsMetadata;
|
||||
} else {
|
||||
|
||||
@@ -13,10 +13,11 @@ import { Registry } from 'vs/platform/registry/common/platform';
|
||||
|
||||
import * as azdata from 'azdata';
|
||||
|
||||
import { entries } from 'sql/base/common/objects';
|
||||
import { toObject } from 'sql/base/common/map';
|
||||
import { IConnectionProviderRegistry, Extensions as ConnectionExtensions } from 'sql/workbench/parts/connection/common/connectionProviderExtension';
|
||||
import { ICapabilitiesService, ProviderFeatures, clientCapabilities, ConnectionProviderProperties } from 'sql/platform/capabilities/common/capabilitiesService';
|
||||
import { find } from 'vs/base/common/arrays';
|
||||
import { entries } from 'sql/base/common/collections';
|
||||
|
||||
const connectionRegistry = Registry.as<IConnectionProviderRegistry>(ConnectionExtensions.ConnectionProviderContributions);
|
||||
|
||||
@@ -77,7 +78,7 @@ export class CapabilitiesService extends Disposable implements ICapabilitiesServ
|
||||
this._register(extensionManagementService.onDidUninstallExtension(({ identifier }) => {
|
||||
const connectionProvider = 'connectionProvider';
|
||||
extensionService.getExtensions().then(i => {
|
||||
let extension = i.find(c => c.identifier.value.toLowerCase() === identifier.id.toLowerCase());
|
||||
let extension = find(i, c => c.identifier.value.toLowerCase() === identifier.id.toLowerCase());
|
||||
if (extension && extension.contributes
|
||||
&& extension.contributes[connectionProvider]
|
||||
&& extension.contributes[connectionProvider].providerId) {
|
||||
@@ -91,7 +92,7 @@ export class CapabilitiesService extends Disposable implements ICapabilitiesServ
|
||||
private cleanupProviders(): void {
|
||||
let knownProviders = Object.keys(connectionRegistry.providers);
|
||||
for (let key in this.capabilities.connectionProviderCache) {
|
||||
if (!knownProviders.includes(key)) {
|
||||
if (!knownProviders.some(x => x === key)) {
|
||||
this._providers.delete(key);
|
||||
delete this.capabilities.connectionProviderCache[key];
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -32,6 +32,7 @@ import { TestStorageService, TestEnvironmentService, TestEditorService } from 'v
|
||||
import { TestNotificationService } from 'vs/platform/notification/test/common/testNotificationService';
|
||||
import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService';
|
||||
import { NullLogService } from 'vs/platform/log/common/log';
|
||||
import { assign } from 'vs/base/common/objects';
|
||||
|
||||
suite('SQL ConnectionManagementService tests', () => {
|
||||
|
||||
@@ -65,9 +66,9 @@ suite('SQL ConnectionManagementService tests', () => {
|
||||
id: undefined
|
||||
};
|
||||
let connectionProfileWithEmptySavedPassword: IConnectionProfile =
|
||||
Object.assign({}, connectionProfile, { password: '', serverName: connectionProfile.serverName + 1 });
|
||||
assign({}, connectionProfile, { password: '', serverName: connectionProfile.serverName + 1 });
|
||||
let connectionProfileWithEmptyUnsavedPassword: IConnectionProfile =
|
||||
Object.assign({}, connectionProfile, { password: '', serverName: connectionProfile.serverName + 2, savePassword: false });
|
||||
assign({}, connectionProfile, { password: '', serverName: connectionProfile.serverName + 2, savePassword: false });
|
||||
|
||||
let connectionManagementService: ConnectionManagementService;
|
||||
let configResult: { [key: string]: any } = {};
|
||||
@@ -758,9 +759,9 @@ suite('SQL ConnectionManagementService tests', () => {
|
||||
let dbName = 'master';
|
||||
let serverName = 'test_server';
|
||||
let userName = 'test_user';
|
||||
let connectionProfileWithoutDb: IConnectionProfile = Object.assign(connectionProfile,
|
||||
let connectionProfileWithoutDb: IConnectionProfile = assign(connectionProfile,
|
||||
{ serverName: serverName, databaseName: '', userName: userName, getOptionsKey: () => undefined });
|
||||
let connectionProfileWithDb: IConnectionProfile = Object.assign(connectionProfileWithoutDb, { databaseName: dbName });
|
||||
let connectionProfileWithDb: IConnectionProfile = assign(connectionProfileWithoutDb, { databaseName: dbName });
|
||||
// Save the database with a URI that has the database name filled in, to mirror Carbon's behavior
|
||||
let ownerUri = Utils.generateUri(connectionProfileWithDb);
|
||||
connect(ownerUri, undefined, false, connectionProfileWithoutDb).then(() => {
|
||||
@@ -806,7 +807,7 @@ suite('SQL ConnectionManagementService tests', () => {
|
||||
});
|
||||
|
||||
test('getActiveConnectionCredentials returns the credentials dictionary for a connection profile', () => {
|
||||
let profile = Object.assign({}, connectionProfile);
|
||||
let profile = assign({}, connectionProfile);
|
||||
profile.options = { password: profile.password };
|
||||
profile.id = 'test_id';
|
||||
connectionStatusManager.addConnection(profile, 'test_uri');
|
||||
@@ -816,7 +817,7 @@ suite('SQL ConnectionManagementService tests', () => {
|
||||
});
|
||||
|
||||
test('getConnectionUriFromId returns a URI of an active connection with the given id', () => {
|
||||
let profile = Object.assign({}, connectionProfile);
|
||||
let profile = assign({}, connectionProfile);
|
||||
profile.options = { password: profile.password };
|
||||
profile.id = 'test_id';
|
||||
let uri = 'test_initial_uri';
|
||||
@@ -831,7 +832,7 @@ suite('SQL ConnectionManagementService tests', () => {
|
||||
});
|
||||
|
||||
test('getConectionUriFromId returns undefined if the given connection is not active', () => {
|
||||
let profile = Object.assign({}, connectionProfile);
|
||||
let profile = assign({}, connectionProfile);
|
||||
profile.options = { password: profile.password };
|
||||
profile.id = 'test_id';
|
||||
connectionStatusManager.addConnection(profile, Utils.generateUri(profile));
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
import { Event, Emitter } from 'vs/base/common/event';
|
||||
|
||||
import { IDashboardTab } from 'sql/workbench/parts/dashboard/browser/dashboardRegistry';
|
||||
import { find } from 'vs/base/common/arrays';
|
||||
|
||||
|
||||
export interface IDashboardUITab {
|
||||
@@ -34,7 +35,7 @@ export class NewDashboardTabViewModel {
|
||||
tabList.push({ tabConfig: tab });
|
||||
});
|
||||
openedTabs.forEach(tab => {
|
||||
let uiTab = tabList.find(i => i.tabConfig === tab);
|
||||
let uiTab = find(tabList, i => i.tabConfig === tab);
|
||||
if (uiTab) {
|
||||
uiTab.isOpened = true;
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ import { InputBox } from 'sql/platform/browser/inputbox/inputBox.component';
|
||||
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { Registry } from 'vs/platform/registry/common/platform';
|
||||
import { IBootstrapParams, ISelector } from 'sql/workbench/services/bootstrap/common/bootstrapParams';
|
||||
import { startsWith } from 'vs/base/common/strings';
|
||||
|
||||
export const DialogModule = (params, selector: string, instantiationService: IInstantiationService): any => {
|
||||
|
||||
@@ -68,7 +69,7 @@ export const DialogModule = (params, selector: string, instantiationService: IIn
|
||||
}
|
||||
|
||||
ngDoBootstrap(appRef: ApplicationRef) {
|
||||
let componentClass = this.selector.startsWith(WizardNavigation.SELECTOR) ? WizardNavigation : DialogContainer;
|
||||
let componentClass = startsWith(this.selector, WizardNavigation.SELECTOR) ? WizardNavigation : DialogContainer;
|
||||
const factoryWrapper: any = this._resolver.resolveComponentFactory<WizardNavigation | DialogContainer>(componentClass);
|
||||
factoryWrapper.factory.selector = this.selector;
|
||||
appRef.bootstrap(factoryWrapper);
|
||||
|
||||
@@ -338,7 +338,7 @@ export class InsightsDialogView extends Modal {
|
||||
if (this._insight.actions && this._insight.actions.types) {
|
||||
let tasks = TaskRegistry.getTasks();
|
||||
for (let action of this._insight.actions.types) {
|
||||
let task = tasks.includes(action);
|
||||
let task = tasks.some(x => x === action);
|
||||
let commandAction = MenuRegistry.getCommand(action);
|
||||
let commandLabel = types.isString(commandAction.title) ? commandAction.title : commandAction.title.value;
|
||||
if (task) {
|
||||
@@ -397,7 +397,7 @@ export class InsightsDialogView extends Modal {
|
||||
let actions = this._insight.actions.types;
|
||||
let returnActions: IAction[] = [];
|
||||
for (let action of actions) {
|
||||
let task = tasks.includes(action);
|
||||
let task = tasks.some(x => x === action);
|
||||
let commandAction = MenuRegistry.getCommand(action);
|
||||
if (task) {
|
||||
returnActions.push(this._instantiationService.createInstance(ExecuteCommandAction, commandAction.id, commandAction.title));
|
||||
|
||||
@@ -42,6 +42,7 @@ import { ILogService } from 'vs/platform/log/common/log';
|
||||
import { toErrorMessage } from 'vs/base/common/errorMessage';
|
||||
import { NotebookChangeType } from 'sql/workbench/parts/notebook/common/models/contracts';
|
||||
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
|
||||
import { find, firstIndex } from 'vs/base/common/arrays';
|
||||
|
||||
export interface NotebookProviderProperties {
|
||||
provider: string;
|
||||
@@ -212,7 +213,7 @@ export class NotebookService extends Disposable implements INotebookService {
|
||||
let sqlNotebookProvider = this._providerToStandardKernels.get(notebookConstants.SQL);
|
||||
if (sqlNotebookProvider) {
|
||||
let sqlConnectionTypes = this._queryManagementService.getRegisteredProviders();
|
||||
let provider = sqlNotebookProvider.find(p => p.name === notebookConstants.SQL);
|
||||
let provider = find(sqlNotebookProvider, p => p.name === notebookConstants.SQL);
|
||||
if (provider) {
|
||||
this._providerToStandardKernels.set(notebookConstants.SQL, [{
|
||||
name: notebookConstants.SQL,
|
||||
@@ -353,7 +354,7 @@ export class NotebookService extends Disposable implements INotebookService {
|
||||
let managers: INotebookManager[] = this._managersMap.get(uriString);
|
||||
// If manager already exists for a given notebook, return it
|
||||
if (managers) {
|
||||
let index = managers.findIndex(m => m.providerId === providerId);
|
||||
let index = firstIndex(managers, m => m.providerId === providerId);
|
||||
if (index && index >= 0) {
|
||||
return managers[index];
|
||||
}
|
||||
@@ -404,7 +405,7 @@ export class NotebookService extends Disposable implements INotebookService {
|
||||
return undefined;
|
||||
}
|
||||
let uriString = notebookUri.toString();
|
||||
let editor = this.listNotebookEditors().find(n => n.id === uriString);
|
||||
let editor = find(this.listNotebookEditors(), n => n.id === uriString);
|
||||
return editor;
|
||||
}
|
||||
|
||||
@@ -512,7 +513,7 @@ export class NotebookService extends Disposable implements INotebookService {
|
||||
let knownProviders = Object.keys(notebookRegistry.providers);
|
||||
let cache = this.providersMemento.notebookProviderCache;
|
||||
for (let key in cache) {
|
||||
if (!knownProviders.includes(key)) {
|
||||
if (!knownProviders.some(x => x === key)) {
|
||||
this._providers.delete(key);
|
||||
delete cache[key];
|
||||
}
|
||||
@@ -532,7 +533,7 @@ export class NotebookService extends Disposable implements INotebookService {
|
||||
private removeContributedProvidersFromCache(identifier: IExtensionIdentifier, extensionService: IExtensionService) {
|
||||
const notebookProvider = 'notebookProvider';
|
||||
extensionService.getExtensions().then(i => {
|
||||
let extension = i.find(c => c.identifier.value.toLowerCase() === identifier.id.toLowerCase());
|
||||
let extension = find(i, c => c.identifier.value.toLowerCase() === identifier.id.toLowerCase());
|
||||
if (extension && extension.contributes
|
||||
&& extension.contributes[notebookProvider]
|
||||
&& extension.contributes[notebookProvider].providerId) {
|
||||
@@ -584,9 +585,9 @@ export class NotebookService extends Disposable implements INotebookService {
|
||||
// 3. Not already saving (e.g. isn't in the queue to be cached)
|
||||
// 4. Notebook is trusted. Don't need to save state of untrusted notebooks
|
||||
let notebookUriString = notebookUri.toString();
|
||||
if (changeType === NotebookChangeType.Saved && this._trustedCacheQueue.findIndex(uri => uri.toString() === notebookUriString) < 0) {
|
||||
if (changeType === NotebookChangeType.Saved && firstIndex(this._trustedCacheQueue, uri => uri.toString() === notebookUriString) < 0) {
|
||||
// Only save if it's trusted
|
||||
let notebook = this.listNotebookEditors().find(n => n.id === notebookUriString);
|
||||
let notebook = find(this.listNotebookEditors(), n => n.id === notebookUriString);
|
||||
if (notebook && notebook.model.trustedMode) {
|
||||
this._trustedCacheQueue.push(notebookUri);
|
||||
this._updateTrustCacheScheduler.schedule();
|
||||
|
||||
@@ -25,6 +25,8 @@ import { ILanguageMagic } from 'sql/workbench/services/notebook/browser/notebook
|
||||
import { ITextResourcePropertiesService } from 'vs/editor/common/services/resourceConfiguration';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { getUriPrefix, uriPrefixes } from 'sql/platform/connection/common/utils';
|
||||
import { firstIndex } from 'vs/base/common/arrays';
|
||||
import { startsWith } from 'vs/base/common/strings';
|
||||
|
||||
export const sqlKernelError: string = localize("sqlKernelError", "SQL kernel error");
|
||||
export const MAX_ROWS = 5000;
|
||||
@@ -71,7 +73,7 @@ export class SqlSessionManager implements nb.SessionManager {
|
||||
|
||||
startNew(options: nb.ISessionOptions): Thenable<nb.ISession> {
|
||||
let sqlSession = new SqlSession(options, this._instantiationService);
|
||||
let index = SqlSessionManager._sessions.findIndex(session => session.path === options.path);
|
||||
let index = firstIndex(SqlSessionManager._sessions, session => session.path === options.path);
|
||||
if (index > -1) {
|
||||
SqlSessionManager._sessions.splice(index);
|
||||
}
|
||||
@@ -80,7 +82,7 @@ export class SqlSessionManager implements nb.SessionManager {
|
||||
}
|
||||
|
||||
shutdown(id: string): Thenable<void> {
|
||||
let index = SqlSessionManager._sessions.findIndex(session => session.id === id);
|
||||
let index = firstIndex(SqlSessionManager._sessions, session => session.id === id);
|
||||
if (index > -1) {
|
||||
let sessionManager = SqlSessionManager._sessions[index];
|
||||
SqlSessionManager._sessions.splice(index);
|
||||
@@ -306,7 +308,7 @@ class SqlKernel extends Disposable implements nb.IKernel {
|
||||
let code = Array.isArray(content.code) ? content.code.join('') : content.code;
|
||||
let firstLineEnd = code.indexOf(this.textResourcePropertiesService.getEOL(URI.file(this._path)));
|
||||
let firstLine = code.substring(0, (firstLineEnd >= 0) ? firstLineEnd : 0).trimLeft();
|
||||
if (firstLine.startsWith('%%')) {
|
||||
if (startsWith(firstLine, '%%')) {
|
||||
// Strip out the line
|
||||
code = code.substring(firstLineEnd, code.length);
|
||||
// Try and match to an external script magic. If we add more magics later, should handle transforms better
|
||||
|
||||
@@ -18,8 +18,10 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
|
||||
import { ServerTreeView } from 'sql/workbench/parts/objectExplorer/browser/serverTreeView';
|
||||
import { ICapabilitiesService } from 'sql/platform/capabilities/common/capabilitiesService';
|
||||
import * as Utils from 'sql/platform/connection/common/utils';
|
||||
import { entries } from 'sql/base/common/objects';
|
||||
import { ILogService } from 'vs/platform/log/common/log';
|
||||
import { entries } from 'sql/base/common/collections';
|
||||
import { values } from 'vs/base/common/collections';
|
||||
import { startsWith } from 'vs/base/common/strings';
|
||||
|
||||
export const SERVICE_ID = 'ObjectExplorerService';
|
||||
|
||||
@@ -669,7 +671,7 @@ export class ObjectExplorerService implements IObjectExplorerService {
|
||||
}
|
||||
|
||||
public getActiveConnectionNodes(): TreeNode[] {
|
||||
return Object.values(this._activeObjectExplorerNodes);
|
||||
return values(this._activeObjectExplorerNodes);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -788,7 +790,7 @@ export class ObjectExplorerService implements IObjectExplorerService {
|
||||
}
|
||||
if (currentNode.children) {
|
||||
// Look at the next node in the path, which is the child object with the longest path where the desired path starts with the child path
|
||||
let children = currentNode.children.filter(child => nodePath.startsWith(child.nodePath));
|
||||
let children = currentNode.children.filter(child => startsWith(nodePath, child.nodePath));
|
||||
if (children.length > 0) {
|
||||
nextNode = children.reduce((currentMax, candidate) => currentMax.nodePath.length < candidate.nodePath.length ? candidate : currentMax);
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import { NullLogService } from 'vs/platform/log/common/log';
|
||||
import { TestObjectExplorerProvider } from 'sql/workbench/services/objectExplorer/test/common/testObjectExplorerProvider';
|
||||
import { TestConnectionManagementService } from 'sql/platform/connection/test/common/testConnectionManagementService';
|
||||
import { TestCapabilitiesService } from 'sql/platform/capabilities/test/common/testCapabilitiesService';
|
||||
import { find } from 'vs/base/common/arrays';
|
||||
|
||||
suite('SQL Object Explorer Service tests', () => {
|
||||
let sqlOEProvider: TypeMoq.Mock<TestObjectExplorerProvider>;
|
||||
@@ -553,7 +554,7 @@ suite('SQL Object Explorer Service tests', () => {
|
||||
sqlOEProvider.setup(x => x.expandNode(TypeMoq.It.isAny())).callback(() => {
|
||||
objectExplorerService.onNodeExpanded(tableExpandInfo);
|
||||
}).returns(() => Promise.resolve(true));
|
||||
let tableNode = childNodes.find(node => node.nodePath === table1NodePath);
|
||||
let tableNode = find(childNodes, node => node.nodePath === table1NodePath);
|
||||
objectExplorerService.resolveTreeNodeChildren(objectExplorerSession, tableNode).then(() => {
|
||||
// If I check whether the table is expanded, the answer should be yes
|
||||
tableNode.isExpanded().then(isExpanded => {
|
||||
@@ -579,7 +580,7 @@ suite('SQL Object Explorer Service tests', () => {
|
||||
objectExplorerService.onSessionCreated(1, objectExplorerSession);
|
||||
objectExplorerService.resolveTreeNodeChildren(objectExplorerSession, objectExplorerService.getObjectExplorerNode(connection)).then(childNodes => {
|
||||
// If I check whether the table is expanded, the answer should be no because only its parent node is expanded
|
||||
let tableNode = childNodes.find(node => node.nodePath === table1NodePath);
|
||||
let tableNode = find(childNodes, node => node.nodePath === table1NodePath);
|
||||
tableNode.isExpanded().then(isExpanded => {
|
||||
try {
|
||||
assert.equal(isExpanded, false);
|
||||
@@ -611,9 +612,9 @@ suite('SQL Object Explorer Service tests', () => {
|
||||
sqlOEProvider.setup(x => x.expandNode(TypeMoq.It.isAny())).callback(() => {
|
||||
objectExplorerService.onNodeExpanded(tableExpandInfo);
|
||||
}).returns(() => Promise.resolve(true));
|
||||
objectExplorerService.resolveTreeNodeChildren(objectExplorerSession, childNodes.find(node => node.nodePath === table1NodePath)).then(() => {
|
||||
objectExplorerService.resolveTreeNodeChildren(objectExplorerSession, find(childNodes, node => node.nodePath === table1NodePath)).then(() => {
|
||||
// If I check whether the table is expanded, the answer should be yes
|
||||
let tableNode = childNodes.find(node => node.nodePath === table1NodePath);
|
||||
let tableNode = find(childNodes, node => node.nodePath === table1NodePath);
|
||||
tableNode.isExpanded().then(isExpanded => {
|
||||
try {
|
||||
assert.equal(isExpanded, false);
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { ProfilerFilterClause, ProfilerFilter, ProfilerFilterClauseOperator } from 'sql/workbench/services/profiler/browser/interfaces';
|
||||
import { startsWith } from 'vs/base/common/strings';
|
||||
|
||||
|
||||
export function FilterData(filter: ProfilerFilter, data: any[]): any[] {
|
||||
@@ -67,16 +68,16 @@ function matches(item: any, clauses: ProfilerFilterClause[]): boolean {
|
||||
match = actualValue !== undefined && actualValue !== null && actualValue !== '';
|
||||
break;
|
||||
case ProfilerFilterClauseOperator.Contains:
|
||||
match = actualValueString && actualValueString.includes(expectedValueString);
|
||||
match = actualValueString && actualValueString.indexOf(expectedValueString) > -1;
|
||||
break;
|
||||
case ProfilerFilterClauseOperator.NotContains:
|
||||
match = !actualValueString || !actualValueString.includes(expectedValueString);
|
||||
match = !actualValueString || !(actualValueString.indexOf(expectedValueString) > -1);
|
||||
break;
|
||||
case ProfilerFilterClauseOperator.StartsWith:
|
||||
match = actualValueString.startsWith(expectedValueString);
|
||||
match = startsWith(actualValueString, expectedValueString);
|
||||
break;
|
||||
case ProfilerFilterClauseOperator.NotStartsWith:
|
||||
match = !actualValueString || !actualValueString.startsWith(expectedValueString);
|
||||
match = !actualValueString || !startsWith(actualValueString, expectedValueString);
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Not a valid operator: ${clause.operator}`);
|
||||
|
||||
@@ -230,7 +230,7 @@ export class ProfilerService implements IProfilerService {
|
||||
// only use the templates that matches the following criteria:
|
||||
// 1. the template doesn't have any engine types specified - for backward compatibility (user with custom templates) or the templates applicable to both AzureSQLDB and standalone server
|
||||
// 2. the template supports the current engine type
|
||||
templates = templates.filter(template => !template.engineTypes || template.engineTypes.length === 0 || template.engineTypes.includes(engineType));
|
||||
templates = templates.filter(template => !template.engineTypes || template.engineTypes.length === 0 || template.engineTypes.some(x => x === engineType));
|
||||
}
|
||||
return this._commandService.executeCommand('profiler.openCreateSessionDialog', input.id, input.providerType, templates);
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ import { IConfigurationService } from 'vs/platform/configuration/common/configur
|
||||
import { IEditorGroup } from 'vs/workbench/services/editor/common/editorGroupsService';
|
||||
import { FileEditorInput } from 'vs/workbench/contrib/files/common/editors/fileEditorInput';
|
||||
import { ILogService } from 'vs/platform/log/common/log';
|
||||
import { assign } from 'vs/base/common/objects';
|
||||
|
||||
/**
|
||||
* Service wrapper for opening and creating SQL documents as sql editor inputs
|
||||
@@ -204,7 +205,7 @@ export class QueryEditorService implements IQueryEditorService {
|
||||
let group: IEditorGroup = editor.group;
|
||||
let index: number = group.editors.indexOf(editor.input);
|
||||
let options: IQueryEditorOptions = editor.options ? editor.options : {};
|
||||
options = Object.assign(options, { index: index });
|
||||
options = assign(options, { index: index });
|
||||
|
||||
// Return a promise that will resovle when the old editor has been replaced by a new editor
|
||||
let newEditorInput = this.getNewEditorInput(changingToSql, editor.input, uri);
|
||||
|
||||
Reference in New Issue
Block a user