From b8713d225be77919bbb2a0e27ef3f450a2dd77e5 Mon Sep 17 00:00:00 2001 From: Luke Elmers Date: Mon, 24 Jun 2019 17:15:38 -0600 Subject: [PATCH 1/9] Clean up plugin definition. --- src/legacy/core_plugins/data/public/index.ts | 53 +++++++++++--------- src/legacy/core_plugins/data/public/setup.ts | 16 ++++-- 2 files changed, 39 insertions(+), 30 deletions(-) diff --git a/src/legacy/core_plugins/data/public/index.ts b/src/legacy/core_plugins/data/public/index.ts index 20be02510e61b..7b3ac106a3603 100644 --- a/src/legacy/core_plugins/data/public/index.ts +++ b/src/legacy/core_plugins/data/public/index.ts @@ -23,29 +23,41 @@ // of the ExpressionExectorService // @ts-ignore import { renderersRegistry } from 'plugins/interpreter/registries'; + +import { + PluginInitializerContext, + CoreSetup, + CoreStart, + Plugin, +} from '../../../../../src/core/public'; + +// Services import { ExpressionsService, ExpressionsSetup } from './expressions'; import { SearchService, SearchSetup } from './search'; import { QueryService, QuerySetup } from './query'; import { FilterService, FilterSetup } from './filter'; import { IndexPatternsService, IndexPatternsSetup } from './index_patterns'; -export class DataPlugin { +/** @public */ +export interface DataPluginSetup { + expressions: ExpressionsSetup; + indexPatterns: IndexPatternsSetup; + filter: FilterSetup; + search: SearchSetup; + query: QuerySetup; +} + +export class DataPublicPlugin implements Plugin { // Exposed services, sorted alphabetically - private readonly expressions: ExpressionsService; - private readonly filter: FilterService; - private readonly indexPatterns: IndexPatternsService; - private readonly search: SearchService; - private readonly query: QueryService; + private readonly expressions = new ExpressionsService(); + private readonly filter = new FilterService(); + private readonly indexPatterns = new IndexPatternsService(); + private readonly search = new SearchService(); + private readonly query = new QueryService(); - constructor() { - this.indexPatterns = new IndexPatternsService(); - this.filter = new FilterService(); - this.query = new QueryService(); - this.search = new SearchService(); - this.expressions = new ExpressionsService(); - } + constructor(initializerContext: PluginInitializerContext) {} - public setup(): DataSetup { + public setup(core: CoreSetup): DataPluginSetup { // TODO: this is imported here to avoid circular imports. // eslint-disable-next-line @typescript-eslint/no-var-requires const { getInterpreter } = require('plugins/interpreter/interpreter'); @@ -66,6 +78,8 @@ export class DataPlugin { }; } + public start(core: CoreStart) {} + public stop() { this.expressions.stop(); this.indexPatterns.stop(); @@ -75,19 +89,8 @@ export class DataPlugin { } } -/** @public */ -export interface DataSetup { - expressions: ExpressionsSetup; - indexPatterns: IndexPatternsSetup; - filter: FilterSetup; - search: SearchSetup; - query: QuerySetup; -} - /** @public types */ export { ExpressionRenderer, ExpressionRendererProps, ExpressionRunner } from './expressions'; - -/** @public types */ export { IndexPattern, StaticIndexPattern, StaticIndexPatternField, Field } from './index_patterns'; export { Query } from './query'; export { FilterManager, FilterStateManager, uniqFilters } from './filter/filter_manager'; diff --git a/src/legacy/core_plugins/data/public/setup.ts b/src/legacy/core_plugins/data/public/setup.ts index 6329d2931ecdb..9f38b52e8c4ab 100644 --- a/src/legacy/core_plugins/data/public/setup.ts +++ b/src/legacy/core_plugins/data/public/setup.ts @@ -17,11 +17,17 @@ * under the License. */ -import { DataPlugin } from './index'; +import { PluginInitializerContext, CoreSetup } from '../../../../../src/core/public'; +import { DataPublicPlugin } from './index'; + +const initializerContext: PluginInitializerContext = {}; + +// core shim +const coreSetup = {} as CoreSetup; /** - * We export data here so that users importing from 'plugins/data' - * will automatically receive the response value of the `setup` contract, mimicking - * the data that will eventually be injected by the new platform. + * We export data here so that users importing from '../core_plugins/data/setup' + * will receive the response value of the `setup` contract, mimicking the + * data that will eventually be injected by the new platform. */ -export const data = new DataPlugin().setup(); +export const data = new DataPublicPlugin(initializerContext).setup(coreSetup); From 3a46a95ef7be2c79b61dde61b4729df1b58dae3c Mon Sep 17 00:00:00 2001 From: Luke Elmers Date: Mon, 24 Jun 2019 21:04:39 -0600 Subject: [PATCH 2/9] Move interpreter imports to expressions service. --- .../expressions/expressions_service.test.tsx | 26 ++++++++-------- .../public/expressions/expressions_service.ts | 31 +++++++++---------- src/legacy/core_plugins/data/public/index.ts | 26 +++------------- 3 files changed, 33 insertions(+), 50 deletions(-) diff --git a/src/legacy/core_plugins/data/public/expressions/expressions_service.test.tsx b/src/legacy/core_plugins/data/public/expressions/expressions_service.test.tsx index fdd0d73763681..2d3fc568266c8 100644 --- a/src/legacy/core_plugins/data/public/expressions/expressions_service.test.tsx +++ b/src/legacy/core_plugins/data/public/expressions/expressions_service.test.tsx @@ -21,12 +21,11 @@ import { fromExpression, Ast } from '@kbn/interpreter/common'; import { ExpressionsService, - RenderFunctionsRegistry, RenderFunction, Interpreter, - ExpressionsServiceDependencies, Result, ExpressionsSetup, + RenderFunctionsRegistry, } from './expressions_service'; import { mount } from 'enzyme'; import React from 'react'; @@ -45,7 +44,6 @@ describe('expressions_service', () => { let interpretAstMock: jest.Mocked['interpretAst']; let interpreterMock: jest.Mocked; let renderFunctionMock: jest.Mocked; - let setupPluginsMock: ExpressionsServiceDependencies; const expressionResult: Result = { type: 'render', as: RENDERER_ID, value: {} }; let api: ExpressionsSetup; @@ -53,20 +51,22 @@ describe('expressions_service', () => { let testAst: Ast; beforeEach(() => { - interpretAstMock = jest.fn(_ => Promise.resolve(expressionResult)); + interpretAstMock = jest.fn((ast, context, handlers) => Promise.resolve(expressionResult)); interpreterMock = { interpretAst: interpretAstMock }; renderFunctionMock = ({ render: jest.fn(), } as unknown) as jest.Mocked; - setupPluginsMock = { - interpreter: { - getInterpreter: () => Promise.resolve({ interpreter: interpreterMock }), - renderersRegistry: ({ - get: (id: string) => (id === RENDERER_ID ? renderFunctionMock : null), - } as unknown) as RenderFunctionsRegistry, - }, - }; - api = new ExpressionsService().setup(setupPluginsMock); + + jest.doMock('plugins/interpreter/interpreter', () => ({ + getInterpreter: () => Promise.resolve({ interpreter: interpreterMock }), + })); + jest.doMock('plugins/interpreter/registries', () => ({ + renderersRegistry: ({ + get: (id: string) => (id === RENDERER_ID ? renderFunctionMock : null), + } as unknown) as RenderFunctionsRegistry, + })); + + api = new ExpressionsService().setup(); testExpression = 'test | expression'; testAst = fromExpression(testExpression); }); diff --git a/src/legacy/core_plugins/data/public/expressions/expressions_service.ts b/src/legacy/core_plugins/data/public/expressions/expressions_service.ts index bb2ca806bbac3..eadfde4163b59 100644 --- a/src/legacy/core_plugins/data/public/expressions/expressions_service.ts +++ b/src/legacy/core_plugins/data/public/expressions/expressions_service.ts @@ -19,9 +19,8 @@ import { Ast } from '@kbn/interpreter/common'; -// TODO: -// this type import and the types below them should be switched to the types of -// the interpreter plugin itself once they are ready +// TODO: These imports should be switched to the types of +// the interpreter plugin itself once they are ready. import { Registry } from '@kbn/interpreter/common'; import { Adapters } from 'ui/inspector'; import { TimeRange } from 'ui/timefilter/time_history'; @@ -71,13 +70,8 @@ export interface Interpreter { interpretAst(ast: Ast, context: Context, handlers: Handlers): Promise; } -type InterpreterGetter = () => Promise<{ interpreter: Interpreter }>; - -export interface ExpressionsServiceDependencies { - interpreter: { - renderersRegistry: RenderFunctionsRegistry; - getInterpreter: InterpreterGetter; - }; +interface InterpreterGetter { + getInterpreter: () => Promise<{ interpreter: Interpreter }>; } /** @@ -85,9 +79,14 @@ export interface ExpressionsServiceDependencies { * @internal */ export class ExpressionsService { - public setup({ - interpreter: { renderersRegistry, getInterpreter }, - }: ExpressionsServiceDependencies) { + public setup() { + // TODO: this is temporarily imported here to avoid circular imports, until interpreter + // moves into the expressions service. + // eslint-disable-next-line @typescript-eslint/no-var-requires + const { getInterpreter }: InterpreterGetter = require('plugins/interpreter/interpreter'); + // eslint-disable-next-line @typescript-eslint/no-var-requires + const { renderersRegistry } = require('plugins/interpreter/registries'); + const run = createRunFn( renderersRegistry, getInterpreter().then(({ interpreter }) => interpreter) @@ -120,9 +119,9 @@ export class ExpressionsService { }; } - public stop() { - // nothing to do here yet - } + public start() {} + + public stop() {} } /** @public */ diff --git a/src/legacy/core_plugins/data/public/index.ts b/src/legacy/core_plugins/data/public/index.ts index 7b3ac106a3603..51c1020f10881 100644 --- a/src/legacy/core_plugins/data/public/index.ts +++ b/src/legacy/core_plugins/data/public/index.ts @@ -17,13 +17,6 @@ * under the License. */ -// TODO these are imports from the old plugin world. -// Once the new platform is ready, they can get removed -// and handled by the platform itself in the setup method -// of the ExpressionExectorService -// @ts-ignore -import { renderersRegistry } from 'plugins/interpreter/registries'; - import { PluginInitializerContext, CoreSetup, @@ -58,21 +51,12 @@ export class DataPublicPlugin implements Plugin { constructor(initializerContext: PluginInitializerContext) {} public setup(core: CoreSetup): DataPluginSetup { - // TODO: this is imported here to avoid circular imports. - // eslint-disable-next-line @typescript-eslint/no-var-requires - const { getInterpreter } = require('plugins/interpreter/interpreter'); - const indexPatternsService = this.indexPatterns.setup(); + const indexPatternsSetup = this.indexPatterns.setup(); + return { - expressions: this.expressions.setup({ - interpreter: { - getInterpreter, - renderersRegistry, - }, - }), - indexPatterns: indexPatternsService, - filter: this.filter.setup({ - indexPatterns: indexPatternsService.indexPatterns, - }), + expressions: this.expressions.setup(), + indexPatterns: indexPatternsSetup, + filter: this.filter.setup({ indexPatterns: indexPatternsSetup }), search: this.search.setup(), query: this.query.setup(), }; From 7d702ef3769a0a3fe59ef19cac508e65773a6e35 Mon Sep 17 00:00:00 2001 From: Luke Elmers Date: Mon, 24 Jun 2019 21:47:46 -0600 Subject: [PATCH 3/9] Move plugin definition to dedicated file. --- src/legacy/core_plugins/data/public/index.ts | 78 ++++++------------- src/legacy/core_plugins/data/public/plugin.ts | 76 ++++++++++++++++++ src/legacy/core_plugins/data/public/setup.ts | 33 +++++--- 3 files changed, 123 insertions(+), 64 deletions(-) create mode 100644 src/legacy/core_plugins/data/public/plugin.ts diff --git a/src/legacy/core_plugins/data/public/index.ts b/src/legacy/core_plugins/data/public/index.ts index 51c1020f10881..6481bcc75aaff 100644 --- a/src/legacy/core_plugins/data/public/index.ts +++ b/src/legacy/core_plugins/data/public/index.ts @@ -17,61 +17,29 @@ * under the License. */ -import { - PluginInitializerContext, - CoreSetup, - CoreStart, - Plugin, -} from '../../../../../src/core/public'; - -// Services -import { ExpressionsService, ExpressionsSetup } from './expressions'; -import { SearchService, SearchSetup } from './search'; -import { QueryService, QuerySetup } from './query'; -import { FilterService, FilterSetup } from './filter'; -import { IndexPatternsService, IndexPatternsSetup } from './index_patterns'; - -/** @public */ -export interface DataPluginSetup { - expressions: ExpressionsSetup; - indexPatterns: IndexPatternsSetup; - filter: FilterSetup; - search: SearchSetup; - query: QuerySetup; -} - -export class DataPublicPlugin implements Plugin { - // Exposed services, sorted alphabetically - private readonly expressions = new ExpressionsService(); - private readonly filter = new FilterService(); - private readonly indexPatterns = new IndexPatternsService(); - private readonly search = new SearchService(); - private readonly query = new QueryService(); - - constructor(initializerContext: PluginInitializerContext) {} - - public setup(core: CoreSetup): DataPluginSetup { - const indexPatternsSetup = this.indexPatterns.setup(); - - return { - expressions: this.expressions.setup(), - indexPatterns: indexPatternsSetup, - filter: this.filter.setup({ indexPatterns: indexPatternsSetup }), - search: this.search.setup(), - query: this.query.setup(), - }; - } - - public start(core: CoreStart) {} - - public stop() { - this.expressions.stop(); - this.indexPatterns.stop(); - this.filter.stop(); - this.search.stop(); - this.query.stop(); - } -} +/** + * Data Plugin - public + * + * This is the entry point for the entire client-side public contract of the plugin. + * If something is not explicitly exported here, you can safely assume it is private + * to the plugin and not considered stable. + * + * All stateful contracts will be injected by the platform at runtime, and are defined + * in the PluginSetup/PluginStart interfaces. The remaining items exported here are + * either types, or static code. + */ +import { PluginInitializer, PluginInitializerContext } from '../../../../../src/core/public'; +import { DataPublicPlugin, DataPluginSetup } from './plugin'; + +// This is what Core looks for when loading our plugin +export const plugin: PluginInitializer = ( + initializerContext: PluginInitializerContext +) => { + return new DataPublicPlugin(initializerContext); +}; + +/** @public interfaces for stateful services */ +export { DataPluginSetup }; /** @public types */ export { ExpressionRenderer, ExpressionRendererProps, ExpressionRunner } from './expressions'; diff --git a/src/legacy/core_plugins/data/public/plugin.ts b/src/legacy/core_plugins/data/public/plugin.ts new file mode 100644 index 0000000000000..efbf2525a8ae6 --- /dev/null +++ b/src/legacy/core_plugins/data/public/plugin.ts @@ -0,0 +1,76 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { + PluginInitializerContext, + CoreSetup, + CoreStart, + Plugin, +} from '../../../../../src/core/public'; + +// Services +import { ExpressionsService, ExpressionsSetup } from './expressions'; +import { FilterService, FilterSetup } from './filter'; +import { IndexPatternsService, IndexPatternsSetup } from './index_patterns'; +import { QueryService, QuerySetup } from './query'; +import { SearchService, SearchSetup } from './search'; + +/** @public */ +export interface DataPluginSetup { + expressions: ExpressionsSetup; + indexPatterns: IndexPatternsSetup; + filter: FilterSetup; + query: QuerySetup; + search: SearchSetup; +} + +export class DataPublicPlugin implements Plugin { + // Exposed services, sorted alphabetically + private readonly expressions = new ExpressionsService(); + private readonly filter = new FilterService(); + private readonly indexPatterns = new IndexPatternsService(); + private readonly query = new QueryService(); + private readonly search = new SearchService(); + + constructor(initializerContext: PluginInitializerContext) {} + + public setup(core: CoreSetup, plugins: {}): DataPluginSetup { + const indexPatternsSetup = this.indexPatterns.setup(); + + return { + expressions: this.expressions.setup(), + indexPatterns: indexPatternsSetup, + filter: this.filter.setup({ indexPatterns: indexPatternsSetup }), + search: this.search.setup(), + query: this.query.setup(), + }; + } + + public start(core: CoreStart, plugins: {}) { + return {}; + } + + public stop() { + this.expressions.stop(); + this.indexPatterns.stop(); + this.filter.stop(); + this.search.stop(); + this.query.stop(); + } +} diff --git a/src/legacy/core_plugins/data/public/setup.ts b/src/legacy/core_plugins/data/public/setup.ts index 9f38b52e8c4ab..85d491f3f98bc 100644 --- a/src/legacy/core_plugins/data/public/setup.ts +++ b/src/legacy/core_plugins/data/public/setup.ts @@ -17,17 +17,32 @@ * under the License. */ +/** + * New Platform Shim + * + * In this file, we import any legacy dependencies we have, and shim them into + * our plugin by manually constructing the values that the new platform will + * eventually be passing to the `setup` method of our plugin definition. + * + * The idea is that our `plugin.ts` can stay "pure" and not contain any legacy + * world code. Then when it comes time to migrate to the new platform, we can + * simply delete this shim file. + * + * We are also calling `setup` here and exporting our public contract so that + * other legacy plugins are able to import from '../core_plugins/data/setup' + * and receive the response value of the `setup` contract, mimicking the + * data that will eventually be injected by the new platform. + */ +import { npSetup } from 'ui/new_platform'; + import { PluginInitializerContext, CoreSetup } from '../../../../../src/core/public'; -import { DataPublicPlugin } from './index'; +import { DataPublicPlugin } from './plugin'; +// core shims const initializerContext: PluginInitializerContext = {}; +const coreSetup: CoreSetup = npSetup.core; -// core shim -const coreSetup = {} as CoreSetup; +// plugin dependency shims +const pluginsSetup = {}; -/** - * We export data here so that users importing from '../core_plugins/data/setup' - * will receive the response value of the `setup` contract, mimicking the - * data that will eventually be injected by the new platform. - */ -export const data = new DataPublicPlugin(initializerContext).setup(coreSetup); +export const data = new DataPublicPlugin(initializerContext).setup(coreSetup, pluginsSetup); From 0527707da07d3df649f448d65234da31fb9873b1 Mon Sep 17 00:00:00 2001 From: Luke Elmers Date: Wed, 26 Jun 2019 13:35:31 -0600 Subject: [PATCH 4/9] Move files that don\'t need to be tsx to ts. --- .../core_plugins/data/public/filter/{index.tsx => index.ts} | 0 .../core_plugins/data/public/search/{index.tsx => index.ts} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename src/legacy/core_plugins/data/public/filter/{index.tsx => index.ts} (100%) rename src/legacy/core_plugins/data/public/search/{index.tsx => index.ts} (100%) diff --git a/src/legacy/core_plugins/data/public/filter/index.tsx b/src/legacy/core_plugins/data/public/filter/index.ts similarity index 100% rename from src/legacy/core_plugins/data/public/filter/index.tsx rename to src/legacy/core_plugins/data/public/filter/index.ts diff --git a/src/legacy/core_plugins/data/public/search/index.tsx b/src/legacy/core_plugins/data/public/search/index.ts similarity index 100% rename from src/legacy/core_plugins/data/public/search/index.tsx rename to src/legacy/core_plugins/data/public/search/index.ts From e9c66461a841746d4cc9612b2eace4a746b99517 Mon Sep 17 00:00:00 2001 From: Luke Elmers Date: Wed, 26 Jun 2019 13:36:00 -0600 Subject: [PATCH 5/9] Update comment to clarify purpose of export. --- src/legacy/core_plugins/data/public/query/query_service.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/legacy/core_plugins/data/public/query/query_service.ts b/src/legacy/core_plugins/data/public/query/query_service.ts index be678776f7526..51bba48ccfaf9 100644 --- a/src/legacy/core_plugins/data/public/query/query_service.ts +++ b/src/legacy/core_plugins/data/public/query/query_service.ts @@ -56,4 +56,5 @@ export class QueryService { /** @public */ export type QuerySetup = ReturnType; +/** @public types */ export { Query } from './query_bar'; From ea1771e868476595972cd6220c4a13b028db1012 Mon Sep 17 00:00:00 2001 From: Luke Elmers Date: Tue, 2 Jul 2019 10:00:40 -0600 Subject: [PATCH 6/9] Resolve merge conflicts & clean up types. --- src/legacy/core_plugins/data/public/index.ts | 27 +++++--- src/legacy/core_plugins/data/public/plugin.ts | 67 +++++++++++++------ src/legacy/core_plugins/data/public/setup.ts | 9 ++- 3 files changed, 69 insertions(+), 34 deletions(-) diff --git a/src/legacy/core_plugins/data/public/index.ts b/src/legacy/core_plugins/data/public/index.ts index 6481bcc75aaff..a2078611ca8ba 100644 --- a/src/legacy/core_plugins/data/public/index.ts +++ b/src/legacy/core_plugins/data/public/index.ts @@ -25,21 +25,30 @@ * to the plugin and not considered stable. * * All stateful contracts will be injected by the platform at runtime, and are defined - * in the PluginSetup/PluginStart interfaces. The remaining items exported here are - * either types, or static code. + * in the setup/start interfaces. The remaining items exported here are either types, + * or static code. */ -import { PluginInitializer, PluginInitializerContext } from '../../../../../src/core/public'; -import { DataPublicPlugin, DataPluginSetup } from './plugin'; +import { PluginInitializer } from 'kibana/public'; +import { + DataPublicPlugin, + DataSetup, + DataSetupPlugins, + DataStart, + DataStartPlugins, +} from './plugin'; // This is what Core looks for when loading our plugin -export const plugin: PluginInitializer = ( - initializerContext: PluginInitializerContext -) => { - return new DataPublicPlugin(initializerContext); +export const plugin: PluginInitializer< + DataSetup, + DataStart, + DataSetupPlugins, + DataStartPlugins +> = initializerContext => { + return new DataPublicPlugin(); }; /** @public interfaces for stateful services */ -export { DataPluginSetup }; +export { DataSetup }; /** @public types */ export { ExpressionRenderer, ExpressionRendererProps, ExpressionRunner } from './expressions'; diff --git a/src/legacy/core_plugins/data/public/plugin.ts b/src/legacy/core_plugins/data/public/plugin.ts index efbf2525a8ae6..004a0a439ce08 100644 --- a/src/legacy/core_plugins/data/public/plugin.ts +++ b/src/legacy/core_plugins/data/public/plugin.ts @@ -17,12 +17,7 @@ * under the License. */ -import { - PluginInitializerContext, - CoreSetup, - CoreStart, - Plugin, -} from '../../../../../src/core/public'; +import { CoreSetup, CoreStart, Plugin } from 'kibana/public'; // Services import { ExpressionsService, ExpressionsSetup } from './expressions'; @@ -31,16 +26,13 @@ import { IndexPatternsService, IndexPatternsSetup } from './index_patterns'; import { QueryService, QuerySetup } from './query'; import { SearchService, SearchSetup } from './search'; -/** @public */ -export interface DataPluginSetup { - expressions: ExpressionsSetup; - indexPatterns: IndexPatternsSetup; - filter: FilterSetup; - query: QuerySetup; - search: SearchSetup; -} - -export class DataPublicPlugin implements Plugin { +/** + * Data Plugin - public + * + * Shared services for applications to access, query, and manipulate data in Kibana. + */ +export class DataPublicPlugin + implements Plugin { // Exposed services, sorted alphabetically private readonly expressions = new ExpressionsService(); private readonly filter = new FilterService(); @@ -48,9 +40,7 @@ export class DataPublicPlugin implements Plugin { private readonly query = new QueryService(); private readonly search = new SearchService(); - constructor(initializerContext: PluginInitializerContext) {} - - public setup(core: CoreSetup, plugins: {}): DataPluginSetup { + public setup(core: CoreSetup, plugins: DataSetupPlugins): DataSetup { const indexPatternsSetup = this.indexPatterns.setup(); return { @@ -62,7 +52,7 @@ export class DataPublicPlugin implements Plugin { }; } - public start(core: CoreStart, plugins: {}) { + public start(core: CoreStart, plugins: DataStartPlugins): DataStart { return {}; } @@ -74,3 +64,40 @@ export class DataPublicPlugin implements Plugin { this.query.stop(); } } + +/** + * Interface for this plugin's returned `setup` contract. + * + * @public + */ +export interface DataSetup { + expressions: ExpressionsSetup; + indexPatterns: IndexPatternsSetup; + filter: FilterSetup; + query: QuerySetup; + search: SearchSetup; +} + +/** + * Interface for this plugin's returned `start` contract. + * + * @public + */ +// eslint-disable-next-line @typescript-eslint/no-empty-interface +export interface DataStart {} + +/** + * Interface for any dependencies on other plugins' `setup` contracts. + * + * @internal + */ +// eslint-disable-next-line @typescript-eslint/no-empty-interface +export interface DataSetupPlugins {} + +/** + * Interface for any dependencies on other plugins' `start` contracts. + * + * @internal + */ +// eslint-disable-next-line @typescript-eslint/no-empty-interface +export interface DataStartPlugins {} diff --git a/src/legacy/core_plugins/data/public/setup.ts b/src/legacy/core_plugins/data/public/setup.ts index 85d491f3f98bc..2264bf0a2c7b2 100644 --- a/src/legacy/core_plugins/data/public/setup.ts +++ b/src/legacy/core_plugins/data/public/setup.ts @@ -35,14 +35,13 @@ */ import { npSetup } from 'ui/new_platform'; -import { PluginInitializerContext, CoreSetup } from '../../../../../src/core/public'; -import { DataPublicPlugin } from './plugin'; +import { CoreSetup } from 'kibana/public'; +import { DataPublicPlugin, DataSetupPlugins } from './plugin'; // core shims -const initializerContext: PluginInitializerContext = {}; const coreSetup: CoreSetup = npSetup.core; // plugin dependency shims -const pluginsSetup = {}; +const pluginsSetup: DataSetupPlugins = {}; -export const data = new DataPublicPlugin(initializerContext).setup(coreSetup, pluginsSetup); +export const data = new DataPublicPlugin().setup(coreSetup, pluginsSetup); From eb2df50aca10fa28d3fff83b8e7a2a706c0d9b50 Mon Sep 17 00:00:00 2001 From: Luke Elmers Date: Tue, 2 Jul 2019 15:57:41 -0600 Subject: [PATCH 7/9] Fix typo from resolving merge conflicts. --- src/legacy/core_plugins/data/public/plugin.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/legacy/core_plugins/data/public/plugin.ts b/src/legacy/core_plugins/data/public/plugin.ts index 004a0a439ce08..8992a4e1e3950 100644 --- a/src/legacy/core_plugins/data/public/plugin.ts +++ b/src/legacy/core_plugins/data/public/plugin.ts @@ -46,7 +46,9 @@ export class DataPublicPlugin return { expressions: this.expressions.setup(), indexPatterns: indexPatternsSetup, - filter: this.filter.setup({ indexPatterns: indexPatternsSetup }), + filter: this.filter.setup({ + indexPatterns: indexPatternsSetup.indexPatterns, + }), search: this.search.setup(), query: this.query.setup(), }; From 0cf6e196e3735de6bfd15aeed42db7a01669b7d4 Mon Sep 17 00:00:00 2001 From: Luke Elmers Date: Tue, 2 Jul 2019 16:00:25 -0600 Subject: [PATCH 8/9] Alphabetize services. --- src/legacy/core_plugins/data/public/plugin.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/legacy/core_plugins/data/public/plugin.ts b/src/legacy/core_plugins/data/public/plugin.ts index 8992a4e1e3950..52844cc1b9ef5 100644 --- a/src/legacy/core_plugins/data/public/plugin.ts +++ b/src/legacy/core_plugins/data/public/plugin.ts @@ -49,8 +49,8 @@ export class DataPublicPlugin filter: this.filter.setup({ indexPatterns: indexPatternsSetup.indexPatterns, }), - search: this.search.setup(), query: this.query.setup(), + search: this.search.setup(), }; } @@ -62,8 +62,8 @@ export class DataPublicPlugin this.expressions.stop(); this.indexPatterns.stop(); this.filter.stop(); - this.search.stop(); this.query.stop(); + this.search.stop(); } } From 42329a3c675d0a68f4a74b22057d2e2a0e194a12 Mon Sep 17 00:00:00 2001 From: Luke Elmers Date: Wed, 3 Jul 2019 16:37:44 -0600 Subject: [PATCH 9/9] Clean up imports that caused broken type checks. --- src/legacy/core_plugins/data/public/index.ts | 11 ++++------- src/legacy/core_plugins/data/public/plugin.ts | 2 +- src/legacy/core_plugins/data/public/setup.ts | 2 +- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/legacy/core_plugins/data/public/index.ts b/src/legacy/core_plugins/data/public/index.ts index a2078611ca8ba..aa5a20cb72f41 100644 --- a/src/legacy/core_plugins/data/public/index.ts +++ b/src/legacy/core_plugins/data/public/index.ts @@ -28,7 +28,7 @@ * in the setup/start interfaces. The remaining items exported here are either types, * or static code. */ -import { PluginInitializer } from 'kibana/public'; +import { PluginInitializer, PluginInitializerContext } from '../../../../core/public'; import { DataPublicPlugin, DataSetup, @@ -38,12 +38,9 @@ import { } from './plugin'; // This is what Core looks for when loading our plugin -export const plugin: PluginInitializer< - DataSetup, - DataStart, - DataSetupPlugins, - DataStartPlugins -> = initializerContext => { +export const plugin: PluginInitializer = ( + initializerContext: PluginInitializerContext +) => { return new DataPublicPlugin(); }; diff --git a/src/legacy/core_plugins/data/public/plugin.ts b/src/legacy/core_plugins/data/public/plugin.ts index 52844cc1b9ef5..6bf7d432d6998 100644 --- a/src/legacy/core_plugins/data/public/plugin.ts +++ b/src/legacy/core_plugins/data/public/plugin.ts @@ -17,7 +17,7 @@ * under the License. */ -import { CoreSetup, CoreStart, Plugin } from 'kibana/public'; +import { CoreSetup, CoreStart, Plugin } from '../../../../core/public'; // Services import { ExpressionsService, ExpressionsSetup } from './expressions'; diff --git a/src/legacy/core_plugins/data/public/setup.ts b/src/legacy/core_plugins/data/public/setup.ts index 2264bf0a2c7b2..dde0f84a8cf12 100644 --- a/src/legacy/core_plugins/data/public/setup.ts +++ b/src/legacy/core_plugins/data/public/setup.ts @@ -35,7 +35,7 @@ */ import { npSetup } from 'ui/new_platform'; -import { CoreSetup } from 'kibana/public'; +import { CoreSetup } from '../../../../core/public'; import { DataPublicPlugin, DataSetupPlugins } from './plugin'; // core shims