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

@@ -7,6 +7,7 @@ import * as azdata from 'azdata';
import { AccountAdditionResult } from 'sql/platform/accounts/common/eventTypes';
import { IAccountStore } from 'sql/platform/accounts/common/interfaces';
import { deepClone } from 'vs/base/common/objects';
import { firstIndex } from 'vs/base/common/arrays';
export default class AccountStore implements IAccountStore {
// CONSTANTS ///////////////////////////////////////////////////////////
@@ -23,7 +24,7 @@ export default class AccountStore implements IAccountStore {
return this.readFromMemento()
.then(accounts => {
// Determine if account exists and proceed accordingly
const match = accounts.findIndex(account => AccountStore.findAccountByKey(account.key, newAccount.key));
const match = firstIndex(accounts, account => AccountStore.findAccountByKey(account.key, newAccount.key));
return match < 0
? this.addToAccountList(accounts, newAccount)
: this.updateAccountList(accounts, newAccount.key, matchAccount => AccountStore.mergeAccounts(newAccount, matchAccount));
@@ -100,7 +101,7 @@ export default class AccountStore implements IAccountStore {
private addToAccountList(accounts: azdata.Account[], accountToAdd: azdata.Account): AccountListOperationResult {
// Check if the entry already exists
const match = accounts.findIndex(account => AccountStore.findAccountByKey(account.key, accountToAdd.key));
const match = firstIndex(accounts, account => AccountStore.findAccountByKey(account.key, accountToAdd.key));
if (match >= 0) {
// Account already exists, we won't do anything
return {
@@ -125,7 +126,7 @@ export default class AccountStore implements IAccountStore {
private removeFromAccountList(accounts: azdata.Account[], accountToRemove: azdata.AccountKey): AccountListOperationResult {
// Check if the entry exists
const match = accounts.findIndex(account => AccountStore.findAccountByKey(account.key, accountToRemove));
const match = firstIndex(accounts, account => AccountStore.findAccountByKey(account.key, accountToRemove));
if (match >= 0) {
// Account exists, remove it from the account list
accounts.splice(match, 1);
@@ -142,7 +143,7 @@ export default class AccountStore implements IAccountStore {
private updateAccountList(accounts: azdata.Account[], accountToUpdate: azdata.AccountKey, updateOperation: (account: azdata.Account) => void): AccountListOperationResult {
// Check if the entry exists
const match = accounts.findIndex(account => AccountStore.findAccountByKey(account.key, accountToUpdate));
const match = firstIndex(accounts, account => AccountStore.findAccountByKey(account.key, accountToUpdate));
if (match < 0) {
// Account doesn't exist, we won't do anything
return {

View File

@@ -20,7 +20,7 @@ export interface IAccountManagementService {
addAccount(providerId: string): Thenable<void>;
getAccountProviderMetadata(): Thenable<azdata.AccountProviderMetadata[]>;
getAccountsForProvider(providerId: string): Thenable<azdata.Account[]>;
getSecurityToken(account: azdata.Account, resource: azdata.AzureResource): Thenable<{}>;
getSecurityToken(account: azdata.Account, resource: azdata.AzureResource): Thenable<{ [key: string]: { token: string } }>;
removeAccount(accountKey: azdata.AccountKey): Thenable<boolean>;
refreshAccount(account: azdata.Account): Thenable<azdata.Account>;

View File

@@ -12,6 +12,7 @@ import * as Utils from 'sql/platform/connection/common/utils';
import { generateUuid } from 'vs/base/common/uuid';
import * as nls from 'vs/nls';
import { ConfigurationTarget, IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { find, firstIndex } from 'vs/base/common/arrays';
const GROUPS_CONFIG_KEY = 'datasource.connectionGroups';
const CONNECTIONS_CONFIG_KEY = 'datasource.connections';
@@ -43,7 +44,7 @@ export class ConnectionConfig {
if (user) {
if (workspace) {
user = user.filter(x => workspace.find(f => this.isSameGroupName(f, x)) === undefined);
user = user.filter(x => find(workspace, f => this.isSameGroupName(f, x)) === undefined);
allGroups = allGroups.concat(workspace);
}
allGroups = allGroups.concat(user);
@@ -71,12 +72,12 @@ export class ConnectionConfig {
let newProfile = ConnectionProfile.convertToProfileStore(this._capabilitiesService, connectionProfile);
// Remove the profile if already set
let sameProfileInList = profiles.find(value => {
let sameProfileInList = find(profiles, value => {
let providerConnectionProfile = ConnectionProfile.createFromStoredProfile(value, this._capabilitiesService);
return providerConnectionProfile.matches(connectionProfile);
});
if (sameProfileInList) {
let profileIndex = profiles.findIndex(value => value === sameProfileInList);
let profileIndex = firstIndex(profiles, value => value === sameProfileInList);
newProfile.id = sameProfileInList.id;
connectionProfile.id = sameProfileInList.id;
profiles[profileIndex] = newProfile;
@@ -123,7 +124,7 @@ export class ConnectionConfig {
return Promise.resolve(profileGroup.id);
} else {
let groups = this.configurationService.inspect<IConnectionProfileGroup[]>(GROUPS_CONFIG_KEY).user;
let sameNameGroup = groups ? groups.find(group => group.name === profileGroup.name) : undefined;
let sameNameGroup = groups ? find(groups, group => group.name === profileGroup.name) : undefined;
if (sameNameGroup) {
let errMessage: string = nls.localize('invalidServerName', "A server group with the same name already exists.");
return Promise.reject(errMessage);
@@ -276,7 +277,7 @@ export class ConnectionConfig {
*/
public canChangeConnectionConfig(profile: ConnectionProfile, newGroupID: string): boolean {
let profiles = this.getConnections(true);
let existingProfile = profiles.find(p => p.getConnectionInfoId() === profile.getConnectionInfoId()
let existingProfile = find(profiles, p => p.getConnectionInfoId() === profile.getConnectionInfoId()
&& p.groupId === newGroupID);
return existingProfile === undefined;
}
@@ -328,7 +329,7 @@ export class ConnectionConfig {
public editGroup(source: ConnectionProfileGroup): Promise<void> {
let groups = this.configurationService.inspect<IConnectionProfileGroup[]>(GROUPS_CONFIG_KEY).user;
let sameNameGroup = groups ? groups.find(group => group.name === source.name && group.id !== source.id) : undefined;
let sameNameGroup = groups ? find(groups, group => group.name === source.name && group.id !== source.id) : undefined;
if (sameNameGroup) {
let errMessage: string = nls.localize('invalidServerName', "A server group with the same name already exists.");
return Promise.reject(errMessage);
@@ -369,7 +370,7 @@ export class ConnectionConfig {
color: color,
description: description
} as IConnectionProfileGroup;
let found = groupTree.find(group => this.isSameGroupName(group, newGroup));
let found = find(groupTree, group => this.isSameGroupName(group, newGroup));
if (found) {
if (index === groupNames.length - 1) {
newGroupId = found.id;

View File

@@ -14,6 +14,7 @@ import { isString } from 'vs/base/common/types';
import { deepClone } from 'vs/base/common/objects';
import { ConnectionOptionSpecialType } from 'sql/workbench/api/common/sqlExtHostTypes';
import * as Constants from 'sql/platform/connection/common/constants';
import { find } from 'vs/base/common/arrays';
// Concrete implementation of the IConnectionProfile interface
@@ -46,7 +47,7 @@ export class ConnectionProfile extends ProviderConnectionInfo implements interfa
let capabilities = this.capabilitiesService.getCapabilities(model.providerName);
if (capabilities && capabilities.connection && capabilities.connection.connectionOptions) {
const options = capabilities.connection.connectionOptions;
let appNameOption = options.find(option => option.specialValueType === ConnectionOptionSpecialType.appName);
let appNameOption = find(options, option => option.specialValueType === ConnectionOptionSpecialType.appName);
if (appNameOption) {
let appNameKey = appNameOption.name;
this.options[appNameKey] = Constants.applicationName;

View File

@@ -6,6 +6,8 @@
import { ConnectionProfile } from 'sql/platform/connection/common/connectionProfile';
import { Disposable } from 'vs/base/common/lifecycle';
import { isUndefinedOrNull } from 'vs/base/common/types';
import { assign } from 'vs/base/common/objects';
import { find } from 'vs/base/common/arrays';
export interface IConnectionProfileGroup {
id: string;
@@ -47,7 +49,7 @@ export class ConnectionProfileGroup extends Disposable implements IConnectionPro
});
}
return Object.assign({}, { name: this.name, id: this.id, parentId: this.parentId, children: subgroups, color: this.color, description: this.description });
return assign({}, { name: this.name, id: this.id, parentId: this.parentId, children: subgroups, color: this.color, description: this.description });
}
public get groupName(): string {
@@ -85,7 +87,7 @@ export class ConnectionProfileGroup extends Disposable implements IConnectionPro
*/
public get hasValidConnections(): boolean {
if (this.connections) {
let invalidConnections = this.connections.find(c => !c.isConnectionOptionsValid);
let invalidConnections = find(this.connections, c => !c.isConnectionOptionsValid);
if (invalidConnections !== undefined) {
return false;
} else {

View File

@@ -14,6 +14,9 @@ import { join } from 'vs/base/common/path';
import * as Utils from 'sql/platform/connection/common/utils';
import * as azdata from 'azdata';
import { INotificationService, Severity } from 'vs/platform/notification/common/notification';
import { startsWith } from 'vs/base/common/strings';
import { values } from 'vs/base/common/collections';
import { firstIndex, find } from 'vs/base/common/arrays';
export class ConnectionStatusManager {
@@ -35,8 +38,8 @@ export class ConnectionStatusManager {
}
}
public findConnectionByProfileId(profileId: string): ConnectionManagementInfo {
return Object.values(this._connections).find((connection: ConnectionManagementInfo) => connection.connectionProfile.id === profileId);
public findConnectionByProfileId(profileId: string): ConnectionManagementInfo | undefined {
return find(values(this._connections), connection => connection.connectionProfile.id === profileId);
}
public findConnectionProfile(connectionProfile: IConnectionProfile): ConnectionManagementInfo | undefined {
@@ -190,7 +193,7 @@ export class ConnectionStatusManager {
}
private isSharedSession(fileUri: string): boolean {
return !!(fileUri && fileUri.startsWith('vsls:'));
return !!(fileUri && startsWith(fileUri, 'vsls:'));
}
public isConnected(id: string): boolean {
@@ -205,7 +208,7 @@ export class ConnectionStatusManager {
}
public isDefaultTypeUri(uri: string): boolean {
return !!(uri && uri.startsWith(Utils.uriPrefixes.default));
return !!(uri && startsWith(uri, Utils.uriPrefixes.default));
}
public getProviderIdFromUri(ownerUri: string): string {
@@ -225,12 +228,12 @@ export class ConnectionStatusManager {
* Get a list of the active connection profiles managed by the status manager
*/
public getActiveConnectionProfiles(providers?: string[]): ConnectionProfile[] {
let profiles = Object.values(this._connections).map((connectionInfo: ConnectionManagementInfo) => connectionInfo.connectionProfile);
let profiles = values(this._connections).map((connectionInfo: ConnectionManagementInfo) => connectionInfo.connectionProfile);
// Remove duplicate profiles that may be listed multiple times under different URIs by filtering for profiles that don't have the same ID as an earlier profile in the list
profiles = profiles.filter((profile, index) => profiles.findIndex(otherProfile => otherProfile.id === profile.id) === index);
profiles = profiles.filter((profile, index) => firstIndex(profiles, otherProfile => otherProfile.id === profile.id) === index);
if (providers) {
profiles = profiles.filter(f => providers.includes(f.providerName));
profiles = profiles.filter(f => find(providers, x => x === f.providerName));
}
return profiles;
}

View File

@@ -13,6 +13,7 @@ import { IConnectionProfile } from 'sql/platform/connection/common/interfaces';
import { ICredentialsService } from 'sql/platform/credentials/common/credentialsService';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
import { find } from 'vs/base/common/arrays';
const MAX_CONNECTIONS_DEFAULT = 25;
@@ -150,7 +151,7 @@ export class ConnectionStore {
public getRecentlyUsedConnections(providers?: string[]): ConnectionProfile[] {
let mru = this.mru.slice();
if (providers && providers.length > 0) {
mru = mru.filter(c => providers.includes(c.providerName));
mru = mru.filter(c => find(providers, x => x === c.providerName));
}
return this.convertConfigValuesToConnectionProfiles(mru);
}
@@ -277,7 +278,7 @@ export class ConnectionStore {
if (!withoutConnections) {
profilesInConfiguration = this.connectionConfig.getConnections(true);
if (providers && providers.length > 0) {
profilesInConfiguration = profilesInConfiguration.filter(x => providers.includes(x.providerName));
profilesInConfiguration = profilesInConfiguration.filter(x => find(providers, p => p === x.providerName));
}
}
const groups = this.connectionConfig.getAllGroups();
@@ -313,9 +314,9 @@ export class ConnectionStore {
return result;
}
public getGroupFromId(groupId: string): IConnectionProfileGroup {
public getGroupFromId(groupId: string): IConnectionProfileGroup | undefined {
const groups = this.connectionConfig.getAllGroups();
return groups.find(group => group.id === groupId);
return find(groups, group => group.id === groupId);
}
private getMaxRecentConnectionsCount(): number {

View File

@@ -10,6 +10,8 @@ import * as azdata from 'azdata';
import { ConnectionOptionSpecialType, ServiceOptionType } from 'sql/workbench/api/common/sqlExtHostTypes';
import * as Constants from 'sql/platform/connection/common/constants';
import { ICapabilitiesService, ConnectionProviderProperties } from 'sql/platform/capabilities/common/capabilitiesService';
import { assign } from 'vs/base/common/objects';
import { find } from 'vs/base/common/arrays';
type SettableProperty = 'serverName' | 'authenticationType' | 'databaseName' | 'password' | 'connectionName' | 'userName';
@@ -94,7 +96,7 @@ export class ProviderConnectionInfo extends Disposable implements azdata.Connect
public clone(): ProviderConnectionInfo {
let instance = new ProviderConnectionInfo(this.capabilitiesService, this.providerName);
instance.options = Object.assign({}, this.options);
instance.options = assign({}, this.options);
return instance;
}
@@ -196,9 +198,9 @@ export class ProviderConnectionInfo extends Disposable implements azdata.Connect
return false;
}
let optionMetadata = this._serverCapabilities.connectionOptions.find(
option => option.specialValueType === ConnectionOptionSpecialType.password);
let isPasswordRequired: boolean = optionMetadata.isRequired;
let optionMetadata = find(this._serverCapabilities.connectionOptions,
option => option.specialValueType === ConnectionOptionSpecialType.password)!; // i guess we are going to assume there is a password field
let isPasswordRequired = optionMetadata.isRequired;
if (this.providerName === Constants.mssqlProviderName) {
isPasswordRequired = this.authenticationType === ProviderConnectionInfo.SqlAuthentication && optionMetadata.isRequired;
}
@@ -267,7 +269,7 @@ export class ProviderConnectionInfo extends Disposable implements azdata.Connect
public getSpecialTypeOptionName(type: string): string | undefined {
if (this._serverCapabilities) {
let optionMetadata = this._serverCapabilities.connectionOptions.find(o => o.specialValueType === type);
let optionMetadata = find(this._serverCapabilities.connectionOptions, o => o.specialValueType === type);
return !!optionMetadata ? optionMetadata.name : undefined;
} else {
return type.toString();
@@ -282,7 +284,7 @@ export class ProviderConnectionInfo extends Disposable implements azdata.Connect
}
public get authenticationTypeDisplayName(): string {
let optionMetadata = this._serverCapabilities.connectionOptions.find(o => o.specialValueType === ConnectionOptionSpecialType.authType);
let optionMetadata = find(this._serverCapabilities.connectionOptions, o => o.specialValueType === ConnectionOptionSpecialType.authType);
let authType = this.authenticationType;
let displayName: string = authType;

View File

@@ -17,6 +17,7 @@ import * as TypeMoq from 'typemoq';
import { Emitter } from 'vs/base/common/event';
import { deepClone, deepFreeze } from 'vs/base/common/objects';
import { ConfigurationTarget } from 'vs/platform/configuration/common/configuration';
import { find } from 'vs/base/common/arrays';
suite('ConnectionConfig', () => {
let capabilitiesService: TypeMoq.Mock<ICapabilitiesService>;
@@ -210,7 +211,7 @@ suite('ConnectionConfig', () => {
}
for (let group of groups1) {
let g2 = groups2.find(g => g.name === group.name);
let g2 = find(groups2, g => g.name === group.name);
// if we couldn't find the group it means they must not be equal
if (!g2) {
return false;
@@ -373,12 +374,12 @@ suite('ConnectionConfig', () => {
let allConnections = config.getConnections(false);
assert.equal(allConnections.length, testConnections.length);
allConnections.forEach(connection => {
let userConnection = testConnections.find(u => u.options['serverName'] === connection.serverName);
let userConnection = find(testConnections, u => u.options['serverName'] === connection.serverName);
if (userConnection !== undefined) {
assert.notEqual(connection.id, connection.getOptionsKey());
assert.ok(!!connection.id);
} else {
let workspaceConnection = workspaceConnections.find(u => u.options['serverName'] === connection.serverName);
let workspaceConnection = find(workspaceConnections, u => u.options['serverName'] === connection.serverName);
assert.notEqual(connection.id, connection.getOptionsKey());
assert.equal(workspaceConnection.id, connection.id);
}
@@ -394,7 +395,7 @@ suite('ConnectionConfig', () => {
let result: ISaveGroupResult = config.saveGroup(groups, newGroups, color, newGroups);
assert.ok(!!result);
assert.equal(result.groups.length, testGroups.length + 2, 'The result groups length is invalid');
let newGroup = result.groups.find(g => g.name === 'new-group2');
let newGroup = find(result.groups, g => g.name === 'new-group2');
assert.equal(result.newGroupId, newGroup.id, 'The groups id is invalid');
});
@@ -407,7 +408,7 @@ suite('ConnectionConfig', () => {
let result: ISaveGroupResult = config.saveGroup(groups, newGroups, color, newGroups);
assert.ok(!!result);
assert.equal(result.groups.length, testGroups.length + 1, 'The result groups length is invalid');
let newGroup = result.groups.find(g => g.name === 'g2-5');
let newGroup = find(result.groups, g => g.name === 'g2-5');
assert.equal(result.newGroupId, newGroup.id, 'The groups id is invalid');
});
@@ -420,7 +421,7 @@ suite('ConnectionConfig', () => {
let result: ISaveGroupResult = config.saveGroup(groups, newGroups, color, newGroups);
assert.ok(!!result);
assert.equal(result.groups.length, testGroups.length, 'The result groups length is invalid');
let newGroup = result.groups.find(g => g.name === 'g2-1');
let newGroup = find(result.groups, g => g.name === 'g2-1');
assert.equal(result.newGroupId, newGroup.id, 'The groups id is invalid');
});
@@ -530,7 +531,7 @@ suite('ConnectionConfig', () => {
let editedGroups = configurationService.inspect<IConnectionProfileGroup[]>('datasource.connectionGroups').user;
assert.equal(editedGroups.length, testGroups.length);
let editedGroup = editedGroups.find(group => group.id === 'g2');
let editedGroup = find(editedGroups, group => group.id === 'g2');
assert.ok(!!editedGroup);
assert.equal(editedGroup.name, 'g-renamed');
});
@@ -547,7 +548,7 @@ suite('ConnectionConfig', () => {
assert.fail();
} catch (e) {
let groups = configurationService.inspect<IConnectionProfileGroup[]>('datasource.connectionGroups').user;
let originalGroup = groups.find(g => g.id === 'g2');
let originalGroup = find(groups, g => g.id === 'g2');
assert.ok(!!originalGroup);
assert.equal(originalGroup.name, 'g2');
}
@@ -565,7 +566,7 @@ suite('ConnectionConfig', () => {
let editedGroups = configurationService.inspect<IConnectionProfileGroup[]>('datasource.connectionGroups').user;
assert.equal(editedGroups.length, testGroups.length);
let editedGroup = editedGroups.find(group => group.id === 'g2');
let editedGroup = find(editedGroups, group => group.id === 'g2');
assert.ok(!!editedGroup);
assert.equal(editedGroup.parentId, 'g3');
});
@@ -622,7 +623,7 @@ suite('ConnectionConfig', () => {
let editedConnections = configurationService.inspect<IConnectionProfileStore[]>('datasource.connections').user;
// two
assert.equal(editedConnections.length, _testConnections.length);
let editedConnection = editedConnections.find(con => con.id === 'server3-2');
let editedConnection = find(editedConnections, con => con.id === 'server3-2');
assert.ok(!!editedConnection);
assert.equal(editedConnection.groupId, 'g3');
}
@@ -658,7 +659,7 @@ suite('ConnectionConfig', () => {
let editedConnections = configurationService.inspect<IConnectionProfileStore[]>('datasource.connections').user;
assert.equal(editedConnections.length, testConnections.length);
let editedConnection = editedConnections.find(con => con.id === 'server3');
let editedConnection = find(editedConnections, con => con.id === 'server3');
assert.ok(!!editedConnection);
assert.equal(editedConnection.groupId, 'newid');
});

View File

@@ -11,6 +11,7 @@ import { ConnectionOptionSpecialType, ServiceOptionType } from 'sql/workbench/ap
import { TestCapabilitiesService } from 'sql/platform/capabilities/test/common/testCapabilitiesService';
import { mssqlProviderName } from 'sql/platform/connection/common/constants';
import { ConnectionProviderProperties } from 'sql/platform/capabilities/common/capabilitiesService';
import { assign } from 'vs/base/common/objects';
suite('SQL ConnectionProfileInfo tests', () => {
let msSQLCapabilities: ConnectionProviderProperties;
@@ -187,7 +188,7 @@ suite('SQL ConnectionProfileInfo tests', () => {
});
test('createFromStoredProfile should set the id to new guid if not set in stored profile', () => {
let savedProfile = Object.assign({}, storedProfile, { id: undefined });
let savedProfile = assign({}, storedProfile, { id: undefined });
let connectionProfile = ConnectionProfile.createFromStoredProfile(savedProfile, capabilitiesService);
assert.equal(savedProfile.groupId, connectionProfile.groupId);
assert.deepEqual(savedProfile.providerName, connectionProfile.providerName);

View File

@@ -13,11 +13,12 @@ import { TestConfigurationService } from 'sql/platform/connection/test/common/te
import { TestCredentialsService } from 'sql/platform/credentials/test/common/testCredentialsService';
import { ConnectionOptionSpecialType, ServiceOptionType } from 'sql/workbench/api/common/sqlExtHostTypes';
import { TestCapabilitiesService } from 'sql/platform/capabilities/test/common/testCapabilitiesService';
import { deepClone, deepFreeze } from 'vs/base/common/objects';
import { deepClone, deepFreeze, assign } from 'vs/base/common/objects';
import { ConfigurationTarget } from 'vs/platform/configuration/common/configuration';
import { mssqlProviderName } from 'sql/platform/connection/common/constants';
import { ConnectionProviderProperties } from 'sql/platform/capabilities/common/capabilitiesService';
import { InMemoryStorageService } from 'vs/platform/storage/common/storage';
import { find } from 'vs/base/common/arrays';
suite('ConnectionStore', () => {
let defaultNamedProfile: IConnectionProfile = deepFreeze({
@@ -153,7 +154,7 @@ suite('ConnectionStore', () => {
const connectionStore = new ConnectionStore(storageService, configurationService,
credentialsService, capabilitiesService);
for (let i = 0; i < numCreds; i++) {
const cred = Object.assign({}, defaultNamedProfile, { serverName: defaultNamedProfile.serverName + i });
const cred = assign({}, defaultNamedProfile, { serverName: defaultNamedProfile.serverName + i });
const connectionProfile = new ConnectionProfile(capabilitiesService, cred);
await connectionStore.addRecentConnection(connectionProfile);
const current = connectionStore.getRecentlyUsedConnections();
@@ -189,7 +190,7 @@ suite('ConnectionStore', () => {
// Then expect the only 1 instance of that connection to be listed in the MRU
const connectionStore = new ConnectionStore(storageService, configurationService,
credentialsService, capabilitiesService);
const cred = Object.assign({}, defaultNamedProfile, { serverName: defaultNamedProfile.serverName + 1 });
const cred = assign({}, defaultNamedProfile, { serverName: defaultNamedProfile.serverName + 1 });
const connectionProfile = new ConnectionProfile(capabilitiesService, cred);
await connectionStore.addRecentConnection(defaultNamedConnectionProfile);
await connectionStore.addRecentConnection(connectionProfile);
@@ -211,13 +212,13 @@ suite('ConnectionStore', () => {
// Given we save 1 connection with password and multiple other connections without
const connectionStore = new ConnectionStore(storageService, configurationService,
credentialsService, capabilitiesService);
const integratedCred = Object.assign({}, defaultNamedProfile, {
const integratedCred = assign({}, defaultNamedProfile, {
serverName: defaultNamedProfile.serverName + 'Integrated',
authenticationType: 'Integrated',
userName: '',
password: ''
});
const noPwdCred = Object.assign({}, defaultNamedProfile, {
const noPwdCred = assign({}, defaultNamedProfile, {
serverName: defaultNamedProfile.serverName + 'NoPwd',
password: ''
});
@@ -232,7 +233,7 @@ suite('ConnectionStore', () => {
// Then verify that since its password based we save the password
assert.equal(credentialsService.credentials.size, 1);
assert.strictEqual(recentCredential.password, defaultNamedProfile.password);
assert.ok(recentCredential.credentialId.includes('Profile'), 'Expect credential to be marked as an Profile cred');
assert.ok(recentCredential.credentialId.indexOf('Profile') > -1, 'Expect credential to be marked as an Profile cred');
assert.ok(!current[0].password);
// When add integrated auth connection
const integratedCredConnectionProfile = new ConnectionProfile(capabilitiesService, integratedCred);
@@ -312,7 +313,7 @@ suite('ConnectionStore', () => {
const connectionStore = new ConnectionStore(storageService, configurationService,
credentialsService, capabilitiesService);
const connectionProfile: IConnectionProfile = Object.assign({}, defaultNamedProfile, { providerName: providerName });
const connectionProfile: IConnectionProfile = assign({}, defaultNamedProfile, { providerName: providerName });
assert.ok(!connectionStore.isPasswordRequired(connectionProfile));
});
@@ -323,7 +324,7 @@ suite('ConnectionStore', () => {
const credentialsService = new TestCredentialsService();
const password: string = 'asdf!@#$';
const connectionProfile: IConnectionProfile = Object.assign({}, defaultNamedProfile, { password });
const connectionProfile: IConnectionProfile = assign({}, defaultNamedProfile, { password });
const connectionStore = new ConnectionStore(storageService, configurationService,
credentialsService, capabilitiesService);
@@ -393,7 +394,7 @@ suite('ConnectionStore', () => {
const profile = deepClone(defaultNamedProfile);
profile.options['password'] = profile.password;
profile.id = 'testId';
let expectedProfile = Object.assign({}, profile);
let expectedProfile = assign({}, profile);
expectedProfile.password = '';
expectedProfile.options['password'] = '';
expectedProfile = ConnectionProfile.fromIConnectionProfile(capabilitiesService, expectedProfile).toIConnectionProfile();
@@ -406,7 +407,7 @@ suite('ConnectionStore', () => {
const configurationService = new TestConfigurationService();
const credentialsService = new TestCredentialsService();
const profile = ConnectionProfile.fromIConnectionProfile(capabilitiesService, Object.assign({}, defaultNamedProfile, { password: undefined }));
const profile = ConnectionProfile.fromIConnectionProfile(capabilitiesService, assign({}, defaultNamedProfile, { password: undefined }));
const credId = `Microsoft.SqlTools|itemtype:Profile|id:${profile.getConnectionInfoId()}`;
const password: string = 'asdf!@#$';
@@ -453,7 +454,7 @@ suite('ConnectionStore', () => {
const connectionGroups = connectionStore.getConnectionProfileGroups();
for (const group of connectionGroups) {
const foundGroup = groups.find(g => g.id === group.id);
const foundGroup = find(groups, g => g.id === group.id);
assert.ok(foundGroup);
}
});
@@ -467,7 +468,7 @@ suite('ConnectionStore', () => {
credentialsService, capabilitiesService);
for (let i = 0; i < 5; i++) {
const cred = Object.assign({}, defaultNamedProfile, { serverName: defaultNamedProfile.serverName + i });
const cred = assign({}, defaultNamedProfile, { serverName: defaultNamedProfile.serverName + i });
const connectionProfile = new ConnectionProfile(capabilitiesService, cred);
await connectionStore.addRecentConnection(connectionProfile);
const current = connectionStore.getRecentlyUsedConnections();
@@ -475,7 +476,7 @@ suite('ConnectionStore', () => {
}
for (let i = 0; i < 5; i++) {
const cred = Object.assign({}, defaultNamedProfile, { serverName: defaultNamedProfile.serverName + i });
const cred = assign({}, defaultNamedProfile, { serverName: defaultNamedProfile.serverName + i });
const connectionProfile = new ConnectionProfile(capabilitiesService, cred);
connectionStore.removeRecentConnection(connectionProfile);
const current = connectionStore.getRecentlyUsedConnections();

View File

@@ -10,6 +10,7 @@ import * as assert from 'assert';
import { ConnectionOptionSpecialType, ServiceOptionType } from 'sql/workbench/api/common/sqlExtHostTypes';
import { TestCapabilitiesService } from 'sql/platform/capabilities/test/common/testCapabilitiesService';
import { mssqlProviderName } from 'sql/platform/connection/common/constants';
import { assign } from 'vs/base/common/objects';
suite('SQL ProviderConnectionInfo tests', () => {
let msSQLCapabilities: any;
@@ -202,7 +203,7 @@ suite('SQL ProviderConnectionInfo tests', () => {
test('constructor should initialize the options given a valid model with options', () => {
let options = {};
options['encrypt'] = 'test value';
let conn2 = Object.assign({}, connectionProfile, { options: options });
let conn2 = assign({}, connectionProfile, { options: options });
let conn = new ProviderConnectionInfo(capabilitiesService, conn2);
assert.equal(conn.connectionName, conn2.connectionName);
@@ -223,7 +224,7 @@ suite('SQL ProviderConnectionInfo tests', () => {
test('getOptionsKey should create different id for different server names', () => {
let conn = new ProviderConnectionInfo(capabilitiesService, connectionProfile);
let conn2 = new ProviderConnectionInfo(capabilitiesService, Object.assign({}, connectionProfile, { serverName: connectionProfile.serverName + '1' }));
let conn2 = new ProviderConnectionInfo(capabilitiesService, assign({}, connectionProfile, { serverName: connectionProfile.serverName + '1' }));
assert.notEqual(conn.getOptionsKey(), conn2.getOptionsKey());
});
@@ -260,4 +261,4 @@ suite('SQL ProviderConnectionInfo tests', () => {
assert.equal(expectedProviderId, actual);
});
});
});

View File

@@ -15,6 +15,7 @@ import { mssqlProviderName } from 'sql/platform/connection/common/constants';
import { NullLogService } from 'vs/platform/log/common/log';
import { EnvironmentService } from 'vs/platform/environment/node/environmentService';
import { parseArgs, OPTIONS } from 'vs/platform/environment/node/argv';
import { assign } from 'vs/base/common/objects';
let connections: ConnectionStatusManager;
let capabilitiesService: TestCapabilitiesService;
@@ -171,7 +172,7 @@ suite('SQL ConnectionStatusManager tests', () => {
let expectedConnectionId = 'new id';
connections.addConnection(connectionProfile, connection1Id);
let updatedConnection = Object.assign({}, connectionProfile, { groupId: expected, getOptionsKey: () => connectionProfile.getOptionsKey() + expected, id: expectedConnectionId });
let updatedConnection = assign({}, connectionProfile, { groupId: expected, getOptionsKey: () => connectionProfile.getOptionsKey() + expected, id: expectedConnectionId });
let actualId = connections.updateConnectionProfile(updatedConnection, connection1Id);
let newId = Utils.generateUri(updatedConnection);
@@ -246,7 +247,7 @@ suite('SQL ConnectionStatusManager tests', () => {
test('getActiveConnectionProfiles should return a list of all the unique connections that the status manager knows about', () => {
// Add duplicate connections
let newConnection = Object.assign({}, connectionProfile);
let newConnection = assign({}, connectionProfile);
newConnection.id = 'test_id';
newConnection.serverName = 'new_server_name';
newConnection.options['databaseDisplayName'] = newConnection.databaseName;

View File

@@ -8,6 +8,7 @@ import * as platform from 'vs/platform/registry/common/platform';
import { IJSONSchema } from 'vs/base/common/jsonSchema';
import * as nls from 'vs/nls';
import { IInsightData } from 'sql/workbench/parts/charts/browser/interfaces';
import { values } from 'vs/base/common/collections';
export type InsightIdentifier = string;
@@ -107,7 +108,7 @@ class InsightRegistry implements IInsightRegistry {
}
public getAllCtors(): Array<Type<IInsightsView>> {
return Object.values(this._idToCtor);
return values(this._idToCtor);
}
public getAllIds(): Array<string> {

View File

@@ -7,6 +7,7 @@ import { ModelComponentTypes } from 'sql/workbench/api/common/sqlExtHostTypes';
import * as platform from 'vs/platform/registry/common/platform';
import { IComponent } from 'sql/workbench/browser/modelComponents/interfaces';
import { values } from 'vs/base/common/collections';
export type ComponentIdentifier = string;
@@ -46,7 +47,7 @@ class ComponentRegistry implements IComponentRegistry {
}
public getAllCtors(): Array<Type<IComponent>> {
return Object.values(this._idToCtor);
return values(this._idToCtor);
}
public getAllIds(): Array<string> {

View File

@@ -4,6 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import * as nls from 'vs/nls';
import { find } from 'vs/base/common/arrays';
export class JobManagementUtilities {
@@ -41,7 +42,7 @@ export class JobManagementUtilities {
}
public static convertToNextRun(date: string) {
if (date.includes('1/1/0001')) {
if (find(date, x => x === '1/1/0001')) {
return nls.localize('agentUtilities.notScheduled', "Not Scheduled");
} else {
return date;
@@ -49,7 +50,7 @@ export class JobManagementUtilities {
}
public static convertToLastRun(date: string) {
if (date.includes('1/1/0001')) {
if (find(date, x => x === '1/1/0001')) {
return nls.localize('agentUtilities.neverRun', "Never Run");
} else {
return date;
@@ -57,7 +58,7 @@ export class JobManagementUtilities {
}
public static setRunnable(icon: HTMLElement, index: number) {
if (icon.className.includes('non-runnable')) {
if (find(icon.className, x => x === 'non-runnable')) {
icon.className = icon.className.slice(0, index);
}
}

View File

@@ -14,6 +14,7 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { Event, Emitter } from 'vs/base/common/event';
import { keys } from 'vs/base/common/map';
import { ILogService } from 'vs/platform/log/common/log';
import { assign } from 'vs/base/common/objects';
export const SERVICE_ID = 'queryManagementService';
@@ -173,7 +174,7 @@ export class QueryManagementService implements IQueryManagementService {
provider: providerId,
};
if (runOptions) {
data = Object.assign({}, data, {
data = assign({}, data, {
displayEstimatedQueryPlan: runOptions.displayEstimatedQueryPlan,
displayActualQueryPlan: runOptions.displayActualQueryPlan
});

View File

@@ -27,6 +27,7 @@ import { mssqlProviderName } from 'sql/platform/connection/common/constants';
import { IGridDataProvider, getResultsString } from 'sql/platform/query/common/gridDataProvider';
import { getErrorMessage } from 'vs/base/common/errors';
import { ILogService } from 'vs/platform/log/common/log';
import { find } from 'vs/base/common/arrays';
export interface IEditSessionReadyEvent {
ownerUri: string;
@@ -346,7 +347,7 @@ export default class QueryRunner extends Disposable {
}
// handle getting queryPlanxml if we need too
// check if this result has show plan, this needs work, it won't work for any other provider
let hasShowPlan = !!result.resultSetSummary.columnInfo.find(e => e.columnName === 'Microsoft SQL Server 2005 XML Showplan');
let hasShowPlan = !!find(result.resultSetSummary.columnInfo, e => e.columnName === 'Microsoft SQL Server 2005 XML Showplan');
if (hasShowPlan) {
this._isQueryPlan = true;
@@ -373,7 +374,7 @@ export default class QueryRunner extends Disposable {
batchSet = this._batchSets[resultSet.batchId];
// handle getting queryPlanxml if we need too
// check if this result has show plan, this needs work, it won't work for any other provider
let hasShowPlan = !!result.resultSetSummary.columnInfo.find(e => e.columnName === 'Microsoft SQL Server 2005 XML Showplan');
let hasShowPlan = !!find(result.resultSetSummary.columnInfo, e => e.columnName === 'Microsoft SQL Server 2005 XML Showplan');
if (hasShowPlan) {
this._isQueryPlan = true;
this.getQueryRows(0, 1, result.resultSetSummary.batchId, result.resultSetSummary.id).then(e => {

View File

@@ -14,6 +14,7 @@ import { IConnectionManagementService } from 'sql/platform/connection/common/con
import { Event, Emitter } from 'vs/base/common/event';
import { Disposable } from 'vs/base/common/lifecycle';
import { IConfigurationService, IConfigurationChangeEvent } from 'vs/platform/configuration/common/configuration';
import { find } from 'vs/base/common/arrays';
/**
* Service that collects the results of executed queries
@@ -41,7 +42,7 @@ export class QueryHistoryService extends Disposable implements IQueryHistoryServ
this._captureEnabled = !!this._configurationService.getValue<boolean>('queryHistory.captureEnabled');
this._register(this._configurationService.onDidChangeConfiguration((e: IConfigurationChangeEvent) => {
if (e.affectedKeys.includes('queryHistory.captureEnabled')) {
if (find(e.affectedKeys, x => x === 'queryHistory.captureEnabled')) {
this.updateCaptureEnabled();
}
}));

View File

@@ -24,6 +24,7 @@ import * as TelemetryUtils from 'sql/platform/telemetry/common/telemetryUtilitie
import { IConnectionManagementService } from 'sql/platform/connection/common/connectionManagement';
import { invalidProvider } from 'sql/base/common/errors';
import { ILogService } from 'vs/platform/log/common/log';
import { find } from 'vs/base/common/arrays';
export class RestoreService implements IRestoreService {
@@ -272,7 +273,7 @@ export class RestoreDialogController implements IRestoreDialogController {
let providerCapabilities = this._capabilitiesService.getLegacyCapabilities(providerId);
if (providerCapabilities) {
let restoreMetadataProvider = providerCapabilities.features.find(f => f.featureName === this._restoreFeature);
let restoreMetadataProvider = find(providerCapabilities.features, f => f.featureName === this._restoreFeature);
if (restoreMetadataProvider) {
options = restoreMetadataProvider.optionsMetadata;
}

View File

@@ -3,12 +3,13 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { createDecorator, ServiceIdentifier } from 'vs/platform/instantiation/common/instantiation';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { IConnectionManagementService } from 'sql/platform/connection/common/connectionManagement';
import { ICapabilitiesService } from 'sql/platform/capabilities/common/capabilitiesService';
import * as azdata from 'azdata';
import { localize } from 'vs/nls';
import { getErrorMessage } from 'vs/base/common/errors';
import { find } from 'vs/base/common/arrays';
export const SERVICE_ID = 'serializationService';
@@ -95,7 +96,7 @@ export class SerializationService implements ISerializationService {
let providerCapabilities = this._capabilitiesService.getLegacyCapabilities(providerId);
if (providerCapabilities) {
return providerCapabilities.features.find(f => f.featureName === SERVICE_ID);
return find(providerCapabilities.features, f => f.featureName === SERVICE_ID);
}
return undefined;

View File

@@ -13,6 +13,7 @@ import { localize } from 'vs/nls';
import Severity from 'vs/base/common/severity';
import { IDialogService } from 'vs/platform/dialogs/common/dialogs';
import { IConnectionManagementService } from 'sql/platform/connection/common/connectionManagement';
import { find } from 'vs/base/common/arrays';
export const SERVICE_ID = 'taskHistoryService';
export const ITaskService = createDecorator<ITaskService>(SERVICE_ID);
@@ -226,7 +227,7 @@ export class TaskService implements ITaskService {
private getTaskInQueue(taskId: string): TaskNode | undefined {
if (this._taskQueue.hasChildren) {
return this._taskQueue.children.find(x => x.id === taskId);
return find(this._taskQueue.children, x => x.id === taskId);
}
return undefined;
}

View File

@@ -6,6 +6,7 @@
import { IAdsTelemetryService, ITelemetryInfo, ITelemetryEvent, ITelemetryConnectionInfo, ITelemetryEventMeasures, ITelemetryEventProperties } from 'sql/platform/telemetry/common/telemetry';
import { ILogService } from 'vs/platform/log/common/log';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { assign } from 'vs/base/common/objects';
class TelemetryEventImpl implements ITelemetryEvent {
@@ -33,17 +34,17 @@ class TelemetryEventImpl implements ITelemetryEvent {
}
public withAdditionalProperties(additionalProperties: ITelemetryEventProperties): ITelemetryEvent {
Object.assign(this._properties, additionalProperties);
assign(this._properties, additionalProperties);
return this;
}
public withAdditionalMeasurements(additionalMeasurements: ITelemetryEventMeasures): ITelemetryEvent {
Object.assign(this._measurements, additionalMeasurements);
assign(this._measurements, additionalMeasurements);
return this;
}
public withConnectionInfo(connectionInfo: ITelemetryConnectionInfo): ITelemetryEvent {
Object.assign(this._properties,
assign(this._properties,
{
authenticationType: connectionInfo.authenticationType,
providerName: connectionInfo.providerName,