Strict null on some query and connection (#7300)

* wip

* make connection work with strict-nulls

* change comments

* fix tests; remove unneeded type forcing

* address feedback

* adjust the logic of query editor

* clean up typing
This commit is contained in:
Anthony Dresser
2019-10-21 15:50:12 -07:00
committed by GitHub
parent 6a375fdd8c
commit 06e86e57e7
22 changed files with 367 additions and 369 deletions

View File

@@ -29,7 +29,7 @@ const CRED_PROFILE_USER = 'Profile';
* @export
*/
export class ConnectionStore {
private groupIdMap = new ReverseLookUpMap<string, string>();
private groupIdMap = new ReverseLookUpMap<string, string | undefined>();
private connectionConfig = new ConnectionConfig(this.configurationService, this.capabilitiesService);
private mru: Array<IConnectionProfile>;
@@ -57,8 +57,7 @@ export class ConnectionStore {
* @returns formatted string with server, DB and username
*/
private formatCredentialId(connectionProfile: IConnectionProfile, itemType?: string): string {
const connectionProfileInstance: ConnectionProfile = ConnectionProfile.fromIConnectionProfile(
this.capabilitiesService, connectionProfile);
const connectionProfileInstance = ConnectionProfile.fromIConnectionProfile(this.capabilitiesService, connectionProfile);
const cred: string[] = [CRED_PREFIX];
if (!itemType) {
itemType = CRED_PROFILE_USER;
@@ -74,12 +73,8 @@ export class ConnectionStore {
* @param connection profile
*/
public isPasswordRequired(connection: IConnectionProfile): boolean {
if (connection) {
const connectionProfile = ConnectionProfile.fromIConnectionProfile(this.capabilitiesService, connection);
return connectionProfile.isPasswordRequired();
} else {
return false;
}
const connectionProfile = ConnectionProfile.fromIConnectionProfile(this.capabilitiesService, connection);
return connectionProfile.isPasswordRequired();
}
public addSavedPassword(credentialsItem: IConnectionProfile): Promise<{ profile: IConnectionProfile, savedCred: boolean }> {
@@ -162,34 +157,26 @@ export class ConnectionStore {
private convertConfigValuesToConnectionProfiles(configValues: IConnectionProfile[]): ConnectionProfile[] {
return configValues.map(c => {
if (c) {
const connectionProfile = new ConnectionProfile(this.capabilitiesService, c);
if (connectionProfile.saveProfile) {
if (!connectionProfile.groupFullName && connectionProfile.groupId) {
connectionProfile.groupFullName = this.getGroupFullName(connectionProfile.groupId);
}
if (!connectionProfile.groupId && connectionProfile.groupFullName) {
connectionProfile.groupId = this.getGroupId(connectionProfile.groupFullName);
} else if (!connectionProfile.groupId && !connectionProfile.groupFullName) {
connectionProfile.groupId = this.getGroupId('');
}
const connectionProfile = new ConnectionProfile(this.capabilitiesService, c);
if (connectionProfile.saveProfile) {
if (!connectionProfile.groupFullName && connectionProfile.groupId) {
connectionProfile.groupFullName = this.getGroupFullName(connectionProfile.groupId);
}
if (!connectionProfile.groupId && connectionProfile.groupFullName) {
connectionProfile.groupId = this.getGroupId(connectionProfile.groupFullName);
} else if (!connectionProfile.groupId && !connectionProfile.groupFullName) {
connectionProfile.groupId = this.getGroupId('');
}
return connectionProfile;
} else {
return undefined;
}
return connectionProfile;
});
}
public getProfileWithoutPassword(conn: IConnectionProfile): ConnectionProfile {
if (conn) {
let savedConn: ConnectionProfile = ConnectionProfile.fromIConnectionProfile(this.capabilitiesService, conn);
savedConn = savedConn.withoutPassword();
let savedConn = ConnectionProfile.fromIConnectionProfile(this.capabilitiesService, conn);
savedConn = savedConn.withoutPassword();
return savedConn;
} else {
return undefined;
}
return savedConn;
}
/**
@@ -221,7 +208,7 @@ export class ConnectionStore {
}
private addToConnectionList(conn: IConnectionProfile, list: ConnectionProfile[]): IConnectionProfile[] {
const savedProfile: ConnectionProfile = this.getProfileWithoutPassword(conn);
const savedProfile = this.getProfileWithoutPassword(conn);
// Remove the connection from the list if it already exists
list = list.filter(value => {
@@ -239,7 +226,7 @@ export class ConnectionStore {
}
private removeFromConnectionList(conn: IConnectionProfile, list: ConnectionProfile[]): IConnectionProfile[] {
const savedProfile: ConnectionProfile = this.getProfileWithoutPassword(conn);
const savedProfile = this.getProfileWithoutPassword(conn);
// Remove the connection from the list if it already exists
list = list.filter(value => {
@@ -286,7 +273,7 @@ export class ConnectionStore {
}
public getConnectionProfileGroups(withoutConnections?: boolean, providers?: string[]): ConnectionProfileGroup[] {
let profilesInConfiguration: ConnectionProfile[];
let profilesInConfiguration: ConnectionProfile[] | undefined;
if (!withoutConnections) {
profilesInConfiguration = this.connectionConfig.getConnections(true);
if (providers && providers.length > 0) {
@@ -295,10 +282,10 @@ export class ConnectionStore {
}
const groups = this.connectionConfig.getAllGroups();
return this.convertToConnectionGroup(groups, profilesInConfiguration, undefined);
return this.convertToConnectionGroup(groups, profilesInConfiguration);
}
private convertToConnectionGroup(groups: IConnectionProfileGroup[], connections: ConnectionProfile[], parent: ConnectionProfileGroup = undefined): ConnectionProfileGroup[] {
private convertToConnectionGroup(groups: IConnectionProfileGroup[], connections?: ConnectionProfile[], parent?: ConnectionProfileGroup): ConnectionProfileGroup[] {
const result: ConnectionProfileGroup[] = [];
const children = groups.filter(g => g.parentId === (parent ? parent.id : undefined));
if (children) {
@@ -307,7 +294,7 @@ export class ConnectionStore {
this.addGroupFullNameToMap(group.id, connectionGroup.fullName);
if (connections) {
let connectionsForGroup = connections.filter(conn => conn.groupId === connectionGroup.id);
let conns = [];
let conns: ConnectionProfile[] = [];
connectionsForGroup.forEach((conn) => {
conn.groupFullName = connectionGroup.fullName;
conns.push(conn);
@@ -359,7 +346,7 @@ export class ConnectionStore {
return this.connectionConfig.changeGroupIdForConnection(source, targetGroupId).then();
}
private addGroupFullNameToMap(groupId: string, groupFullName: string): void {
private addGroupFullNameToMap(groupId: string, groupFullName?: string): void {
if (groupId) {
this.groupIdMap.set(groupId, groupFullName);
}
@@ -373,7 +360,7 @@ export class ConnectionStore {
// Load the cache
this.getConnectionProfileGroups(true);
}
return this.groupIdMap.get(groupId);
return this.groupIdMap.get(groupId)!;
}
private getGroupId(groupFullName: string): string {
@@ -385,6 +372,6 @@ export class ConnectionStore {
// Load the cache
this.getConnectionProfileGroups(true);
}
return this.groupIdMap.reverseGet(key);
return this.groupIdMap.reverseGet(key)!;
}
}