Skip to content

Commit

Permalink
Move src/core/types/elasticsearch to @kbn/es-types (#140522)
Browse files Browse the repository at this point in the history
* create empty package

* move types to packages

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

* start fixing imports

* fix more imports

* fix inline import

* add apm-ui as owners

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

* fix new usages

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
pgayvallet and kibanamachine committed Sep 20, 2022
1 parent 256f2e7 commit 9579ea7
Show file tree
Hide file tree
Showing 76 changed files with 254 additions and 93 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,7 @@ packages/kbn-es @elastic/kibana-operations
packages/kbn-es-archiver @elastic/kibana-operations
packages/kbn-es-errors @elastic/kibana-core
packages/kbn-es-query @elastic/kibana-app-services
packages/kbn-es-types @elastic/kibana-core @elastic/apm-ui
packages/kbn-eslint-config @elastic/kibana-operations
packages/kbn-eslint-plugin-disable @elastic/kibana-operations
packages/kbn-eslint-plugin-eslint @elastic/kibana-operations
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@
"@kbn/ebt-tools": "link:bazel-bin/packages/kbn-ebt-tools",
"@kbn/es-errors": "link:bazel-bin/packages/kbn-es-errors",
"@kbn/es-query": "link:bazel-bin/packages/kbn-es-query",
"@kbn/es-types": "link:bazel-bin/packages/kbn-es-types",
"@kbn/field-types": "link:bazel-bin/packages/kbn-field-types",
"@kbn/flot-charts": "link:bazel-bin/packages/kbn-flot-charts",
"@kbn/handlebars": "link:bazel-bin/packages/kbn-handlebars",
Expand Down Expand Up @@ -1010,6 +1011,7 @@
"@types/kbn__es-archiver": "link:bazel-bin/packages/kbn-es-archiver/npm_module_types",
"@types/kbn__es-errors": "link:bazel-bin/packages/kbn-es-errors/npm_module_types",
"@types/kbn__es-query": "link:bazel-bin/packages/kbn-es-query/npm_module_types",
"@types/kbn__es-types": "link:bazel-bin/packages/kbn-es-types/npm_module_types",
"@types/kbn__eslint-plugin-disable": "link:bazel-bin/packages/kbn-eslint-plugin-disable/npm_module_types",
"@types/kbn__eslint-plugin-imports": "link:bazel-bin/packages/kbn-eslint-plugin-imports/npm_module_types",
"@types/kbn__field-types": "link:bazel-bin/packages/kbn-field-types/npm_module_types",
Expand Down
2 changes: 2 additions & 0 deletions packages/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ filegroup(
"//packages/kbn-es-archiver:build",
"//packages/kbn-es-errors:build",
"//packages/kbn-es-query:build",
"//packages/kbn-es-types:build",
"//packages/kbn-eslint-config:build",
"//packages/kbn-eslint-plugin-disable:build",
"//packages/kbn-eslint-plugin-eslint:build",
Expand Down Expand Up @@ -506,6 +507,7 @@ filegroup(
"//packages/kbn-es-archiver:build_types",
"//packages/kbn-es-errors:build_types",
"//packages/kbn-es-query:build_types",
"//packages/kbn-es-types:build_types",
"//packages/kbn-eslint-plugin-disable:build_types",
"//packages/kbn-eslint-plugin-imports:build_types",
"//packages/kbn-field-types:build_types",
Expand Down
107 changes: 107 additions & 0 deletions packages/kbn-es-types/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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 = "kbn-es-types"
PKG_REQUIRE_NAME = "@kbn/es-types"

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",
"@npm//utility-types",
"@npm//@elastic/elasticsearch",
]

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 changes: 3 additions & 0 deletions packages/kbn-es-types/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# @kbn/es-types

This package contains 'missing' types for the `@elastic/elasticsearch` client.
20 changes: 20 additions & 0 deletions packages/kbn-es-types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* 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 {
AggregationOptionsByType,
ESSearchOptions,
SearchHit,
ESSearchResponse,
ESSearchRequest,
ESSourceOptions,
InferSearchResponseOf,
AggregationResultOf,
ESFilter,
MaybeReadonlyArray,
} from './src';
13 changes: 13 additions & 0 deletions packages/kbn-es-types/jest.config.js
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/kbn-es-types'],
};
7 changes: 7 additions & 0 deletions packages/kbn-es-types/kibana.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "shared-common",
"id": "@kbn/es-types",
"owner": ["@elastic/kibana-core", "@elastic/apm-ui"],
"runtimeDeps": [],
"typeDeps": [],
}
8 changes: 8 additions & 0 deletions packages/kbn-es-types/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "@kbn/es-types",
"private": true,
"version": "1.0.0",
"main": "./target_node/index.js",
"author": "Kibana Core",
"license": "SSPL-1.0 OR Elastic License 2.0"
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import { ValuesType, UnionToIntersection } from 'utility-types';
import type { ValuesType, UnionToIntersection } from 'utility-types';
import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';

