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

Extract src/core in a separate TS project #76785

Merged
merged 25 commits into from
Sep 15, 2020
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
871fa93
break dependency on data plugin TS code
mshustov Sep 4, 2020
2f8fe03
move global typings to @kbn/utility-types
mshustov Sep 4, 2020
58a6833
import types from @kbn/utility-types
mshustov Sep 4, 2020
053f33a
remove type dependency on plugins
mshustov Sep 4, 2020
3ee5024
add intermediate js files to break dependency on outter TS code
mshustov Sep 4, 2020
0afe83f
temp type declaration for query-string
mshustov Sep 4, 2020
b013a97
declare src/core project
mshustov Sep 4, 2020
4d11218
export types to reference in the built d.ts files
mshustov Sep 4, 2020
51f9a25
reference core project
mshustov Sep 4, 2020
4c720f0
move jest types out of kbn/utility-types due to a clash with mocha types
mshustov Sep 4, 2020
5109563
Merge branch 'master' into src-core-ts-project
mshustov Sep 4, 2020
51e45d5
fix wrong es_kuery path and ts project paths
mshustov Sep 4, 2020
702edf8
reference core from packages consuming it
mshustov Sep 4, 2020
79cec57
x-pack & oss should use the same lodash version
mshustov Sep 5, 2020
568cf5d
Revert "x-pack & oss should use the same lodash version"
mshustov Sep 5, 2020
ffadf41
use the same lodash version
mshustov Sep 6, 2020
a14a7ed
fix @types/lodash TS2300: Duplicate identifier error
mshustov Sep 7, 2020
795026e
fix wrong imports
mshustov Sep 7, 2020
3c5dd03
Merge branch 'master' into src-core-ts-project
mshustov Sep 7, 2020
c9b2342
update docs
mshustov Sep 7, 2020
d016606
Merge branch 'master' into src-core-ts-project
mshustov Sep 8, 2020
2fba6fa
update docs
mshustov Sep 8, 2020
744a7b1
Merge branch 'master' into src-core-ts-project
mshustov Sep 14, 2020
a4f8860
Merge branch 'master' into src-core-ts-project
mshustov Sep 15, 2020
5cd4bad
add a comment why file is needed
mshustov Sep 15, 2020
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
12 changes: 12 additions & 0 deletions packages/kbn-utility-types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,15 @@ export type PublicKeys<T> = keyof T;
* Returns an object with public keys only.
*/
export type PublicContract<T> = Pick<T, PublicKeys<T>>;

/**
* Returns public method names
*/
export type MethodKeysOf<T> = {
[K in keyof T]: T[K] extends (...args: any[]) => any ? K : never;
}[keyof T];

