Skip to content

Commit

Permalink
[ML] Fix types.
Browse files Browse the repository at this point in the history
  • Loading branch information
walterra committed Sep 10, 2020
1 parent 7725de8 commit 7329dea
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 18 deletions.
22 changes: 15 additions & 7 deletions x-pack/plugins/ml/common/types/es_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,22 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { SearchResponse } from 'elasticsearch';
import { SearchResponse, ShardsResponse } from 'elasticsearch';

// The types specified in `@types/elasticsearch` are out of date and still have `total: number`.
export interface SearchResponse7 extends SearchResponse<any> {
hits: SearchResponse<any>['hits'] & {
total: {
value: number;
relation: string;
};
interface SearchResponse7Hits<T> {
hits: SearchResponse<T>['hits']['hits'];
max_score: number;
total: {
value: number;
relation: string;
};
}
export interface SearchResponse7<T = any> {
took: number;
timed_out: boolean;
_scroll_id?: string;
_shards: ShardsResponse;
hits: SearchResponse7Hits<T>;
aggregations?: any;
}
3 changes: 1 addition & 2 deletions x-pack/plugins/transform/common/api_schemas/type_guards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ export const isEsIndices = (arg: any): arg is EsIndex[] => {
return Array.isArray(arg);
};

type EsSearchResponse = SearchResponse7;
export const isEsSearchResponse = (arg: any): arg is EsSearchResponse => {
export const isEsSearchResponse = (arg: any): arg is SearchResponse7 => {
return isBasicObject(arg) && {}.hasOwnProperty.call(arg, 'hits');
};

Expand Down
7 changes: 7 additions & 0 deletions x-pack/plugins/transform/common/shared_imports.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

export type { SearchResponse7 } from '../../ml/common';
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export {
DataGrid,
EsSorting,
RenderCellValue,
SearchResponse7,
UseDataGridReturnType,
UseIndexDataReturnType,
INDEX_STATUS,
Expand Down
18 changes: 15 additions & 3 deletions x-pack/plugins/transform/public/app/hooks/__mocks__/use_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@ import type {
PostTransformsUpdateResponseSchema,
} from '../../../../common/api_schemas/update_transforms';

import type { SearchResponse7 } from '../../../../common/shared_imports';
import { EsIndex } from '../../../../common/types/es_index';

import type { SearchResponse7 } from '../../../shared_imports';

import type { SavedSearchQuery } from '../use_search_items';

// Default sampler shard size used for field histograms
Expand Down Expand Up @@ -135,8 +134,21 @@ const apiFactory = () => ({
return Promise.resolve([]);
},
async esSearch(payload: any): Promise<SearchResponse7 | HttpFetchError> {
return Promise.resolve([]);
return Promise.resolve({
hits: {
hits: [],
total: {
value: 0,
relation: 'the-relation',
},
max_score: 0,
},
timed_out: false,
took: 10,
_shards: { total: 1, successful: 1, failed: 0, skipped: 0 },
});
},

async getEsIndices(): Promise<EsIndex[] | HttpFetchError> {
return Promise.resolve([]);
},
Expand Down
3 changes: 1 addition & 2 deletions x-pack/plugins/transform/public/app/hooks/use_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ import type { GetTransformsStatsResponseSchema } from '../../../common/api_schem
import { TransformId } from '../../../common/types/transform';
import { API_BASE_PATH } from '../../../common/constants';
import { EsIndex } from '../../../common/types/es_index';

import type { SearchResponse7 } from '../../shared_imports';
import type { SearchResponse7 } from '../../../common/shared_imports';

import { useAppDependencies } from '../app_dependencies';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export const FilterTermForm: FilterAggConfigTerm['aggTypeConfig']['FilterAggForm
defaultMessage: 'Unable to fetch suggestions',
})
);
return;
}

setOptions(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import {
} from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { TermClause, FieldClause, Value } from './common';
import { TRANSFORM_STATE } from '../../../../../../common';
import { TRANSFORM_MODE, TransformListRow } from '../../../../common';
import { TRANSFORM_MODE, TRANSFORM_STATE } from '../../../../../../common/constants';
import { TransformListRow } from '../../../../common';
import { getTaskStateBadge } from './use_columns';

const filters: SearchFilterConfig[] = [
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/transform/public/shared_imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export {
DataGrid,
EsSorting,
RenderCellValue,
SearchResponse7,
UseDataGridReturnType,
UseIndexDataReturnType,
INDEX_STATUS,
Expand Down

0 comments on commit 7329dea

Please sign in to comment.