interface AggregationsAggregationContainer extends Record<string, any> {
Expand Down
17 changes: 17 additions & 0 deletions packages/kbn-es-types/tsconfig.json
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",
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import DateMath from '@kbn/datemath';
import type { DataView, DataViewField } from '@kbn/data-views-plugin/common';
import type { ESSearchResponse } from '@kbn/core/types/elasticsearch';
import type { ESSearchResponse } from '@kbn/es-types';
import type { FieldStatsResponse } from '../types';
import { getFieldExampleBuckets, canProvideExamplesForField } from './field_examples_calculator';

Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/aiops/server/routes/queries/get_filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';

import { ESFilter } from '@kbn/core/types/elasticsearch';
import type { ESFilter } from '@kbn/es-types';

import type { AiopsExplainLogRateSpikesSchema } from '../../../common/api/explain_log_rate_spikes';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { ESFilter } from '@kbn/core/types/elasticsearch';
import type { ESFilter } from '@kbn/es-types';
import {
ERROR_GROUP_ID,
PROCESSOR_EVENT,
Expand Down
5 changes: 1 addition & 4 deletions x-pack/plugins/apm/public/utils/test_helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ import { Moment } from 'moment-timezone';
import React from 'react';
import { MemoryRouter } from 'react-router-dom';
import { EuiThemeProvider } from '@kbn/kibana-react-plugin/common';
import {
ESSearchRequest,
ESSearchResponse,
} from '@kbn/core/types/elasticsearch';
import type { ESSearchRequest, ESSearchResponse } from '@kbn/es-types';
import { APMConfig } from '../../server';
import { MockApmPluginContextWrapper } from '../context/apm_plugin/mock_apm_plugin_context';
import { UrlParamsProvider } from '../context/url_params_context/url_params_context';
Expand Down
5 changes: 1 addition & 4 deletions x-pack/plugins/apm/scripts/shared/get_es_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@

import { Client } from '@elastic/elasticsearch';
import type { ClientOptions } from '@elastic/elasticsearch/lib/client';
import {
ESSearchResponse,
ESSearchRequest,
} from '@kbn/core/types/elasticsearch';
import type { ESSearchResponse, ESSearchRequest } from '@kbn/es-types';

export type ESClient = ReturnType<typeof getEsClient>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
* 2.0.
*/

import {
ESSearchRequest,
ESSearchResponse,
} from '@kbn/core/types/elasticsearch';
import type { ESSearchRequest, ESSearchResponse } from '@kbn/es-types';
import { Setup } from '../helpers/setup_request';

interface SharedFields {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
import { merge } from 'lodash';
import { Logger, SavedObjectsClient } from '@kbn/core/server';
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import {
ESSearchRequest,
ESSearchResponse,
} from '@kbn/core/types/elasticsearch';
import type { ESSearchRequest, ESSearchResponse } from '@kbn/es-types';
import { ApmIndicesConfig } from '../../../routes/settings/apm_indices/get_apm_indices';
import { tasks } from './tasks';
import { APMDataTelemetry } from '../types';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ import type {
} from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import { ValuesType } from 'utility-types';
import { ElasticsearchClient, KibanaRequest } from '@kbn/core/server';
import {
ESSearchRequest,
InferSearchResponseOf,
} from '@kbn/core/types/elasticsearch';
import type { ESSearchRequest, InferSearchResponseOf } from '@kbn/es-types';
import { unwrapEsResponse } from '@kbn/observability-plugin/server';
import { omit } from 'lodash';
import { ProcessorEvent } from '@kbn/observability-plugin/common';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { uniq, defaultsDeep, cloneDeep } from 'lodash';
import { ESSearchRequest, ESFilter } from '@kbn/core/types/elasticsearch';
import type { ESSearchRequest, ESFilter } from '@kbn/es-types';
import { ProcessorEvent } from '@kbn/observability-plugin/common';
import { PROCESSOR_EVENT } from '../../../../../common/elasticsearch_fieldnames';
import { ApmIndicesConfig } from '../../../../routes/settings/apm_indices/get_apm_indices';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@

import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import { unwrapEsResponse } from '@kbn/observability-plugin/server';
import {
ESSearchResponse,
ESSearchRequest,
} from '@kbn/core/types/elasticsearch';
import type { ESSearchResponse, ESSearchRequest } from '@kbn/es-types';
import { APMRouteHandlerResources } from '../../../../routes/typings';
import {
callAsyncWithDebug,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
* 2.0.
*/

import {
import type {
AggregationOptionsByType,
AggregationResultOf,
} from '@kbn/core/types/elasticsearch';
} from '@kbn/es-types';
import { FAAS_COLDSTART } from '../../../common/elasticsearch_fieldnames';

export const getColdstartAggregation = () => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
* 2.0.
*/

import {
import type {
AggregationOptionsByType,
AggregationResultOf,
} from '@kbn/core/types/elasticsearch';
} from '@kbn/es-types';
import { EVENT_OUTCOME } from '../../../common/elasticsearch_fieldnames';
import { EventOutcome } from '../../../common/event_outcome';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
* 2.0.
*/

import {
ESSearchRequest,
ESSearchResponse,
} from '@kbn/core/types/elasticsearch';
import type { ESSearchRequest, ESSearchResponse } from '@kbn/es-types';
import { RuleExecutorServices } from '@kbn/alerting-plugin/server';

export async function alertingEsClient<TParams extends ESSearchRequest>({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
ALERT_SEVERITY,
} from '@kbn/rule-data-utils';
import { compact } from 'lodash';
import { ESSearchResponse } from '@kbn/core/types/elasticsearch';
import type { ESSearchResponse } from '@kbn/es-types';
import { KibanaRequest } from '@kbn/core/server';
import { termQuery } from '@kbn/observability-plugin/server';
import { createLifecycleRuleTypeFactory } from '@kbn/rule-registry-plugin/server';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { Unionize } from 'utility-types';
import { euiLightVars as theme } from '@kbn/ui-theme';
import { QueryDslQueryContainer } from '@elastic/elasticsearch/lib/api/types';
import { AggregationOptionsByType } from '@kbn/core/types/elasticsearch';
import type { AggregationOptionsByType } from '@kbn/es-types';
import { kqlQuery, rangeQuery } from '@kbn/observability-plugin/server';
import { ProcessorEvent } from '@kbn/observability-plugin/common';
import { getVizColorForIndex } from '../../../common/viz_colors';
Expand Down
Loading

0 comments on commit 9579ea7

Please sign in to comment.