From 4bc901edea4e3831dde1c8bcc3d4b5f0286d5180 Mon Sep 17 00:00:00 2001 From: Christiane Heiligers Date: Fri, 8 Jul 2022 17:56:52 -0700 Subject: [PATCH 1/9] Moves types to core-preboot-server and creates public versions where needed --- package.json | 2 + packages/BUILD.bazel | 2 + .../preboot/core-preboot-server/BUILD.bazel | 98 +++++++++++++++++++ .../preboot/core-preboot-server/README.md | 3 + .../core-preboot-server/jest.config.js | 13 +++ .../preboot/core-preboot-server/package.json | 7 ++ .../core-preboot-server/src/contracts.ts | 88 +++++++++++++++++ .../preboot/core-preboot-server/src/index.ts | 13 +++ .../preboot/core-preboot-server/tsconfig.json | 18 ++++ src/core/server/index.ts | 4 +- src/core/server/preboot/index.ts | 2 +- .../server/preboot/preboot_service.mock.ts | 9 +- src/core/server/preboot/preboot_service.ts | 4 +- src/core/server/preboot/types.ts | 45 --------- .../interactive_setup/server/routes/index.ts | 3 +- yarn.lock | 8 ++ 16 files changed, 261 insertions(+), 58 deletions(-) create mode 100644 packages/core/preboot/core-preboot-server/BUILD.bazel create mode 100644 packages/core/preboot/core-preboot-server/README.md create mode 100644 packages/core/preboot/core-preboot-server/jest.config.js create mode 100644 packages/core/preboot/core-preboot-server/package.json create mode 100644 packages/core/preboot/core-preboot-server/src/contracts.ts create mode 100644 packages/core/preboot/core-preboot-server/src/index.ts create mode 100644 packages/core/preboot/core-preboot-server/tsconfig.json diff --git a/package.json b/package.json index f6d01e45fcb1a..b87e61a54f6b2 100644 --- a/package.json +++ b/package.json @@ -189,6 +189,7 @@ "@kbn/core-node-server": "link:bazel-bin/packages/core/node/core-node-server", "@kbn/core-node-server-internal": "link:bazel-bin/packages/core/node/core-node-server-internal", "@kbn/core-node-server-mocks": "link:bazel-bin/packages/core/node/core-node-server-mocks", + "@kbn/core-preboot-server": "link:bazel-bin/packages/core/preboot/core-preboot-server", "@kbn/core-theme-browser": "link:bazel-bin/packages/core/theme/core-theme-browser", "@kbn/core-theme-browser-internal": "link:bazel-bin/packages/core/theme/core-theme-browser-internal", "@kbn/core-theme-browser-mocks": "link:bazel-bin/packages/core/theme/core-theme-browser-mocks", @@ -744,6 +745,7 @@ "@types/kbn__core-node-server": "link:bazel-bin/packages/core/node/core-node-server/npm_module_types", "@types/kbn__core-node-server-internal": "link:bazel-bin/packages/core/node/core-node-server-internal/npm_module_types", "@types/kbn__core-node-server-mocks": "link:bazel-bin/packages/core/node/core-node-server-mocks/npm_module_types", + "@types/kbn__core-preboot-server": "link:bazel-bin/packages/core/preboot/core-preboot-server/npm_module_types", "@types/kbn__core-public-internal-base": "link:bazel-bin/packages/core/public/internal-base/npm_module_types", "@types/kbn__core-server-internal-base": "link:bazel-bin/packages/core/server/internal-base/npm_module_types", "@types/kbn__core-theme-browser": "link:bazel-bin/packages/core/theme/core-theme-browser/npm_module_types", diff --git a/packages/BUILD.bazel b/packages/BUILD.bazel index 07d7212cf6a79..efd640aeb7903 100644 --- a/packages/BUILD.bazel +++ b/packages/BUILD.bazel @@ -58,6 +58,7 @@ filegroup( "//packages/core/node/core-node-server-internal:build", "//packages/core/node/core-node-server-mocks:build", "//packages/core/node/core-node-server:build", + "//packages/core/preboot/core-preboot-server:build", "//packages/core/theme/core-theme-browser-internal:build", "//packages/core/theme/core-theme-browser-mocks:build", "//packages/core/theme/core-theme-browser:build", @@ -238,6 +239,7 @@ filegroup( "//packages/core/node/core-node-server-internal:build_types", "//packages/core/node/core-node-server-mocks:build_types", "//packages/core/node/core-node-server:build_types", + "//packages/core/preboot/core-preboot-server:build_types", "//packages/core/theme/core-theme-browser-internal:build_types", "//packages/core/theme/core-theme-browser-mocks:build_types", "//packages/core/theme/core-theme-browser:build_types", diff --git a/packages/core/preboot/core-preboot-server/BUILD.bazel b/packages/core/preboot/core-preboot-server/BUILD.bazel new file mode 100644 index 0000000000000..178d866c86ab0 --- /dev/null +++ b/packages/core/preboot/core-preboot-server/BUILD.bazel @@ -0,0 +1,98 @@ +load("@npm//@bazel/typescript:index.bzl", "ts_config") +load("@build_bazel_rules_nodejs//:index.bzl", "js_library") +load("//src/dev/bazel:index.bzl", "jsts_transpiler", "pkg_npm", "pkg_npm_types", "ts_project") + +PKG_DIRNAME = "core-preboot-server" +PKG_REQUIRE_NAME = "@kbn/core-preboot-server" + +SOURCE_FILES = glob( + [ + "src/**/*.ts", + ], + exclude = [ + "**/*.test.*", + "**/*.stories.*", + ], +) + +SRCS = SOURCE_FILES + +filegroup( + name = "srcs", + srcs = SRCS, +) + +NPM_MODULE_EXTRA_FILES = [ + "package.json", +] + +RUNTIME_DEPS = [ +] + +TYPES_DEPS = [ + "@npm//@types/node", + "@npm//@types/jest", + "//packages/core/base/core-base-common:npm_module_types", +] + +jsts_transpiler( + name = "target_node", + srcs = SRCS, + build_pkg_name = package_name(), +) + +ts_config( + name = "tsconfig", + src = "tsconfig.json", + deps = [ + "//:tsconfig.base.json", + "//:tsconfig.bazel.json", + ], +) + +ts_project( + name = "tsc_types", + args = ['--pretty'], + srcs = SRCS, + deps = TYPES_DEPS, + declaration = True, + declaration_map = True, + emit_declaration_only = True, + out_dir = "target_types", + root_dir = "src", + tsconfig = ":tsconfig", +) + +js_library( + name = PKG_DIRNAME, + srcs = NPM_MODULE_EXTRA_FILES, + deps = RUNTIME_DEPS + [":target_node"], + package_name = PKG_REQUIRE_NAME, + visibility = ["//visibility:public"], +) + +pkg_npm( + name = "npm_module", + deps = [":" + PKG_DIRNAME], +) + +filegroup( + name = "build", + srcs = [":npm_module"], + visibility = ["//visibility:public"], +) + +pkg_npm_types( + name = "npm_module_types", + srcs = SRCS, + deps = [":tsc_types"], + package_name = PKG_REQUIRE_NAME, + tsconfig = ":tsconfig", + visibility = ["//visibility:public"], +) + +filegroup( + name = "build_types", + srcs = [":npm_module_types"], + visibility = ["//visibility:public"], +) diff --git a/packages/core/preboot/core-preboot-server/README.md b/packages/core/preboot/core-preboot-server/README.md new file mode 100644 index 0000000000000..8eaed8836415f --- /dev/null +++ b/packages/core/preboot/core-preboot-server/README.md @@ -0,0 +1,3 @@ +# @kbn/core-preboot-server + +Contains public types for Core's server-side `preboot` service diff --git a/packages/core/preboot/core-preboot-server/jest.config.js b/packages/core/preboot/core-preboot-server/jest.config.js new file mode 100644 index 0000000000000..aae1c1ac8f821 --- /dev/null +++ b/packages/core/preboot/core-preboot-server/jest.config.js @@ -0,0 +1,13 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +module.exports = { + preset: '@kbn/test/jest_node', + rootDir: '../../../..', + roots: ['/packages/core/preboot/core-preboot-server'], +}; diff --git a/packages/core/preboot/core-preboot-server/package.json b/packages/core/preboot/core-preboot-server/package.json new file mode 100644 index 0000000000000..ef598d368ace4 --- /dev/null +++ b/packages/core/preboot/core-preboot-server/package.json @@ -0,0 +1,7 @@ +{ + "name": "@kbn/core-preboot-server", + "private": true, + "version": "1.0.0", + "main": "./target_node/index.js", + "license": "SSPL-1.0 OR Elastic License 2.0" +} diff --git a/packages/core/preboot/core-preboot-server/src/contracts.ts b/packages/core/preboot/core-preboot-server/src/contracts.ts new file mode 100644 index 0000000000000..9870ecc284ca8 --- /dev/null +++ b/packages/core/preboot/core-preboot-server/src/contracts.ts @@ -0,0 +1,88 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ +import type { PluginName } from '@kbn/core-base-common'; +/** + * Kibana Preboot Service allows to control the boot flow of Kibana. Preboot plugins can use it to hold the boot until certain condition is met. + * + * @example + * A plugin can supply a `Promise` to a `holdSetupUntilResolved` method to signal Kibana to initialize and start `standard` plugins only after this + * `Promise` is resolved. If `Promise` is rejected, Kibana will shut down. + * ```ts + * core.preboot.holdSetupUntilResolved('Just waiting for 5 seconds', + * new Promise((resolve) => { + * setTimeout(resolve, 5000); + * }) + * ); + * ``` + * + * If the supplied `Promise` resolves to an object with the `shouldReloadConfig` property set to `true`, Kibana will also reload its configuration from disk. + * ```ts + * let completeSetup: (result: { shouldReloadConfig: boolean }) => void; + * core.preboot.holdSetupUntilResolved('Just waiting for 5 seconds before reloading configuration', + * new Promise<{ shouldReloadConfig: boolean }>((resolve) => { + * setTimeout(() => resolve({ shouldReloadConfig: true }), 5000); + * }) + * ); + * ``` + * @public + */ +export interface PrebootServicePreboot { + /** + * Indicates whether Kibana is currently on hold and cannot proceed to `setup` yet. + */ + readonly isSetupOnHold: () => boolean; + + /** + * Registers a `Promise` as a precondition before Kibana can proceed to `setup`. This method can be invoked multiple + * times and from multiple `preboot` plugins. Kibana will proceed to `setup` only when all registered `Promises` + * instances are resolved, or it will shut down if any of them is rejected. + * @param reason A string that explains the reason why this promise should hold `setup`. It's supposed to be a human + * readable string that will be recorded in the logs or standard output. + * @param promise A `Promise` that should resolved before Kibana can proceed to `setup`. + */ + readonly holdSetupUntilResolved: ( + reason: string, + promise: Promise<{ shouldReloadConfig: boolean } | undefined> + ) => void; +} + +/** + * @public + */ +export interface KibanaPrebootServicePreboot + extends Omit { + /** + * Registers a `Promise` as a precondition before Kibana can proceed to `setup`. This method can be invoked multiple + * times and from multiple `preboot` plugins. Kibana will proceed to `setup` only when all registered `Promise` are + * resolved, or it will shut down if any of them are rejected. + * @param pluginName Name of the plugin that needs to hold `setup`. + * @param reason A string that explains the reason why this promise should hold `setup`. It's supposed to be a human + * readable string that will be recorded in the logs or standard output. + * @param promise A `Promise` that should resolved before Kibana can proceed to `setup`. + */ + readonly holdSetupUntilResolved: ( + pluginName: PluginName, + reason: string, + promise: Promise<{ shouldReloadConfig: boolean } | undefined> + ) => void; + /** + * Returns a `Promise` that is resolved only when all `Promise` instances registered with {@link holdSetupUntilResolved} + * are resolved, or rejected if any of them are rejected. If the supplied `Promise` resolves to an object with the + * `shouldReloadConfig` property set to `true`, it indicates that Kibana configuration might have changed and Kibana + * needs to reload it from the disk. + */ + readonly waitUntilCanSetup: () => Promise<{ shouldReloadConfig: boolean }>; +} + +/** + * @public + */ +export interface KibanaPrebootServiceContract { + preboot: () => KibanaPrebootServicePreboot; + stop: () => void; +} diff --git a/packages/core/preboot/core-preboot-server/src/index.ts b/packages/core/preboot/core-preboot-server/src/index.ts new file mode 100644 index 0000000000000..01f0dc952562a --- /dev/null +++ b/packages/core/preboot/core-preboot-server/src/index.ts @@ -0,0 +1,13 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +export type { + PrebootServicePreboot, + KibanaPrebootServicePreboot, + KibanaPrebootServiceContract, +} from './contracts'; diff --git a/packages/core/preboot/core-preboot-server/tsconfig.json b/packages/core/preboot/core-preboot-server/tsconfig.json new file mode 100644 index 0000000000000..39d3c7097814a --- /dev/null +++ b/packages/core/preboot/core-preboot-server/tsconfig.json @@ -0,0 +1,18 @@ +{ + "extends": "../../../../tsconfig.bazel.json", + "compilerOptions": { + "declaration": true, + "declarationMap": true, + "emitDeclarationOnly": true, + "outDir": "target_types", + "rootDir": "src", + "stripInternal": false, + "types": [ + "jest", + "node" + ] + }, + "include": [ + "src/**/*" + ] +} diff --git a/src/core/server/index.ts b/src/core/server/index.ts index 1f1bdaeab57f0..5a143bdf22a45 100644 --- a/src/core/server/index.ts +++ b/src/core/server/index.ts @@ -42,6 +42,7 @@ import type { ExecutionContextSetup, ExecutionContextStart, } from '@kbn/core-execution-context-server'; +import type { PrebootServicePreboot } from '@kbn/core-preboot-server'; import { ElasticsearchServiceSetup, configSchema as elasticsearchConfigSchema, @@ -76,13 +77,10 @@ import { CoreEnvironmentUsageData, CoreServicesUsageData, } from './core_usage_data'; -import { PrebootServicePreboot } from './preboot'; import type { CoreRequestHandlerContext } from './core_route_handler_context'; import type { PrebootCoreRequestHandlerContext } from './preboot_core_route_handler_context'; import { KibanaResponseFactory, RouteMethod } from './http'; -export type { PrebootServicePreboot } from './preboot'; - export type { CoreUsageStats, CoreUsageData, diff --git a/src/core/server/preboot/index.ts b/src/core/server/preboot/index.ts index 2b7f25538dcb1..0f4df508c5b31 100644 --- a/src/core/server/preboot/index.ts +++ b/src/core/server/preboot/index.ts @@ -7,4 +7,4 @@ */ export { PrebootService } from './preboot_service'; -export type { InternalPrebootServicePreboot, PrebootServicePreboot } from './types'; +export type { InternalPrebootServicePreboot } from './types'; diff --git a/src/core/server/preboot/preboot_service.mock.ts b/src/core/server/preboot/preboot_service.mock.ts index acdd9458a462d..1c67f6b38b722 100644 --- a/src/core/server/preboot/preboot_service.mock.ts +++ b/src/core/server/preboot/preboot_service.mock.ts @@ -6,13 +6,12 @@ * Side Public License, v 1. */ -import type { PublicMethodsOf } from '@kbn/utility-types'; -import type { InternalPrebootServicePreboot, PrebootServicePreboot } from './types'; -import { PrebootService } from './preboot_service'; +import type { InternalPrebootServicePreboot } from './types'; +import type { PrebootServicePreboot, KibanaPrebootServiceContract } from '@kbn/core-preboot-server'; export type InternalPrebootServicePrebootMock = jest.Mocked; export type PrebootServicePrebootMock = jest.Mocked; - +export type PrebootServiceContract = jest.Mocked; const createInternalPrebootContractMock = () => { const mock: InternalPrebootServicePrebootMock = { isSetupOnHold: jest.fn(), @@ -31,8 +30,6 @@ const createPrebootContractMock = () => { return mock; }; -type PrebootServiceContract = PublicMethodsOf; - const createPrebootServiceMock = () => { const mocked: jest.Mocked = { preboot: jest.fn(), diff --git a/src/core/server/preboot/preboot_service.ts b/src/core/server/preboot/preboot_service.ts index 328f4f2cdd360..841c9bde02f9b 100644 --- a/src/core/server/preboot/preboot_service.ts +++ b/src/core/server/preboot/preboot_service.ts @@ -8,7 +8,7 @@ import type { Logger } from '@kbn/logging'; import type { CoreContext } from '@kbn/core-base-server-internal'; -import { InternalPrebootServicePreboot } from './types'; +import type { KibanaPrebootServicePreboot } from '@kbn/core-preboot-server'; /** @internal */ export class PrebootService { @@ -21,7 +21,7 @@ export class PrebootService { this.log = this.core.logger.get('preboot'); } - public preboot(): InternalPrebootServicePreboot { + public preboot(): KibanaPrebootServicePreboot { return { isSetupOnHold: () => this.isSetupOnHold, holdSetupUntilResolved: (pluginName, reason, promise) => { diff --git a/src/core/server/preboot/types.ts b/src/core/server/preboot/types.ts index 4d36eeb569429..a8d5a60fd9e48 100644 --- a/src/core/server/preboot/types.ts +++ b/src/core/server/preboot/types.ts @@ -38,48 +38,3 @@ export interface InternalPrebootServicePreboot { */ readonly waitUntilCanSetup: () => Promise<{ shouldReloadConfig: boolean }>; } - -/** - * Kibana Preboot Service allows to control the boot flow of Kibana. Preboot plugins can use it to hold the boot until certain condition is met. - * - * @example - * A plugin can supply a `Promise` to a `holdSetupUntilResolved` method to signal Kibana to initialize and start `standard` plugins only after this - * `Promise` is resolved. If `Promise` is rejected, Kibana will shut down. - * ```ts - * core.preboot.holdSetupUntilResolved('Just waiting for 5 seconds', - * new Promise((resolve) => { - * setTimeout(resolve, 5000); - * }) - * ); - * ``` - * - * If the supplied `Promise` resolves to an object with the `shouldReloadConfig` property set to `true`, Kibana will also reload its configuration from disk. - * ```ts - * let completeSetup: (result: { shouldReloadConfig: boolean }) => void; - * core.preboot.holdSetupUntilResolved('Just waiting for 5 seconds before reloading configuration', - * new Promise<{ shouldReloadConfig: boolean }>((resolve) => { - * setTimeout(() => resolve({ shouldReloadConfig: true }), 5000); - * }) - * ); - * ``` - * @public - */ -export interface PrebootServicePreboot { - /** - * Indicates whether Kibana is currently on hold and cannot proceed to `setup` yet. - */ - readonly isSetupOnHold: () => boolean; - - /** - * Registers a `Promise` as a precondition before Kibana can proceed to `setup`. This method can be invoked multiple - * times and from multiple `preboot` plugins. Kibana will proceed to `setup` only when all registered `Promises` - * instances are resolved, or it will shut down if any of them is rejected. - * @param reason A string that explains the reason why this promise should hold `setup`. It's supposed to be a human - * readable string that will be recorded in the logs or standard output. - * @param promise A `Promise` that should resolved before Kibana can proceed to `setup`. - */ - readonly holdSetupUntilResolved: ( - reason: string, - promise: Promise<{ shouldReloadConfig: boolean } | undefined> - ) => void; -} diff --git a/src/plugins/interactive_setup/server/routes/index.ts b/src/plugins/interactive_setup/server/routes/index.ts index 804bc9bddbc91..410fb5b42037c 100644 --- a/src/plugins/interactive_setup/server/routes/index.ts +++ b/src/plugins/interactive_setup/server/routes/index.ts @@ -6,7 +6,8 @@ * Side Public License, v 1. */ -import type { IBasePath, IRouter, Logger, PrebootServicePreboot } from '@kbn/core/server'; +import type { PrebootServicePreboot } from '@kbn/core-preboot-server'; +import type { IBasePath, IRouter, Logger } from '@kbn/core/server'; import type { PublicContract, PublicMethodsOf } from '@kbn/utility-types'; import type { ConfigType } from '../config'; diff --git a/yarn.lock b/yarn.lock index e388ecd6ec457..fd0e8d9644355 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3228,6 +3228,10 @@ version "0.0.0" uid "" +"@kbn/core-preboot-server@link:bazel-bin/packages/core/preboot/core-preboot-server": + version "0.0.0" + uid "" + "@kbn/core-theme-browser-internal@link:bazel-bin/packages/core/theme/core-theme-browser-internal": version "0.0.0" uid "" @@ -6779,6 +6783,10 @@ version "0.0.0" uid "" +"@types/kbn__core-preboot-server@link:bazel-bin/packages/core/preboot/core-preboot-server/npm_module_types": + version "0.0.0" + uid "" + "@types/kbn__core-public-internal-base@link:bazel-bin/packages/core/public/internal-base/npm_module_types": version "0.0.0" uid "" From fec237948c3eb5ec985d2d0f58eef1609d13bc27 Mon Sep 17 00:00:00 2001 From: Christiane Heiligers Date: Fri, 8 Jul 2022 18:41:18 -0700 Subject: [PATCH 2/9] Moves implementation and internal types to core-preboot-server-internal package --- package.json | 2 + packages/BUILD.bazel | 2 + .../core-preboot-server-internal/BUILD.bazel | 129 ++++++++++++++++++ .../core-preboot-server-internal/README.md | 3 + .../jest.config.js | 13 ++ .../core-preboot-server-internal/package.json | 7 + .../core-preboot-server-internal/src/index.ts | 10 ++ .../src}/preboot_service.test.ts | 4 +- .../src}/preboot_service.ts | 0 .../src}/types.ts | 0 .../tsconfig.json | 18 +++ yarn.lock | 8 ++ 12 files changed, 194 insertions(+), 2 deletions(-) create mode 100644 packages/core/preboot/core-preboot-server-internal/BUILD.bazel create mode 100644 packages/core/preboot/core-preboot-server-internal/README.md create mode 100644 packages/core/preboot/core-preboot-server-internal/jest.config.js create mode 100644 packages/core/preboot/core-preboot-server-internal/package.json create mode 100644 packages/core/preboot/core-preboot-server-internal/src/index.ts rename {src/core/server/preboot => packages/core/preboot/core-preboot-server-internal/src}/preboot_service.test.ts (97%) rename {src/core/server/preboot => packages/core/preboot/core-preboot-server-internal/src}/preboot_service.ts (100%) rename {src/core/server/preboot => packages/core/preboot/core-preboot-server-internal/src}/types.ts (100%) create mode 100644 packages/core/preboot/core-preboot-server-internal/tsconfig.json diff --git a/package.json b/package.json index b87e61a54f6b2..4cb812e8d74a7 100644 --- a/package.json +++ b/package.json @@ -190,6 +190,7 @@ "@kbn/core-node-server-internal": "link:bazel-bin/packages/core/node/core-node-server-internal", "@kbn/core-node-server-mocks": "link:bazel-bin/packages/core/node/core-node-server-mocks", "@kbn/core-preboot-server": "link:bazel-bin/packages/core/preboot/core-preboot-server", + "@kbn/core-preboot-server-internal": "link:bazel-bin/packages/core/preboot/core-preboot-server-internal", "@kbn/core-theme-browser": "link:bazel-bin/packages/core/theme/core-theme-browser", "@kbn/core-theme-browser-internal": "link:bazel-bin/packages/core/theme/core-theme-browser-internal", "@kbn/core-theme-browser-mocks": "link:bazel-bin/packages/core/theme/core-theme-browser-mocks", @@ -746,6 +747,7 @@ "@types/kbn__core-node-server-internal": "link:bazel-bin/packages/core/node/core-node-server-internal/npm_module_types", "@types/kbn__core-node-server-mocks": "link:bazel-bin/packages/core/node/core-node-server-mocks/npm_module_types", "@types/kbn__core-preboot-server": "link:bazel-bin/packages/core/preboot/core-preboot-server/npm_module_types", + "@types/kbn__core-preboot-server-internal": "link:bazel-bin/packages/core/preboot/core-preboot-server-internal/npm_module_types", "@types/kbn__core-public-internal-base": "link:bazel-bin/packages/core/public/internal-base/npm_module_types", "@types/kbn__core-server-internal-base": "link:bazel-bin/packages/core/server/internal-base/npm_module_types", "@types/kbn__core-theme-browser": "link:bazel-bin/packages/core/theme/core-theme-browser/npm_module_types", diff --git a/packages/BUILD.bazel b/packages/BUILD.bazel index efd640aeb7903..3329141b80d97 100644 --- a/packages/BUILD.bazel +++ b/packages/BUILD.bazel @@ -58,6 +58,7 @@ filegroup( "//packages/core/node/core-node-server-internal:build", "//packages/core/node/core-node-server-mocks:build", "//packages/core/node/core-node-server:build", + "//packages/core/preboot/core-preboot-server-internal:build", "//packages/core/preboot/core-preboot-server:build", "//packages/core/theme/core-theme-browser-internal:build", "//packages/core/theme/core-theme-browser-mocks:build", @@ -239,6 +240,7 @@ filegroup( "//packages/core/node/core-node-server-internal:build_types", "//packages/core/node/core-node-server-mocks:build_types", "//packages/core/node/core-node-server:build_types", + "//packages/core/preboot/core-preboot-server-internal:build_types", "//packages/core/preboot/core-preboot-server:build_types", "//packages/core/theme/core-theme-browser-internal:build_types", "//packages/core/theme/core-theme-browser-mocks:build_types", diff --git a/packages/core/preboot/core-preboot-server-internal/BUILD.bazel b/packages/core/preboot/core-preboot-server-internal/BUILD.bazel new file mode 100644 index 0000000000000..5e8b4cba592c5 --- /dev/null +++ b/packages/core/preboot/core-preboot-server-internal/BUILD.bazel @@ -0,0 +1,129 @@ +load("@npm//@bazel/typescript:index.bzl", "ts_config") +load("@build_bazel_rules_nodejs//:index.bzl", "js_library") +load("//src/dev/bazel:index.bzl", "jsts_transpiler", "pkg_npm", "pkg_npm_types", "ts_project") + +PKG_DIRNAME = "core-preboot-server-internal" +PKG_REQUIRE_NAME = "@kbn/core-preboot-server-internal" + +SOURCE_FILES = glob( + [ + "src/**/*.ts", + ], + exclude = [ + "**/*.test.*", + "**/*.stories.*", + ], +) + +SRCS = SOURCE_FILES + +filegroup( + name = "srcs", + srcs = SRCS, +) + +NPM_MODULE_EXTRA_FILES = [ + "package.json", +] + +# In this array place runtime dependencies, including other packages and NPM packages +# which must be available for this code to run. +# +# To reference other packages use: +# "//repo/relative/path/to/package" +# eg. "//packages/kbn-utils" +# +# To reference a NPM package use: +# "@npm//name-of-package" +# eg. "@npm//lodash" +RUNTIME_DEPS = [ + "//packages/core/logging/core-logging-server-mocks", + "//packages/core/base/core-base-common", + "//packages/kbn-config-mocks", + "//packages/kbn-config", + "//packages/kbn-logging", + "//packages/kbn-utils" +] + +# In this array place dependencies necessary to build the types, which will include the +# :npm_module_types target of other packages and packages from NPM, including @types/* +# packages. +# +# To reference the types for another package use: +# "//repo/relative/path/to/package:npm_module_types" +# eg. "//packages/kbn-utils:npm_module_types" +# +# References to NPM packages work the same as RUNTIME_DEPS +TYPES_DEPS = [ + "@npm//@types/node", + "@npm//@types/jest", + "//packages/core/logging/core-logging-server-mocks:npm_module_types", + "//packages/core/base/core-base-common:npm_module_types", + "//packages/kbn-config-mocks:npm_module_types", + "//packages/kbn-config:npm_module_types", + "//packages/kbn-logging:npm_module_types", + "//packages/kbn-utils:npm_module_types", + "//packages/core/preboot/core-preboot-server:npm_module_types" +] + +jsts_transpiler( + name = "target_node", + srcs = SRCS, + build_pkg_name = package_name(), +) + +ts_config( + name = "tsconfig", + src = "tsconfig.json", + deps = [ + "//:tsconfig.base.json", + "//:tsconfig.bazel.json", + ], +) + +ts_project( + name = "tsc_types", + args = ['--pretty'], + srcs = SRCS, + deps = TYPES_DEPS, + declaration = True, + declaration_map = True, + emit_declaration_only = True, + out_dir = "target_types", + root_dir = "src", + tsconfig = ":tsconfig", +) + +js_library( + name = PKG_DIRNAME, + srcs = NPM_MODULE_EXTRA_FILES, + deps = RUNTIME_DEPS + [":target_node"], + package_name = PKG_REQUIRE_NAME, + visibility = ["//visibility:public"], +) + +pkg_npm( + name = "npm_module", + deps = [":" + PKG_DIRNAME], +) + +filegroup( + name = "build", + srcs = [":npm_module"], + visibility = ["//visibility:public"], +) + +pkg_npm_types( + name = "npm_module_types", + srcs = SRCS, + deps = [":tsc_types"], + package_name = PKG_REQUIRE_NAME, + tsconfig = ":tsconfig", + visibility = ["//visibility:public"], +) + +filegroup( + name = "build_types", + srcs = [":npm_module_types"], + visibility = ["//visibility:public"], +) diff --git a/packages/core/preboot/core-preboot-server-internal/README.md b/packages/core/preboot/core-preboot-server-internal/README.md new file mode 100644 index 0000000000000..c26e2d00210c3 --- /dev/null +++ b/packages/core/preboot/core-preboot-server-internal/README.md @@ -0,0 +1,3 @@ +# @kbn/core-preboot-server-internal + +This package contains the internal types and implementation for Core's server-side preboot service. diff --git a/packages/core/preboot/core-preboot-server-internal/jest.config.js b/packages/core/preboot/core-preboot-server-internal/jest.config.js new file mode 100644 index 0000000000000..419bd4ebf014c --- /dev/null +++ b/packages/core/preboot/core-preboot-server-internal/jest.config.js @@ -0,0 +1,13 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +module.exports = { + preset: '@kbn/test/jest_node', + rootDir: '../../../..', + roots: ['/packages/core/preboot/core-preboot-server-internal'], +}; diff --git a/packages/core/preboot/core-preboot-server-internal/package.json b/packages/core/preboot/core-preboot-server-internal/package.json new file mode 100644 index 0000000000000..897d4506b3f7f --- /dev/null +++ b/packages/core/preboot/core-preboot-server-internal/package.json @@ -0,0 +1,7 @@ +{ + "name": "@kbn/core-preboot-server-internal", + "private": true, + "version": "1.0.0", + "main": "./target_node/index.js", + "license": "SSPL-1.0 OR Elastic License 2.0" +} diff --git a/packages/core/preboot/core-preboot-server-internal/src/index.ts b/packages/core/preboot/core-preboot-server-internal/src/index.ts new file mode 100644 index 0000000000000..e4e0571da72e4 --- /dev/null +++ b/packages/core/preboot/core-preboot-server-internal/src/index.ts @@ -0,0 +1,10 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +export type { InternalPrebootServicePreboot } from './types'; +export { PrebootService } from './preboot_service'; diff --git a/src/core/server/preboot/preboot_service.test.ts b/packages/core/preboot/core-preboot-server-internal/src/preboot_service.test.ts similarity index 97% rename from src/core/server/preboot/preboot_service.test.ts rename to packages/core/preboot/core-preboot-server-internal/src/preboot_service.test.ts index 7dc0eac5c4348..beb3e9d71b9c7 100644 --- a/src/core/server/preboot/preboot_service.test.ts +++ b/packages/core/preboot/core-preboot-server-internal/src/preboot_service.test.ts @@ -9,8 +9,8 @@ import { REPO_ROOT } from '@kbn/utils'; import { LoggerFactory } from '@kbn/logging'; import { Env } from '@kbn/config'; -import { getEnvOptions } from '@kbn/config-mocks'; -import { configServiceMock, loggingSystemMock } from '../mocks'; +import { configServiceMock, getEnvOptions } from '@kbn/config-mocks'; +import { loggingSystemMock } from '@kbn/core-logging-server-mocks'; import { PrebootService } from './preboot_service'; diff --git a/src/core/server/preboot/preboot_service.ts b/packages/core/preboot/core-preboot-server-internal/src/preboot_service.ts similarity index 100% rename from src/core/server/preboot/preboot_service.ts rename to packages/core/preboot/core-preboot-server-internal/src/preboot_service.ts diff --git a/src/core/server/preboot/types.ts b/packages/core/preboot/core-preboot-server-internal/src/types.ts similarity index 100% rename from src/core/server/preboot/types.ts rename to packages/core/preboot/core-preboot-server-internal/src/types.ts diff --git a/packages/core/preboot/core-preboot-server-internal/tsconfig.json b/packages/core/preboot/core-preboot-server-internal/tsconfig.json new file mode 100644 index 0000000000000..39d3c7097814a --- /dev/null +++ b/packages/core/preboot/core-preboot-server-internal/tsconfig.json @@ -0,0 +1,18 @@ +{ + "extends": "../../../../tsconfig.bazel.json", + "compilerOptions": { + "declaration": true, + "declarationMap": true, + "emitDeclarationOnly": true, + "outDir": "target_types", + "rootDir": "src", + "stripInternal": false, + "types": [ + "jest", + "node" + ] + }, + "include": [ + "src/**/*" + ] +} diff --git a/yarn.lock b/yarn.lock index fd0e8d9644355..7a0da590ecd93 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3228,6 +3228,10 @@ version "0.0.0" uid "" +"@kbn/core-preboot-server-internal@link:bazel-bin/packages/core/preboot/core-preboot-server-internal": + version "0.0.0" + uid "" + "@kbn/core-preboot-server@link:bazel-bin/packages/core/preboot/core-preboot-server": version "0.0.0" uid "" @@ -6783,6 +6787,10 @@ version "0.0.0" uid "" +"@types/kbn__core-preboot-server-internal@link:bazel-bin/packages/core/preboot/core-preboot-server-internal/npm_module_types": + version "0.0.0" + uid "" + "@types/kbn__core-preboot-server@link:bazel-bin/packages/core/preboot/core-preboot-server/npm_module_types": version "0.0.0" uid "" From 4308f12232d9dff1761eef4a393813342e9ecf74 Mon Sep 17 00:00:00 2001 From: Christiane Heiligers Date: Fri, 8 Jul 2022 19:01:53 -0700 Subject: [PATCH 3/9] Updates core imports of preboot implementation and internal types --- src/core/server/internal_types.ts | 2 +- src/core/server/preboot/index.ts | 10 ---------- src/core/server/server.test.mocks.ts | 2 +- src/core/server/server.ts | 2 +- 4 files changed, 3 insertions(+), 13 deletions(-) delete mode 100644 src/core/server/preboot/index.ts diff --git a/src/core/server/internal_types.ts b/src/core/server/internal_types.ts index 98fb13be13d28..298fa83e0b2d7 100644 --- a/src/core/server/internal_types.ts +++ b/src/core/server/internal_types.ts @@ -21,6 +21,7 @@ import type { InternalExecutionContextSetup, InternalExecutionContextStart, } from '@kbn/core-execution-context-server-internal'; +import { InternalPrebootServicePreboot } from '@kbn/core-preboot-server-internal'; import { CapabilitiesSetup, CapabilitiesStart } from './capabilities'; import { InternalContextPreboot, InternalContextSetup } from './context'; import { @@ -49,7 +50,6 @@ import { InternalStatusServiceSetup } from './status'; import { CoreUsageDataStart, InternalCoreUsageDataSetup } from './core_usage_data'; import { I18nServiceSetup } from './i18n'; import { InternalDeprecationsServiceSetup, InternalDeprecationsServiceStart } from './deprecations'; -import { InternalPrebootServicePreboot } from './preboot'; /** @internal */ export interface InternalCorePreboot { diff --git a/src/core/server/preboot/index.ts b/src/core/server/preboot/index.ts deleted file mode 100644 index 0f4df508c5b31..0000000000000 --- a/src/core/server/preboot/index.ts +++ /dev/null @@ -1,10 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -export { PrebootService } from './preboot_service'; -export type { InternalPrebootServicePreboot } from './types'; diff --git a/src/core/server/server.test.mocks.ts b/src/core/server/server.test.mocks.ts index 8594d51dcd756..d9c52c4e6d0fa 100644 --- a/src/core/server/server.test.mocks.ts +++ b/src/core/server/server.test.mocks.ts @@ -113,7 +113,7 @@ jest.doMock('./i18n/i18n_service', () => ({ import { prebootServiceMock } from './preboot/preboot_service.mock'; export const mockPrebootService = prebootServiceMock.create(); -jest.doMock('./preboot/preboot_service', () => ({ +jest.doMock('@kbn/core-preboot-server-internal', () => ({ PrebootService: jest.fn(() => mockPrebootService), })); diff --git a/src/core/server/server.ts b/src/core/server/server.ts index 3f877d31eec3a..b8f47cdda45f7 100644 --- a/src/core/server/server.ts +++ b/src/core/server/server.ts @@ -29,6 +29,7 @@ import { ExecutionContextService, executionContextConfig, } from '@kbn/core-execution-context-server-internal'; +import { PrebootService } from '@kbn/core-preboot-server-internal'; import { CoreApp } from './core_app'; import { I18nService } from './i18n'; import { ElasticsearchService } from './elasticsearch'; @@ -55,7 +56,6 @@ import { CoreUsageDataService } from './core_usage_data'; import { DeprecationsService, config as deprecationConfig } from './deprecations'; import { CoreRouteHandlerContext } from './core_route_handler_context'; import { PrebootCoreRouteHandlerContext } from './preboot_core_route_handler_context'; -import { PrebootService } from './preboot'; import { DiscoveredPlugins } from './plugins'; import type { RequestHandlerContext, PrebootRequestHandlerContext } from '.'; From 303b3b994e540e958345d3fabe4d20cb81941202 Mon Sep 17 00:00:00 2001 From: Christiane Heiligers Date: Fri, 8 Jul 2022 19:12:50 -0700 Subject: [PATCH 4/9] Adds core-preboot-server-mocks package and moves the preboot mock --- package.json | 2 + packages/BUILD.bazel | 2 + .../core-preboot-server-mocks/BUILD.bazel | 100 ++++++++++++++++++ .../core-preboot-server-mocks/README.md | 3 + .../core-preboot-server-mocks/jest.config.js | 13 +++ .../core-preboot-server-mocks/package.json | 7 ++ .../core-preboot-server-mocks/src/index.ts | 14 +++ .../src}/preboot_service.mock.ts | 2 +- .../core-preboot-server-mocks/tsconfig.json | 18 ++++ yarn.lock | 8 ++ 10 files changed, 168 insertions(+), 1 deletion(-) create mode 100644 packages/core/preboot/core-preboot-server-mocks/BUILD.bazel create mode 100644 packages/core/preboot/core-preboot-server-mocks/README.md create mode 100644 packages/core/preboot/core-preboot-server-mocks/jest.config.js create mode 100644 packages/core/preboot/core-preboot-server-mocks/package.json create mode 100644 packages/core/preboot/core-preboot-server-mocks/src/index.ts rename {src/core/server/preboot => packages/core/preboot/core-preboot-server-mocks/src}/preboot_service.mock.ts (94%) create mode 100644 packages/core/preboot/core-preboot-server-mocks/tsconfig.json diff --git a/package.json b/package.json index 4cb812e8d74a7..fa4c53e1e0c3b 100644 --- a/package.json +++ b/package.json @@ -191,6 +191,7 @@ "@kbn/core-node-server-mocks": "link:bazel-bin/packages/core/node/core-node-server-mocks", "@kbn/core-preboot-server": "link:bazel-bin/packages/core/preboot/core-preboot-server", "@kbn/core-preboot-server-internal": "link:bazel-bin/packages/core/preboot/core-preboot-server-internal", + "@kbn/core-preboot-server-mocks": "link:bazel-bin/packages/core/preboot/core-preboot-server-mocks", "@kbn/core-theme-browser": "link:bazel-bin/packages/core/theme/core-theme-browser", "@kbn/core-theme-browser-internal": "link:bazel-bin/packages/core/theme/core-theme-browser-internal", "@kbn/core-theme-browser-mocks": "link:bazel-bin/packages/core/theme/core-theme-browser-mocks", @@ -748,6 +749,7 @@ "@types/kbn__core-node-server-mocks": "link:bazel-bin/packages/core/node/core-node-server-mocks/npm_module_types", "@types/kbn__core-preboot-server": "link:bazel-bin/packages/core/preboot/core-preboot-server/npm_module_types", "@types/kbn__core-preboot-server-internal": "link:bazel-bin/packages/core/preboot/core-preboot-server-internal/npm_module_types", + "@types/kbn__core-preboot-server-mocks": "link:bazel-bin/packages/core/preboot/core-preboot-server-mocks/npm_module_types", "@types/kbn__core-public-internal-base": "link:bazel-bin/packages/core/public/internal-base/npm_module_types", "@types/kbn__core-server-internal-base": "link:bazel-bin/packages/core/server/internal-base/npm_module_types", "@types/kbn__core-theme-browser": "link:bazel-bin/packages/core/theme/core-theme-browser/npm_module_types", diff --git a/packages/BUILD.bazel b/packages/BUILD.bazel index 3329141b80d97..8c89ae7d0af1a 100644 --- a/packages/BUILD.bazel +++ b/packages/BUILD.bazel @@ -59,6 +59,7 @@ filegroup( "//packages/core/node/core-node-server-mocks:build", "//packages/core/node/core-node-server:build", "//packages/core/preboot/core-preboot-server-internal:build", + "//packages/core/preboot/core-preboot-server-mocks:build", "//packages/core/preboot/core-preboot-server:build", "//packages/core/theme/core-theme-browser-internal:build", "//packages/core/theme/core-theme-browser-mocks:build", @@ -241,6 +242,7 @@ filegroup( "//packages/core/node/core-node-server-mocks:build_types", "//packages/core/node/core-node-server:build_types", "//packages/core/preboot/core-preboot-server-internal:build_types", + "//packages/core/preboot/core-preboot-server-mocks:build_types", "//packages/core/preboot/core-preboot-server:build_types", "//packages/core/theme/core-theme-browser-internal:build_types", "//packages/core/theme/core-theme-browser-mocks:build_types", diff --git a/packages/core/preboot/core-preboot-server-mocks/BUILD.bazel b/packages/core/preboot/core-preboot-server-mocks/BUILD.bazel new file mode 100644 index 0000000000000..a8d4c3521e8c8 --- /dev/null +++ b/packages/core/preboot/core-preboot-server-mocks/BUILD.bazel @@ -0,0 +1,100 @@ +load("@npm//@bazel/typescript:index.bzl", "ts_config") +load("@build_bazel_rules_nodejs//:index.bzl", "js_library") +load("//src/dev/bazel:index.bzl", "jsts_transpiler", "pkg_npm", "pkg_npm_types", "ts_project") + +PKG_DIRNAME = "core-preboot-server-mocks" +PKG_REQUIRE_NAME = "@kbn/core-preboot-server-mocks" + +SOURCE_FILES = glob( + [ + "src/**/*.ts", + ], + exclude = [ + "**/*.test.*", + "**/*.stories.*", + ], +) + +SRCS = SOURCE_FILES + +filegroup( + name = "srcs", + srcs = SRCS, +) + +NPM_MODULE_EXTRA_FILES = [ + "package.json", +] + +RUNTIME_DEPS = [ + "//packages/core/preboot/core-preboot-server-internal" +] + +TYPES_DEPS = [ + "@npm//@types/node", + "@npm//@types/jest", + "//packages/core/preboot/core-preboot-server-internal:npm_module_types", + "//packages/core/preboot/core-preboot-server:npm_module_types" +] + +jsts_transpiler( + name = "target_node", + srcs = SRCS, + build_pkg_name = package_name(), +) + +ts_config( + name = "tsconfig", + src = "tsconfig.json", + deps = [ + "//:tsconfig.base.json", + "//:tsconfig.bazel.json", + ], +) + +ts_project( + name = "tsc_types", + args = ['--pretty'], + srcs = SRCS, + deps = TYPES_DEPS, + declaration = True, + declaration_map = True, + emit_declaration_only = True, + out_dir = "target_types", + root_dir = "src", + tsconfig = ":tsconfig", +) + +js_library( + name = PKG_DIRNAME, + srcs = NPM_MODULE_EXTRA_FILES, + deps = RUNTIME_DEPS + [":target_node"], + package_name = PKG_REQUIRE_NAME, + visibility = ["//visibility:public"], +) + +pkg_npm( + name = "npm_module", + deps = [":" + PKG_DIRNAME], +) + +filegroup( + name = "build", + srcs = [":npm_module"], + visibility = ["//visibility:public"], +) + +pkg_npm_types( + name = "npm_module_types", + srcs = SRCS, + deps = [":tsc_types"], + package_name = PKG_REQUIRE_NAME, + tsconfig = ":tsconfig", + visibility = ["//visibility:public"], +) + +filegroup( + name = "build_types", + srcs = [":npm_module_types"], + visibility = ["//visibility:public"], +) diff --git a/packages/core/preboot/core-preboot-server-mocks/README.md b/packages/core/preboot/core-preboot-server-mocks/README.md new file mode 100644 index 0000000000000..b52c6777c72be --- /dev/null +++ b/packages/core/preboot/core-preboot-server-mocks/README.md @@ -0,0 +1,3 @@ +# @kbn/core-preboot-server-mocks + +This package contains the mocks for Core's server-side preboot service. diff --git a/packages/core/preboot/core-preboot-server-mocks/jest.config.js b/packages/core/preboot/core-preboot-server-mocks/jest.config.js new file mode 100644 index 0000000000000..00a08d96aeace --- /dev/null +++ b/packages/core/preboot/core-preboot-server-mocks/jest.config.js @@ -0,0 +1,13 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +module.exports = { + preset: '@kbn/test/jest_node', + rootDir: '../../../..', + roots: ['/packages/core/preboot/core-preboot-server-mocks'], +}; diff --git a/packages/core/preboot/core-preboot-server-mocks/package.json b/packages/core/preboot/core-preboot-server-mocks/package.json new file mode 100644 index 0000000000000..e88cee9cfd551 --- /dev/null +++ b/packages/core/preboot/core-preboot-server-mocks/package.json @@ -0,0 +1,7 @@ +{ + "name": "@kbn/core-preboot-server-mocks", + "private": true, + "version": "1.0.0", + "main": "./target_node/index.js", + "license": "SSPL-1.0 OR Elastic License 2.0" +} diff --git a/packages/core/preboot/core-preboot-server-mocks/src/index.ts b/packages/core/preboot/core-preboot-server-mocks/src/index.ts new file mode 100644 index 0000000000000..4e3fb46039778 --- /dev/null +++ b/packages/core/preboot/core-preboot-server-mocks/src/index.ts @@ -0,0 +1,14 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +export { prebootServiceMock } from './preboot_service.mock'; +export type { + InternalPrebootServicePrebootMock, + PrebootServicePrebootMock, + PrebootServiceContract, +} from './preboot_service.mock'; diff --git a/src/core/server/preboot/preboot_service.mock.ts b/packages/core/preboot/core-preboot-server-mocks/src/preboot_service.mock.ts similarity index 94% rename from src/core/server/preboot/preboot_service.mock.ts rename to packages/core/preboot/core-preboot-server-mocks/src/preboot_service.mock.ts index 1c67f6b38b722..af37068727f73 100644 --- a/src/core/server/preboot/preboot_service.mock.ts +++ b/packages/core/preboot/core-preboot-server-mocks/src/preboot_service.mock.ts @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import type { InternalPrebootServicePreboot } from './types'; +import type { InternalPrebootServicePreboot } from '@kbn/core-preboot-server-internal'; import type { PrebootServicePreboot, KibanaPrebootServiceContract } from '@kbn/core-preboot-server'; export type InternalPrebootServicePrebootMock = jest.Mocked; diff --git a/packages/core/preboot/core-preboot-server-mocks/tsconfig.json b/packages/core/preboot/core-preboot-server-mocks/tsconfig.json new file mode 100644 index 0000000000000..39d3c7097814a --- /dev/null +++ b/packages/core/preboot/core-preboot-server-mocks/tsconfig.json @@ -0,0 +1,18 @@ +{ + "extends": "../../../../tsconfig.bazel.json", + "compilerOptions": { + "declaration": true, + "declarationMap": true, + "emitDeclarationOnly": true, + "outDir": "target_types", + "rootDir": "src", + "stripInternal": false, + "types": [ + "jest", + "node" + ] + }, + "include": [ + "src/**/*" + ] +} diff --git a/yarn.lock b/yarn.lock index 7a0da590ecd93..0cb10541f4b9f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3232,6 +3232,10 @@ version "0.0.0" uid "" +"@kbn/core-preboot-server-mocks@link:bazel-bin/packages/core/preboot/core-preboot-server-mocks": + version "0.0.0" + uid "" + "@kbn/core-preboot-server@link:bazel-bin/packages/core/preboot/core-preboot-server": version "0.0.0" uid "" @@ -6791,6 +6795,10 @@ version "0.0.0" uid "" +"@types/kbn__core-preboot-server-mocks@link:bazel-bin/packages/core/preboot/core-preboot-server-mocks/npm_module_types": + version "0.0.0" + uid "" + "@types/kbn__core-preboot-server@link:bazel-bin/packages/core/preboot/core-preboot-server/npm_module_types": version "0.0.0" uid "" From 732e00e727c46dbe410d90fdfc9d4d69118045e8 Mon Sep 17 00:00:00 2001 From: Christiane Heiligers Date: Fri, 8 Jul 2022 19:18:51 -0700 Subject: [PATCH 5/9] Updates mock imports --- src/core/server/mocks.ts | 3 +-- src/core/server/server.test.mocks.ts | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/core/server/mocks.ts b/src/core/server/mocks.ts index f224ff76418ab..2d8d34be93e5c 100644 --- a/src/core/server/mocks.ts +++ b/src/core/server/mocks.ts @@ -17,6 +17,7 @@ import { analyticsServiceMock } from '@kbn/core-analytics-server-mocks'; import { environmentServiceMock } from '@kbn/core-environment-server-mocks'; import { nodeServiceMock } from '@kbn/core-node-server-mocks'; import { executionContextServiceMock } from '@kbn/core-execution-context-server-mocks'; +import { prebootServiceMock } from '@kbn/core-preboot-server-mocks'; import type { PluginInitializerContext, CoreSetup, @@ -41,8 +42,6 @@ import { statusServiceMock } from './status/status_service.mock'; import { coreUsageDataServiceMock } from './core_usage_data/core_usage_data_service.mock'; import { i18nServiceMock } from './i18n/i18n_service.mock'; import { deprecationsServiceMock } from './deprecations/deprecations_service.mock'; -import { prebootServiceMock } from './preboot/preboot_service.mock'; - export { configServiceMock, configDeprecationsMock } from '@kbn/config-mocks'; export { loggingSystemMock } from '@kbn/core-logging-server-mocks'; export { httpServerMock } from './http/http_server.mocks'; diff --git a/src/core/server/server.test.mocks.ts b/src/core/server/server.test.mocks.ts index d9c52c4e6d0fa..16f2fb3d2e1df 100644 --- a/src/core/server/server.test.mocks.ts +++ b/src/core/server/server.test.mocks.ts @@ -110,7 +110,7 @@ jest.doMock('./i18n/i18n_service', () => ({ I18nService: jest.fn(() => mockI18nService), })); -import { prebootServiceMock } from './preboot/preboot_service.mock'; +import { prebootServiceMock } from '@kbn/core-preboot-server-mocks'; export const mockPrebootService = prebootServiceMock.create(); jest.doMock('@kbn/core-preboot-server-internal', () => ({ From 1c695c64eb14090d09da62f90d438b2395e4dd7c Mon Sep 17 00:00:00 2001 From: Christiane Heiligers Date: Fri, 8 Jul 2022 19:20:19 -0700 Subject: [PATCH 6/9] Cleans up bazel build file --- .../core-preboot-server-internal/BUILD.bazel | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/packages/core/preboot/core-preboot-server-internal/BUILD.bazel b/packages/core/preboot/core-preboot-server-internal/BUILD.bazel index 5e8b4cba592c5..04d99ac806ddc 100644 --- a/packages/core/preboot/core-preboot-server-internal/BUILD.bazel +++ b/packages/core/preboot/core-preboot-server-internal/BUILD.bazel @@ -26,16 +26,6 @@ NPM_MODULE_EXTRA_FILES = [ "package.json", ] -# In this array place runtime dependencies, including other packages and NPM packages -# which must be available for this code to run. -# -# To reference other packages use: -# "//repo/relative/path/to/package" -# eg. "//packages/kbn-utils" -# -# To reference a NPM package use: -# "@npm//name-of-package" -# eg. "@npm//lodash" RUNTIME_DEPS = [ "//packages/core/logging/core-logging-server-mocks", "//packages/core/base/core-base-common", @@ -45,15 +35,6 @@ RUNTIME_DEPS = [ "//packages/kbn-utils" ] -# In this array place dependencies necessary to build the types, which will include the -# :npm_module_types target of other packages and packages from NPM, including @types/* -# packages. -# -# To reference the types for another package use: -# "//repo/relative/path/to/package:npm_module_types" -# eg. "//packages/kbn-utils:npm_module_types" -# -# References to NPM packages work the same as RUNTIME_DEPS TYPES_DEPS = [ "@npm//@types/node", "@npm//@types/jest", From e17a1d86289210bd7e58dcb040e8cd751c73505d Mon Sep 17 00:00:00 2001 From: Christiane Heiligers Date: Sat, 9 Jul 2022 14:35:06 -0700 Subject: [PATCH 7/9] reverts type change in mocks --- .../src/preboot_service.ts | 4 ++-- .../preboot/core-preboot-server-mocks/src/index.ts | 1 - .../src/preboot_service.mock.ts | 12 +++++++++--- .../preboot/core-preboot-server/src/contracts.ts | 1 + 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/core/preboot/core-preboot-server-internal/src/preboot_service.ts b/packages/core/preboot/core-preboot-server-internal/src/preboot_service.ts index 841c9bde02f9b..d62996bb04b1a 100644 --- a/packages/core/preboot/core-preboot-server-internal/src/preboot_service.ts +++ b/packages/core/preboot/core-preboot-server-internal/src/preboot_service.ts @@ -8,7 +8,7 @@ import type { Logger } from '@kbn/logging'; import type { CoreContext } from '@kbn/core-base-server-internal'; -import type { KibanaPrebootServicePreboot } from '@kbn/core-preboot-server'; +import type { InternalPrebootServicePreboot } from './types'; /** @internal */ export class PrebootService { @@ -21,7 +21,7 @@ export class PrebootService { this.log = this.core.logger.get('preboot'); } - public preboot(): KibanaPrebootServicePreboot { + public preboot(): InternalPrebootServicePreboot { return { isSetupOnHold: () => this.isSetupOnHold, holdSetupUntilResolved: (pluginName, reason, promise) => { diff --git a/packages/core/preboot/core-preboot-server-mocks/src/index.ts b/packages/core/preboot/core-preboot-server-mocks/src/index.ts index 4e3fb46039778..fc1c1edbf2c58 100644 --- a/packages/core/preboot/core-preboot-server-mocks/src/index.ts +++ b/packages/core/preboot/core-preboot-server-mocks/src/index.ts @@ -10,5 +10,4 @@ export { prebootServiceMock } from './preboot_service.mock'; export type { InternalPrebootServicePrebootMock, PrebootServicePrebootMock, - PrebootServiceContract, } from './preboot_service.mock'; diff --git a/packages/core/preboot/core-preboot-server-mocks/src/preboot_service.mock.ts b/packages/core/preboot/core-preboot-server-mocks/src/preboot_service.mock.ts index af37068727f73..930b915fdeb36 100644 --- a/packages/core/preboot/core-preboot-server-mocks/src/preboot_service.mock.ts +++ b/packages/core/preboot/core-preboot-server-mocks/src/preboot_service.mock.ts @@ -6,12 +6,16 @@ * Side Public License, v 1. */ -import type { InternalPrebootServicePreboot } from '@kbn/core-preboot-server-internal'; -import type { PrebootServicePreboot, KibanaPrebootServiceContract } from '@kbn/core-preboot-server'; +import type { + InternalPrebootServicePreboot, + PrebootService, +} from '@kbn/core-preboot-server-internal'; +import type { PrebootServicePreboot } from '@kbn/core-preboot-server'; +import { PublicMethodsOf } from '@kbn/utility-types'; export type InternalPrebootServicePrebootMock = jest.Mocked; export type PrebootServicePrebootMock = jest.Mocked; -export type PrebootServiceContract = jest.Mocked; + const createInternalPrebootContractMock = () => { const mock: InternalPrebootServicePrebootMock = { isSetupOnHold: jest.fn(), @@ -30,6 +34,8 @@ const createPrebootContractMock = () => { return mock; }; +type PrebootServiceContract = PublicMethodsOf; + const createPrebootServiceMock = () => { const mocked: jest.Mocked = { preboot: jest.fn(), diff --git a/packages/core/preboot/core-preboot-server/src/contracts.ts b/packages/core/preboot/core-preboot-server/src/contracts.ts index 9870ecc284ca8..24bdc6bcb47df 100644 --- a/packages/core/preboot/core-preboot-server/src/contracts.ts +++ b/packages/core/preboot/core-preboot-server/src/contracts.ts @@ -52,6 +52,7 @@ export interface PrebootServicePreboot { } /** + * public version of InternalPrebootServicePreboot that is exposed in the public service contract * @public */ export interface KibanaPrebootServicePreboot From 386b75fdcbdbfb2cfdae35056a8bf8985b099436 Mon Sep 17 00:00:00 2001 From: Christiane Heiligers Date: Sat, 9 Jul 2022 14:39:28 -0700 Subject: [PATCH 8/9] reverts mock back to original implementation --- .../core-preboot-server-mocks/src/preboot_service.mock.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/core/preboot/core-preboot-server-mocks/src/preboot_service.mock.ts b/packages/core/preboot/core-preboot-server-mocks/src/preboot_service.mock.ts index 930b915fdeb36..f0077549f33a1 100644 --- a/packages/core/preboot/core-preboot-server-mocks/src/preboot_service.mock.ts +++ b/packages/core/preboot/core-preboot-server-mocks/src/preboot_service.mock.ts @@ -5,13 +5,12 @@ * in compliance with, at your election, the Elastic License 2.0 or the Server * Side Public License, v 1. */ - +import { PublicMethodsOf } from '@kbn/utility-types'; import type { InternalPrebootServicePreboot, PrebootService, } from '@kbn/core-preboot-server-internal'; import type { PrebootServicePreboot } from '@kbn/core-preboot-server'; -import { PublicMethodsOf } from '@kbn/utility-types'; export type InternalPrebootServicePrebootMock = jest.Mocked; export type PrebootServicePrebootMock = jest.Mocked; From 8016e44a0b88eac37d2c65c30d726af2b5a28ecb Mon Sep 17 00:00:00 2001 From: Christiane Heiligers Date: Sat, 9 Jul 2022 15:07:13 -0700 Subject: [PATCH 9/9] removes public version of internal contract and removes contract type --- .../core-preboot-server-internal/BUILD.bazel | 19 +++++----- .../core-preboot-server-mocks/BUILD.bazel | 4 +- .../preboot/core-preboot-server/BUILD.bazel | 1 - .../core-preboot-server/src/contracts.ts | 38 ------------------- .../preboot/core-preboot-server/src/index.ts | 6 +-- 5 files changed, 14 insertions(+), 54 deletions(-) diff --git a/packages/core/preboot/core-preboot-server-internal/BUILD.bazel b/packages/core/preboot/core-preboot-server-internal/BUILD.bazel index 04d99ac806ddc..4afb072e6387b 100644 --- a/packages/core/preboot/core-preboot-server-internal/BUILD.bazel +++ b/packages/core/preboot/core-preboot-server-internal/BUILD.bazel @@ -27,24 +27,25 @@ NPM_MODULE_EXTRA_FILES = [ ] RUNTIME_DEPS = [ - "//packages/core/logging/core-logging-server-mocks", + "//packages/kbn-logging", + "//packages/core/base/core-base-server-internal", "//packages/core/base/core-base-common", - "//packages/kbn-config-mocks", + "//packages/kbn-utils", "//packages/kbn-config", - "//packages/kbn-logging", - "//packages/kbn-utils" + "//packages/kbn-config-mocks", + "//packages/core/logging/core-logging-server-mocks", ] TYPES_DEPS = [ "@npm//@types/node", "@npm//@types/jest", - "//packages/core/logging/core-logging-server-mocks:npm_module_types", - "//packages/core/base/core-base-common:npm_module_types", - "//packages/kbn-config-mocks:npm_module_types", - "//packages/kbn-config:npm_module_types", "//packages/kbn-logging:npm_module_types", + "//packages/core/base/core-base-server-internal:npm_module_types", + "//packages/core/base/core-base-common:npm_module_types", "//packages/kbn-utils:npm_module_types", - "//packages/core/preboot/core-preboot-server:npm_module_types" + "//packages/kbn-config:npm_module_types", + "//packages/kbn-config-mocks:npm_module_types", + "//packages/core/logging/core-logging-server-mocks:npm_module_types", ] jsts_transpiler( diff --git a/packages/core/preboot/core-preboot-server-mocks/BUILD.bazel b/packages/core/preboot/core-preboot-server-mocks/BUILD.bazel index a8d4c3521e8c8..572a8f80d6012 100644 --- a/packages/core/preboot/core-preboot-server-mocks/BUILD.bazel +++ b/packages/core/preboot/core-preboot-server-mocks/BUILD.bazel @@ -27,12 +27,14 @@ NPM_MODULE_EXTRA_FILES = [ ] RUNTIME_DEPS = [ - "//packages/core/preboot/core-preboot-server-internal" + "//packages/kbn-utility-types", + "//packages/core/preboot/core-preboot-server-internal", ] TYPES_DEPS = [ "@npm//@types/node", "@npm//@types/jest", + "//packages/kbn-utility-types:npm_module_types", "//packages/core/preboot/core-preboot-server-internal:npm_module_types", "//packages/core/preboot/core-preboot-server:npm_module_types" ] diff --git a/packages/core/preboot/core-preboot-server/BUILD.bazel b/packages/core/preboot/core-preboot-server/BUILD.bazel index 178d866c86ab0..e568ca5ab8a3b 100644 --- a/packages/core/preboot/core-preboot-server/BUILD.bazel +++ b/packages/core/preboot/core-preboot-server/BUILD.bazel @@ -32,7 +32,6 @@ RUNTIME_DEPS = [ TYPES_DEPS = [ "@npm//@types/node", "@npm//@types/jest", - "//packages/core/base/core-base-common:npm_module_types", ] jsts_transpiler( diff --git a/packages/core/preboot/core-preboot-server/src/contracts.ts b/packages/core/preboot/core-preboot-server/src/contracts.ts index 24bdc6bcb47df..b76298e4d3e98 100644 --- a/packages/core/preboot/core-preboot-server/src/contracts.ts +++ b/packages/core/preboot/core-preboot-server/src/contracts.ts @@ -5,7 +5,6 @@ * in compliance with, at your election, the Elastic License 2.0 or the Server * Side Public License, v 1. */ -import type { PluginName } from '@kbn/core-base-common'; /** * Kibana Preboot Service allows to control the boot flow of Kibana. Preboot plugins can use it to hold the boot until certain condition is met. * @@ -50,40 +49,3 @@ export interface PrebootServicePreboot { promise: Promise<{ shouldReloadConfig: boolean } | undefined> ) => void; } - -/** - * public version of InternalPrebootServicePreboot that is exposed in the public service contract - * @public - */ -export interface KibanaPrebootServicePreboot - extends Omit { - /** - * Registers a `Promise` as a precondition before Kibana can proceed to `setup`. This method can be invoked multiple - * times and from multiple `preboot` plugins. Kibana will proceed to `setup` only when all registered `Promise` are - * resolved, or it will shut down if any of them are rejected. - * @param pluginName Name of the plugin that needs to hold `setup`. - * @param reason A string that explains the reason why this promise should hold `setup`. It's supposed to be a human - * readable string that will be recorded in the logs or standard output. - * @param promise A `Promise` that should resolved before Kibana can proceed to `setup`. - */ - readonly holdSetupUntilResolved: ( - pluginName: PluginName, - reason: string, - promise: Promise<{ shouldReloadConfig: boolean } | undefined> - ) => void; - /** - * Returns a `Promise` that is resolved only when all `Promise` instances registered with {@link holdSetupUntilResolved} - * are resolved, or rejected if any of them are rejected. If the supplied `Promise` resolves to an object with the - * `shouldReloadConfig` property set to `true`, it indicates that Kibana configuration might have changed and Kibana - * needs to reload it from the disk. - */ - readonly waitUntilCanSetup: () => Promise<{ shouldReloadConfig: boolean }>; -} - -/** - * @public - */ -export interface KibanaPrebootServiceContract { - preboot: () => KibanaPrebootServicePreboot; - stop: () => void; -} diff --git a/packages/core/preboot/core-preboot-server/src/index.ts b/packages/core/preboot/core-preboot-server/src/index.ts index 01f0dc952562a..eb8e763e53b14 100644 --- a/packages/core/preboot/core-preboot-server/src/index.ts +++ b/packages/core/preboot/core-preboot-server/src/index.ts @@ -6,8 +6,4 @@ * Side Public License, v 1. */ -export type { - PrebootServicePreboot, - KibanaPrebootServicePreboot, - KibanaPrebootServiceContract, -} from './contracts'; +export type { PrebootServicePreboot } from './contracts';