Move RequestHandlerContext types and implementation to packages (#141759)

* create empty packages

* continue moving things

* adapt usages

* [CI] Auto-commit changed files from 'node scripts/generate codeowners'

* renaming packages...

* adapting usages again

* [CI] Auto-commit changed files from 'node scripts/generate codeowners'

* move preboot context to packages too

* add internal test mocks

* update READMEs

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Pierre Gayvallet 2022-09-28 08:59:09 +02:00 committed by GitHub
parent 411f80d0d8
commit e24fc503f6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
33 changed files with 607 additions and 96 deletions

2
.github/CODEOWNERS vendored
View file

@ -743,6 +743,8 @@ packages/core/http/core-http-browser-mocks @elastic/kibana-core
packages/core/http/core-http-common @elastic/kibana-core
packages/core/http/core-http-context-server-internal @elastic/kibana-core
packages/core/http/core-http-context-server-mocks @elastic/kibana-core
packages/core/http/core-http-request-handler-context-server @elastic/kibana-core
packages/core/http/core-http-request-handler-context-server-internal @elastic/kibana-core
packages/core/http/core-http-router-server-internal @elastic/kibana-core
packages/core/http/core-http-router-server-mocks @elastic/kibana-core
packages/core/http/core-http-server @elastic/kibana-core

View file

@ -213,6 +213,8 @@
"@kbn/core-http-common": "link:bazel-bin/packages/core/http/core-http-common",
"@kbn/core-http-context-server-internal": "link:bazel-bin/packages/core/http/core-http-context-server-internal",
"@kbn/core-http-context-server-mocks": "link:bazel-bin/packages/core/http/core-http-context-server-mocks",
"@kbn/core-http-request-handler-context-server": "link:bazel-bin/packages/core/http/core-http-request-handler-context-server",
"@kbn/core-http-request-handler-context-server-internal": "link:bazel-bin/packages/core/http/core-http-request-handler-context-server-internal",
"@kbn/core-http-router-server-internal": "link:bazel-bin/packages/core/http/core-http-router-server-internal",
"@kbn/core-http-router-server-mocks": "link:bazel-bin/packages/core/http/core-http-router-server-mocks",
"@kbn/core-http-server": "link:bazel-bin/packages/core/http/core-http-server",
@ -934,6 +936,8 @@
"@types/kbn__core-http-common": "link:bazel-bin/packages/core/http/core-http-common/npm_module_types",
"@types/kbn__core-http-context-server-internal": "link:bazel-bin/packages/core/http/core-http-context-server-internal/npm_module_types",
"@types/kbn__core-http-context-server-mocks": "link:bazel-bin/packages/core/http/core-http-context-server-mocks/npm_module_types",
"@types/kbn__core-http-request-handler-context-server": "link:bazel-bin/packages/core/http/core-http-request-handler-context-server/npm_module_types",
"@types/kbn__core-http-request-handler-context-server-internal": "link:bazel-bin/packages/core/http/core-http-request-handler-context-server-internal/npm_module_types",
"@types/kbn__core-http-router-server-internal": "link:bazel-bin/packages/core/http/core-http-router-server-internal/npm_module_types",
"@types/kbn__core-http-router-server-mocks": "link:bazel-bin/packages/core/http/core-http-router-server-mocks/npm_module_types",
"@types/kbn__core-http-server": "link:bazel-bin/packages/core/http/core-http-server/npm_module_types",

View file

@ -79,6 +79,8 @@ filegroup(
"//packages/core/http/core-http-common:build",
"//packages/core/http/core-http-context-server-internal:build",
"//packages/core/http/core-http-context-server-mocks:build",
"//packages/core/http/core-http-request-handler-context-server:build",
"//packages/core/http/core-http-request-handler-context-server-internal:build",
"//packages/core/http/core-http-router-server-internal:build",
"//packages/core/http/core-http-router-server-mocks:build",
"//packages/core/http/core-http-server:build",
@ -410,6 +412,8 @@ filegroup(
"//packages/core/http/core-http-common:build_types",
"//packages/core/http/core-http-context-server-internal:build_types",
"//packages/core/http/core-http-context-server-mocks:build_types",
"//packages/core/http/core-http-request-handler-context-server:build_types",
"//packages/core/http/core-http-request-handler-context-server-internal:build_types",
"//packages/core/http/core-http-router-server-internal:build_types",
"//packages/core/http/core-http-router-server-mocks:build_types",
"//packages/core/http/core-http-server:build_types",

View file

@ -0,0 +1,116 @@
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-http-request-handler-context-server-internal"
PKG_REQUIRE_NAME = "@kbn/core-http-request-handler-context-server-internal"
SOURCE_FILES = glob(
[
"**/*.ts",
],
exclude = [
"**/*.config.js",
"**/*.mock.*",
"**/*.test.*",
"**/*.stories.*",
"**/__snapshots__/**",
"**/integration_tests/**",
"**/mocks/**",
"**/scripts/**",
"**/storybook/**",
"**/test_fixtures/**",
"**/test_helpers/**",
],
)
SRCS = SOURCE_FILES
filegroup(
name = "srcs",
srcs = SRCS,
)
NPM_MODULE_EXTRA_FILES = [
"package.json",
]
RUNTIME_DEPS = [
"//packages/core/elasticsearch/core-elasticsearch-server-internal",
"//packages/core/saved-objects/core-saved-objects-server-internal",
"//packages/core/deprecations/core-deprecations-server-internal",
"//packages/core/ui-settings/core-ui-settings-server-internal",
]
TYPES_DEPS = [
"@npm//@types/node",
"@npm//@types/jest",
"//packages/core/http/core-http-server:npm_module_types",
"//packages/core/http/core-http-request-handler-context-server:npm_module_types",
"//packages/core/elasticsearch/core-elasticsearch-server-internal:npm_module_types",
"//packages/core/saved-objects/core-saved-objects-server-internal:npm_module_types",
"//packages/core/deprecations/core-deprecations-server-internal:npm_module_types",
"//packages/core/ui-settings/core-ui-settings-server:npm_module_types",
"//packages/core/ui-settings/core-ui-settings-server-internal: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",
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"],
)

View file

@ -0,0 +1,3 @@
# @kbn/core-http-request-handler-context-server-internal
This package contains the internal types and implementation of Core's `CoreRequestHandlerContext`

View file

@ -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 { CoreRouteHandlerContext, PrebootCoreRouteHandlerContext } from './src';
export type { CoreRouteHandlerContextParams, PrebootCoreRouteHandlerContextParams } from './src';

View file

@ -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: ['<rootDir>/packages/core/http/core-http-request-handler-context-server-internal'],
};

View file

@ -0,0 +1,7 @@
{
"type": "shared-common",
"id": "@kbn/core-http-request-handler-context-server-internal",
"owner": "@elastic/kibana-core",
"runtimeDeps": [],
"typeDeps": [],
}

View file

@ -0,0 +1,8 @@
{
"name": "@kbn/core-http-request-handler-context-server-internal",
"private": true,
"version": "1.0.0",
"main": "./target_node/index.js",
"author": "Kibana Core",
"license": "SSPL-1.0 OR Elastic License 2.0"
}

View file

@ -7,13 +7,14 @@
*/
import { CoreRouteHandlerContext } from './core_route_handler_context';
import { coreMock, httpServerMock } from './mocks';
import { httpServerMock } from '@kbn/core-http-server-mocks';
import { createCoreRouteHandlerContextParamsMock } from './test_helpers';
describe('#elasticsearch', () => {
describe('#client', () => {
test('returns the results of coreStart.elasticsearch.client.asScoped', () => {
const request = httpServerMock.createKibanaRequest();
const coreStart = coreMock.createInternalStart();
const coreStart = createCoreRouteHandlerContextParamsMock();
const context = new CoreRouteHandlerContext(coreStart, request);
const client = context.elasticsearch.client;
@ -22,7 +23,7 @@ describe('#elasticsearch', () => {
test('lazily created', () => {
const request = httpServerMock.createKibanaRequest();
const coreStart = coreMock.createInternalStart();
const coreStart = createCoreRouteHandlerContextParamsMock();
const context = new CoreRouteHandlerContext(coreStart, request);
expect(coreStart.elasticsearch.client.asScoped).not.toHaveBeenCalled();
@ -33,7 +34,7 @@ describe('#elasticsearch', () => {
test('only creates one instance', () => {
const request = httpServerMock.createKibanaRequest();
const coreStart = coreMock.createInternalStart();
const coreStart = createCoreRouteHandlerContextParamsMock();
const context = new CoreRouteHandlerContext(coreStart, request);
const client1 = context.elasticsearch.client;
@ -50,7 +51,7 @@ describe('#savedObjects', () => {
describe('#client', () => {
test('returns the results of coreStart.savedObjects.getScopedClient', () => {
const request = httpServerMock.createKibanaRequest();
const coreStart = coreMock.createInternalStart();
const coreStart = createCoreRouteHandlerContextParamsMock();
const context = new CoreRouteHandlerContext(coreStart, request);
const client = context.savedObjects.client;
@ -59,7 +60,7 @@ describe('#savedObjects', () => {
test('lazily created', () => {
const request = httpServerMock.createKibanaRequest();
const coreStart = coreMock.createInternalStart();
const coreStart = createCoreRouteHandlerContextParamsMock();
const context = new CoreRouteHandlerContext(coreStart, request);
const savedObjects = context.savedObjects;
@ -71,7 +72,7 @@ describe('#savedObjects', () => {
test('only creates one instance', () => {
const request = httpServerMock.createKibanaRequest();
const coreStart = coreMock.createInternalStart();
const coreStart = createCoreRouteHandlerContextParamsMock();
const context = new CoreRouteHandlerContext(coreStart, request);
const client1 = context.savedObjects.client;
@ -86,7 +87,7 @@ describe('#savedObjects', () => {
describe('#typeRegistry', () => {
test('returns the results of coreStart.savedObjects.getTypeRegistry', () => {
const request = httpServerMock.createKibanaRequest();
const coreStart = coreMock.createInternalStart();
const coreStart = createCoreRouteHandlerContextParamsMock();
const context = new CoreRouteHandlerContext(coreStart, request);
const typeRegistry = context.savedObjects.typeRegistry;
@ -95,7 +96,7 @@ describe('#savedObjects', () => {
test('lazily created', () => {
const request = httpServerMock.createKibanaRequest();
const coreStart = coreMock.createInternalStart();
const coreStart = createCoreRouteHandlerContextParamsMock();
const context = new CoreRouteHandlerContext(coreStart, request);
expect(coreStart.savedObjects.getTypeRegistry).not.toHaveBeenCalled();
@ -106,7 +107,7 @@ describe('#savedObjects', () => {
test('only creates one instance', () => {
const request = httpServerMock.createKibanaRequest();
const coreStart = coreMock.createInternalStart();
const coreStart = createCoreRouteHandlerContextParamsMock();
const context = new CoreRouteHandlerContext(coreStart, request);
const typeRegistry1 = context.savedObjects.typeRegistry;
@ -123,7 +124,7 @@ describe('#uiSettings', () => {
describe('#client', () => {
test('returns the results of coreStart.uiSettings.asScopedToClient', () => {
const request = httpServerMock.createKibanaRequest();
const coreStart = coreMock.createInternalStart();
const coreStart = createCoreRouteHandlerContextParamsMock();
const context = new CoreRouteHandlerContext(coreStart, request);
const client = context.uiSettings.client;
@ -132,7 +133,7 @@ describe('#uiSettings', () => {
test('lazily created', () => {
const request = httpServerMock.createKibanaRequest();
const coreStart = coreMock.createInternalStart();
const coreStart = createCoreRouteHandlerContextParamsMock();
const context = new CoreRouteHandlerContext(coreStart, request);
expect(coreStart.uiSettings.asScopedToClient).not.toHaveBeenCalled();
@ -143,7 +144,7 @@ describe('#uiSettings', () => {
test('only creates one instance', () => {
const request = httpServerMock.createKibanaRequest();
const coreStart = coreMock.createInternalStart();
const coreStart = createCoreRouteHandlerContextParamsMock();
const context = new CoreRouteHandlerContext(coreStart, request);
const client1 = context.uiSettings.client;
@ -160,7 +161,7 @@ describe('#deprecations', () => {
describe('#client', () => {
test('returns the results of coreStart.deprecations.asScopedToClient', () => {
const request = httpServerMock.createKibanaRequest();
const coreStart = coreMock.createInternalStart();
const coreStart = createCoreRouteHandlerContextParamsMock();
const context = new CoreRouteHandlerContext(coreStart, request);
const client = context.deprecations.client;
@ -169,7 +170,7 @@ describe('#deprecations', () => {
test('lazily created', () => {
const request = httpServerMock.createKibanaRequest();
const coreStart = coreMock.createInternalStart();
const coreStart = createCoreRouteHandlerContextParamsMock();
const context = new CoreRouteHandlerContext(coreStart, request);
expect(coreStart.deprecations.asScopedToClient).not.toHaveBeenCalled();
@ -180,7 +181,7 @@ describe('#deprecations', () => {
test('only creates one instance', () => {
const request = httpServerMock.createKibanaRequest();
const coreStart = coreMock.createInternalStart();
const coreStart = createCoreRouteHandlerContextParamsMock();
const context = new CoreRouteHandlerContext(coreStart, request);
const client1 = context.deprecations.client;

View file

@ -0,0 +1,63 @@
/*
* 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 { KibanaRequest } from '@kbn/core-http-server';
import type { CoreRequestHandlerContext } from '@kbn/core-http-request-handler-context-server';
import {
CoreElasticsearchRouteHandlerContext,
type InternalElasticsearchServiceStart,
} from '@kbn/core-elasticsearch-server-internal';
import {
CoreSavedObjectsRouteHandlerContext,
type InternalSavedObjectsServiceStart,
} from '@kbn/core-saved-objects-server-internal';
import {
CoreDeprecationsRouteHandlerContext,
type InternalDeprecationsServiceStart,
} from '@kbn/core-deprecations-server-internal';
import {
CoreUiSettingsRouteHandlerContext,
type InternalUiSettingsServiceStart,
} from '@kbn/core-ui-settings-server-internal';
/**
* Subset of `InternalCoreStart` used by {@link CoreRouteHandlerContext}
* @internal
*/
export interface CoreRouteHandlerContextParams {
elasticsearch: InternalElasticsearchServiceStart;
savedObjects: InternalSavedObjectsServiceStart;
uiSettings: InternalUiSettingsServiceStart;
deprecations: InternalDeprecationsServiceStart;
}
/**
* The concrete implementation for Core's route handler context.
*
* @internal
*/
export class CoreRouteHandlerContext implements CoreRequestHandlerContext {
readonly elasticsearch: CoreElasticsearchRouteHandlerContext;
readonly savedObjects: CoreSavedObjectsRouteHandlerContext;
readonly uiSettings: CoreUiSettingsRouteHandlerContext;
readonly deprecations: CoreDeprecationsRouteHandlerContext;
constructor(coreStart: CoreRouteHandlerContextParams, request: KibanaRequest) {
this.elasticsearch = new CoreElasticsearchRouteHandlerContext(coreStart.elasticsearch, request);
this.savedObjects = new CoreSavedObjectsRouteHandlerContext(coreStart.savedObjects, request);
this.uiSettings = new CoreUiSettingsRouteHandlerContext(
coreStart.uiSettings,
this.savedObjects
);
this.deprecations = new CoreDeprecationsRouteHandlerContext(
coreStart.deprecations,
this.elasticsearch,
this.savedObjects
);
}
}

View file

@ -0,0 +1,12 @@
/*
* 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 { CoreRouteHandlerContext } from './core_route_handler_context';
export type { CoreRouteHandlerContextParams } from './core_route_handler_context';
export { PrebootCoreRouteHandlerContext } from './preboot_core_route_handler_context';
export type { PrebootCoreRouteHandlerContextParams } from './preboot_core_route_handler_context';

View file

@ -7,12 +7,12 @@
*/
import { PrebootCoreRouteHandlerContext } from './preboot_core_route_handler_context';
import { coreMock } from './mocks';
import { createPrebootCoreRouteHandlerContextParamsMock } from './test_helpers';
describe('#uiSettings', () => {
describe('#client', () => {
test('returns the results of corePreboot.uiSettings.createDefaultsClient', () => {
const corePreboot = coreMock.createInternalPreboot();
const corePreboot = createPrebootCoreRouteHandlerContextParamsMock();
const context = new PrebootCoreRouteHandlerContext(corePreboot);
const client = context.uiSettings.client;
@ -21,7 +21,7 @@ describe('#uiSettings', () => {
});
test('only creates one instance', () => {
const corePreboot = coreMock.createInternalPreboot();
const corePreboot = createPrebootCoreRouteHandlerContextParamsMock();
const context = new PrebootCoreRouteHandlerContext(corePreboot);
const client1 = context.uiSettings.client;

View file

@ -8,13 +8,17 @@
// eslint-disable-next-line max-classes-per-file
import type { IUiSettingsClient } from '@kbn/core-ui-settings-server';
import type { InternalCorePreboot } from './internal_types';
import type {
PrebootUiSettingsRequestHandlerContext,
PrebootCoreRequestHandlerContext,
} from '@kbn/core-http-request-handler-context-server';
import type { InternalUiSettingsServicePreboot } from '@kbn/core-ui-settings-server-internal';
/**
* @public
* @internal
*/
export interface PrebootUiSettingsRequestHandlerContext {
client: IUiSettingsClient;
export interface PrebootCoreRouteHandlerContextParams {
uiSettings: InternalUiSettingsServicePreboot;
}
/**
@ -25,13 +29,6 @@ class PrebootCoreUiSettingsRouteHandlerContext implements PrebootUiSettingsReque
constructor(public readonly client: IUiSettingsClient) {}
}
/**
* @public
*/
export interface PrebootCoreRequestHandlerContext {
uiSettings: PrebootUiSettingsRequestHandlerContext;
}
/**
* Implementation of {@link PrebootCoreRequestHandlerContext}.
* @internal
@ -39,7 +36,7 @@ export interface PrebootCoreRequestHandlerContext {
export class PrebootCoreRouteHandlerContext implements PrebootCoreRequestHandlerContext {
readonly uiSettings: PrebootUiSettingsRequestHandlerContext;
constructor(private readonly corePreboot: InternalCorePreboot) {
constructor(private readonly corePreboot: PrebootCoreRouteHandlerContextParams) {
this.uiSettings = new PrebootCoreUiSettingsRouteHandlerContext(
this.corePreboot.uiSettings.createDefaultsClient()
);

View file

@ -0,0 +1,21 @@
/*
* 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 { elasticsearchServiceMock } from '@kbn/core-elasticsearch-server-mocks';
import { savedObjectsServiceMock } from '@kbn/core-saved-objects-server-mocks';
import { uiSettingsServiceMock } from '@kbn/core-ui-settings-server-mocks';
import { deprecationsServiceMock } from '@kbn/core-deprecations-server-mocks';
export const createCoreRouteHandlerContextParamsMock = () => {
return {
elasticsearch: elasticsearchServiceMock.createInternalStart(),
savedObjects: savedObjectsServiceMock.createInternalStartContract(),
uiSettings: uiSettingsServiceMock.createStartContract(),
deprecations: deprecationsServiceMock.createInternalStartContract(),
};
};

View file

@ -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 { createCoreRouteHandlerContextParamsMock } from './core_route_handler_context_params.mock';
export { createPrebootCoreRouteHandlerContextParamsMock } from './preboot_core_route_handler_context_params.mock';

View file

@ -0,0 +1,15 @@
/*
* 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 { uiSettingsServiceMock } from '@kbn/core-ui-settings-server-mocks';
export const createPrebootCoreRouteHandlerContextParamsMock = () => {
return {
uiSettings: uiSettingsServiceMock.createPrebootContract(),
};
};

View file

@ -0,0 +1,17 @@
{
"extends": "../../../../tsconfig.bazel.json",
"compilerOptions": {
"declaration": true,
"declarationMap": true,
"emitDeclarationOnly": true,
"outDir": "target_types",
"stripInternal": false,
"types": [
"jest",
"node"
]
},
"include": [
"**/*.ts",
]
}

View file

@ -0,0 +1,110 @@
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-http-request-handler-context-server"
PKG_REQUIRE_NAME = "@kbn/core-http-request-handler-context-server"
SOURCE_FILES = glob(
[
"**/*.ts",
],
exclude = [
"**/*.config.js",
"**/*.mock.*",
"**/*.test.*",
"**/*.stories.*",
"**/__snapshots__/**",
"**/integration_tests/**",
"**/mocks/**",
"**/scripts/**",
"**/storybook/**",
"**/test_fixtures/**",
"**/test_helpers/**",
],
)
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/http/core-http-server:npm_module_types",
"//packages/core/elasticsearch/core-elasticsearch-server:npm_module_types",
"//packages/core/saved-objects/core-saved-objects-server:npm_module_types",
"//packages/core/deprecations/core-deprecations-server:npm_module_types",
"//packages/core/ui-settings/core-ui-settings-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",
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"],
)

View file

@ -0,0 +1,3 @@
# @kbn/core-http-request-handler-context-server
This package contains the public types for Core's server-side `RequestHandlerContext` http subdomain.

View file

@ -0,0 +1,16 @@
/*
* 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 {
RequestHandlerContext,
CoreRequestHandlerContext,
CustomRequestHandlerContext,
PrebootCoreRequestHandlerContext,
PrebootRequestHandlerContext,
PrebootUiSettingsRequestHandlerContext,
} from './src';

View file

@ -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: ['<rootDir>/packages/core/http/core-http-request-handler-context-server'],
};

View file

@ -0,0 +1,7 @@
{
"type": "shared-common",
"id": "@kbn/core-http-request-handler-context-server",
"owner": "@elastic/kibana-core",
"runtimeDeps": [],
"typeDeps": [],
}

View file

@ -0,0 +1,8 @@
{
"name": "@kbn/core-http-request-handler-context-server",
"private": true,
"version": "1.0.0",
"main": "./target_node/index.js",
"author": "Kibana Core",
"license": "SSPL-1.0 OR Elastic License 2.0"
}

View file

@ -0,0 +1,18 @@
/*
* 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 {
RequestHandlerContext,
CoreRequestHandlerContext,
CustomRequestHandlerContext,
} from './request_handler_context';
export type {
PrebootRequestHandlerContext,
PrebootCoreRequestHandlerContext,
PrebootUiSettingsRequestHandlerContext,
} from './preboot_request_handler_context';

View file

@ -0,0 +1,31 @@
/*
* 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 { RequestHandlerContextBase } from '@kbn/core-http-server';
import type { IUiSettingsClient } from '@kbn/core-ui-settings-server';
/**
* @public
*/
export interface PrebootUiSettingsRequestHandlerContext {
client: IUiSettingsClient;
}
/**
* @public
*/
export interface PrebootCoreRequestHandlerContext {
uiSettings: PrebootUiSettingsRequestHandlerContext;
}
/**
* @public
*/
export interface PrebootRequestHandlerContext extends RequestHandlerContextBase {
core: Promise<PrebootCoreRequestHandlerContext>;
}

View file

@ -6,16 +6,11 @@
* Side Public License, v 1.
*/
import type { KibanaRequest } from '@kbn/core-http-server';
import type { RequestHandlerContextBase } from '@kbn/core-http-server';
import type { ElasticsearchRequestHandlerContext } from '@kbn/core-elasticsearch-server';
import { CoreElasticsearchRouteHandlerContext } from '@kbn/core-elasticsearch-server-internal';
import type { SavedObjectsRequestHandlerContext } from '@kbn/core-saved-objects-server';
import { CoreSavedObjectsRouteHandlerContext } from '@kbn/core-saved-objects-server-internal';
import type { DeprecationsRequestHandlerContext } from '@kbn/core-deprecations-server';
import { CoreDeprecationsRouteHandlerContext } from '@kbn/core-deprecations-server-internal';
import type { UiSettingsRequestHandlerContext } from '@kbn/core-ui-settings-server';
import { CoreUiSettingsRouteHandlerContext } from '@kbn/core-ui-settings-server-internal';
import type { InternalCoreStart } from './internal_types';
/**
* The `core` context provided to route handler.
@ -39,27 +34,19 @@ export interface CoreRequestHandlerContext {
}
/**
* The concrete implementation for Core's route handler context.
* Base context passed to a route handler, containing the `core` context part.
*
* @internal
* @public
*/
export class CoreRouteHandlerContext implements CoreRequestHandlerContext {
readonly elasticsearch: CoreElasticsearchRouteHandlerContext;
readonly savedObjects: CoreSavedObjectsRouteHandlerContext;
readonly uiSettings: CoreUiSettingsRouteHandlerContext;
readonly deprecations: CoreDeprecationsRouteHandlerContext;
constructor(coreStart: InternalCoreStart, request: KibanaRequest) {
this.elasticsearch = new CoreElasticsearchRouteHandlerContext(coreStart.elasticsearch, request);
this.savedObjects = new CoreSavedObjectsRouteHandlerContext(coreStart.savedObjects, request);
this.uiSettings = new CoreUiSettingsRouteHandlerContext(
coreStart.uiSettings,
this.savedObjects
);
this.deprecations = new CoreDeprecationsRouteHandlerContext(
coreStart.deprecations,
this.elasticsearch,
this.savedObjects
);
}
export interface RequestHandlerContext extends RequestHandlerContextBase {
core: Promise<CoreRequestHandlerContext>;
}
/**
* Mixin allowing plugins to define their own request handler contexts.
*
* @public
*/
export type CustomRequestHandlerContext<T> = RequestHandlerContext & {
[Key in keyof T]: T[Key] extends Promise<unknown> ? T[Key] : Promise<T[Key]>;
};

View file

@ -0,0 +1,17 @@
{
"extends": "../../../../tsconfig.bazel.json",
"compilerOptions": {
"declaration": true,
"declarationMap": true,
"emitDeclarationOnly": true,
"outDir": "target_types",
"stripInternal": false,
"types": [
"jest",
"node"
]
},
"include": [
"**/*.ts",
]
}

View file

@ -18,7 +18,7 @@ import type {
InternalHttpServiceSetup,
InternalHttpServicePreboot,
} from '@kbn/core-http-server-internal';
import { RequestHandlerContext } from '..';
import type { RequestHandlerContext } from '@kbn/core-http-request-handler-context-server';
import { InternalRenderingServicePreboot, InternalRenderingServiceSetup } from '../rendering';
import {
InternalHttpResourcesSetup,

View file

@ -15,7 +15,7 @@ import type {
KibanaResponseFactory,
RequestHandler,
} from '@kbn/core-http-server';
import type { RequestHandlerContext } from '..';
import type { RequestHandlerContext } from '@kbn/core-http-request-handler-context-server';
/**
* Allows to configure HTTP response parameters

View file

@ -42,7 +42,6 @@ import type {
ExecutionContextStart,
} from '@kbn/core-execution-context-server';
import type {
RequestHandlerContextBase,
IRouter,
RequestHandler,
KibanaResponseFactory,
@ -69,12 +68,11 @@ import type { CoreUsageDataStart, CoreUsageDataSetup } from '@kbn/core-usage-dat
import type { I18nServiceSetup } from '@kbn/core-i18n-server';
import type { StatusServiceSetup } from '@kbn/core-status-server';
import type { UiSettingsServiceSetup, UiSettingsServiceStart } from '@kbn/core-ui-settings-server';
import type { RequestHandlerContext } from '@kbn/core-http-request-handler-context-server';
import { HttpResources } from './http_resources';
import { PluginsServiceSetup, PluginsServiceStart, PluginOpaqueId } from './plugins';
import type { CoreRequestHandlerContext } from './core_route_handler_context';
import type { PrebootCoreRequestHandlerContext } from './preboot_core_route_handler_context';
import { PluginsServiceSetup, PluginsServiceStart } from './plugins';
export type { PluginOpaqueId } from '@kbn/core-base-common';
export type {
CoreUsageStats,
CoreUsageData,
@ -462,33 +460,13 @@ export type {
AnalyticsServicePreboot,
AnalyticsServiceStart,
} from '@kbn/core-analytics-server';
export type { CoreRequestHandlerContext } from './core_route_handler_context';
/**
* Base context passed to a route handler, containing the `core` context part.
*
* @public
*/
export interface RequestHandlerContext extends RequestHandlerContextBase {
core: Promise<CoreRequestHandlerContext>;
}
/**
* @internal
*/
export interface PrebootRequestHandlerContext extends RequestHandlerContextBase {
core: Promise<PrebootCoreRequestHandlerContext>;
}
/**
* Mixin allowing plugins to define their own request handler contexts.
*
* @public
*/
export type CustomRequestHandlerContext<T> = RequestHandlerContext & {
[Key in keyof T]: T[Key] extends Promise<unknown> ? T[Key] : Promise<T[Key]>;
};
export type {
RequestHandlerContext,
CoreRequestHandlerContext,
CustomRequestHandlerContext,
PrebootRequestHandlerContext,
PrebootCoreRequestHandlerContext,
} from '@kbn/core-http-request-handler-context-server';
/**
* Context passed to the `setup` method of `preboot` plugins.
@ -599,7 +577,6 @@ export type {
HttpResources,
PluginsServiceSetup,
PluginsServiceStart,
PluginOpaqueId,
};
/**

View file

@ -58,16 +58,21 @@ import {
import { CoreUsageDataService } from '@kbn/core-usage-data-server-internal';
import { StatusService, statusConfig } from '@kbn/core-status-server-internal';
import { UiSettingsService, uiSettingsConfig } from '@kbn/core-ui-settings-server-internal';
import {
CoreRouteHandlerContext,
PrebootCoreRouteHandlerContext,
} from '@kbn/core-http-request-handler-context-server-internal';
import type {
RequestHandlerContext,
PrebootRequestHandlerContext,
} from '@kbn/core-http-request-handler-context-server';
import { CoreApp } from './core_app';
import { HttpResourcesService } from './http_resources';
import { RenderingService } from './rendering';
import { PluginsService, config as pluginsConfig } from './plugins';
import { InternalCorePreboot, InternalCoreSetup, InternalCoreStart } from './internal_types';
import { CoreRouteHandlerContext } from './core_route_handler_context';
import { PrebootCoreRouteHandlerContext } from './preboot_core_route_handler_context';
import { DiscoveredPlugins } from './plugins';
import type { RequestHandlerContext, PrebootRequestHandlerContext } from '.';
const coreId = Symbol('core');
const rootConfigPath = '';

View file

@ -2954,6 +2954,14 @@
version "0.0.0"
uid ""
"@kbn/core-http-request-handler-context-server-internal@link:bazel-bin/packages/core/http/core-http-request-handler-context-server-internal":
version "0.0.0"
uid ""
"@kbn/core-http-request-handler-context-server@link:bazel-bin/packages/core/http/core-http-request-handler-context-server":
version "0.0.0"
uid ""
"@kbn/core-http-router-server-internal@link:bazel-bin/packages/core/http/core-http-router-server-internal":
version "0.0.0"
uid ""
@ -7075,6 +7083,14 @@
version "0.0.0"
uid ""
"@types/kbn__core-http-request-handler-context-server-internal@link:bazel-bin/packages/core/http/core-http-request-handler-context-server-internal/npm_module_types":
version "0.0.0"
uid ""
"@types/kbn__core-http-request-handler-context-server@link:bazel-bin/packages/core/http/core-http-request-handler-context-server/npm_module_types":
version "0.0.0"
uid ""
"@types/kbn__core-http-router-server-internal@link:bazel-bin/packages/core/http/core-http-router-server-internal/npm_module_types":
version "0.0.0"
uid ""