Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate server-side deprecation service to packages #139789

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@
"@kbn/core-deprecations-browser-mocks": "link:bazel-bin/packages/core/deprecations/core-deprecations-browser-mocks",
"@kbn/core-deprecations-common": "link:bazel-bin/packages/core/deprecations/core-deprecations-common",
"@kbn/core-deprecations-server": "link:bazel-bin/packages/core/deprecations/core-deprecations-server",
"@kbn/core-deprecations-server-internal": "link:bazel-bin/packages/core/deprecations/core-deprecations-server-internal",
"@kbn/core-deprecations-server-mocks": "link:bazel-bin/packages/core/deprecations/core-deprecations-server-mocks",
"@kbn/core-doc-links-browser": "link:bazel-bin/packages/core/doc-links/core-doc-links-browser",
"@kbn/core-doc-links-browser-internal": "link:bazel-bin/packages/core/doc-links/core-doc-links-browser-internal",
"@kbn/core-doc-links-browser-mocks": "link:bazel-bin/packages/core/doc-links/core-doc-links-browser-mocks",
Expand Down Expand Up @@ -851,6 +853,8 @@
"@types/kbn__core-deprecations-browser-mocks": "link:bazel-bin/packages/core/deprecations/core-deprecations-browser-mocks/npm_module_types",
"@types/kbn__core-deprecations-common": "link:bazel-bin/packages/core/deprecations/core-deprecations-common/npm_module_types",
"@types/kbn__core-deprecations-server": "link:bazel-bin/packages/core/deprecations/core-deprecations-server/npm_module_types",
"@types/kbn__core-deprecations-server-internal": "link:bazel-bin/packages/core/deprecations/core-deprecations-server-internal/npm_module_types",
"@types/kbn__core-deprecations-server-mocks": "link:bazel-bin/packages/core/deprecations/core-deprecations-server-mocks/npm_module_types",
"@types/kbn__core-doc-links-browser": "link:bazel-bin/packages/core/doc-links/core-doc-links-browser/npm_module_types",
"@types/kbn__core-doc-links-browser-internal": "link:bazel-bin/packages/core/doc-links/core-doc-links-browser-internal/npm_module_types",
"@types/kbn__core-doc-links-browser-mocks": "link:bazel-bin/packages/core/doc-links/core-doc-links-browser-mocks/npm_module_types",
Expand Down
4 changes: 4 additions & 0 deletions packages/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ filegroup(
"//packages/core/deprecations/core-deprecations-browser-mocks:build",
"//packages/core/deprecations/core-deprecations-common:build",
"//packages/core/deprecations/core-deprecations-server:build",
"//packages/core/deprecations/core-deprecations-server-internal:build",
"//packages/core/deprecations/core-deprecations-server-mocks:build",
"//packages/core/doc-links/core-doc-links-browser:build",
"//packages/core/doc-links/core-doc-links-browser-internal:build",
"//packages/core/doc-links/core-doc-links-browser-mocks:build",
Expand Down Expand Up @@ -335,6 +337,8 @@ filegroup(
"//packages/core/deprecations/core-deprecations-browser-mocks:build_types",
"//packages/core/deprecations/core-deprecations-common:build_types",
"//packages/core/deprecations/core-deprecations-server:build_types",
"//packages/core/deprecations/core-deprecations-server-internal:build_types",
"//packages/core/deprecations/core-deprecations-server-mocks:build_types",
"//packages/core/doc-links/core-doc-links-browser:build_types",
"//packages/core/doc-links/core-doc-links-browser-internal:build_types",
"//packages/core/doc-links/core-doc-links-browser-mocks:build_types",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
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-deprecations-server-internal"
PKG_REQUIRE_NAME = "@kbn/core-deprecations-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//rxjs",
"//packages/kbn-i18n",
"//packages/kbn-std",
### test dependencies
"//packages/kbn-logging-mocks",
]

TYPES_DEPS = [
"@npm//@types/node",
"@npm//@types/jest",
"@npm//rxjs",
"//packages/kbn-config-schema:npm_module_types",
"//packages/kbn-utility-types:npm_module_types",
"//packages/kbn-std:npm_module_types",
"//packages/kbn-i18n:npm_module_types",
"//packages/kbn-logging:npm_module_types",
"//packages/kbn-config:npm_module_types",
"//packages/core/base/core-base-server-internal:npm_module_types",
"//packages/core/http/core-http-server-internal:npm_module_types",
"//packages/core/elasticsearch/core-elasticsearch-server:npm_module_types",
"//packages/core/elasticsearch/core-elasticsearch-server-internal:npm_module_types",
"//packages/core/saved-objects/core-saved-objects-api-server:npm_module_types",
"//packages/core/saved-objects/core-saved-objects-server-internal:npm_module_types",
"//packages/core/deprecations/core-deprecations-common:npm_module_types",
"//packages/core/deprecations/core-deprecations-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"],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# @kbn/core-deprecations-server-internal

This package contains the internal types and implementation of Core's server-side `deprecations` service.
Original file line number Diff line number Diff line change
@@ -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 { DeprecationsService, config, CoreDeprecationsRouteHandlerContext } from './src';
export type { InternalDeprecationsServiceSetup, InternalDeprecationsServiceStart } from './src';
Original file line number Diff line number Diff line change
@@ -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/deprecations/core-deprecations-server-internal'],
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "@kbn/core-deprecations-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"
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,11 @@

import type { CoreElasticsearchRouteHandlerContext } from '@kbn/core-elasticsearch-server-internal';
import type { CoreSavedObjectsRouteHandlerContext } from '@kbn/core-saved-objects-server-internal';
import type { DeprecationsClient, InternalDeprecationsServiceStart } from './deprecations_service';

/**
* Core's `deprecations` request handler context.
* @public
*/
export interface DeprecationsRequestHandlerContext {
client: DeprecationsClient;
}
import type {
DeprecationsRequestHandlerContext,
DeprecationsClient,
} from '@kbn/core-deprecations-server';
import type { InternalDeprecationsServiceStart } from './deprecations_service';

/**
* The {@link DeprecationsRequestHandlerContext} implementation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import { mockDeprecationsFactory } from './deprecations_factory.mock';
import { mockDeprecationsFactory } from './mocks';

export const mockedDeprecationFactoryInstance = mockDeprecationsFactory.create();
export const DeprecationsFactoryMock = jest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ import { DeprecationsFactoryMock } from './deprecations_service.test.mocks';

import { mockCoreContext } from '@kbn/core-base-server-mocks';
import { httpServiceMock } from '@kbn/core-http-server-mocks';
/* eslint-disable dot-notation */
import { configServiceMock } from '@kbn/config-mocks';
import { savedObjectsClientMock } from '@kbn/core-saved-objects-api-server-mocks';
import { elasticsearchServiceMock } from '@kbn/core-elasticsearch-server-mocks';
import { DeprecationsService, DeprecationsSetupDeps } from './deprecations_service';
import { savedObjectsClientMock, elasticsearchServiceMock, configServiceMock } from '../mocks';
import { mockDeprecationsFactory } from './deprecations_factory.mock';
import { mockDeprecationsRegistry } from './deprecations_registry.mock';
import { mockDeprecationsRegistry, mockDeprecationsFactory } from './mocks';

/* eslint-disable dot-notation */
describe('DeprecationsService', () => {
let coreContext: ReturnType<typeof mockCoreContext.create>;
let http: ReturnType<typeof httpServiceMock.createInternalSetupContract>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,18 @@ import { firstValueFrom } from 'rxjs';
import type { Logger } from '@kbn/logging';
import type { IConfigService } from '@kbn/config';
import type { CoreContext, CoreService } from '@kbn/core-base-server-internal';
import type { DomainDeprecationDetails } from '@kbn/core-deprecations-common';
import type { InternalHttpServiceSetup } from '@kbn/core-http-server-internal';
import type { IScopedClusterClient } from '@kbn/core-elasticsearch-server';
import type { SavedObjectsClientContract } from '@kbn/core-saved-objects-api-server';
import type {
DeprecationsServiceSetup,
DeprecationRegistryProvider,
DeprecationsClient,
} from '@kbn/core-deprecations-server';
import { DeprecationsFactory } from './deprecations_factory';
import { registerRoutes } from './routes';
import { config as deprecationConfig, DeprecationConfigType } from './deprecation_config';

/**
* Server-side client that provides access to fetch all Kibana deprecations
*
* @public
*/
export interface DeprecationsClient {
getAllDeprecations: () => Promise<DomainDeprecationDetails[]>;
}

export interface InternalDeprecationsServiceStart {
/**
* Creates a {@link DeprecationsClient} with provided SO client and ES client.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,11 @@
* Side Public License, v 1.
*/

export type {
DeprecationsServiceSetup,
GetDeprecationsContext,
RegisterDeprecationsConfig,
} from '@kbn/core-deprecations-server';

export type {
InternalDeprecationsServiceSetup,
InternalDeprecationsServiceStart,
DeprecationsClient,
} from './deprecations_service';

export { DeprecationsService } from './deprecations_service';
export { config } from './deprecation_config';
export { CoreDeprecationsRouteHandlerContext } from './deprecations_route_handler_context';
export type { DeprecationsRequestHandlerContext } from './deprecations_route_handler_context';
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import type { IRouter, RequestHandlerContextBase } from '@kbn/core-http-server';
import type { DeprecationsRequestHandlerContext } from './deprecations_route_handler_context';
import type { DeprecationsRequestHandlerContext } from '@kbn/core-deprecations-server';

/**
* Request handler context used by core's deprecations routes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
*/

import type { PublicMethodsOf } from '@kbn/utility-types';
import type { DeprecationsFactory } from './deprecations_factory';
import type { DeprecationsFactory } from '../deprecations_factory';

type DeprecationsFactoryContract = PublicMethodsOf<DeprecationsFactory>;

const createDeprecationsFactoryMock = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type { PublicMethodsOf } from '@kbn/utility-types';
import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import type { GetDeprecationsContext } from '@kbn/core-deprecations-server';
import { savedObjectsClientMock } from '@kbn/core-saved-objects-api-server-mocks';
import type { DeprecationsRegistry } from './deprecations_registry';
import type { DeprecationsRegistry } from '../deprecations_registry';

type DeprecationsRegistryContract = PublicMethodsOf<DeprecationsRegistry>;

Expand Down
Original file line number Diff line number Diff line change
@@ -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 { mockDeprecationsRegistry } from './deprecations_registry.mock';
export { mockDeprecationsFactory } from './deprecations_factory.mock';
Comment on lines +9 to +10
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two mocks were only used for internal testing. There is no code duplication involved this time.

Original file line number Diff line number Diff line change
@@ -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",
]
}
Loading