Even more strictness (#11879)

* add more to strict nulls

* maintain error handling properly

* fix lint

* the rest of workbench/services

* fix compile
This commit is contained in:
Anthony Dresser
2020-08-20 14:00:26 -07:00
committed by GitHub
parent ca2b893c2c
commit adfdd56907
23 changed files with 260 additions and 302 deletions

View File

@@ -12,7 +12,7 @@ suite('Assessment service tests', () => {
});
test('Construction - Assessment service Initialization', () => {
let service = new AssessmentService(undefined);
let service = new AssessmentService(undefined!);
assert(service);
});

View File

@@ -29,7 +29,7 @@ export function providerIterator(service: IInstantiationService): Provider[] {
function createUniqueSelector(selector: string): string {
let num: number;
if (selectorCounter.has(selector)) {
num = selectorCounter.get(selector);
num = selectorCounter.get(selector)!;
} else {
num = 0;
}

View File

@@ -95,13 +95,13 @@ export class SingleQueryManagementService {
*/
@Injectable()
export class CommonServiceInterface extends AngularDisposable {
protected _uri: string;
protected _uri!: string;
/* Special Services */
protected _singleMetadataService: SingleConnectionMetadataService;
protected _singleConnectionManagementService: SingleConnectionManagementService;
protected _singleAdminService: SingleAdminService;
protected _singleQueryManagementService: SingleQueryManagementService;
protected _singleMetadataService?: SingleConnectionMetadataService;
protected _singleConnectionManagementService?: SingleConnectionManagementService;
protected _singleAdminService?: SingleAdminService;
protected _singleQueryManagementService?: SingleQueryManagementService;
public scopedContextKeyService: IContextKeyService;
protected _connectionContextKey: ConnectionContextKey;
@@ -114,36 +114,25 @@ export class CommonServiceInterface extends AngularDisposable {
@Inject(IQueryManagementService) protected _queryManagementService: IQueryManagementService
) {
super();
// during testing there may not be params
if (this._params) {
this.scopedContextKeyService = this._params.scopedContextService;
this._connectionContextKey = this._params.connectionContextKey;
this.uri = this._params.ownerUri;
}
this.scopedContextKeyService = this._params.scopedContextService;
this._connectionContextKey = this._params.connectionContextKey;
this.uri = this._params.ownerUri;
}
public get metadataService(): SingleConnectionMetadataService {
return this._singleMetadataService;
return this._singleMetadataService!;
}
public get connectionManagementService(): SingleConnectionManagementService {
return this._singleConnectionManagementService;
return this._singleConnectionManagementService!;
}
public get adminService(): SingleAdminService {
return this._singleAdminService;
return this._singleAdminService!;
}
public get queryManagementService(): SingleQueryManagementService {
return this._singleQueryManagementService;
}
protected setUri(uri: string) {
this._uri = uri;
this._singleMetadataService = new SingleConnectionMetadataService(this._metadataService, this._uri);
this._singleConnectionManagementService = new SingleConnectionManagementService(this._connectionManagementService, this._uri, this._connectionContextKey);
this._singleAdminService = new SingleAdminService(this._adminService, this._uri);
this._singleQueryManagementService = new SingleQueryManagementService(this._queryManagementService, this._uri);
return this._singleQueryManagementService!;
}
/**
@@ -151,11 +140,15 @@ export class CommonServiceInterface extends AngularDisposable {
* Inits all the services that depend on knowing a uri
*/
protected set uri(uri: string) {
this.setUri(uri);
this._uri = uri;
this._singleMetadataService = new SingleConnectionMetadataService(this._metadataService, this._uri);
this._singleConnectionManagementService = new SingleConnectionManagementService(this._connectionManagementService, this._uri, this._connectionContextKey);
this._singleAdminService = new SingleAdminService(this._adminService, this._uri);
this._singleQueryManagementService = new SingleQueryManagementService(this._queryManagementService, this._uri);
}
protected get uri(): string {
return this._uri;
return this._uri!;
}
/**
@@ -163,7 +156,7 @@ export class CommonServiceInterface extends AngularDisposable {
* In general don't use this, use specific services instances exposed publicly
*/
public getUnderlyingUri(): string {
return this._uri;
return this._uri!;
}
public getOriginalConnectionProfile(): IConnectionProfile {

View File

@@ -43,7 +43,7 @@ export class ConnectionContextKey implements IContextKey<IConnectionProfile> {
this._providerKey.set(value && value.providerName);
this._serverKey.set(value && value.serverName);
this._databaseKey.set(value && value.databaseName);
this._isQueryProviderKey.set(value && value.providerName && queryProviders.indexOf(value.providerName) !== -1);
this._isQueryProviderKey.set(!!value && !!value.providerName && queryProviders.indexOf(value.providerName) !== -1);
}
private setCanOpenInPortal(connectionProfile: IConnectionProfile): void {
@@ -64,7 +64,7 @@ export class ConnectionContextKey implements IContextKey<IConnectionProfile> {
this._canOpenInAzurePortal.reset();
}
public get(): IConnectionProfile {
public get(): IConnectionProfile | undefined {
return this._connectionKey.get();
}
}

View File

@@ -76,7 +76,7 @@ class ExtensionListRenderer implements IListRenderer<IDashboardUITab, ExtensionL
templateData.icon.classList.add(ExtensionListRenderer.OPENED_TAB_CLASS);
}
templateData.title.innerText = dashboardTab.tabConfig.title;
templateData.description.innerText = dashboardTab.tabConfig.description;
templateData.description.innerText = dashboardTab.tabConfig.description ?? '';
templateData.publisher.innerText = dashboardTab.tabConfig.publisher;
}
@@ -92,11 +92,11 @@ class ExtensionListRenderer implements IListRenderer<IDashboardUITab, ExtensionL
export class NewDashboardTabDialog extends Modal {
// MEMBER letIABLES ////////////////////////////////////////////////////
private _addNewTabButton: Button;
private _cancelButton: Button;
private _extensionList: List<IDashboardUITab>;
private _extensionViewContainer: HTMLElement;
private _noExtensionViewContainer: HTMLElement;
private _addNewTabButton?: Button;
private _cancelButton?: Button;
private _extensionList?: List<IDashboardUITab>;
private _extensionViewContainer?: HTMLElement;
private _noExtensionViewContainer?: HTMLElement;
private _viewModel: NewDashboardTabViewModel;
@@ -139,7 +139,7 @@ export class NewDashboardTabDialog extends Modal {
// MODAL OVERRIDE METHODS //////////////////////////////////////////////
protected layout(height?: number): void {
this._extensionList.layout(height);
this._extensionList!.layout(height);
}
public render() {
@@ -188,8 +188,8 @@ export class NewDashboardTabDialog extends Modal {
private registerListeners(): void {
// Theme styler
this._register(attachButtonStyler(this._cancelButton, this._themeService));
this._register(attachButtonStyler(this._addNewTabButton, this._themeService));
this._register(attachButtonStyler(this._cancelButton!, this._themeService));
this._register(attachButtonStyler(this._addNewTabButton!, this._themeService));
}
/* Overwrite escape key behavior */
@@ -207,8 +207,8 @@ export class NewDashboardTabDialog extends Modal {
}
private addNewTabs() {
if (this._addNewTabButton.enabled) {
let selectedTabs = this._extensionList.getSelectedElements();
if (this._addNewTabButton!.enabled) {
let selectedTabs = this._extensionList!.getSelectedElements();
this._onAddTabs.fire(selectedTabs);
}
}
@@ -223,19 +223,19 @@ export class NewDashboardTabDialog extends Modal {
}
private onUpdateTabList(tabs: IDashboardUITab[]) {
this._extensionList.splice(0, this._extensionList.length, tabs);
this._extensionList!.splice(0, this._extensionList!.length, tabs);
this.layout();
if (this._extensionList.length > 0) {
this._extensionViewContainer.hidden = false;
this._noExtensionViewContainer.hidden = true;
this._extensionList.setSelection([0]);
this._extensionList.domFocus();
this._addNewTabButton.enabled = true;
if (this._extensionList!.length > 0) {
this._extensionViewContainer!.hidden = false;
this._noExtensionViewContainer!.hidden = true;
this._extensionList!.setSelection([0]);
this._extensionList!.domFocus();
this._addNewTabButton!.enabled = true;
} else {
this._extensionViewContainer.hidden = true;
this._noExtensionViewContainer.hidden = false;
this._addNewTabButton.enabled = false;
this._cancelButton.focus();
this._extensionViewContainer!.hidden = true;
this._noExtensionViewContainer!.hidden = false;
this._addNewTabButton!.enabled = false;
this._cancelButton!.focus();
}
}

View File

@@ -15,8 +15,8 @@ export class NewDashboardTabDialogService implements INewDashboardTabDialogServi
_serviceBrand: undefined;
// MEMBER VARIABLES ////////////////////////////////////////////////////
private _addNewTabDialog: NewDashboardTabDialog;
private _uri: string;
private _addNewTabDialog?: NewDashboardTabDialog;
private _uri?: string;
constructor(
@IAngularEventingService private _angularEventService: IAngularEventingService,
@@ -45,8 +45,8 @@ export class NewDashboardTabDialogService implements INewDashboardTabDialogServi
// PRIVATE HELPERS /////////////////////////////////////////////////////
private handleOnAddTabs(selectedUiTabs: Array<IDashboardUITab>): void {
let selectedTabs = selectedUiTabs.map(tab => tab.tabConfig);
this._angularEventService.sendAngularEvent(this._uri, AngularEventType.NEW_TABS, { dashboardTabs: selectedTabs });
this._addNewTabDialog.close();
this._angularEventService.sendAngularEvent(this._uri!, AngularEventType.NEW_TABS, { dashboardTabs: selectedTabs });
this._addNewTabDialog!.close();
}
private handleOnCancel(): void { }

View File

@@ -29,14 +29,14 @@ const maxActions = 1;
export class ErrorMessageDialog extends Modal {
private _body: HTMLElement;
private _okButton: Button;
private _copyButton: Button;
private _actionButtons: Button[];
private _actions: IAction[];
private _severity: Severity;
private _message: string;
private _messageDetails: string;
private _body?: HTMLElement;
private _okButton?: Button;
private _copyButton?: Button;
private _actionButtons: Button[] = [];
private _actions: IAction[] = [];
private _severity?: Severity;
private _message?: string;
private _messageDetails?: string;
private _okLabel: string;
private _closeLabel: string;
@@ -75,10 +75,12 @@ export class ErrorMessageDialog extends Modal {
private createCopyButton() {
let copyButtonLabel = localize('copyDetails', "Copy details");
this._copyButton = this.addFooterButton(copyButtonLabel, () => this._clipboardService.writeText(this._messageDetails).catch(err => onUnexpectedError(err)), 'left');
this._copyButton.icon = 'codicon scriptToClipboard';
this._copyButton.element.title = copyButtonLabel;
this._register(attachButtonStyler(this._copyButton, this._themeService, { buttonBackground: SIDE_BAR_BACKGROUND, buttonHoverBackground: SIDE_BAR_BACKGROUND, buttonForeground: SIDE_BAR_FOREGROUND }));
if (this._messageDetails) {
this._copyButton = this.addFooterButton(copyButtonLabel, () => this._clipboardService.writeText(this._messageDetails!).catch(err => onUnexpectedError(err)), 'left');
}
this._copyButton!.icon = 'codicon scriptToClipboard';
this._copyButton!.element.title = copyButtonLabel;
this._register(attachButtonStyler(this._copyButton!, this._themeService, { buttonBackground: SIDE_BAR_BACKGROUND, buttonHoverBackground: SIDE_BAR_BACKGROUND, buttonForeground: SIDE_BAR_FOREGROUND }));
}
private createStandardButton(label: string, onSelect: () => void): Button {
@@ -101,8 +103,8 @@ export class ErrorMessageDialog extends Modal {
}
private updateDialogBody(): void {
DOM.clearNode(this._body);
DOM.append(this._body, DOM.$('div.error-message')).innerText = this._message;
DOM.clearNode(this._body!);
DOM.append(this._body!, DOM.$('div.error-message')).innerText = this._message!;
}
private updateIconTitle(): void {
@@ -138,15 +140,15 @@ export class ErrorMessageDialog extends Modal {
this.hide();
}
public open(severity: Severity, headerTitle: string, message: string, messageDetails: string, actions: IAction[]) {
public open(severity: Severity, headerTitle: string, message: string, messageDetails?: string, actions?: IAction[]) {
this._severity = severity;
this._message = message;
this.title = headerTitle;
this._messageDetails = messageDetails;
if (this._messageDetails) {
this._copyButton.element.style.visibility = 'visible';
this._copyButton!.element.style.visibility = 'visible';
} else {
this._copyButton.element.style.visibility = 'hidden';
this._copyButton!.element.style.visibility = 'hidden';
}
this.resetActions();
if (actions && actions.length > 0) {
@@ -156,14 +158,14 @@ export class ErrorMessageDialog extends Modal {
button.label = actions[i].label;
button.element.style.visibility = 'visible';
}
this._okButton.label = this._closeLabel;
this._okButton!.label = this._closeLabel;
} else {
this._okButton.label = this._okLabel;
this._okButton!.label = this._okLabel;
}
this.updateIconTitle();
this.updateDialogBody();
this.show();
this._okButton.focus();
this._okButton!.focus();
}
private resetActions(): void {

View File

@@ -15,7 +15,7 @@ export class ErrorMessageService implements IErrorMessageService {
_serviceBrand: undefined;
private _errorDialog: ErrorMessageDialog;
private _errorDialog?: ErrorMessageDialog;
private handleOnOk(): void {
}
@@ -28,7 +28,7 @@ export class ErrorMessageService implements IErrorMessageService {
this.doShowDialog(severity, headerTitle, message, messageDetails, actions);
}
private doShowDialog(severity: Severity, headerTitle: string, message: string, messageDetails: string, actions?: IAction[]): void {
private doShowDialog(severity: Severity, headerTitle: string, message: string, messageDetails?: string, actions?: IAction[]): void {
if (!this._errorDialog) {
this._errorDialog = this._instantiationService.createInstance(ErrorMessageDialog);
this._errorDialog.onOk(() => this.handleOnOk());
@@ -40,17 +40,15 @@ export class ErrorMessageService implements IErrorMessageService {
}
private getDefaultTitle(severity: Severity) {
let defaultTitle: string;
switch (severity) {
case Severity.Error:
defaultTitle = localize('error', "Error");
break;
return localize('error', "Error");
case Severity.Warning:
defaultTitle = localize('warning', "Warning");
break;
return localize('warning', "Warning");
case Severity.Info:
defaultTitle = localize('info', "Info");
return localize('info', "Info");
case Severity.Ignore:
return localize('ignore', "Ignore");
}
return defaultTitle;
}
}

View File

@@ -41,8 +41,8 @@ export interface IJobManagementService {
getTemplateNotebook(connectionUri: string, targetDatabase: string, jobId: string): Thenable<azdata.AgentNotebookTemplateResult>;
deleteNotebook(connectionUri: string, notebook: azdata.AgentNotebookInfo): Thenable<azdata.ResultStatus>;
deleteMaterializedNotebook(connectionUri: string, agentNotebookHistory: azdata.AgentNotebookHistoryInfo, targetDatabase: string): Thenable<azdata.ResultStatus>;
updateNotebookMaterializedName(connectionUri: string, agentNotebookHistory: azdata.AgentNotebookHistoryInfo, targetDatabase: string, name: string);
updateNotebookMaterializedPin(connectionUri: string, agentNotebookHistory: azdata.AgentNotebookHistoryInfo, targetDatabase: string, pin: boolean);
updateNotebookMaterializedName(connectionUri: string, agentNotebookHistory: azdata.AgentNotebookHistoryInfo, targetDatabase: string, name: string): Promise<azdata.ResultStatus>;
updateNotebookMaterializedPin(connectionUri: string, agentNotebookHistory: azdata.AgentNotebookHistoryInfo, targetDatabase: string, pin: boolean): Promise<azdata.ResultStatus>;
getAlerts(connectionUri: string): Thenable<azdata.AgentAlertsResult>;
deleteAlert(connectionUri: string, alert: azdata.AgentAlertInfo): Thenable<azdata.ResultStatus>;
@@ -56,11 +56,11 @@ export interface IJobManagementService {
getCredentials(connectionUri: string): Thenable<azdata.GetCredentialsResult>;
jobAction(connectionUri: string, jobName: string, action: string): Thenable<azdata.ResultStatus>;
addToCache(server: string, cache: JobCacheObject | OperatorsCacheObject | NotebookCacheObject);
addToCache(server: string, cache: JobCacheObject | OperatorsCacheObject | NotebookCacheObject): void;
jobCacheObjectMap: { [server: string]: JobCacheObject; };
notebookCacheObjectMap: { [server: string]: NotebookCacheObject; };
operatorsCacheObjectMap: { [server: string]: OperatorsCacheObject; };
alertsCacheObjectMap: { [server: string]: AlertsCacheObject; };
proxiesCacheObjectMap: { [server: string]: ProxiesCacheObject };
addToCache(server: string, cache: JobCacheObject | ProxiesCacheObject | AlertsCacheObject | OperatorsCacheObject | NotebookCacheObject);
addToCache(server: string, cache: JobCacheObject | ProxiesCacheObject | AlertsCacheObject | OperatorsCacheObject | NotebookCacheObject): void;
}

View File

@@ -34,32 +34,32 @@ export class JobManagementService implements IJobManagementService {
}
// Jobs
public getJobs(connectionUri: string): Thenable<azdata.AgentJobsResult> {
public getJobs(connectionUri: string): Promise<azdata.AgentJobsResult> {
return this._runAction(connectionUri, (runner) => {
return runner.getJobs(connectionUri);
});
}
public deleteJob(connectionUri: string, job: azdata.AgentJobInfo): Thenable<azdata.ResultStatus> {
public deleteJob(connectionUri: string, job: azdata.AgentJobInfo): Promise<azdata.ResultStatus> {
return this._runAction(connectionUri, (runner) => {
return runner.deleteJob(connectionUri, job);
});
}
public getJobHistory(connectionUri: string, jobID: string, jobName: string): Thenable<azdata.AgentJobHistoryResult> {
public getJobHistory(connectionUri: string, jobID: string, jobName: string): Promise<azdata.AgentJobHistoryResult> {
return this._runAction(connectionUri, (runner) => {
return runner.getJobHistory(connectionUri, jobID, jobName);
});
}
public jobAction(connectionUri: string, jobName: string, action: string): Thenable<azdata.ResultStatus> {
public jobAction(connectionUri: string, jobName: string, action: string): Promise<azdata.ResultStatus> {
return this._runAction(connectionUri, (runner) => {
return runner.jobAction(connectionUri, jobName, action);
});
}
// Steps
public deleteJobStep(connectionUri: string, stepInfo: azdata.AgentJobStepInfo): Thenable<azdata.ResultStatus> {
public deleteJobStep(connectionUri: string, stepInfo: azdata.AgentJobStepInfo): Promise<azdata.ResultStatus> {
return this._runAction(connectionUri, (runner) => {
return runner.deleteJobStep(connectionUri, stepInfo);
});
@@ -71,100 +71,100 @@ export class JobManagementService implements IJobManagementService {
}
// Notebooks
public getNotebooks(connectionUri: string): Thenable<azdata.AgentNotebooksResult> {
public getNotebooks(connectionUri: string): Promise<azdata.AgentNotebooksResult> {
return this._runAction(connectionUri, (runner) => {
return runner.getNotebooks(connectionUri);
});
}
public getNotebookHistory(connectionUri: string, jobID: string, jobName: string, targetDatabase: string): Thenable<azdata.AgentNotebookHistoryResult> {
public getNotebookHistory(connectionUri: string, jobID: string, jobName: string, targetDatabase: string): Promise<azdata.AgentNotebookHistoryResult> {
return this._runAction(connectionUri, (runner) => {
return runner.getNotebookHistory(connectionUri, jobID, jobName, targetDatabase);
});
}
public getMaterialziedNotebook(connectionUri: string, targetDatabase: string, notebookMaterializedId: number): Thenable<azdata.AgentNotebookMaterializedResult> {
public getMaterialziedNotebook(connectionUri: string, targetDatabase: string, notebookMaterializedId: number): Promise<azdata.AgentNotebookMaterializedResult> {
return this._runAction(connectionUri, (runner) => {
return runner.getMaterializedNotebook(connectionUri, targetDatabase, notebookMaterializedId);
});
}
public getTemplateNotebook(connectionUri: string, targetDatabase: string, jobId: string): Thenable<azdata.AgentNotebookTemplateResult> {
public getTemplateNotebook(connectionUri: string, targetDatabase: string, jobId: string): Promise<azdata.AgentNotebookTemplateResult> {
return this._runAction(connectionUri, (runner) => {
return runner.getTemplateNotebook(connectionUri, targetDatabase, jobId);
});
}
public deleteNotebook(connectionUri: string, notebook: azdata.AgentNotebookInfo): Thenable<azdata.ResultStatus> {
public deleteNotebook(connectionUri: string, notebook: azdata.AgentNotebookInfo): Promise<azdata.ResultStatus> {
return this._runAction(connectionUri, (runner) => {
return runner.deleteNotebook(connectionUri, notebook);
});
}
public deleteMaterializedNotebook(connectionUri: string, agentNotebookHistory: azdata.AgentNotebookHistoryInfo, targetDatabase: string): Thenable<azdata.ResultStatus> {
public deleteMaterializedNotebook(connectionUri: string, agentNotebookHistory: azdata.AgentNotebookHistoryInfo, targetDatabase: string): Promise<azdata.ResultStatus> {
return this._runAction(connectionUri, (runner) => {
return runner.deleteMaterializedNotebook(connectionUri, agentNotebookHistory, targetDatabase);
});
}
public updateNotebookMaterializedName(connectionUri: string, agentNotebookHistory: azdata.AgentNotebookHistoryInfo, targetDatabase: string, name: string): Thenable<azdata.ResultStatus> {
public updateNotebookMaterializedName(connectionUri: string, agentNotebookHistory: azdata.AgentNotebookHistoryInfo, targetDatabase: string, name: string): Promise<azdata.ResultStatus> {
return this._runAction(connectionUri, (runner) => {
return runner.updateNotebookMaterializedName(connectionUri, agentNotebookHistory, targetDatabase, name);
});
}
public updateNotebookMaterializedPin(connectionUri: string, agentNotebookHistory: azdata.AgentNotebookHistoryInfo, targetDatabase: string, pin: boolean): Thenable<azdata.ResultStatus> {
public updateNotebookMaterializedPin(connectionUri: string, agentNotebookHistory: azdata.AgentNotebookHistoryInfo, targetDatabase: string, pin: boolean): Promise<azdata.ResultStatus> {
return this._runAction(connectionUri, (runner) => {
return runner.updateNotebookMaterializedPin(connectionUri, agentNotebookHistory, targetDatabase, pin);
});
}
// Alerts
public getAlerts(connectionUri: string): Thenable<azdata.AgentAlertsResult> {
public getAlerts(connectionUri: string): Promise<azdata.AgentAlertsResult> {
return this._runAction(connectionUri, (runner) => {
return runner.getAlerts(connectionUri);
});
}
public deleteAlert(connectionUri: string, alert: azdata.AgentAlertInfo): Thenable<azdata.ResultStatus> {
public deleteAlert(connectionUri: string, alert: azdata.AgentAlertInfo): Promise<azdata.ResultStatus> {
return this._runAction(connectionUri, (runner) => {
return runner.deleteAlert(connectionUri, alert);
});
}
// Operators
public getOperators(connectionUri: string): Thenable<azdata.AgentOperatorsResult> {
public getOperators(connectionUri: string): Promise<azdata.AgentOperatorsResult> {
return this._runAction(connectionUri, (runner) => {
return runner.getOperators(connectionUri);
});
}
public deleteOperator(connectionUri: string, operator: azdata.AgentOperatorInfo): Thenable<azdata.ResultStatus> {
public deleteOperator(connectionUri: string, operator: azdata.AgentOperatorInfo): Promise<azdata.ResultStatus> {
return this._runAction(connectionUri, (runner) => {
return runner.deleteOperator(connectionUri, operator);
});
}
// Proxies
public getProxies(connectionUri: string): Thenable<azdata.AgentProxiesResult> {
public getProxies(connectionUri: string): Promise<azdata.AgentProxiesResult> {
return this._runAction(connectionUri, (runner) => {
return runner.getProxies(connectionUri);
});
}
public deleteProxy(connectionUri: string, proxy: azdata.AgentProxyInfo): Thenable<azdata.ResultStatus> {
public deleteProxy(connectionUri: string, proxy: azdata.AgentProxyInfo): Promise<azdata.ResultStatus> {
return this._runAction(connectionUri, (runner) => {
return runner.deleteProxy(connectionUri, proxy);
});
}
public getCredentials(connectionUri: string): Thenable<azdata.GetCredentialsResult> {
public getCredentials(connectionUri: string): Promise<azdata.GetCredentialsResult> {
return this._runAction(connectionUri, (runner) => {
return runner.getCredentials(connectionUri);
});
}
private _runAction<T>(uri: string, action: (handler: azdata.AgentServicesProvider) => Thenable<T>): Thenable<T> {
private _runAction<T>(uri: string, action: (handler: azdata.AgentServicesProvider) => Thenable<T>): Promise<T> {
let providerId: string = this._connectionService.getProviderIdFromUri(uri);
if (!providerId) {
@@ -172,7 +172,7 @@ export class JobManagementService implements IJobManagementService {
}
let handler = this._providers[providerId];
if (handler) {
return action(handler);
return Promise.resolve(action(handler));
} else {
return Promise.reject(new Error(localize('noHandlerRegistered', "No Handler Registered")));
}
@@ -228,9 +228,9 @@ export class JobCacheObject {
private _jobAlerts: { [jobID: string]: azdata.AgentAlertInfo[]; } = {};
private _jobSchedules: { [jobID: string]: azdata.AgentJobScheduleInfo[]; } = {};
private _runCharts: { [jobID: string]: string[]; } = {};
private _prevJobID: string;
private _serverName: string;
private _dataView: Slick.Data.DataView<any>;
private _prevJobID?: string;
private _serverName?: string;
private _dataView?: Slick.Data.DataView<any>;
/* Getters */
public get jobs(): azdata.AgentJobInfo[] {
@@ -241,7 +241,7 @@ export class JobCacheObject {
return this._jobHistories;
}
public get prevJobID(): string {
public get prevJobID(): string | undefined {
return this._prevJobID;
}
@@ -249,11 +249,11 @@ export class JobCacheObject {
return this._jobHistories[jobID];
}
public get serverName(): string {
public get serverName(): string | undefined {
return this._serverName;
}
public get dataView(): Slick.Data.DataView<any> {
public get dataView(): Slick.Data.DataView<any> | undefined {
return this._dataView;
}
@@ -282,7 +282,7 @@ export class JobCacheObject {
this._jobHistories = value;
}
public set prevJobID(value: string) {
public set prevJobID(value: string | undefined) {
this._prevJobID = value;
}
@@ -294,11 +294,11 @@ export class JobCacheObject {
this._runCharts[jobID] = value;
}
public set serverName(value: string) {
public set serverName(value: string | undefined) {
this._serverName = value;
}
public set dataView(value: Slick.Data.DataView<any>) {
public set dataView(value: Slick.Data.DataView<any> | undefined) {
this._dataView = value;
}
@@ -324,9 +324,9 @@ export class NotebookCacheObject {
private _jobSteps: { [jobID: string]: azdata.AgentJobStepInfo[]; } = {};
private _jobSchedules: { [jobID: string]: azdata.AgentJobScheduleInfo[]; } = {};
private _runCharts: { [jobID: string]: string[]; } = {};
private _prevJobID: string;
private _serverName: string;
private _dataView: Slick.Data.DataView<any>;
private _prevJobID?: string;
private _serverName?: string;
private _dataView?: Slick.Data.DataView<any>;
/* Getters */
public get notebooks(): azdata.AgentNotebookInfo[] {
@@ -337,7 +337,7 @@ export class NotebookCacheObject {
return this._notebookHistories;
}
public get prevJobID(): string {
public get prevJobID(): string | undefined {
return this._prevJobID;
}
@@ -345,11 +345,11 @@ export class NotebookCacheObject {
return this._notebookHistories[jobID];
}
public get serverName(): string {
public get serverName(): string | undefined {
return this._serverName;
}
public get dataView(): Slick.Data.DataView<any> {
public get dataView(): Slick.Data.DataView<any> | undefined {
return this._dataView;
}
@@ -374,7 +374,7 @@ export class NotebookCacheObject {
this._notebookHistories = value;
}
public set prevJobID(value: string) {
public set prevJobID(value: string | undefined) {
this._prevJobID = value;
}
@@ -386,11 +386,11 @@ export class NotebookCacheObject {
this._runCharts[jobID] = value;
}
public set serverName(value: string) {
public set serverName(value: string | undefined) {
this._serverName = value;
}
public set dataView(value: Slick.Data.DataView<any>) {
public set dataView(value: Slick.Data.DataView<any> | undefined) {
this._dataView = value;
}
@@ -408,33 +408,33 @@ export class NotebookCacheObject {
*/
export class OperatorsCacheObject {
_serviceBrand: undefined;
private _operators: azdata.AgentOperatorInfo[];
private _dataView: Slick.Data.DataView<any>;
private _serverName: string;
private _operators?: azdata.AgentOperatorInfo[];
private _dataView?: Slick.Data.DataView<any>;
private _serverName?: string;
/** Getters */
public get operators(): azdata.AgentOperatorInfo[] {
public get operators(): azdata.AgentOperatorInfo[] | undefined {
return this._operators;
}
public get dataview(): Slick.Data.DataView<any> {
public get dataview(): Slick.Data.DataView<any> | undefined {
return this._dataView;
}
public get serverName(): string {
public get serverName(): string | undefined {
return this._serverName;
}
/** Setters */
public set operators(value: azdata.AgentOperatorInfo[]) {
public set operators(value: azdata.AgentOperatorInfo[] | undefined) {
this._operators = value;
}
public set dataview(value: Slick.Data.DataView<any>) {
public set dataview(value: Slick.Data.DataView<any> | undefined) {
this._dataView = value;
}
public set serverName(value: string) {
public set serverName(value: string | undefined) {
this._serverName = value;
}
@@ -445,33 +445,33 @@ export class OperatorsCacheObject {
*/
export class AlertsCacheObject {
_serviceBrand: undefined;
private _alerts: azdata.AgentAlertInfo[];
private _dataView: Slick.Data.DataView<any>;
private _serverName: string;
private _alerts?: azdata.AgentAlertInfo[];
private _dataView?: Slick.Data.DataView<any>;
private _serverName?: string;
/** Getters */
public get alerts(): azdata.AgentAlertInfo[] {
public get alerts(): azdata.AgentAlertInfo[] | undefined {
return this._alerts;
}
public get dataview(): Slick.Data.DataView<any> {
public get dataview(): Slick.Data.DataView<any> | undefined {
return this._dataView;
}
public get serverName(): string {
public get serverName(): string | undefined {
return this._serverName;
}
/** Setters */
public set alerts(value: azdata.AgentAlertInfo[]) {
public set alerts(value: azdata.AgentAlertInfo[] | undefined) {
this._alerts = value;
}
public set dataview(value: Slick.Data.DataView<any>) {
public set dataview(value: Slick.Data.DataView<any> | undefined) {
this._dataView = value;
}
public set serverName(value: string) {
public set serverName(value: string | undefined) {
this._serverName = value;
}
}
@@ -482,36 +482,36 @@ export class AlertsCacheObject {
*/
export class ProxiesCacheObject {
_serviceBrand: undefined;
private _proxies: azdata.AgentProxyInfo[];
private _dataView: Slick.Data.DataView<any>;
private _serverName: string;
private _proxies?: azdata.AgentProxyInfo[];
private _dataView?: Slick.Data.DataView<any>;
private _serverName?: string;
/**
* Getters
*/
public get proxies(): azdata.AgentProxyInfo[] {
public get proxies(): azdata.AgentProxyInfo[] | undefined {
return this._proxies;
}
public get dataview(): Slick.Data.DataView<any> {
public get dataview(): Slick.Data.DataView<any> | undefined {
return this._dataView;
}
public get serverName(): string {
public get serverName(): string | undefined {
return this._serverName;
}
/** Setters */
public set proxies(value: azdata.AgentProxyInfo[]) {
public set proxies(value: azdata.AgentProxyInfo[] | undefined) {
this._proxies = value;
}
public set dataview(value: Slick.Data.DataView<any>) {
public set dataview(value: Slick.Data.DataView<any> | undefined) {
this._dataView = value;
}
public set serverName(value: string) {
public set serverName(value: string | undefined) {
this._serverName = value;
}
}

View File

@@ -13,7 +13,7 @@ suite('Job Management service tests', () => {
test('Construction - Job Service Initialization', () => {
// ... Create instance of the service and reder account picker
let service = new JobManagementService(undefined);
let service = new JobManagementService(undefined!);
assert(service);
});
});

View File

@@ -19,7 +19,7 @@ export class QueryHistoryInfo {
public database: string;
public status: QueryStatus;
public status?: QueryStatus;
public readonly id = generateUuid();

View File

@@ -26,7 +26,7 @@ export class QueryHistoryService extends Disposable implements IQueryHistoryServ
private _infos: QueryHistoryInfo[] = [];
private _onInfosUpdated: Emitter<QueryHistoryInfo[]> = new Emitter<QueryHistoryInfo[]>();
private _onQueryHistoryCaptureChanged: Emitter<boolean> = new Emitter<boolean>();
private _captureEnabled;
private _captureEnabled: boolean;
// EVENTS //////////////////////////////////////////////////////////////
public get onInfosUpdated(): Event<QueryHistoryInfo[]> { return this._onInfosUpdated.event; }
public get onQueryHistoryCaptureChanged(): Event<boolean> { return this._onQueryHistoryCaptureChanged.event; }
@@ -50,29 +50,32 @@ export class QueryHistoryService extends Disposable implements IQueryHistoryServ
this._register(_queryModelService.onQueryEvent((e: IQueryEvent) => {
if (this._captureEnabled && e.type === 'queryStop') {
const uri: URI = URI.parse(e.uri);
// VS Range is 1 based so offset values by 1. The endLine we get back from SqlToolsService is incremented
// by 1 from the original input range sent in as well so take that into account and don't modify
const text: string = e.queryInfo.range && e.queryInfo.range.length > 0 ?
_modelService.getModel(uri).getValueInRange(new Range(
e.queryInfo.range[0].startLineNumber,
e.queryInfo.range[0].startColumn,
e.queryInfo.range[0].endLineNumber,
e.queryInfo.range[0].endColumn)) :
// If no specific selection get the entire text
_modelService.getModel(uri).getValue();
const model = _modelService.getModel(uri);
if (model) {
// VS Range is 1 based so offset values by 1. The endLine we get back from SqlToolsService is incremented
// by 1 from the original input range sent in as well so take that into account and don't modify
const text: string = e.queryInfo.range && e.queryInfo.range.length > 0 ?
model.getValueInRange(new Range(
e.queryInfo.range[0].startLineNumber,
e.queryInfo.range[0].startColumn,
e.queryInfo.range[0].endLineNumber,
e.queryInfo.range[0].endColumn)) :
// If no specific selection get the entire text
model.getValue();
const newInfo = new QueryHistoryInfo(text, _connectionManagementService.getConnectionProfile(e.uri), new Date(), QueryStatus.Succeeded);
const newInfo = new QueryHistoryInfo(text, _connectionManagementService.getConnectionProfile(e.uri), new Date(), QueryStatus.Succeeded);
// icon as required (for now logic is if any message has error query has error)
let error: boolean = false;
e.queryInfo.messages.forEach(x => error = error || x.isError);
if (error) {
newInfo.status = QueryStatus.Failed;
// icon as required (for now logic is if any message has error query has error)
let error: boolean = false;
e.queryInfo.messages.forEach(x => error = error || x.isError);
if (error) {
newInfo.status = QueryStatus.Failed;
}
// Append new node to beginning of array so the newest ones are at the top
this._infos.unshift(newInfo);
this._onInfosUpdated.fire(this._infos);
}
// Append new node to beginning of array so the newest ones are at the top
this._infos.unshift(newInfo);
this._onInfosUpdated.fire(this._infos);
}
}));
}

View File

@@ -44,15 +44,15 @@ const LocalizedStrings = {
export class FirewallRuleDialog extends Modal {
public viewModel: FirewallRuleViewModel;
private _createButton: Button;
private _closeButton: Button;
private _fromRangeinputBox: InputBox;
private _toRangeinputBox: InputBox;
private _createButton?: Button;
private _closeButton?: Button;
private _fromRangeinputBox?: InputBox;
private _toRangeinputBox?: InputBox;
private _helpLink: HTMLElement;
private _IPAddressInput: HTMLElement;
private _subnetIPRangeInput: HTMLElement;
private _IPAddressElement: HTMLElement;
private _helpLink?: HTMLElement;
private _IPAddressInput?: HTMLElement;
private _subnetIPRangeInput?: HTMLElement;
private _IPAddressElement?: HTMLElement;
// EVENTING ////////////////////////////////////////////////////////////
private _onAddAccountErrorEmitter: Emitter<string>;
@@ -105,8 +105,8 @@ export class FirewallRuleDialog extends Modal {
public render() {
super.render();
attachModalDialogStyler(this, this._themeService);
this.backButton.onDidClick(() => this.cancel());
this._register(attachButtonStyler(this.backButton, this._themeService, { buttonBackground: SIDE_BAR_BACKGROUND, buttonHoverBackground: SIDE_BAR_BACKGROUND }));
this.backButton!.onDidClick(() => this.cancel());
this._register(attachButtonStyler(this.backButton!, this._themeService, { buttonBackground: SIDE_BAR_BACKGROUND, buttonHoverBackground: SIDE_BAR_BACKGROUND }));
this._createButton = this.addFooterButton(localize('firewall.ok', "OK"), () => this.createFirewallRule());
this._closeButton = this.addFooterButton(localize('firewall.cancel', "Cancel"), () => this.cancel());
this.registerListeners();
@@ -138,7 +138,7 @@ export class FirewallRuleDialog extends Modal {
});
this._accountPickerService.addAccountStartEvent(() => this.spinner = true);
this._accountPickerService.onAccountSelectionChangeEvent((account) => this.onAccountSelectionChange(account));
this._accountPickerService.onTenantSelectionChangeEvent((tenantId) => this.onTenantSelectionChange(tenantId));
this._accountPickerService.onTenantSelectionChangeEvent((tenantId) => !!tenantId && this.onTenantSelectionChange(tenantId));
const azureAccountSection = DOM.append(body, DOM.$('.azure-account-section.new-section'));
this._accountPickerService.renderAccountPicker(azureAccountSection);
@@ -222,7 +222,7 @@ export class FirewallRuleDialog extends Modal {
// Update theming that is specific to firewall rule flyout body
private updateTheme(theme: IColorTheme): void {
const linkColor = theme.getColor(buttonBackground);
const link = linkColor ? linkColor.toString() : null;
const link = linkColor ? linkColor.toString() : '';
if (this._helpLink) {
this._helpLink.style.color = link;
}
@@ -230,18 +230,18 @@ export class FirewallRuleDialog extends Modal {
private registerListeners(): void {
// Theme styler
this._register(attachButtonStyler(this._createButton, this._themeService));
this._register(attachButtonStyler(this._closeButton, this._themeService));
this._register(attachInputBoxStyler(this._fromRangeinputBox, this._themeService));
this._register(attachInputBoxStyler(this._toRangeinputBox, this._themeService));
this._register(attachButtonStyler(this._createButton!, this._themeService));
this._register(attachButtonStyler(this._closeButton!, this._themeService));
this._register(attachInputBoxStyler(this._fromRangeinputBox!, this._themeService));
this._register(attachInputBoxStyler(this._toRangeinputBox!, this._themeService));
// handler for from subnet ip range change events
this._register(this._fromRangeinputBox.onDidChange(IPAddress => {
this._register(this._fromRangeinputBox!.onDidChange(IPAddress => {
this.fromRangeInputChanged(IPAddress);
}));
// handler for to subnet ip range change events
this._register(this._toRangeinputBox.onDidChange(IPAddress => {
this._register(this._toRangeinputBox!.onDidChange(IPAddress => {
this.toRangeInputChanged(IPAddress);
}));
}
@@ -274,8 +274,8 @@ export class FirewallRuleDialog extends Modal {
}
public createFirewallRule() {
if (this._createButton.enabled) {
this._createButton.enabled = false;
if (this._createButton!.enabled) {
this._createButton!.enabled = false;
this.spinner = true;
this._onCreateFirewallRule.fire();
}
@@ -284,9 +284,9 @@ export class FirewallRuleDialog extends Modal {
public onAccountSelectionChange(account: azdata.Account | undefined): void {
this.viewModel.selectedAccount = account;
if (account && !account.isStale) {
this._createButton.enabled = true;
this._createButton!.enabled = true;
} else {
this._createButton.enabled = false;
this._createButton!.enabled = false;
}
}
@@ -295,16 +295,16 @@ export class FirewallRuleDialog extends Modal {
}
public onServiceComplete() {
this._createButton.enabled = true;
this._createButton!.enabled = true;
this.spinner = false;
}
public open() {
this._IPAddressInput.click();
this._IPAddressInput!.click();
this.onAccountSelectionChange(this._accountPickerService.selectedAccount);
this._fromRangeinputBox.setPlaceHolder(this.viewModel.defaultFromSubnetIPRange);
this._toRangeinputBox.setPlaceHolder(this.viewModel.defaultToSubnetIPRange);
this._IPAddressElement.innerText = '(' + this.viewModel.defaultIPAddress + ')';
this._fromRangeinputBox!.setPlaceHolder(this.viewModel!.defaultFromSubnetIPRange ?? '');
this._toRangeinputBox!.setPlaceHolder(this.viewModel!.defaultToSubnetIPRange ?? '');
this._IPAddressElement!.innerText = '(' + this.viewModel.defaultIPAddress ?? '' + ')';
this.show();
}

View File

@@ -17,13 +17,13 @@ import { IErrorMessageService } from 'sql/platform/errorMessage/common/errorMess
export class FirewallRuleDialogController {
private _firewallRuleDialog: FirewallRuleDialog;
private _connection: IConnectionProfile;
private _resourceProviderId: string;
private _firewallRuleDialog?: FirewallRuleDialog;
private _connection?: IConnectionProfile;
private _resourceProviderId?: string;
private _addAccountErrorTitle = localize('firewallDialog.addAccountErrorTitle', "Error adding account");
private _firewallRuleErrorTitle = localize('firewallRuleError', "Firewall rule error");
private _deferredPromise: Deferred<boolean>;
private _deferredPromise?: Deferred<boolean>;
constructor(
@IInstantiationService private _instantiationService: IInstantiationService,
@@ -58,29 +58,29 @@ export class FirewallRuleDialogController {
}
private async handleOnCreateFirewallRule(): Promise<void> {
const resourceProviderId = this._resourceProviderId;
const resourceProviderId = this._resourceProviderId!;
try {
const tenantId = this._firewallRuleDialog.viewModel.selectedTenantId;
const token = await this._accountManagementService.getAccountSecurityToken(this._firewallRuleDialog.viewModel.selectedAccount!, tenantId, AzureResource.ResourceManagement);
const tenantId = this._firewallRuleDialog!.viewModel.selectedTenantId!;
const token = await this._accountManagementService.getAccountSecurityToken(this._firewallRuleDialog!.viewModel.selectedAccount!, tenantId, AzureResource.ResourceManagement);
const securityTokenMappings = {
[tenantId]: token
};
const firewallRuleInfo: azdata.FirewallRuleInfo = {
startIpAddress: this._firewallRuleDialog.viewModel.isIPAddressSelected ? this._firewallRuleDialog.viewModel.defaultIPAddress : this._firewallRuleDialog.viewModel.fromSubnetIPRange,
endIpAddress: this._firewallRuleDialog.viewModel.isIPAddressSelected ? this._firewallRuleDialog.viewModel.defaultIPAddress : this._firewallRuleDialog.viewModel.toSubnetIPRange,
serverName: this._connection.serverName,
startIpAddress: this._firewallRuleDialog!.viewModel.isIPAddressSelected ? this._firewallRuleDialog!.viewModel.defaultIPAddress : this._firewallRuleDialog!.viewModel.fromSubnetIPRange,
endIpAddress: this._firewallRuleDialog!.viewModel.isIPAddressSelected ? this._firewallRuleDialog!.viewModel.defaultIPAddress : this._firewallRuleDialog!.viewModel.toSubnetIPRange,
serverName: this._connection!.serverName,
securityTokenMappings
};
const response = await this._resourceProviderService.createFirewallRule(this._firewallRuleDialog.viewModel.selectedAccount!, firewallRuleInfo, resourceProviderId);
const response = await this._resourceProviderService.createFirewallRule(this._firewallRuleDialog!.viewModel.selectedAccount!, firewallRuleInfo, resourceProviderId);
if (response.result) {
this._firewallRuleDialog.close();
this._deferredPromise.resolve(true);
this._firewallRuleDialog!.close();
this._deferredPromise!.resolve(true);
} else {
this._errorMessageService.showDialog(Severity.Error, this._firewallRuleErrorTitle, response.errorMessage);
}
this._firewallRuleDialog.onServiceComplete();
this._firewallRuleDialog!.onServiceComplete();
} catch (e) {
this.showError(e);
}
@@ -88,12 +88,12 @@ export class FirewallRuleDialogController {
private showError(error: any): void {
this._errorMessageService.showDialog(Severity.Error, this._firewallRuleErrorTitle, error);
this._firewallRuleDialog.onServiceComplete();
this._firewallRuleDialog!.onServiceComplete();
// Note: intentionally not rejecting the promise as we want users to be able to choose a different account
}
private handleOnCancel(): void {
this._deferredPromise.resolve(false);
this._deferredPromise!.resolve(false);
}
}

View File

@@ -18,7 +18,7 @@ export class ResourceProviderService implements IResourceProviderService {
public _serviceBrand: undefined;
private _providers: { [handle: string]: azdata.ResourceProvider; } = Object.create(null);
private _firewallRuleDialogController: FirewallRuleDialogController;
private _firewallRuleDialogController?: FirewallRuleDialogController;
constructor(
@IAdsTelemetryService private _telemetryService: IAdsTelemetryService,

View File

@@ -14,8 +14,8 @@ export const IResourceProviderService = createDecorator<IResourceProviderService
export interface IHandleFirewallRuleResult {
canHandleFirewallRule: boolean;
ipAddress: string;
resourceProviderId: string;
ipAddress?: string;
resourceProviderId?: string;
}
export interface IResourceProviderService {

View File

@@ -237,7 +237,7 @@ function getMockResourceProvider(resolveCreateFirewallRule: boolean, response?:
let resourceProviderStub = new TestResourceProvider();
let mockResourceProvider = TypeMoq.Mock.ofInstance(resourceProviderStub);
mockResourceProvider.setup(x => x.createFirewallRule(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny()))
.returns(() => resolveCreateFirewallRule ? Promise.resolve(response) : Promise.reject(null));
.returns(() => resolveCreateFirewallRule ? Promise.resolve(response!) : Promise.reject(null));
return mockResourceProvider;
}

View File

@@ -12,7 +12,7 @@ import { IServerGroupController, IServerGroupDialogCallbacks } from 'sql/platfor
import { IConnectionManagementService } from 'sql/platform/connection/common/connectionManagement';
import { ServerGroupDialog } from 'sql/workbench/services/serverGroup/browser/serverGroupDialog';
import { ServerGroupViewModel } from 'sql/workbench/services/serverGroup/common/serverGroupViewModel';
import { ConnectionProfileGroup, IConnectionProfileGroup } from 'sql/platform/connection/common/connectionProfileGroup';
import { ConnectionProfileGroup, INewConnectionProfileGroup } from 'sql/platform/connection/common/connectionProfileGroup';
import { SERVER_GROUP_CONFIG, SERVER_GROUP_COLORS_CONFIG } from 'sql/workbench/services/serverGroup/common/interfaces';
export class ServerGroupController implements IServerGroupController {
@@ -47,12 +47,11 @@ export class ServerGroupController implements IServerGroupController {
});
} else {
let newGroup: IConnectionProfileGroup = {
name: this._viewModel.groupName,
id: undefined,
let newGroup: INewConnectionProfileGroup = {
name: viewModel.groupName,
parentId: undefined,
color: this._viewModel.groupColor,
description: this._viewModel.groupDescription
color: viewModel.groupColor,
description: viewModel.groupDescription
};
this.connectionManagementService.saveProfileGroup(newGroup).then(groupId => {
if (this._callbacks) {