mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
Migrate server-side http_resources service to packages (#142537)
Co-authored-by: pgayvallet <pierre.gayvallet@elastic.co> Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
5ff2232c26
commit
1c8e0ed785
43 changed files with 675 additions and 43 deletions
3
.github/CODEOWNERS
vendored
3
.github/CODEOWNERS
vendored
|
@ -745,6 +745,9 @@ 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-resources-server @elastic/kibana-core
|
||||
packages/core/http/core-http-resources-server-internal @elastic/kibana-core
|
||||
packages/core/http/core-http-resources-server-mocks @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
|
||||
|
|
|
@ -215,6 +215,9 @@
|
|||
"@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-resources-server": "link:bazel-bin/packages/core/http/core-http-resources-server",
|
||||
"@kbn/core-http-resources-server-internal": "link:bazel-bin/packages/core/http/core-http-resources-server-internal",
|
||||
"@kbn/core-http-resources-server-mocks": "link:bazel-bin/packages/core/http/core-http-resources-server-mocks",
|
||||
"@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",
|
||||
|
@ -942,6 +945,9 @@
|
|||
"@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-resources-server": "link:bazel-bin/packages/core/http/core-http-resources-server/npm_module_types",
|
||||
"@types/kbn__core-http-resources-server-internal": "link:bazel-bin/packages/core/http/core-http-resources-server-internal/npm_module_types",
|
||||
"@types/kbn__core-http-resources-server-mocks": "link:bazel-bin/packages/core/http/core-http-resources-server-mocks/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",
|
||||
|
|
|
@ -81,6 +81,9 @@ filegroup(
|
|||
"//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-resources-server:build",
|
||||
"//packages/core/http/core-http-resources-server-internal:build",
|
||||
"//packages/core/http/core-http-resources-server-mocks: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",
|
||||
|
@ -418,6 +421,9 @@ filegroup(
|
|||
"//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-resources-server:build_types",
|
||||
"//packages/core/http/core-http-resources-server-internal:build_types",
|
||||
"//packages/core/http/core-http-resources-server-mocks: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",
|
||||
|
|
|
@ -0,0 +1,115 @@
|
|||
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-resources-server-internal"
|
||||
PKG_REQUIRE_NAME = "@kbn/core-http-resources-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 = [
|
||||
"@npm//elastic-apm-node",
|
||||
"//packages/kbn-logging",
|
||||
"//packages/kbn-apm-config-loader",
|
||||
]
|
||||
|
||||
TYPES_DEPS = [
|
||||
"@npm//@types/node",
|
||||
"@npm//@types/jest",
|
||||
"@npm//elastic-apm-node",
|
||||
"//packages/kbn-apm-config-loader:npm_module_types",
|
||||
"//packages/kbn-logging:npm_module_types",
|
||||
"//packages/core/http/core-http-server:npm_module_types",
|
||||
"//packages/core/http/core-http-resources-server:npm_module_types",
|
||||
"//packages/core/rendering/core-rendering-server-internal:npm_module_types",
|
||||
"//packages/core/http/core-http-request-handler-context-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"],
|
||||
)
|
|
@ -0,0 +1,3 @@
|
|||
# @kbn/core-http-resources-server-internal
|
||||
|
||||
This package contains the internal types and implementation for Core's internal `http` resources service.
|
|
@ -0,0 +1,11 @@
|
|||
/*
|
||||
* 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 { HttpResourcesService } from './src';
|
||||
|
||||
export type { InternalHttpResourcesPreboot, InternalHttpResourcesSetup } from './src';
|
|
@ -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-resources-server-internal'],
|
||||
};
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"type": "shared-common",
|
||||
"id": "@kbn/core-http-resources-server-internal",
|
||||
"owner": "@elastic/kibana-core",
|
||||
"runtimeDeps": [],
|
||||
"typeDeps": [],
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"name": "@kbn/core-http-resources-server-internal",
|
||||
"private": true,
|
||||
"version": "1.0.0",
|
||||
"main": "./target_node/index.js",
|
||||
"license": "SSPL-1.0 OR Elastic License 2.0"
|
||||
}
|
|
@ -12,11 +12,13 @@ import type { RouteConfig } from '@kbn/core-http-server';
|
|||
|
||||
import { mockCoreContext } from '@kbn/core-base-server-mocks';
|
||||
import { httpServiceMock, httpServerMock } from '@kbn/core-http-server-mocks';
|
||||
import { coreMock } from '../mocks';
|
||||
import { renderingServiceMock } from '@kbn/core-rendering-server-mocks';
|
||||
import { HttpResourcesService, PrebootDeps, SetupDeps } from './http_resources_service';
|
||||
import { httpResourcesMock } from './http_resources_service.mock';
|
||||
import { HttpResources } from '..';
|
||||
import type { HttpResources } from '@kbn/core-http-resources-server';
|
||||
import {
|
||||
createCoreRequestHandlerContextMock,
|
||||
createHttpResourcesResponseFactory,
|
||||
} from './test_helpers/http_resources_service_test_mocks';
|
||||
|
||||
const coreContext = mockCoreContext.create();
|
||||
|
||||
|
@ -26,7 +28,7 @@ describe('HttpResources service', () => {
|
|||
let setupDeps: SetupDeps;
|
||||
let router: ReturnType<typeof httpServiceMock.createRouter>;
|
||||
const kibanaRequest = httpServerMock.createKibanaRequest();
|
||||
const context = coreMock.createCustomRequestHandlerContext({});
|
||||
const context = createCoreRequestHandlerContextMock();
|
||||
const apmConfig = { mockApmConfig: true };
|
||||
|
||||
beforeEach(() => {
|
||||
|
@ -66,7 +68,7 @@ describe('HttpResources service', () => {
|
|||
});
|
||||
const [[, routeHandler]] = router.get.mock.calls;
|
||||
|
||||
const responseFactory = httpResourcesMock.createResponseFactory();
|
||||
const responseFactory = createHttpResourcesResponseFactory();
|
||||
await routeHandler(context, kibanaRequest, responseFactory);
|
||||
expect(getDeps().rendering.render).toHaveBeenCalledWith(
|
||||
kibanaRequest,
|
||||
|
@ -92,7 +94,7 @@ describe('HttpResources service', () => {
|
|||
|
||||
const [[, routeHandler]] = router.get.mock.calls;
|
||||
|
||||
const responseFactory = httpResourcesMock.createResponseFactory();
|
||||
const responseFactory = createHttpResourcesResponseFactory();
|
||||
await routeHandler(context, kibanaRequest, responseFactory);
|
||||
|
||||
expect(responseFactory.ok).toHaveBeenCalledWith({
|
||||
|
@ -112,7 +114,7 @@ describe('HttpResources service', () => {
|
|||
});
|
||||
const [[, routeHandler]] = router.get.mock.calls;
|
||||
|
||||
const responseFactory = httpResourcesMock.createResponseFactory();
|
||||
const responseFactory = createHttpResourcesResponseFactory();
|
||||
await routeHandler(context, kibanaRequest, responseFactory);
|
||||
expect(getDeps().rendering.render).toHaveBeenCalledWith(
|
||||
kibanaRequest,
|
||||
|
@ -138,7 +140,7 @@ describe('HttpResources service', () => {
|
|||
|
||||
const [[, routeHandler]] = router.get.mock.calls;
|
||||
|
||||
const responseFactory = httpResourcesMock.createResponseFactory();
|
||||
const responseFactory = createHttpResourcesResponseFactory();
|
||||
await routeHandler(context, kibanaRequest, responseFactory);
|
||||
|
||||
expect(responseFactory.ok).toHaveBeenCalledWith({
|
||||
|
@ -159,7 +161,7 @@ describe('HttpResources service', () => {
|
|||
});
|
||||
const [[, routeHandler]] = router.get.mock.calls;
|
||||
|
||||
const responseFactory = httpResourcesMock.createResponseFactory();
|
||||
const responseFactory = createHttpResourcesResponseFactory();
|
||||
await routeHandler(context, kibanaRequest, responseFactory);
|
||||
expect(responseFactory.ok).toHaveBeenCalledWith({
|
||||
body: htmlBody,
|
||||
|
@ -186,7 +188,7 @@ describe('HttpResources service', () => {
|
|||
|
||||
const [[, routeHandler]] = router.get.mock.calls;
|
||||
|
||||
const responseFactory = httpResourcesMock.createResponseFactory();
|
||||
const responseFactory = createHttpResourcesResponseFactory();
|
||||
await routeHandler(context, kibanaRequest, responseFactory);
|
||||
|
||||
expect(responseFactory.ok).toHaveBeenCalledWith({
|
||||
|
@ -208,7 +210,7 @@ describe('HttpResources service', () => {
|
|||
});
|
||||
const [[, routeHandler]] = router.get.mock.calls;
|
||||
|
||||
const responseFactory = httpResourcesMock.createResponseFactory();
|
||||
const responseFactory = createHttpResourcesResponseFactory();
|
||||
await routeHandler(context, kibanaRequest, responseFactory);
|
||||
expect(responseFactory.ok).toHaveBeenCalledWith({
|
||||
body: jsBody,
|
||||
|
@ -235,7 +237,7 @@ describe('HttpResources service', () => {
|
|||
|
||||
const [[, routeHandler]] = router.get.mock.calls;
|
||||
|
||||
const responseFactory = httpResourcesMock.createResponseFactory();
|
||||
const responseFactory = createHttpResourcesResponseFactory();
|
||||
await routeHandler(context, kibanaRequest, responseFactory);
|
||||
|
||||
expect(responseFactory.ok).toHaveBeenCalledWith({
|
|
@ -23,21 +23,29 @@ import type {
|
|||
InternalRenderingServiceSetup,
|
||||
} from '@kbn/core-rendering-server-internal';
|
||||
import type { RequestHandlerContext } from '@kbn/core-http-request-handler-context-server';
|
||||
import {
|
||||
InternalHttpResourcesSetup,
|
||||
import type {
|
||||
HttpResources,
|
||||
HttpResourcesResponseOptions,
|
||||
HttpResourcesRenderOptions,
|
||||
HttpResourcesRequestHandler,
|
||||
HttpResourcesServiceToolkit,
|
||||
} from './types';
|
||||
} from '@kbn/core-http-resources-server';
|
||||
|
||||
import type { InternalHttpResourcesSetup } from './types';
|
||||
|
||||
import { getApmConfig } from './get_apm_config';
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export interface PrebootDeps {
|
||||
http: InternalHttpServicePreboot;
|
||||
rendering: InternalRenderingServicePreboot;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export interface SetupDeps {
|
||||
http: InternalHttpServiceSetup;
|
||||
rendering: InternalRenderingServiceSetup;
|
|
@ -0,0 +1,11 @@
|
|||
/*
|
||||
* 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 { HttpResourcesService } from './http_resources_service';
|
||||
|
||||
export type { InternalHttpResourcesPreboot, InternalHttpResourcesSetup } from './types';
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* 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 { HttpResourcesServiceToolkit } from '@kbn/core-http-resources-server';
|
||||
import { httpServerMock } from '@kbn/core-http-server-mocks';
|
||||
import { uiSettingsServiceMock } from '@kbn/core-ui-settings-server-mocks';
|
||||
|
||||
// partial duplicate of coreMock
|
||||
export function createCoreRequestHandlerContextMock() {
|
||||
return {
|
||||
core: {
|
||||
uiSettings: { client: uiSettingsServiceMock.createClient() },
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
// duplicate of public mock for internal testing only
|
||||
export function createHttpResourcesResponseFactory() {
|
||||
const mocked: jest.Mocked<HttpResourcesServiceToolkit> = {
|
||||
renderCoreApp: jest.fn(),
|
||||
renderAnonymousCoreApp: jest.fn(),
|
||||
renderHtml: jest.fn(),
|
||||
renderJs: jest.fn(),
|
||||
};
|
||||
|
||||
return {
|
||||
...httpServerMock.createResponseFactory(),
|
||||
...mocked,
|
||||
};
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* 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 { IRouter } from '@kbn/core-http-server';
|
||||
import type { HttpResources } from '@kbn/core-http-resources-server';
|
||||
|
||||
/**
|
||||
* Allows to configure HTTP response parameters
|
||||
* @internal
|
||||
*/
|
||||
export interface InternalHttpResourcesPreboot {
|
||||
createRegistrar(router: IRouter): HttpResources;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows to configure HTTP response parameters
|
||||
* @internal
|
||||
*/
|
||||
export type InternalHttpResourcesSetup = InternalHttpResourcesPreboot;
|
|
@ -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",
|
||||
]
|
||||
}
|
110
packages/core/http/core-http-resources-server-mocks/BUILD.bazel
Normal file
110
packages/core/http/core-http-resources-server-mocks/BUILD.bazel
Normal 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-resources-server-mocks"
|
||||
PKG_REQUIRE_NAME = "@kbn/core-http-resources-server-mocks"
|
||||
|
||||
SOURCE_FILES = glob(
|
||||
[
|
||||
"**/*.ts",
|
||||
],
|
||||
exclude = [
|
||||
"**/*.config.js",
|
||||
"**/*.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/http/core-http-server-mocks",
|
||||
"//packages/core/http/core-http-resources-server-internal",
|
||||
]
|
||||
|
||||
TYPES_DEPS = [
|
||||
"@npm//@types/node",
|
||||
"@npm//@types/jest",
|
||||
"//packages/kbn-utility-types:npm_module_types",
|
||||
"//packages/core/http/core-http-server-mocks:npm_module_types",
|
||||
"//packages/core/http/core-http-resources-server:npm_module_types",
|
||||
"//packages/core/http/core-http-resources-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"],
|
||||
)
|
|
@ -0,0 +1,3 @@
|
|||
# @kbn/core-http-resources-server-mocks
|
||||
|
||||
This package contains the mocks for Core's internal `http` resources service.
|
10
packages/core/http/core-http-resources-server-mocks/index.ts
Normal file
10
packages/core/http/core-http-resources-server-mocks/index.ts
Normal 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 { httpResourcesMock } from './src/http_resources_server.mock';
|
||||
export type { HttpResourcesMock } from './src/http_resources_server.mock';
|
|
@ -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-resources-server-mocks'],
|
||||
};
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"type": "shared-common",
|
||||
"id": "@kbn/core-http-resources-server-mocks",
|
||||
"owner": "@elastic/kibana-core",
|
||||
"runtimeDeps": [],
|
||||
"typeDeps": [],
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"name": "@kbn/core-http-resources-server-mocks",
|
||||
"private": true,
|
||||
"version": "1.0.0",
|
||||
"main": "./target_node/index.js",
|
||||
"author": "Kibana Core",
|
||||
"license": "SSPL-1.0 OR Elastic License 2.0"
|
||||
}
|
|
@ -7,7 +7,25 @@
|
|||
*/
|
||||
|
||||
import { httpServerMock } from '@kbn/core-http-server-mocks';
|
||||
import { HttpResources, HttpResourcesServiceToolkit } from './types';
|
||||
import type { PublicMethodsOf } from '@kbn/utility-types';
|
||||
import { HttpResourcesService } from '@kbn/core-http-resources-server-internal';
|
||||
import type { HttpResources, HttpResourcesServiceToolkit } from '@kbn/core-http-resources-server';
|
||||
|
||||
export type HttpResourcesMock = jest.Mocked<PublicMethodsOf<HttpResourcesService>>;
|
||||
|
||||
function createHttpResourcesService() {
|
||||
const mock: HttpResourcesMock = {
|
||||
preboot: jest.fn(),
|
||||
setup: jest.fn(),
|
||||
start: jest.fn(),
|
||||
stop: jest.fn(),
|
||||
};
|
||||
|
||||
mock.preboot.mockReturnValue(createInternalHttpResourcesPreboot());
|
||||
mock.setup.mockReturnValue(createInternalHttpResourcesSetup());
|
||||
|
||||
return mock;
|
||||
}
|
||||
|
||||
const createHttpResourcesMock = (): jest.Mocked<HttpResources> => ({
|
||||
register: jest.fn(),
|
||||
|
@ -38,6 +56,7 @@ function createHttpResourcesResponseFactory() {
|
|||
}
|
||||
|
||||
export const httpResourcesMock = {
|
||||
create: createHttpResourcesService,
|
||||
createRegistrar: createHttpResourcesMock,
|
||||
createPrebootContract: createInternalHttpResourcesPreboot,
|
||||
createSetupContract: createInternalHttpResourcesSetup,
|
|
@ -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",
|
||||
]
|
||||
}
|
107
packages/core/http/core-http-resources-server/BUILD.bazel
Normal file
107
packages/core/http/core-http-resources-server/BUILD.bazel
Normal file
|
@ -0,0 +1,107 @@
|
|||
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-resources-server"
|
||||
PKG_REQUIRE_NAME = "@kbn/core-http-resources-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/http/core-http-request-handler-context-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"],
|
||||
)
|
3
packages/core/http/core-http-resources-server/README.md
Normal file
3
packages/core/http/core-http-resources-server/README.md
Normal file
|
@ -0,0 +1,3 @@
|
|||
# @kbn/core-http-resources-server
|
||||
|
||||
This package contains the public types for Core's HTTP resources service.
|
15
packages/core/http/core-http-resources-server/index.ts
Normal file
15
packages/core/http/core-http-resources-server/index.ts
Normal 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.
|
||||
*/
|
||||
|
||||
export type {
|
||||
HttpResourcesRenderOptions,
|
||||
HttpResourcesResponseOptions,
|
||||
HttpResourcesServiceToolkit,
|
||||
HttpResourcesRequestHandler,
|
||||
HttpResources,
|
||||
} from './src';
|
13
packages/core/http/core-http-resources-server/jest.config.js
Normal file
13
packages/core/http/core-http-resources-server/jest.config.js
Normal 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-resources-server'],
|
||||
};
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"type": "shared-common",
|
||||
"id": "@kbn/core-http-resources-server",
|
||||
"owner": "@elastic/kibana-core",
|
||||
"runtimeDeps": [],
|
||||
"typeDeps": [],
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"name": "@kbn/core-http-resources-server",
|
||||
"private": true,
|
||||
"version": "1.0.0",
|
||||
"main": "./target_node/index.js",
|
||||
"license": "SSPL-1.0 OR Elastic License 2.0"
|
||||
}
|
|
@ -6,14 +6,10 @@
|
|||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
export { HttpResourcesService } from './http_resources_service';
|
||||
|
||||
export type {
|
||||
HttpResourcesRenderOptions,
|
||||
HttpResourcesResponseOptions,
|
||||
HttpResourcesServiceToolkit,
|
||||
HttpResourcesRequestHandler,
|
||||
HttpResources,
|
||||
InternalHttpResourcesPreboot,
|
||||
InternalHttpResourcesSetup,
|
||||
} from './types';
|
|
@ -7,7 +7,6 @@
|
|||
*/
|
||||
|
||||
import type {
|
||||
IRouter,
|
||||
RouteConfig,
|
||||
IKibanaResponse,
|
||||
ResponseHeaders,
|
||||
|
@ -85,20 +84,6 @@ export type HttpResourcesRequestHandler<
|
|||
Context extends RequestHandlerContext = RequestHandlerContext
|
||||
> = RequestHandler<P, Q, B, Context, 'get', KibanaResponseFactory & HttpResourcesServiceToolkit>;
|
||||
|
||||
/**
|
||||
* Allows to configure HTTP response parameters
|
||||
* @internal
|
||||
*/
|
||||
export interface InternalHttpResourcesPreboot {
|
||||
createRegistrar(router: IRouter): HttpResources;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows to configure HTTP response parameters
|
||||
* @internal
|
||||
*/
|
||||
export type InternalHttpResourcesSetup = InternalHttpResourcesPreboot;
|
||||
|
||||
/**
|
||||
* HttpResources service is responsible for serving static & dynamic assets for Kibana application via HTTP.
|
||||
* Provides API allowing plug-ins to respond with:
|
17
packages/core/http/core-http-resources-server/tsconfig.json
Normal file
17
packages/core/http/core-http-resources-server/tsconfig.json
Normal 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",
|
||||
]
|
||||
}
|
|
@ -12,7 +12,7 @@ import { mockCoreContext } from '@kbn/core-base-server-mocks';
|
|||
import { mockRouter } from '@kbn/core-http-router-server-mocks';
|
||||
import type { UiPlugins } from '@kbn/core-plugins-base-server-internal';
|
||||
import { coreMock, httpServerMock } from '../mocks';
|
||||
import { httpResourcesMock } from '../http_resources/http_resources_service.mock';
|
||||
import { httpResourcesMock } from '@kbn/core-http-resources-server-mocks';
|
||||
import { PluginType } from '../plugins';
|
||||
import { CoreApp } from './core_app';
|
||||
import { RequestHandlerContext } from '..';
|
||||
|
|
|
@ -21,7 +21,7 @@ import type {
|
|||
IBasePath,
|
||||
} from '@kbn/core-http-server';
|
||||
import type { UiPlugins } from '@kbn/core-plugins-base-server-internal';
|
||||
import { HttpResources, HttpResourcesServiceToolkit } from '../http_resources';
|
||||
import type { HttpResources, HttpResourcesServiceToolkit } from '@kbn/core-http-resources-server';
|
||||
import { InternalCorePreboot, InternalCoreSetup } from '../internal_types';
|
||||
import { registerBundleRoutes } from './bundle_routes';
|
||||
import type { InternalCoreAppRequestHandlerContext } from './internal_types';
|
||||
|
|
|
@ -69,7 +69,7 @@ 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 type { HttpResources } from '@kbn/core-http-resources-server';
|
||||
import { PluginsServiceSetup, PluginsServiceStart } from './plugins';
|
||||
|
||||
export type { PluginOpaqueId } from '@kbn/core-base-common';
|
||||
|
@ -228,7 +228,7 @@ export type {
|
|||
HttpResourcesResponseOptions,
|
||||
HttpResourcesServiceToolkit,
|
||||
HttpResourcesRequestHandler,
|
||||
} from './http_resources';
|
||||
} from '@kbn/core-http-resources-server';
|
||||
|
||||
export type {
|
||||
LoggingServiceSetup,
|
||||
|
|
|
@ -59,7 +59,10 @@ import type {
|
|||
InternalUiSettingsServiceStart,
|
||||
} from '@kbn/core-ui-settings-server-internal';
|
||||
import type { InternalRenderingServiceSetup } from '@kbn/core-rendering-server-internal';
|
||||
import { InternalHttpResourcesPreboot, InternalHttpResourcesSetup } from './http_resources';
|
||||
import type {
|
||||
InternalHttpResourcesPreboot,
|
||||
InternalHttpResourcesSetup,
|
||||
} from '@kbn/core-http-resources-server-internal';
|
||||
|
||||
/** @internal */
|
||||
export interface InternalCorePreboot {
|
||||
|
|
|
@ -32,6 +32,7 @@ import { i18nServiceMock } from '@kbn/core-i18n-server-mocks';
|
|||
import { statusServiceMock } from '@kbn/core-status-server-mocks';
|
||||
import { uiSettingsServiceMock } from '@kbn/core-ui-settings-server-mocks';
|
||||
import { renderingServiceMock } from '@kbn/core-rendering-server-mocks';
|
||||
import { httpResourcesMock } from '@kbn/core-http-resources-server-mocks';
|
||||
import type {
|
||||
PluginInitializerContext,
|
||||
CoreSetup,
|
||||
|
@ -40,7 +41,6 @@ import type {
|
|||
CorePreboot,
|
||||
RequestHandlerContext,
|
||||
} from '.';
|
||||
import { httpResourcesMock } from './http_resources/http_resources_service.mock';
|
||||
import { SharedGlobalConfig } from './plugins';
|
||||
|
||||
export { configServiceMock, configDeprecationsMock } from '@kbn/config-mocks';
|
||||
|
@ -48,7 +48,7 @@ export { loggingSystemMock } from '@kbn/core-logging-server-mocks';
|
|||
export { httpServerMock, sessionStorageMock, httpServiceMock } from '@kbn/core-http-server-mocks';
|
||||
export { elasticsearchServiceMock } from '@kbn/core-elasticsearch-server-mocks';
|
||||
export { typeRegistryMock as savedObjectsTypeRegistryMock } from '@kbn/core-saved-objects-base-server-mocks';
|
||||
export { httpResourcesMock } from './http_resources/http_resources_service.mock';
|
||||
export { httpResourcesMock } from '@kbn/core-http-resources-server-mocks';
|
||||
export { savedObjectsServiceMock } from '@kbn/core-saved-objects-server-mocks';
|
||||
export {
|
||||
savedObjectsClientMock,
|
||||
|
|
|
@ -68,8 +68,8 @@ import type {
|
|||
} from '@kbn/core-http-request-handler-context-server';
|
||||
import { RenderingService } from '@kbn/core-rendering-server-internal';
|
||||
|
||||
import { HttpResourcesService } from '@kbn/core-http-resources-server-internal';
|
||||
import { CoreApp } from './core_app';
|
||||
import { HttpResourcesService } from './http_resources';
|
||||
import { PluginsService, config as pluginsConfig } from './plugins';
|
||||
import { InternalCorePreboot, InternalCoreSetup, InternalCoreStart } from './internal_types';
|
||||
import { DiscoveredPlugins } from './plugins';
|
||||
|
|
24
yarn.lock
24
yarn.lock
|
@ -2962,6 +2962,18 @@
|
|||
version "0.0.0"
|
||||
uid ""
|
||||
|
||||
"@kbn/core-http-resources-server-internal@link:bazel-bin/packages/core/http/core-http-resources-server-internal":
|
||||
version "0.0.0"
|
||||
uid ""
|
||||
|
||||
"@kbn/core-http-resources-server-mocks@link:bazel-bin/packages/core/http/core-http-resources-server-mocks":
|
||||
version "0.0.0"
|
||||
uid ""
|
||||
|
||||
"@kbn/core-http-resources-server@link:bazel-bin/packages/core/http/core-http-resources-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 ""
|
||||
|
@ -7107,6 +7119,18 @@
|
|||
version "0.0.0"
|
||||
uid ""
|
||||
|
||||
"@types/kbn__core-http-resources-server-internal@link:bazel-bin/packages/core/http/core-http-resources-server-internal/npm_module_types":
|
||||
version "0.0.0"
|
||||
uid ""
|
||||
|
||||
"@types/kbn__core-http-resources-server-mocks@link:bazel-bin/packages/core/http/core-http-resources-server-mocks/npm_module_types":
|
||||
version "0.0.0"
|
||||
uid ""
|
||||
|
||||
"@types/kbn__core-http-resources-server@link:bazel-bin/packages/core/http/core-http-resources-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 ""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue