Skip to content

Commit

Permalink
Cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeelmers committed Aug 12, 2020
1 parent 41d3cfd commit 0a1bea9
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/plugins/data/common/search/aggs/agg_config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { identity } from 'lodash';
import { AggConfig, IAggConfig } from './agg_config';
import { AggConfigs, CreateAggConfigParams } from './agg_configs';
import { AggType } from './agg_type';
import { AggTypesRegistryStart } from './types';
import { AggTypesRegistryStart } from './agg_types_registry';
import { mockAggTypesRegistry } from './test_helpers';
import { MetricAggType } from './metrics/metric_agg_type';
import { IndexPattern } from '../../index_patterns/index_patterns/index_pattern';
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/data/common/search/aggs/agg_configs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import { keyBy } from 'lodash';
import { AggConfig } from './agg_config';
import { AggConfigs } from './agg_configs';
import { AggTypesRegistryStart } from './types';
import { AggTypesRegistryStart } from './agg_types_registry';
import { mockAggTypesRegistry } from './test_helpers';
import type { IndexPatternField } from '../../index_patterns';
import { IndexPattern } from '../../index_patterns/index_patterns/index_pattern';
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/data/common/search/aggs/agg_configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { Assign } from '@kbn/utility-types';
import { FetchOptions, ISearchSource } from 'src/plugins/data/public';
import { AggConfig, AggConfigSerialized, IAggConfig } from './agg_config';
import { IAggType } from './agg_type';
import { AggTypesRegistryStart } from './types';
import { AggTypesRegistryStart } from './agg_types_registry';
import { AggGroupNames } from './agg_groups';
import { IndexPattern } from '../../index_patterns/index_patterns/index_pattern';
import { TimeRange } from '../../../common';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/

import { AggTypesRegistry, AggTypesRegistrySetup } from './agg_types_registry';
import { AggTypesRegistryStart } from './types';
import { BucketAggType } from './buckets/bucket_agg_type';
import { MetricAggType } from './metrics/metric_agg_type';

Expand All @@ -28,7 +27,7 @@ const metricType = () => ({ name: 'count', type: 'metrics' } as MetricAggType<an
describe('AggTypesRegistry', () => {
let registry: AggTypesRegistry;
let setup: AggTypesRegistrySetup;
let start: AggTypesRegistryStart;
let start: ReturnType<AggTypesRegistry['start']>;

beforeEach(() => {
registry = new AggTypesRegistry();
Expand Down
12 changes: 12 additions & 0 deletions src/plugins/data/common/search/aggs/agg_types_registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ import { MetricAggType } from './metrics/metric_agg_type';
import { AggTypesDependencies } from './agg_types';

export type AggTypesRegistrySetup = ReturnType<AggTypesRegistry['setup']>;
/**
* AggsCommonStart returns the _unitialized_ agg type providers, but in our
* real start contract we will need to return the initialized versions.
* So we need to provide the correct typings so they can be overwritten
* on client/server.
*
* @internal
*/
export interface AggTypesRegistryStart {
get: (id: string) => BucketAggType<any> | MetricAggType<any>;
getAll: () => { buckets: Array<BucketAggType<any>>; metrics: Array<MetricAggType<any>> };
}

export class AggTypesRegistry {
private readonly bucketAggs = new Map();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@

import { fieldFormatsMock } from '../../../field_formats/mocks';

import { AggTypesRegistry } from '../agg_types_registry';
import { AggTypesRegistry, AggTypesRegistryStart } from '../agg_types_registry';
import { AggTypesDependencies, getAggTypes } from '../agg_types';
import { TimeBucketsConfig } from '../buckets/lib/time_buckets/time_buckets';
import { AggTypesRegistryStart } from '../types';

// Mocked uiSettings shared among aggs unit tests
const mockGetConfig = jest.fn().mockImplementation((key: string) => {
Expand Down
16 changes: 6 additions & 10 deletions src/plugins/data/common/search/aggs/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* under the License.
*/

import { Assign } from '@kbn/utility-types';
import { IndexPattern } from '../../index_patterns/index_patterns/index_pattern';
import {
AggConfigSerialized,
Expand Down Expand Up @@ -54,10 +55,9 @@ import {
AggParamsDateHistogram,
AggTypesRegistry,
AggTypesRegistrySetup,
BucketAggType,
AggTypesRegistryStart,
CreateAggConfigParams,
getCalculateAutoTimeExpression,
MetricAggType,
METRIC_TYPES,
BUCKET_TYPES,
} from './';
Expand Down Expand Up @@ -89,17 +89,13 @@ export interface AggsCommonStart {
}

/**
* AggsCommonStart returns the _unitialized_ agg type providers, but in our
* real start contract we will need to return the initialized versions.
* So we need to provide the correct typings so they can be overwritten
* on client/server.
* AggsStart represents the actual external contract as AggsCommonStart
* is only used internally. The difference is that AggsStart includes the
* typings for the registry with initialized agg types.
*
* @internal
*/
export interface AggTypesRegistryStart {
get: (id: string) => BucketAggType<any> | MetricAggType<any>;
getAll: () => { buckets: Array<BucketAggType<any>>; metrics: Array<MetricAggType<any>> };
}
export type AggsStart = Assign<AggsCommonStart, { types: AggTypesRegistryStart }>;

/** @internal */
export interface BaseAggParams {
Expand Down
5 changes: 2 additions & 3 deletions src/plugins/data/public/search/aggs/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
* under the License.
*/

import { Assign } from '@kbn/utility-types';
import { AggsCommonSetup, AggsCommonStart, AggTypesRegistryStart } from '../../../common';
import { AggsCommonSetup } from '../../../common';

export type AggsSetup = AggsCommonSetup;
export type AggsStart = Assign<AggsCommonStart, { types: AggTypesRegistryStart }>;
export { AggsStart } from '../../../common';
7 changes: 2 additions & 5 deletions src/plugins/data/server/search/aggs/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,11 @@
* under the License.
*/

import { Assign } from '@kbn/utility-types';
import { SavedObjectsClientContract } from 'src/core/server';
import { AggsCommonSetup, AggsCommonStart, AggTypesRegistryStart } from '../../../common';
import { AggsCommonSetup, AggsStart as Start } from '../../../common';

export type AggsSetup = AggsCommonSetup;

export interface AggsStart {
asScopedToClient: (
savedObjectsClient: SavedObjectsClientContract
) => Promise<Assign<AggsCommonStart, { types: AggTypesRegistryStart }>>;
asScopedToClient: (savedObjectsClient: SavedObjectsClientContract) => Promise<Start>;
}

0 comments on commit 0a1bea9

Please sign in to comment.