More layering and compile strictness (#8973)

* add more folders to strictire compile, add more strict compile options

* update ci

* wip

* add more layering and fix issues

* add more strictness

* remove unnecessary assertion

* add missing checks

* fix indentation

* remove jsdoc
This commit is contained in:
Anthony Dresser
2020-01-29 20:35:11 -08:00
committed by GitHub
parent ddfdd43fc3
commit 56695be14a
185 changed files with 725 additions and 635 deletions

View File

@@ -2,12 +2,10 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { Type } from '@angular/core';
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/contrib/charts/browser/interfaces';
import { values } from 'vs/base/common/collections';
export type InsightIdentifier = string;
@@ -62,6 +60,11 @@ export interface ISize {
y: number;
}
export interface IInsightData {
columns: Array<string>;
rows: Array<Array<string>>;
}
export interface IInsightsView {
data: IInsightData;
setConfig?: (config: { [key: string]: any }) => void;
@@ -70,18 +73,22 @@ export interface IInsightsView {
export interface IInsightRegistry {
insightSchema: IJSONSchema;
registerInsight(id: string, description: string, schema: IJSONSchema, ctor: Type<IInsightsView>): InsightIdentifier;
registerInsight(id: string, description: string, schema: IJSONSchema, ctor: IInsightsViewCtor): InsightIdentifier;
registerExtensionInsight(id: string, val: IInsightsConfig): void;
getRegisteredExtensionInsights(id: string): IInsightsConfig;
getCtorFromId(id: string): Type<IInsightsView>;
getAllCtors(): Array<Type<IInsightsView>>;
getCtorFromId(id: string): IInsightsViewCtor;
getAllCtors(): Array<IInsightsViewCtor>;
getAllIds(): Array<string>;
}
interface IInsightsViewCtor {
new(...args: any[]): IInsightsView;
}
class InsightRegistry implements IInsightRegistry {
private _insightSchema: IJSONSchema = { type: 'object', description: nls.localize('schema.dashboardWidgets.InsightsRegistry', "Widget used in the dashboards"), properties: {}, additionalProperties: false };
private _extensionInsights: { [x: string]: IInsightsConfig } = {};
private _idToCtor: { [x: string]: Type<IInsightsView> } = {};
private _idToCtor: { [x: string]: IInsightsViewCtor } = {};
/**
* Register a dashboard widget
@@ -89,7 +96,7 @@ class InsightRegistry implements IInsightRegistry {
* @param description description of the widget
* @param schema config schema of the widget
*/
public registerInsight(id: string, description: string, schema: IJSONSchema, ctor: Type<IInsightsView>): InsightIdentifier {
public registerInsight(id: string, description: string, schema: IJSONSchema, ctor: IInsightsViewCtor): InsightIdentifier {
this._insightSchema.properties![id] = schema;
this._idToCtor[id] = ctor;
return id;
@@ -103,11 +110,11 @@ class InsightRegistry implements IInsightRegistry {
return this._extensionInsights[id];
}
public getCtorFromId(id: string): Type<IInsightsView> {
public getCtorFromId(id: string): IInsightsViewCtor {
return this._idToCtor[id];
}
public getAllCtors(): Array<Type<IInsightsView>> {
public getAllCtors(): Array<IInsightsViewCtor> {
return values(this._idToCtor);
}
@@ -123,7 +130,7 @@ class InsightRegistry implements IInsightRegistry {
const insightRegistry = new InsightRegistry();
platform.Registry.add(Extensions.InsightContribution, insightRegistry);
export function registerInsight(id: string, description: string, schema: IJSONSchema, ctor: Type<IInsightsView>): InsightIdentifier {
export function registerInsight(id: string, description: string, schema: IJSONSchema, ctor: IInsightsViewCtor): InsightIdentifier {
return insightRegistry.registerInsight(id, description, schema, ctor);
}

View File

@@ -0,0 +1,129 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { IDisposable } from 'vs/base/common/lifecycle';
export interface IComponentEventArgs {
eventType: ComponentEventType;
args: any;
componentId?: string;
}
export enum ComponentEventType {
PropertiesChanged,
onDidChange,
onDidClick,
validityChanged,
onMessage,
onSelectedRowChanged,
onComponentCreated,
onCellAction,
onEnterKeyPressed
}
/**
* Defines a component and can be used to map from the model-backed version of the
* world to the frontend UI;
*
* @export
*/
export interface IComponentDescriptor {
/**
* The type of this component. Used to map to the correct angular selector
* when loading the component
*/
type: string;
/**
* A unique ID for this component
*/
id: string;
}
export interface IModelStore {
/**
* Creates and saves the reference of a component descriptor.
* This can be used during creation of a component later
*/
createComponentDescriptor(type: string, createComponentDescriptor: string): IComponentDescriptor;
/**
* gets the descriptor for a previously created component ID
*/
getComponentDescriptor(componentId: string): IComponentDescriptor;
registerComponent(component: IComponent): void;
unregisterComponent(component: IComponent): void;
getComponent(componentId: string): IComponent;
/**
* Runs on a component immediately if the component exists, or runs on
* registration of the component otherwise
*
* @param componentId unique identifier of the component
* @param action some action to perform
*/
eventuallyRunOnComponent<T>(componentId: string, action: (component: IComponent) => T): Promise<T>;
/**
* Register a callback that will validate components when given a component ID
*/
registerValidationCallback(callback: (componentId: string) => Thenable<boolean>): void;
/**
* Run all validations for the given component and return the new validation value
*/
validate(component: IComponent): Thenable<boolean>;
}
/**
* An instance of a model-backed component. This will be a UI element
*
* @export
*/
export interface IComponent extends IDisposable {
descriptor: IComponentDescriptor;
modelStore: IModelStore;
layout(): void;
registerEventHandler(handler: (event: IComponentEventArgs) => void): IDisposable;
clearContainer?: () => void;
addToContainer?: (componentDescriptor: IComponentDescriptor, config: any, index?: number) => void;
removeFromContainer?: (componentDescriptor: IComponentDescriptor) => void;
setLayout?: (layout: any) => void;
getHtml: () => any;
setProperties?: (properties: { [key: string]: any; }) => void;
enabled: boolean;
readonly valid?: boolean;
validate(): Thenable<boolean>;
setDataProvider(handle: number, componentId: string, context: any): void;
refreshDataProvider(item: any): void;
focus(): void;
}
export enum ModelComponentTypes {
NavContainer,
DivContainer,
FlexContainer,
SplitViewContainer,
Card,
InputBox,
DropDown,
DeclarativeTable,
ListBox,
Button,
CheckBox,
RadioButton,
WebView,
Text,
Table,
DashboardWidget,
DashboardWebview,
Form,
Group,
Toolbar,
LoadingComponent,
TreeComponent,
FileBrowserTree,
Editor,
DiffEditor,
Dom,
Hyperlink,
Image,
RadioCardGroup
}

View File

@@ -2,12 +2,10 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { Type } from '@angular/core';
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';
import { IComponent, ModelComponentTypes } from 'sql/platform/dashboard/browser/interfaces';
export type ComponentIdentifier = string;
@@ -15,20 +13,24 @@ export const Extensions = {
ComponentContribution: 'dashboard.contributions.components'
};
interface ComponentCtor {
new(...args: any[]): IComponent;
}
export interface IComponentRegistry {
registerComponentType(id: string, typeMapping: ModelComponentTypes, ctor: Type<IComponent>): ComponentIdentifier;
registerComponentType(id: string, typeMapping: ModelComponentTypes, ctor: ComponentCtor): ComponentIdentifier;
getIdForTypeMapping(typeMapping: ModelComponentTypes): string;
getCtorForType(typeMapping: ModelComponentTypes): Type<IComponent> | undefined;
getCtorFromId(id: string): Type<IComponent>;
getAllCtors(): Array<Type<IComponent>>;
getCtorForType(typeMapping: ModelComponentTypes): ComponentCtor | undefined;
getCtorFromId(id: string): ComponentCtor;
getAllCtors(): Array<ComponentCtor>;
getAllIds(): Array<string>;
}
class ComponentRegistry implements IComponentRegistry {
private _idToCtor: { [x: string]: Type<IComponent> } = {};
private _idToCtor: { [x: string]: ComponentCtor } = {};
private _typeNameToId: { [x: string]: string } = {};
registerComponentType(id: string, typeMapping: ModelComponentTypes, ctor: Type<IComponent>): string {
registerComponentType(id: string, typeMapping: ModelComponentTypes, ctor: ComponentCtor): string {
this._idToCtor[id] = ctor;
this._typeNameToId[ModelComponentTypes[typeMapping]] = id;
return id;
@@ -38,15 +40,15 @@ class ComponentRegistry implements IComponentRegistry {
return this._typeNameToId[ModelComponentTypes[typeMapping]];
}
public getCtorForType(typeMapping: ModelComponentTypes): Type<IComponent> | undefined {
public getCtorForType(typeMapping: ModelComponentTypes): ComponentCtor | undefined {
let id = this.getIdForTypeMapping(typeMapping);
return id ? this._idToCtor[id] : undefined;
}
public getCtorFromId(id: string): Type<IComponent> {
public getCtorFromId(id: string): ComponentCtor {
return this._idToCtor[id];
}
public getAllCtors(): Array<Type<IComponent>> {
public getAllCtors(): Array<ComponentCtor> {
return values(this._idToCtor);
}
@@ -59,6 +61,6 @@ class ComponentRegistry implements IComponentRegistry {
const componentRegistry = new ComponentRegistry();
platform.Registry.add(Extensions.ComponentContribution, componentRegistry);
export function registerComponentType(id: string, typeMapping: ModelComponentTypes, ctor: Type<IComponent>): ComponentIdentifier {
export function registerComponentType(id: string, typeMapping: ModelComponentTypes, ctor: ComponentCtor): ComponentIdentifier {
return componentRegistry.registerComponentType(id, typeMapping, ctor);
}