From 189529a762b6ea49aa5da6520d7d3bc1124ae61f Mon Sep 17 00:00:00 2001 From: streamich Date: Tue, 2 Jul 2019 09:54:36 +0200 Subject: [PATCH 1/4] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20add=20EmptyPluginCon?= =?UTF-8?q?tracts=20type?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/public/plugins/plugin.ts | 15 ++++++++------- src/core/public/plugins/plugin_context.ts | 11 ++++++----- src/core/public/plugins/plugin_loader.ts | 9 +++++---- src/core/server/plugins/plugin.ts | 13 +++++++------ src/core/types/index.ts | 1 + src/core/types/plugins.ts | 21 +++++++++++++++++++++ 6 files changed, 48 insertions(+), 22 deletions(-) create mode 100644 src/core/types/plugins.ts diff --git a/src/core/public/plugins/plugin.ts b/src/core/public/plugins/plugin.ts index 4ac7c46e6ebca..f53f183cdff83 100644 --- a/src/core/public/plugins/plugin.ts +++ b/src/core/public/plugins/plugin.ts @@ -17,9 +17,10 @@ * under the License. */ -import { DiscoveredPlugin, PluginName } from '../../server'; +import { DiscoveredPlugin } from '../../server'; import { PluginInitializerContext } from './plugin_context'; import { loadPluginBundle } from './plugin_loader'; +import { EmptyPluginContracts } from '../../types/plugins'; import { CoreStart, CoreSetup } from '..'; /** @@ -30,8 +31,8 @@ import { CoreStart, CoreSetup } from '..'; export interface Plugin< TSetup = void, TStart = void, - TPluginsSetup extends {} = {}, - TPluginsStart extends {} = {} + TPluginsSetup extends EmptyPluginContracts = EmptyPluginContracts, + TPluginsStart extends EmptyPluginContracts = EmptyPluginContracts > { setup(core: CoreSetup, plugins: TPluginsSetup): TSetup | Promise; start(core: CoreStart, plugins: TPluginsStart): TStart | Promise; @@ -47,8 +48,8 @@ export interface Plugin< export type PluginInitializer< TSetup, TStart, - TPluginsSetup extends Record = {}, - TPluginsStart extends Record = {} + TPluginsSetup extends EmptyPluginContracts = EmptyPluginContracts, + TPluginsStart extends EmptyPluginContracts = EmptyPluginContracts > = (core: PluginInitializerContext) => Plugin; /** @@ -60,8 +61,8 @@ export type PluginInitializer< export class PluginWrapper< TSetup = unknown, TStart = unknown, - TPluginsSetup extends Record = Record, - TPluginsStart extends Record = Record + TPluginsSetup extends EmptyPluginContracts = EmptyPluginContracts, + TPluginsStart extends EmptyPluginContracts = EmptyPluginContracts > { public readonly name: DiscoveredPlugin['id']; public readonly configPath: DiscoveredPlugin['configPath']; diff --git a/src/core/public/plugins/plugin_context.ts b/src/core/public/plugins/plugin_context.ts index 022c71492f383..1f830904244ae 100644 --- a/src/core/public/plugins/plugin_context.ts +++ b/src/core/public/plugins/plugin_context.ts @@ -19,11 +19,12 @@ import { omit } from 'lodash'; -import { DiscoveredPlugin, PluginName } from '../../server'; +import { DiscoveredPlugin } from '../../server'; import { CoreContext } from '../core_system'; import { PluginWrapper } from './plugin'; import { PluginsServiceSetupDeps, PluginsServiceStartDeps } from './plugins_service'; import { CoreSetup, CoreStart } from '../'; +import { EmptyPluginContracts } from '../../types/plugins'; /** * The available core services passed to a `PluginInitializer` @@ -61,8 +62,8 @@ export function createPluginInitializerContext( export function createPluginSetupContext< TSetup, TStart, - TPluginsSetup extends Record, - TPluginsStart extends Record + TPluginsSetup extends EmptyPluginContracts, + TPluginsStart extends EmptyPluginContracts >( coreContext: CoreContext, deps: PluginsServiceSetupDeps, @@ -89,8 +90,8 @@ export function createPluginSetupContext< export function createPluginStartContext< TSetup, TStart, - TPluginsSetup extends Record, - TPluginsStart extends Record + TPluginsSetup extends EmptyPluginContracts, + TPluginsStart extends EmptyPluginContracts >( coreContext: CoreContext, deps: PluginsServiceStartDeps, diff --git a/src/core/public/plugins/plugin_loader.ts b/src/core/public/plugins/plugin_loader.ts index 9ec24adaabbe7..23f43762fb1de 100644 --- a/src/core/public/plugins/plugin_loader.ts +++ b/src/core/public/plugins/plugin_loader.ts @@ -19,6 +19,7 @@ import { PluginName } from '../../server'; import { PluginInitializer } from './plugin'; +import { EmptyPluginContracts } from '../../types/plugins'; /** * Unknown variant for internal use only for when plugins are not known. @@ -62,8 +63,8 @@ export const LOAD_TIMEOUT = 120 * 1000; // 2 minutes export const loadPluginBundle: LoadPluginBundle = < TSetup, TStart, - TPluginsSetup extends Record, - TPluginsStart extends Record + TPluginsSetup extends EmptyPluginContracts, + TPluginsStart extends EmptyPluginContracts >( addBasePath: (path: string) => string, pluginName: PluginName, @@ -125,8 +126,8 @@ export const loadPluginBundle: LoadPluginBundle = < export type LoadPluginBundle = < TSetup, TStart, - TPluginsSetup extends Record, - TPluginsStart extends Record + TPluginsSetup extends EmptyPluginContracts, + TPluginsStart extends EmptyPluginContracts >( addBasePath: (path: string) => string, pluginName: PluginName, diff --git a/src/core/server/plugins/plugin.ts b/src/core/server/plugins/plugin.ts index 6f3d6c68b4fd3..4e680b9fee096 100644 --- a/src/core/server/plugins/plugin.ts +++ b/src/core/server/plugins/plugin.ts @@ -25,6 +25,7 @@ import { Type } from '@kbn/config-schema'; import { ConfigPath } from '../config'; import { Logger } from '../logging'; import { PluginInitializerContext } from './plugin_context'; +import { EmptyPluginContracts } from '../../types/plugins'; import { CoreSetup, CoreStart } from '..'; export type PluginConfigSchema = Type | null; @@ -138,8 +139,8 @@ export interface DiscoveredPluginInternal extends DiscoveredPlugin { export interface Plugin< TSetup = void, TStart = void, - TPluginsSetup extends {} = {}, - TPluginsStart extends {} = {} + TPluginsSetup extends EmptyPluginContracts = EmptyPluginContracts, + TPluginsStart extends EmptyPluginContracts = EmptyPluginContracts > { setup(core: CoreSetup, plugins: TPluginsSetup): TSetup | Promise; start(core: CoreStart, plugins: TPluginsStart): TStart | Promise; @@ -155,8 +156,8 @@ export interface Plugin< export type PluginInitializer< TSetup, TStart, - TPluginsSetup extends Record = {}, - TPluginsStart extends Record = {} + TPluginsSetup extends EmptyPluginContracts = EmptyPluginContracts, + TPluginsStart extends EmptyPluginContracts = EmptyPluginContracts > = (core: PluginInitializerContext) => Plugin; /** @@ -168,8 +169,8 @@ export type PluginInitializer< export class PluginWrapper< TSetup = unknown, TStart = unknown, - TPluginsSetup extends Record = Record, - TPluginsStart extends Record = Record + TPluginsSetup extends EmptyPluginContracts = EmptyPluginContracts, + TPluginsStart extends EmptyPluginContracts = EmptyPluginContracts > { public readonly name: PluginManifest['id']; public readonly configPath: PluginManifest['configPath']; diff --git a/src/core/types/index.ts b/src/core/types/index.ts index 3aae17e6ea594..5feea393be92d 100644 --- a/src/core/types/index.ts +++ b/src/core/types/index.ts @@ -22,3 +22,4 @@ * types are stripped. */ export * from './core_service'; +export * from './plugins'; diff --git a/src/core/types/plugins.ts b/src/core/types/plugins.ts new file mode 100644 index 0000000000000..a4d577893537e --- /dev/null +++ b/src/core/types/plugins.ts @@ -0,0 +1,21 @@ +/* + * 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. + */ + +// eslint-disable-next-line @typescript-eslint/no-empty-interface +export interface EmptyPluginContracts {} From 28a642423a09ed701a310469dccbc88fb9d32056 Mon Sep 17 00:00:00 2001 From: streamich Date: Tue, 2 Jul 2019 10:05:33 +0200 Subject: [PATCH 2/4] =?UTF-8?q?docs:=20=E2=9C=8F=EF=B8=8F=20update=20Core?= =?UTF-8?q?=20docs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/development/core/public/kibana-plugin-public.plugin.md | 2 +- .../core/public/kibana-plugin-public.plugininitializer.md | 2 +- docs/development/core/server/kibana-plugin-server.plugin.md | 2 +- .../core/server/kibana-plugin-server.plugininitializer.md | 2 +- src/core/public/public.api.md | 6 ++++-- src/core/server/server.api.md | 6 ++++-- 6 files changed, 12 insertions(+), 8 deletions(-) diff --git a/docs/development/core/public/kibana-plugin-public.plugin.md b/docs/development/core/public/kibana-plugin-public.plugin.md index 879897ec18d84..2275a82bcf6ab 100644 --- a/docs/development/core/public/kibana-plugin-public.plugin.md +++ b/docs/development/core/public/kibana-plugin-public.plugin.md @@ -9,7 +9,7 @@ The interface that should be returned by a `PluginInitializer`. Signature: ```typescript -export interface Plugin +export interface Plugin ``` ## Methods diff --git a/docs/development/core/public/kibana-plugin-public.plugininitializer.md b/docs/development/core/public/kibana-plugin-public.plugininitializer.md index adb389e0fda3a..66862e904c19d 100644 --- a/docs/development/core/public/kibana-plugin-public.plugininitializer.md +++ b/docs/development/core/public/kibana-plugin-public.plugininitializer.md @@ -9,5 +9,5 @@ The `plugin` export at the root of a plugin's `public` directory should conform Signature: ```typescript -export declare type PluginInitializer = {}, TPluginsStart extends Record = {}> = (core: PluginInitializerContext) => Plugin; +export declare type PluginInitializer = (core: PluginInitializerContext) => Plugin; ``` diff --git a/docs/development/core/server/kibana-plugin-server.plugin.md b/docs/development/core/server/kibana-plugin-server.plugin.md index 5cef833ecc30e..8213b8a96e828 100644 --- a/docs/development/core/server/kibana-plugin-server.plugin.md +++ b/docs/development/core/server/kibana-plugin-server.plugin.md @@ -9,7 +9,7 @@ The interface that should be returned by a `PluginInitializer`. Signature: ```typescript -export interface Plugin +export interface Plugin ``` ## Methods diff --git a/docs/development/core/server/kibana-plugin-server.plugininitializer.md b/docs/development/core/server/kibana-plugin-server.plugininitializer.md index 402b4001ce633..bb0a88694f71c 100644 --- a/docs/development/core/server/kibana-plugin-server.plugininitializer.md +++ b/docs/development/core/server/kibana-plugin-server.plugininitializer.md @@ -9,5 +9,5 @@ The `plugin` export at the root of a plugin's `server` directory should conform Signature: ```typescript -export declare type PluginInitializer = {}, TPluginsStart extends Record = {}> = (core: PluginInitializerContext) => Plugin; +export declare type PluginInitializer = (core: PluginInitializerContext) => Plugin; ``` diff --git a/src/core/public/public.api.md b/src/core/public/public.api.md index aa8f1c9ccf375..c8da1f802afcf 100644 --- a/src/core/public/public.api.md +++ b/src/core/public/public.api.md @@ -474,8 +474,10 @@ export interface OverlayStart { }) => OverlayRef; } +// Warning: (ae-forgotten-export) The symbol "EmptyPluginContracts" needs to be exported by the entry point index.d.ts +// // @public -export interface Plugin { +export interface Plugin { // (undocumented) setup(core: CoreSetup, plugins: TPluginsSetup): TSetup | Promise; // (undocumented) @@ -485,7 +487,7 @@ export interface Plugin = {}, TPluginsStart extends Record = {}> = (core: PluginInitializerContext) => Plugin; +export type PluginInitializer = (core: PluginInitializerContext) => Plugin; // @public export interface PluginInitializerContext { diff --git a/src/core/server/server.api.md b/src/core/server/server.api.md index f2b8aa894f042..048ae79824b4f 100644 --- a/src/core/server/server.api.md +++ b/src/core/server/server.api.md @@ -312,8 +312,10 @@ export interface OnPreAuthToolkit { }) => OnPreAuthResult; } +// Warning: (ae-forgotten-export) The symbol "EmptyPluginContracts" needs to be exported by the entry point index.d.ts +// // @public -export interface Plugin { +export interface Plugin { // (undocumented) setup(core: CoreSetup, plugins: TPluginsSetup): TSetup | Promise; // (undocumented) @@ -323,7 +325,7 @@ export interface Plugin = {}, TPluginsStart extends Record = {}> = (core: PluginInitializerContext) => Plugin; +export type PluginInitializer = (core: PluginInitializerContext) => Plugin; // @public export interface PluginInitializerContext { From 6cd7fb898d26fef63941b67f716f390309183c49 Mon Sep 17 00:00:00 2001 From: streamich Date: Wed, 3 Jul 2019 22:57:03 +0200 Subject: [PATCH 3/4] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20use=20"extends=20(ob?= =?UTF-8?q?ject=20|=20void)=20=3D=20object"=20for=20contracts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/public/plugins/plugin.test.ts | 2 +- src/core/public/plugins/plugin.ts | 25 +++-- src/core/public/plugins/plugin_context.ts | 17 ++-- src/core/public/plugins/plugin_loader.mock.ts | 10 +- src/core/public/plugins/plugin_loader.ts | 25 ++--- .../plugins/plugins_service.test.mocks.ts | 6 +- src/core/public/plugins/plugins_service.ts | 5 +- src/core/server/plugins/plugin.ts | 25 +++-- src/core/server/plugins/plugin_context.ts | 8 +- .../server/plugins/plugins_system.test.ts | 92 ++++++++++++------- src/core/types/index.ts | 1 - src/core/types/plugins.ts | 21 ----- src/plugins/data/public/plugin.ts | 2 +- src/plugins/data/server/plugin.ts | 2 +- 14 files changed, 115 insertions(+), 126 deletions(-) delete mode 100644 src/core/types/plugins.ts diff --git a/src/core/public/plugins/plugin.test.ts b/src/core/public/plugins/plugin.test.ts index bbe2baf006a85..e91c3ab1a8a00 100644 --- a/src/core/public/plugins/plugin.test.ts +++ b/src/core/public/plugins/plugin.test.ts @@ -34,7 +34,7 @@ function createManifest( } as DiscoveredPlugin; } -let plugin: PluginWrapper>; +let plugin: PluginWrapper; const initializerContext = {}; const addBasePath = (path: string) => path; diff --git a/src/core/public/plugins/plugin.ts b/src/core/public/plugins/plugin.ts index f53f183cdff83..89a62248d8b09 100644 --- a/src/core/public/plugins/plugin.ts +++ b/src/core/public/plugins/plugin.ts @@ -20,7 +20,6 @@ import { DiscoveredPlugin } from '../../server'; import { PluginInitializerContext } from './plugin_context'; import { loadPluginBundle } from './plugin_loader'; -import { EmptyPluginContracts } from '../../types/plugins'; import { CoreStart, CoreSetup } from '..'; /** @@ -29,10 +28,10 @@ import { CoreStart, CoreSetup } from '..'; * @public */ export interface Plugin< - TSetup = void, - TStart = void, - TPluginsSetup extends EmptyPluginContracts = EmptyPluginContracts, - TPluginsStart extends EmptyPluginContracts = EmptyPluginContracts + TSetup extends object | void = object, + TStart extends object | void = object, + TPluginsSetup extends object = object, + TPluginsStart extends object = object > { setup(core: CoreSetup, plugins: TPluginsSetup): TSetup | Promise; start(core: CoreStart, plugins: TPluginsStart): TStart | Promise; @@ -46,10 +45,10 @@ export interface Plugin< * @public */ export type PluginInitializer< - TSetup, - TStart, - TPluginsSetup extends EmptyPluginContracts = EmptyPluginContracts, - TPluginsStart extends EmptyPluginContracts = EmptyPluginContracts + TSetup extends object | void = object, + TStart extends object | void = object, + TPluginsSetup extends object = object, + TPluginsStart extends object = object > = (core: PluginInitializerContext) => Plugin; /** @@ -59,10 +58,10 @@ export type PluginInitializer< * @internal */ export class PluginWrapper< - TSetup = unknown, - TStart = unknown, - TPluginsSetup extends EmptyPluginContracts = EmptyPluginContracts, - TPluginsStart extends EmptyPluginContracts = EmptyPluginContracts + TSetup extends object | void = object, + TStart extends object | void = object, + TPluginsSetup extends object = object, + TPluginsStart extends object = object > { public readonly name: DiscoveredPlugin['id']; public readonly configPath: DiscoveredPlugin['configPath']; diff --git a/src/core/public/plugins/plugin_context.ts b/src/core/public/plugins/plugin_context.ts index 1f830904244ae..1d7dc19f3fdd3 100644 --- a/src/core/public/plugins/plugin_context.ts +++ b/src/core/public/plugins/plugin_context.ts @@ -24,7 +24,6 @@ import { CoreContext } from '../core_system'; import { PluginWrapper } from './plugin'; import { PluginsServiceSetupDeps, PluginsServiceStartDeps } from './plugins_service'; import { CoreSetup, CoreStart } from '../'; -import { EmptyPluginContracts } from '../../types/plugins'; /** * The available core services passed to a `PluginInitializer` @@ -60,10 +59,10 @@ export function createPluginInitializerContext( * @internal */ export function createPluginSetupContext< - TSetup, - TStart, - TPluginsSetup extends EmptyPluginContracts, - TPluginsStart extends EmptyPluginContracts + TSetup extends object | void = object, + TStart extends object | void = object, + TPluginsSetup extends object = object, + TPluginsStart extends object = object >( coreContext: CoreContext, deps: PluginsServiceSetupDeps, @@ -88,10 +87,10 @@ export function createPluginSetupContext< * @internal */ export function createPluginStartContext< - TSetup, - TStart, - TPluginsSetup extends EmptyPluginContracts, - TPluginsStart extends EmptyPluginContracts + TSetup extends object | void = object, + TStart extends object | void = object, + TPluginsSetup extends object = object, + TPluginsStart extends object = object >( coreContext: CoreContext, deps: PluginsServiceStartDeps, diff --git a/src/core/public/plugins/plugin_loader.mock.ts b/src/core/public/plugins/plugin_loader.mock.ts index 5f55cbcc86744..35bc364e6bbd9 100644 --- a/src/core/public/plugins/plugin_loader.mock.ts +++ b/src/core/public/plugins/plugin_loader.mock.ts @@ -18,16 +18,12 @@ */ import { PluginName } from 'src/core/server'; -import { LoadPluginBundle, UnknownPluginInitializer } from './plugin_loader'; +import { PluginInitializer } from '..'; /** * @param initializerProvider A function provided by the test to resolve initializers. */ -const createLoadPluginBundleMock = ( - initializerProvider: (name: PluginName) => UnknownPluginInitializer -): jest.Mock, Parameters> => - jest.fn((addBasePath, pluginName) => { - return Promise.resolve(initializerProvider(pluginName)) as any; - }); +const createLoadPluginBundleMock = (initializerProvider: (name: PluginName) => PluginInitializer) => + jest.fn(async (addBasePath, pluginName) => initializerProvider(pluginName)); export const loadPluginBundleMock = { create: createLoadPluginBundleMock }; diff --git a/src/core/public/plugins/plugin_loader.ts b/src/core/public/plugins/plugin_loader.ts index 23f43762fb1de..b3cecf8fd77f8 100644 --- a/src/core/public/plugins/plugin_loader.ts +++ b/src/core/public/plugins/plugin_loader.ts @@ -19,13 +19,6 @@ import { PluginName } from '../../server'; import { PluginInitializer } from './plugin'; -import { EmptyPluginContracts } from '../../types/plugins'; - -/** - * Unknown variant for internal use only for when plugins are not known. - * @internal - */ -export type UnknownPluginInitializer = PluginInitializer>; /** * Custom window type for loading bundles. Do not extend global Window to avoid leaking these types. @@ -34,7 +27,7 @@ export type UnknownPluginInitializer = PluginInitializer( addBasePath: (path: string) => string, pluginName: PluginName, @@ -124,10 +117,10 @@ export const loadPluginBundle: LoadPluginBundle = < * @internal */ export type LoadPluginBundle = < - TSetup, - TStart, - TPluginsSetup extends EmptyPluginContracts, - TPluginsStart extends EmptyPluginContracts + TSetup extends object | void = object, + TStart extends object | void = object, + TPluginsSetup extends object = object, + TPluginsStart extends object = object >( addBasePath: (path: string) => string, pluginName: PluginName, diff --git a/src/core/public/plugins/plugins_service.test.mocks.ts b/src/core/public/plugins/plugins_service.test.mocks.ts index a76078932518f..a8f52bd24adc9 100644 --- a/src/core/public/plugins/plugins_service.test.mocks.ts +++ b/src/core/public/plugins/plugins_service.test.mocks.ts @@ -17,15 +17,13 @@ * under the License. */ -import { PluginName } from 'kibana/server'; import { Plugin } from './plugin'; import { loadPluginBundleMock } from './plugin_loader.mock'; -export type MockedPluginInitializer = jest.Mock>, any>; +export type MockedPluginInitializer = jest.Mock; export const mockPluginInitializerProvider: jest.Mock< - MockedPluginInitializer, - [PluginName] + MockedPluginInitializer > = jest.fn().mockRejectedValue(new Error('No provider specified')); export const mockLoadPluginBundle = loadPluginBundleMock.create(mockPluginInitializerProvider); diff --git a/src/core/public/plugins/plugins_service.ts b/src/core/public/plugins/plugins_service.ts index 03725a9d7f883..fabb189d2536d 100644 --- a/src/core/public/plugins/plugins_service.ts +++ b/src/core/public/plugins/plugins_service.ts @@ -50,10 +50,7 @@ export interface PluginsServiceStart { */ export class PluginsService implements CoreService { /** Plugin wrappers in topological order. */ - private readonly plugins: Map< - PluginName, - PluginWrapper> - > = new Map(); + private readonly plugins: Map> = new Map(); private readonly satupPlugins: PluginName[] = []; constructor(private readonly coreContext: CoreContext) {} diff --git a/src/core/server/plugins/plugin.ts b/src/core/server/plugins/plugin.ts index 4e680b9fee096..0ee81f86605e6 100644 --- a/src/core/server/plugins/plugin.ts +++ b/src/core/server/plugins/plugin.ts @@ -25,7 +25,6 @@ import { Type } from '@kbn/config-schema'; import { ConfigPath } from '../config'; import { Logger } from '../logging'; import { PluginInitializerContext } from './plugin_context'; -import { EmptyPluginContracts } from '../../types/plugins'; import { CoreSetup, CoreStart } from '..'; export type PluginConfigSchema = Type | null; @@ -137,10 +136,10 @@ export interface DiscoveredPluginInternal extends DiscoveredPlugin { * @public */ export interface Plugin< - TSetup = void, - TStart = void, - TPluginsSetup extends EmptyPluginContracts = EmptyPluginContracts, - TPluginsStart extends EmptyPluginContracts = EmptyPluginContracts + TSetup extends object | void = object, + TStart extends object | void = object, + TPluginsSetup extends object = object, + TPluginsStart extends object = object > { setup(core: CoreSetup, plugins: TPluginsSetup): TSetup | Promise; start(core: CoreStart, plugins: TPluginsStart): TStart | Promise; @@ -154,10 +153,10 @@ export interface Plugin< * @public */ export type PluginInitializer< - TSetup, - TStart, - TPluginsSetup extends EmptyPluginContracts = EmptyPluginContracts, - TPluginsStart extends EmptyPluginContracts = EmptyPluginContracts + TSetup extends object | void = object, + TStart extends object | void = object, + TPluginsSetup extends object = object, + TPluginsStart extends object = object > = (core: PluginInitializerContext) => Plugin; /** @@ -167,10 +166,10 @@ export type PluginInitializer< * @internal */ export class PluginWrapper< - TSetup = unknown, - TStart = unknown, - TPluginsSetup extends EmptyPluginContracts = EmptyPluginContracts, - TPluginsStart extends EmptyPluginContracts = EmptyPluginContracts + TSetup extends object | void = object, + TStart extends object | void = object, + TPluginsSetup extends object = object, + TPluginsStart extends object = object > { public readonly name: PluginManifest['id']; public readonly configPath: PluginManifest['configPath']; diff --git a/src/core/server/plugins/plugin_context.ts b/src/core/server/plugins/plugin_context.ts index 885b2b0e46552..e7d85e1bfeec2 100644 --- a/src/core/server/plugins/plugin_context.ts +++ b/src/core/server/plugins/plugin_context.ts @@ -106,10 +106,10 @@ export function createPluginInitializerContext( * @param deps Dependencies that Plugins services gets during setup. * @internal */ -export function createPluginSetupContext( +export function createPluginSetupContext( coreContext: CoreContext, deps: PluginsServiceSetupDeps, - plugin: PluginWrapper + plugin: PluginWrapper ): CoreSetup { return { elasticsearch: { @@ -138,10 +138,10 @@ export function createPluginSetupContext( * @param deps Dependencies that Plugins services gets during start. * @internal */ -export function createPluginStartContext( +export function createPluginStartContext( coreContext: CoreContext, deps: PluginsServiceStartDeps, - plugin: PluginWrapper + plugin: PluginWrapper ): CoreStart { return {}; } diff --git a/src/core/server/plugins/plugins_system.test.ts b/src/core/server/plugins/plugins_system.test.ts index 9754c1b03d030..687e617056e70 100644 --- a/src/core/server/plugins/plugins_system.test.ts +++ b/src/core/server/plugins/plugins_system.test.ts @@ -117,7 +117,7 @@ test('`setupPlugins` throws if plugins have circular optional dependency', async test('`setupPlugins` ignores missing optional dependency', async () => { const plugin = createPlugin('some-id', { optional: ['missing-dep'] }); - jest.spyOn(plugin, 'setup').mockResolvedValue('test'); + jest.spyOn(plugin, 'setup').mockResolvedValue({ foo: 'bar' }); pluginsSystem.addPlugin(plugin); @@ -125,7 +125,9 @@ test('`setupPlugins` ignores missing optional dependency', async () => { Array [ Array [ "some-id", - "test", + Object { + "foo": "bar", + }, ], ] `); @@ -140,8 +142,8 @@ test('correctly orders plugins and returns exposed values for "setup" and "start [ createPlugin('order-4', { required: ['order-2'] }), { - setup: { 'order-2': 'added-as-2' }, - start: { 'order-2': 'started-as-2' }, + setup: { 'order-2': { foo: 'added-as-2' } }, + start: { 'order-2': { foo: 'started-as-2' } }, }, ], [ @@ -154,22 +156,22 @@ test('correctly orders plugins and returns exposed values for "setup" and "start [ createPlugin('order-2', { required: ['order-1'], optional: ['order-0'] }), { - setup: { 'order-1': 'added-as-3', 'order-0': 'added-as-1' }, - start: { 'order-1': 'started-as-3', 'order-0': 'started-as-1' }, + setup: { 'order-1': { foo: 'added-as-3' }, 'order-0': { foo: 'added-as-1' } }, + start: { 'order-1': { foo: 'started-as-3' }, 'order-0': { foo: 'started-as-1' } }, }, ], [ createPlugin('order-1', { required: ['order-0'] }), { - setup: { 'order-0': 'added-as-1' }, - start: { 'order-0': 'started-as-1' }, + setup: { 'order-0': { foo: 'added-as-1' } }, + start: { 'order-0': { foo: 'started-as-1' } }, }, ], [ createPlugin('order-3', { required: ['order-2'], optional: ['missing-dep'] }), { - setup: { 'order-2': 'added-as-2' }, - start: { 'order-2': 'started-as-2' }, + setup: { 'order-2': { foo: 'added-as-2' } }, + start: { 'order-2': { foo: 'started-as-2' } }, }, ], ] as Array<[PluginWrapper, Contracts]>); @@ -178,11 +180,11 @@ test('correctly orders plugins and returns exposed values for "setup" and "start const startContextMap = new Map(); [...plugins.keys()].forEach((plugin, index) => { - jest.spyOn(plugin, 'setup').mockResolvedValue(`added-as-${index}`); - jest.spyOn(plugin, 'start').mockResolvedValue(`started-as-${index}`); + jest.spyOn(plugin, 'setup').mockResolvedValue({ foo: `added-as-${index}` }); + jest.spyOn(plugin, 'start').mockResolvedValue({ foo: `started-as-${index}` }); - setupContextMap.set(plugin.name, `setup-for-${plugin.name}`); - startContextMap.set(plugin.name, `start-for-${plugin.name}`); + setupContextMap.set(plugin.name, { foo: `setup-for-${plugin.name}` }); + startContextMap.set(plugin.name, { foo: `start-for-${plugin.name}` }); pluginsSystem.addPlugin(plugin); }); @@ -199,23 +201,33 @@ test('correctly orders plugins and returns exposed values for "setup" and "start Array [ Array [ "order-0", - "added-as-1", + Object { + "foo": "added-as-1", + }, ], Array [ "order-1", - "added-as-3", + Object { + "foo": "added-as-3", + }, ], Array [ "order-2", - "added-as-2", + Object { + "foo": "added-as-2", + }, ], Array [ "order-3", - "added-as-4", + Object { + "foo": "added-as-4", + }, ], Array [ "order-4", - "added-as-0", + Object { + "foo": "added-as-0", + }, ], ] `); @@ -231,23 +243,33 @@ Array [ Array [ Array [ "order-0", - "started-as-1", + Object { + "foo": "started-as-1", + }, ], Array [ "order-1", - "started-as-3", + Object { + "foo": "started-as-3", + }, ], Array [ "order-2", - "started-as-2", + Object { + "foo": "started-as-2", + }, ], Array [ "order-3", - "started-as-4", + Object { + "foo": "started-as-4", + }, ], Array [ "order-4", - "started-as-0", + Object { + "foo": "started-as-0", + }, ], ] `); @@ -265,7 +287,7 @@ test('`setupPlugins` only setups plugins that have server side', async () => { const thirdPluginToRun = createPlugin('order-1'); [firstPluginToRun, secondPluginNotToRun, thirdPluginToRun].forEach((plugin, index) => { - jest.spyOn(plugin, 'setup').mockResolvedValue(`added-as-${index}`); + jest.spyOn(plugin, 'setup').mockResolvedValue({ foo: `added-as-${index}` }); pluginsSystem.addPlugin(plugin); }); @@ -274,11 +296,15 @@ test('`setupPlugins` only setups plugins that have server side', async () => { Array [ Array [ "order-1", - "added-as-2", + Object { + "foo": "added-as-2", + }, ], Array [ "order-0", - "added-as-0", + Object { + "foo": "added-as-0", + }, ], ] `); @@ -353,8 +379,8 @@ test('`startPlugins` only starts plugins that were setup', async () => { const thirdPluginToRun = createPlugin('order-1'); [firstPluginToRun, secondPluginNotToRun, thirdPluginToRun].forEach((plugin, index) => { - jest.spyOn(plugin, 'setup').mockResolvedValue(`setup-as-${index}`); - jest.spyOn(plugin, 'start').mockResolvedValue(`started-as-${index}`); + jest.spyOn(plugin, 'setup').mockResolvedValue({ foo: `setup-as-${index}` }); + jest.spyOn(plugin, 'start').mockResolvedValue({ foo: `started-as-${index}` }); pluginsSystem.addPlugin(plugin); }); @@ -364,11 +390,15 @@ test('`startPlugins` only starts plugins that were setup', async () => { Array [ Array [ "order-1", - "started-as-2", + Object { + "foo": "started-as-2", + }, ], Array [ "order-0", - "started-as-0", + Object { + "foo": "started-as-0", + }, ], ] `); diff --git a/src/core/types/index.ts b/src/core/types/index.ts index 5feea393be92d..3aae17e6ea594 100644 --- a/src/core/types/index.ts +++ b/src/core/types/index.ts @@ -22,4 +22,3 @@ * types are stripped. */ export * from './core_service'; -export * from './plugins'; diff --git a/src/core/types/plugins.ts b/src/core/types/plugins.ts deleted file mode 100644 index a4d577893537e..0000000000000 --- a/src/core/types/plugins.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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. - */ - -// eslint-disable-next-line @typescript-eslint/no-empty-interface -export interface EmptyPluginContracts {} diff --git a/src/plugins/data/public/plugin.ts b/src/plugins/data/public/plugin.ts index 96dcb7ca27fad..ef2b8eb0a98f4 100644 --- a/src/plugins/data/public/plugin.ts +++ b/src/plugins/data/public/plugin.ts @@ -20,7 +20,7 @@ import { PluginInitializerContext, CoreSetup, CoreStart, Plugin } from '../../../core/public'; import { ExpressionsService } from './expressions/expressions_service'; -export class DataPublicPlugin implements Plugin<{}> { +export class DataPublicPlugin implements Plugin, void> { expressions = new ExpressionsService(); constructor(initializerContext: PluginInitializerContext) {} diff --git a/src/plugins/data/server/plugin.ts b/src/plugins/data/server/plugin.ts index 3aa04c7a5be7a..3ce67e19701fd 100644 --- a/src/plugins/data/server/plugin.ts +++ b/src/plugins/data/server/plugin.ts @@ -19,7 +19,7 @@ import { PluginInitializerContext, CoreSetup, CoreStart, Plugin } from '../../../core/server'; -export class DataServerPlugin implements Plugin { +export class DataServerPlugin implements Plugin { constructor(initializerContext: PluginInitializerContext) {} public setup(core: CoreSetup) {} public start(core: CoreStart) {} From af295b43bdf27bcefd7ed293fa97e96a9656add0 Mon Sep 17 00:00:00 2001 From: streamich Date: Wed, 3 Jul 2019 22:59:35 +0200 Subject: [PATCH 4/4] =?UTF-8?q?docs:=20=E2=9C=8F=EF=B8=8F=20update=20Core?= =?UTF-8?q?=20documentation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/development/core/public/kibana-plugin-public.plugin.md | 2 +- .../core/public/kibana-plugin-public.plugininitializer.md | 2 +- docs/development/core/server/kibana-plugin-server.plugin.md | 2 +- .../core/server/kibana-plugin-server.plugininitializer.md | 2 +- src/core/public/public.api.md | 6 ++---- src/core/server/server.api.md | 6 ++---- 6 files changed, 8 insertions(+), 12 deletions(-) diff --git a/docs/development/core/public/kibana-plugin-public.plugin.md b/docs/development/core/public/kibana-plugin-public.plugin.md index 2275a82bcf6ab..c538273782cb6 100644 --- a/docs/development/core/public/kibana-plugin-public.plugin.md +++ b/docs/development/core/public/kibana-plugin-public.plugin.md @@ -9,7 +9,7 @@ The interface that should be returned by a `PluginInitializer`. Signature: ```typescript -export interface Plugin +export interface Plugin ``` ## Methods diff --git a/docs/development/core/public/kibana-plugin-public.plugininitializer.md b/docs/development/core/public/kibana-plugin-public.plugininitializer.md index 66862e904c19d..14f27b1fa709c 100644 --- a/docs/development/core/public/kibana-plugin-public.plugininitializer.md +++ b/docs/development/core/public/kibana-plugin-public.plugininitializer.md @@ -9,5 +9,5 @@ The `plugin` export at the root of a plugin's `public` directory should conform Signature: ```typescript -export declare type PluginInitializer = (core: PluginInitializerContext) => Plugin; +export declare type PluginInitializer = (core: PluginInitializerContext) => Plugin; ``` diff --git a/docs/development/core/server/kibana-plugin-server.plugin.md b/docs/development/core/server/kibana-plugin-server.plugin.md index 8213b8a96e828..b0385f81da0d2 100644 --- a/docs/development/core/server/kibana-plugin-server.plugin.md +++ b/docs/development/core/server/kibana-plugin-server.plugin.md @@ -9,7 +9,7 @@ The interface that should be returned by a `PluginInitializer`. Signature: ```typescript -export interface Plugin +export interface Plugin ``` ## Methods diff --git a/docs/development/core/server/kibana-plugin-server.plugininitializer.md b/docs/development/core/server/kibana-plugin-server.plugininitializer.md index bb0a88694f71c..255d2ac4ed654 100644 --- a/docs/development/core/server/kibana-plugin-server.plugininitializer.md +++ b/docs/development/core/server/kibana-plugin-server.plugininitializer.md @@ -9,5 +9,5 @@ The `plugin` export at the root of a plugin's `server` directory should conform Signature: ```typescript -export declare type PluginInitializer = (core: PluginInitializerContext) => Plugin; +export declare type PluginInitializer = (core: PluginInitializerContext) => Plugin; ``` diff --git a/src/core/public/public.api.md b/src/core/public/public.api.md index c8da1f802afcf..6851f416f23e0 100644 --- a/src/core/public/public.api.md +++ b/src/core/public/public.api.md @@ -474,10 +474,8 @@ export interface OverlayStart { }) => OverlayRef; } -// Warning: (ae-forgotten-export) The symbol "EmptyPluginContracts" needs to be exported by the entry point index.d.ts -// // @public -export interface Plugin { +export interface Plugin { // (undocumented) setup(core: CoreSetup, plugins: TPluginsSetup): TSetup | Promise; // (undocumented) @@ -487,7 +485,7 @@ export interface Plugin = (core: PluginInitializerContext) => Plugin; +export type PluginInitializer = (core: PluginInitializerContext) => Plugin; // @public export interface PluginInitializerContext { diff --git a/src/core/server/server.api.md b/src/core/server/server.api.md index 048ae79824b4f..b56f40ffd4331 100644 --- a/src/core/server/server.api.md +++ b/src/core/server/server.api.md @@ -312,10 +312,8 @@ export interface OnPreAuthToolkit { }) => OnPreAuthResult; } -// Warning: (ae-forgotten-export) The symbol "EmptyPluginContracts" needs to be exported by the entry point index.d.ts -// // @public -export interface Plugin { +export interface Plugin { // (undocumented) setup(core: CoreSetup, plugins: TPluginsSetup): TSetup | Promise; // (undocumented) @@ -325,7 +323,7 @@ export interface Plugin = (core: PluginInitializerContext) => Plugin; +export type PluginInitializer = (core: PluginInitializerContext) => Plugin; // @public export interface PluginInitializerContext {