From a7d5e977a2d93ec423472a2cbf294ac0ad1afbb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Ferna=CC=81ndez=20Haro?= Date: Wed, 20 Nov 2019 10:06:18 +0000 Subject: [PATCH 01/21] [NP] Expose global config to the plugins --- ...-server.plugininitializercontext.config.md | 1 + ...-plugin-server.plugininitializercontext.md | 2 +- src/core/server/mocks.ts | 6 +- .../server/plugins/plugin_context.test.ts | 73 +++++++++++++++++++ src/core/server/plugins/plugin_context.ts | 7 ++ src/core/server/plugins/types.ts | 3 +- src/core/server/server.api.md | 1 + 7 files changed, 89 insertions(+), 4 deletions(-) create mode 100644 src/core/server/plugins/plugin_context.test.ts diff --git a/docs/development/core/server/kibana-plugin-server.plugininitializercontext.config.md b/docs/development/core/server/kibana-plugin-server.plugininitializercontext.config.md index 33a26eef8a7cb5..d0ce3f75ec0242 100644 --- a/docs/development/core/server/kibana-plugin-server.plugininitializercontext.config.md +++ b/docs/development/core/server/kibana-plugin-server.plugininitializercontext.config.md @@ -8,6 +8,7 @@ ```typescript config: { + globalConfig__deprecated$: Observable; create: () => Observable; createIfExists: () => Observable; }; diff --git a/docs/development/core/server/kibana-plugin-server.plugininitializercontext.md b/docs/development/core/server/kibana-plugin-server.plugininitializercontext.md index e7aa32edaa293b..171fcfc2c64c61 100644 --- a/docs/development/core/server/kibana-plugin-server.plugininitializercontext.md +++ b/docs/development/core/server/kibana-plugin-server.plugininitializercontext.md @@ -16,7 +16,7 @@ export interface PluginInitializerContext | Property | Type | Description | | --- | --- | --- | -| [config](./kibana-plugin-server.plugininitializercontext.config.md) | {
create: <T = ConfigSchema>() => Observable<T>;
createIfExists: <T = ConfigSchema>() => Observable<T | undefined>;
} | | +| [config](./kibana-plugin-server.plugininitializercontext.config.md) | {
globalConfig__deprecated$: Observable<Config>;
create: <T = ConfigSchema>() => Observable<T>;
createIfExists: <T = ConfigSchema>() => Observable<T | undefined>;
} | | | [env](./kibana-plugin-server.plugininitializercontext.env.md) | {
mode: EnvironmentMode;
packageInfo: Readonly<PackageInfo>;
} | | | [logger](./kibana-plugin-server.plugininitializercontext.logger.md) | LoggerFactory | | | [opaqueId](./kibana-plugin-server.plugininitializercontext.opaqueid.md) | PluginOpaqueId | | diff --git a/src/core/server/mocks.ts b/src/core/server/mocks.ts index b51d5302e32746..b03d827d7c4063 100644 --- a/src/core/server/mocks.ts +++ b/src/core/server/mocks.ts @@ -16,13 +16,14 @@ * specific language governing permissions and limitations * under the License. */ -import { of } from 'rxjs'; +import { of, BehaviorSubject } from 'rxjs'; import { PluginInitializerContext, CoreSetup, CoreStart } from '.'; import { loggingServiceMock } from './logging/logging_service.mock'; import { elasticsearchServiceMock } from './elasticsearch/elasticsearch_service.mock'; import { httpServiceMock } from './http/http_service.mock'; import { contextServiceMock } from './context/context_service.mock'; import { uiSettingsServiceMock } from './ui_settings/ui_settings_service.mock'; +import { ObjectToConfigAdapter } from './config'; export { httpServerMock } from './http/http_server.mocks'; export { sessionStorageMock } from './http/cookie_session_storage.mocks'; @@ -33,8 +34,9 @@ export { loggingServiceMock } from './logging/logging_service.mock'; export { savedObjectsClientMock } from './saved_objects/service/saved_objects_client.mock'; export { uiSettingsServiceMock } from './ui_settings/ui_settings_service.mock'; -export function pluginInitializerContextConfigMock(config: T) { +export function pluginInitializerContextConfigMock(config: T, globalConfig = {}) { const mock: jest.Mocked['config']> = { + globalConfig__deprecated$: new BehaviorSubject(new ObjectToConfigAdapter(globalConfig)), create: jest.fn().mockReturnValue(of(config)), createIfExists: jest.fn().mockReturnValue(of(config)), }; diff --git a/src/core/server/plugins/plugin_context.test.ts b/src/core/server/plugins/plugin_context.test.ts new file mode 100644 index 00000000000000..29730b554f573f --- /dev/null +++ b/src/core/server/plugins/plugin_context.test.ts @@ -0,0 +1,73 @@ +/* + * 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 { createPluginInitializerContext } from './plugin_context'; +import { CoreContext } from '../core_context'; +import { Env, ObjectToConfigAdapter } from '../config'; +import { configServiceMock } from '../config/config_service.mock'; +import { loggingServiceMock } from '../logging/logging_service.mock'; +import { getEnvOptions } from '../config/__mocks__/env'; +import { PluginManifest } from './types'; +import { first } from 'rxjs/operators'; + +const logger = loggingServiceMock.create(); +const configService = configServiceMock.create({ getConfig$: { globalConfig: { subpath: 1 } } }); + +let coreId: symbol; +let env: Env; +let coreContext: CoreContext; + +function createPluginManifest(manifestProps: Partial = {}): PluginManifest { + return { + id: 'some-plugin-id', + version: 'some-version', + configPath: 'path', + kibanaVersion: '7.0.0', + requiredPlugins: ['some-required-dep'], + optionalPlugins: ['some-optional-dep'], + server: true, + ui: true, + ...manifestProps, + }; +} + +beforeEach(() => { + coreId = Symbol('core'); + env = Env.createDefault(getEnvOptions()); + coreContext = { coreId, env, logger, configService }; +}); + +test('should return a globalConfig handler in the context (to be deprecated)', async () => { + const manifest = createPluginManifest(); + const opaqueId = Symbol(); + const pluginInitializerContext = createPluginInitializerContext(coreContext, opaqueId, manifest); + + expect(pluginInitializerContext.config.globalConfig__deprecated$).toBeDefined(); + + const configObject = await pluginInitializerContext.config.globalConfig__deprecated$ + .pipe(first()) + .toPromise(); + expect(configObject).toBeInstanceOf(ObjectToConfigAdapter); + + const configPaths = configObject.getFlattenedPaths(); + expect(configPaths).toHaveLength(1); + expect(configPaths).toStrictEqual(['globalConfig.subpath']); + expect(configObject.has('globalConfig.subpath')).toBe(true); + expect(configObject.get('globalConfig.subpath')).toBe(1); +}); diff --git a/src/core/server/plugins/plugin_context.ts b/src/core/server/plugins/plugin_context.ts index 9885a572ad8c00..f75692eda22b3a 100644 --- a/src/core/server/plugins/plugin_context.ts +++ b/src/core/server/plugins/plugin_context.ts @@ -65,6 +65,13 @@ export function createPluginInitializerContext( * Core configuration functionality, enables fetching a subset of the config. */ config: { + /** + * Global configuration + * Note: naming not final here, it will be renamed in a near future (https://github.com/elastic/kibana/issues/46240) + * @deprecated + */ + globalConfig__deprecated$: coreContext.configService.getConfig$(), + /** * Reads the subset of the config at the `configPath` defined in the plugin * manifest and validates it against the schema in the static `schema` on diff --git a/src/core/server/plugins/types.ts b/src/core/server/plugins/types.ts index 17704ce687b92d..6e32fb7dc26253 100644 --- a/src/core/server/plugins/types.ts +++ b/src/core/server/plugins/types.ts @@ -20,7 +20,7 @@ import { Observable } from 'rxjs'; import { Type } from '@kbn/config-schema'; -import { ConfigPath, EnvironmentMode, PackageInfo } from '../config'; +import { ConfigPath, EnvironmentMode, PackageInfo, Config } from '../config'; import { LoggerFactory } from '../logging'; import { CoreSetup, CoreStart } from '..'; @@ -209,6 +209,7 @@ export interface PluginInitializerContext { }; logger: LoggerFactory; config: { + globalConfig__deprecated$: Observable; create: () => Observable; createIfExists: () => Observable; }; diff --git a/src/core/server/server.api.md b/src/core/server/server.api.md index 7ecb9053a4bcff..3fa9d5aeaeb128 100644 --- a/src/core/server/server.api.md +++ b/src/core/server/server.api.md @@ -977,6 +977,7 @@ export type PluginInitializer { // (undocumented) config: { + globalConfig__deprecated$: Observable; create: () => Observable; createIfExists: () => Observable; }; From 7ea1c50c6b9bf6604f062f1787b8f1f7a30d631d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Ferna=CC=81ndez=20Haro?= Date: Mon, 25 Nov 2019 10:50:40 +0000 Subject: [PATCH 02/21] globalConfig in Plugin context: expose read-only methods only --- ...plugin-server.plugininitializercontext.config.md | 2 +- ...kibana-plugin-server.plugininitializercontext.md | 2 +- src/core/server/plugins/plugin_context.test.ts | 3 +-- src/core/server/plugins/plugin_context.ts | 13 +++++++++++-- src/core/server/plugins/types.ts | 2 +- src/core/server/server.api.md | 2 +- 6 files changed, 16 insertions(+), 8 deletions(-) diff --git a/docs/development/core/server/kibana-plugin-server.plugininitializercontext.config.md b/docs/development/core/server/kibana-plugin-server.plugininitializercontext.config.md index d0ce3f75ec0242..c73bcf4cb8cd0f 100644 --- a/docs/development/core/server/kibana-plugin-server.plugininitializercontext.config.md +++ b/docs/development/core/server/kibana-plugin-server.plugininitializercontext.config.md @@ -8,7 +8,7 @@ ```typescript config: { - globalConfig__deprecated$: Observable; + globalConfig__deprecated$: Observable>; create: () => Observable; createIfExists: () => Observable; }; diff --git a/docs/development/core/server/kibana-plugin-server.plugininitializercontext.md b/docs/development/core/server/kibana-plugin-server.plugininitializercontext.md index 171fcfc2c64c61..b492fa1abda2c3 100644 --- a/docs/development/core/server/kibana-plugin-server.plugininitializercontext.md +++ b/docs/development/core/server/kibana-plugin-server.plugininitializercontext.md @@ -16,7 +16,7 @@ export interface PluginInitializerContext | Property | Type | Description | | --- | --- | --- | -| [config](./kibana-plugin-server.plugininitializercontext.config.md) | {
globalConfig__deprecated$: Observable<Config>;
create: <T = ConfigSchema>() => Observable<T>;
createIfExists: <T = ConfigSchema>() => Observable<T | undefined>;
} | | +| [config](./kibana-plugin-server.plugininitializercontext.config.md) | {
globalConfig__deprecated$: Observable<Pick<Config, 'has' | 'get' | 'getFlattenedPaths'>>;
create: <T = ConfigSchema>() => Observable<T>;
createIfExists: <T = ConfigSchema>() => Observable<T | undefined>;
} | | | [env](./kibana-plugin-server.plugininitializercontext.env.md) | {
mode: EnvironmentMode;
packageInfo: Readonly<PackageInfo>;
} | | | [logger](./kibana-plugin-server.plugininitializercontext.logger.md) | LoggerFactory | | | [opaqueId](./kibana-plugin-server.plugininitializercontext.opaqueid.md) | PluginOpaqueId | | diff --git a/src/core/server/plugins/plugin_context.test.ts b/src/core/server/plugins/plugin_context.test.ts index 29730b554f573f..1f5fccedde50b2 100644 --- a/src/core/server/plugins/plugin_context.test.ts +++ b/src/core/server/plugins/plugin_context.test.ts @@ -19,7 +19,7 @@ import { createPluginInitializerContext } from './plugin_context'; import { CoreContext } from '../core_context'; -import { Env, ObjectToConfigAdapter } from '../config'; +import { Env } from '../config'; import { configServiceMock } from '../config/config_service.mock'; import { loggingServiceMock } from '../logging/logging_service.mock'; import { getEnvOptions } from '../config/__mocks__/env'; @@ -63,7 +63,6 @@ test('should return a globalConfig handler in the context (to be deprecated)', a const configObject = await pluginInitializerContext.config.globalConfig__deprecated$ .pipe(first()) .toPromise(); - expect(configObject).toBeInstanceOf(ObjectToConfigAdapter); const configPaths = configObject.getFlattenedPaths(); expect(configPaths).toHaveLength(1); diff --git a/src/core/server/plugins/plugin_context.ts b/src/core/server/plugins/plugin_context.ts index f75692eda22b3a..65e5bdb4f766c8 100644 --- a/src/core/server/plugins/plugin_context.ts +++ b/src/core/server/plugins/plugin_context.ts @@ -17,11 +17,12 @@ * under the License. */ +import { map } from 'rxjs/operators'; import { CoreContext } from '../core_context'; import { PluginWrapper } from './plugin'; import { PluginsServiceSetupDeps, PluginsServiceStartDeps } from './plugins_service'; import { PluginInitializerContext, PluginManifest, PluginOpaqueId } from './types'; -import { CoreSetup, CoreStart } from '..'; +import { CoreSetup, CoreStart, ConfigPath } from '..'; /** * This returns a facade for `CoreContext` that will be exposed to the plugin initializer. @@ -70,7 +71,13 @@ export function createPluginInitializerContext( * Note: naming not final here, it will be renamed in a near future (https://github.com/elastic/kibana/issues/46240) * @deprecated */ - globalConfig__deprecated$: coreContext.configService.getConfig$(), + globalConfig__deprecated$: coreContext.configService.getConfig$().pipe( + map(conf => ({ + has: (configPath: ConfigPath) => conf.has(configPath), + get: (configPath: ConfigPath) => conf.get(configPath), + getFlattenedPaths: () => conf.getFlattenedPaths(), + })) + ), /** * Reads the subset of the config at the `configPath` defined in the plugin @@ -89,6 +96,8 @@ export function createPluginInitializerContext( }; } +// function exposeReadOnlyMethods(conf: ) + /** * This returns a facade for `CoreContext` that will be exposed to the plugin `setup` method. * This facade should be safe to use only within `setup` itself. diff --git a/src/core/server/plugins/types.ts b/src/core/server/plugins/types.ts index 6e32fb7dc26253..ebf9aaa0f42714 100644 --- a/src/core/server/plugins/types.ts +++ b/src/core/server/plugins/types.ts @@ -209,7 +209,7 @@ export interface PluginInitializerContext { }; logger: LoggerFactory; config: { - globalConfig__deprecated$: Observable; + globalConfig__deprecated$: Observable>; create: () => Observable; createIfExists: () => Observable; }; diff --git a/src/core/server/server.api.md b/src/core/server/server.api.md index 3fa9d5aeaeb128..6ce0895dd6b5b6 100644 --- a/src/core/server/server.api.md +++ b/src/core/server/server.api.md @@ -977,7 +977,7 @@ export type PluginInitializer { // (undocumented) config: { - globalConfig__deprecated$: Observable; + globalConfig__deprecated$: Observable>; create: () => Observable; createIfExists: () => Observable; }; From 4e31b77ddde2b7eb411cb08e6b4530ad35cb8912 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Ferna=CC=81ndez=20Haro?= Date: Wed, 27 Nov 2019 12:47:47 +0000 Subject: [PATCH 03/21] SharedGlobalConfig rework + Moving pkg, fromRoot & path utils from legacy to NP --- ...a-plugin-public.savedobjectsclient.find.md | 2 +- ...kibana-plugin-public.savedobjectsclient.md | 2 +- ...-server.plugininitializercontext.config.md | 2 +- ...-plugin-server.plugininitializercontext.md | 2 +- src/cli/cli.js | 2 +- src/cli/cluster/cluster_manager.js | 2 +- src/cli/cluster/worker.js | 3 +- src/cli/serve/read_keystore.js | 4 +- src/cli/serve/serve.js | 7 ++-- src/cli_keystore/cli_keystore.js | 6 +-- src/cli_plugin/cli.js | 2 +- src/cli_plugin/install/index.js | 6 +-- src/cli_plugin/install/settings.test.js | 2 +- src/cli_plugin/list/index.js | 2 +- src/cli_plugin/list/settings.test.js | 2 +- src/cli_plugin/remove/index.js | 6 +-- src/cli_plugin/remove/settings.test.js | 2 +- src/core/public/public.api.md | 2 +- .../__snapshots__/legacy_service.test.ts.snap | 2 + src/core/server/legacy/legacy_service.test.ts | 12 +++--- src/core/server/legacy/legacy_service.ts | 23 +++++++---- src/core/server/mocks.ts | 22 ++++++++-- .../server/path.test.ts} | 14 +++---- .../path/index.js => core/server/path.ts} | 41 ++++++++++++------- .../server/plugins/plugin_context.test.ts | 34 +++++++++------ src/core/server/plugins/plugin_context.ts | 33 +++++++++++---- .../plugins/plugins_service.test.mocks.ts | 7 +++- src/core/server/plugins/types.ts | 21 +++++++++- src/core/server/server.api.md | 4 +- src/core/server/server.ts | 2 + src/{legacy => core}/utils/from_root.ts | 0 src/core/utils/index.ts | 2 + src/{legacy => core}/utils/package_json.ts | 0 src/core/utils/pick.ts | 2 +- src/legacy/core_plugins/telemetry/index.ts | 4 +- .../tests_bundle/find_source_files.js | 2 +- src/legacy/core_plugins/tests_bundle/index.js | 2 +- src/legacy/server/config/config.js | 5 +-- src/legacy/server/config/schema.js | 11 ++--- src/legacy/server/i18n/index.js | 2 +- src/legacy/server/kbn_server.js | 2 +- src/legacy/server/sass/index.js | 3 +- src/legacy/server/status/server_status.js | 2 +- .../ui/ui_bundles/ui_bundles_controller.js | 3 +- src/legacy/ui/ui_render/ui_render_mixin.js | 2 +- src/legacy/utils/artifact_type.ts | 2 +- src/legacy/utils/index.js | 2 - src/optimize/base_optimizer.js | 3 +- .../dynamic_dll_plugin/dll_compiler.js | 2 +- .../dynamic_dll_plugin/dll_config_model.js | 3 +- src/optimize/index.js | 2 +- src/optimize/watch/watch_optimizer.js | 2 +- .../services/visual_testing/visual_testing.ts | 2 +- 53 files changed, 209 insertions(+), 122 deletions(-) rename src/{legacy/server/path/index.test.js => core/server/path.test.ts} (71%) rename src/{legacy/server/path/index.js => core/server/path.ts} (56%) rename src/{legacy => core}/utils/from_root.ts (100%) rename src/{legacy => core}/utils/package_json.ts (100%) diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsclient.find.md b/docs/development/core/public/kibana-plugin-public.savedobjectsclient.find.md index 866755e78648af..e4ab3e284b5af9 100644 --- a/docs/development/core/public/kibana-plugin-public.savedobjectsclient.find.md +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsclient.find.md @@ -9,5 +9,5 @@ Search for objects Signature: ```typescript -find: (options: Pick) => Promise>; +find: (options: Pick) => Promise>; ``` diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsclient.md b/docs/development/core/public/kibana-plugin-public.savedobjectsclient.md index 50451b813a61c0..32854d061280a3 100644 --- a/docs/development/core/public/kibana-plugin-public.savedobjectsclient.md +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsclient.md @@ -20,7 +20,7 @@ export declare class SavedObjectsClient | [bulkGet](./kibana-plugin-public.savedobjectsclient.bulkget.md) | | (objects?: {
id: string;
type: string;
}[]) => Promise<SavedObjectsBatchResponse<SavedObjectAttributes>> | Returns an array of objects by id | | [create](./kibana-plugin-public.savedobjectsclient.create.md) | | <T extends SavedObjectAttributes>(type: string, attributes: T, options?: SavedObjectsCreateOptions) => Promise<SimpleSavedObject<T>> | Persists an object | | [delete](./kibana-plugin-public.savedobjectsclient.delete.md) | | (type: string, id: string) => Promise<{}> | Deletes an object | -| [find](./kibana-plugin-public.savedobjectsclient.find.md) | | <T extends SavedObjectAttributes>(options: Pick<SavedObjectFindOptionsServer, "search" | "filter" | "type" | "searchFields" | "defaultSearchOperator" | "hasReference" | "sortField" | "page" | "perPage" | "fields">) => Promise<SavedObjectsFindResponsePublic<T>> | Search for objects | +| [find](./kibana-plugin-public.savedobjectsclient.find.md) | | <T extends SavedObjectAttributes>(options: Pick<SavedObjectFindOptionsServer, "search" | "filter" | "type" | "page" | "searchFields" | "defaultSearchOperator" | "hasReference" | "sortField" | "perPage" | "fields">) => Promise<SavedObjectsFindResponsePublic<T>> | Search for objects | | [get](./kibana-plugin-public.savedobjectsclient.get.md) | | <T extends SavedObjectAttributes>(type: string, id: string) => Promise<SimpleSavedObject<T>> | Fetches a single object | ## Methods diff --git a/docs/development/core/server/kibana-plugin-server.plugininitializercontext.config.md b/docs/development/core/server/kibana-plugin-server.plugininitializercontext.config.md index c73bcf4cb8cd0f..e051e1369ddd35 100644 --- a/docs/development/core/server/kibana-plugin-server.plugininitializercontext.config.md +++ b/docs/development/core/server/kibana-plugin-server.plugininitializercontext.config.md @@ -8,7 +8,7 @@ ```typescript config: { - globalConfig__deprecated$: Observable>; + globalConfig__deprecated$: Observable; create: () => Observable; createIfExists: () => Observable; }; diff --git a/docs/development/core/server/kibana-plugin-server.plugininitializercontext.md b/docs/development/core/server/kibana-plugin-server.plugininitializercontext.md index b492fa1abda2c3..a40a4919d39ba9 100644 --- a/docs/development/core/server/kibana-plugin-server.plugininitializercontext.md +++ b/docs/development/core/server/kibana-plugin-server.plugininitializercontext.md @@ -16,7 +16,7 @@ export interface PluginInitializerContext | Property | Type | Description | | --- | --- | --- | -| [config](./kibana-plugin-server.plugininitializercontext.config.md) | {
globalConfig__deprecated$: Observable<Pick<Config, 'has' | 'get' | 'getFlattenedPaths'>>;
create: <T = ConfigSchema>() => Observable<T>;
createIfExists: <T = ConfigSchema>() => Observable<T | undefined>;
} | | +| [config](./kibana-plugin-server.plugininitializercontext.config.md) | {
globalConfig__deprecated$: Observable<SharedGlobalConfig>;
create: <T = ConfigSchema>() => Observable<T>;
createIfExists: <T = ConfigSchema>() => Observable<T | undefined>;
} | | | [env](./kibana-plugin-server.plugininitializercontext.env.md) | {
mode: EnvironmentMode;
packageInfo: Readonly<PackageInfo>;
} | | | [logger](./kibana-plugin-server.plugininitializercontext.logger.md) | LoggerFactory | | | [opaqueId](./kibana-plugin-server.plugininitializercontext.opaqueid.md) | PluginOpaqueId | | diff --git a/src/cli/cli.js b/src/cli/cli.js index 6b6d45ed2eb3ed..cbf3d5bfa19374 100644 --- a/src/cli/cli.js +++ b/src/cli/cli.js @@ -18,7 +18,7 @@ */ import _ from 'lodash'; -import { pkg } from '../legacy/utils'; +import { pkg } from '../core/utils'; import Command from './command'; import serveCommand from './serve/serve'; diff --git a/src/cli/cluster/cluster_manager.js b/src/cli/cluster/cluster_manager.js index a67593c02a5935..5317b705b2252d 100644 --- a/src/cli/cluster/cluster_manager.js +++ b/src/cli/cluster/cluster_manager.js @@ -167,7 +167,7 @@ export default class ClusterManager { setupWatching(extraPaths, pluginInternalDirsIgnore) { const chokidar = require('chokidar'); - const { fromRoot } = require('../../legacy/utils'); + const { fromRoot } = require('../../core/utils'); const watchPaths = [ fromRoot('src/core'), diff --git a/src/cli/cluster/worker.js b/src/cli/cluster/worker.js index 8eca55a08af2ca..d430c37263e3a3 100644 --- a/src/cli/cluster/worker.js +++ b/src/cli/cluster/worker.js @@ -21,7 +21,8 @@ import _ from 'lodash'; import cluster from 'cluster'; import { EventEmitter } from 'events'; -import { BinderFor, fromRoot } from '../../legacy/utils'; +import { BinderFor } from '../../legacy/utils'; +import { fromRoot } from '../../core/utils'; const cliPath = fromRoot('src/cli'); const baseArgs = _.difference(process.argv.slice(2), ['--no-watch']); diff --git a/src/cli/serve/read_keystore.js b/src/cli/serve/read_keystore.js index b5b580cbc2d73a..c17091a11f5c14 100644 --- a/src/cli/serve/read_keystore.js +++ b/src/cli/serve/read_keystore.js @@ -21,9 +21,9 @@ import path from 'path'; import { set } from 'lodash'; import { Keystore } from '../../legacy/server/keystore'; -import { getData } from '../../legacy/server/path'; +import { getDataPath } from '../../core/server/path'; -export function readKeystore(dataPath = getData()) { +export function readKeystore(dataPath = getDataPath()) { const keystore = new Keystore(path.join(dataPath, 'kibana.keystore')); keystore.load(); diff --git a/src/cli/serve/serve.js b/src/cli/serve/serve.js index 1f7593d788304b..fe056684efea76 100644 --- a/src/cli/serve/serve.js +++ b/src/cli/serve/serve.js @@ -22,8 +22,9 @@ import { statSync } from 'fs'; import { resolve } from 'path'; import url from 'url'; -import { fromRoot, IS_KIBANA_DISTRIBUTABLE } from '../../legacy/utils'; -import { getConfig } from '../../legacy/server/path'; +import { IS_KIBANA_DISTRIBUTABLE } from '../../legacy/utils'; +import { fromRoot } from '../../core/utils'; +import { getConfigPath } from '../../core/server/path'; import { bootstrap } from '../../core/server'; import { readKeystore } from './read_keystore'; @@ -166,7 +167,7 @@ export default function (program) { '-c, --config ', 'Path to the config file, use multiple --config args to include multiple config files', configPathCollector, - [ getConfig() ] + [ getConfigPath() ] ) .option('-p, --port ', 'The port to bind to', parseInt) .option('-q, --quiet', 'Prevent all logging except errors') diff --git a/src/cli_keystore/cli_keystore.js b/src/cli_keystore/cli_keystore.js index 823d7bd4f44ebd..ebee0b411388cc 100644 --- a/src/cli_keystore/cli_keystore.js +++ b/src/cli_keystore/cli_keystore.js @@ -19,12 +19,12 @@ import { join } from 'path'; -import { pkg } from '../legacy/utils'; +import { pkg } from '../core/utils'; import Command from '../cli/command'; -import { getData } from '../legacy/server/path'; +import { getDataPath } from '../core/server/path'; import { Keystore } from '../legacy/server/keystore'; -const path = join(getData(), 'kibana.keystore'); +const path = join(getDataPath(), 'kibana.keystore'); const keystore = new Keystore(path); import { createCli } from './create'; diff --git a/src/cli_plugin/cli.js b/src/cli_plugin/cli.js index e4e49a0e299678..c46221ab552ef2 100644 --- a/src/cli_plugin/cli.js +++ b/src/cli_plugin/cli.js @@ -18,7 +18,7 @@ */ import _ from 'lodash'; -import { pkg } from '../legacy/utils'; +import { pkg } from '../core/utils'; import Command from '../cli/command'; import listCommand from './list'; import installCommand from './install'; diff --git a/src/cli_plugin/install/index.js b/src/cli_plugin/install/index.js index 16927357082ea3..dba0e2c24e745a 100644 --- a/src/cli_plugin/install/index.js +++ b/src/cli_plugin/install/index.js @@ -17,10 +17,10 @@ * under the License. */ -import { fromRoot, pkg } from '../../legacy/utils'; +import { fromRoot, pkg } from '../../core/utils'; import install from './install'; import Logger from '../lib/logger'; -import { getConfig } from '../../legacy/server/path'; +import { getConfigPath } from '../../core/server/path'; import { parse, parseMilliseconds } from './settings'; import logWarnings from '../lib/log_warnings'; import { warnIfUsingPluginDirOption } from '../lib/warn_if_plugin_dir_option'; @@ -50,7 +50,7 @@ export default function pluginInstall(program) { .option( '-c, --config ', 'path to the config file', - getConfig() + getConfigPath() ) .option( '-t, --timeout ', diff --git a/src/cli_plugin/install/settings.test.js b/src/cli_plugin/install/settings.test.js index 9e3da9ee3a492c..18ab0feda49530 100644 --- a/src/cli_plugin/install/settings.test.js +++ b/src/cli_plugin/install/settings.test.js @@ -17,7 +17,7 @@ * under the License. */ -import { fromRoot } from '../../legacy/utils'; +import { fromRoot } from '../../core/utils'; import { resolve } from 'path'; import { parseMilliseconds, parse } from './settings'; diff --git a/src/cli_plugin/list/index.js b/src/cli_plugin/list/index.js index 60965b95ab2ea4..2f5a2f331b2e8d 100644 --- a/src/cli_plugin/list/index.js +++ b/src/cli_plugin/list/index.js @@ -17,7 +17,7 @@ * under the License. */ -import { fromRoot } from '../../legacy/utils'; +import { fromRoot } from '../../core/utils'; import list from './list'; import Logger from '../lib/logger'; import { parse } from './settings'; diff --git a/src/cli_plugin/list/settings.test.js b/src/cli_plugin/list/settings.test.js index 38ec96dff1770a..32b78723735681 100644 --- a/src/cli_plugin/list/settings.test.js +++ b/src/cli_plugin/list/settings.test.js @@ -17,7 +17,7 @@ * under the License. */ -import { fromRoot } from '../../legacy/utils'; +import { fromRoot } from '../../core/utils'; import { parse } from './settings'; describe('kibana cli', function () { diff --git a/src/cli_plugin/remove/index.js b/src/cli_plugin/remove/index.js index 8937ade8d162ff..3c0099c46bd6f1 100644 --- a/src/cli_plugin/remove/index.js +++ b/src/cli_plugin/remove/index.js @@ -17,11 +17,11 @@ * under the License. */ -import { fromRoot } from '../../legacy/utils'; +import { fromRoot } from '../../core/utils'; import remove from './remove'; import Logger from '../lib/logger'; import { parse } from './settings'; -import { getConfig } from '../../legacy/server/path'; +import { getConfigPath } from '../../core/server/path'; import logWarnings from '../lib/log_warnings'; import { warnIfUsingPluginDirOption } from '../lib/warn_if_plugin_dir_option'; @@ -50,7 +50,7 @@ export default function pluginRemove(program) { .option( '-c, --config ', 'path to the config file', - getConfig() + getConfigPath() ) .option( '-d, --plugin-dir ', diff --git a/src/cli_plugin/remove/settings.test.js b/src/cli_plugin/remove/settings.test.js index 8cf8ff1d72c5c4..8eb9ed1b129e9c 100644 --- a/src/cli_plugin/remove/settings.test.js +++ b/src/cli_plugin/remove/settings.test.js @@ -17,7 +17,7 @@ * under the License. */ -import { fromRoot } from '../../legacy/utils'; +import { fromRoot } from '../../core/utils'; import { parse } from './settings'; describe('kibana cli', function () { diff --git a/src/core/public/public.api.md b/src/core/public/public.api.md index 16a634b2d32872..623d7bf1642c7d 100644 --- a/src/core/public/public.api.md +++ b/src/core/public/public.api.md @@ -846,7 +846,7 @@ export class SavedObjectsClient { bulkUpdate(objects?: SavedObjectsBulkUpdateObject[]): Promise>; create: (type: string, attributes: T, options?: SavedObjectsCreateOptions) => Promise>; delete: (type: string, id: string) => Promise<{}>; - find: (options: Pick) => Promise>; + find: (options: Pick) => Promise>; get: (type: string, id: string) => Promise>; update(type: string, id: string, attributes: T, { version, migrationVersion, references }?: SavedObjectsUpdateOptions): Promise>; } diff --git a/src/core/server/legacy/__snapshots__/legacy_service.test.ts.snap b/src/core/server/legacy/__snapshots__/legacy_service.test.ts.snap index 9a23b3b3b23b37..69b7f9fc783154 100644 --- a/src/core/server/legacy/__snapshots__/legacy_service.test.ts.snap +++ b/src/core/server/legacy/__snapshots__/legacy_service.test.ts.snap @@ -7,6 +7,7 @@ Array [ "logging": Object { "verbose": true, }, + "path": Object {}, }, ], ] @@ -19,6 +20,7 @@ Array [ "logging": Object { "verbose": true, }, + "path": Object {}, }, ], ] diff --git a/src/core/server/legacy/legacy_service.test.ts b/src/core/server/legacy/legacy_service.test.ts index 030caa8324521c..38a8c9a1a0dea6 100644 --- a/src/core/server/legacy/legacy_service.test.ts +++ b/src/core/server/legacy/legacy_service.test.ts @@ -133,8 +133,8 @@ describe('once LegacyService is set up with connection info', () => { expect(MockKbnServer).toHaveBeenCalledTimes(1); expect(MockKbnServer).toHaveBeenCalledWith( - { server: { autoListen: true } }, - { server: { autoListen: true } }, + { path: { autoListen: true }, server: { autoListen: true } }, + { path: { autoListen: true }, server: { autoListen: true } }, // Because of the mock, path also gets the value expect.any(Object), { disabledPluginSpecs: [], pluginSpecs: [], uiExports: [] } ); @@ -158,8 +158,8 @@ describe('once LegacyService is set up with connection info', () => { expect(MockKbnServer).toHaveBeenCalledTimes(1); expect(MockKbnServer).toHaveBeenCalledWith( - { server: { autoListen: true } }, - { server: { autoListen: true } }, + { path: { autoListen: false }, server: { autoListen: true } }, + { path: { autoListen: false }, server: { autoListen: true } }, expect.any(Object), { disabledPluginSpecs: [], pluginSpecs: [], uiExports: [] } ); @@ -288,8 +288,8 @@ describe('once LegacyService is set up without connection info', () => { test('creates legacy kbnServer with `autoListen: false`.', () => { expect(MockKbnServer).toHaveBeenCalledTimes(1); expect(MockKbnServer).toHaveBeenCalledWith( - { server: { autoListen: true } }, - { server: { autoListen: true } }, + { path: {}, server: { autoListen: true } }, + { path: {}, server: { autoListen: true } }, expect.any(Object), { disabledPluginSpecs: [], pluginSpecs: [], uiExports: [] } ); diff --git a/src/core/server/legacy/legacy_service.ts b/src/core/server/legacy/legacy_service.ts index 99963ad9ce3e89..f4043656c22d8f 100644 --- a/src/core/server/legacy/legacy_service.ts +++ b/src/core/server/legacy/legacy_service.ts @@ -31,6 +31,7 @@ import { Logger } from '../logging'; import { PluginsServiceSetup, PluginsServiceStart } from '../plugins'; import { findLegacyPluginSpecs } from './plugins'; import { LegacyPluginSpec } from './plugins/find_legacy_plugin_specs'; +import { PathConfigType } from '../path'; interface LegacyKbnServer { applyLoggingConfiguration: (settings: Readonly>) => void; @@ -39,7 +40,7 @@ interface LegacyKbnServer { close: () => Promise; } -function getLegacyRawConfig(config: Config) { +function getLegacyRawConfig(config: Config, pathConfig: PathConfigType) { const rawConfig = config.toRaw(); // Elasticsearch config is solely handled by the core and legacy platform @@ -48,7 +49,10 @@ function getLegacyRawConfig(config: Config) { delete rawConfig.elasticsearch; } - return rawConfig; + return { + ...rawConfig, + path: pathConfig, // We rely heavily in the default value of 'path.data' in the legacy world and, since it has been moved to NP, it won't show up in RawConfig + }; } /** @@ -90,7 +94,7 @@ export class LegacyService implements CoreService { private kbnServer?: LegacyKbnServer; private configSubscription?: Subscription; private setupDeps?: LegacyServiceSetupDeps; - private update$: ConnectableObservable | undefined; + private update$: ConnectableObservable<[Config, PathConfigType]> | undefined; private legacyRawConfig: Config | undefined; private legacyPlugins: | { @@ -114,22 +118,25 @@ export class LegacyService implements CoreService { public async setup(setupDeps: LegacyServiceSetupDeps) { this.setupDeps = setupDeps; - this.update$ = this.coreContext.configService.getConfig$().pipe( - tap(config => { + this.update$ = combineLatest( + this.coreContext.configService.getConfig$(), + this.coreContext.configService.atPath('path') + ).pipe( + tap(([config, pathConfig]) => { if (this.kbnServer !== undefined) { - this.kbnServer.applyLoggingConfiguration(getLegacyRawConfig(config)); + this.kbnServer.applyLoggingConfiguration(getLegacyRawConfig(config, pathConfig)); } }), tap({ error: err => this.log.error(err) }), publishReplay(1) - ) as ConnectableObservable; + ) as ConnectableObservable<[Config, PathConfigType]>; this.configSubscription = this.update$.connect(); this.settings = await this.update$ .pipe( first(), - map(config => getLegacyRawConfig(config)) + map(([config, pathConfig]) => getLegacyRawConfig(config, pathConfig)) ) .toPromise(); diff --git a/src/core/server/mocks.ts b/src/core/server/mocks.ts index b03d827d7c4063..42c7466ea7c4e3 100644 --- a/src/core/server/mocks.ts +++ b/src/core/server/mocks.ts @@ -16,14 +16,15 @@ * specific language governing permissions and limitations * under the License. */ -import { of, BehaviorSubject } from 'rxjs'; +import { of } from 'rxjs'; +import { duration } from 'moment'; import { PluginInitializerContext, CoreSetup, CoreStart } from '.'; import { loggingServiceMock } from './logging/logging_service.mock'; import { elasticsearchServiceMock } from './elasticsearch/elasticsearch_service.mock'; import { httpServiceMock } from './http/http_service.mock'; import { contextServiceMock } from './context/context_service.mock'; import { uiSettingsServiceMock } from './ui_settings/ui_settings_service.mock'; -import { ObjectToConfigAdapter } from './config'; +import { SharedGlobalConfig } from './plugins'; export { httpServerMock } from './http/http_server.mocks'; export { sessionStorageMock } from './http/cookie_session_storage.mocks'; @@ -34,9 +35,22 @@ export { loggingServiceMock } from './logging/logging_service.mock'; export { savedObjectsClientMock } from './saved_objects/service/saved_objects_client.mock'; export { uiSettingsServiceMock } from './ui_settings/ui_settings_service.mock'; -export function pluginInitializerContextConfigMock(config: T, globalConfig = {}) { +export function pluginInitializerContextConfigMock(config: T) { + const globalConfig: SharedGlobalConfig = { + kibana: { defaultAppId: 'home-mocks', index: '.kibana-tests' }, + elasticsearch: { + shardTimeout: duration('30s'), + requestTimeout: duration('30s'), + pingTimeout: duration('30s'), + startupTimeout: duration('30s'), + }, + path: { + data: '/tmp', + }, + }; + const mock: jest.Mocked['config']> = { - globalConfig__deprecated$: new BehaviorSubject(new ObjectToConfigAdapter(globalConfig)), + globalConfig__deprecated$: of(globalConfig), create: jest.fn().mockReturnValue(of(config)), createIfExists: jest.fn().mockReturnValue(of(config)), }; diff --git a/src/legacy/server/path/index.test.js b/src/core/server/path.test.ts similarity index 71% rename from src/legacy/server/path/index.test.js rename to src/core/server/path.test.ts index 08d3568cfbbadb..440bcc3f0fac0e 100644 --- a/src/legacy/server/path/index.test.js +++ b/src/core/server/path.test.ts @@ -17,17 +17,17 @@ * under the License. */ -import { getConfig, getData } from './'; -import { accessSync, R_OK } from 'fs'; +import { getConfigPath, getDataPath } from './path'; +import { accessSync, constants } from 'fs'; -describe('Default path finder', function () { +describe('Default path finder', () => { it('should find a kibana.yml', () => { - const configPath = getConfig(); - expect(() => accessSync(configPath, R_OK)).not.toThrow(); + const configPath = getConfigPath(); + expect(() => accessSync(configPath, constants.R_OK)).not.toThrow(); }); it('should find a data directory', () => { - const dataPath = getData(); - expect(() => accessSync(dataPath, R_OK)).not.toThrow(); + const dataPath = getDataPath(); + expect(() => accessSync(dataPath, constants.R_OK)).not.toThrow(); }); }); diff --git a/src/legacy/server/path/index.js b/src/core/server/path.ts similarity index 56% rename from src/legacy/server/path/index.js rename to src/core/server/path.ts index 130ce59694d072..b5af5f9210aa30 100644 --- a/src/legacy/server/path/index.js +++ b/src/core/server/path.ts @@ -18,34 +18,45 @@ */ import { join } from 'path'; -import { accessSync, R_OK } from 'fs'; -import { find } from 'lodash'; -import { fromRoot } from '../../utils'; +import { accessSync, constants } from 'fs'; +import { TypeOf, schema } from '@kbn/config-schema'; +import { fromRoot } from '../utils'; + +const isString = (v: any): v is string => typeof v === 'string'; const CONFIG_PATHS = [ process.env.KIBANA_PATH_CONF && join(process.env.KIBANA_PATH_CONF, 'kibana.yml'), - process.env.CONFIG_PATH, //deprecated + process.env.CONFIG_PATH, // deprecated fromRoot('config/kibana.yml'), - '/etc/kibana/kibana.yml' -].filter(Boolean); + '/etc/kibana/kibana.yml', +].filter(isString); const DATA_PATHS = [ - process.env.DATA_PATH, //deprecated + process.env.DATA_PATH, // deprecated fromRoot('data'), - '/var/lib/kibana' -].filter(Boolean); + '/var/lib/kibana', +].filter(isString); -function findFile(paths) { - const availablePath = find(paths, configPath => { +function findFile(paths: string[]) { + const availablePath = paths.find(configPath => { try { - accessSync(configPath, R_OK); + accessSync(configPath, constants.R_OK); return true; } catch (e) { - //Check the next path + // Check the next path } }); return availablePath || paths[0]; } -export const getConfig = () => findFile(CONFIG_PATHS); -export const getData = () => findFile(DATA_PATHS); +export const getConfigPath = () => findFile(CONFIG_PATHS); +export const getDataPath = () => findFile(DATA_PATHS); + +export type PathConfigType = TypeOf; + +export const config = { + path: 'path', + schema: schema.object({ + data: schema.string({ defaultValue: () => getDataPath() }), + }), +}; diff --git a/src/core/server/plugins/plugin_context.test.ts b/src/core/server/plugins/plugin_context.test.ts index 1f5fccedde50b2..5da5c9e4d9b10b 100644 --- a/src/core/server/plugins/plugin_context.test.ts +++ b/src/core/server/plugins/plugin_context.test.ts @@ -17,21 +17,24 @@ * under the License. */ +import { duration } from 'moment'; +import { BehaviorSubject } from 'rxjs'; +import { first } from 'rxjs/operators'; import { createPluginInitializerContext } from './plugin_context'; import { CoreContext } from '../core_context'; -import { Env } from '../config'; -import { configServiceMock } from '../config/config_service.mock'; +import { Env, ObjectToConfigAdapter } from '../config'; import { loggingServiceMock } from '../logging/logging_service.mock'; import { getEnvOptions } from '../config/__mocks__/env'; import { PluginManifest } from './types'; -import { first } from 'rxjs/operators'; +import { Server } from '../server'; +import { fromRoot } from '../../utils'; const logger = loggingServiceMock.create(); -const configService = configServiceMock.create({ getConfig$: { globalConfig: { subpath: 1 } } }); let coreId: symbol; let env: Env; let coreContext: CoreContext; +let server: Server; function createPluginManifest(manifestProps: Partial = {}): PluginManifest { return { @@ -47,10 +50,13 @@ function createPluginManifest(manifestProps: Partial = {}): Plug }; } -beforeEach(() => { +beforeEach(async () => { coreId = Symbol('core'); env = Env.createDefault(getEnvOptions()); - coreContext = { coreId, env, logger, configService }; + const config$ = new BehaviorSubject(new ObjectToConfigAdapter({})); + server = new Server(config$, env, logger); + await server.setupConfigSchemas(); + coreContext = { coreId, env, logger, configService: server.configService }; }); test('should return a globalConfig handler in the context (to be deprecated)', async () => { @@ -63,10 +69,14 @@ test('should return a globalConfig handler in the context (to be deprecated)', a const configObject = await pluginInitializerContext.config.globalConfig__deprecated$ .pipe(first()) .toPromise(); - - const configPaths = configObject.getFlattenedPaths(); - expect(configPaths).toHaveLength(1); - expect(configPaths).toStrictEqual(['globalConfig.subpath']); - expect(configObject.has('globalConfig.subpath')).toBe(true); - expect(configObject.get('globalConfig.subpath')).toBe(1); + expect(configObject).toStrictEqual({ + kibana: { defaultAppId: 'home', index: '.kibana' }, + elasticsearch: { + shardTimeout: duration(30, 's'), + requestTimeout: duration(30, 's'), + pingTimeout: duration(30, 's'), + startupTimeout: duration(5, 's'), + }, + path: { data: fromRoot('data') }, + }); }); diff --git a/src/core/server/plugins/plugin_context.ts b/src/core/server/plugins/plugin_context.ts index 65e5bdb4f766c8..2b287c09d34b9a 100644 --- a/src/core/server/plugins/plugin_context.ts +++ b/src/core/server/plugins/plugin_context.ts @@ -18,11 +18,24 @@ */ import { map } from 'rxjs/operators'; +import { zip } from 'rxjs'; import { CoreContext } from '../core_context'; import { PluginWrapper } from './plugin'; import { PluginsServiceSetupDeps, PluginsServiceStartDeps } from './plugins_service'; -import { PluginInitializerContext, PluginManifest, PluginOpaqueId } from './types'; -import { CoreSetup, CoreStart, ConfigPath } from '..'; +import { + PluginInitializerContext, + PluginManifest, + PluginOpaqueId, + SharedGlobalConfigKeys, +} from './types'; +import { PathConfigType, config as pathConfig } from '../path'; +import { KibanaConfigType, config as kibanaConfig } from '../kibana_config'; +import { + ElasticsearchConfigType, + config as elasticsearchConfig, +} from '../elasticsearch/elasticsearch_config'; +import { pick } from '../../utils'; +import { CoreSetup, CoreStart } from '..'; /** * This returns a facade for `CoreContext` that will be exposed to the plugin initializer. @@ -71,11 +84,15 @@ export function createPluginInitializerContext( * Note: naming not final here, it will be renamed in a near future (https://github.com/elastic/kibana/issues/46240) * @deprecated */ - globalConfig__deprecated$: coreContext.configService.getConfig$().pipe( - map(conf => ({ - has: (configPath: ConfigPath) => conf.has(configPath), - get: (configPath: ConfigPath) => conf.get(configPath), - getFlattenedPaths: () => conf.getFlattenedPaths(), + globalConfig__deprecated$: zip( + coreContext.configService.atPath(kibanaConfig.path), + coreContext.configService.atPath(elasticsearchConfig.path), + coreContext.configService.atPath(pathConfig.path) + ).pipe( + map(([kibana, elasticsearch, path]) => ({ + kibana: pick(kibana, SharedGlobalConfigKeys.kibana), + elasticsearch: pick(elasticsearch, SharedGlobalConfigKeys.elasticsearch), + path: pick(path, SharedGlobalConfigKeys.path), })) ), @@ -96,8 +113,6 @@ export function createPluginInitializerContext( }; } -// function exposeReadOnlyMethods(conf: ) - /** * This returns a facade for `CoreContext` that will be exposed to the plugin `setup` method. * This facade should be safe to use only within `setup` itself. diff --git a/src/core/server/plugins/plugins_service.test.mocks.ts b/src/core/server/plugins/plugins_service.test.mocks.ts index 13b492e382d676..3ec518e4663542 100644 --- a/src/core/server/plugins/plugins_service.test.mocks.ts +++ b/src/core/server/plugins/plugins_service.test.mocks.ts @@ -17,8 +17,11 @@ * under the License. */ -export const mockPackage = new Proxy({ raw: {} as any }, { get: (obj, prop) => obj.raw[prop] }); -jest.mock('../../../legacy/utils/package_json', () => ({ pkg: mockPackage })); +export const mockPackage = new Proxy( + { raw: { __dirname: '/tmp' } as any }, + { get: (obj, prop) => obj.raw[prop] } +); +jest.mock('../../../core/utils/package_json', () => ({ pkg: mockPackage })); export const mockDiscover = jest.fn(); jest.mock('./discovery/plugins_discovery', () => ({ discover: mockDiscover })); diff --git a/src/core/server/plugins/types.ts b/src/core/server/plugins/types.ts index 4c5068aa62bafd..b71468ed1b1029 100644 --- a/src/core/server/plugins/types.ts +++ b/src/core/server/plugins/types.ts @@ -20,8 +20,12 @@ import { Observable } from 'rxjs'; import { Type } from '@kbn/config-schema'; -import { ConfigPath, EnvironmentMode, PackageInfo, Config } from '../config'; +import { RecursiveReadonly } from 'kibana/public'; +import { ConfigPath, EnvironmentMode, PackageInfo } from '../config'; import { LoggerFactory } from '../logging'; +import { KibanaConfigType } from '../kibana_config'; +import { ElasticsearchConfigType } from '../elasticsearch/elasticsearch_config'; +import { PathConfigType } from '../path'; import { CoreSetup, CoreStart } from '..'; /** @@ -195,6 +199,19 @@ export interface Plugin< stop?(): void; } +export const SharedGlobalConfigKeys = { + // We can add more if really needed + kibana: ['defaultAppId', 'index'] as const, + elasticsearch: ['shardTimeout', 'requestTimeout', 'pingTimeout', 'startupTimeout'] as const, + path: ['data'] as const, +}; + +export type SharedGlobalConfig = RecursiveReadonly<{ + kibana: Pick; + elasticsearch: Pick; + path: Pick; +}>; + /** * Context that's available to plugins during initialization stage. * @@ -208,7 +225,7 @@ export interface PluginInitializerContext { }; logger: LoggerFactory; config: { - globalConfig__deprecated$: Observable>; + globalConfig__deprecated$: Observable; create: () => Observable; createIfExists: () => Observable; }; diff --git a/src/core/server/server.api.md b/src/core/server/server.api.md index 5b2dc2ea12e624..1fe45a38205db2 100644 --- a/src/core/server/server.api.md +++ b/src/core/server/server.api.md @@ -109,6 +109,7 @@ import { PingParams } from 'elasticsearch'; import { PutScriptParams } from 'elasticsearch'; import { PutTemplateParams } from 'elasticsearch'; import { Readable } from 'stream'; +import { RecursiveReadonly as RecursiveReadonly_2 } from 'kibana/public'; import { ReindexParams } from 'elasticsearch'; import { ReindexRethrottleParams } from 'elasticsearch'; import { RenderSearchTemplateParams } from 'elasticsearch'; @@ -978,7 +979,7 @@ export type PluginInitializer { // (undocumented) config: { - globalConfig__deprecated$: Observable>; + globalConfig__deprecated$: Observable; create: () => Observable; createIfExists: () => Observable; }; @@ -1633,5 +1634,6 @@ export interface UserProvidedValues { // // src/core/server/http/router/response.ts:316:3 - (ae-forgotten-export) The symbol "KibanaResponse" needs to be exported by the entry point index.d.ts // src/core/server/plugins/plugins_service.ts:43:5 - (ae-forgotten-export) The symbol "InternalPluginInfo" needs to be exported by the entry point index.d.ts +// src/core/server/plugins/types.ts:228:5 - (ae-forgotten-export) The symbol "SharedGlobalConfig" needs to be exported by the entry point index.d.ts ``` diff --git a/src/core/server/server.ts b/src/core/server/server.ts index 6c38de03f0f2d3..79daaa76243a8a 100644 --- a/src/core/server/server.ts +++ b/src/core/server/server.ts @@ -33,6 +33,7 @@ import { config as elasticsearchConfig } from './elasticsearch'; import { config as httpConfig } from './http'; import { config as loggingConfig } from './logging'; import { config as devConfig } from './dev'; +import { config as pathConfig } from './path'; import { config as kibanaConfig } from './kibana_config'; import { config as savedObjectsConfig } from './saved_objects'; import { config as uiSettingsConfig } from './ui_settings'; @@ -196,6 +197,7 @@ export class Server { public async setupConfigSchemas() { const schemas: Array<[ConfigPath, Type]> = [ + [pathConfig.path, pathConfig.schema], [elasticsearchConfig.path, elasticsearchConfig.schema], [loggingConfig.path, loggingConfig.schema], [httpConfig.path, httpConfig.schema], diff --git a/src/legacy/utils/from_root.ts b/src/core/utils/from_root.ts similarity index 100% rename from src/legacy/utils/from_root.ts rename to src/core/utils/from_root.ts diff --git a/src/core/utils/index.ts b/src/core/utils/index.ts index 98f0800feae79a..906d0a0e6db399 100644 --- a/src/core/utils/index.ts +++ b/src/core/utils/index.ts @@ -20,8 +20,10 @@ export * from './assert_never'; export * from './context'; export * from './deep_freeze'; +export * from './from_root'; export * from './get'; export * from './map_to_object'; export * from './merge'; +export * from './package_json'; export * from './pick'; export * from './url'; diff --git a/src/legacy/utils/package_json.ts b/src/core/utils/package_json.ts similarity index 100% rename from src/legacy/utils/package_json.ts rename to src/core/utils/package_json.ts diff --git a/src/core/utils/pick.ts b/src/core/utils/pick.ts index 08288343d90778..24801774727f25 100644 --- a/src/core/utils/pick.ts +++ b/src/core/utils/pick.ts @@ -17,7 +17,7 @@ * under the License. */ -export function pick(obj: T, keys: K[]): Pick { +export function pick(obj: T, keys: readonly K[]): Pick { return keys.reduce((acc, key) => { if (obj.hasOwnProperty(key)) { acc[key] = obj[key]; diff --git a/src/legacy/core_plugins/telemetry/index.ts b/src/legacy/core_plugins/telemetry/index.ts index 5ae0d5f127eeda..9e81b923da1128 100644 --- a/src/legacy/core_plugins/telemetry/index.ts +++ b/src/legacy/core_plugins/telemetry/index.ts @@ -23,6 +23,8 @@ import JoiNamespace from 'joi'; import { Server } from 'hapi'; import { CoreSetup, PluginInitializerContext } from 'src/core/server'; import { i18n } from '@kbn/i18n'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths +import { getConfigPath } from '../../../core/server/path'; // @ts-ignore import mappings from './mappings.json'; import { CONFIG_TELEMETRY, getConfigTelemetryDesc } from './common/constants'; @@ -54,7 +56,7 @@ const telemetry = (kibana: any) => { otherwise: Joi.boolean().default(true), }), // `config` is used internally and not intended to be set - config: Joi.string().default(Joi.ref('$defaultConfigPath')), + config: Joi.string().default(getConfigPath()), banner: Joi.boolean().default(true), url: Joi.when('$dev', { is: true, diff --git a/src/legacy/core_plugins/tests_bundle/find_source_files.js b/src/legacy/core_plugins/tests_bundle/find_source_files.js index eb5b4f50e4e85b..261aa9c1f73674 100644 --- a/src/legacy/core_plugins/tests_bundle/find_source_files.js +++ b/src/legacy/core_plugins/tests_bundle/find_source_files.js @@ -18,7 +18,7 @@ */ -import { fromRoot } from '../../../legacy/utils'; +import { fromRoot } from '../../../core/utils'; import { chain } from 'lodash'; import { resolve } from 'path'; import { fromNode } from 'bluebird'; diff --git a/src/legacy/core_plugins/tests_bundle/index.js b/src/legacy/core_plugins/tests_bundle/index.js index 803fe1d220f44f..b22fa8bf085d41 100644 --- a/src/legacy/core_plugins/tests_bundle/index.js +++ b/src/legacy/core_plugins/tests_bundle/index.js @@ -23,7 +23,7 @@ import globby from 'globby'; import MultiStream from 'multistream'; import webpackMerge from 'webpack-merge'; -import { fromRoot } from '../../../legacy/utils'; +import { fromRoot } from '../../../core/utils'; import { replacePlaceholder } from '../../../optimize/public_path_placeholder'; import findSourceFiles from './find_source_files'; import { createTestEntryTemplate } from './tests_entry_template'; diff --git a/src/legacy/server/config/config.js b/src/legacy/server/config/config.js index e871a20ee8b981..05e2996a213c61 100644 --- a/src/legacy/server/config/config.js +++ b/src/legacy/server/config/config.js @@ -21,8 +21,8 @@ import Joi from 'joi'; import _ from 'lodash'; import override from './override'; import createDefaultSchema from './schema'; -import { getConfig } from '../path'; -import { pkg, unset, deepCloneWithBuffers as clone, IS_KIBANA_DISTRIBUTABLE } from '../../utils'; +import { unset, deepCloneWithBuffers as clone, IS_KIBANA_DISTRIBUTABLE } from '../../utils'; +import { pkg } from '../../../core/utils'; const schema = Symbol('Joi Schema'); const schemaExts = Symbol('Schema Extensions'); @@ -111,7 +111,6 @@ export class Config { buildNum: IS_KIBANA_DISTRIBUTABLE ? pkg.build.number : Number.MAX_SAFE_INTEGER, buildSha: IS_KIBANA_DISTRIBUTABLE ? pkg.build.sha : 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', dist: IS_KIBANA_DISTRIBUTABLE, - defaultConfigPath: getConfig(), }; if (!context.dev && !context.prod) { diff --git a/src/legacy/server/config/schema.js b/src/legacy/server/config/schema.js index 3f9b897730f51c..b76e468776cf21 100644 --- a/src/legacy/server/config/schema.js +++ b/src/legacy/server/config/schema.js @@ -20,9 +20,8 @@ import Joi from 'joi'; import os from 'os'; import { join } from 'path'; -import { - getData -} from '../path'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths +import { getDataPath } from '../../../core/server/path'; // Still used by optimize config schema import { DEFAULT_CSP_RULES, DEFAULT_CSP_STRICT, @@ -148,9 +147,7 @@ export default () => Joi.object({ initialize: Joi.boolean().default(true) }).default(), - path: Joi.object({ - data: Joi.string().default(getData()) - }).default(), + path: HANDLED_IN_NEW_PLATFORM, stats: Joi.object({ maximumWaitTimeForAllCollectorsInS: Joi.number().default(60) @@ -159,7 +156,7 @@ export default () => Joi.object({ optimize: Joi.object({ enabled: Joi.boolean().default(true), bundleFilter: Joi.string().default('!tests'), - bundleDir: Joi.string().default(join(getData(), 'optimize')), + bundleDir: Joi.string().default(join(getDataPath(), 'optimize')), viewCaching: Joi.boolean().default(Joi.ref('$prod')), watch: Joi.boolean().default(false), watchPort: Joi.number().default(5602), diff --git a/src/legacy/server/i18n/index.js b/src/legacy/server/i18n/index.js index ce01d07576f28c..efae956c5f2f74 100644 --- a/src/legacy/server/i18n/index.js +++ b/src/legacy/server/i18n/index.js @@ -19,7 +19,7 @@ import { i18n, i18nLoader } from '@kbn/i18n'; import { basename } from 'path'; -import { fromRoot } from '../../utils'; +import { fromRoot } from '../../../core/utils'; import { getTranslationPaths } from './get_translations_path'; import { I18N_RC } from './constants'; diff --git a/src/legacy/server/kbn_server.js b/src/legacy/server/kbn_server.js index f7ed56b10c267a..1a0ef52d2bdcaa 100644 --- a/src/legacy/server/kbn_server.js +++ b/src/legacy/server/kbn_server.js @@ -21,7 +21,7 @@ import { constant, once, compact, flatten } from 'lodash'; import { isWorker } from 'cluster'; -import { fromRoot, pkg } from '../utils'; +import { fromRoot, pkg } from '../../core/utils'; import { Config } from './config'; import loggingConfiguration from './logging/configuration'; import httpMixin from './http'; diff --git a/src/legacy/server/sass/index.js b/src/legacy/server/sass/index.js index 7bd7c79d34fe69..0dfa72281e6470 100644 --- a/src/legacy/server/sass/index.js +++ b/src/legacy/server/sass/index.js @@ -17,7 +17,8 @@ * under the License. */ -import { IS_KIBANA_DISTRIBUTABLE, fromRoot } from '../../utils'; +import { IS_KIBANA_DISTRIBUTABLE } from '../../utils'; +import { fromRoot } from '../../../core/utils'; export async function sassMixin(kbnServer, server, config) { if (process.env.kbnWorkerType === 'optmzr') { diff --git a/src/legacy/server/status/server_status.js b/src/legacy/server/status/server_status.js index 162ddf92310fe5..3a16af879c48f1 100644 --- a/src/legacy/server/status/server_status.js +++ b/src/legacy/server/status/server_status.js @@ -21,7 +21,7 @@ import _ from 'lodash'; import * as states from './states'; import Status from './status'; -import { pkg } from '../../utils/package_json'; +import { pkg } from '../../../core/utils'; export default class ServerStatus { constructor(server) { diff --git a/src/legacy/ui/ui_bundles/ui_bundles_controller.js b/src/legacy/ui/ui_bundles/ui_bundles_controller.js index 2e6436b370fbe8..3e233dbc3da409 100644 --- a/src/legacy/ui/ui_bundles/ui_bundles_controller.js +++ b/src/legacy/ui/ui_bundles/ui_bundles_controller.js @@ -26,7 +26,8 @@ import del from 'del'; import { makeRe } from 'minimatch'; import jsonStableStringify from 'json-stable-stringify'; -import { IS_KIBANA_DISTRIBUTABLE, fromRoot } from '../../utils'; +import { IS_KIBANA_DISTRIBUTABLE } from '../../utils'; +import { fromRoot } from '../../../core/utils'; import { UiBundle } from './ui_bundle'; import { appEntryTemplate } from './app_entry_template'; diff --git a/src/legacy/ui/ui_render/ui_render_mixin.js b/src/legacy/ui/ui_render/ui_render_mixin.js index 763167c6b5ccf4..da7d154e7d3414 100644 --- a/src/legacy/ui/ui_render/ui_render_mixin.js +++ b/src/legacy/ui/ui_render/ui_render_mixin.js @@ -26,7 +26,7 @@ import { get } from 'lodash'; import { i18n } from '@kbn/i18n'; import { AppBootstrap } from './bootstrap'; import { mergeVariables } from './lib'; -import { fromRoot } from '../../utils'; +import { fromRoot } from '../../../core/utils'; import { createCSPRuleString } from '../../server/csp'; export function uiRenderMixin(kbnServer, server, config) { diff --git a/src/legacy/utils/artifact_type.ts b/src/legacy/utils/artifact_type.ts index c5d8b78eb49551..d43fdf79639e62 100644 --- a/src/legacy/utils/artifact_type.ts +++ b/src/legacy/utils/artifact_type.ts @@ -17,7 +17,7 @@ * under the License. */ -import { pkg } from './package_json'; +import { pkg } from '../../core/utils'; export const IS_KIBANA_DISTRIBUTABLE = pkg.build && pkg.build.distributable === true; export const IS_KIBANA_RELEASE = pkg.build && pkg.build.release === true; diff --git a/src/legacy/utils/index.js b/src/legacy/utils/index.js index a34c691f9578a0..fca3ea56a99483 100644 --- a/src/legacy/utils/index.js +++ b/src/legacy/utils/index.js @@ -20,8 +20,6 @@ export { BinderBase } from './binder'; export { BinderFor } from './binder_for'; export { deepCloneWithBuffers } from './deep_clone_with_buffers'; -export { fromRoot } from './from_root'; -export { pkg } from './package_json'; export { unset } from './unset'; export { encodeQueryComponent } from './encode_query_component'; export { getFlattenedObject } from './get_flattened_object'; diff --git a/src/optimize/base_optimizer.js b/src/optimize/base_optimizer.js index 2eaf4c1d6e8828..c44cbbed139074 100644 --- a/src/optimize/base_optimizer.js +++ b/src/optimize/base_optimizer.js @@ -31,7 +31,8 @@ import WrapperPlugin from 'wrapper-webpack-plugin'; import { defaults } from 'lodash'; -import { IS_KIBANA_DISTRIBUTABLE, fromRoot } from '../legacy/utils'; +import { IS_KIBANA_DISTRIBUTABLE } from '../legacy/utils'; +import { fromRoot } from '../core/utils'; import { PUBLIC_PATH_PLACEHOLDER } from './public_path_placeholder'; diff --git a/src/optimize/dynamic_dll_plugin/dll_compiler.js b/src/optimize/dynamic_dll_plugin/dll_compiler.js index 3f3bb3e4e196c7..0c2d363530889a 100644 --- a/src/optimize/dynamic_dll_plugin/dll_compiler.js +++ b/src/optimize/dynamic_dll_plugin/dll_compiler.js @@ -19,7 +19,7 @@ import { configModel } from './dll_config_model'; import { notInNodeModulesOrWebpackShims, notInNodeModules, inDllPluginPublic } from './dll_allowed_modules'; -import { fromRoot } from '../../legacy/utils'; +import { fromRoot } from '../../core/utils'; import { PUBLIC_PATH_PLACEHOLDER } from '../public_path_placeholder'; import fs from 'fs'; import webpack from 'webpack'; diff --git a/src/optimize/dynamic_dll_plugin/dll_config_model.js b/src/optimize/dynamic_dll_plugin/dll_config_model.js index cb1f9be9b16c95..8daf528fc4536d 100644 --- a/src/optimize/dynamic_dll_plugin/dll_config_model.js +++ b/src/optimize/dynamic_dll_plugin/dll_config_model.js @@ -17,7 +17,8 @@ * under the License. */ -import { fromRoot, IS_KIBANA_DISTRIBUTABLE } from '../../legacy/utils'; +import { IS_KIBANA_DISTRIBUTABLE } from '../../legacy/utils'; +import { fromRoot } from '../../core/utils'; import webpack from 'webpack'; import webpackMerge from 'webpack-merge'; import MiniCssExtractPlugin from 'mini-css-extract-plugin'; diff --git a/src/optimize/index.js b/src/optimize/index.js index 0960f9ecb10b6d..94309e67c2c8e8 100644 --- a/src/optimize/index.js +++ b/src/optimize/index.js @@ -20,7 +20,7 @@ import FsOptimizer from './fs_optimizer'; import { createBundlesRoute } from './bundles_route'; import { DllCompiler } from './dynamic_dll_plugin'; -import { fromRoot } from '../legacy/utils'; +import { fromRoot } from '../core/utils'; export default async (kbnServer, server, config) => { if (!config.get('optimize.enabled')) return; diff --git a/src/optimize/watch/watch_optimizer.js b/src/optimize/watch/watch_optimizer.js index 159ba68a6aaba8..331ca41250a29f 100644 --- a/src/optimize/watch/watch_optimizer.js +++ b/src/optimize/watch/watch_optimizer.js @@ -20,7 +20,7 @@ import BaseOptimizer from '../base_optimizer'; import { createBundlesRoute } from '../bundles_route'; import { DllCompiler } from '../dynamic_dll_plugin'; -import { fromRoot } from '../../legacy/utils'; +import { fromRoot } from '../../core/utils'; import * as Rx from 'rxjs'; import { mergeMap, take } from 'rxjs/operators'; diff --git a/test/visual_regression/services/visual_testing/visual_testing.ts b/test/visual_regression/services/visual_testing/visual_testing.ts index bc9ded352faf8f..8ac80ffe0398d9 100644 --- a/test/visual_regression/services/visual_testing/visual_testing.ts +++ b/test/visual_regression/services/visual_testing/visual_testing.ts @@ -23,7 +23,7 @@ import _ from 'lodash'; import testSubjSelector from '@kbn/test-subj-selector'; -import { pkg } from '../../../../src/legacy/utils/package_json'; +import { pkg } from 'src/core/utils'; import { FtrProviderContext } from '../../ftr_provider_context'; // @ts-ignore internal js that is passed to the browser as is From 592e9350fe36899b96cc279707739c4473759cd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Ferna=CC=81ndez=20Haro?= Date: Wed, 27 Nov 2019 15:42:31 +0000 Subject: [PATCH 04/21] Updated API docs --- ...a-plugin-public.savedobjectsclient.find.md | 26 +- ...kibana-plugin-public.savedobjectsclient.md | 72 +- src/core/public/public.api.md | 2068 ++++++++--------- 3 files changed, 1083 insertions(+), 1083 deletions(-) diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsclient.find.md b/docs/development/core/public/kibana-plugin-public.savedobjectsclient.find.md index 4ce0b73a31b7ba..1ce18834f53196 100644 --- a/docs/development/core/public/kibana-plugin-public.savedobjectsclient.find.md +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsclient.find.md @@ -1,13 +1,13 @@ - - -[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObjectsClient](./kibana-plugin-public.savedobjectsclient.md) > [find](./kibana-plugin-public.savedobjectsclient.find.md) - -## SavedObjectsClient.find property - -Search for objects - -Signature: - -```typescript -find: (options: Pick) => Promise>; -``` + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObjectsClient](./kibana-plugin-public.savedobjectsclient.md) > [find](./kibana-plugin-public.savedobjectsclient.find.md) + +## SavedObjectsClient.find property + +Search for objects + +Signature: + +```typescript +find: (options: Pick) => Promise>; +``` diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsclient.md b/docs/development/core/public/kibana-plugin-public.savedobjectsclient.md index 27c80fdcc9c344..6033c667c1866c 100644 --- a/docs/development/core/public/kibana-plugin-public.savedobjectsclient.md +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsclient.md @@ -1,36 +1,36 @@ - - -[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObjectsClient](./kibana-plugin-public.savedobjectsclient.md) - -## SavedObjectsClient class - -Saved Objects is Kibana's data persisentence mechanism allowing plugins to use Elasticsearch for storing plugin state. The client-side SavedObjectsClient is a thin convenience library around the SavedObjects HTTP API for interacting with Saved Objects. - -Signature: - -```typescript -export declare class SavedObjectsClient -``` - -## Properties - -| Property | Modifiers | Type | Description | -| --- | --- | --- | --- | -| [bulkCreate](./kibana-plugin-public.savedobjectsclient.bulkcreate.md) | | (objects?: SavedObjectsBulkCreateObject<SavedObjectAttributes>[], options?: SavedObjectsBulkCreateOptions) => Promise<SavedObjectsBatchResponse<SavedObjectAttributes>> | Creates multiple documents at once | -| [bulkGet](./kibana-plugin-public.savedobjectsclient.bulkget.md) | | (objects?: {
id: string;
type: string;
}[]) => Promise<SavedObjectsBatchResponse<SavedObjectAttributes>> | Returns an array of objects by id | -| [create](./kibana-plugin-public.savedobjectsclient.create.md) | | <T extends SavedObjectAttributes>(type: string, attributes: T, options?: SavedObjectsCreateOptions) => Promise<SimpleSavedObject<T>> | Persists an object | -| [delete](./kibana-plugin-public.savedobjectsclient.delete.md) | | (type: string, id: string) => Promise<{}> | Deletes an object | -| [find](./kibana-plugin-public.savedobjectsclient.find.md) | | <T extends SavedObjectAttributes>(options: Pick<SavedObjectFindOptionsServer, "search" | "filter" | "type" | "fields" | "searchFields" | "defaultSearchOperator" | "hasReference" | "sortField" | "page" | "perPage">) => Promise<SavedObjectsFindResponsePublic<T>> | Search for objects | -| [get](./kibana-plugin-public.savedobjectsclient.get.md) | | <T extends SavedObjectAttributes>(type: string, id: string) => Promise<SimpleSavedObject<T>> | Fetches a single object | - -## Methods - -| Method | Modifiers | Description | -| --- | --- | --- | -| [bulkUpdate(objects)](./kibana-plugin-public.savedobjectsclient.bulkupdate.md) | | Update multiple documents at once | -| [update(type, id, attributes, { version, migrationVersion, references })](./kibana-plugin-public.savedobjectsclient.update.md) | | Updates an object | - -## Remarks - -The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the `SavedObjectsClient` class. - + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObjectsClient](./kibana-plugin-public.savedobjectsclient.md) + +## SavedObjectsClient class + +Saved Objects is Kibana's data persisentence mechanism allowing plugins to use Elasticsearch for storing plugin state. The client-side SavedObjectsClient is a thin convenience library around the SavedObjects HTTP API for interacting with Saved Objects. + +Signature: + +```typescript +export declare class SavedObjectsClient +``` + +## Properties + +| Property | Modifiers | Type | Description | +| --- | --- | --- | --- | +| [bulkCreate](./kibana-plugin-public.savedobjectsclient.bulkcreate.md) | | (objects?: SavedObjectsBulkCreateObject<SavedObjectAttributes>[], options?: SavedObjectsBulkCreateOptions) => Promise<SavedObjectsBatchResponse<SavedObjectAttributes>> | Creates multiple documents at once | +| [bulkGet](./kibana-plugin-public.savedobjectsclient.bulkget.md) | | (objects?: {
id: string;
type: string;
}[]) => Promise<SavedObjectsBatchResponse<SavedObjectAttributes>> | Returns an array of objects by id | +| [create](./kibana-plugin-public.savedobjectsclient.create.md) | | <T extends SavedObjectAttributes>(type: string, attributes: T, options?: SavedObjectsCreateOptions) => Promise<SimpleSavedObject<T>> | Persists an object | +| [delete](./kibana-plugin-public.savedobjectsclient.delete.md) | | (type: string, id: string) => Promise<{}> | Deletes an object | +| [find](./kibana-plugin-public.savedobjectsclient.find.md) | | <T extends SavedObjectAttributes>(options: Pick<SavedObjectFindOptionsServer, "search" | "filter" | "type" | "page" | "fields" | "searchFields" | "defaultSearchOperator" | "hasReference" | "sortField" | "perPage">) => Promise<SavedObjectsFindResponsePublic<T>> | Search for objects | +| [get](./kibana-plugin-public.savedobjectsclient.get.md) | | <T extends SavedObjectAttributes>(type: string, id: string) => Promise<SimpleSavedObject<T>> | Fetches a single object | + +## Methods + +| Method | Modifiers | Description | +| --- | --- | --- | +| [bulkUpdate(objects)](./kibana-plugin-public.savedobjectsclient.bulkupdate.md) | | Update multiple documents at once | +| [update(type, id, attributes, { version, migrationVersion, references })](./kibana-plugin-public.savedobjectsclient.update.md) | | Updates an object | + +## Remarks + +The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the `SavedObjectsClient` class. + diff --git a/src/core/public/public.api.md b/src/core/public/public.api.md index 641c333c50497f..01e4f3c78ac4ea 100644 --- a/src/core/public/public.api.md +++ b/src/core/public/public.api.md @@ -1,1034 +1,1034 @@ -## API Report File for "kibana" - -> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). - -```ts - -import { Breadcrumb } from '@elastic/eui'; -import { EuiButtonEmptyProps } from '@elastic/eui'; -import { EuiGlobalToastListToast } from '@elastic/eui'; -import { ExclusiveUnion } from '@elastic/eui'; -import { IconType } from '@elastic/eui'; -import { Observable } from 'rxjs'; -import React from 'react'; -import * as Rx from 'rxjs'; -import { ShallowPromise } from '@kbn/utility-types'; -import { UiSettingsParams as UiSettingsParams_2 } from 'src/core/server/types'; -import { UserProvidedValues as UserProvidedValues_2 } from 'src/core/server/types'; - -// @public -export interface App extends AppBase { - chromeless?: boolean; - mount: (context: AppMountContext, params: AppMountParameters) => AppUnmount | Promise; -} - -// @public (undocumented) -export interface AppBase { - capabilities?: Partial; - euiIconType?: string; - icon?: string; - // (undocumented) - id: string; - order?: number; - title: string; - tooltip$?: Observable; -} - -// @public (undocumented) -export interface ApplicationSetup { - register(app: App): void; - registerMountContext(contextName: T, provider: IContextProvider): void; -} - -// @public (undocumented) -export interface ApplicationStart { - capabilities: RecursiveReadonly; - getUrlForApp(appId: string, options?: { - path?: string; - }): string; - navigateToApp(appId: string, options?: { - path?: string; - state?: any; - }): void; - registerMountContext(contextName: T, provider: IContextProvider): void; -} - -// @public -export interface AppMountContext { - core: { - application: Pick; - chrome: ChromeStart; - docLinks: DocLinksStart; - http: HttpStart; - i18n: I18nStart; - notifications: NotificationsStart; - overlays: OverlayStart; - uiSettings: UiSettingsClientContract; - injectedMetadata: { - getInjectedVar: (name: string, defaultValue?: any) => unknown; - }; - }; -} - -// @public (undocumented) -export interface AppMountParameters { - appBasePath: string; - element: HTMLElement; -} - -// @public -export type AppUnmount = () => void; - -// @public -export interface Capabilities { - [key: string]: Record>; - catalogue: Record; - management: { - [sectionId: string]: Record; - }; - navLinks: Record; -} - -// @public (undocumented) -export interface ChromeBadge { - // (undocumented) - iconType?: IconType; - // (undocumented) - text: string; - // (undocumented) - tooltip: string; -} - -// @public (undocumented) -export interface ChromeBrand { - // (undocumented) - logo?: string; - // (undocumented) - smallLogo?: string; -} - -// @public (undocumented) -export type ChromeBreadcrumb = Breadcrumb; - -// @public -export interface ChromeDocTitle { - // @internal (undocumented) - __legacy: { - setBaseTitle(baseTitle: string): void; - }; - change(newTitle: string | string[]): void; - reset(): void; -} - -// @public (undocumented) -export interface ChromeHelpExtension { - appName: string; - content?: (element: HTMLDivElement) => () => void; - links?: ChromeHelpExtensionMenuLink[]; -} - -// @public (undocumented) -export type ChromeHelpExtensionMenuCustomLink = EuiButtonEmptyProps & { - linkType: 'custom'; - content: React.ReactNode; -}; - -// @public (undocumented) -export type ChromeHelpExtensionMenuDiscussLink = EuiButtonEmptyProps & { - linkType: 'discuss'; - href: string; -}; - -// @public (undocumented) -export type ChromeHelpExtensionMenuDocumentationLink = EuiButtonEmptyProps & { - linkType: 'documentation'; - href: string; -}; - -// @public (undocumented) -export type ChromeHelpExtensionMenuGitHubLink = EuiButtonEmptyProps & { - linkType: 'github'; - labels: string[]; - title?: string; -}; - -// @public (undocumented) -export type ChromeHelpExtensionMenuLink = ExclusiveUnion>>; - -// @public (undocumented) -export interface ChromeNavControl { - // (undocumented) - mount: MountPoint; - // (undocumented) - order?: number; -} - -// @public -export interface ChromeNavControls { - // @internal (undocumented) - getLeft$(): Observable; - // @internal (undocumented) - getRight$(): Observable; - registerLeft(navControl: ChromeNavControl): void; - registerRight(navControl: ChromeNavControl): void; -} - -// @public (undocumented) -export interface ChromeNavLink { - // @deprecated - readonly active?: boolean; - readonly baseUrl: string; - // @deprecated - readonly disabled?: boolean; - readonly euiIconType?: string; - readonly hidden?: boolean; - readonly icon?: string; - readonly id: string; - // @internal - readonly legacy: boolean; - // @deprecated - readonly linkToLastSubUrl?: boolean; - readonly order?: number; - // @deprecated - readonly subUrlBase?: string; - readonly title: string; - readonly tooltip?: string; - // @deprecated - readonly url?: string; -} - -// @public -export interface ChromeNavLinks { - enableForcedAppSwitcherNavigation(): void; - get(id: string): ChromeNavLink | undefined; - getAll(): Array>; - getForceAppSwitcherNavigation$(): Observable; - getNavLinks$(): Observable>>; - has(id: string): boolean; - showOnly(id: string): void; - update(id: string, values: ChromeNavLinkUpdateableFields): ChromeNavLink | undefined; -} - -// @public (undocumented) -export type ChromeNavLinkUpdateableFields = Partial>; - -// @public -export interface ChromeRecentlyAccessed { - // Warning: (ae-unresolved-link) The @link reference could not be resolved: No member was found with name "basePath" - add(link: string, label: string, id: string): void; - get$(): Observable; - get(): ChromeRecentlyAccessedHistoryItem[]; -} - -// @public (undocumented) -export interface ChromeRecentlyAccessedHistoryItem { - // (undocumented) - id: string; - // (undocumented) - label: string; - // (undocumented) - link: string; -} - -// @public -export interface ChromeStart { - addApplicationClass(className: string): void; - docTitle: ChromeDocTitle; - getApplicationClasses$(): Observable; - getBadge$(): Observable; - getBrand$(): Observable; - getBreadcrumbs$(): Observable; - getHelpExtension$(): Observable; - getIsCollapsed$(): Observable; - getIsVisible$(): Observable; - navControls: ChromeNavControls; - navLinks: ChromeNavLinks; - recentlyAccessed: ChromeRecentlyAccessed; - removeApplicationClass(className: string): void; - setAppTitle(appTitle: string): void; - setBadge(badge?: ChromeBadge): void; - setBrand(brand: ChromeBrand): void; - setBreadcrumbs(newBreadcrumbs: ChromeBreadcrumb[]): void; - setHelpExtension(helpExtension?: ChromeHelpExtension): void; - setIsCollapsed(isCollapsed: boolean): void; - setIsVisible(isVisible: boolean): void; -} - -// @public -export interface ContextSetup { - createContextContainer>(): IContextContainer; -} - -// @internal (undocumented) -export interface CoreContext { - // Warning: (ae-forgotten-export) The symbol "CoreId" needs to be exported by the entry point index.d.ts - // - // (undocumented) - coreId: CoreId; - // (undocumented) - env: { - mode: Readonly; - packageInfo: Readonly; - }; -} - -// @public -export interface CoreSetup { - // (undocumented) - application: ApplicationSetup; - // (undocumented) - context: ContextSetup; - // (undocumented) - fatalErrors: FatalErrorsSetup; - // (undocumented) - http: HttpSetup; - // @deprecated - injectedMetadata: { - getInjectedVar: (name: string, defaultValue?: any) => unknown; - }; - // (undocumented) - notifications: NotificationsSetup; - // (undocumented) - uiSettings: UiSettingsClientContract; -} - -// @public -export interface CoreStart { - // (undocumented) - application: ApplicationStart; - // (undocumented) - chrome: ChromeStart; - // (undocumented) - docLinks: DocLinksStart; - // (undocumented) - http: HttpStart; - // (undocumented) - i18n: I18nStart; - // @deprecated - injectedMetadata: { - getInjectedVar: (name: string, defaultValue?: any) => unknown; - }; - // (undocumented) - notifications: NotificationsStart; - // (undocumented) - overlays: OverlayStart; - // (undocumented) - savedObjects: SavedObjectsStart; - // (undocumented) - uiSettings: UiSettingsClientContract; -} - -// @internal -export class CoreSystem { - // Warning: (ae-forgotten-export) The symbol "Params" needs to be exported by the entry point index.d.ts - constructor(params: Params); - // (undocumented) - setup(): Promise<{ - fatalErrors: FatalErrorsSetup; - } | undefined>; - // (undocumented) - start(): Promise; - // (undocumented) - stop(): void; - } - -// @public (undocumented) -export interface DocLinksStart { - // (undocumented) - readonly DOC_LINK_VERSION: string; - // (undocumented) - readonly ELASTIC_WEBSITE_URL: string; - // (undocumented) - readonly links: { - readonly filebeat: { - readonly base: string; - readonly installation: string; - readonly configuration: string; - readonly elasticsearchOutput: string; - readonly startup: string; - readonly exportedFields: string; - }; - readonly auditbeat: { - readonly base: string; - }; - readonly metricbeat: { - readonly base: string; - }; - readonly heartbeat: { - readonly base: string; - }; - readonly logstash: { - readonly base: string; - }; - readonly functionbeat: { - readonly base: string; - }; - readonly winlogbeat: { - readonly base: string; - }; - readonly aggs: { - readonly date_histogram: string; - readonly date_range: string; - readonly filter: string; - readonly filters: string; - readonly geohash_grid: string; - readonly histogram: string; - readonly ip_range: string; - readonly range: string; - readonly significant_terms: string; - readonly terms: string; - readonly avg: string; - readonly avg_bucket: string; - readonly max_bucket: string; - readonly min_bucket: string; - readonly sum_bucket: string; - readonly cardinality: string; - readonly count: string; - readonly cumulative_sum: string; - readonly derivative: string; - readonly geo_bounds: string; - readonly geo_centroid: string; - readonly max: string; - readonly median: string; - readonly min: string; - readonly moving_avg: string; - readonly percentile_ranks: string; - readonly serial_diff: string; - readonly std_dev: string; - readonly sum: string; - readonly top_hits: string; - }; - readonly scriptedFields: { - readonly scriptFields: string; - readonly scriptAggs: string; - readonly painless: string; - readonly painlessApi: string; - readonly painlessSyntax: string; - readonly luceneExpressions: string; - }; - readonly indexPatterns: { - readonly loadingData: string; - readonly introduction: string; - }; - readonly kibana: string; - readonly siem: string; - readonly query: { - readonly luceneQuerySyntax: string; - readonly queryDsl: string; - readonly kueryQuerySyntax: string; - }; - readonly date: { - readonly dateMath: string; - }; - }; -} - -// @public (undocumented) -export interface EnvironmentMode { - // (undocumented) - dev: boolean; - // (undocumented) - name: 'development' | 'production'; - // (undocumented) - prod: boolean; -} - -// @public -export interface ErrorToastOptions { - title: string; - toastMessage?: string; -} - -// @public -export interface FatalErrorInfo { - // (undocumented) - message: string; - // (undocumented) - stack: string | undefined; -} - -// @public -export interface FatalErrorsSetup { - add: (error: string | Error, source?: string) => never; - get$: () => Rx.Observable; -} - -// @public -export type HandlerContextType> = T extends HandlerFunction ? U : never; - -// @public -export type HandlerFunction = (context: T, ...args: any[]) => any; - -// @public -export type HandlerParameters> = T extends (context: any, ...args: infer U) => any ? U : never; - -// @public (undocumented) -export type HttpBody = BodyInit | null | any; - -// @public (undocumented) -export interface HttpErrorRequest { - // (undocumented) - error: Error; - // (undocumented) - request: Request; -} - -// @public (undocumented) -export interface HttpErrorResponse extends HttpResponse { - // (undocumented) - error: Error | IHttpFetchError; -} - -// @public -export interface HttpFetchOptions extends HttpRequestInit { - headers?: HttpHeadersInit; - prependBasePath?: boolean; - query?: HttpFetchQuery; -} - -// @public (undocumented) -export interface HttpFetchQuery { - // (undocumented) - [key: string]: string | number | boolean | undefined; -} - -// @public -export type HttpHandler = (path: string, options?: HttpFetchOptions) => Promise; - -// @public (undocumented) -export interface HttpHeadersInit { - // (undocumented) - [name: string]: any; -} - -// @public -export interface HttpInterceptor { - request?(request: Request, controller: IHttpInterceptController): Promise | Request | void; - requestError?(httpErrorRequest: HttpErrorRequest, controller: IHttpInterceptController): Promise | Request | void; - response?(httpResponse: HttpResponse, controller: IHttpInterceptController): Promise | InterceptedHttpResponse | void; - responseError?(httpErrorResponse: HttpErrorResponse, controller: IHttpInterceptController): Promise | InterceptedHttpResponse | void; -} - -// @public -export interface HttpRequestInit { - body?: BodyInit | null; - cache?: RequestCache; - credentials?: RequestCredentials; - // (undocumented) - headers?: HttpHeadersInit; - integrity?: string; - keepalive?: boolean; - method?: string; - mode?: RequestMode; - redirect?: RequestRedirect; - referrer?: string; - referrerPolicy?: ReferrerPolicy; - signal?: AbortSignal | null; - window?: null; -} - -// @public (undocumented) -export interface HttpResponse extends InterceptedHttpResponse { - // (undocumented) - request: Readonly; -} - -// @public (undocumented) -export interface HttpServiceBase { - addLoadingCount(countSource$: Observable): void; - anonymousPaths: IAnonymousPaths; - basePath: IBasePath; - delete: HttpHandler; - fetch: HttpHandler; - get: HttpHandler; - getLoadingCount$(): Observable; - head: HttpHandler; - intercept(interceptor: HttpInterceptor): () => void; - options: HttpHandler; - patch: HttpHandler; - post: HttpHandler; - put: HttpHandler; - removeAllInterceptors(): void; - // @internal (undocumented) - stop(): void; -} - -// @public -export type HttpSetup = HttpServiceBase; - -// @public -export type HttpStart = HttpServiceBase; - -// @public -export interface I18nStart { - Context: ({ children }: { - children: React.ReactNode; - }) => JSX.Element; -} - -// Warning: (ae-missing-release-tag) "IAnonymousPaths" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) -// -// @public -export interface IAnonymousPaths { - isAnonymous(path: string): boolean; - register(path: string): void; -} - -// @public -export interface IBasePath { - get: () => string; - prepend: (url: string) => string; - remove: (url: string) => string; -} - -// @public -export interface IContextContainer> { - createHandler(pluginOpaqueId: PluginOpaqueId, handler: THandler): (...rest: HandlerParameters) => ShallowPromise>; - registerContext>(pluginOpaqueId: PluginOpaqueId, contextName: TContextName, provider: IContextProvider): this; -} - -// @public -export type IContextProvider, TContextName extends keyof HandlerContextType> = (context: Partial>, ...rest: HandlerParameters) => Promise[TContextName]> | HandlerContextType[TContextName]; - -// @public (undocumented) -export interface IHttpFetchError extends Error { - // (undocumented) - readonly body?: any; - // @deprecated (undocumented) - readonly req: Request; - // (undocumented) - readonly request: Request; - // @deprecated (undocumented) - readonly res?: Response; - // (undocumented) - readonly response?: Response; -} - -// @public -export interface IHttpInterceptController { - halt(): void; - halted: boolean; -} - -// @public (undocumented) -export interface InterceptedHttpResponse { - // (undocumented) - body?: HttpBody; - // (undocumented) - response?: Response; -} - -// @public -export type IToasts = Pick; - -// @public @deprecated -export interface LegacyCoreSetup extends CoreSetup { - // Warning: (ae-forgotten-export) The symbol "InjectedMetadataSetup" needs to be exported by the entry point index.d.ts - // - // @deprecated (undocumented) - injectedMetadata: InjectedMetadataSetup; -} - -// @public @deprecated -export interface LegacyCoreStart extends CoreStart { - // Warning: (ae-forgotten-export) The symbol "InjectedMetadataStart" needs to be exported by the entry point index.d.ts - // - // @deprecated (undocumented) - injectedMetadata: InjectedMetadataStart; -} - -// @public (undocumented) -export interface LegacyNavLink { - // (undocumented) - euiIconType?: string; - // (undocumented) - icon?: string; - // (undocumented) - id: string; - // (undocumented) - order: number; - // (undocumented) - title: string; - // (undocumented) - url: string; -} - -// @public -export type MountPoint = (element: T) => UnmountCallback; - -// @public (undocumented) -export interface NotificationsSetup { - // (undocumented) - toasts: ToastsSetup; -} - -// @public (undocumented) -export interface NotificationsStart { - // (undocumented) - toasts: ToastsStart; -} - -// @public (undocumented) -export interface OverlayBannersStart { - add(mount: MountPoint, priority?: number): string; - // Warning: (ae-forgotten-export) The symbol "OverlayBanner" needs to be exported by the entry point index.d.ts - // - // @internal (undocumented) - get$(): Observable; - // (undocumented) - getComponent(): JSX.Element; - remove(id: string): boolean; - replace(id: string | undefined, mount: MountPoint, priority?: number): string; -} - -// @public -export interface OverlayRef { - close(): Promise; - onClose: Promise; -} - -// @public (undocumented) -export interface OverlayStart { - // (undocumented) - banners: OverlayBannersStart; - // Warning: (ae-forgotten-export) The symbol "OverlayFlyoutStart" needs to be exported by the entry point index.d.ts - // - // (undocumented) - openFlyout: OverlayFlyoutStart['open']; - // Warning: (ae-forgotten-export) The symbol "OverlayModalStart" needs to be exported by the entry point index.d.ts - // - // (undocumented) - openModal: OverlayModalStart['open']; -} - -// @public (undocumented) -export interface PackageInfo { - // (undocumented) - branch: string; - // (undocumented) - buildNum: number; - // (undocumented) - buildSha: string; - // (undocumented) - dist: boolean; - // (undocumented) - version: string; -} - -// @public -export interface Plugin { - // (undocumented) - setup(core: CoreSetup, plugins: TPluginsSetup): TSetup | Promise; - // (undocumented) - start(core: CoreStart, plugins: TPluginsStart): TStart | Promise; - // (undocumented) - stop?(): void; -} - -// @public -export type PluginInitializer = (core: PluginInitializerContext) => Plugin; - -// @public -export interface PluginInitializerContext { - // (undocumented) - readonly config: { - get: () => T; - }; - // (undocumented) - readonly env: { - mode: Readonly; - packageInfo: Readonly; - }; - readonly opaqueId: PluginOpaqueId; -} - -// @public (undocumented) -export type PluginOpaqueId = symbol; - -// Warning: (ae-forgotten-export) The symbol "RecursiveReadonlyArray" needs to be exported by the entry point index.d.ts -// -// @public (undocumented) -export type RecursiveReadonly = T extends (...args: any[]) => any ? T : T extends any[] ? RecursiveReadonlyArray : T extends object ? Readonly<{ - [K in keyof T]: RecursiveReadonly; -}> : T; - -// @public (undocumented) -export interface SavedObject { - attributes: T; - // (undocumented) - error?: { - message: string; - statusCode: number; - }; - id: string; - migrationVersion?: SavedObjectsMigrationVersion; - references: SavedObjectReference[]; - type: string; - updated_at?: string; - version?: string; -} - -// @public -export type SavedObjectAttribute = SavedObjectAttributeSingle | SavedObjectAttributeSingle[]; - -// @public -export interface SavedObjectAttributes { - // (undocumented) - [key: string]: SavedObjectAttribute; -} - -// @public -export type SavedObjectAttributeSingle = string | number | boolean | null | undefined | SavedObjectAttributes; - -// @public -export interface SavedObjectReference { - // (undocumented) - id: string; - // (undocumented) - name: string; - // (undocumented) - type: string; -} - -// @public (undocumented) -export interface SavedObjectsBaseOptions { - namespace?: string; -} - -// @public (undocumented) -export interface SavedObjectsBatchResponse { - // (undocumented) - savedObjects: Array>; -} - -// @public (undocumented) -export interface SavedObjectsBulkCreateObject extends SavedObjectsCreateOptions { - // (undocumented) - attributes: T; - // (undocumented) - type: string; -} - -// @public (undocumented) -export interface SavedObjectsBulkCreateOptions { - overwrite?: boolean; -} - -// @public (undocumented) -export interface SavedObjectsBulkUpdateObject { - // (undocumented) - attributes: T; - // (undocumented) - id: string; - // (undocumented) - references?: SavedObjectReference[]; - // (undocumented) - type: string; - // (undocumented) - version?: string; -} - -// @public (undocumented) -export interface SavedObjectsBulkUpdateOptions { - // (undocumented) - namespace?: string; -} - -// @public -export class SavedObjectsClient { - // @internal - constructor(http: HttpServiceBase); - bulkCreate: (objects?: SavedObjectsBulkCreateObject[], options?: SavedObjectsBulkCreateOptions) => Promise>; - bulkGet: (objects?: { - id: string; - type: string; - }[]) => Promise>; - bulkUpdate(objects?: SavedObjectsBulkUpdateObject[]): Promise>; - create: (type: string, attributes: T, options?: SavedObjectsCreateOptions) => Promise>; - delete: (type: string, id: string) => Promise<{}>; - find: (options: Pick) => Promise>; - get: (type: string, id: string) => Promise>; - update(type: string, id: string, attributes: T, { version, migrationVersion, references }?: SavedObjectsUpdateOptions): Promise>; -} - -// @public -export type SavedObjectsClientContract = PublicMethodsOf; - -// @public (undocumented) -export interface SavedObjectsCreateOptions { - id?: string; - migrationVersion?: SavedObjectsMigrationVersion; - overwrite?: boolean; - // (undocumented) - references?: SavedObjectReference[]; -} - -// @public (undocumented) -export interface SavedObjectsFindOptions extends SavedObjectsBaseOptions { - // (undocumented) - defaultSearchOperator?: 'AND' | 'OR'; - fields?: string[]; - // (undocumented) - filter?: string; - // (undocumented) - hasReference?: { - type: string; - id: string; - }; - // (undocumented) - page?: number; - // (undocumented) - perPage?: number; - search?: string; - searchFields?: string[]; - // (undocumented) - sortField?: string; - // (undocumented) - sortOrder?: string; - // (undocumented) - type: string | string[]; -} - -// @public -export interface SavedObjectsFindResponsePublic extends SavedObjectsBatchResponse { - // (undocumented) - page: number; - // (undocumented) - perPage: number; - // (undocumented) - total: number; -} - -// @public -export interface SavedObjectsMigrationVersion { - // (undocumented) - [pluginName: string]: string; -} - -// @public (undocumented) -export interface SavedObjectsStart { - // (undocumented) - client: SavedObjectsClientContract; -} - -// @public (undocumented) -export interface SavedObjectsUpdateOptions { - migrationVersion?: SavedObjectsMigrationVersion; - // (undocumented) - references?: SavedObjectReference[]; - // (undocumented) - version?: string; -} - -// @public -export class SimpleSavedObject { - constructor(client: SavedObjectsClient, { id, type, version, attributes, error, references, migrationVersion }: SavedObject); - // (undocumented) - attributes: T; - // (undocumented) - delete(): Promise<{}>; - // (undocumented) - error: SavedObject['error']; - // (undocumented) - get(key: string): any; - // (undocumented) - has(key: string): boolean; - // (undocumented) - id: SavedObject['id']; - // (undocumented) - migrationVersion: SavedObject['migrationVersion']; - // (undocumented) - references: SavedObject['references']; - // (undocumented) - save(): Promise>; - // (undocumented) - set(key: string, value: any): T; - // (undocumented) - type: SavedObject['type']; - // (undocumented) - _version?: SavedObject['version']; -} - -// Warning: (ae-missing-release-tag) "Toast" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) -// -// @public (undocumented) -export type Toast = ToastInputFields & { - id: string; -}; - -// @public -export type ToastInput = string | ToastInputFields; - -// @public -export type ToastInputFields = Pick> & { - title?: string | MountPoint; - text?: string | MountPoint; -}; - -// @public -export class ToastsApi implements IToasts { - constructor(deps: { - uiSettings: UiSettingsClientContract; - }); - add(toastOrTitle: ToastInput): Toast; - addDanger(toastOrTitle: ToastInput): Toast; - addError(error: Error, options: ErrorToastOptions): Toast; - addSuccess(toastOrTitle: ToastInput): Toast; - addWarning(toastOrTitle: ToastInput): Toast; - get$(): Rx.Observable; - remove(toastOrId: Toast | string): void; - // @internal (undocumented) - start({ overlays, i18n }: { - overlays: OverlayStart; - i18n: I18nStart; - }): void; - } - -// @public (undocumented) -export type ToastsSetup = IToasts; - -// @public (undocumented) -export type ToastsStart = IToasts; - -// @public (undocumented) -export class UiSettingsClient { - // Warning: (ae-forgotten-export) The symbol "UiSettingsClientParams" needs to be exported by the entry point index.d.ts - constructor(params: UiSettingsClientParams); - get$(key: string, defaultOverride?: any): Rx.Observable; - get(key: string, defaultOverride?: any): any; - getAll(): Record>; - getSaved$(): Rx.Observable<{ - key: string; - newValue: any; - oldValue: any; - }>; - getUpdate$(): Rx.Observable<{ - key: string; - newValue: any; - oldValue: any; - }>; - getUpdateErrors$(): Rx.Observable; - isCustom(key: string): boolean; - isDeclared(key: string): boolean; - isDefault(key: string): boolean; - isOverridden(key: string): boolean; - overrideLocalDefault(key: string, newDefault: any): void; - remove(key: string): Promise; - set(key: string, val: any): Promise; - stop(): void; - } - -// @public -export type UiSettingsClientContract = PublicMethodsOf; - -// @public (undocumented) -export interface UiSettingsState { - // (undocumented) - [key: string]: UiSettingsParams_2 & UserProvidedValues_2; -} - -// @public -export type UnmountCallback = () => void; - - -``` +## API Report File for "kibana" + +> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). + +```ts + +import { Breadcrumb } from '@elastic/eui'; +import { EuiButtonEmptyProps } from '@elastic/eui'; +import { EuiGlobalToastListToast } from '@elastic/eui'; +import { ExclusiveUnion } from '@elastic/eui'; +import { IconType } from '@elastic/eui'; +import { Observable } from 'rxjs'; +import React from 'react'; +import * as Rx from 'rxjs'; +import { ShallowPromise } from '@kbn/utility-types'; +import { UiSettingsParams as UiSettingsParams_2 } from 'src/core/server/types'; +import { UserProvidedValues as UserProvidedValues_2 } from 'src/core/server/types'; + +// @public +export interface App extends AppBase { + chromeless?: boolean; + mount: (context: AppMountContext, params: AppMountParameters) => AppUnmount | Promise; +} + +// @public (undocumented) +export interface AppBase { + capabilities?: Partial; + euiIconType?: string; + icon?: string; + // (undocumented) + id: string; + order?: number; + title: string; + tooltip$?: Observable; +} + +// @public (undocumented) +export interface ApplicationSetup { + register(app: App): void; + registerMountContext(contextName: T, provider: IContextProvider): void; +} + +// @public (undocumented) +export interface ApplicationStart { + capabilities: RecursiveReadonly; + getUrlForApp(appId: string, options?: { + path?: string; + }): string; + navigateToApp(appId: string, options?: { + path?: string; + state?: any; + }): void; + registerMountContext(contextName: T, provider: IContextProvider): void; +} + +// @public +export interface AppMountContext { + core: { + application: Pick; + chrome: ChromeStart; + docLinks: DocLinksStart; + http: HttpStart; + i18n: I18nStart; + notifications: NotificationsStart; + overlays: OverlayStart; + uiSettings: UiSettingsClientContract; + injectedMetadata: { + getInjectedVar: (name: string, defaultValue?: any) => unknown; + }; + }; +} + +// @public (undocumented) +export interface AppMountParameters { + appBasePath: string; + element: HTMLElement; +} + +// @public +export type AppUnmount = () => void; + +// @public +export interface Capabilities { + [key: string]: Record>; + catalogue: Record; + management: { + [sectionId: string]: Record; + }; + navLinks: Record; +} + +// @public (undocumented) +export interface ChromeBadge { + // (undocumented) + iconType?: IconType; + // (undocumented) + text: string; + // (undocumented) + tooltip: string; +} + +// @public (undocumented) +export interface ChromeBrand { + // (undocumented) + logo?: string; + // (undocumented) + smallLogo?: string; +} + +// @public (undocumented) +export type ChromeBreadcrumb = Breadcrumb; + +// @public +export interface ChromeDocTitle { + // @internal (undocumented) + __legacy: { + setBaseTitle(baseTitle: string): void; + }; + change(newTitle: string | string[]): void; + reset(): void; +} + +// @public (undocumented) +export interface ChromeHelpExtension { + appName: string; + content?: (element: HTMLDivElement) => () => void; + links?: ChromeHelpExtensionMenuLink[]; +} + +// @public (undocumented) +export type ChromeHelpExtensionMenuCustomLink = EuiButtonEmptyProps & { + linkType: 'custom'; + content: React.ReactNode; +}; + +// @public (undocumented) +export type ChromeHelpExtensionMenuDiscussLink = EuiButtonEmptyProps & { + linkType: 'discuss'; + href: string; +}; + +// @public (undocumented) +export type ChromeHelpExtensionMenuDocumentationLink = EuiButtonEmptyProps & { + linkType: 'documentation'; + href: string; +}; + +// @public (undocumented) +export type ChromeHelpExtensionMenuGitHubLink = EuiButtonEmptyProps & { + linkType: 'github'; + labels: string[]; + title?: string; +}; + +// @public (undocumented) +export type ChromeHelpExtensionMenuLink = ExclusiveUnion>>; + +// @public (undocumented) +export interface ChromeNavControl { + // (undocumented) + mount: MountPoint; + // (undocumented) + order?: number; +} + +// @public +export interface ChromeNavControls { + // @internal (undocumented) + getLeft$(): Observable; + // @internal (undocumented) + getRight$(): Observable; + registerLeft(navControl: ChromeNavControl): void; + registerRight(navControl: ChromeNavControl): void; +} + +// @public (undocumented) +export interface ChromeNavLink { + // @deprecated + readonly active?: boolean; + readonly baseUrl: string; + // @deprecated + readonly disabled?: boolean; + readonly euiIconType?: string; + readonly hidden?: boolean; + readonly icon?: string; + readonly id: string; + // @internal + readonly legacy: boolean; + // @deprecated + readonly linkToLastSubUrl?: boolean; + readonly order?: number; + // @deprecated + readonly subUrlBase?: string; + readonly title: string; + readonly tooltip?: string; + // @deprecated + readonly url?: string; +} + +// @public +export interface ChromeNavLinks { + enableForcedAppSwitcherNavigation(): void; + get(id: string): ChromeNavLink | undefined; + getAll(): Array>; + getForceAppSwitcherNavigation$(): Observable; + getNavLinks$(): Observable>>; + has(id: string): boolean; + showOnly(id: string): void; + update(id: string, values: ChromeNavLinkUpdateableFields): ChromeNavLink | undefined; +} + +// @public (undocumented) +export type ChromeNavLinkUpdateableFields = Partial>; + +// @public +export interface ChromeRecentlyAccessed { + // Warning: (ae-unresolved-link) The @link reference could not be resolved: No member was found with name "basePath" + add(link: string, label: string, id: string): void; + get$(): Observable; + get(): ChromeRecentlyAccessedHistoryItem[]; +} + +// @public (undocumented) +export interface ChromeRecentlyAccessedHistoryItem { + // (undocumented) + id: string; + // (undocumented) + label: string; + // (undocumented) + link: string; +} + +// @public +export interface ChromeStart { + addApplicationClass(className: string): void; + docTitle: ChromeDocTitle; + getApplicationClasses$(): Observable; + getBadge$(): Observable; + getBrand$(): Observable; + getBreadcrumbs$(): Observable; + getHelpExtension$(): Observable; + getIsCollapsed$(): Observable; + getIsVisible$(): Observable; + navControls: ChromeNavControls; + navLinks: ChromeNavLinks; + recentlyAccessed: ChromeRecentlyAccessed; + removeApplicationClass(className: string): void; + setAppTitle(appTitle: string): void; + setBadge(badge?: ChromeBadge): void; + setBrand(brand: ChromeBrand): void; + setBreadcrumbs(newBreadcrumbs: ChromeBreadcrumb[]): void; + setHelpExtension(helpExtension?: ChromeHelpExtension): void; + setIsCollapsed(isCollapsed: boolean): void; + setIsVisible(isVisible: boolean): void; +} + +// @public +export interface ContextSetup { + createContextContainer>(): IContextContainer; +} + +// @internal (undocumented) +export interface CoreContext { + // Warning: (ae-forgotten-export) The symbol "CoreId" needs to be exported by the entry point index.d.ts + // + // (undocumented) + coreId: CoreId; + // (undocumented) + env: { + mode: Readonly; + packageInfo: Readonly; + }; +} + +// @public +export interface CoreSetup { + // (undocumented) + application: ApplicationSetup; + // (undocumented) + context: ContextSetup; + // (undocumented) + fatalErrors: FatalErrorsSetup; + // (undocumented) + http: HttpSetup; + // @deprecated + injectedMetadata: { + getInjectedVar: (name: string, defaultValue?: any) => unknown; + }; + // (undocumented) + notifications: NotificationsSetup; + // (undocumented) + uiSettings: UiSettingsClientContract; +} + +// @public +export interface CoreStart { + // (undocumented) + application: ApplicationStart; + // (undocumented) + chrome: ChromeStart; + // (undocumented) + docLinks: DocLinksStart; + // (undocumented) + http: HttpStart; + // (undocumented) + i18n: I18nStart; + // @deprecated + injectedMetadata: { + getInjectedVar: (name: string, defaultValue?: any) => unknown; + }; + // (undocumented) + notifications: NotificationsStart; + // (undocumented) + overlays: OverlayStart; + // (undocumented) + savedObjects: SavedObjectsStart; + // (undocumented) + uiSettings: UiSettingsClientContract; +} + +// @internal +export class CoreSystem { + // Warning: (ae-forgotten-export) The symbol "Params" needs to be exported by the entry point index.d.ts + constructor(params: Params); + // (undocumented) + setup(): Promise<{ + fatalErrors: FatalErrorsSetup; + } | undefined>; + // (undocumented) + start(): Promise; + // (undocumented) + stop(): void; + } + +// @public (undocumented) +export interface DocLinksStart { + // (undocumented) + readonly DOC_LINK_VERSION: string; + // (undocumented) + readonly ELASTIC_WEBSITE_URL: string; + // (undocumented) + readonly links: { + readonly filebeat: { + readonly base: string; + readonly installation: string; + readonly configuration: string; + readonly elasticsearchOutput: string; + readonly startup: string; + readonly exportedFields: string; + }; + readonly auditbeat: { + readonly base: string; + }; + readonly metricbeat: { + readonly base: string; + }; + readonly heartbeat: { + readonly base: string; + }; + readonly logstash: { + readonly base: string; + }; + readonly functionbeat: { + readonly base: string; + }; + readonly winlogbeat: { + readonly base: string; + }; + readonly aggs: { + readonly date_histogram: string; + readonly date_range: string; + readonly filter: string; + readonly filters: string; + readonly geohash_grid: string; + readonly histogram: string; + readonly ip_range: string; + readonly range: string; + readonly significant_terms: string; + readonly terms: string; + readonly avg: string; + readonly avg_bucket: string; + readonly max_bucket: string; + readonly min_bucket: string; + readonly sum_bucket: string; + readonly cardinality: string; + readonly count: string; + readonly cumulative_sum: string; + readonly derivative: string; + readonly geo_bounds: string; + readonly geo_centroid: string; + readonly max: string; + readonly median: string; + readonly min: string; + readonly moving_avg: string; + readonly percentile_ranks: string; + readonly serial_diff: string; + readonly std_dev: string; + readonly sum: string; + readonly top_hits: string; + }; + readonly scriptedFields: { + readonly scriptFields: string; + readonly scriptAggs: string; + readonly painless: string; + readonly painlessApi: string; + readonly painlessSyntax: string; + readonly luceneExpressions: string; + }; + readonly indexPatterns: { + readonly loadingData: string; + readonly introduction: string; + }; + readonly kibana: string; + readonly siem: string; + readonly query: { + readonly luceneQuerySyntax: string; + readonly queryDsl: string; + readonly kueryQuerySyntax: string; + }; + readonly date: { + readonly dateMath: string; + }; + }; +} + +// @public (undocumented) +export interface EnvironmentMode { + // (undocumented) + dev: boolean; + // (undocumented) + name: 'development' | 'production'; + // (undocumented) + prod: boolean; +} + +// @public +export interface ErrorToastOptions { + title: string; + toastMessage?: string; +} + +// @public +export interface FatalErrorInfo { + // (undocumented) + message: string; + // (undocumented) + stack: string | undefined; +} + +// @public +export interface FatalErrorsSetup { + add: (error: string | Error, source?: string) => never; + get$: () => Rx.Observable; +} + +// @public +export type HandlerContextType> = T extends HandlerFunction ? U : never; + +// @public +export type HandlerFunction = (context: T, ...args: any[]) => any; + +// @public +export type HandlerParameters> = T extends (context: any, ...args: infer U) => any ? U : never; + +// @public (undocumented) +export type HttpBody = BodyInit | null | any; + +// @public (undocumented) +export interface HttpErrorRequest { + // (undocumented) + error: Error; + // (undocumented) + request: Request; +} + +// @public (undocumented) +export interface HttpErrorResponse extends HttpResponse { + // (undocumented) + error: Error | IHttpFetchError; +} + +// @public +export interface HttpFetchOptions extends HttpRequestInit { + headers?: HttpHeadersInit; + prependBasePath?: boolean; + query?: HttpFetchQuery; +} + +// @public (undocumented) +export interface HttpFetchQuery { + // (undocumented) + [key: string]: string | number | boolean | undefined; +} + +// @public +export type HttpHandler = (path: string, options?: HttpFetchOptions) => Promise; + +// @public (undocumented) +export interface HttpHeadersInit { + // (undocumented) + [name: string]: any; +} + +// @public +export interface HttpInterceptor { + request?(request: Request, controller: IHttpInterceptController): Promise | Request | void; + requestError?(httpErrorRequest: HttpErrorRequest, controller: IHttpInterceptController): Promise | Request | void; + response?(httpResponse: HttpResponse, controller: IHttpInterceptController): Promise | InterceptedHttpResponse | void; + responseError?(httpErrorResponse: HttpErrorResponse, controller: IHttpInterceptController): Promise | InterceptedHttpResponse | void; +} + +// @public +export interface HttpRequestInit { + body?: BodyInit | null; + cache?: RequestCache; + credentials?: RequestCredentials; + // (undocumented) + headers?: HttpHeadersInit; + integrity?: string; + keepalive?: boolean; + method?: string; + mode?: RequestMode; + redirect?: RequestRedirect; + referrer?: string; + referrerPolicy?: ReferrerPolicy; + signal?: AbortSignal | null; + window?: null; +} + +// @public (undocumented) +export interface HttpResponse extends InterceptedHttpResponse { + // (undocumented) + request: Readonly; +} + +// @public (undocumented) +export interface HttpServiceBase { + addLoadingCount(countSource$: Observable): void; + anonymousPaths: IAnonymousPaths; + basePath: IBasePath; + delete: HttpHandler; + fetch: HttpHandler; + get: HttpHandler; + getLoadingCount$(): Observable; + head: HttpHandler; + intercept(interceptor: HttpInterceptor): () => void; + options: HttpHandler; + patch: HttpHandler; + post: HttpHandler; + put: HttpHandler; + removeAllInterceptors(): void; + // @internal (undocumented) + stop(): void; +} + +// @public +export type HttpSetup = HttpServiceBase; + +// @public +export type HttpStart = HttpServiceBase; + +// @public +export interface I18nStart { + Context: ({ children }: { + children: React.ReactNode; + }) => JSX.Element; +} + +// Warning: (ae-missing-release-tag) "IAnonymousPaths" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// +// @public +export interface IAnonymousPaths { + isAnonymous(path: string): boolean; + register(path: string): void; +} + +// @public +export interface IBasePath { + get: () => string; + prepend: (url: string) => string; + remove: (url: string) => string; +} + +// @public +export interface IContextContainer> { + createHandler(pluginOpaqueId: PluginOpaqueId, handler: THandler): (...rest: HandlerParameters) => ShallowPromise>; + registerContext>(pluginOpaqueId: PluginOpaqueId, contextName: TContextName, provider: IContextProvider): this; +} + +// @public +export type IContextProvider, TContextName extends keyof HandlerContextType> = (context: Partial>, ...rest: HandlerParameters) => Promise[TContextName]> | HandlerContextType[TContextName]; + +// @public (undocumented) +export interface IHttpFetchError extends Error { + // (undocumented) + readonly body?: any; + // @deprecated (undocumented) + readonly req: Request; + // (undocumented) + readonly request: Request; + // @deprecated (undocumented) + readonly res?: Response; + // (undocumented) + readonly response?: Response; +} + +// @public +export interface IHttpInterceptController { + halt(): void; + halted: boolean; +} + +// @public (undocumented) +export interface InterceptedHttpResponse { + // (undocumented) + body?: HttpBody; + // (undocumented) + response?: Response; +} + +// @public +export type IToasts = Pick; + +// @public @deprecated +export interface LegacyCoreSetup extends CoreSetup { + // Warning: (ae-forgotten-export) The symbol "InjectedMetadataSetup" needs to be exported by the entry point index.d.ts + // + // @deprecated (undocumented) + injectedMetadata: InjectedMetadataSetup; +} + +// @public @deprecated +export interface LegacyCoreStart extends CoreStart { + // Warning: (ae-forgotten-export) The symbol "InjectedMetadataStart" needs to be exported by the entry point index.d.ts + // + // @deprecated (undocumented) + injectedMetadata: InjectedMetadataStart; +} + +// @public (undocumented) +export interface LegacyNavLink { + // (undocumented) + euiIconType?: string; + // (undocumented) + icon?: string; + // (undocumented) + id: string; + // (undocumented) + order: number; + // (undocumented) + title: string; + // (undocumented) + url: string; +} + +// @public +export type MountPoint = (element: T) => UnmountCallback; + +// @public (undocumented) +export interface NotificationsSetup { + // (undocumented) + toasts: ToastsSetup; +} + +// @public (undocumented) +export interface NotificationsStart { + // (undocumented) + toasts: ToastsStart; +} + +// @public (undocumented) +export interface OverlayBannersStart { + add(mount: MountPoint, priority?: number): string; + // Warning: (ae-forgotten-export) The symbol "OverlayBanner" needs to be exported by the entry point index.d.ts + // + // @internal (undocumented) + get$(): Observable; + // (undocumented) + getComponent(): JSX.Element; + remove(id: string): boolean; + replace(id: string | undefined, mount: MountPoint, priority?: number): string; +} + +// @public +export interface OverlayRef { + close(): Promise; + onClose: Promise; +} + +// @public (undocumented) +export interface OverlayStart { + // (undocumented) + banners: OverlayBannersStart; + // Warning: (ae-forgotten-export) The symbol "OverlayFlyoutStart" needs to be exported by the entry point index.d.ts + // + // (undocumented) + openFlyout: OverlayFlyoutStart['open']; + // Warning: (ae-forgotten-export) The symbol "OverlayModalStart" needs to be exported by the entry point index.d.ts + // + // (undocumented) + openModal: OverlayModalStart['open']; +} + +// @public (undocumented) +export interface PackageInfo { + // (undocumented) + branch: string; + // (undocumented) + buildNum: number; + // (undocumented) + buildSha: string; + // (undocumented) + dist: boolean; + // (undocumented) + version: string; +} + +// @public +export interface Plugin { + // (undocumented) + setup(core: CoreSetup, plugins: TPluginsSetup): TSetup | Promise; + // (undocumented) + start(core: CoreStart, plugins: TPluginsStart): TStart | Promise; + // (undocumented) + stop?(): void; +} + +// @public +export type PluginInitializer = (core: PluginInitializerContext) => Plugin; + +// @public +export interface PluginInitializerContext { + // (undocumented) + readonly config: { + get: () => T; + }; + // (undocumented) + readonly env: { + mode: Readonly; + packageInfo: Readonly; + }; + readonly opaqueId: PluginOpaqueId; +} + +// @public (undocumented) +export type PluginOpaqueId = symbol; + +// Warning: (ae-forgotten-export) The symbol "RecursiveReadonlyArray" needs to be exported by the entry point index.d.ts +// +// @public (undocumented) +export type RecursiveReadonly = T extends (...args: any[]) => any ? T : T extends any[] ? RecursiveReadonlyArray : T extends object ? Readonly<{ + [K in keyof T]: RecursiveReadonly; +}> : T; + +// @public (undocumented) +export interface SavedObject { + attributes: T; + // (undocumented) + error?: { + message: string; + statusCode: number; + }; + id: string; + migrationVersion?: SavedObjectsMigrationVersion; + references: SavedObjectReference[]; + type: string; + updated_at?: string; + version?: string; +} + +// @public +export type SavedObjectAttribute = SavedObjectAttributeSingle | SavedObjectAttributeSingle[]; + +// @public +export interface SavedObjectAttributes { + // (undocumented) + [key: string]: SavedObjectAttribute; +} + +// @public +export type SavedObjectAttributeSingle = string | number | boolean | null | undefined | SavedObjectAttributes; + +// @public +export interface SavedObjectReference { + // (undocumented) + id: string; + // (undocumented) + name: string; + // (undocumented) + type: string; +} + +// @public (undocumented) +export interface SavedObjectsBaseOptions { + namespace?: string; +} + +// @public (undocumented) +export interface SavedObjectsBatchResponse { + // (undocumented) + savedObjects: Array>; +} + +// @public (undocumented) +export interface SavedObjectsBulkCreateObject extends SavedObjectsCreateOptions { + // (undocumented) + attributes: T; + // (undocumented) + type: string; +} + +// @public (undocumented) +export interface SavedObjectsBulkCreateOptions { + overwrite?: boolean; +} + +// @public (undocumented) +export interface SavedObjectsBulkUpdateObject { + // (undocumented) + attributes: T; + // (undocumented) + id: string; + // (undocumented) + references?: SavedObjectReference[]; + // (undocumented) + type: string; + // (undocumented) + version?: string; +} + +// @public (undocumented) +export interface SavedObjectsBulkUpdateOptions { + // (undocumented) + namespace?: string; +} + +// @public +export class SavedObjectsClient { + // @internal + constructor(http: HttpServiceBase); + bulkCreate: (objects?: SavedObjectsBulkCreateObject[], options?: SavedObjectsBulkCreateOptions) => Promise>; + bulkGet: (objects?: { + id: string; + type: string; + }[]) => Promise>; + bulkUpdate(objects?: SavedObjectsBulkUpdateObject[]): Promise>; + create: (type: string, attributes: T, options?: SavedObjectsCreateOptions) => Promise>; + delete: (type: string, id: string) => Promise<{}>; + find: (options: Pick) => Promise>; + get: (type: string, id: string) => Promise>; + update(type: string, id: string, attributes: T, { version, migrationVersion, references }?: SavedObjectsUpdateOptions): Promise>; +} + +// @public +export type SavedObjectsClientContract = PublicMethodsOf; + +// @public (undocumented) +export interface SavedObjectsCreateOptions { + id?: string; + migrationVersion?: SavedObjectsMigrationVersion; + overwrite?: boolean; + // (undocumented) + references?: SavedObjectReference[]; +} + +// @public (undocumented) +export interface SavedObjectsFindOptions extends SavedObjectsBaseOptions { + // (undocumented) + defaultSearchOperator?: 'AND' | 'OR'; + fields?: string[]; + // (undocumented) + filter?: string; + // (undocumented) + hasReference?: { + type: string; + id: string; + }; + // (undocumented) + page?: number; + // (undocumented) + perPage?: number; + search?: string; + searchFields?: string[]; + // (undocumented) + sortField?: string; + // (undocumented) + sortOrder?: string; + // (undocumented) + type: string | string[]; +} + +// @public +export interface SavedObjectsFindResponsePublic extends SavedObjectsBatchResponse { + // (undocumented) + page: number; + // (undocumented) + perPage: number; + // (undocumented) + total: number; +} + +// @public +export interface SavedObjectsMigrationVersion { + // (undocumented) + [pluginName: string]: string; +} + +// @public (undocumented) +export interface SavedObjectsStart { + // (undocumented) + client: SavedObjectsClientContract; +} + +// @public (undocumented) +export interface SavedObjectsUpdateOptions { + migrationVersion?: SavedObjectsMigrationVersion; + // (undocumented) + references?: SavedObjectReference[]; + // (undocumented) + version?: string; +} + +// @public +export class SimpleSavedObject { + constructor(client: SavedObjectsClient, { id, type, version, attributes, error, references, migrationVersion }: SavedObject); + // (undocumented) + attributes: T; + // (undocumented) + delete(): Promise<{}>; + // (undocumented) + error: SavedObject['error']; + // (undocumented) + get(key: string): any; + // (undocumented) + has(key: string): boolean; + // (undocumented) + id: SavedObject['id']; + // (undocumented) + migrationVersion: SavedObject['migrationVersion']; + // (undocumented) + references: SavedObject['references']; + // (undocumented) + save(): Promise>; + // (undocumented) + set(key: string, value: any): T; + // (undocumented) + type: SavedObject['type']; + // (undocumented) + _version?: SavedObject['version']; +} + +// Warning: (ae-missing-release-tag) "Toast" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// +// @public (undocumented) +export type Toast = ToastInputFields & { + id: string; +}; + +// @public +export type ToastInput = string | ToastInputFields; + +// @public +export type ToastInputFields = Pick> & { + title?: string | MountPoint; + text?: string | MountPoint; +}; + +// @public +export class ToastsApi implements IToasts { + constructor(deps: { + uiSettings: UiSettingsClientContract; + }); + add(toastOrTitle: ToastInput): Toast; + addDanger(toastOrTitle: ToastInput): Toast; + addError(error: Error, options: ErrorToastOptions): Toast; + addSuccess(toastOrTitle: ToastInput): Toast; + addWarning(toastOrTitle: ToastInput): Toast; + get$(): Rx.Observable; + remove(toastOrId: Toast | string): void; + // @internal (undocumented) + start({ overlays, i18n }: { + overlays: OverlayStart; + i18n: I18nStart; + }): void; + } + +// @public (undocumented) +export type ToastsSetup = IToasts; + +// @public (undocumented) +export type ToastsStart = IToasts; + +// @public (undocumented) +export class UiSettingsClient { + // Warning: (ae-forgotten-export) The symbol "UiSettingsClientParams" needs to be exported by the entry point index.d.ts + constructor(params: UiSettingsClientParams); + get$(key: string, defaultOverride?: any): Rx.Observable; + get(key: string, defaultOverride?: any): any; + getAll(): Record>; + getSaved$(): Rx.Observable<{ + key: string; + newValue: any; + oldValue: any; + }>; + getUpdate$(): Rx.Observable<{ + key: string; + newValue: any; + oldValue: any; + }>; + getUpdateErrors$(): Rx.Observable; + isCustom(key: string): boolean; + isDeclared(key: string): boolean; + isDefault(key: string): boolean; + isOverridden(key: string): boolean; + overrideLocalDefault(key: string, newDefault: any): void; + remove(key: string): Promise; + set(key: string, val: any): Promise; + stop(): void; + } + +// @public +export type UiSettingsClientContract = PublicMethodsOf; + +// @public (undocumented) +export interface UiSettingsState { + // (undocumented) + [key: string]: UiSettingsParams_2 & UserProvidedValues_2; +} + +// @public +export type UnmountCallback = () => void; + + +``` From 5f7c0e35c9ddd95159f245a46f621ceea38c5244 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Ferna=CC=81ndez=20Haro?= Date: Wed, 27 Nov 2019 16:24:46 +0000 Subject: [PATCH 05/21] Fix test references to the moved utils --- src/legacy/ui/public/chrome/api/__tests__/xsrf.js | 2 +- src/legacy/ui/public/legacy_compat/__tests__/xsrf.js | 2 +- .../visual_regression/services/visual_testing/visual_testing.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/legacy/ui/public/chrome/api/__tests__/xsrf.js b/src/legacy/ui/public/chrome/api/__tests__/xsrf.js index 54255562cb6110..f54bf5ef908405 100644 --- a/src/legacy/ui/public/chrome/api/__tests__/xsrf.js +++ b/src/legacy/ui/public/chrome/api/__tests__/xsrf.js @@ -21,7 +21,7 @@ import expect from '@kbn/expect'; import sinon from 'sinon'; import { initChromeXsrfApi } from '../xsrf'; -import { version } from '../../../../../utils/package_json'; +import { version } from '../../../../../../core/utils/package_json'; describe('chrome xsrf apis', function () { const sandbox = sinon.createSandbox(); diff --git a/src/legacy/ui/public/legacy_compat/__tests__/xsrf.js b/src/legacy/ui/public/legacy_compat/__tests__/xsrf.js index 9073d7588ddcf7..91b38c5d811d54 100644 --- a/src/legacy/ui/public/legacy_compat/__tests__/xsrf.js +++ b/src/legacy/ui/public/legacy_compat/__tests__/xsrf.js @@ -23,7 +23,7 @@ import sinon from 'sinon'; import ngMock from 'ng_mock'; import { $setupXsrfRequestInterceptor } from '../angular_config'; -import { version } from '../../../../utils/package_json'; +import { version } from '../../../../../core/utils/package_json'; const xsrfHeader = 'kbn-version'; const newPlatform = { diff --git a/test/visual_regression/services/visual_testing/visual_testing.ts b/test/visual_regression/services/visual_testing/visual_testing.ts index 8ac80ffe0398d9..25f36bdc1b893a 100644 --- a/test/visual_regression/services/visual_testing/visual_testing.ts +++ b/test/visual_regression/services/visual_testing/visual_testing.ts @@ -23,7 +23,7 @@ import _ from 'lodash'; import testSubjSelector from '@kbn/test-subj-selector'; -import { pkg } from 'src/core/utils'; +import { pkg } from '../../../../src/core/utils'; import { FtrProviderContext } from '../../ftr_provider_context'; // @ts-ignore internal js that is passed to the browser as is From 7b7ea57466e5b676bbed3488bb80ddc139ce1cb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Ferna=CC=81ndez=20Haro?= Date: Thu, 28 Nov 2019 10:04:15 +0000 Subject: [PATCH 06/21] Replace zip with combineLatest --- src/core/server/path.ts | 8 ++++++++ src/core/server/plugins/plugin_context.ts | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/core/server/path.ts b/src/core/server/path.ts index b5af5f9210aa30..ef8a3caeefa2cd 100644 --- a/src/core/server/path.ts +++ b/src/core/server/path.ts @@ -49,7 +49,15 @@ function findFile(paths: string[]) { return availablePath || paths[0]; } +/** + * Get the path where the config files are stored + * @internal + */ export const getConfigPath = () => findFile(CONFIG_PATHS); +/** + * Get the path where the data can be stored + * @internal + */ export const getDataPath = () => findFile(DATA_PATHS); export type PathConfigType = TypeOf; diff --git a/src/core/server/plugins/plugin_context.ts b/src/core/server/plugins/plugin_context.ts index b79cc2c3002f03..eaec5e35dda67d 100644 --- a/src/core/server/plugins/plugin_context.ts +++ b/src/core/server/plugins/plugin_context.ts @@ -18,7 +18,7 @@ */ import { map } from 'rxjs/operators'; -import { zip } from 'rxjs'; +import { combineLatest } from 'rxjs'; import { CoreContext } from '../core_context'; import { PluginWrapper } from './plugin'; import { PluginsServiceSetupDeps, PluginsServiceStartDeps } from './plugins_service'; @@ -84,7 +84,7 @@ export function createPluginInitializerContext( * Note: naming not final here, it will be renamed in a near future (https://github.com/elastic/kibana/issues/46240) * @deprecated */ - globalConfig__deprecated$: zip( + globalConfig__deprecated$: combineLatest( coreContext.configService.atPath(kibanaConfig.path), coreContext.configService.atPath(elasticsearchConfig.path), coreContext.configService.atPath(pathConfig.path) From 82b62c8b1537b6fabbcef54860d149c70266a044 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Ferna=CC=81ndez=20Haro?= Date: Fri, 29 Nov 2019 10:30:13 +0000 Subject: [PATCH 07/21] Change tests to describe/it + remove "(deprecated)" from the test description --- .../server/plugins/plugin_context.test.ts | 56 ++++++++++--------- 1 file changed, 31 insertions(+), 25 deletions(-) diff --git a/src/core/server/plugins/plugin_context.test.ts b/src/core/server/plugins/plugin_context.test.ts index 5da5c9e4d9b10b..8647d93050e736 100644 --- a/src/core/server/plugins/plugin_context.test.ts +++ b/src/core/server/plugins/plugin_context.test.ts @@ -50,33 +50,39 @@ function createPluginManifest(manifestProps: Partial = {}): Plug }; } -beforeEach(async () => { - coreId = Symbol('core'); - env = Env.createDefault(getEnvOptions()); - const config$ = new BehaviorSubject(new ObjectToConfigAdapter({})); - server = new Server(config$, env, logger); - await server.setupConfigSchemas(); - coreContext = { coreId, env, logger, configService: server.configService }; -}); +describe('Plugin Context', () => { + beforeEach(async () => { + coreId = Symbol('core'); + env = Env.createDefault(getEnvOptions()); + const config$ = new BehaviorSubject(new ObjectToConfigAdapter({})); + server = new Server(config$, env, logger); + await server.setupConfigSchemas(); + coreContext = { coreId, env, logger, configService: server.configService }; + }); -test('should return a globalConfig handler in the context (to be deprecated)', async () => { - const manifest = createPluginManifest(); - const opaqueId = Symbol(); - const pluginInitializerContext = createPluginInitializerContext(coreContext, opaqueId, manifest); + it('should return a globalConfig handler in the context', async () => { + const manifest = createPluginManifest(); + const opaqueId = Symbol(); + const pluginInitializerContext = createPluginInitializerContext( + coreContext, + opaqueId, + manifest + ); - expect(pluginInitializerContext.config.globalConfig__deprecated$).toBeDefined(); + expect(pluginInitializerContext.config.globalConfig__deprecated$).toBeDefined(); - const configObject = await pluginInitializerContext.config.globalConfig__deprecated$ - .pipe(first()) - .toPromise(); - expect(configObject).toStrictEqual({ - kibana: { defaultAppId: 'home', index: '.kibana' }, - elasticsearch: { - shardTimeout: duration(30, 's'), - requestTimeout: duration(30, 's'), - pingTimeout: duration(30, 's'), - startupTimeout: duration(5, 's'), - }, - path: { data: fromRoot('data') }, + const configObject = await pluginInitializerContext.config.globalConfig__deprecated$ + .pipe(first()) + .toPromise(); + expect(configObject).toStrictEqual({ + kibana: { defaultAppId: 'home', index: '.kibana' }, + elasticsearch: { + shardTimeout: duration(30, 's'), + requestTimeout: duration(30, 's'), + pingTimeout: duration(30, 's'), + startupTimeout: duration(5, 's'), + }, + path: { data: fromRoot('data') }, + }); }); }); From dc9b6922a6882269c53788e304b5a386339ff343 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Ferna=CC=81ndez=20Haro?= Date: Fri, 29 Nov 2019 11:35:28 +0000 Subject: [PATCH 08/21] Moving path files to a folder + exposing the config path in the contract --- src/core/server/{path.test.ts => path/index.test.ts} | 2 +- src/core/server/{path.ts => path/index.ts} | 6 ++++-- src/core/server/plugins/plugin_context.test.ts | 2 +- src/core/server/plugins/types.ts | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) rename src/core/server/{path.test.ts => path/index.test.ts} (95%) rename src/core/server/{path.ts => path/index.ts} (88%) diff --git a/src/core/server/path.test.ts b/src/core/server/path/index.test.ts similarity index 95% rename from src/core/server/path.test.ts rename to src/core/server/path/index.test.ts index 440bcc3f0fac0e..048622e1f7eabd 100644 --- a/src/core/server/path.test.ts +++ b/src/core/server/path/index.test.ts @@ -17,8 +17,8 @@ * under the License. */ -import { getConfigPath, getDataPath } from './path'; import { accessSync, constants } from 'fs'; +import { getConfigPath, getDataPath } from './'; describe('Default path finder', () => { it('should find a kibana.yml', () => { diff --git a/src/core/server/path.ts b/src/core/server/path/index.ts similarity index 88% rename from src/core/server/path.ts rename to src/core/server/path/index.ts index ef8a3caeefa2cd..0e0bbf2f9646c6 100644 --- a/src/core/server/path.ts +++ b/src/core/server/path/index.ts @@ -17,10 +17,10 @@ * under the License. */ -import { join } from 'path'; +import { join, resolve } from 'path'; import { accessSync, constants } from 'fs'; import { TypeOf, schema } from '@kbn/config-schema'; -import { fromRoot } from '../utils'; +import { fromRoot } from '../../utils'; const isString = (v: any): v is string => typeof v === 'string'; @@ -65,6 +65,8 @@ export type PathConfigType = TypeOf; export const config = { path: 'path', schema: schema.object({ + // getConfigPath returns the path until the kibana.yml config. We need to move 1 level up for the dir + config: schema.string({ defaultValue: () => resolve(getConfigPath(), '..') }), data: schema.string({ defaultValue: () => getDataPath() }), }), }; diff --git a/src/core/server/plugins/plugin_context.test.ts b/src/core/server/plugins/plugin_context.test.ts index 8647d93050e736..cad1e55d9eef41 100644 --- a/src/core/server/plugins/plugin_context.test.ts +++ b/src/core/server/plugins/plugin_context.test.ts @@ -82,7 +82,7 @@ describe('Plugin Context', () => { pingTimeout: duration(30, 's'), startupTimeout: duration(5, 's'), }, - path: { data: fromRoot('data') }, + path: { config: fromRoot('config'), data: fromRoot('data') }, }); }); }); diff --git a/src/core/server/plugins/types.ts b/src/core/server/plugins/types.ts index b71468ed1b1029..175a94f55c77cf 100644 --- a/src/core/server/plugins/types.ts +++ b/src/core/server/plugins/types.ts @@ -203,7 +203,7 @@ export const SharedGlobalConfigKeys = { // We can add more if really needed kibana: ['defaultAppId', 'index'] as const, elasticsearch: ['shardTimeout', 'requestTimeout', 'pingTimeout', 'startupTimeout'] as const, - path: ['data'] as const, + path: ['config', 'data'] as const, }; export type SharedGlobalConfig = RecursiveReadonly<{ From e341ee23b56fbd0decb53b08db17ee4ee0a69a43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Ferna=CC=81ndez=20Haro?= Date: Fri, 29 Nov 2019 11:42:28 +0000 Subject: [PATCH 09/21] deepFreeze the globalConfig in the pluginContext --- src/core/server/plugins/plugin_context.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/core/server/plugins/plugin_context.ts b/src/core/server/plugins/plugin_context.ts index eaec5e35dda67d..1e65f759394c7b 100644 --- a/src/core/server/plugins/plugin_context.ts +++ b/src/core/server/plugins/plugin_context.ts @@ -34,7 +34,7 @@ import { ElasticsearchConfigType, config as elasticsearchConfig, } from '../elasticsearch/elasticsearch_config'; -import { pick } from '../../utils'; +import { pick, deepFreeze } from '../../utils'; import { CoreSetup, CoreStart } from '..'; /** @@ -89,11 +89,13 @@ export function createPluginInitializerContext( coreContext.configService.atPath(elasticsearchConfig.path), coreContext.configService.atPath(pathConfig.path) ).pipe( - map(([kibana, elasticsearch, path]) => ({ - kibana: pick(kibana, SharedGlobalConfigKeys.kibana), - elasticsearch: pick(elasticsearch, SharedGlobalConfigKeys.elasticsearch), - path: pick(path, SharedGlobalConfigKeys.path), - })) + map(([kibana, elasticsearch, path]) => + deepFreeze({ + kibana: pick(kibana, SharedGlobalConfigKeys.kibana), + elasticsearch: pick(elasticsearch, SharedGlobalConfigKeys.elasticsearch), + path: pick(path, SharedGlobalConfigKeys.path), + }) + ) ), /** From edd8760bd428c925df375e129f82c46a7c7ba7f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Ferna=CC=81ndez=20Haro?= Date: Fri, 29 Nov 2019 12:19:02 +0000 Subject: [PATCH 10/21] Fix types in tests with new path.config --- src/core/server/mocks.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/core/server/mocks.ts b/src/core/server/mocks.ts index c77bc301b9f207..84ca9fa8a96196 100644 --- a/src/core/server/mocks.ts +++ b/src/core/server/mocks.ts @@ -47,6 +47,7 @@ export function pluginInitializerContextConfigMock(config: T) { startupTimeout: duration('30s'), }, path: { + config: '/tmp', data: '/tmp', }, }; From 3502f9a3f97af7dccecbfd7049349eb672a8daf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Ferna=CC=81ndez=20Haro?= Date: Mon, 2 Dec 2019 12:43:57 +0000 Subject: [PATCH 11/21] Move fromRoot and package_json utils to core/server/utils --- src/cli/cli.js | 2 +- src/cli/cluster/cluster_manager.js | 2 +- src/cli/cluster/worker.js | 2 +- src/cli/serve/serve.js | 2 +- src/cli_keystore/cli_keystore.js | 2 +- src/cli_plugin/cli.js | 2 +- src/cli_plugin/install/index.js | 2 +- src/cli_plugin/install/settings.test.js | 2 +- src/cli_plugin/list/index.js | 2 +- src/cli_plugin/list/settings.test.js | 2 +- src/cli_plugin/remove/index.js | 2 +- src/cli_plugin/remove/settings.test.js | 2 +- src/core/server/path/index.ts | 2 +- .../server/plugins/plugin_context.test.ts | 2 +- .../plugins/plugins_service.test.mocks.ts | 2 +- src/core/{ => server}/utils/from_root.ts | 0 src/core/server/utils/index.ts | 21 +++++++++++++++++++ src/core/{ => server}/utils/package_json.ts | 6 +++--- src/core/utils/index.ts | 2 -- .../tests_bundle/find_source_files.js | 3 ++- src/legacy/core_plugins/tests_bundle/index.js | 3 ++- src/legacy/server/config/config.js | 4 ++-- src/legacy/server/i18n/index.js | 3 ++- src/legacy/server/kbn_server.js | 3 ++- src/legacy/server/sass/index.js | 3 ++- src/legacy/server/status/server_status.js | 3 ++- .../ui/public/chrome/api/__tests__/xsrf.js | 3 ++- .../ui/public/legacy_compat/__tests__/xsrf.js | 3 ++- .../ui/ui_bundles/ui_bundles_controller.js | 4 ++-- src/legacy/ui/ui_render/ui_render_mixin.js | 3 ++- src/legacy/utils/artifact_type.ts | 4 ++-- src/optimize/base_optimizer.js | 3 +-- .../dynamic_dll_plugin/dll_compiler.js | 2 +- .../dynamic_dll_plugin/dll_config_model.js | 2 +- src/optimize/index.js | 4 +--- src/optimize/watch/watch_optimizer.js | 2 +- .../services/visual_testing/visual_testing.ts | 2 +- 37 files changed, 69 insertions(+), 44 deletions(-) rename src/core/{ => server}/utils/from_root.ts (100%) create mode 100644 src/core/server/utils/index.ts rename src/core/{ => server}/utils/package_json.ts (84%) diff --git a/src/cli/cli.js b/src/cli/cli.js index cbf3d5bfa19374..36cf82ee50bc14 100644 --- a/src/cli/cli.js +++ b/src/cli/cli.js @@ -18,7 +18,7 @@ */ import _ from 'lodash'; -import { pkg } from '../core/utils'; +import { pkg } from '../core/server/utils'; import Command from './command'; import serveCommand from './serve/serve'; diff --git a/src/cli/cluster/cluster_manager.js b/src/cli/cluster/cluster_manager.js index 5697eab37c3a48..8ddeda93e6a7e1 100644 --- a/src/cli/cluster/cluster_manager.js +++ b/src/cli/cluster/cluster_manager.js @@ -167,7 +167,7 @@ export default class ClusterManager { setupWatching(extraPaths, pluginInternalDirsIgnore) { const chokidar = require('chokidar'); - const { fromRoot } = require('../../core/utils'); + const { fromRoot } = require('../../core/server/utils'); const watchPaths = [ fromRoot('src/core'), diff --git a/src/cli/cluster/worker.js b/src/cli/cluster/worker.js index d430c37263e3a3..4d9aba93d61dba 100644 --- a/src/cli/cluster/worker.js +++ b/src/cli/cluster/worker.js @@ -22,7 +22,7 @@ import cluster from 'cluster'; import { EventEmitter } from 'events'; import { BinderFor } from '../../legacy/utils'; -import { fromRoot } from '../../core/utils'; +import { fromRoot } from '../../core/server/utils'; const cliPath = fromRoot('src/cli'); const baseArgs = _.difference(process.argv.slice(2), ['--no-watch']); diff --git a/src/cli/serve/serve.js b/src/cli/serve/serve.js index fe056684efea76..48b5db318d1c2d 100644 --- a/src/cli/serve/serve.js +++ b/src/cli/serve/serve.js @@ -23,7 +23,7 @@ import { resolve } from 'path'; import url from 'url'; import { IS_KIBANA_DISTRIBUTABLE } from '../../legacy/utils'; -import { fromRoot } from '../../core/utils'; +import { fromRoot } from '../../core/server/utils'; import { getConfigPath } from '../../core/server/path'; import { bootstrap } from '../../core/server'; import { readKeystore } from './read_keystore'; diff --git a/src/cli_keystore/cli_keystore.js b/src/cli_keystore/cli_keystore.js index ebee0b411388cc..47b49d936028e3 100644 --- a/src/cli_keystore/cli_keystore.js +++ b/src/cli_keystore/cli_keystore.js @@ -19,7 +19,7 @@ import { join } from 'path'; -import { pkg } from '../core/utils'; +import { pkg } from '../core/server/utils'; import Command from '../cli/command'; import { getDataPath } from '../core/server/path'; import { Keystore } from '../legacy/server/keystore'; diff --git a/src/cli_plugin/cli.js b/src/cli_plugin/cli.js index c46221ab552ef2..cbe82d973442d0 100644 --- a/src/cli_plugin/cli.js +++ b/src/cli_plugin/cli.js @@ -18,7 +18,7 @@ */ import _ from 'lodash'; -import { pkg } from '../core/utils'; +import { pkg } from '../core/server/utils'; import Command from '../cli/command'; import listCommand from './list'; import installCommand from './install'; diff --git a/src/cli_plugin/install/index.js b/src/cli_plugin/install/index.js index dba0e2c24e745a..ad00fdc9eb9692 100644 --- a/src/cli_plugin/install/index.js +++ b/src/cli_plugin/install/index.js @@ -17,7 +17,7 @@ * under the License. */ -import { fromRoot, pkg } from '../../core/utils'; +import { fromRoot, pkg } from '../../core/server/utils'; import install from './install'; import Logger from '../lib/logger'; import { getConfigPath } from '../../core/server/path'; diff --git a/src/cli_plugin/install/settings.test.js b/src/cli_plugin/install/settings.test.js index 18ab0feda49530..6e674e63d3a729 100644 --- a/src/cli_plugin/install/settings.test.js +++ b/src/cli_plugin/install/settings.test.js @@ -17,7 +17,7 @@ * under the License. */ -import { fromRoot } from '../../core/utils'; +import { fromRoot } from '../../core/server/utils'; import { resolve } from 'path'; import { parseMilliseconds, parse } from './settings'; diff --git a/src/cli_plugin/list/index.js b/src/cli_plugin/list/index.js index 2f5a2f331b2e8d..c0f708b8ccf833 100644 --- a/src/cli_plugin/list/index.js +++ b/src/cli_plugin/list/index.js @@ -17,7 +17,7 @@ * under the License. */ -import { fromRoot } from '../../core/utils'; +import { fromRoot } from '../../core/server/utils'; import list from './list'; import Logger from '../lib/logger'; import { parse } from './settings'; diff --git a/src/cli_plugin/list/settings.test.js b/src/cli_plugin/list/settings.test.js index 32b78723735681..812d6ee294eb67 100644 --- a/src/cli_plugin/list/settings.test.js +++ b/src/cli_plugin/list/settings.test.js @@ -17,7 +17,7 @@ * under the License. */ -import { fromRoot } from '../../core/utils'; +import { fromRoot } from '../../core/server/utils'; import { parse } from './settings'; describe('kibana cli', function () { diff --git a/src/cli_plugin/remove/index.js b/src/cli_plugin/remove/index.js index 3c0099c46bd6f1..d9eebd03bf0ef3 100644 --- a/src/cli_plugin/remove/index.js +++ b/src/cli_plugin/remove/index.js @@ -17,7 +17,7 @@ * under the License. */ -import { fromRoot } from '../../core/utils'; +import { fromRoot } from '../../core/server/utils'; import remove from './remove'; import Logger from '../lib/logger'; import { parse } from './settings'; diff --git a/src/cli_plugin/remove/settings.test.js b/src/cli_plugin/remove/settings.test.js index 8eb9ed1b129e9c..027178ae080464 100644 --- a/src/cli_plugin/remove/settings.test.js +++ b/src/cli_plugin/remove/settings.test.js @@ -17,7 +17,7 @@ * under the License. */ -import { fromRoot } from '../../core/utils'; +import { fromRoot } from '../../core/server/utils'; import { parse } from './settings'; describe('kibana cli', function () { diff --git a/src/core/server/path/index.ts b/src/core/server/path/index.ts index 0e0bbf2f9646c6..d4cb7bc4a26ed5 100644 --- a/src/core/server/path/index.ts +++ b/src/core/server/path/index.ts @@ -20,7 +20,7 @@ import { join, resolve } from 'path'; import { accessSync, constants } from 'fs'; import { TypeOf, schema } from '@kbn/config-schema'; -import { fromRoot } from '../../utils'; +import { fromRoot } from '../utils'; const isString = (v: any): v is string => typeof v === 'string'; diff --git a/src/core/server/plugins/plugin_context.test.ts b/src/core/server/plugins/plugin_context.test.ts index cad1e55d9eef41..ffb4cf10e2439e 100644 --- a/src/core/server/plugins/plugin_context.test.ts +++ b/src/core/server/plugins/plugin_context.test.ts @@ -27,7 +27,7 @@ import { loggingServiceMock } from '../logging/logging_service.mock'; import { getEnvOptions } from '../config/__mocks__/env'; import { PluginManifest } from './types'; import { Server } from '../server'; -import { fromRoot } from '../../utils'; +import { fromRoot } from '../utils'; const logger = loggingServiceMock.create(); diff --git a/src/core/server/plugins/plugins_service.test.mocks.ts b/src/core/server/plugins/plugins_service.test.mocks.ts index 3ec518e4663542..8d4ba12c8375c0 100644 --- a/src/core/server/plugins/plugins_service.test.mocks.ts +++ b/src/core/server/plugins/plugins_service.test.mocks.ts @@ -21,7 +21,7 @@ export const mockPackage = new Proxy( { raw: { __dirname: '/tmp' } as any }, { get: (obj, prop) => obj.raw[prop] } ); -jest.mock('../../../core/utils/package_json', () => ({ pkg: mockPackage })); +jest.mock('../../../core/server/utils/package_json', () => ({ pkg: mockPackage })); export const mockDiscover = jest.fn(); jest.mock('./discovery/plugins_discovery', () => ({ discover: mockDiscover })); diff --git a/src/core/utils/from_root.ts b/src/core/server/utils/from_root.ts similarity index 100% rename from src/core/utils/from_root.ts rename to src/core/server/utils/from_root.ts diff --git a/src/core/server/utils/index.ts b/src/core/server/utils/index.ts new file mode 100644 index 00000000000000..86924c559e5fa0 --- /dev/null +++ b/src/core/server/utils/index.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. + */ + +export * from './from_root'; +export * from './package_json'; diff --git a/src/core/utils/package_json.ts b/src/core/server/utils/package_json.ts similarity index 84% rename from src/core/utils/package_json.ts rename to src/core/server/utils/package_json.ts index 7cc67b413922a3..ab1700e681a929 100644 --- a/src/core/utils/package_json.ts +++ b/src/core/server/utils/package_json.ts @@ -20,8 +20,8 @@ import { dirname } from 'path'; export const pkg = { - __filename: require.resolve('../../../package.json'), - __dirname: dirname(require.resolve('../../../package.json')), + __filename: require.resolve('../../../../package.json'), + __dirname: dirname(require.resolve('../../../../package.json')), // eslint-disable no-var-requires - ...require('../../../package.json'), + ...require('../../../../package.json'), }; diff --git a/src/core/utils/index.ts b/src/core/utils/index.ts index 906d0a0e6db399..98f0800feae79a 100644 --- a/src/core/utils/index.ts +++ b/src/core/utils/index.ts @@ -20,10 +20,8 @@ export * from './assert_never'; export * from './context'; export * from './deep_freeze'; -export * from './from_root'; export * from './get'; export * from './map_to_object'; export * from './merge'; -export * from './package_json'; export * from './pick'; export * from './url'; diff --git a/src/legacy/core_plugins/tests_bundle/find_source_files.js b/src/legacy/core_plugins/tests_bundle/find_source_files.js index 261aa9c1f73674..f880f6ebc4553c 100644 --- a/src/legacy/core_plugins/tests_bundle/find_source_files.js +++ b/src/legacy/core_plugins/tests_bundle/find_source_files.js @@ -18,7 +18,8 @@ */ -import { fromRoot } from '../../../core/utils'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths +import { fromRoot } from '../../../core/server/utils'; import { chain } from 'lodash'; import { resolve } from 'path'; import { fromNode } from 'bluebird'; diff --git a/src/legacy/core_plugins/tests_bundle/index.js b/src/legacy/core_plugins/tests_bundle/index.js index b22fa8bf085d41..4c7ad4c8ea0f4d 100644 --- a/src/legacy/core_plugins/tests_bundle/index.js +++ b/src/legacy/core_plugins/tests_bundle/index.js @@ -23,7 +23,8 @@ import globby from 'globby'; import MultiStream from 'multistream'; import webpackMerge from 'webpack-merge'; -import { fromRoot } from '../../../core/utils'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths +import { fromRoot } from '../../../core/server/utils'; import { replacePlaceholder } from '../../../optimize/public_path_placeholder'; import findSourceFiles from './find_source_files'; import { createTestEntryTemplate } from './tests_entry_template'; diff --git a/src/legacy/server/config/config.js b/src/legacy/server/config/config.js index 05e2996a213c61..2fb79d78e780ef 100644 --- a/src/legacy/server/config/config.js +++ b/src/legacy/server/config/config.js @@ -22,8 +22,8 @@ import _ from 'lodash'; import override from './override'; import createDefaultSchema from './schema'; import { unset, deepCloneWithBuffers as clone, IS_KIBANA_DISTRIBUTABLE } from '../../utils'; -import { pkg } from '../../../core/utils'; - +// eslint-disable-next-line @kbn/eslint/no-restricted-paths +import { pkg } from '../../../core/server/utils'; const schema = Symbol('Joi Schema'); const schemaExts = Symbol('Schema Extensions'); const vals = Symbol('config values'); diff --git a/src/legacy/server/i18n/index.js b/src/legacy/server/i18n/index.js index efae956c5f2f74..50261d3988f6e1 100644 --- a/src/legacy/server/i18n/index.js +++ b/src/legacy/server/i18n/index.js @@ -19,7 +19,8 @@ import { i18n, i18nLoader } from '@kbn/i18n'; import { basename } from 'path'; -import { fromRoot } from '../../../core/utils'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths +import { fromRoot } from '../../../core/server/utils'; import { getTranslationPaths } from './get_translations_path'; import { I18N_RC } from './constants'; diff --git a/src/legacy/server/kbn_server.js b/src/legacy/server/kbn_server.js index ff2cba79dbc2e3..ec41d5d075dce1 100644 --- a/src/legacy/server/kbn_server.js +++ b/src/legacy/server/kbn_server.js @@ -21,7 +21,8 @@ import { constant, once, compact, flatten } from 'lodash'; import { isWorker } from 'cluster'; -import { fromRoot, pkg } from '../../core/utils'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths +import { fromRoot, pkg } from '../../core/server/utils'; import { Config } from './config'; import loggingConfiguration from './logging/configuration'; import httpMixin from './http'; diff --git a/src/legacy/server/sass/index.js b/src/legacy/server/sass/index.js index 0dfa72281e6470..9b16203ec49b7d 100644 --- a/src/legacy/server/sass/index.js +++ b/src/legacy/server/sass/index.js @@ -18,7 +18,8 @@ */ import { IS_KIBANA_DISTRIBUTABLE } from '../../utils'; -import { fromRoot } from '../../../core/utils'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths +import { fromRoot } from '../../../core/server/utils'; export async function sassMixin(kbnServer, server, config) { if (process.env.kbnWorkerType === 'optmzr') { diff --git a/src/legacy/server/status/server_status.js b/src/legacy/server/status/server_status.js index 3a16af879c48f1..deaebe05d3a7b6 100644 --- a/src/legacy/server/status/server_status.js +++ b/src/legacy/server/status/server_status.js @@ -21,7 +21,8 @@ import _ from 'lodash'; import * as states from './states'; import Status from './status'; -import { pkg } from '../../../core/utils'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths +import { pkg } from '../../../core/server/utils'; export default class ServerStatus { constructor(server) { diff --git a/src/legacy/ui/public/chrome/api/__tests__/xsrf.js b/src/legacy/ui/public/chrome/api/__tests__/xsrf.js index f54bf5ef908405..3197b79f407dad 100644 --- a/src/legacy/ui/public/chrome/api/__tests__/xsrf.js +++ b/src/legacy/ui/public/chrome/api/__tests__/xsrf.js @@ -21,7 +21,8 @@ import expect from '@kbn/expect'; import sinon from 'sinon'; import { initChromeXsrfApi } from '../xsrf'; -import { version } from '../../../../../../core/utils/package_json'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths +import { version } from '../../../../../../core/server/utils/package_json'; describe('chrome xsrf apis', function () { const sandbox = sinon.createSandbox(); diff --git a/src/legacy/ui/public/legacy_compat/__tests__/xsrf.js b/src/legacy/ui/public/legacy_compat/__tests__/xsrf.js index 91b38c5d811d54..d66965d00b7e2d 100644 --- a/src/legacy/ui/public/legacy_compat/__tests__/xsrf.js +++ b/src/legacy/ui/public/legacy_compat/__tests__/xsrf.js @@ -23,7 +23,8 @@ import sinon from 'sinon'; import ngMock from 'ng_mock'; import { $setupXsrfRequestInterceptor } from '../angular_config'; -import { version } from '../../../../../core/utils/package_json'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths +import { version } from '../../../../../core/server/utils/package_json'; const xsrfHeader = 'kbn-version'; const newPlatform = { diff --git a/src/legacy/ui/ui_bundles/ui_bundles_controller.js b/src/legacy/ui/ui_bundles/ui_bundles_controller.js index 3e233dbc3da409..7067cfac1b55dc 100644 --- a/src/legacy/ui/ui_bundles/ui_bundles_controller.js +++ b/src/legacy/ui/ui_bundles/ui_bundles_controller.js @@ -27,8 +27,8 @@ import { makeRe } from 'minimatch'; import jsonStableStringify from 'json-stable-stringify'; import { IS_KIBANA_DISTRIBUTABLE } from '../../utils'; -import { fromRoot } from '../../../core/utils'; - +// eslint-disable-next-line @kbn/eslint/no-restricted-paths +import { fromRoot } from '../../../core/server/utils'; import { UiBundle } from './ui_bundle'; import { appEntryTemplate } from './app_entry_template'; diff --git a/src/legacy/ui/ui_render/ui_render_mixin.js b/src/legacy/ui/ui_render/ui_render_mixin.js index da7d154e7d3414..b0361217bfb117 100644 --- a/src/legacy/ui/ui_render/ui_render_mixin.js +++ b/src/legacy/ui/ui_render/ui_render_mixin.js @@ -26,7 +26,8 @@ import { get } from 'lodash'; import { i18n } from '@kbn/i18n'; import { AppBootstrap } from './bootstrap'; import { mergeVariables } from './lib'; -import { fromRoot } from '../../../core/utils'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths +import { fromRoot } from '../../../core/server/utils'; import { createCSPRuleString } from '../../server/csp'; export function uiRenderMixin(kbnServer, server, config) { diff --git a/src/legacy/utils/artifact_type.ts b/src/legacy/utils/artifact_type.ts index d43fdf79639e62..69f728e9e2220b 100644 --- a/src/legacy/utils/artifact_type.ts +++ b/src/legacy/utils/artifact_type.ts @@ -17,7 +17,7 @@ * under the License. */ -import { pkg } from '../../core/utils'; - +// eslint-disable-next-line @kbn/eslint/no-restricted-paths +import { pkg } from '../../core/server/utils'; export const IS_KIBANA_DISTRIBUTABLE = pkg.build && pkg.build.distributable === true; export const IS_KIBANA_RELEASE = pkg.build && pkg.build.release === true; diff --git a/src/optimize/base_optimizer.js b/src/optimize/base_optimizer.js index c44cbbed139074..3b98592fdbbed1 100644 --- a/src/optimize/base_optimizer.js +++ b/src/optimize/base_optimizer.js @@ -32,8 +32,7 @@ import WrapperPlugin from 'wrapper-webpack-plugin'; import { defaults } from 'lodash'; import { IS_KIBANA_DISTRIBUTABLE } from '../legacy/utils'; -import { fromRoot } from '../core/utils'; - +import { fromRoot } from '../core/server/utils'; import { PUBLIC_PATH_PLACEHOLDER } from './public_path_placeholder'; const POSTCSS_CONFIG_PATH = require.resolve('./postcss.config'); diff --git a/src/optimize/dynamic_dll_plugin/dll_compiler.js b/src/optimize/dynamic_dll_plugin/dll_compiler.js index 0c2d363530889a..3f97394effdcce 100644 --- a/src/optimize/dynamic_dll_plugin/dll_compiler.js +++ b/src/optimize/dynamic_dll_plugin/dll_compiler.js @@ -19,7 +19,7 @@ import { configModel } from './dll_config_model'; import { notInNodeModulesOrWebpackShims, notInNodeModules, inDllPluginPublic } from './dll_allowed_modules'; -import { fromRoot } from '../../core/utils'; +import { fromRoot } from '../../core/server/utils'; import { PUBLIC_PATH_PLACEHOLDER } from '../public_path_placeholder'; import fs from 'fs'; import webpack from 'webpack'; diff --git a/src/optimize/dynamic_dll_plugin/dll_config_model.js b/src/optimize/dynamic_dll_plugin/dll_config_model.js index 8daf528fc4536d..b914eab5b17749 100644 --- a/src/optimize/dynamic_dll_plugin/dll_config_model.js +++ b/src/optimize/dynamic_dll_plugin/dll_config_model.js @@ -18,7 +18,7 @@ */ import { IS_KIBANA_DISTRIBUTABLE } from '../../legacy/utils'; -import { fromRoot } from '../../core/utils'; +import { fromRoot } from '../../core/server/utils'; import webpack from 'webpack'; import webpackMerge from 'webpack-merge'; import MiniCssExtractPlugin from 'mini-css-extract-plugin'; diff --git a/src/optimize/index.js b/src/optimize/index.js index 94309e67c2c8e8..27adc241878892 100644 --- a/src/optimize/index.js +++ b/src/optimize/index.js @@ -20,9 +20,7 @@ import FsOptimizer from './fs_optimizer'; import { createBundlesRoute } from './bundles_route'; import { DllCompiler } from './dynamic_dll_plugin'; -import { fromRoot } from '../core/utils'; - -export default async (kbnServer, server, config) => { +import { fromRoot } from '../core/server/utils'; export default async (kbnServer, server, config) => { if (!config.get('optimize.enabled')) return; // the watch optimizer sets up two threads, one is the server listening diff --git a/src/optimize/watch/watch_optimizer.js b/src/optimize/watch/watch_optimizer.js index 331ca41250a29f..d3b19ccdaecd97 100644 --- a/src/optimize/watch/watch_optimizer.js +++ b/src/optimize/watch/watch_optimizer.js @@ -20,7 +20,7 @@ import BaseOptimizer from '../base_optimizer'; import { createBundlesRoute } from '../bundles_route'; import { DllCompiler } from '../dynamic_dll_plugin'; -import { fromRoot } from '../../core/utils'; +import { fromRoot } from '../../core/server/utils'; import * as Rx from 'rxjs'; import { mergeMap, take } from 'rxjs/operators'; diff --git a/test/visual_regression/services/visual_testing/visual_testing.ts b/test/visual_regression/services/visual_testing/visual_testing.ts index 25f36bdc1b893a..fd31a4d8b6e4fd 100644 --- a/test/visual_regression/services/visual_testing/visual_testing.ts +++ b/test/visual_regression/services/visual_testing/visual_testing.ts @@ -23,7 +23,7 @@ import _ from 'lodash'; import testSubjSelector from '@kbn/test-subj-selector'; -import { pkg } from '../../../../src/core/utils'; +import { pkg } from '../../../../src/core/server/utils'; import { FtrProviderContext } from '../../ftr_provider_context'; // @ts-ignore internal js that is passed to the browser as is From 146161a1c39c050f5082913f30026c6a10aeec52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Ferna=CC=81ndez=20Haro?= Date: Mon, 2 Dec 2019 13:42:25 +0000 Subject: [PATCH 12/21] Rename globalConfig to legacy.globalConfig$ --- ...-server.plugininitializercontext.config.md | 4 +- ...-plugin-server.plugininitializercontext.md | 2 +- src/core/server/mocks.ts | 2 +- .../server/plugins/plugin_context.test.ts | 4 +- src/core/server/plugins/plugin_context.ts | 38 ++++++++++--------- src/core/server/plugins/types.ts | 2 +- src/core/server/server.api.md | 6 ++- 7 files changed, 32 insertions(+), 26 deletions(-) diff --git a/docs/development/core/server/kibana-plugin-server.plugininitializercontext.config.md b/docs/development/core/server/kibana-plugin-server.plugininitializercontext.config.md index e051e1369ddd35..56d064dcb290e4 100644 --- a/docs/development/core/server/kibana-plugin-server.plugininitializercontext.config.md +++ b/docs/development/core/server/kibana-plugin-server.plugininitializercontext.config.md @@ -8,7 +8,9 @@ ```typescript config: { - globalConfig__deprecated$: Observable; + legacy: { + globalConfig$: Observable; + }; create: () => Observable; createIfExists: () => Observable; }; diff --git a/docs/development/core/server/kibana-plugin-server.plugininitializercontext.md b/docs/development/core/server/kibana-plugin-server.plugininitializercontext.md index a40a4919d39ba9..c2fadfb779fc97 100644 --- a/docs/development/core/server/kibana-plugin-server.plugininitializercontext.md +++ b/docs/development/core/server/kibana-plugin-server.plugininitializercontext.md @@ -16,7 +16,7 @@ export interface PluginInitializerContext | Property | Type | Description | | --- | --- | --- | -| [config](./kibana-plugin-server.plugininitializercontext.config.md) | {
globalConfig__deprecated$: Observable<SharedGlobalConfig>;
create: <T = ConfigSchema>() => Observable<T>;
createIfExists: <T = ConfigSchema>() => Observable<T | undefined>;
} | | +| [config](./kibana-plugin-server.plugininitializercontext.config.md) | {
legacy: {
globalConfig$: Observable<SharedGlobalConfig>;
};
create: <T = ConfigSchema>() => Observable<T>;
createIfExists: <T = ConfigSchema>() => Observable<T | undefined>;
} | | | [env](./kibana-plugin-server.plugininitializercontext.env.md) | {
mode: EnvironmentMode;
packageInfo: Readonly<PackageInfo>;
} | | | [logger](./kibana-plugin-server.plugininitializercontext.logger.md) | LoggerFactory | | | [opaqueId](./kibana-plugin-server.plugininitializercontext.opaqueid.md) | PluginOpaqueId | | diff --git a/src/core/server/mocks.ts b/src/core/server/mocks.ts index 84ca9fa8a96196..bb1d6358e6c8cf 100644 --- a/src/core/server/mocks.ts +++ b/src/core/server/mocks.ts @@ -53,7 +53,7 @@ export function pluginInitializerContextConfigMock(config: T) { }; const mock: jest.Mocked['config']> = { - globalConfig__deprecated$: of(globalConfig), + legacy: { globalConfig$: of(globalConfig) }, create: jest.fn().mockReturnValue(of(config)), createIfExists: jest.fn().mockReturnValue(of(config)), }; diff --git a/src/core/server/plugins/plugin_context.test.ts b/src/core/server/plugins/plugin_context.test.ts index ffb4cf10e2439e..205cc53a4be0ce 100644 --- a/src/core/server/plugins/plugin_context.test.ts +++ b/src/core/server/plugins/plugin_context.test.ts @@ -69,9 +69,9 @@ describe('Plugin Context', () => { manifest ); - expect(pluginInitializerContext.config.globalConfig__deprecated$).toBeDefined(); + expect(pluginInitializerContext.config.legacy.globalConfig$).toBeDefined(); - const configObject = await pluginInitializerContext.config.globalConfig__deprecated$ + const configObject = await pluginInitializerContext.config.legacy.globalConfig$ .pipe(first()) .toPromise(); expect(configObject).toStrictEqual({ diff --git a/src/core/server/plugins/plugin_context.ts b/src/core/server/plugins/plugin_context.ts index 1e65f759394c7b..90cb3c0d3cf026 100644 --- a/src/core/server/plugins/plugin_context.ts +++ b/src/core/server/plugins/plugin_context.ts @@ -79,24 +79,26 @@ export function createPluginInitializerContext( * Core configuration functionality, enables fetching a subset of the config. */ config: { - /** - * Global configuration - * Note: naming not final here, it will be renamed in a near future (https://github.com/elastic/kibana/issues/46240) - * @deprecated - */ - globalConfig__deprecated$: combineLatest( - coreContext.configService.atPath(kibanaConfig.path), - coreContext.configService.atPath(elasticsearchConfig.path), - coreContext.configService.atPath(pathConfig.path) - ).pipe( - map(([kibana, elasticsearch, path]) => - deepFreeze({ - kibana: pick(kibana, SharedGlobalConfigKeys.kibana), - elasticsearch: pick(elasticsearch, SharedGlobalConfigKeys.elasticsearch), - path: pick(path, SharedGlobalConfigKeys.path), - }) - ) - ), + legacy: { + /** + * Global configuration + * Note: naming not final here, it will be renamed in a near future (https://github.com/elastic/kibana/issues/46240) + * @deprecated + */ + globalConfig$: combineLatest( + coreContext.configService.atPath(kibanaConfig.path), + coreContext.configService.atPath(elasticsearchConfig.path), + coreContext.configService.atPath(pathConfig.path) + ).pipe( + map(([kibana, elasticsearch, path]) => + deepFreeze({ + kibana: pick(kibana, SharedGlobalConfigKeys.kibana), + elasticsearch: pick(elasticsearch, SharedGlobalConfigKeys.elasticsearch), + path: pick(path, SharedGlobalConfigKeys.path), + }) + ) + ), + }, /** * Reads the subset of the config at the `configPath` defined in the plugin diff --git a/src/core/server/plugins/types.ts b/src/core/server/plugins/types.ts index 175a94f55c77cf..f67e79d7f6bf4f 100644 --- a/src/core/server/plugins/types.ts +++ b/src/core/server/plugins/types.ts @@ -225,7 +225,7 @@ export interface PluginInitializerContext { }; logger: LoggerFactory; config: { - globalConfig__deprecated$: Observable; + legacy: { globalConfig$: Observable }; create: () => Observable; createIfExists: () => Observable; }; diff --git a/src/core/server/server.api.md b/src/core/server/server.api.md index 5690cd76f4a4a6..99c04d3f78188b 100644 --- a/src/core/server/server.api.md +++ b/src/core/server/server.api.md @@ -987,7 +987,9 @@ export type PluginInitializer { // (undocumented) config: { - globalConfig__deprecated$: Observable; + legacy: { + globalConfig$: Observable; + }; create: () => Observable; createIfExists: () => Observable; }; @@ -1729,6 +1731,6 @@ export const validBodyOutput: readonly ["data", "stream"]; // // src/core/server/http/router/response.ts:316:3 - (ae-forgotten-export) The symbol "KibanaResponse" needs to be exported by the entry point index.d.ts // src/core/server/plugins/plugins_service.ts:43:5 - (ae-forgotten-export) The symbol "InternalPluginInfo" needs to be exported by the entry point index.d.ts -// src/core/server/plugins/types.ts:228:5 - (ae-forgotten-export) The symbol "SharedGlobalConfig" needs to be exported by the entry point index.d.ts +// src/core/server/plugins/types.ts:228:15 - (ae-forgotten-export) The symbol "SharedGlobalConfig" needs to be exported by the entry point index.d.ts ``` From 8f67cc9b54ab4185dd81a856a3148c947d3e0741 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Ferna=CC=81ndez=20Haro?= Date: Mon, 2 Dec 2019 17:01:08 +0000 Subject: [PATCH 13/21] path.config renamed to path.configDir (not renaming path.data because it might be a breaking change) --- src/core/server/path/index.ts | 2 +- src/core/server/plugins/types.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/server/path/index.ts b/src/core/server/path/index.ts index d4cb7bc4a26ed5..5e25e8e36946e2 100644 --- a/src/core/server/path/index.ts +++ b/src/core/server/path/index.ts @@ -66,7 +66,7 @@ export const config = { path: 'path', schema: schema.object({ // getConfigPath returns the path until the kibana.yml config. We need to move 1 level up for the dir - config: schema.string({ defaultValue: () => resolve(getConfigPath(), '..') }), + configDir: schema.string({ defaultValue: () => resolve(getConfigPath(), '..') }), data: schema.string({ defaultValue: () => getDataPath() }), }), }; diff --git a/src/core/server/plugins/types.ts b/src/core/server/plugins/types.ts index f67e79d7f6bf4f..a44e01e3fabc6a 100644 --- a/src/core/server/plugins/types.ts +++ b/src/core/server/plugins/types.ts @@ -203,7 +203,7 @@ export const SharedGlobalConfigKeys = { // We can add more if really needed kibana: ['defaultAppId', 'index'] as const, elasticsearch: ['shardTimeout', 'requestTimeout', 'pingTimeout', 'startupTimeout'] as const, - path: ['config', 'data'] as const, + path: ['configDir', 'data'] as const, }; export type SharedGlobalConfig = RecursiveReadonly<{ From e729d5e156f5eef3a629bbc32ecc092c926b8e35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Ferna=CC=81ndez=20Haro?= Date: Mon, 2 Dec 2019 17:05:40 +0000 Subject: [PATCH 14/21] Change configDir in mocker as well --- src/core/server/mocks.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/server/mocks.ts b/src/core/server/mocks.ts index bb1d6358e6c8cf..81c53bd79a2224 100644 --- a/src/core/server/mocks.ts +++ b/src/core/server/mocks.ts @@ -47,7 +47,7 @@ export function pluginInitializerContextConfigMock(config: T) { startupTimeout: duration('30s'), }, path: { - config: '/tmp', + configDir: '/tmp', data: '/tmp', }, }; From 2bc791653b71548d19fe91d8bc35ad622d2fa0e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Ferna=CC=81ndez=20Haro?= Date: Mon, 2 Dec 2019 17:54:26 +0000 Subject: [PATCH 15/21] Fix test after config renamed to configDir --- src/core/server/plugins/plugin_context.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/server/plugins/plugin_context.test.ts b/src/core/server/plugins/plugin_context.test.ts index 205cc53a4be0ce..9de22781dc718c 100644 --- a/src/core/server/plugins/plugin_context.test.ts +++ b/src/core/server/plugins/plugin_context.test.ts @@ -82,7 +82,7 @@ describe('Plugin Context', () => { pingTimeout: duration(30, 's'), startupTimeout: duration(5, 's'), }, - path: { config: fromRoot('config'), data: fromRoot('data') }, + path: { configDir: fromRoot('config'), data: fromRoot('data') }, }); }); }); From 83f1d80ef1fb48356691044251e3d54d980b5311 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Ferna=CC=81ndez=20Haro?= Date: Tue, 3 Dec 2019 09:45:09 +0000 Subject: [PATCH 16/21] Fix API docs conflicts --- src/core/server/server.api.md | 1796 +-------------------------------- 1 file changed, 31 insertions(+), 1765 deletions(-) diff --git a/src/core/server/server.api.md b/src/core/server/server.api.md index d5f367842bc5ea..ed6ea058b8f70f 100644 --- a/src/core/server/server.api.md +++ b/src/core/server/server.api.md @@ -1,4 +1,3 @@ -<<<<<<< HEAD ## API Report File for "kibana" > Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). @@ -468,6 +467,33 @@ export interface CallAPIOptions { wrap401Errors?: boolean; } +// @public +export interface Capabilities { + [key: string]: Record>; + catalogue: Record; + management: { + [sectionId: string]: Record; + }; + navLinks: Record; +} + +// @public +export type CapabilitiesProvider = () => Partial; + +// @public +export interface CapabilitiesSetup { + registerProvider(provider: CapabilitiesProvider): void; + registerSwitcher(switcher: CapabilitiesSwitcher): void; +} + +// @public +export interface CapabilitiesStart { + resolveCapabilities(request: KibanaRequest): Promise; +} + +// @public +export type CapabilitiesSwitcher = (request: KibanaRequest, uiCapabilities: Capabilities) => Partial | Promise>; + // @public export class ClusterClient implements IClusterClient { constructor(config: ElasticsearchClientConfig, log: Logger, getAuthHeaders?: GetAuthHeaders); @@ -506,6 +532,8 @@ export type CoreId = symbol; // @public export interface CoreSetup { + // (undocumented) + capabilities: CapabilitiesSetup; // (undocumented) context: ContextSetup; // (undocumented) @@ -520,6 +548,8 @@ export interface CoreSetup { // @public export interface CoreStart { + // (undocumented) + capabilities: CapabilitiesStart; // (undocumented) savedObjects: SavedObjectsServiceStart; } @@ -1735,1767 +1765,3 @@ export const validBodyOutput: readonly ["data", "stream"]; // src/core/server/plugins/types.ts:228:15 - (ae-forgotten-export) The symbol "SharedGlobalConfig" needs to be exported by the entry point index.d.ts ``` -======= -## API Report File for "kibana" - -> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). - -```ts - -import Boom from 'boom'; -import { BulkIndexDocumentsParams } from 'elasticsearch'; -import { CatAliasesParams } from 'elasticsearch'; -import { CatAllocationParams } from 'elasticsearch'; -import { CatCommonParams } from 'elasticsearch'; -import { CatFielddataParams } from 'elasticsearch'; -import { CatHealthParams } from 'elasticsearch'; -import { CatHelpParams } from 'elasticsearch'; -import { CatIndicesParams } from 'elasticsearch'; -import { CatRecoveryParams } from 'elasticsearch'; -import { CatSegmentsParams } from 'elasticsearch'; -import { CatShardsParams } from 'elasticsearch'; -import { CatSnapshotsParams } from 'elasticsearch'; -import { CatTasksParams } from 'elasticsearch'; -import { CatThreadPoolParams } from 'elasticsearch'; -import { ClearScrollParams } from 'elasticsearch'; -import { Client } from 'elasticsearch'; -import { ClusterAllocationExplainParams } from 'elasticsearch'; -import { ClusterGetSettingsParams } from 'elasticsearch'; -import { ClusterHealthParams } from 'elasticsearch'; -import { ClusterPendingTasksParams } from 'elasticsearch'; -import { ClusterPutSettingsParams } from 'elasticsearch'; -import { ClusterRerouteParams } from 'elasticsearch'; -import { ClusterStateParams } from 'elasticsearch'; -import { ClusterStatsParams } from 'elasticsearch'; -import { ConfigOptions } from 'elasticsearch'; -import { CountParams } from 'elasticsearch'; -import { CreateDocumentParams } from 'elasticsearch'; -import { DeleteDocumentByQueryParams } from 'elasticsearch'; -import { DeleteDocumentParams } from 'elasticsearch'; -import { DeleteScriptParams } from 'elasticsearch'; -import { DeleteTemplateParams } from 'elasticsearch'; -import { DetailedPeerCertificate } from 'tls'; -import { Duration } from 'moment'; -import { ExistsParams } from 'elasticsearch'; -import { ExplainParams } from 'elasticsearch'; -import { FieldStatsParams } from 'elasticsearch'; -import { GenericParams } from 'elasticsearch'; -import { GetParams } from 'elasticsearch'; -import { GetResponse } from 'elasticsearch'; -import { GetScriptParams } from 'elasticsearch'; -import { GetSourceParams } from 'elasticsearch'; -import { GetTemplateParams } from 'elasticsearch'; -import { IncomingHttpHeaders } from 'http'; -import { IndexDocumentParams } from 'elasticsearch'; -import { IndicesAnalyzeParams } from 'elasticsearch'; -import { IndicesClearCacheParams } from 'elasticsearch'; -import { IndicesCloseParams } from 'elasticsearch'; -import { IndicesCreateParams } from 'elasticsearch'; -import { IndicesDeleteAliasParams } from 'elasticsearch'; -import { IndicesDeleteParams } from 'elasticsearch'; -import { IndicesDeleteTemplateParams } from 'elasticsearch'; -import { IndicesExistsAliasParams } from 'elasticsearch'; -import { IndicesExistsParams } from 'elasticsearch'; -import { IndicesExistsTemplateParams } from 'elasticsearch'; -import { IndicesExistsTypeParams } from 'elasticsearch'; -import { IndicesFlushParams } from 'elasticsearch'; -import { IndicesFlushSyncedParams } from 'elasticsearch'; -import { IndicesForcemergeParams } from 'elasticsearch'; -import { IndicesGetAliasParams } from 'elasticsearch'; -import { IndicesGetFieldMappingParams } from 'elasticsearch'; -import { IndicesGetMappingParams } from 'elasticsearch'; -import { IndicesGetParams } from 'elasticsearch'; -import { IndicesGetSettingsParams } from 'elasticsearch'; -import { IndicesGetTemplateParams } from 'elasticsearch'; -import { IndicesGetUpgradeParams } from 'elasticsearch'; -import { IndicesOpenParams } from 'elasticsearch'; -import { IndicesPutAliasParams } from 'elasticsearch'; -import { IndicesPutMappingParams } from 'elasticsearch'; -import { IndicesPutSettingsParams } from 'elasticsearch'; -import { IndicesPutTemplateParams } from 'elasticsearch'; -import { IndicesRecoveryParams } from 'elasticsearch'; -import { IndicesRefreshParams } from 'elasticsearch'; -import { IndicesRolloverParams } from 'elasticsearch'; -import { IndicesSegmentsParams } from 'elasticsearch'; -import { IndicesShardStoresParams } from 'elasticsearch'; -import { IndicesShrinkParams } from 'elasticsearch'; -import { IndicesStatsParams } from 'elasticsearch'; -import { IndicesUpdateAliasesParams } from 'elasticsearch'; -import { IndicesUpgradeParams } from 'elasticsearch'; -import { IndicesValidateQueryParams } from 'elasticsearch'; -import { InfoParams } from 'elasticsearch'; -import { IngestDeletePipelineParams } from 'elasticsearch'; -import { IngestGetPipelineParams } from 'elasticsearch'; -import { IngestPutPipelineParams } from 'elasticsearch'; -import { IngestSimulateParams } from 'elasticsearch'; -import { KibanaConfigType } from 'src/core/server/kibana_config'; -import { Logger as Logger_2 } from 'src/core/server/logging'; -import { MGetParams } from 'elasticsearch'; -import { MGetResponse } from 'elasticsearch'; -import { MSearchParams } from 'elasticsearch'; -import { MSearchResponse } from 'elasticsearch'; -import { MSearchTemplateParams } from 'elasticsearch'; -import { MTermVectorsParams } from 'elasticsearch'; -import { NodesHotThreadsParams } from 'elasticsearch'; -import { NodesInfoParams } from 'elasticsearch'; -import { NodesStatsParams } from 'elasticsearch'; -import { ObjectType } from '@kbn/config-schema'; -import { Observable } from 'rxjs'; -import { PeerCertificate } from 'tls'; -import { PingParams } from 'elasticsearch'; -import { PutScriptParams } from 'elasticsearch'; -import { PutTemplateParams } from 'elasticsearch'; -import { Readable } from 'stream'; -import { ReindexParams } from 'elasticsearch'; -import { ReindexRethrottleParams } from 'elasticsearch'; -import { RenderSearchTemplateParams } from 'elasticsearch'; -import { Request } from 'hapi'; -import { ResponseObject } from 'hapi'; -import { ResponseToolkit } from 'hapi'; -import { ScrollParams } from 'elasticsearch'; -import { SearchParams } from 'elasticsearch'; -import { SearchResponse } from 'elasticsearch'; -import { SearchShardsParams } from 'elasticsearch'; -import { SearchTemplateParams } from 'elasticsearch'; -import { Server } from 'hapi'; -import { ShallowPromise } from '@kbn/utility-types'; -import { SnapshotCreateParams } from 'elasticsearch'; -import { SnapshotCreateRepositoryParams } from 'elasticsearch'; -import { SnapshotDeleteParams } from 'elasticsearch'; -import { SnapshotDeleteRepositoryParams } from 'elasticsearch'; -import { SnapshotGetParams } from 'elasticsearch'; -import { SnapshotGetRepositoryParams } from 'elasticsearch'; -import { SnapshotRestoreParams } from 'elasticsearch'; -import { SnapshotStatusParams } from 'elasticsearch'; -import { SnapshotVerifyRepositoryParams } from 'elasticsearch'; -import { Stream } from 'stream'; -import { SuggestParams } from 'elasticsearch'; -import { TasksCancelParams } from 'elasticsearch'; -import { TasksGetParams } from 'elasticsearch'; -import { TasksListParams } from 'elasticsearch'; -import { TermvectorsParams } from 'elasticsearch'; -import { Type } from '@kbn/config-schema'; -import { TypeOf } from '@kbn/config-schema'; -import { UpdateDocumentByQueryParams } from 'elasticsearch'; -import { UpdateDocumentParams } from 'elasticsearch'; -import { Url } from 'url'; - -// @public (undocumented) -export interface APICaller { - // (undocumented) - (endpoint: 'cluster.state', params: ClusterStateParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'bulk', params: BulkIndexDocumentsParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'count', params: CountParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'create', params: CreateDocumentParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'delete', params: DeleteDocumentParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'deleteByQuery', params: DeleteDocumentByQueryParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'deleteScript', params: DeleteScriptParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'deleteTemplate', params: DeleteTemplateParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'exists', params: ExistsParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'explain', params: ExplainParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'fieldStats', params: FieldStatsParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'get', params: GetParams, options?: CallAPIOptions): Promise>; - // (undocumented) - (endpoint: 'getScript', params: GetScriptParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'getSource', params: GetSourceParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'getTemplate', params: GetTemplateParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'index', params: IndexDocumentParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'info', params: InfoParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'mget', params: MGetParams, options?: CallAPIOptions): Promise>; - // (undocumented) - (endpoint: 'msearch', params: MSearchParams, options?: CallAPIOptions): Promise>; - // (undocumented) - (endpoint: 'msearchTemplate', params: MSearchTemplateParams, options?: CallAPIOptions): Promise>; - // (undocumented) - (endpoint: 'mtermvectors', params: MTermVectorsParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'ping', params: PingParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'putScript', params: PutScriptParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'putTemplate', params: PutTemplateParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'reindex', params: ReindexParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'reindexRethrottle', params: ReindexRethrottleParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'renderSearchTemplate', params: RenderSearchTemplateParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'scroll', params: ScrollParams, options?: CallAPIOptions): Promise>; - // (undocumented) - (endpoint: 'search', params: SearchParams, options?: CallAPIOptions): Promise>; - // (undocumented) - (endpoint: 'searchShards', params: SearchShardsParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'searchTemplate', params: SearchTemplateParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'suggest', params: SuggestParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'termvectors', params: TermvectorsParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'update', params: UpdateDocumentParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'updateByQuery', params: UpdateDocumentByQueryParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'cat.aliases', params: CatAliasesParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'cat.allocation', params: CatAllocationParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'cat.count', params: CatAllocationParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'cat.fielddata', params: CatFielddataParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'cat.health', params: CatHealthParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'cat.help', params: CatHelpParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'cat.indices', params: CatIndicesParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'cat.master', params: CatCommonParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'cat.nodeattrs', params: CatCommonParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'cat.nodes', params: CatCommonParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'cat.pendingTasks', params: CatCommonParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'cat.plugins', params: CatCommonParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'cat.recovery', params: CatRecoveryParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'cat.repositories', params: CatCommonParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'cat.segments', params: CatSegmentsParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'cat.shards', params: CatShardsParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'cat.snapshots', params: CatSnapshotsParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'cat.tasks', params: CatTasksParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'cat.threadPool', params: CatThreadPoolParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'cluster.allocationExplain', params: ClusterAllocationExplainParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'cluster.getSettings', params: ClusterGetSettingsParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'cluster.health', params: ClusterHealthParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'cluster.pendingTasks', params: ClusterPendingTasksParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'cluster.putSettings', params: ClusterPutSettingsParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'cluster.reroute', params: ClusterRerouteParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'clearScroll', params: ClearScrollParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'cluster.stats', params: ClusterStatsParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'indices.analyze', params: IndicesAnalyzeParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'indices.clearCache', params: IndicesClearCacheParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'indices.close', params: IndicesCloseParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'indices.create', params: IndicesCreateParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'indices.delete', params: IndicesDeleteParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'indices.deleteAlias', params: IndicesDeleteAliasParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'indices.deleteTemplate', params: IndicesDeleteTemplateParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'indices.exists', params: IndicesExistsParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'indices.existsAlias', params: IndicesExistsAliasParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'indices.existsTemplate', params: IndicesExistsTemplateParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'indices.existsType', params: IndicesExistsTypeParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'indices.flush', params: IndicesFlushParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'indices.flushSynced', params: IndicesFlushSyncedParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'indices.forcemerge', params: IndicesForcemergeParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'indices.get', params: IndicesGetParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'indices.getAlias', params: IndicesGetAliasParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'indices.getFieldMapping', params: IndicesGetFieldMappingParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'indices.getMapping', params: IndicesGetMappingParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'indices.getSettings', params: IndicesGetSettingsParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'indices.getTemplate', params: IndicesGetTemplateParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'indices.getUpgrade', params: IndicesGetUpgradeParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'indices.open', params: IndicesOpenParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'indices.putAlias', params: IndicesPutAliasParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'indices.putMapping', params: IndicesPutMappingParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'indices.putSettings', params: IndicesPutSettingsParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'indices.putTemplate', params: IndicesPutTemplateParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'indices.recovery', params: IndicesRecoveryParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'indices.refresh', params: IndicesRefreshParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'indices.rollover', params: IndicesRolloverParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'indices.segments', params: IndicesSegmentsParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'indices.shardStores', params: IndicesShardStoresParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'indices.shrink', params: IndicesShrinkParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'indices.stats', params: IndicesStatsParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'indices.updateAliases', params: IndicesUpdateAliasesParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'indices.upgrade', params: IndicesUpgradeParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'indices.validateQuery', params: IndicesValidateQueryParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'ingest.deletePipeline', params: IngestDeletePipelineParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'ingest.getPipeline', params: IngestGetPipelineParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'ingest.putPipeline', params: IngestPutPipelineParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'ingest.simulate', params: IngestSimulateParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'nodes.hotThreads', params: NodesHotThreadsParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'nodes.info', params: NodesInfoParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'nodes.stats', params: NodesStatsParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'snapshot.create', params: SnapshotCreateParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'snapshot.createRepository', params: SnapshotCreateRepositoryParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'snapshot.delete', params: SnapshotDeleteParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'snapshot.deleteRepository', params: SnapshotDeleteRepositoryParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'snapshot.get', params: SnapshotGetParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'snapshot.getRepository', params: SnapshotGetRepositoryParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'snapshot.restore', params: SnapshotRestoreParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'snapshot.status', params: SnapshotStatusParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'snapshot.verifyRepository', params: SnapshotVerifyRepositoryParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'tasks.cancel', params: TasksCancelParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'tasks.get', params: TasksGetParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'tasks.list', params: TasksListParams, options?: CallAPIOptions): ReturnType; - // (undocumented) - (endpoint: 'transport.request', clientParams: AssistantAPIClientParams, options?: CallAPIOptions): Promise; - // (undocumented) - (endpoint: 'transport.request', clientParams: DeprecationAPIClientParams, options?: CallAPIOptions): Promise; - // (undocumented) - (endpoint: string, clientParams?: Record, options?: CallAPIOptions): Promise; -} - -// @public (undocumented) -export interface AssistanceAPIResponse { - // (undocumented) - indices: { - [indexName: string]: { - action_required: MIGRATION_ASSISTANCE_INDEX_ACTION; - }; - }; -} - -// @public (undocumented) -export interface AssistantAPIClientParams extends GenericParams { - // (undocumented) - method: 'GET'; - // (undocumented) - path: '/_migration/assistance'; -} - -// @public (undocumented) -export interface Authenticated extends AuthResultParams { - // (undocumented) - type: AuthResultType.authenticated; -} - -// @public -export type AuthenticationHandler = (request: KibanaRequest, response: LifecycleResponseFactory, toolkit: AuthToolkit) => AuthResult | IKibanaResponse | Promise; - -// @public -export type AuthHeaders = Record; - -// @public (undocumented) -export type AuthResult = Authenticated; - -// @public -export interface AuthResultParams { - requestHeaders?: AuthHeaders; - responseHeaders?: AuthHeaders; - state?: Record; -} - -// @public (undocumented) -export enum AuthResultType { - // (undocumented) - authenticated = "authenticated" -} - -// @public -export enum AuthStatus { - authenticated = "authenticated", - unauthenticated = "unauthenticated", - unknown = "unknown" -} - -// @public -export interface AuthToolkit { - authenticated: (data?: AuthResultParams) => AuthResult; -} - -// @public -export class BasePath { - // @internal - constructor(serverBasePath?: string); - get: (request: KibanaRequest | LegacyRequest) => string; - prepend: (path: string) => string; - remove: (path: string) => string; - readonly serverBasePath: string; - set: (request: KibanaRequest | LegacyRequest, requestSpecificBasePath: string) => void; -} - -// Warning: (ae-forgotten-export) The symbol "BootstrapArgs" needs to be exported by the entry point index.d.ts -// -// @internal (undocumented) -export function bootstrap({ configs, cliArgs, applyConfigOverrides, features, }: BootstrapArgs): Promise; - -// @public -export interface CallAPIOptions { - signal?: AbortSignal; - wrap401Errors?: boolean; -} - -// @public -export interface Capabilities { - [key: string]: Record>; - catalogue: Record; - management: { - [sectionId: string]: Record; - }; - navLinks: Record; -} - -// @public -export type CapabilitiesProvider = () => Partial; - -// @public -export interface CapabilitiesSetup { - registerProvider(provider: CapabilitiesProvider): void; - registerSwitcher(switcher: CapabilitiesSwitcher): void; -} - -// @public -export interface CapabilitiesStart { - resolveCapabilities(request: KibanaRequest): Promise; -} - -// @public -export type CapabilitiesSwitcher = (request: KibanaRequest, uiCapabilities: Capabilities) => Partial | Promise>; - -// @public -export class ClusterClient implements IClusterClient { - constructor(config: ElasticsearchClientConfig, log: Logger, getAuthHeaders?: GetAuthHeaders); - asScoped(request?: KibanaRequest | LegacyRequest | FakeRequest): IScopedClusterClient; - callAsInternalUser: APICaller; - close(): void; - } - -// @public (undocumented) -export type ConfigPath = string | string[]; - -// @internal (undocumented) -export class ConfigService { - // Warning: (ae-forgotten-export) The symbol "Config" needs to be exported by the entry point index.d.ts - // Warning: (ae-forgotten-export) The symbol "Env" needs to be exported by the entry point index.d.ts - constructor(config$: Observable, env: Env, logger: LoggerFactory); - atPath(path: ConfigPath): Observable; - getConfig$(): Observable; - // (undocumented) - getUnusedPaths(): Promise; - // (undocumented) - getUsedPaths(): Promise; - // (undocumented) - isEnabledAtPath(path: ConfigPath): Promise; - optionalAtPath(path: ConfigPath): Observable; - setSchema(path: ConfigPath, schema: Type): Promise; - } - -// @public -export interface ContextSetup { - createContextContainer>(): IContextContainer; -} - -// @internal (undocumented) -export type CoreId = symbol; - -// @public -export interface CoreSetup { - // (undocumented) - capabilities: CapabilitiesSetup; - // (undocumented) - context: ContextSetup; - // (undocumented) - elasticsearch: ElasticsearchServiceSetup; - // (undocumented) - http: HttpServiceSetup; - // (undocumented) - savedObjects: SavedObjectsServiceSetup; - // (undocumented) - uiSettings: UiSettingsServiceSetup; -} - -// @public -export interface CoreStart { - // (undocumented) - capabilities: CapabilitiesStart; - // (undocumented) - savedObjects: SavedObjectsServiceStart; -} - -// @public -export interface CustomHttpResponseOptions { - body?: T; - headers?: ResponseHeaders; - // (undocumented) - statusCode: number; -} - -// @public (undocumented) -export interface DeprecationAPIClientParams extends GenericParams { - // (undocumented) - method: 'GET'; - // (undocumented) - path: '/_migration/deprecations'; -} - -// @public (undocumented) -export interface DeprecationAPIResponse { - // (undocumented) - cluster_settings: DeprecationInfo[]; - // (undocumented) - index_settings: IndexSettingsDeprecationInfo; - // (undocumented) - ml_settings: DeprecationInfo[]; - // (undocumented) - node_settings: DeprecationInfo[]; -} - -// @public (undocumented) -export interface DeprecationInfo { - // (undocumented) - details?: string; - // (undocumented) - level: MIGRATION_DEPRECATION_LEVEL; - // (undocumented) - message: string; - // (undocumented) - url: string; -} - -// @public -export interface DiscoveredPlugin { - readonly configPath: ConfigPath; - readonly id: PluginName; - readonly optionalPlugins: readonly PluginName[]; - readonly requiredPlugins: readonly PluginName[]; -} - -// Warning: (ae-forgotten-export) The symbol "ElasticsearchConfig" needs to be exported by the entry point index.d.ts -// -// @public (undocumented) -export type ElasticsearchClientConfig = Pick & Pick & { - pingTimeout?: ElasticsearchConfig['pingTimeout'] | ConfigOptions['pingTimeout']; - requestTimeout?: ElasticsearchConfig['requestTimeout'] | ConfigOptions['requestTimeout']; - sniffInterval?: ElasticsearchConfig['sniffInterval'] | ConfigOptions['sniffInterval']; - ssl?: Partial; -}; - -// @public (undocumented) -export interface ElasticsearchError extends Boom { - // (undocumented) - [code]?: string; -} - -// @public -export class ElasticsearchErrorHelpers { - // (undocumented) - static decorateNotAuthorizedError(error: Error, reason?: string): ElasticsearchError; - // (undocumented) - static isNotAuthorizedError(error: any): error is ElasticsearchError; -} - -// @public (undocumented) -export interface ElasticsearchServiceSetup { - readonly adminClient$: Observable; - readonly createClient: (type: string, clientConfig?: Partial) => IClusterClient; - readonly dataClient$: Observable; -} - -// @public (undocumented) -export interface EnvironmentMode { - // (undocumented) - dev: boolean; - // (undocumented) - name: 'development' | 'production'; - // (undocumented) - prod: boolean; -} - -// @public -export interface ErrorHttpResponseOptions { - body?: ResponseError; - headers?: ResponseHeaders; -} - -// @public -export interface FakeRequest { - headers: Headers; -} - -// @public -export type GetAuthHeaders = (request: KibanaRequest | LegacyRequest) => AuthHeaders | undefined; - -// @public -export type GetAuthState = (request: KibanaRequest | LegacyRequest) => { - status: AuthStatus; - state: unknown; -}; - -// @public -export type HandlerContextType> = T extends HandlerFunction ? U : never; - -// @public -export type HandlerFunction = (context: T, ...args: any[]) => any; - -// @public -export type HandlerParameters> = T extends (context: any, ...args: infer U) => any ? U : never; - -// @public -export type Headers = { - [header in KnownHeaders]?: string | string[] | undefined; -} & { - [header: string]: string | string[] | undefined; -}; - -// @public -export interface HttpResponseOptions { - body?: HttpResponsePayload; - headers?: ResponseHeaders; -} - -// @public -export type HttpResponsePayload = undefined | string | Record | Buffer | Stream; - -// @public -export interface HttpServiceSetup { - basePath: IBasePath; - createCookieSessionStorageFactory: (cookieOptions: SessionStorageCookieOptions) => Promise>; - createRouter: () => IRouter; - isTlsEnabled: boolean; - registerAuth: (handler: AuthenticationHandler) => void; - registerOnPostAuth: (handler: OnPostAuthHandler) => void; - registerOnPreAuth: (handler: OnPreAuthHandler) => void; - registerRouteHandlerContext: (contextName: T, provider: RequestHandlerContextProvider) => RequestHandlerContextContainer; -} - -// @public (undocumented) -export interface HttpServiceStart { - isListening: (port: number) => boolean; -} - -// @public -export type IBasePath = Pick; - -// @public -export type IClusterClient = Pick; - -// @public -export interface IContextContainer> { - createHandler(pluginOpaqueId: PluginOpaqueId, handler: THandler): (...rest: HandlerParameters) => ShallowPromise>; - registerContext>(pluginOpaqueId: PluginOpaqueId, contextName: TContextName, provider: IContextProvider): this; -} - -// @public -export type IContextProvider, TContextName extends keyof HandlerContextType> = (context: Partial>, ...rest: HandlerParameters) => Promise[TContextName]> | HandlerContextType[TContextName]; - -// @public -export interface IKibanaResponse { - // (undocumented) - readonly options: HttpResponseOptions; - // (undocumented) - readonly payload?: T; - // (undocumented) - readonly status: number; -} - -// @public -export interface IKibanaSocket { - readonly authorizationError?: Error; - readonly authorized?: boolean; - // (undocumented) - getPeerCertificate(detailed: true): DetailedPeerCertificate | null; - // (undocumented) - getPeerCertificate(detailed: false): PeerCertificate | null; - getPeerCertificate(detailed?: boolean): PeerCertificate | DetailedPeerCertificate | null; -} - -// @public (undocumented) -export interface IndexSettingsDeprecationInfo { - // (undocumented) - [indexName: string]: DeprecationInfo[]; -} - -// @public -export interface IRouter { - delete: RouteRegistrar<'delete'>; - get: RouteRegistrar<'get'>; - // Warning: (ae-forgotten-export) The symbol "RouterRoute" needs to be exported by the entry point index.d.ts - // - // @internal - getRoutes: () => RouterRoute[]; - handleLegacyErrors:

(handler: RequestHandler) => RequestHandler; - patch: RouteRegistrar<'patch'>; - post: RouteRegistrar<'post'>; - put: RouteRegistrar<'put'>; - routerPath: string; -} - -// @public -export type IsAuthenticated = (request: KibanaRequest | LegacyRequest) => boolean; - -// @public -export type ISavedObjectsRepository = Pick; - -// @public -export type IScopedClusterClient = Pick; - -// @public -export interface IUiSettingsClient { - get: (key: string) => Promise; - getAll: () => Promise>; - getRegistered: () => Readonly>; - getUserProvided: () => Promise>>; - isOverridden: (key: string) => boolean; - remove: (key: string) => Promise; - removeMany: (keys: string[]) => Promise; - set: (key: string, value: any) => Promise; - setMany: (changes: Record) => Promise; -} - -// @public -export class KibanaRequest { - // @internal (undocumented) - protected readonly [requestSymbol]: Request; - constructor(request: Request, params: Params, query: Query, body: Body, withoutSecretHeaders: boolean); - // (undocumented) - readonly body: Body; - // @internal - static from

| Type>(req: Request, routeSchemas?: RouteSchemas, withoutSecretHeaders?: boolean): KibanaRequest; - readonly headers: Headers; - // (undocumented) - readonly params: Params; - // (undocumented) - readonly query: Query; - readonly route: RecursiveReadonly>; - // (undocumented) - readonly socket: IKibanaSocket; - readonly url: Url; - } - -// @public -export interface KibanaRequestRoute { - // (undocumented) - method: Method; - // (undocumented) - options: KibanaRequestRouteOptions; - // (undocumented) - path: string; -} - -// @public -export type KibanaRequestRouteOptions = Method extends 'get' | 'options' ? Required, 'body'>> : Required>; - -// @public -export type KibanaResponseFactory = typeof kibanaResponseFactory; - -// @public -export const kibanaResponseFactory: { - custom: | Buffer | Stream | { - message: string | Error; - attributes?: Record | undefined; - } | undefined>(options: CustomHttpResponseOptions) => KibanaResponse; - badRequest: (options?: ErrorHttpResponseOptions) => KibanaResponse; - unauthorized: (options?: ErrorHttpResponseOptions) => KibanaResponse; - forbidden: (options?: ErrorHttpResponseOptions) => KibanaResponse; - notFound: (options?: ErrorHttpResponseOptions) => KibanaResponse; - conflict: (options?: ErrorHttpResponseOptions) => KibanaResponse; - internalError: (options?: ErrorHttpResponseOptions) => KibanaResponse; - customError: (options: CustomHttpResponseOptions) => KibanaResponse; - redirected: (options: RedirectResponseOptions) => KibanaResponse | Buffer | Stream>; - ok: (options?: HttpResponseOptions) => KibanaResponse | Buffer | Stream>; - accepted: (options?: HttpResponseOptions) => KibanaResponse | Buffer | Stream>; - noContent: (options?: HttpResponseOptions) => KibanaResponse; -}; - -// Warning: (ae-forgotten-export) The symbol "KnownKeys" needs to be exported by the entry point index.d.ts -// -// @public -export type KnownHeaders = KnownKeys; - -// @public @deprecated (undocumented) -export interface LegacyRequest extends Request { -} - -// @public @deprecated (undocumented) -export interface LegacyServiceSetupDeps { - // Warning: (ae-forgotten-export) The symbol "InternalCoreSetup" needs to be exported by the entry point index.d.ts - // - // (undocumented) - core: InternalCoreSetup & { - plugins: PluginsServiceSetup; - }; - // (undocumented) - plugins: Record; -} - -// @public @deprecated (undocumented) -export interface LegacyServiceStartDeps { - // Warning: (ae-forgotten-export) The symbol "InternalCoreStart" needs to be exported by the entry point index.d.ts - // - // (undocumented) - core: InternalCoreStart & { - plugins: PluginsServiceStart; - }; - // (undocumented) - plugins: Record; -} - -// Warning: (ae-forgotten-export) The symbol "lifecycleResponseFactory" needs to be exported by the entry point index.d.ts -// -// @public -export type LifecycleResponseFactory = typeof lifecycleResponseFactory; - -// @public -export interface Logger { - debug(message: string, meta?: LogMeta): void; - error(errorOrMessage: string | Error, meta?: LogMeta): void; - fatal(errorOrMessage: string | Error, meta?: LogMeta): void; - info(message: string, meta?: LogMeta): void; - // @internal (undocumented) - log(record: LogRecord): void; - trace(message: string, meta?: LogMeta): void; - warn(errorOrMessage: string | Error, meta?: LogMeta): void; -} - -// @public -export interface LoggerFactory { - get(...contextParts: string[]): Logger; -} - -// @internal -export class LogLevel { - // (undocumented) - static readonly All: LogLevel; - // (undocumented) - static readonly Debug: LogLevel; - // (undocumented) - static readonly Error: LogLevel; - // (undocumented) - static readonly Fatal: LogLevel; - static fromId(level: LogLevelId): LogLevel; - // Warning: (ae-forgotten-export) The symbol "LogLevelId" needs to be exported by the entry point index.d.ts - // - // (undocumented) - readonly id: LogLevelId; - // (undocumented) - static readonly Info: LogLevel; - // (undocumented) - static readonly Off: LogLevel; - supports(level: LogLevel): boolean; - // (undocumented) - static readonly Trace: LogLevel; - // (undocumented) - readonly value: number; - // (undocumented) - static readonly Warn: LogLevel; -} - -// @public -export interface LogMeta { - // (undocumented) - [key: string]: any; -} - -// @internal -export interface LogRecord { - // (undocumented) - context: string; - // (undocumented) - error?: Error; - // (undocumented) - level: LogLevel; - // (undocumented) - message: string; - // (undocumented) - meta?: { - [name: string]: any; - }; - // (undocumented) - timestamp: Date; -} - -// @public (undocumented) -export type MIGRATION_ASSISTANCE_INDEX_ACTION = 'upgrade' | 'reindex'; - -// @public (undocumented) -export type MIGRATION_DEPRECATION_LEVEL = 'none' | 'info' | 'warning' | 'critical'; - -// @public -export type MutatingOperationRefreshSetting = boolean | 'wait_for'; - -// Warning: (ae-forgotten-export) The symbol "OnPostAuthResult" needs to be exported by the entry point index.d.ts -// -// @public -export type OnPostAuthHandler = (request: KibanaRequest, response: LifecycleResponseFactory, toolkit: OnPostAuthToolkit) => OnPostAuthResult | KibanaResponse | Promise; - -// @public -export interface OnPostAuthToolkit { - next: () => OnPostAuthResult; -} - -// Warning: (ae-forgotten-export) The symbol "OnPreAuthResult" needs to be exported by the entry point index.d.ts -// -// @public -export type OnPreAuthHandler = (request: KibanaRequest, response: LifecycleResponseFactory, toolkit: OnPreAuthToolkit) => OnPreAuthResult | KibanaResponse | Promise; - -// @public -export interface OnPreAuthToolkit { - next: () => OnPreAuthResult; - rewriteUrl: (url: string) => OnPreAuthResult; -} - -// @public (undocumented) -export interface PackageInfo { - // (undocumented) - branch: string; - // (undocumented) - buildNum: number; - // (undocumented) - buildSha: string; - // (undocumented) - dist: boolean; - // (undocumented) - version: string; -} - -// @public -export interface Plugin { - // (undocumented) - setup(core: CoreSetup, plugins: TPluginsSetup): TSetup | Promise; - // (undocumented) - start(core: CoreStart, plugins: TPluginsStart): TStart | Promise; - // (undocumented) - stop?(): void; -} - -// @public -export interface PluginConfigDescriptor { - exposeToBrowser?: { - [P in keyof T]?: boolean; - }; - schema: PluginConfigSchema; -} - -// @public -export type PluginConfigSchema = Type; - -// @public -export type PluginInitializer = (core: PluginInitializerContext) => Plugin; - -// @public -export interface PluginInitializerContext { - // (undocumented) - config: { - create: () => Observable; - createIfExists: () => Observable; - }; - // (undocumented) - env: { - mode: EnvironmentMode; - packageInfo: Readonly; - }; - // (undocumented) - logger: LoggerFactory; - // (undocumented) - opaqueId: PluginOpaqueId; -} - -// @public -export interface PluginManifest { - readonly configPath: ConfigPath; - readonly id: PluginName; - readonly kibanaVersion: string; - readonly optionalPlugins: readonly PluginName[]; - readonly requiredPlugins: readonly PluginName[]; - readonly server: boolean; - readonly ui: boolean; - readonly version: string; -} - -// @public -export type PluginName = string; - -// @public (undocumented) -export type PluginOpaqueId = symbol; - -// @public (undocumented) -export interface PluginsServiceSetup { - // (undocumented) - contracts: Map; - // (undocumented) - uiPlugins: { - internal: Map; - public: Map; - browserConfigs: Map>; - }; -} - -// @public (undocumented) -export interface PluginsServiceStart { - // (undocumented) - contracts: Map; -} - -// Warning: (ae-forgotten-export) The symbol "RecursiveReadonlyArray" needs to be exported by the entry point index.d.ts -// -// @public (undocumented) -export type RecursiveReadonly = T extends (...args: any[]) => any ? T : T extends any[] ? RecursiveReadonlyArray : T extends object ? Readonly<{ - [K in keyof T]: RecursiveReadonly; -}> : T; - -// @public -export type RedirectResponseOptions = HttpResponseOptions & { - headers: { - location: string; - }; -}; - -// @public -export type RequestHandler

| Type, Method extends RouteMethod = any> = (context: RequestHandlerContext, request: KibanaRequest, TypeOf, TypeOf, Method>, response: KibanaResponseFactory) => IKibanaResponse | Promise>; - -// @public -export interface RequestHandlerContext { - // (undocumented) - core: { - savedObjects: { - client: SavedObjectsClientContract; - }; - elasticsearch: { - dataClient: IScopedClusterClient; - adminClient: IScopedClusterClient; - }; - uiSettings: { - client: IUiSettingsClient; - }; - }; -} - -// @public -export type RequestHandlerContextContainer = IContextContainer>; - -// @public -export type RequestHandlerContextProvider = IContextProvider, TContextName>; - -// @public -export type ResponseError = string | Error | { - message: string | Error; - attributes?: ResponseErrorAttributes; -}; - -// @public -export type ResponseErrorAttributes = Record; - -// @public -export type ResponseHeaders = { - [header in KnownHeaders]?: string | string[]; -} & { - [header: string]: string | string[]; -}; - -// @public -export interface RouteConfig

| Type, Method extends RouteMethod> { - options?: RouteConfigOptions; - path: string; - validate: RouteSchemas | false; -} - -// @public -export interface RouteConfigOptions { - authRequired?: boolean; - body?: Method extends 'get' | 'options' ? undefined : RouteConfigOptionsBody; - tags?: readonly string[]; -} - -// @public -export interface RouteConfigOptionsBody { - accepts?: RouteContentType | RouteContentType[] | string | string[]; - maxBytes?: number; - output?: typeof validBodyOutput[number]; - parse?: boolean | 'gunzip'; -} - -// @public -export type RouteContentType = 'application/json' | 'application/*+json' | 'application/octet-stream' | 'application/x-www-form-urlencoded' | 'multipart/form-data' | 'text/*'; - -// @public -export type RouteMethod = 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options'; - -// @public -export type RouteRegistrar =

| Type>(route: RouteConfig, handler: RequestHandler) => void; - -// @public -export interface RouteSchemas

| Type> { - // (undocumented) - body?: B; - // (undocumented) - params?: P; - // (undocumented) - query?: Q; -} - -// @public (undocumented) -export interface SavedObject { - attributes: T; - // (undocumented) - error?: { - message: string; - statusCode: number; - }; - id: string; - migrationVersion?: SavedObjectsMigrationVersion; - references: SavedObjectReference[]; - type: string; - updated_at?: string; - version?: string; -} - -// @public -export type SavedObjectAttribute = SavedObjectAttributeSingle | SavedObjectAttributeSingle[]; - -// @public -export interface SavedObjectAttributes { - // (undocumented) - [key: string]: SavedObjectAttribute; -} - -// @public -export type SavedObjectAttributeSingle = string | number | boolean | null | undefined | SavedObjectAttributes; - -// @public -export interface SavedObjectReference { - // (undocumented) - id: string; - // (undocumented) - name: string; - // (undocumented) - type: string; -} - -// @public (undocumented) -export interface SavedObjectsBaseOptions { - namespace?: string; -} - -// @public (undocumented) -export interface SavedObjectsBulkCreateObject { - // (undocumented) - attributes: T; - // (undocumented) - id?: string; - migrationVersion?: SavedObjectsMigrationVersion; - // (undocumented) - references?: SavedObjectReference[]; - // (undocumented) - type: string; -} - -// @public (undocumented) -export interface SavedObjectsBulkGetObject { - fields?: string[]; - // (undocumented) - id: string; - // (undocumented) - type: string; -} - -// @public (undocumented) -export interface SavedObjectsBulkResponse { - // (undocumented) - saved_objects: Array>; -} - -// @public (undocumented) -export interface SavedObjectsBulkResponse { - // (undocumented) - saved_objects: Array>; -} - -// @public (undocumented) -export interface SavedObjectsBulkUpdateObject extends Pick { - attributes: Partial; - id: string; - type: string; -} - -// @public (undocumented) -export interface SavedObjectsBulkUpdateOptions extends SavedObjectsBaseOptions { - refresh?: MutatingOperationRefreshSetting; -} - -// @public (undocumented) -export interface SavedObjectsBulkUpdateResponse { - // (undocumented) - saved_objects: Array>; -} - -// @public (undocumented) -export class SavedObjectsClient { - // @internal - constructor(repository: ISavedObjectsRepository); - bulkCreate(objects: Array>, options?: SavedObjectsCreateOptions): Promise>; - bulkGet(objects?: SavedObjectsBulkGetObject[], options?: SavedObjectsBaseOptions): Promise>; - bulkUpdate(objects: Array>, options?: SavedObjectsBulkUpdateOptions): Promise>; - create(type: string, attributes: T, options?: SavedObjectsCreateOptions): Promise>; - delete(type: string, id: string, options?: SavedObjectsDeleteOptions): Promise<{}>; - // (undocumented) - errors: typeof SavedObjectsErrorHelpers; - // (undocumented) - static errors: typeof SavedObjectsErrorHelpers; - find(options: SavedObjectsFindOptions): Promise>; - get(type: string, id: string, options?: SavedObjectsBaseOptions): Promise>; - update(type: string, id: string, attributes: Partial, options?: SavedObjectsUpdateOptions): Promise>; -} - -// @public -export type SavedObjectsClientContract = Pick; - -// @public -export type SavedObjectsClientFactory = ({ request, }: { - request: Request; -}) => SavedObjectsClientContract; - -// @public -export interface SavedObjectsClientProviderOptions { - // (undocumented) - excludedWrappers?: string[]; -} - -// @public -export type SavedObjectsClientWrapperFactory = (options: SavedObjectsClientWrapperOptions) => SavedObjectsClientContract; - -// @public -export interface SavedObjectsClientWrapperOptions { - // (undocumented) - client: SavedObjectsClientContract; - // (undocumented) - request: Request; -} - -// @public (undocumented) -export interface SavedObjectsCreateOptions extends SavedObjectsBaseOptions { - id?: string; - migrationVersion?: SavedObjectsMigrationVersion; - overwrite?: boolean; - // (undocumented) - references?: SavedObjectReference[]; - refresh?: MutatingOperationRefreshSetting; -} - -// @public (undocumented) -export interface SavedObjectsDeleteByNamespaceOptions extends SavedObjectsBaseOptions { - refresh?: MutatingOperationRefreshSetting; -} - -// @public (undocumented) -export interface SavedObjectsDeleteOptions extends SavedObjectsBaseOptions { - refresh?: MutatingOperationRefreshSetting; -} - -// @public (undocumented) -export class SavedObjectsErrorHelpers { - // (undocumented) - static createBadRequestError(reason?: string): DecoratedError; - // (undocumented) - static createEsAutoCreateIndexError(): DecoratedError; - // (undocumented) - static createGenericNotFoundError(type?: string | null, id?: string | null): DecoratedError; - // (undocumented) - static createInvalidVersionError(versionInput?: string): DecoratedError; - // (undocumented) - static createUnsupportedTypeError(type: string): DecoratedError; - // (undocumented) - static decorateBadRequestError(error: Error, reason?: string): DecoratedError; - // (undocumented) - static decorateConflictError(error: Error, reason?: string): DecoratedError; - // (undocumented) - static decorateEsUnavailableError(error: Error, reason?: string): DecoratedError; - // (undocumented) - static decorateForbiddenError(error: Error, reason?: string): DecoratedError; - // (undocumented) - static decorateGeneralError(error: Error, reason?: string): DecoratedError; - // (undocumented) - static decorateNotAuthorizedError(error: Error, reason?: string): DecoratedError; - // (undocumented) - static decorateRequestEntityTooLargeError(error: Error, reason?: string): DecoratedError; - // (undocumented) - static isBadRequestError(error: Error | DecoratedError): boolean; - // (undocumented) - static isConflictError(error: Error | DecoratedError): boolean; - // (undocumented) - static isEsAutoCreateIndexError(error: Error | DecoratedError): boolean; - // (undocumented) - static isEsUnavailableError(error: Error | DecoratedError): boolean; - // (undocumented) - static isForbiddenError(error: Error | DecoratedError): boolean; - // (undocumented) - static isInvalidVersionError(error: Error | DecoratedError): boolean; - // (undocumented) - static isNotAuthorizedError(error: Error | DecoratedError): boolean; - // (undocumented) - static isNotFoundError(error: Error | DecoratedError): boolean; - // (undocumented) - static isRequestEntityTooLargeError(error: Error | DecoratedError): boolean; - // Warning: (ae-forgotten-export) The symbol "DecoratedError" needs to be exported by the entry point index.d.ts - // - // (undocumented) - static isSavedObjectsClientError(error: any): error is DecoratedError; -} - -// @public -export interface SavedObjectsExportOptions { - excludeExportDetails?: boolean; - exportSizeLimit: number; - includeReferencesDeep?: boolean; - namespace?: string; - objects?: Array<{ - id: string; - type: string; - }>; - savedObjectsClient: SavedObjectsClientContract; - search?: string; - types?: string[]; -} - -// @public -export interface SavedObjectsExportResultDetails { - exportedCount: number; - missingRefCount: number; - missingReferences: Array<{ - id: string; - type: string; - }>; -} - -// @public (undocumented) -export interface SavedObjectsFindOptions extends SavedObjectsBaseOptions { - // (undocumented) - defaultSearchOperator?: 'AND' | 'OR'; - fields?: string[]; - // (undocumented) - filter?: string; - // (undocumented) - hasReference?: { - type: string; - id: string; - }; - // (undocumented) - page?: number; - // (undocumented) - perPage?: number; - search?: string; - searchFields?: string[]; - // (undocumented) - sortField?: string; - // (undocumented) - sortOrder?: string; - // (undocumented) - type: string | string[]; -} - -// @public -export interface SavedObjectsFindResponse { - // (undocumented) - page: number; - // (undocumented) - per_page: number; - // (undocumented) - saved_objects: Array>; - // (undocumented) - total: number; -} - -// @public -export interface SavedObjectsImportConflictError { - // (undocumented) - type: 'conflict'; -} - -// @public -export interface SavedObjectsImportError { - // (undocumented) - error: SavedObjectsImportConflictError | SavedObjectsImportUnsupportedTypeError | SavedObjectsImportMissingReferencesError | SavedObjectsImportUnknownError; - // (undocumented) - id: string; - // (undocumented) - title?: string; - // (undocumented) - type: string; -} - -// @public -export interface SavedObjectsImportMissingReferencesError { - // (undocumented) - blocking: Array<{ - type: string; - id: string; - }>; - // (undocumented) - references: Array<{ - type: string; - id: string; - }>; - // (undocumented) - type: 'missing_references'; -} - -// @public -export interface SavedObjectsImportOptions { - // (undocumented) - namespace?: string; - // (undocumented) - objectLimit: number; - // (undocumented) - overwrite: boolean; - // (undocumented) - readStream: Readable; - // (undocumented) - savedObjectsClient: SavedObjectsClientContract; - // (undocumented) - supportedTypes: string[]; -} - -// @public -export interface SavedObjectsImportResponse { - // (undocumented) - errors?: SavedObjectsImportError[]; - // (undocumented) - success: boolean; - // (undocumented) - successCount: number; -} - -// @public -export interface SavedObjectsImportRetry { - // (undocumented) - id: string; - // (undocumented) - overwrite: boolean; - // (undocumented) - replaceReferences: Array<{ - type: string; - from: string; - to: string; - }>; - // (undocumented) - type: string; -} - -// @public -export interface SavedObjectsImportUnknownError { - // (undocumented) - message: string; - // (undocumented) - statusCode: number; - // (undocumented) - type: 'unknown'; -} - -// @public -export interface SavedObjectsImportUnsupportedTypeError { - // (undocumented) - type: 'unsupported_type'; -} - -// @public (undocumented) -export interface SavedObjectsIncrementCounterOptions extends SavedObjectsBaseOptions { - // (undocumented) - migrationVersion?: SavedObjectsMigrationVersion; - refresh?: MutatingOperationRefreshSetting; -} - -// @internal @deprecated (undocumented) -export interface SavedObjectsLegacyService { - // Warning: (ae-forgotten-export) The symbol "SavedObjectsClientProvider" needs to be exported by the entry point index.d.ts - // - // (undocumented) - addScopedSavedObjectsClientWrapperFactory: SavedObjectsClientProvider['addClientWrapperFactory']; - // (undocumented) - getSavedObjectsRepository(...rest: any[]): any; - // (undocumented) - getScopedSavedObjectsClient: SavedObjectsClientProvider['getClient']; - // (undocumented) - importExport: { - objectLimit: number; - importSavedObjects(options: SavedObjectsImportOptions): Promise; - resolveImportErrors(options: SavedObjectsResolveImportErrorsOptions): Promise; - getSortedObjectsForExport(options: SavedObjectsExportOptions): Promise; - }; - // (undocumented) - SavedObjectsClient: typeof SavedObjectsClient; - // (undocumented) - schema: SavedObjectsSchema; - // (undocumented) - setScopedSavedObjectsClientFactory: SavedObjectsClientProvider['setClientFactory']; - // (undocumented) - types: string[]; -} - -// @public (undocumented) -export interface SavedObjectsMigrationLogger { - // (undocumented) - debug: (msg: string) => void; - // (undocumented) - info: (msg: string) => void; - // (undocumented) - warning: (msg: string) => void; -} - -// @public -export interface SavedObjectsMigrationVersion { - // (undocumented) - [pluginName: string]: string; -} - -// Warning: (ae-missing-release-tag) "RawDoc" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) -// -// @public -export interface SavedObjectsRawDoc { - // (undocumented) - _id: string; - // (undocumented) - _primary_term?: number; - // (undocumented) - _seq_no?: number; - // (undocumented) - _source: any; - // (undocumented) - _type?: string; -} - -// @public (undocumented) -export class SavedObjectsRepository { - // Warning: (ae-forgotten-export) The symbol "SavedObjectsRepositoryOptions" needs to be exported by the entry point index.d.ts - // - // @internal - constructor(options: SavedObjectsRepositoryOptions); - bulkCreate(objects: Array>, options?: SavedObjectsCreateOptions): Promise>; - bulkGet(objects?: SavedObjectsBulkGetObject[], options?: SavedObjectsBaseOptions): Promise>; - bulkUpdate(objects: Array>, options?: SavedObjectsBulkUpdateOptions): Promise>; - create(type: string, attributes: T, options?: SavedObjectsCreateOptions): Promise>; - delete(type: string, id: string, options?: SavedObjectsDeleteOptions): Promise<{}>; - deleteByNamespace(namespace: string, options?: SavedObjectsDeleteByNamespaceOptions): Promise; - // (undocumented) - find({ search, defaultSearchOperator, searchFields, hasReference, page, perPage, sortField, sortOrder, fields, namespace, type, filter, }: SavedObjectsFindOptions): Promise>; - get(type: string, id: string, options?: SavedObjectsBaseOptions): Promise>; - incrementCounter(type: string, id: string, counterFieldName: string, options?: SavedObjectsIncrementCounterOptions): Promise<{ - id: string; - type: string; - updated_at: string; - references: any; - version: string; - attributes: any; - }>; - update(type: string, id: string, attributes: Partial, options?: SavedObjectsUpdateOptions): Promise>; - } - -// @public -export interface SavedObjectsResolveImportErrorsOptions { - // (undocumented) - namespace?: string; - // (undocumented) - objectLimit: number; - // (undocumented) - readStream: Readable; - // (undocumented) - retries: SavedObjectsImportRetry[]; - // (undocumented) - savedObjectsClient: SavedObjectsClientContract; - // (undocumented) - supportedTypes: string[]; -} - -// @internal (undocumented) -export class SavedObjectsSchema { - // Warning: (ae-forgotten-export) The symbol "SavedObjectsSchemaDefinition" needs to be exported by the entry point index.d.ts - constructor(schemaDefinition?: SavedObjectsSchemaDefinition); - // (undocumented) - getConvertToAliasScript(type: string): string | undefined; - // (undocumented) - getIndexForType(config: Config, type: string): string | undefined; - // (undocumented) - isHiddenType(type: string): boolean; - // (undocumented) - isNamespaceAgnostic(type: string): boolean; -} - -// @internal (undocumented) -export class SavedObjectsSerializer { - constructor(schema: SavedObjectsSchema); - generateRawId(namespace: string | undefined, type: string, id?: string): string; - isRawSavedObject(rawDoc: SavedObjectsRawDoc): any; - // Warning: (ae-forgotten-export) The symbol "SanitizedSavedObjectDoc" needs to be exported by the entry point index.d.ts - rawToSavedObject(doc: SavedObjectsRawDoc): SanitizedSavedObjectDoc; - savedObjectToRaw(savedObj: SanitizedSavedObjectDoc): SavedObjectsRawDoc; - } - -// @public -export interface SavedObjectsServiceSetup { - addClientWrapper: (priority: number, id: string, factory: SavedObjectsClientWrapperFactory) => void; - createInternalRepository: (extraTypes?: string[]) => ISavedObjectsRepository; - createScopedRepository: (req: KibanaRequest, extraTypes?: string[]) => ISavedObjectsRepository; - setClientFactory: (customClientFactory: SavedObjectsClientFactory) => void; -} - -// @public -export interface SavedObjectsServiceStart { - getScopedClient: (req: KibanaRequest, options?: SavedObjectsClientProviderOptions) => SavedObjectsClientContract; -} - -// @public (undocumented) -export interface SavedObjectsUpdateOptions extends SavedObjectsBaseOptions { - references?: SavedObjectReference[]; - refresh?: MutatingOperationRefreshSetting; - version?: string; -} - -// @public (undocumented) -export interface SavedObjectsUpdateResponse extends Omit, 'attributes' | 'references'> { - // (undocumented) - attributes: Partial; - // (undocumented) - references: SavedObjectReference[] | undefined; -} - -// @public -export class ScopedClusterClient implements IScopedClusterClient { - constructor(internalAPICaller: APICaller, scopedAPICaller: APICaller, headers?: Headers | undefined); - callAsCurrentUser(endpoint: string, clientParams?: Record, options?: CallAPIOptions): Promise; - callAsInternalUser(endpoint: string, clientParams?: Record, options?: CallAPIOptions): Promise; - } - -// @public -export interface SessionCookieValidationResult { - isValid: boolean; - path?: string; -} - -// @public -export interface SessionStorage { - clear(): void; - get(): Promise; - set(sessionValue: T): void; -} - -// @public -export interface SessionStorageCookieOptions { - encryptionKey: string; - isSecure: boolean; - name: string; - validate: (sessionValue: T | T[]) => SessionCookieValidationResult; -} - -// @public -export interface SessionStorageFactory { - // (undocumented) - asScoped: (request: KibanaRequest) => SessionStorage; -} - -// @public -export interface UiSettingsParams { - category?: string[]; - description?: string; - name?: string; - optionLabels?: Record; - options?: string[]; - readonly?: boolean; - requiresPageReload?: boolean; - type?: UiSettingsType; - value?: SavedObjectAttribute; -} - -// @public (undocumented) -export interface UiSettingsServiceSetup { - register(settings: Record): void; -} - -// @public -export type UiSettingsType = 'json' | 'markdown' | 'number' | 'select' | 'boolean' | 'string'; - -// @public -export interface UserProvidedValues { - // (undocumented) - isOverridden?: boolean; - // (undocumented) - userValue?: T; -} - -// @public -export const validBodyOutput: readonly ["data", "stream"]; - - -// Warnings were encountered during analysis: -// -// src/core/server/http/router/response.ts:316:3 - (ae-forgotten-export) The symbol "KibanaResponse" needs to be exported by the entry point index.d.ts -// src/core/server/plugins/plugins_service.ts:43:5 - (ae-forgotten-export) The symbol "InternalPluginInfo" needs to be exported by the entry point index.d.ts - -``` ->>>>>>> a80366b36481c8efb3046a7766e90fe241f1b5e3 From 23a34f896e2c5faf8d8c4bddd32529c849ccbfe9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Ferna=CC=81ndez=20Haro?= Date: Tue, 3 Dec 2019 10:49:04 +0000 Subject: [PATCH 17/21] Rename the path properties when exposing them --- src/core/server/mocks.ts | 2 +- src/core/server/plugins/plugin_context.test.ts | 2 +- src/core/server/plugins/plugin_context.ts | 5 ++++- src/core/server/plugins/types.ts | 7 ++++--- src/core/server/server.api.md | 2 +- 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/core/server/mocks.ts b/src/core/server/mocks.ts index d641bcdfd7b148..5d7d04f042a1a4 100644 --- a/src/core/server/mocks.ts +++ b/src/core/server/mocks.ts @@ -49,7 +49,7 @@ export function pluginInitializerContextConfigMock(config: T) { }, path: { configDir: '/tmp', - data: '/tmp', + dataDir: '/tmp', }, }; diff --git a/src/core/server/plugins/plugin_context.test.ts b/src/core/server/plugins/plugin_context.test.ts index 9de22781dc718c..c012e1ee2260db 100644 --- a/src/core/server/plugins/plugin_context.test.ts +++ b/src/core/server/plugins/plugin_context.test.ts @@ -82,7 +82,7 @@ describe('Plugin Context', () => { pingTimeout: duration(30, 's'), startupTimeout: duration(5, 's'), }, - path: { configDir: fromRoot('config'), data: fromRoot('data') }, + path: { configDir: fromRoot('config'), dataDir: fromRoot('data') }, }); }); }); diff --git a/src/core/server/plugins/plugin_context.ts b/src/core/server/plugins/plugin_context.ts index dfd1052bbec757..5be3411555b5d5 100644 --- a/src/core/server/plugins/plugin_context.ts +++ b/src/core/server/plugins/plugin_context.ts @@ -94,7 +94,10 @@ export function createPluginInitializerContext( deepFreeze({ kibana: pick(kibana, SharedGlobalConfigKeys.kibana), elasticsearch: pick(elasticsearch, SharedGlobalConfigKeys.elasticsearch), - path: pick(path, SharedGlobalConfigKeys.path), + path: { + configDir: path.configDir, + dataDir: path.data, + }, }) ) ), diff --git a/src/core/server/plugins/types.ts b/src/core/server/plugins/types.ts index a44e01e3fabc6a..1b5118412c59af 100644 --- a/src/core/server/plugins/types.ts +++ b/src/core/server/plugins/types.ts @@ -25,7 +25,6 @@ import { ConfigPath, EnvironmentMode, PackageInfo } from '../config'; import { LoggerFactory } from '../logging'; import { KibanaConfigType } from '../kibana_config'; import { ElasticsearchConfigType } from '../elasticsearch/elasticsearch_config'; -import { PathConfigType } from '../path'; import { CoreSetup, CoreStart } from '..'; /** @@ -203,13 +202,15 @@ export const SharedGlobalConfigKeys = { // We can add more if really needed kibana: ['defaultAppId', 'index'] as const, elasticsearch: ['shardTimeout', 'requestTimeout', 'pingTimeout', 'startupTimeout'] as const, - path: ['configDir', 'data'] as const, }; export type SharedGlobalConfig = RecursiveReadonly<{ kibana: Pick; elasticsearch: Pick; - path: Pick; + path: { + configDir: string; + dataDir: string; + }; }>; /** diff --git a/src/core/server/server.api.md b/src/core/server/server.api.md index ed6ea058b8f70f..177d8efc3057be 100644 --- a/src/core/server/server.api.md +++ b/src/core/server/server.api.md @@ -1762,6 +1762,6 @@ export const validBodyOutput: readonly ["data", "stream"]; // // src/core/server/http/router/response.ts:316:3 - (ae-forgotten-export) The symbol "KibanaResponse" needs to be exported by the entry point index.d.ts // src/core/server/plugins/plugins_service.ts:43:5 - (ae-forgotten-export) The symbol "InternalPluginInfo" needs to be exported by the entry point index.d.ts -// src/core/server/plugins/types.ts:228:15 - (ae-forgotten-export) The symbol "SharedGlobalConfig" needs to be exported by the entry point index.d.ts +// src/core/server/plugins/types.ts:229:15 - (ae-forgotten-export) The symbol "SharedGlobalConfig" needs to be exported by the entry point index.d.ts ``` From 4adebd5b868e72cf8111a6e18d5d6b55c059d5a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Ferna=CC=81ndez=20Haro?= Date: Tue, 3 Dec 2019 16:10:44 +0000 Subject: [PATCH 18/21] path.configDir removed from the path config-schema --- src/core/server/path/index.ts | 4 +--- src/core/server/plugins/plugin_context.ts | 6 ++++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/core/server/path/index.ts b/src/core/server/path/index.ts index 5e25e8e36946e2..ef8a3caeefa2cd 100644 --- a/src/core/server/path/index.ts +++ b/src/core/server/path/index.ts @@ -17,7 +17,7 @@ * under the License. */ -import { join, resolve } from 'path'; +import { join } from 'path'; import { accessSync, constants } from 'fs'; import { TypeOf, schema } from '@kbn/config-schema'; import { fromRoot } from '../utils'; @@ -65,8 +65,6 @@ export type PathConfigType = TypeOf; export const config = { path: 'path', schema: schema.object({ - // getConfigPath returns the path until the kibana.yml config. We need to move 1 level up for the dir - configDir: schema.string({ defaultValue: () => resolve(getConfigPath(), '..') }), data: schema.string({ defaultValue: () => getDataPath() }), }), }; diff --git a/src/core/server/plugins/plugin_context.ts b/src/core/server/plugins/plugin_context.ts index 5be3411555b5d5..90f0c3b662296b 100644 --- a/src/core/server/plugins/plugin_context.ts +++ b/src/core/server/plugins/plugin_context.ts @@ -19,6 +19,7 @@ import { map } from 'rxjs/operators'; import { combineLatest } from 'rxjs'; +import { resolve } from 'path'; import { CoreContext } from '../core_context'; import { PluginWrapper } from './plugin'; import { PluginsServiceSetupDeps, PluginsServiceStartDeps } from './plugins_service'; @@ -28,7 +29,7 @@ import { PluginOpaqueId, SharedGlobalConfigKeys, } from './types'; -import { PathConfigType, config as pathConfig } from '../path'; +import { PathConfigType, config as pathConfig, getConfigPath } from '../path'; import { KibanaConfigType, config as kibanaConfig } from '../kibana_config'; import { ElasticsearchConfigType, @@ -95,7 +96,8 @@ export function createPluginInitializerContext( kibana: pick(kibana, SharedGlobalConfigKeys.kibana), elasticsearch: pick(elasticsearch, SharedGlobalConfigKeys.elasticsearch), path: { - configDir: path.configDir, + // getConfigPath returns the path until the kibana.yml config. We need to move 1 level up for the dir + configDir: resolve(getConfigPath(), '..'), dataDir: path.data, }, }) From 31cbab2ce718468b8f0f79563631c1f2d13fcf8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Ferna=CC=81ndez=20Haro?= Date: Tue, 3 Dec 2019 16:43:53 +0000 Subject: [PATCH 19/21] Remove path.configDir. It is already in env.configs --- src/core/server/mocks.ts | 5 +---- src/core/server/plugins/plugin_context.test.ts | 2 +- src/core/server/plugins/plugin_context.ts | 9 ++------- src/core/server/plugins/types.ts | 7 +++---- src/core/server/server.api.md | 2 +- 5 files changed, 8 insertions(+), 17 deletions(-) diff --git a/src/core/server/mocks.ts b/src/core/server/mocks.ts index 5d7d04f042a1a4..8f864dda6b9f30 100644 --- a/src/core/server/mocks.ts +++ b/src/core/server/mocks.ts @@ -47,10 +47,7 @@ export function pluginInitializerContextConfigMock(config: T) { pingTimeout: duration('30s'), startupTimeout: duration('30s'), }, - path: { - configDir: '/tmp', - dataDir: '/tmp', - }, + path: { data: '/tmp' }, }; const mock: jest.Mocked['config']> = { diff --git a/src/core/server/plugins/plugin_context.test.ts b/src/core/server/plugins/plugin_context.test.ts index c012e1ee2260db..547ac08cca76db 100644 --- a/src/core/server/plugins/plugin_context.test.ts +++ b/src/core/server/plugins/plugin_context.test.ts @@ -82,7 +82,7 @@ describe('Plugin Context', () => { pingTimeout: duration(30, 's'), startupTimeout: duration(5, 's'), }, - path: { configDir: fromRoot('config'), dataDir: fromRoot('data') }, + path: { data: fromRoot('data') }, }); }); }); diff --git a/src/core/server/plugins/plugin_context.ts b/src/core/server/plugins/plugin_context.ts index 90f0c3b662296b..dfd1052bbec757 100644 --- a/src/core/server/plugins/plugin_context.ts +++ b/src/core/server/plugins/plugin_context.ts @@ -19,7 +19,6 @@ import { map } from 'rxjs/operators'; import { combineLatest } from 'rxjs'; -import { resolve } from 'path'; import { CoreContext } from '../core_context'; import { PluginWrapper } from './plugin'; import { PluginsServiceSetupDeps, PluginsServiceStartDeps } from './plugins_service'; @@ -29,7 +28,7 @@ import { PluginOpaqueId, SharedGlobalConfigKeys, } from './types'; -import { PathConfigType, config as pathConfig, getConfigPath } from '../path'; +import { PathConfigType, config as pathConfig } from '../path'; import { KibanaConfigType, config as kibanaConfig } from '../kibana_config'; import { ElasticsearchConfigType, @@ -95,11 +94,7 @@ export function createPluginInitializerContext( deepFreeze({ kibana: pick(kibana, SharedGlobalConfigKeys.kibana), elasticsearch: pick(elasticsearch, SharedGlobalConfigKeys.elasticsearch), - path: { - // getConfigPath returns the path until the kibana.yml config. We need to move 1 level up for the dir - configDir: resolve(getConfigPath(), '..'), - dataDir: path.data, - }, + path: pick(path, SharedGlobalConfigKeys.path), }) ) ), diff --git a/src/core/server/plugins/types.ts b/src/core/server/plugins/types.ts index 1b5118412c59af..b4c8c988642635 100644 --- a/src/core/server/plugins/types.ts +++ b/src/core/server/plugins/types.ts @@ -25,6 +25,7 @@ import { ConfigPath, EnvironmentMode, PackageInfo } from '../config'; import { LoggerFactory } from '../logging'; import { KibanaConfigType } from '../kibana_config'; import { ElasticsearchConfigType } from '../elasticsearch/elasticsearch_config'; +import { PathConfigType } from '../path'; import { CoreSetup, CoreStart } from '..'; /** @@ -202,15 +203,13 @@ export const SharedGlobalConfigKeys = { // We can add more if really needed kibana: ['defaultAppId', 'index'] as const, elasticsearch: ['shardTimeout', 'requestTimeout', 'pingTimeout', 'startupTimeout'] as const, + path: ['data'] as const, }; export type SharedGlobalConfig = RecursiveReadonly<{ kibana: Pick; elasticsearch: Pick; - path: { - configDir: string; - dataDir: string; - }; + path: Pick; }>; /** diff --git a/src/core/server/server.api.md b/src/core/server/server.api.md index 6e9b92934d100f..4adebfe86888d0 100644 --- a/src/core/server/server.api.md +++ b/src/core/server/server.api.md @@ -1764,6 +1764,6 @@ export const validBodyOutput: readonly ["data", "stream"]; // // src/core/server/http/router/response.ts:316:3 - (ae-forgotten-export) The symbol "KibanaResponse" needs to be exported by the entry point index.d.ts // src/core/server/plugins/plugins_service.ts:43:5 - (ae-forgotten-export) The symbol "InternalPluginInfo" needs to be exported by the entry point index.d.ts -// src/core/server/plugins/types.ts:229:15 - (ae-forgotten-export) The symbol "SharedGlobalConfig" needs to be exported by the entry point index.d.ts +// src/core/server/plugins/types.ts:228:15 - (ae-forgotten-export) The symbol "SharedGlobalConfig" needs to be exported by the entry point index.d.ts ``` From 79b2133b22348072425ea746bb440ce3f2267e00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Ferna=CC=81ndez=20Haro?= Date: Wed, 4 Dec 2019 10:59:05 +0000 Subject: [PATCH 20/21] Add Migration documentation and examples --- src/core/MIGRATION.md | 126 +++++++++++++++++++++++---------- src/core/MIGRATION_EXAMPLES.md | 75 ++++++++++++++++++-- 2 files changed, 161 insertions(+), 40 deletions(-) diff --git a/src/core/MIGRATION.md b/src/core/MIGRATION.md index 7c1489a345e55e..f14b4cb290c228 100644 --- a/src/core/MIGRATION.md +++ b/src/core/MIGRATION.md @@ -16,15 +16,15 @@ - [Switch to new platform services](#switch-to-new-platform-services) - [Migrate to the new plugin system](#migrate-to-the-new-plugin-system) - [Browser-side plan of action](#browser-side-plan-of-action) - - [1. Create a plugin definition file](#1-create-a-plugin-definition-file) - - [2. Export all static code and types from `public/index.ts`](#2-export-all-static-code-and-types-from-publicindexts) - - [3. Export your runtime contract](#3-export-your-runtime-contract) - - [4. Move "owned" UI modules into your plugin and expose them from your public contract](#4-move-owned-ui-modules-into-your-plugin-and-expose-them-from-your-public-contract) - - [5. Provide plugin extension points decoupled from angular.js](#5-provide-plugin-extension-points-decoupled-from-angularjs) - - [6. Move all webpack alias imports into uiExport entry files](#6-move-all-webpack-alias-imports-into-uiexport-entry-files) - - [7. Switch to new platform services](#7-switch-to-new-platform-services) - - [8. Migrate to the new plugin system](#8-migrate-to-the-new-plugin-system) - - [Bonus: Tips for complex migration scenarios](#bonus-tips-for-complex-migration-scenarios) + - [1. Create a plugin definition file](#1-create-a-plugin-definition-file) + - [2. Export all static code and types from `public/index.ts`](#2-export-all-static-code-and-types-from-publicindexts) + - [3. Export your runtime contract](#3-export-your-runtime-contract) + - [4. Move "owned" UI modules into your plugin and expose them from your public contract](#4-move-owned-ui-modules-into-your-plugin-and-expose-them-from-your-public-contract) + - [5. Provide plugin extension points decoupled from angular.js](#5-provide-plugin-extension-points-decoupled-from-angularjs) + - [6. Move all webpack alias imports into uiExport entry files](#6-move-all-webpack-alias-imports-into-uiexport-entry-files) + - [7. Switch to new platform services](#7-switch-to-new-platform-services) + - [8. Migrate to the new plugin system](#8-migrate-to-the-new-plugin-system) + - [Bonus: Tips for complex migration scenarios](#bonus-tips-for-complex-migration-scenarios) - [Frequently asked questions](#frequently-asked-questions) - [Is migrating a plugin an all-or-nothing thing?](#is-migrating-a-plugin-an-all-or-nothing-thing) - [Do plugins need to be converted to TypeScript?](#do-plugins-need-to-be-converted-to-typescript) @@ -71,7 +71,7 @@ Plugins are defined as classes and exposed to the platform itself through a simp The basic file structure of a new platform plugin named "demo" that had both client-side and server-side code would be: -``` +```tree src/plugins demo kibana.json [1] @@ -83,7 +83,7 @@ src/plugins plugin.ts [5] ``` -**[1] `kibana.json`** is a static manifest file that is used to identify the plugin and to determine what kind of code the platform should execute from the plugin: +**[1] `kibana.json`** is a [static manifest](../../docs/development/core/server/kibana-plugin-server.pluginmanifest.md) file that is used to identify the plugin and to determine what kind of code the platform should execute from the plugin: ```json { @@ -99,7 +99,7 @@ Note that `package.json` files are irrelevant to and ignored by the new platform **[2] `public/index.ts`** is the entry point into the client-side code of this plugin. It must export a function named `plugin`, which will receive a standard set of core capabilities as an argument (e.g. logger). It should return an instance of its plugin definition for the platform to register at load time. ```ts -import { PluginInitializerContext } from '../../../core/public'; +import { PluginInitializerContext } from 'kibana/server'; import { Plugin } from './plugin'; export function plugin(initializerContext: PluginInitializerContext) { @@ -110,7 +110,7 @@ export function plugin(initializerContext: PluginInitializerContext) { **[3] `public/plugin.ts`** is the client-side plugin definition itself. Technically speaking it does not need to be a class or even a separate file from the entry point, but _all plugins at Elastic_ should be consistent in this way. ```ts -import { PluginInitializerContext, CoreSetup, CoreStart } from '../../../core/public'; +import { PluginInitializerContext, CoreSetup, CoreStart } from 'kibana/server'; export class Plugin { constructor(initializerContext: PluginInitializerContext) { @@ -133,7 +133,7 @@ export class Plugin { **[4] `server/index.ts`** is the entry-point into the server-side code of this plugin. It is identical in almost every way to the client-side entry-point: ```ts -import { PluginInitializerContext } from '../../../core/server'; +import { PluginInitializerContext } from 'kibana/server'; import { Plugin } from './plugin'; export function plugin(initializerContext: PluginInitializerContext) { @@ -144,7 +144,7 @@ export function plugin(initializerContext: PluginInitializerContext) { **[5] `server/plugin.ts`** is the server-side plugin definition. The _shape_ of this plugin is the same as it's client-side counter-part: ```ts -import { PluginInitializerContext, CoreSetup, CoreStart } from '../../../core/server'; +import { PluginInitializerContext, CoreSetup, CoreStart } from 'kibana/server'; export class Plugin { constructor(initializerContext: PluginInitializerContext) { @@ -185,7 +185,7 @@ There is no equivalent behavior to `start` or `stop` in legacy plugins, so this The lifecycle-specific contracts exposed by core services are always passed as the first argument to the equivalent lifecycle function in a plugin. For example, the core `UiSettings` service exposes a function `get` to all plugin `setup` functions. To use this function to retrieve a specific UI setting, a plugin just accesses it off of the first argument: ```ts -import { CoreSetup } from '../../../core/public'; +import { CoreSetup } from 'kibana/server'; export class Plugin { public setup(core: CoreSetup) { @@ -200,6 +200,15 @@ For example, the `stop` function in the browser gets invoked as part of the `win Core services that expose functionality to plugins always have their `setup` function ran before any plugins. +These are the contracts exposed by the core services for each lifecycle event: + +| lifecycle event | contract | +| --------------- | --------------------------------------------------------------------------------------------------------------- | +| *contructor* | [PluginInitializerContext](../../docs/development/core/server/kibana-plugin-server.plugininitializercontext.md) | +| *setup* | [CoreSetup](../../docs/development/core/server/kibana-plugin-server.coresetup.md) | +| *start* | [CoreStart](../../docs/development/core/server/kibana-plugin-server.corestart.md) | +| *stop* | | + ### Integrating with other plugins Plugins can expose public interfaces for other plugins to consume. Like `core`, those interfaces are bound to the lifecycle functions `setup` and/or `start`. @@ -357,6 +366,7 @@ npStart.plugins.data.fieldFormats.getType(myFieldFormatId); Legacy server-side plugins access functionality from core and other plugins at runtime via function arguments, which is similar to how they must be architected to use the new plugin system. This greatly simplifies the plan of action for migrating server-side plugins. Here is the high-level for migrating a server-side plugin: + - De-couple from hapi.js server and request objects - Introduce a new plugin definition shim - Replace legacy services in shim with new platform services @@ -515,7 +525,7 @@ interface FooSetup { } // We inject the miminal legacy dependencies into our plugin including dependencies on other legacy -// plugins. Take care to only expose the legacy functionality you need e.g. don't inject the whole +// plugins. Take care to only expose the legacy functionality you need e.g. don't inject the whole // `Legacy.Server` if you only depend on `Legacy.Server['route']`. interface LegacySetup { route: Legacy.Server['route'] @@ -539,7 +549,7 @@ export class DemoPlugin implements Plugin { }); } ``` + > Note: An equally valid approach is to extend `CoreSetup` with a `__legacy` > property instead of introducing a third parameter to your plugins lifecycle > function. The important thing is that you reduce the legacy API surface that @@ -657,7 +668,7 @@ the legacy core. A similar approach can be taken for your plugin dependencies. To start consuming an API from a New Platform plugin access these from `server.newPlatform.setup.plugins` and inject it into your plugin's setup -function. +function. ```ts init(server) { @@ -689,7 +700,7 @@ entirely powered by the New Platform and New Platform plugins. > Note: All New Platform plugins are exposed to legacy plugins via > `server.newPlatform.setup.plugins`. Once you move your plugin over to the > New Platform you will have to explicitly declare your dependencies on other -> plugins in your `kibana.json` manifest file. +> plugins in your `kibana.json` manifest file. At this point, your legacy server-side plugin logic is no longer coupled to legacy plugins. @@ -702,6 +713,7 @@ Many plugins will copy and paste all of their plugin code into a new plugin dire With the previous steps resolved, this final step should be easy, but the exact process may vary plugin by plugin, so when you're at this point talk to the platform team to figure out the exact changes you need. Other plugins may want to move subsystems over individually. For instance, you can move routes over to the New Platform in groups rather than all at once. Other examples that could be broken up: + - Configuration schema ([see example](./MIGRATION_EXAMPLES.md#declaring-config-schema)) - HTTP route registration ([see example](./MIGRATION_EXAMPLES.md#http-routes)) - Polling mechanisms (eg. job worker) @@ -726,7 +738,7 @@ This definition isn't going to do much for us just yet, but as we get further in ```ts // public/plugin.ts -import { CoreSetup, CoreStart, Plugin } from '../../../../core/public'; +import { CoreSetup, CoreStart, Plugin } from '../kibana/server'; import { FooSetup, FooStart } from '../../../../legacy/core_plugins/foo/public'; /** @@ -794,7 +806,7 @@ While you're at it, you can also add your plugin initializer to this file: ```ts // public/index.ts -import { PluginInitializer, PluginInitializerContext } from '../../../../core/public'; +import { PluginInitializer, PluginInitializerContext } from '../kibana/server'; import { DemoSetup, DemoStart, DemoSetupDeps, DemoStartDeps, DemoPlugin } from './plugin'; // Core will be looking for this when loading our plugin in the new platform @@ -828,7 +840,7 @@ So we will take a similar approach to what was described above in the server sec ```ts // public/legacy.ts -import { PluginInitializerContext } from '../../../../core/public'; +import { PluginInitializerContext } from '../kibana/server'; import { npSetup, npStart } from 'ui/new_platform'; import { plugin } from '.'; @@ -858,10 +870,10 @@ The point is that, over time, this becomes the one file in our plugin containing Everything inside of the `ui/public` directory is going to be dealt with in one of the following ways: -* Deleted because it doesn't need to be used anymore -* Moved to or replaced by something in core that isn't coupled to angular -* Moved to or replaced by an extension point in a specific plugin that "owns" that functionality -* Copied into each plugin that depends on it and becomes an implementation detail there +- Deleted because it doesn't need to be used anymore +- Moved to or replaced by something in core that isn't coupled to angular +- Moved to or replaced by an extension point in a specific plugin that "owns" that functionality +- Copied into each plugin that depends on it and becomes an implementation detail there To rapidly define ownership and determine interdependencies, UI modules should move to the most appropriate plugins to own them. Modules that are considered "core" can remain in the ui directory as the platform team works to move them out. @@ -873,12 +885,12 @@ If it is determined that your plugin is going to own any UI modules that other p Depending on the module's level of complexity and the number of other places in Kibana that rely on it, there are a number of strategies you could use for this: -* **Do it all at once.** Move the code, expose it from your plugin, and update all imports across Kibana. +- **Do it all at once.** Move the code, expose it from your plugin, and update all imports across Kibana. - This works best for small pieces of code that aren't widely used. -* **Shim first, move later.** Expose the code from your plugin by importing it in your shim and then re-exporting it from your plugin first, then gradually update imports to pull from the new location, leaving the actual moving of the code as a final step. +- **Shim first, move later.** Expose the code from your plugin by importing it in your shim and then re-exporting it from your plugin first, then gradually update imports to pull from the new location, leaving the actual moving of the code as a final step. - This works best for the largest, most widely used modules that would otherwise result in huge, hard-to-review PRs. - It makes things easier by splitting the process into small, incremental PRs, but is probably overkill for things with a small surface area. -* **Hybrid approach.** As a middle ground, you can also move the code to your plugin immediately, and then re-export your plugin code from the original `ui/public` directory. +- **Hybrid approach.** As a middle ground, you can also move the code to your plugin immediately, and then re-export your plugin code from the original `ui/public` directory. - This eliminates any concerns about backwards compatibility by allowing you to update the imports across Kibana later. - Works best when the size of the PR is such that moving the code can be done without much refactoring. @@ -940,6 +952,7 @@ Many plugins at this point will copy over their plugin definition class & the co With the previous steps resolved, this final step should be easy, but the exact process may vary plugin by plugin, so when you're at this point talk to the platform team to figure out the exact changes you need. Other plugins may want to move subsystems over individually. Examples of pieces that could be broken up: + - Registration logic (eg. viz types, embeddables, chrome nav controls) - Application mounting - Polling mechanisms (eg. job worker) @@ -977,6 +990,7 @@ At the very least, any plugin exposing an extension point should do so with firs Legacy Kibana has never run as a single page application. Each plugin has it's own entry point and gets "ownership" of every module it imports when it is loaded into the browser. This has allowed stateful modules to work without breaking other plugins because each time the user navigates to a new plugin, the browser reloads with a different entry bundle, clearing the state of the previous plugin. Because of this "feature" many undesirable things developed in the legacy platform: + - We had to invent an unconventional and fragile way of allowing plugins to integrate and communicate with one another, `uiExports`. - It has never mattered if shared modules in `ui/public` were stateful or cleaned up after themselves, so many of them behave like global singletons. These modules could never work in single-page application because of this state. - We've had to ship Webpack with Kibana in production so plugins could be disabled or installed and still have access to all the "platform" features of `ui/public` modules and all the `uiExports` would be present for any enabled plugins. @@ -994,7 +1008,6 @@ One goal of a stable Kibana core API is to allow Kibana instances to run plugins This method of building and installing plugins comes with side effects which are important to be aware of when developing a plugin. - - **Any code you export to other plugins will get copied into their bundles.** If a plugin is built for 8.1 and is running on Kibana 8.2, any modules it imported that changed will not be updated in that plugin. - **When a plugin is disabled, other plugins can still import its static exports.** This can make code difficult to reason about and result in poor user experience. For example, users generally expect that all of a plugin’s features will be disabled when the plugin is disabled. If another plugin imports a disabled plugin’s feature and exposes it to the user, then users will be confused about whether that plugin really is disabled or not. - **Plugins cannot share state by importing each others modules.** Sharing state via imports does not work because exported modules will be copied into plugins that import them. Let’s say your plugin exports a module that’s imported by other plugins. If your plugin populates state into this module, a natural expectation would be that the other plugins now have access to this state. However, because those plugins have copies of the exported module, this assumption will be incorrect. @@ -1004,16 +1017,19 @@ This method of building and installing plugins comes with side effects which are The general rule of thumb here is: any module that is not purely functional should not be shared statically, and instead should be exposed at runtime via the plugin's `setup` and/or `start` contracts. Ask yourself these questions when deciding to share code through static exports or plugin contracts: + - Is its behavior dependent on any state populated from my plugin? - If a plugin uses an old copy (from an older version of Kibana) of this module, will it still break? If you answered yes to any of the above questions, you probably have an impure module that cannot be shared across plugins. Another way to think about this: if someone literally copied and pasted your exported module into their plugin, would it break if: + - Your original module changed in a future version and the copy was the old version; or - If your plugin doesn’t have access to the copied version in the other plugin (because it doesn't know about it). If your module were to break for either of these reasons, it should not be exported statically. This can be more easily illustrated by examples of what can and cannot be exported statically. Examples of code that could be shared statically: + - Constants. Strings and numbers that do not ever change (even between Kibana versions) - If constants do change between Kibana versions, then they should only be exported statically if the old value would not _break_ if it is still used. For instance, exporting a constant like `VALID_INDEX_NAME_CHARACTERS` would be fine, but exporting a constant like `API_BASE_PATH` would not because if this changed, old bundles using the previous value would break. - React components that do not depend on module state. @@ -1022,25 +1038,33 @@ Examples of code that could be shared statically: - Pure computation functions, for example lodash-like functions like `mapValues`. Examples of code that could **not** be shared statically and how to fix it: + - A function that calls a Core service, but does not take that service as a parameter. - If the function does not take a client as an argument, it must have an instance of the client in its internal state, populated by your plugin. This would not work across plugin boundaries because your plugin would not be able to call `setClient` in the copy of this module in other plugins: + ```js let esClient; export const setClient = (client) => esClient = client; export const query = (params) => esClient.search(params); ``` + - This could be fixed by requiring the calling code to provide the client: + ```js export const query = (esClient, params) => esClient.search(params); ``` + - A function that allows other plugins to register values that get pushed into an array defined internally to the module. - The values registered would only be visible to the plugin that imported it. Each plugin would essentially have their own registry of visTypes that is not visible to any other plugins. + ```js const visTypes = []; export const registerVisType = (visType) => visTypes.push(visType); export const getVisTypes = () => visTypes; ``` + - For state that does need to be shared across plugins, you will need to expose methods in your plugin's `setup` and `start` contracts. + ```js class MyPlugin { constructor() { this.visTypes = [] } @@ -1084,6 +1108,7 @@ If you have code that should be available to other plugins on both the client an ### How can I avoid passing Core services deeply within my UI component tree? There are some Core services that are purely presentational, for example `core.overlays.openModal()` or `core.application.createLink()` where UI code does need access to these deeply within your application. However, passing these services down as props throughout your application leads to lots of boilerplate. To avoid this, you have three options: + 1. Use an abstraction layer, like Redux, to decouple your UI code from core (**this is the highly preferred option**); or - [redux-thunk](https://github.com/reduxjs/redux-thunk#injecting-a-custom-argument) and [redux-saga](https://redux-saga.js.org/docs/api/#createsagamiddlewareoptions) already have ways to do this. 2. Use React Context to provide these services to large parts of your React tree; or @@ -1121,12 +1146,12 @@ The packages directory should have the least amount of code in Kibana. Just beca Many of the utilities you're using to build your plugins are available in the New Platform or in New Platform plugins. To help you build the shim for these new services, use the tables below to find where the New Platform equivalent lives. - #### Client-side TODO: add links to API docs on items in "New Platform" column. ##### Core services + In client code, `core` can be imported in legacy plugins via the `ui/new_platform` module. ```ts @@ -1155,6 +1180,7 @@ import { npStart: { core } } from 'ui/new_platform'; _See also: [Public's CoreStart API Docs](/docs/development/core/public/kibana-plugin-public.corestart.md)_ ##### Plugins for shared application services + In client code, we have a series of plugins which house shared application services that are being built in the shape of the new platform, but for the time being, are only available in legacy. So if your plugin depends on any of the APIs below, you'll need build your plugin as a legacy plugin that shims the new platform. Once these API's have been moved to the new platform you can migrate your plugin and declare a dependency on the plugin that owns the API's you require. The contracts for these plugins are exposed for you to consume in your own plugin; we have created dedicated exports for the `setup` and `start` contracts in a file called `legacy`. By passing these contracts to your plugin's `setup` and `start` methods, you can mimic the functionality that will eventually be provided in the new platform. @@ -1189,6 +1215,7 @@ import { setup, start } from '../core_plugins/visualizations/public/legacy'; #### Server-side ##### Core services + In server code, `core` can be accessed from either `server.newPlatform` or `kbnServer.newPlatform`. There are not currently very many services available on the server-side: | Legacy Platform | New Platform | Notes | @@ -1251,6 +1278,7 @@ Examples: - **uiSettingDefaults** Before: + ```js uiExports: { uiSettingDefaults: { @@ -1263,7 +1291,9 @@ uiExports: { } } ``` + After: + ```ts // src/plugins/my-plugin/server/plugin.ts setup(core: CoreSetup){ @@ -1281,6 +1311,7 @@ setup(core: CoreSetup){ ## How to ### Configure plugin + Kibana provides ConfigService if a plugin developer may want to support adjustable runtime behavior for their plugins. Access to Kibana config in New platform has been subject to significant refactoring. Config service does not provide access to the whole config anymore. New platform plugin cannot read configuration parameters of the core services nor other plugins directly. Use plugin contract to provide data. @@ -1294,8 +1325,10 @@ const basePath = core.http.basePath.get(request); ``` In order to have access to your plugin config, you *should*: + - Declare plugin specific "configPath" (will fallback to plugin "id" if not specified) in `kibana.json` file. - Export schema validation for config from plugin's main file. Schema is mandatory. If a plugin reads from the config without schema declaration, ConfigService will throw an error. + ```typescript // my_plugin/server/index.ts import { schema, TypeOf } from '@kbn/config-schema'; @@ -1305,7 +1338,9 @@ export const config = { }; export type MyPluginConfigType = TypeOf; ``` + - Read config value exposed via initializerContext. No config path is required. + ```typescript class MyPlugin { constructor(initializerContext: PluginInitializerContext) { @@ -1316,6 +1351,7 @@ class MyPlugin { ``` If your plugin also have a client-side part, you can also expose configuration properties to it using a whitelisting mechanism with the configuration `exposeToBrowser` property. + ```typescript // my_plugin/server/index.ts import { schema, TypeOf } from '@kbn/config-schema'; @@ -1337,6 +1373,7 @@ export const config: PluginConfigDescriptor = { ``` Configuration containing only the exposed properties will be then available on the client-side using the plugin's `initializerContext`: + ```typescript // my_plugin/public/index.ts interface ClientConfigType { @@ -1355,7 +1392,9 @@ export class Plugin implements Plugin { ### Mock new platform services in tests #### Writing mocks for your plugin + Core services already provide mocks to simplify testing and make sure plugins always rely on valid public contracts: + ```typescript // my_plugin/server/plugin.test.ts import { configServiceMock } from 'src/core/server/mocks'; @@ -1367,6 +1406,7 @@ const plugin = new MyPlugin({ configService }, …); ``` Or if you need to get the whole core `setup` or `start` contracts: + ```typescript // my_plugin/public/plugin.test.ts import { coreMock } from 'src/core/public/mocks'; @@ -1379,8 +1419,8 @@ coreSetup.uiSettings.get.mockImplementation((key: string) => { const plugin = new MyPlugin(coreSetup, ...); ``` - Although it isn't mandatory, we strongly recommended you export your plugin mocks as well, in order for dependent plugins to use them in tests. Your plugin mocks should be exported from the root `/server` and `/public` directories in your plugin: + ```typescript // my_plugin/server/mocks.ts or my_plugin/public/mocks.ts const createSetupContractMock = () => { @@ -1397,26 +1437,31 @@ export const myPluginMocks = { createStart: … } ``` + Plugin mocks should consist of mocks for *public APIs only*: setup/start/stop contracts. Mocks aren't necessary for pure functions as other plugins can call the original implementation in tests. #### Using mocks in your tests + During the migration process, it is likely you are preparing your plugin by shimming in new platform-ready dependencies via the legacy `ui/new_platform` module: + ```typescript import { npSetup, npStart } from 'ui/new_platform'; ``` If you are using this approach, the easiest way to mock core and new platform-ready plugins in your legacy tests is to mock the `ui/new_platform` module: + ```typescript jest.mock('ui/new_platform'); ``` -This will automatically mock the services in `ui/new_platform` thanks to the [helpers that have been added](https://github.com/elastic/kibana/blob/master/src/legacy/ui/public/new_platform/__mocks__/helpers.ts) to that module. +This will automatically mock the services in `ui/new_platform` thanks to the [helpers that have been added](../../src/legacy/ui/public/new_platform/__mocks__/helpers.ts) to that module. If others are consuming your plugin's new platform contracts via the `ui/new_platform` module, you'll want to update the helpers as well to ensure your contracts are properly mocked. > Note: The `ui/new_platform` mock is only designed for use by old Jest tests. If you are writing new tests, you should structure your code and tests such that you don't need this mock. Instead, you should import the `core` mock directly and instantiate it. #### What about karma tests? + While our plan is to only provide first-class mocks for Jest tests, there are many legacy karma tests that cannot be quickly or easily converted to Jest -- particularly those which are still relying on mocking Angular services via `ngMock`. For these tests, we are maintaining a separate set of mocks. Files with a `.karma_mock.{js|ts|tsx}` extension will be loaded _globally_ before karma tests are run. @@ -1424,11 +1469,15 @@ For these tests, we are maintaining a separate set of mocks. Files with a `.karm It is important to note that this behavior is different from `jest.mock('ui/new_platform')`, which only mocks tests on an individual basis. If you encounter any failures in karma tests as a result of new platform migration efforts, you may need to add a `.karma_mock.js` file for the affected services, or add to the existing karma mock we are maintaining in `ui/new_platform`. ### Provide Legacy Platform API to the New platform plugin + #### On the server side + During migration, you can face a problem that not all API is available in the New platform yet. You can work around this by extending your new platform plugin with Legacy API: + - create New platform plugin - New platform plugin should expose a method `registerLegacyAPI` that allows passing API from the Legacy platform and store it in the NP plugin instance + ```js class MyPlugin { public async setup(core){ @@ -1438,7 +1487,9 @@ class MyPlugin { } } ``` + - The legacy plugin provides API calling `registerLegacyAPI` + ```js new kibana.Plugin({ init(server){ @@ -1450,7 +1501,9 @@ new kibana.Plugin({ } }) ``` + - The new platform plugin access stored Legacy platform API via `getLegacyAPI` getter. Getter function must have name indicating that’s API provided from the Legacy platform. + ```js class MyPlugin { private getLegacyAPI(){ @@ -1469,6 +1522,7 @@ class MyPlugin { ``` #### On the client side -It's not currently possible to use a similar pattern on the client-side. -Because Legacy platform plugins heavily rely on global angular modules, which aren't available on the new platform. + +It's not currently possible to use a similar pattern on the client-side. +Because Legacy platform plugins heavily rely on global angular modules, which aren't available on the new platform. So you can utilize the same approach for only *stateless Angular components*, as long as they are not consumed by a New Platform application. When New Platform applications are on the page, no legacy code is executed, so the `registerLegacyAPI` function would not be called. diff --git a/src/core/MIGRATION_EXAMPLES.md b/src/core/MIGRATION_EXAMPLES.md index ccf14879baa379..04535039acbe70 100644 --- a/src/core/MIGRATION_EXAMPLES.md +++ b/src/core/MIGRATION_EXAMPLES.md @@ -56,6 +56,62 @@ export const config = { export type MyPluginConfig = TypeOf; ``` +### Using New Platform config in a new plugin + +After setting the config schema for your plugin, you might want to reach the configuration in the plugin. +It is provided as part of the [PluginInitializerContext](../../docs/development/core/server/kibana-plugin-server.plugininitializercontext.md) +in the *constructor* of the plugin: + +```ts +// myPlugin/(public|server)/index.ts + +import { PluginInitializerContext } from 'kibana/server'; +import { MyPlugin } from './plugin'; + +export function plugin(initializerContext: PluginInitializerContext) { + return new MyPlugin(initializerContext); +} +``` + +```ts +// myPlugin/(public|server)/plugin.ts + +import { Observable } from 'rxjs'; +import { first } from 'rxjs/operators'; +import { CoreSetup, Logger, Plugin, PluginInitializerContext, PluginName } from 'kibana/server'; +import { MyPlugin } from './plugin'; + +export class MyPlugin implements Plugin { + private readonly config$: Observable; + private readonly log: Logger; + + constructor(private readonly initializerContext: PluginInitializerContext) { + this.log = initializerContext.logger.get(); + this.config$ = initializerContext.config.create(); + } + + public async setup(core: CoreSetup, deps: Record) { + const isEnabled = await this.config$.pipe(first()).toPromise(); + ... + } + ... +} +} +``` + +Additionally, some plugins need to read other plugins' config to act accordingly (like timing out a request, matching ElasticSearch's timeout). For those use cases, the plugin can rely on the *globalConfig* and *env* properties in the context: + +```ts +export class MyPlugin implements Plugin { +... + public async setup(core: CoreSetup, deps: Record) { + const { mode: { dev }, packageInfo: { version } } = this.initializerContext.env; + const { elasticsearch: { shardTimeout }, path: { data } } = await this.initializerContext.config.legacy.globalConfig$ + .pipe(first()).toPromise(); + ... + } +``` + ### Using New Platform config from a Legacy plugin During the migration process, you'll want to migrate your schema to the new @@ -64,6 +120,7 @@ config service due to the way that config is tied to the `kibana.json` file (which does not exist for legacy plugins). There is a workaround though: + - Create a New Platform plugin that contains your plugin's config schema in the new format - Expose the config from the New Platform plugin in its setup contract - Read the config from the setup contract in your legacy plugin @@ -153,6 +210,7 @@ interface, which is exposed via the object injected into the `setup` method of server-side plugins. This interface has a different API with slightly different behaviors. + - All input (body, query parameters, and URL parameters) must be validated using the `@kbn/config-schema` package. If no validation schema is provided, these values will be empty objects. @@ -166,6 +224,7 @@ Because of the incompatibility between the legacy and New Platform HTTP Route API's it might be helpful to break up your migration work into several stages. ### 1. Legacy route registration + ```ts // legacy/plugins/myplugin/index.ts import Joi from 'joi'; @@ -191,6 +250,7 @@ new kibana.Plugin({ ``` ### 2. New Platform shim using legacy router + Create a New Platform shim and inject the legacy `server.route` into your plugin's setup function. @@ -214,6 +274,7 @@ export default (kibana) => { } } ``` + ```ts // legacy/plugins/demoplugin/server/plugin.ts import { CoreSetup } from 'src/core/server'; @@ -246,11 +307,13 @@ export class Plugin { ``` ### 3. New Platform shim using New Platform router + We now switch the shim to use the real New Platform HTTP API's in `coreSetup` instead of relying on the legacy `server.route`. Since our plugin is now using -the New Platform API's we are guaranteed that our HTTP route handling is 100% +the New Platform API's we are guaranteed that our HTTP route handling is 100% compatible with the New Platform. As a result, we will also have to adapt our -route registration accordingly. +route registration accordingly. + ```ts // legacy/plugins/demoplugin/index.ts import { Plugin } from './server/plugin'; @@ -268,6 +331,7 @@ export default (kibana) => { } } ``` + ```ts // legacy/plugins/demoplugin/server/plugin.ts import { schema } from '@kbn/config-schema'; @@ -298,8 +362,10 @@ class Plugin { } } ``` -If your plugin still relies on throwing Boom errors from routes, you can use the `router.handleLegacyErrors` + +If your plugin still relies on throwing Boom errors from routes, you can use the `router.handleLegacyErrors` as a temporary solution until error migration is complete: + ```ts // legacy/plugins/demoplugin/server/plugin.ts import { schema } from '@kbn/config-schema'; @@ -327,11 +393,12 @@ class Plugin { } ``` - #### 4. New Platform plugin + As the final step we delete the shim and move all our code into a New Platform plugin. Since we were already consuming the New Platform API's no code changes are necessary inside `plugin.ts`. + ```ts // Move legacy/plugins/demoplugin/server/plugin.ts -> plugins/demoplugin/server/plugin.ts ``` From 9337633f95f941735157090dc2574cc10a500be8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Ferna=CC=81ndez=20Haro?= Date: Wed, 4 Dec 2019 15:51:48 +0000 Subject: [PATCH 21/21] Fix 'kibana/server' imports in the MIGRATION docs --- src/core/MIGRATION.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/MIGRATION.md b/src/core/MIGRATION.md index f14b4cb290c228..7b8ee6d2fcf75a 100644 --- a/src/core/MIGRATION.md +++ b/src/core/MIGRATION.md @@ -738,7 +738,7 @@ This definition isn't going to do much for us just yet, but as we get further in ```ts // public/plugin.ts -import { CoreSetup, CoreStart, Plugin } from '../kibana/server'; +import { CoreSetup, CoreStart, Plugin } from 'kibana/server'; import { FooSetup, FooStart } from '../../../../legacy/core_plugins/foo/public'; /** @@ -806,7 +806,7 @@ While you're at it, you can also add your plugin initializer to this file: ```ts // public/index.ts -import { PluginInitializer, PluginInitializerContext } from '../kibana/server'; +import { PluginInitializer, PluginInitializerContext } from 'kibana/server'; import { DemoSetup, DemoStart, DemoSetupDeps, DemoStartDeps, DemoPlugin } from './plugin'; // Core will be looking for this when loading our plugin in the new platform @@ -840,7 +840,7 @@ So we will take a similar approach to what was described above in the server sec ```ts // public/legacy.ts -import { PluginInitializerContext } from '../kibana/server'; +import { PluginInitializerContext } from 'kibana/server'; import { npSetup, npStart } from 'ui/new_platform'; import { plugin } from '.';