/**
* Returns an object with public methods only.
*/
export type PublicMethodsOf<T> = Pick<T, MethodKeysOf<T>>;
1 change: 0 additions & 1 deletion packages/kbn-utility-types/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"stripInternal": true,
"declarationMap": true,
"types": [
"jest",
"node"
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import type { PublicMethodsOf } from '@kbn/utility-types';
import { CapabilitiesService, CapabilitiesStart } from './capabilities_service';
import { deepFreeze } from '../../../utils';

Expand Down
2 changes: 1 addition & 1 deletion src/core/public/application/test_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/

import type { PublicMethodsOf } from '@kbn/utility-types';
import { AppUnmount, Mounter } from './types';
import { ApplicationService } from './application_service';

Expand Down
1 change: 1 addition & 0 deletions src/core/public/chrome/chrome_service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* under the License.
*/
import { BehaviorSubject } from 'rxjs';
import type { PublicMethodsOf } from '@kbn/utility-types';
import {
ChromeBadge,
ChromeBrand,
Expand Down
2 changes: 1 addition & 1 deletion src/core/public/context/context_service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/

import type { PublicMethodsOf } from '@kbn/utility-types';
import { ContextService, ContextSetup } from './context_service';
import { contextMock } from '../../utils/context.mock';

Expand Down
2 changes: 1 addition & 1 deletion src/core/public/core_app/core_app.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/

import type { PublicMethodsOf } from '@kbn/utility-types';
import { CoreApp } from './core_app';

type CoreAppContract = PublicMethodsOf<CoreApp>;
Expand Down
2 changes: 1 addition & 1 deletion src/core/public/doc_links/doc_links_service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/

import type { PublicMethodsOf } from '@kbn/utility-types';
import { injectedMetadataServiceMock } from '../injected_metadata/injected_metadata_service.mock';
import { DocLinksService, DocLinksStart } from './doc_links_service';

Expand Down
1 change: 1 addition & 0 deletions src/core/public/fatal_errors/fatal_errors_service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import type { PublicMethodsOf } from '@kbn/utility-types';
import { FatalErrorsService, FatalErrorsSetup } from './fatal_errors_service';

const createSetupContractMock = () => {
Expand Down
2 changes: 1 addition & 1 deletion src/core/public/http/http_service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/

import type { PublicMethodsOf } from '@kbn/utility-types';
import { HttpService } from './http_service';
import { HttpSetup } from './types';
import { BehaviorSubject } from 'rxjs';
Expand Down
1 change: 1 addition & 0 deletions src/core/public/http/loading_count_service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import { LoadingCountSetup, LoadingCountService } from './loading_count_service';
import { BehaviorSubject } from 'rxjs';
import type { PublicMethodsOf } from '@kbn/utility-types';

const createSetupContractMock = () => {
const setupContract: jest.Mocked<LoadingCountSetup> = {
Expand Down
2 changes: 2 additions & 0 deletions src/core/public/i18n/i18n_service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/

import React from 'react';
import type { PublicMethodsOf } from '@kbn/utility-types';

import { I18nService, I18nStart } from './i18n_service';

const PassThroughComponent = ({ children }: { children: React.ReactNode }) => children;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import type { PublicMethodsOf } from '@kbn/utility-types';
import { InjectedMetadataService, InjectedMetadataSetup } from './injected_metadata_service';

const createSetupContractMock = () => {
Expand Down
2 changes: 1 addition & 1 deletion src/core/public/integrations/integrations_service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/

import type { PublicMethodsOf } from '@kbn/utility-types';
import { IntegrationsService } from './integrations_service';

type IntegrationsServiceContract = PublicMethodsOf<IntegrationsService>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import type { PublicMethodsOf } from '@kbn/utility-types';
import {
NotificationsService,
NotificationsSetup,
Expand Down
2 changes: 1 addition & 1 deletion src/core/public/overlays/banners/banners_service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/

import type { PublicMethodsOf } from '@kbn/utility-types';
import { OverlayBannersStart, OverlayBannersService } from './banners_service';

const createStartContractMock = () => {
Expand Down
2 changes: 1 addition & 1 deletion src/core/public/overlays/flyout/flyout_service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/

import type { PublicMethodsOf } from '@kbn/utility-types';
import { FlyoutService, OverlayFlyoutStart } from './flyout_service';

const createStartContractMock = () => {
Expand Down
2 changes: 1 addition & 1 deletion src/core/public/overlays/modal/modal_service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/

import type { PublicMethodsOf } from '@kbn/utility-types';
import { ModalService, OverlayModalStart } from './modal_service';

const createStartContractMock = () => {
Expand Down
1 change: 1 addition & 0 deletions src/core/public/overlays/overlay_service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import type { PublicMethodsOf } from '@kbn/utility-types';
import { OverlayService, OverlayStart } from './overlay_service';
import { overlayBannersServiceMock } from './banners/banners_service.mock';
import { overlayFlyoutServiceMock } from './flyout/flyout_service.mock';
Expand Down
2 changes: 1 addition & 1 deletion src/core/public/plugins/plugins_service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/

import type { PublicMethodsOf } from '@kbn/utility-types';
import { PluginsService, PluginsServiceSetup } from './plugins_service';

const createSetupContractMock = () => {
Expand Down
2 changes: 1 addition & 1 deletion src/core/public/rendering/rendering_service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/

import type { PublicMethodsOf } from '@kbn/utility-types';
import { RenderingService } from './rendering_service';

type RenderingServiceContract = PublicMethodsOf<RenderingService>;
Expand Down
1 change: 1 addition & 0 deletions src/core/public/saved_objects/saved_objects_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import { cloneDeep, pick, throttle } from 'lodash';
import { resolve as resolveUrl } from 'url';
import type { PublicMethodsOf } from '@kbn/utility-types';

import {
SavedObject,
Expand Down
1 change: 1 addition & 0 deletions src/core/public/ui_settings/ui_settings_service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* under the License.
*/
import * as Rx from 'rxjs';
import type { PublicMethodsOf } from '@kbn/utility-types';
import { UiSettingsService } from './';
import { IUiSettingsClient } from './types';

Expand Down
2 changes: 1 addition & 1 deletion src/core/server/audit_trail/audit_trail_service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/

import type { PublicMethodsOf } from '@kbn/utility-types';
import { AuditTrailSetup, AuditTrailStart, Auditor } from './types';
import { AuditTrailService } from './audit_trail_service';

Expand Down
2 changes: 1 addition & 1 deletion src/core/server/capabilities/capabilities_service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/

import type { PublicMethodsOf } from '@kbn/utility-types';
import { CapabilitiesService, CapabilitiesSetup, CapabilitiesStart } from './capabilities_service';

const createSetupContractMock = () => {
Expand Down
2 changes: 1 addition & 1 deletion src/core/server/config/config_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/

import type { PublicMethodsOf } from '@kbn/utility-types';
import { Type } from '@kbn/config-schema';
import { isEqual } from 'lodash';
import { BehaviorSubject, combineLatest, Observable } from 'rxjs';
Expand Down
2 changes: 1 addition & 1 deletion src/core/server/config/raw_config_service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/

import type { PublicMethodsOf } from '@kbn/utility-types';
import { RawConfigService } from './raw_config_service';
import { Observable, of } from 'rxjs';

Expand Down
1 change: 1 addition & 0 deletions src/core/server/context/context_service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import type { PublicMethodsOf } from '@kbn/utility-types';

import { ContextService, ContextSetup } from './context_service';
import { contextMock } from '../../utils/context.mock';
Expand Down
1 change: 0 additions & 1 deletion src/core/server/core_context.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
* specific language governing permissions and limitations
* under the License.
*/

import { CoreContext } from './core_context';
import { getEnvOptions } from './config/__mocks__/env';
import { Env, IConfigService } from './config';
Expand Down
3 changes: 1 addition & 2 deletions src/core/server/elasticsearch/client/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
* specific language governing permissions and limitations
* under the License.
*/

import { Client, ApiResponse } from '@elastic/elasticsearch';
import { TransportRequestPromise } from '@elastic/elasticsearch/lib/Transport';
import { ElasticsearchClient } from './types';
Expand Down Expand Up @@ -75,7 +74,7 @@ export type ElasticsearchClientMock = DeeplyMockedKeys<ElasticsearchClient>;
const createClientMock = (): ElasticsearchClientMock =>
(createInternalClientMock() as unknown) as ElasticsearchClientMock;

interface ScopedClusterClientMock {
export interface ScopedClusterClientMock {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

required for TS to be able to reference the type in a declaration file

asInternalUser: ElasticsearchClientMock;
asCurrentUser: ElasticsearchClientMock;
}
Expand Down
4 changes: 3 additions & 1 deletion src/core/server/elasticsearch/elasticsearch_service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/

import { BehaviorSubject } from 'rxjs';
import type { PublicMethodsOf } from '@kbn/utility-types';

import { ILegacyClusterClient, ILegacyCustomClusterClient } from './legacy';
import {
elasticsearchClientMock,
Expand All @@ -32,7 +34,7 @@ import { InternalElasticsearchServiceSetup, ElasticsearchStatusMeta } from './ty
import { NodesVersionCompatibility } from './version_check/ensure_es_version';
import { ServiceStatus, ServiceStatusLevels } from '../status';

interface MockedElasticSearchServiceSetup {
export interface MockedElasticSearchServiceSetup {
legacy: {
config$: BehaviorSubject<ElasticsearchConfig>;
createClient: jest.Mock<ILegacyCustomClusterClient, any>;
Expand Down
1 change: 1 addition & 0 deletions src/core/server/environment/environment_service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import type { PublicMethodsOf } from '@kbn/utility-types';

import { EnvironmentService, InternalEnvironmentServiceSetup } from './environment_service';

Expand Down
2 changes: 2 additions & 0 deletions src/core/server/http/http_service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/

import { Server } from 'hapi';
import type { PublicMethodsOf } from '@kbn/utility-types';

import { CspConfig } from '../csp';
import { mockRouter, RouterMock } from './router/router.mock';
import { configMock } from '../config/config.mock';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import supertest from 'supertest';
import { BehaviorSubject } from 'rxjs';
import { ByteSizeValue } from '@kbn/config-schema';
import pkg from '../../../../../package.json';

import { createHttpServer } from '../test_utils';
import { HttpService } from '../http_service';
Expand All @@ -30,6 +29,9 @@ import { IRouter, RouteRegistrar } from '../router';
import { configServiceMock } from '../../config/config_service.mock';
import { contextServiceMock } from '../../context/context_service.mock';

// eslint-disable-next-line @typescript-eslint/no-var-requires
const pkg = require('../../../../../package.json');
Comment on lines +32 to +33
Copy link
Contributor

Choose a reason for hiding this comment

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

The package file is also considered as an external dependency?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if you import, yes. it should gone when @kbn/utils is merged.


const actualVersion = pkg.version;
const versionHeader = 'kbn-version';
const xsrfHeader = 'kbn-xsrf';
Expand Down
20 changes: 20 additions & 0 deletions src/core/server/legacy/cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export { startRepl } from '../../../cli/repl';
20 changes: 20 additions & 0 deletions src/core/server/legacy/cluster_manager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export { ClusterManager } from '../../../cli/cluster/cluster_manager';
2 changes: 1 addition & 1 deletion src/core/server/legacy/legacy_service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/

import type { PublicMethodsOf } from '@kbn/utility-types';
import { LegacyService } from './legacy_service';
import { LegacyConfig, LegacyServiceDiscoverPlugins, LegacyServiceSetupDeps } from './types';

Expand Down
5 changes: 3 additions & 2 deletions src/core/server/legacy/legacy_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

jest.mock('../../../legacy/server/kbn_server');
jest.mock('../../../cli/cluster/cluster_manager');
jest.mock('./cluster_manager');
jest.mock('./config/legacy_deprecation_adapters', () => ({
convertLegacyDeprecationProvider: (provider: any) => Promise.resolve(provider),
}));
Expand All @@ -29,7 +29,8 @@ import {

import { BehaviorSubject, throwError } from 'rxjs';

import { ClusterManager as MockClusterManager } from '../../../cli/cluster/cluster_manager';
// @ts-expect-error js file to remove TS dependency on cli
import { ClusterManager as MockClusterManager } from './cluster_manager';
import KbnServer from '../../../legacy/server/kbn_server';
import { Config, Env, ObjectToConfigAdapter } from '../config';
import { getEnvOptions } from '../config/__mocks__/env';
Expand Down
Loading