diff --git a/package.json b/package.json index f6d01e45fcb1a..fa4c53e1e0c3b 100644 --- a/package.json +++ b/package.json @@ -189,6 +189,9 @@ "@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-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", @@ -744,6 +747,9 @@ "@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-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 07d7212cf6a79..8c89ae7d0af1a 100644 --- a/packages/BUILD.bazel +++ b/packages/BUILD.bazel @@ -58,6 +58,9 @@ 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-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", "//packages/core/theme/core-theme-browser:build", @@ -238,6 +241,9 @@ 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-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", "//packages/core/theme/core-theme-browser: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..4afb072e6387b --- /dev/null +++ b/packages/core/preboot/core-preboot-server-internal/BUILD.bazel @@ -0,0 +1,111 @@ +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", +] + +RUNTIME_DEPS = [ + "//packages/kbn-logging", + "//packages/core/base/core-base-server-internal", + "//packages/core/base/core-base-common", + "//packages/kbn-utils", + "//packages/kbn-config", + "//packages/kbn-config-mocks", + "//packages/core/logging/core-logging-server-mocks", +] + +TYPES_DEPS = [ + "@npm//@types/node", + "@npm//@types/jest", + "//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/kbn-config:npm_module_types", + "//packages/kbn-config-mocks:npm_module_types", + "//packages/core/logging/core-logging-server-mocks: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/src/core/server/preboot/index.ts b/packages/core/preboot/core-preboot-server-internal/src/index.ts similarity index 82% rename from src/core/server/preboot/index.ts rename to packages/core/preboot/core-preboot-server-internal/src/index.ts index 2b7f25538dcb1..e4e0571da72e4 100644 --- a/src/core/server/preboot/index.ts +++ b/packages/core/preboot/core-preboot-server-internal/src/index.ts @@ -6,5 +6,5 @@ * Side Public License, v 1. */ +export type { InternalPrebootServicePreboot } from './types'; export { PrebootService } from './preboot_service'; -export type { InternalPrebootServicePreboot, PrebootServicePreboot } from './types'; 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 96% rename from src/core/server/preboot/preboot_service.ts rename to packages/core/preboot/core-preboot-server-internal/src/preboot_service.ts index 328f4f2cdd360..d62996bb04b1a 100644 --- a/src/core/server/preboot/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 { InternalPrebootServicePreboot } from './types'; +import type { InternalPrebootServicePreboot } from './types'; /** @internal */ export class PrebootService { diff --git a/packages/core/preboot/core-preboot-server-internal/src/types.ts b/packages/core/preboot/core-preboot-server-internal/src/types.ts new file mode 100644 index 0000000000000..a8d5a60fd9e48 --- /dev/null +++ b/packages/core/preboot/core-preboot-server-internal/src/types.ts @@ -0,0 +1,40 @@ +/* + * 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'; + +/** @internal */ +export interface InternalPrebootServicePreboot { + /** + * 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 `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 }>; +} 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/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..572a8f80d6012 --- /dev/null +++ b/packages/core/preboot/core-preboot-server-mocks/BUILD.bazel @@ -0,0 +1,102 @@ +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/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" +] + +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..fc1c1edbf2c58 --- /dev/null +++ b/packages/core/preboot/core-preboot-server-mocks/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 { prebootServiceMock } from './preboot_service.mock'; +export type { + InternalPrebootServicePrebootMock, + PrebootServicePrebootMock, +} 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 85% 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 acdd9458a462d..f0077549f33a1 100644 --- a/src/core/server/preboot/preboot_service.mock.ts +++ b/packages/core/preboot/core-preboot-server-mocks/src/preboot_service.mock.ts @@ -5,10 +5,12 @@ * in compliance with, at your election, the Elastic License 2.0 or the Server * Side Public License, v 1. */ - -import type { PublicMethodsOf } from '@kbn/utility-types'; -import type { InternalPrebootServicePreboot, PrebootServicePreboot } from './types'; -import { PrebootService } from './preboot_service'; +import { PublicMethodsOf } from '@kbn/utility-types'; +import type { + InternalPrebootServicePreboot, + PrebootService, +} from '@kbn/core-preboot-server-internal'; +import type { PrebootServicePreboot } from '@kbn/core-preboot-server'; export type InternalPrebootServicePrebootMock = jest.Mocked; export type PrebootServicePrebootMock = 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/packages/core/preboot/core-preboot-server/BUILD.bazel b/packages/core/preboot/core-preboot-server/BUILD.bazel new file mode 100644 index 0000000000000..e568ca5ab8a3b --- /dev/null +++ b/packages/core/preboot/core-preboot-server/BUILD.bazel @@ -0,0 +1,97 @@ +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", +] + +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/src/core/server/preboot/types.ts b/packages/core/preboot/core-preboot-server/src/contracts.ts similarity index 59% rename from src/core/server/preboot/types.ts rename to packages/core/preboot/core-preboot-server/src/contracts.ts index 4d36eeb569429..b76298e4d3e98 100644 --- a/src/core/server/preboot/types.ts +++ b/packages/core/preboot/core-preboot-server/src/contracts.ts @@ -5,40 +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'; - -/** @internal */ -export interface InternalPrebootServicePreboot { - /** - * 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 `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 }>; -} - /** * 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. * 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..eb8e763e53b14 --- /dev/null +++ b/packages/core/preboot/core-preboot-server/src/index.ts @@ -0,0 +1,9 @@ +/* + * 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 } 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/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/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 8594d51dcd756..16f2fb3d2e1df 100644 --- a/src/core/server/server.test.mocks.ts +++ b/src/core/server/server.test.mocks.ts @@ -110,10 +110,10 @@ 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('./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 '.'; 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..0cb10541f4b9f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3228,6 +3228,18 @@ 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-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 "" + "@kbn/core-theme-browser-internal@link:bazel-bin/packages/core/theme/core-theme-browser-internal": version "0.0.0" uid "" @@ -6779,6 +6791,18 @@ 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-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 "" + "@types/kbn__core-public-internal-base@link:bazel-bin/packages/core/public/internal-base/npm_module_types": version "0.0.0" uid ""