diff --git a/package.json b/package.json index 954a43a8af4..d1c0a619d0b 100644 --- a/package.json +++ b/package.json @@ -131,13 +131,13 @@ "style-loader": "0.23.1", "terser-webpack-plugin": "1.2.3", "ts-jest": "24.1.0", - "ts-loader": "6.1.1", - "ts-node": "8.4.1", + "ts-loader": "6.2.1", + "ts-node": "8.5.0", "tslib": "1.10.0", - "tslint": "5.20.0", + "tslint": "5.20.1", "tslint-loader": "3.5.4", "tslint-react": "4.1.0", - "typescript": "3.6.3", + "typescript": "3.7.2", "webpack": "4.29.6", "webpack-bundle-analyzer": "3.3.2", "webpack-cleanup-plugin": "0.5.1", diff --git a/packages/grafana-data/package.json b/packages/grafana-data/package.json index 0328b1ba3bb..74118783606 100644 --- a/packages/grafana-data/package.json +++ b/packages/grafana-data/package.json @@ -40,6 +40,6 @@ "rollup-plugin-visualizer": "0.9.2", "rxjs": "6.4.0", "sinon": "1.17.6", - "typescript": "3.6.3" + "typescript": "3.7.2" } } diff --git a/packages/grafana-data/src/types/datasource.ts b/packages/grafana-data/src/types/datasource.ts index ce0fb961525..eb3acec5868 100644 --- a/packages/grafana-data/src/types/datasource.ts +++ b/packages/grafana-data/src/types/datasource.ts @@ -5,7 +5,7 @@ import { PanelData } from './panel'; import { LogRowModel } from './logs'; import { AnnotationEvent, KeyValue, LoadingState, TableData, TimeSeries } from './data'; import { DataFrame, DataFrameDTO } from './dataFrame'; -import { RawTimeRange, TimeRange } from './time'; +import { RawTimeRange, TimeRange, AbsoluteTimeRange } from './time'; import { ScopedVars } from './ScopedVars'; export interface DataSourcePluginOptionsEditorProps { @@ -13,18 +13,31 @@ export interface DataSourcePluginOptionsEditorProps) => void; } +// Utility type to extract the query type TQuery from a class extending DataSourceApi +export type DataSourceQueryType> = DSType extends DataSourceApi< + infer TQuery, + infer _TOptions +> + ? TQuery + : never; + +// Utility type to extract the options type TOptions from a class extending DataSourceApi +export type DataSourceOptionsType> = DSType extends DataSourceApi< + infer _TQuery, + infer TOptions +> + ? TOptions + : never; + export class DataSourcePlugin< DSType extends DataSourceApi, - TQuery extends DataQuery = DataQuery, - TOptions extends DataSourceJsonData = DataSourceJsonData + TQuery extends DataQuery = DataSourceQueryType, + TOptions extends DataSourceJsonData = DataSourceOptionsType > extends GrafanaPlugin { - DataSourceClass: DataSourceConstructor; - components: DataSourcePluginComponents; + components: DataSourcePluginComponents = {}; - constructor(DataSourceClass: DataSourceConstructor) { + constructor(public DataSourceClass: DataSourceConstructor) { super(); - this.DataSourceClass = DataSourceClass; - this.components = {}; } setConfigEditor(editor: ComponentType>) { @@ -284,6 +297,7 @@ export interface ExploreQueryFieldProps< > extends QueryEditorProps { history: any[]; onBlur?: () => void; + absoluteRange?: AbsoluteTimeRange; } export interface ExploreStartPageProps { @@ -555,12 +569,13 @@ export interface HistoryItem { } export abstract class LanguageProvider { - datasource!: DataSourceApi; - request!: (url: string, params?: any) => Promise; + abstract datasource: DataSourceApi; + abstract request: (url: string, params?: any) => Promise; + /** * Returns startTask that resolves with a task list when main syntax is loaded. * Task list consists of secondary promises that load more detailed language features. */ - start!: () => Promise; + abstract start: () => Promise; startTask?: Promise; } diff --git a/packages/grafana-runtime/package.json b/packages/grafana-runtime/package.json index a8ae0ca262a..ded9b7001f5 100644 --- a/packages/grafana-runtime/package.json +++ b/packages/grafana-runtime/package.json @@ -37,7 +37,7 @@ "rollup-plugin-terser": "4.0.4", "rollup-plugin-typescript2": "0.19.3", "rollup-plugin-visualizer": "0.9.2", - "typescript": "3.6.3" + "typescript": "3.7.2" }, "types": "src/index.ts" } diff --git a/packages/grafana-toolkit/package.json b/packages/grafana-toolkit/package.json index c53e8d3a0ad..7ab7b1b3c3b 100644 --- a/packages/grafana-toolkit/package.json +++ b/packages/grafana-toolkit/package.json @@ -85,12 +85,12 @@ "style-loader": "^0.23.1", "terser-webpack-plugin": "^1.3.0", "ts-jest": "24.1.0", - "ts-loader": "6.1.1", - "ts-node": "8.4.1", + "ts-loader": "6.2.1", + "ts-node": "8.5.0", "tslib": "1.10.0", - "tslint": "5.20.0", + "tslint": "5.20.1", "tslint-config-prettier": "^1.18.0", - "typescript": "3.6.3", + "typescript": "3.7.2", "url-loader": "^2.0.1", "webpack": "4.35.0" }, diff --git a/packages/grafana-ui/package.json b/packages/grafana-ui/package.json index d318bf36f5d..a65812749b5 100644 --- a/packages/grafana-ui/package.json +++ b/packages/grafana-ui/package.json @@ -89,7 +89,7 @@ "rollup-plugin-terser": "4.0.4", "rollup-plugin-typescript2": "0.19.3", "rollup-plugin-visualizer": "0.9.2", - "typescript": "3.6.3" + "typescript": "3.7.2" }, "types": "src/index.ts" } diff --git a/packages/grafana-ui/src/components/Chart/Tooltip.test.tsx b/packages/grafana-ui/src/components/Chart/Tooltip.test.tsx index f4457bf0b42..28bdffb6793 100644 --- a/packages/grafana-ui/src/components/Chart/Tooltip.test.tsx +++ b/packages/grafana-ui/src/components/Chart/Tooltip.test.tsx @@ -12,7 +12,7 @@ describe('Chart Tooltip', () => { // We need to mock getBoundingClientRect to return what DOM would actually return // when measuring tooltip container (wrapper with padding and content inside) Element.prototype.getBoundingClientRect = jest.fn(() => { - return { width: 100, height: 100, top: 0, left: 0, bottom: 0, right: 0 }; + return { width: 100, height: 100, top: 0, left: 0, bottom: 0, right: 0 } as DOMRect; }); }); diff --git a/packages/grafana-ui/src/slate-plugins/suggestions.tsx b/packages/grafana-ui/src/slate-plugins/suggestions.tsx index 96fd2e6360a..818a05e8bdf 100644 --- a/packages/grafana-ui/src/slate-plugins/suggestions.tsx +++ b/packages/grafana-ui/src/slate-plugins/suggestions.tsx @@ -6,15 +6,10 @@ import { Editor as CoreEditor } from 'slate'; import { Plugin as SlatePlugin } from '@grafana/slate-react'; import TOKEN_MARK from './slate-prism/TOKEN_MARK'; -import { - makeFragment, - TypeaheadOutput, - CompletionItem, - TypeaheadInput, - SuggestionsState, - CompletionItemGroup, -} from '..'; import { Typeahead } from '../components/Typeahead/Typeahead'; +import { CompletionItem, TypeaheadOutput, TypeaheadInput, SuggestionsState } from '../types/completion'; +import { makeFragment } from '../utils/slate'; + export const TYPEAHEAD_DEBOUNCE = 100; // Commands added to the editor by this plugin. @@ -23,13 +18,6 @@ interface SuggestionsPluginCommands { applyTypeahead: (suggestion: CompletionItem) => CoreEditor; } -export interface SuggestionsState { - groupedItems: CompletionItemGroup[]; - typeaheadPrefix: string; - typeaheadContext: string; - typeaheadText: string; -} - export function SuggestionsPlugin({ onTypeahead, cleanText, diff --git a/public/app/features/explore/AdHocFilterField.tsx b/public/app/features/explore/AdHocFilterField.tsx index 9a50e9f081d..980ee9e5cb2 100644 --- a/public/app/features/explore/AdHocFilterField.tsx +++ b/public/app/features/explore/AdHocFilterField.tsx @@ -34,7 +34,7 @@ export class AdHocFilterField< > extends React.PureComponent, State> { state: State = { pairs: [] }; - componentDidUpdate(prevProps: Props) { + componentDidUpdate(prevProps: Props) { if (_.isEqual(prevProps.extendedOptions, this.props.extendedOptions) === false) { const pairs: any[] = []; diff --git a/public/app/features/explore/QueryRow.tsx b/public/app/features/explore/QueryRow.tsx index 6a16926f4cd..f8877a1280d 100644 --- a/public/app/features/explore/QueryRow.tsx +++ b/public/app/features/explore/QueryRow.tsx @@ -146,7 +146,6 @@ export class QueryRow extends PureComponent {
{QueryField ? ( - //@ts-ignore ; /** @ngInject */ constructor( @@ -60,7 +60,7 @@ export class DatasourceSrv implements DataSourceService { loadDatasource(name: string): Promise { // Expression Datasource (not a real datasource) if (name === expressionDatasource.name) { - this.datasources[name] = expressionDatasource; + this.datasources[name] = expressionDatasource as any; return this.$q.when(expressionDatasource); } diff --git a/public/app/features/plugins/plugin_loader.ts b/public/app/features/plugins/plugin_loader.ts index 23cce0674cb..ef1d9173a01 100644 --- a/public/app/features/plugins/plugin_loader.ts +++ b/public/app/features/plugins/plugin_loader.ts @@ -22,7 +22,17 @@ import config from 'app/core/config'; import TimeSeries from 'app/core/time_series2'; import TableModel from 'app/core/table_model'; import { coreModule, appEvents, contextSrv } from 'app/core/core'; -import { DataSourcePlugin, AppPlugin, PanelPlugin, PluginMeta, DataSourcePluginMeta, dateMath } from '@grafana/data'; +import { + DataSourcePlugin, + AppPlugin, + PanelPlugin, + PluginMeta, + DataSourcePluginMeta, + dateMath, + DataSourceApi, + DataSourceJsonData, + DataQuery, +} from '@grafana/data'; import * as fileExport from 'app/core/utils/file_export'; import * as flatten from 'app/core/utils/flatten'; import * as ticks from 'app/core/utils/ticks'; @@ -180,16 +190,20 @@ export async function importPluginModule(path: string): Promise { return grafanaRuntime.SystemJS.import(path); } -export function importDataSourcePlugin(meta: DataSourcePluginMeta): Promise> { +export function importDataSourcePlugin(meta: DataSourcePluginMeta): Promise { return importPluginModule(meta.module).then(pluginExports => { if (pluginExports.plugin) { - const dsPlugin = pluginExports.plugin as DataSourcePlugin; + const dsPlugin = pluginExports.plugin as GenericDataSourcePlugin; dsPlugin.meta = meta; return dsPlugin; } if (pluginExports.Datasource) { - const dsPlugin = new DataSourcePlugin(pluginExports.Datasource); + const dsPlugin = new DataSourcePlugin< + DataSourceApi, + DataQuery, + DataSourceJsonData + >(pluginExports.Datasource); dsPlugin.setComponentsFromLegacyExports(pluginExports); dsPlugin.meta = meta; return dsPlugin; @@ -210,6 +224,7 @@ export function importAppPlugin(meta: PluginMeta): Promise { } import { getPanelPluginNotFound, getPanelPluginLoadError } from '../dashboard/dashgrid/PanelPluginError'; +import { GenericDataSourcePlugin } from '../datasources/settings/PluginSettings'; interface PanelCache { [key: string]: PanelPlugin; diff --git a/public/app/plugins/datasource/elasticsearch/query_builder.ts b/public/app/plugins/datasource/elasticsearch/query_builder.ts index beeecad271f..e857202edd0 100644 --- a/public/app/plugins/datasource/elasticsearch/query_builder.ts +++ b/public/app/plugins/datasource/elasticsearch/query_builder.ts @@ -224,7 +224,7 @@ export class ElasticQueryBuilder { nestedAggs = query; for (i = 0; i < target.bucketAggs.length; i++) { - const aggDef = target.bucketAggs[i]; + const aggDef: any = target.bucketAggs[i]; const esAgg: any = {}; switch (aggDef.type) { diff --git a/yarn.lock b/yarn.lock index 2464a222901..1b00847ac68 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5862,11 +5862,6 @@ caniuse-api@^3.0.0: lodash.memoize "^4.1.2" lodash.uniq "^4.5.0" -caniuse-db@1.0.30000772: - version "1.0.30000772" - resolved "https://registry.yarnpkg.com/caniuse-db/-/caniuse-db-1.0.30000772.tgz#51aae891768286eade4a3d8319ea76d6a01b512b" - integrity sha1-UarokXaChureSj2DGep21qAbUSs= - caniuse-lite@^1.0.0, caniuse-lite@^1.0.30000939, caniuse-lite@^1.0.30000947, caniuse-lite@^1.0.30000989, caniuse-lite@^1.0.30000999: version "1.0.30000999" resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30000999.tgz#427253a69ad7bea4aa8d8345687b8eec51ca0e43" @@ -20278,10 +20273,10 @@ ts-jest@24.1.0: semver "^5.5" yargs-parser "10.x" -ts-loader@6.1.1: - version "6.1.1" - resolved "https://registry.yarnpkg.com/ts-loader/-/ts-loader-6.1.1.tgz#f30c68aa1ce59fa266f0bb70a36959ca68f40ddc" - integrity sha512-AoOek8ZWJlWwTRH5ttNmZPBRcASUJZc8wc8E/2PGOXef96H97J8KaLXaW/zUnvyFjvCoRBhTGh9ZIMKL1arcCA== +ts-loader@6.2.1: + version "6.2.1" + resolved "https://registry.yarnpkg.com/ts-loader/-/ts-loader-6.2.1.tgz#67939d5772e8a8c6bdaf6277ca023a4812da02ef" + integrity sha512-Dd9FekWuABGgjE1g0TlQJ+4dFUfYGbYcs52/HQObE0ZmUNjQlmLAS7xXsSzy23AMaMwipsx5sNHvoEpT2CZq1g== dependencies: chalk "^2.3.0" enhanced-resolve "^4.0.0" @@ -20289,10 +20284,10 @@ ts-loader@6.1.1: micromatch "^4.0.0" semver "^6.0.0" -ts-node@8.4.1: - version "8.4.1" - resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-8.4.1.tgz#270b0dba16e8723c9fa4f9b4775d3810fd994b4f" - integrity sha512-5LpRN+mTiCs7lI5EtbXmF/HfMeCjzt7DH9CZwtkr6SywStrNQC723wG+aOWFiLNn7zT3kD/RnFqi3ZUfr4l5Qw== +ts-node@8.5.0: + version "8.5.0" + resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-8.5.0.tgz#bc7d5a39133d222bf25b1693651e4d893785f884" + integrity sha512-fbG32iZEupNV2E2Fd2m2yt1TdAwR3GTCrJQBHDevIiEBNy1A8kqnyl1fv7jmRmmbtcapFab2glZXHJvfD1ed0Q== dependencies: arg "^4.1.0" diff "^4.0.1" @@ -20338,10 +20333,10 @@ tslint-react@4.1.0: dependencies: tsutils "^3.9.1" -tslint@5.20.0: - version "5.20.0" - resolved "https://registry.yarnpkg.com/tslint/-/tslint-5.20.0.tgz#fac93bfa79568a5a24e7be9cdde5e02b02d00ec1" - integrity sha512-2vqIvkMHbnx8acMogAERQ/IuINOq6DFqgF8/VDvhEkBqQh/x6SP0Y+OHnKth9/ZcHQSroOZwUQSN18v8KKF0/g== +tslint@5.20.1: + version "5.20.1" + resolved "https://registry.yarnpkg.com/tslint/-/tslint-5.20.1.tgz#e401e8aeda0152bc44dd07e614034f3f80c67b7d" + integrity sha512-EcMxhzCFt8k+/UP5r8waCf/lzmeSyVlqxqMEDQE7rWYiQky8KpIBz1JAoYXfROHrPZ1XXd43q8yQnULOLiBRQg== dependencies: "@babel/code-frame" "^7.0.0" builtin-modules "^1.1.1" @@ -20438,10 +20433,10 @@ typeface-oswald@0.0.54: resolved "https://registry.yarnpkg.com/typeface-oswald/-/typeface-oswald-0.0.54.tgz#1e253011622cdd50f580c04e7d625e7f449763d7" integrity sha512-U1WMNp4qfy4/3khIfHMVAIKnNu941MXUfs3+H9R8PFgnoz42Hh9pboSFztWr86zut0eXC8byalmVhfkiKON/8Q== -typescript@3.6.3: - version "3.6.3" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.6.3.tgz#fea942fabb20f7e1ca7164ff626f1a9f3f70b4da" - integrity sha512-N7bceJL1CtRQ2RiG0AQME13ksR7DiuQh/QehubYcghzv20tnh+MQnQIuJddTmsbqYj+dztchykemz0zFzlvdQw== +typescript@3.7.2: + version "3.7.2" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.7.2.tgz#27e489b95fa5909445e9fef5ee48d81697ad18fb" + integrity sha512-ml7V7JfiN2Xwvcer+XAf2csGO1bPBdRbFCkYBczNZggrBZ9c7G3riSUeJmqEU5uOtXNPMhE3n+R4FA/3YOAWOQ== typical@^2.6.1: version "2.6.1"