[ML] Update to using estypes.RuntimeField

This commit is contained in:
Quynh Nguyen 2021-03-26 13:54:16 -05:00
parent b68e7366c3
commit 54b62f827e
5 changed files with 10 additions and 20 deletions

View file

@ -10,4 +10,6 @@ export { ChartData } from './types/field_histograms';
export { ANOMALY_SEVERITY, ANOMALY_THRESHOLD, SEVERITY_COLORS } from './constants/anomalies';
export { getSeverityColor, getSeverityType } from './util/anomaly_utils';
export { composeValidators, patternValidator } from './util/validators';
export { isRuntimeMappings, isRuntimeField } from './util/runtime_field_utils';
export { extractErrorMessage } from './util/errors';
export type { RuntimeMappings } from './types/fields';

View file

@ -28,7 +28,7 @@ export interface Field {
aggregatable?: boolean;
aggIds?: AggId[];
aggs?: Aggregation[];
runtimeField?: RuntimeField;
runtimeField?: estypes.RuntimeField;
}
export interface Aggregation {
@ -108,17 +108,4 @@ export interface AggCardinality {
export type RollupFields = Record<FieldId, [Record<'agg', ES_AGGREGATION>]>;
// Replace this with import once #88995 is merged
const RUNTIME_FIELD_TYPES = ['keyword', 'long', 'double', 'date', 'ip', 'boolean'] as const;
type RuntimeType = typeof RUNTIME_FIELD_TYPES[number];
export interface RuntimeField {
type: RuntimeType;
script?:
| string
| {
source: string;
};
}
export type RuntimeMappings = estypes.RuntimeFields;
export type RuntimeMappings = Record<string, estypes.RuntimeField>;

View file

@ -5,7 +5,7 @@
* 2.0.
*/
import { isRuntimeField, isRuntimeMappings } from './types';
import { isRuntimeField, isRuntimeMappings } from './runtime_field_utils';
describe('Transform: step_define type guards', () => {
it('isRuntimeField()', () => {

View file

@ -5,14 +5,15 @@
* 2.0.
*/
import { estypes } from '@elastic/elasticsearch';
import { isPopulatedObject } from './object_utils';
import {
RUNTIME_FIELD_TYPES,
RuntimeType,
} from '../../../../../src/plugins/data/common/index_patterns';
import type { RuntimeField, RuntimeMappings } from '../types/fields';
import type { RuntimeMappings } from '../types/fields';
export function isRuntimeField(arg: unknown): arg is RuntimeField {
export function isRuntimeField(arg: unknown): arg is estypes.RuntimeField {
return (
isPopulatedObject(arg) &&
((Object.keys(arg).length === 1 && arg.hasOwnProperty('type')) ||

View file

@ -18,6 +18,7 @@ import { i18n } from '@kbn/i18n';
import { CoreSetup } from 'src/core/public';
import type { estypes } from '@elastic/elasticsearch';
import {
IndexPattern,
IFieldType,
@ -49,7 +50,6 @@ import { getNestedProperty } from '../../util/object_utils';
import { mlFieldFormatService } from '../../services/field_format_service';
import { DataGridItem, IndexPagination, RenderCellValue } from './types';
import type { RuntimeField } from '../../../../../../../src/plugins/data/common/index_patterns';
import { RuntimeMappings } from '../../../../common/types/fields';
import { isPopulatedObject } from '../../../../common/util/object_utils';
@ -178,7 +178,7 @@ export const getDataGridSchemasFromFieldTypes = (fieldTypes: FieldTypes, results
export const NON_AGGREGATABLE = 'non-aggregatable';
export const getDataGridSchemaFromESFieldType = (
fieldType: ES_FIELD_TYPES | undefined | RuntimeField['type']
fieldType: ES_FIELD_TYPES | undefined | estypes.RuntimeField['type']
): string | undefined => {
// Built-in values are ['boolean', 'currency', 'datetime', 'numeric', 'json']
// To fall back to the default string schema it needs to be undefined.