From b02e2d9de4c6b0932e5f5426e5ac1c878387dfa9 Mon Sep 17 00:00:00 2001 From: Matthew Kime Date: Thu, 25 Jun 2020 09:21:41 -0500 Subject: [PATCH] Index pattern serialize and de-serialize (#68844) * serialize and deserialize index patterns --- ...a-plugin-plugins-data-public.ifieldtype.md | 1 + ...n-plugins-data-public.ifieldtype.tospec.md | 11 + ...plugins-data-public.indexpattern.fields.md | 4 +- ...s-data-public.indexpattern.initfromspec.md | 22 + ...plugin-plugins-data-public.indexpattern.md | 5 +- ...lugins-data-public.indexpattern.tospec.md} | 10 +- ...-public.indexpatternfield._constructor_.md | 4 +- ....indexpatternfield.conflictdescriptions.md | 2 +- ...n-plugins-data-public.indexpatternfield.md | 3 +- ...ns-data-public.indexpatternfield.tospec.md | 11 + ...a-plugin-plugins-data-server.ifieldtype.md | 1 + ...n-plugins-data-server.ifieldtype.tospec.md | 11 + .../stubbed_saved_object_index_pattern.js | 1 + .../fields/__snapshots__/field.test.ts.snap | 40 ++ .../index_patterns/fields/field.test.ts | 24 +- .../common/index_patterns/fields/field.ts | 37 +- .../index_patterns/fields/field_list.ts | 8 +- .../common/index_patterns/fields/types.ts | 6 +- .../__snapshots__/index_pattern.test.ts.snap | 503 ++++++++++++++++++ .../index_patterns/index_patterns/index.ts | 1 - .../index_patterns/index_pattern.test.ts | 27 + .../index_patterns/index_pattern.ts | 64 ++- .../index_patterns/index_patterns.ts | 23 +- .../index_patterns/index_patterns/types.ts | 35 -- .../data/common/index_patterns/types.ts | 64 +++ src/plugins/data/public/index.ts | 4 +- .../data/public/index_patterns/index.ts | 9 +- src/plugins/data/public/public.api.md | 27 +- src/plugins/data/server/server.api.md | 4 + .../sidebar/discover_field.test.tsx | 2 + 30 files changed, 868 insertions(+), 96 deletions(-) create mode 100644 docs/development/plugins/data/public/kibana-plugin-plugins-data-public.ifieldtype.tospec.md create mode 100644 docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.initfromspec.md rename docs/development/plugins/data/public/{kibana-plugin-plugins-data-public.indexpattern.type.md => kibana-plugin-plugins-data-public.indexpattern.tospec.md} (53%) create mode 100644 docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.tospec.md create mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.ifieldtype.tospec.md create mode 100644 src/plugins/data/common/index_patterns/index_patterns/__snapshots__/index_pattern.test.ts.snap delete mode 100644 src/plugins/data/common/index_patterns/index_patterns/types.ts diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.ifieldtype.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.ifieldtype.md index be6af335f20c..6f42fb32fdb7 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.ifieldtype.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.ifieldtype.md @@ -28,6 +28,7 @@ export interface IFieldType | [searchable](./kibana-plugin-plugins-data-public.ifieldtype.searchable.md) | boolean | | | [sortable](./kibana-plugin-plugins-data-public.ifieldtype.sortable.md) | boolean | | | [subType](./kibana-plugin-plugins-data-public.ifieldtype.subtype.md) | IFieldSubType | | +| [toSpec](./kibana-plugin-plugins-data-public.ifieldtype.tospec.md) | () => FieldSpec | | | [type](./kibana-plugin-plugins-data-public.ifieldtype.type.md) | string | | | [visualizable](./kibana-plugin-plugins-data-public.ifieldtype.visualizable.md) | boolean | | diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.ifieldtype.tospec.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.ifieldtype.tospec.md new file mode 100644 index 000000000000..1fb4084c25d3 --- /dev/null +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.ifieldtype.tospec.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [IFieldType](./kibana-plugin-plugins-data-public.ifieldtype.md) > [toSpec](./kibana-plugin-plugins-data-public.ifieldtype.tospec.md) + +## IFieldType.toSpec property + +Signature: + +```typescript +toSpec?: () => FieldSpec; +``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.fields.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.fields.md index 9a93148e4a46..d4dca48c7cd7 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.fields.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.fields.md @@ -7,5 +7,7 @@ Signature: ```typescript -fields: IIndexPatternFieldList; +fields: IIndexPatternFieldList & { + toSpec: () => FieldSpec[]; + }; ``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.initfromspec.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.initfromspec.md new file mode 100644 index 000000000000..764dd1163822 --- /dev/null +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.initfromspec.md @@ -0,0 +1,22 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [IndexPattern](./kibana-plugin-plugins-data-public.indexpattern.md) > [initFromSpec](./kibana-plugin-plugins-data-public.indexpattern.initfromspec.md) + +## IndexPattern.initFromSpec() method + +Signature: + +```typescript +initFromSpec(spec: IndexPatternSpec): this; +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| spec | IndexPatternSpec | | + +Returns: + +`this` + diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.md index 8ffa7b6b36f5..d39b384c538f 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.md @@ -21,7 +21,7 @@ export declare class IndexPattern implements IIndexPattern | Property | Modifiers | Type | Description | | --- | --- | --- | --- | | [fieldFormatMap](./kibana-plugin-plugins-data-public.indexpattern.fieldformatmap.md) | | any | | -| [fields](./kibana-plugin-plugins-data-public.indexpattern.fields.md) | | IIndexPatternFieldList | | +| [fields](./kibana-plugin-plugins-data-public.indexpattern.fields.md) | | IIndexPatternFieldList & {
toSpec: () => FieldSpec[];
} | | | [fieldsFetcher](./kibana-plugin-plugins-data-public.indexpattern.fieldsfetcher.md) | | any | | | [flattenHit](./kibana-plugin-plugins-data-public.indexpattern.flattenhit.md) | | any | | | [formatField](./kibana-plugin-plugins-data-public.indexpattern.formatfield.md) | | any | | @@ -30,7 +30,6 @@ export declare class IndexPattern implements IIndexPattern | [metaFields](./kibana-plugin-plugins-data-public.indexpattern.metafields.md) | | string[] | | | [timeFieldName](./kibana-plugin-plugins-data-public.indexpattern.timefieldname.md) | | string | undefined | | | [title](./kibana-plugin-plugins-data-public.indexpattern.title.md) | | string | | -| [type](./kibana-plugin-plugins-data-public.indexpattern.type.md) | | string | | | [typeMeta](./kibana-plugin-plugins-data-public.indexpattern.typemeta.md) | | TypeMeta | | ## Methods @@ -49,6 +48,7 @@ export declare class IndexPattern implements IIndexPattern | [getSourceFiltering()](./kibana-plugin-plugins-data-public.indexpattern.getsourcefiltering.md) | | | | [getTimeField()](./kibana-plugin-plugins-data-public.indexpattern.gettimefield.md) | | | | [init(forceFieldRefresh)](./kibana-plugin-plugins-data-public.indexpattern.init.md) | | | +| [initFromSpec(spec)](./kibana-plugin-plugins-data-public.indexpattern.initfromspec.md) | | | | [isTimeBased()](./kibana-plugin-plugins-data-public.indexpattern.istimebased.md) | | | | [isTimeBasedWildcard()](./kibana-plugin-plugins-data-public.indexpattern.istimebasedwildcard.md) | | | | [isTimeNanosBased()](./kibana-plugin-plugins-data-public.indexpattern.istimenanosbased.md) | | | @@ -59,5 +59,6 @@ export declare class IndexPattern implements IIndexPattern | [removeScriptedField(field)](./kibana-plugin-plugins-data-public.indexpattern.removescriptedfield.md) | | | | [save(saveAttempts)](./kibana-plugin-plugins-data-public.indexpattern.save.md) | | | | [toJSON()](./kibana-plugin-plugins-data-public.indexpattern.tojson.md) | | | +| [toSpec()](./kibana-plugin-plugins-data-public.indexpattern.tospec.md) | | | | [toString()](./kibana-plugin-plugins-data-public.indexpattern.tostring.md) | | | diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.type.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.tospec.md similarity index 53% rename from docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.type.md rename to docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.tospec.md index 58047d9e27ac..d1a78eea660c 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.type.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.tospec.md @@ -1,11 +1,15 @@ -[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [IndexPattern](./kibana-plugin-plugins-data-public.indexpattern.md) > [type](./kibana-plugin-plugins-data-public.indexpattern.type.md) +[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [IndexPattern](./kibana-plugin-plugins-data-public.indexpattern.md) > [toSpec](./kibana-plugin-plugins-data-public.indexpattern.tospec.md) -## IndexPattern.type property +## IndexPattern.toSpec() method Signature: ```typescript -type?: string; +toSpec(): IndexPatternSpec; ``` +Returns: + +`IndexPatternSpec` + diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield._constructor_.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield._constructor_.md index e1e0d58ce38c..7a195702b6f1 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield._constructor_.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield._constructor_.md @@ -9,7 +9,7 @@ Constructs a new instance of the `Field` class Signature: ```typescript -constructor(indexPattern: IIndexPattern, spec: FieldSpec | Field, shortDotsEnable: boolean, { fieldFormats, onNotification }: FieldDependencies); +constructor(indexPattern: IIndexPattern, spec: FieldSpecExportFmt | FieldSpec | Field, shortDotsEnable: boolean, { fieldFormats, onNotification }: FieldDependencies); ``` ## Parameters @@ -17,7 +17,7 @@ constructor(indexPattern: IIndexPattern, spec: FieldSpec | Field, shortDotsEnabl | Parameter | Type | Description | | --- | --- | --- | | indexPattern | IIndexPattern | | -| spec | FieldSpec | Field | | +| spec | FieldSpecExportFmt | FieldSpec | Field | | | shortDotsEnable | boolean | | | { fieldFormats, onNotification } | FieldDependencies | | diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.conflictdescriptions.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.conflictdescriptions.md index ca2552aeb1b4..ec19a4854bf0 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.conflictdescriptions.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.conflictdescriptions.md @@ -7,5 +7,5 @@ Signature: ```typescript -conflictDescriptions?: Record; +conflictDescriptions?: FieldSpecConflictDescriptions; ``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.md index 8fa1ee0d72e5..d82999e7a96a 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.md @@ -22,7 +22,7 @@ export declare class Field implements IFieldType | --- | --- | --- | --- | | [$$spec](./kibana-plugin-plugins-data-public.indexpatternfield.__spec.md) | | FieldSpec | | | [aggregatable](./kibana-plugin-plugins-data-public.indexpatternfield.aggregatable.md) | | boolean | | -| [conflictDescriptions](./kibana-plugin-plugins-data-public.indexpatternfield.conflictdescriptions.md) | | Record<string, string[]> | | +| [conflictDescriptions](./kibana-plugin-plugins-data-public.indexpatternfield.conflictdescriptions.md) | | FieldSpecConflictDescriptions | | | [count](./kibana-plugin-plugins-data-public.indexpatternfield.count.md) | | number | | | [displayName](./kibana-plugin-plugins-data-public.indexpatternfield.displayname.md) | | string | | | [esTypes](./kibana-plugin-plugins-data-public.indexpatternfield.estypes.md) | | string[] | | @@ -37,6 +37,7 @@ export declare class Field implements IFieldType | [searchable](./kibana-plugin-plugins-data-public.indexpatternfield.searchable.md) | | boolean | | | [sortable](./kibana-plugin-plugins-data-public.indexpatternfield.sortable.md) | | boolean | | | [subType](./kibana-plugin-plugins-data-public.indexpatternfield.subtype.md) | | IFieldSubType | | +| [toSpec](./kibana-plugin-plugins-data-public.indexpatternfield.tospec.md) | | () => FieldSpecExportFmt | | | [type](./kibana-plugin-plugins-data-public.indexpatternfield.type.md) | | string | | | [visualizable](./kibana-plugin-plugins-data-public.indexpatternfield.visualizable.md) | | boolean | | diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.tospec.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.tospec.md new file mode 100644 index 000000000000..35714faa03bc --- /dev/null +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.tospec.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [IndexPatternField](./kibana-plugin-plugins-data-public.indexpatternfield.md) > [toSpec](./kibana-plugin-plugins-data-public.indexpatternfield.tospec.md) + +## IndexPatternField.toSpec property + +Signature: + +```typescript +toSpec: () => FieldSpecExportFmt; +``` diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.ifieldtype.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.ifieldtype.md index 5375cf2a2ef4..77a2954428f8 100644 --- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.ifieldtype.md +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.ifieldtype.md @@ -28,6 +28,7 @@ export interface IFieldType | [searchable](./kibana-plugin-plugins-data-server.ifieldtype.searchable.md) | boolean | | | [sortable](./kibana-plugin-plugins-data-server.ifieldtype.sortable.md) | boolean | | | [subType](./kibana-plugin-plugins-data-server.ifieldtype.subtype.md) | IFieldSubType | | +| [toSpec](./kibana-plugin-plugins-data-server.ifieldtype.tospec.md) | () => FieldSpec | | | [type](./kibana-plugin-plugins-data-server.ifieldtype.type.md) | string | | | [visualizable](./kibana-plugin-plugins-data-server.ifieldtype.visualizable.md) | boolean | | diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.ifieldtype.tospec.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.ifieldtype.tospec.md new file mode 100644 index 000000000000..d1863bebce4f --- /dev/null +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.ifieldtype.tospec.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [IFieldType](./kibana-plugin-plugins-data-server.ifieldtype.md) > [toSpec](./kibana-plugin-plugins-data-server.ifieldtype.tospec.md) + +## IFieldType.toSpec property + +Signature: + +```typescript +toSpec?: () => FieldSpec; +``` diff --git a/src/fixtures/stubbed_saved_object_index_pattern.js b/src/fixtures/stubbed_saved_object_index_pattern.js index 15e47b40eb20..8e0e230ef33d 100644 --- a/src/fixtures/stubbed_saved_object_index_pattern.js +++ b/src/fixtures/stubbed_saved_object_index_pattern.js @@ -27,6 +27,7 @@ export function stubbedSavedObjectIndexPattern(id) { id, type: 'index-pattern', attributes: { + timeFieldName: 'timestamp', customFormats: '{}', fields: mockLogstashFields, }, diff --git a/src/plugins/data/common/index_patterns/fields/__snapshots__/field.test.ts.snap b/src/plugins/data/common/index_patterns/fields/__snapshots__/field.test.ts.snap index 4593349a408a..e61593f6bfb2 100644 --- a/src/plugins/data/common/index_patterns/fields/__snapshots__/field.test.ts.snap +++ b/src/plugins/data/common/index_patterns/fields/__snapshots__/field.test.ts.snap @@ -33,3 +33,43 @@ Object { "type": "type", } `; + +exports[`Field spec snapshot 1`] = ` +Object { + "aggregatable": true, + "conflictDescriptions": Object { + "a": Array [ + "b", + "c", + ], + "d": Array [ + "e", + ], + }, + "count": 1, + "esTypes": Array [ + "type", + ], + "format": Object { + "id": "number", + "params": Object { + "pattern": "$0,0.[00]", + }, + }, + "lang": "lang", + "name": "name", + "readFromDocValues": false, + "script": "script", + "scripted": true, + "searchable": true, + "subType": Object { + "multi": Object { + "parent": "parent", + }, + "nested": Object { + "path": "path", + }, + }, + "type": "type", +} +`; diff --git a/src/plugins/data/common/index_patterns/fields/field.test.ts b/src/plugins/data/common/index_patterns/fields/field.test.ts index 711c176fed9c..910f22088f43 100644 --- a/src/plugins/data/common/index_patterns/fields/field.test.ts +++ b/src/plugins/data/common/index_patterns/fields/field.test.ts @@ -20,7 +20,7 @@ import { Field } from './field'; import { IndexPattern } from '../index_patterns'; import { FieldFormatsStartCommon } from '../..'; -import { KBN_FIELD_TYPES } from '../../../common'; +import { KBN_FIELD_TYPES, FieldSpec, FieldSpecExportFmt } from '../../../common'; describe('Field', function () { function flatten(obj: Record) { @@ -59,8 +59,9 @@ describe('Field', function () { fieldFormatMap: { name: {}, _source: {}, _score: {}, _id: {} }, } as unknown) as IndexPattern, format: { name: 'formatName' }, - $$spec: {}, + $$spec: ({} as unknown) as FieldSpec, conflictDescriptions: { a: ['b', 'c'], d: ['e'] }, + toSpec: () => (({} as unknown) as FieldSpecExportFmt), } as Field; it('the correct properties are writable', () => { @@ -145,7 +146,7 @@ describe('Field', function () { }).toThrow(); expect(() => { - field.$$spec = { a: 'b' }; + field.$$spec = ({ a: 'b' } as unknown) as FieldSpec; }).toThrow(); }); @@ -219,4 +220,21 @@ describe('Field', function () { }); expect(flatten(field)).toMatchSnapshot(); }); + + it('spec snapshot', () => { + const field = new Field( + { + fieldFormatMap: { + name: { toJSON: () => ({ id: 'number', params: { pattern: '$0,0.[00]' } }) }, + }, + } as IndexPattern, + fieldValues, + false, + { + fieldFormats: {} as FieldFormatsStartCommon, + onNotification: () => {}, + } + ); + expect(field.toSpec()).toMatchSnapshot(); + }); }); diff --git a/src/plugins/data/common/index_patterns/fields/field.ts b/src/plugins/data/common/index_patterns/fields/field.ts index c53e3f2b1f62..81c7aff8a0fa 100644 --- a/src/plugins/data/common/index_patterns/fields/field.ts +++ b/src/plugins/data/common/index_patterns/fields/field.ts @@ -28,11 +28,14 @@ import { FieldFormat, shortenDottedString, } from '../../../common'; -import { OnNotification } from '../types'; +import { + OnNotification, + FieldSpec, + FieldSpecConflictDescriptions, + FieldSpecExportFmt, +} from '../types'; import { FieldFormatsStartCommon } from '../../field_formats'; -export type FieldSpec = Record; - interface FieldDependencies { fieldFormats: FieldFormatsStartCommon; onNotification: OnNotification; @@ -59,11 +62,11 @@ export class Field implements IFieldType { readFromDocValues?: boolean; format: any; $$spec: FieldSpec; - conflictDescriptions?: Record; + conflictDescriptions?: FieldSpecConflictDescriptions; constructor( indexPattern: IIndexPattern, - spec: FieldSpec | Field, + spec: FieldSpecExportFmt | FieldSpec | Field, shortDotsEnable: boolean, { fieldFormats, onNotification }: FieldDependencies ) { @@ -95,7 +98,7 @@ export class Field implements IFieldType { if (!type) type = getKbnFieldType('unknown'); - let format = spec.format; + let format: any = spec.format; if (!FieldFormat.isInstanceOfFieldFormat(format)) { format = @@ -148,6 +151,26 @@ export class Field implements IFieldType { // multi info obj.fact('subType'); - return obj.create(); + const newObj = obj.create(); + newObj.toSpec = function () { + return { + count: this.count, + script: this.script, + lang: this.lang, + conflictDescriptions: this.conflictDescriptions, + name: this.name, + type: this.type, + esTypes: this.esTypes, + scripted: this.scripted, + searchable: this.searchable, + aggregatable: this.aggregatable, + readFromDocValues: this.readFromDocValues, + subType: this.subType, + format: this.indexPattern?.fieldFormatMap[this.name]?.toJSON() || undefined, + }; + }; + return newObj; } + // only providing type info as constructor returns new object instead of `this` + toSpec = () => (({} as unknown) as FieldSpecExportFmt); } diff --git a/src/plugins/data/common/index_patterns/fields/field_list.ts b/src/plugins/data/common/index_patterns/fields/field_list.ts index 173a629863a7..c1ca5341328c 100644 --- a/src/plugins/data/common/index_patterns/fields/field_list.ts +++ b/src/plugins/data/common/index_patterns/fields/field_list.ts @@ -20,8 +20,8 @@ import { findIndex } from 'lodash'; import { IIndexPattern } from '../../types'; import { IFieldType } from '../../../common'; -import { Field, FieldSpec } from './field'; -import { OnNotification } from '../types'; +import { Field } from './field'; +import { OnNotification, FieldSpec } from '../types'; import { FieldFormatsStartCommon } from '../../field_formats'; type FieldMap = Map; @@ -102,6 +102,10 @@ export const getIndexPatternFieldListCreator = ({ this.removeByGroup(newField); this.setByGroup(newField); }; + + toSpec = () => { + return [...this.map((field) => field.toSpec())]; + }; } return new FieldList(...fieldListParams); diff --git a/src/plugins/data/common/index_patterns/fields/types.ts b/src/plugins/data/common/index_patterns/fields/types.ts index c336472a1e7d..558b5b57dce4 100644 --- a/src/plugins/data/common/index_patterns/fields/types.ts +++ b/src/plugins/data/common/index_patterns/fields/types.ts @@ -17,10 +17,7 @@ * under the License. */ -export interface IFieldSubType { - multi?: { parent: string }; - nested?: { path: string }; -} +import { FieldSpec, IFieldSubType } from '../types'; export interface IFieldType { name: string; @@ -41,4 +38,5 @@ export interface IFieldType { subType?: IFieldSubType; displayName?: string; format?: any; + toSpec?: () => FieldSpec; } diff --git a/src/plugins/data/common/index_patterns/index_patterns/__snapshots__/index_pattern.test.ts.snap b/src/plugins/data/common/index_patterns/index_patterns/__snapshots__/index_pattern.test.ts.snap new file mode 100644 index 000000000000..047ac836a87d --- /dev/null +++ b/src/plugins/data/common/index_patterns/index_patterns/__snapshots__/index_pattern.test.ts.snap @@ -0,0 +1,503 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`IndexPattern toSpec should match snapshot 1`] = ` +Object { + "fields": Array [ + Object { + "aggregatable": true, + "conflictDescriptions": undefined, + "count": 10, + "esTypes": Array [ + "long", + ], + "format": Object { + "id": "number", + "params": Object { + "pattern": "$0,0.[00]", + }, + }, + "lang": undefined, + "name": "bytes", + "readFromDocValues": true, + "script": undefined, + "scripted": false, + "searchable": true, + "subType": undefined, + "type": "number", + }, + Object { + "aggregatable": true, + "conflictDescriptions": undefined, + "count": 20, + "esTypes": Array [ + "boolean", + ], + "format": undefined, + "lang": undefined, + "name": "ssl", + "readFromDocValues": true, + "script": undefined, + "scripted": false, + "searchable": true, + "subType": undefined, + "type": "boolean", + }, + Object { + "aggregatable": true, + "conflictDescriptions": undefined, + "count": 30, + "esTypes": Array [ + "date", + ], + "format": undefined, + "lang": undefined, + "name": "@timestamp", + "readFromDocValues": true, + "script": undefined, + "scripted": false, + "searchable": true, + "subType": undefined, + "type": "date", + }, + Object { + "aggregatable": true, + "conflictDescriptions": undefined, + "count": 30, + "esTypes": Array [ + "date", + ], + "format": undefined, + "lang": undefined, + "name": "time", + "readFromDocValues": true, + "script": undefined, + "scripted": false, + "searchable": true, + "subType": undefined, + "type": "date", + }, + Object { + "aggregatable": true, + "conflictDescriptions": undefined, + "count": 0, + "esTypes": Array [ + "keyword", + ], + "format": undefined, + "lang": undefined, + "name": "@tags", + "readFromDocValues": true, + "script": undefined, + "scripted": false, + "searchable": true, + "subType": undefined, + "type": "string", + }, + Object { + "aggregatable": true, + "conflictDescriptions": undefined, + "count": 0, + "esTypes": Array [ + "date", + ], + "format": undefined, + "lang": undefined, + "name": "utc_time", + "readFromDocValues": true, + "script": undefined, + "scripted": false, + "searchable": true, + "subType": undefined, + "type": "date", + }, + Object { + "aggregatable": true, + "conflictDescriptions": undefined, + "count": 0, + "esTypes": Array [ + "integer", + ], + "format": undefined, + "lang": undefined, + "name": "phpmemory", + "readFromDocValues": true, + "script": undefined, + "scripted": false, + "searchable": true, + "subType": undefined, + "type": "number", + }, + Object { + "aggregatable": true, + "conflictDescriptions": undefined, + "count": 0, + "esTypes": Array [ + "ip", + ], + "format": undefined, + "lang": undefined, + "name": "ip", + "readFromDocValues": true, + "script": undefined, + "scripted": false, + "searchable": true, + "subType": undefined, + "type": "ip", + }, + Object { + "aggregatable": true, + "conflictDescriptions": undefined, + "count": 0, + "esTypes": Array [ + "attachment", + ], + "format": undefined, + "lang": undefined, + "name": "request_body", + "readFromDocValues": true, + "script": undefined, + "scripted": false, + "searchable": true, + "subType": undefined, + "type": "attachment", + }, + Object { + "aggregatable": true, + "conflictDescriptions": undefined, + "count": 0, + "esTypes": Array [ + "geo_point", + ], + "format": undefined, + "lang": undefined, + "name": "point", + "readFromDocValues": true, + "script": undefined, + "scripted": false, + "searchable": true, + "subType": undefined, + "type": "geo_point", + }, + Object { + "aggregatable": true, + "conflictDescriptions": undefined, + "count": 0, + "esTypes": Array [ + "geo_shape", + ], + "format": undefined, + "lang": undefined, + "name": "area", + "readFromDocValues": false, + "script": undefined, + "scripted": false, + "searchable": true, + "subType": undefined, + "type": "geo_shape", + }, + Object { + "aggregatable": false, + "conflictDescriptions": undefined, + "count": 0, + "esTypes": Array [ + "murmur3", + ], + "format": undefined, + "lang": undefined, + "name": "hashed", + "readFromDocValues": false, + "script": undefined, + "scripted": false, + "searchable": true, + "subType": undefined, + "type": "murmur3", + }, + Object { + "aggregatable": true, + "conflictDescriptions": undefined, + "count": 0, + "esTypes": Array [ + "geo_point", + ], + "format": undefined, + "lang": undefined, + "name": "geo.coordinates", + "readFromDocValues": true, + "script": undefined, + "scripted": false, + "searchable": true, + "subType": undefined, + "type": "geo_point", + }, + Object { + "aggregatable": true, + "conflictDescriptions": undefined, + "count": 0, + "esTypes": Array [ + "text", + ], + "format": undefined, + "lang": undefined, + "name": "extension", + "readFromDocValues": false, + "script": undefined, + "scripted": false, + "searchable": true, + "subType": undefined, + "type": "string", + }, + Object { + "aggregatable": true, + "conflictDescriptions": undefined, + "count": 0, + "esTypes": Array [ + "keyword", + ], + "format": undefined, + "lang": undefined, + "name": "extension.keyword", + "readFromDocValues": true, + "script": undefined, + "scripted": false, + "searchable": true, + "subType": Object { + "multi": Object { + "parent": "extension", + }, + }, + "type": "string", + }, + Object { + "aggregatable": true, + "conflictDescriptions": undefined, + "count": 0, + "esTypes": Array [ + "text", + ], + "format": undefined, + "lang": undefined, + "name": "machine.os", + "readFromDocValues": false, + "script": undefined, + "scripted": false, + "searchable": true, + "subType": undefined, + "type": "string", + }, + Object { + "aggregatable": true, + "conflictDescriptions": undefined, + "count": 0, + "esTypes": Array [ + "keyword", + ], + "format": undefined, + "lang": undefined, + "name": "machine.os.raw", + "readFromDocValues": true, + "script": undefined, + "scripted": false, + "searchable": true, + "subType": Object { + "multi": Object { + "parent": "machine.os", + }, + }, + "type": "string", + }, + Object { + "aggregatable": true, + "conflictDescriptions": undefined, + "count": 0, + "esTypes": Array [ + "keyword", + ], + "format": undefined, + "lang": undefined, + "name": "geo.src", + "readFromDocValues": true, + "script": undefined, + "scripted": false, + "searchable": true, + "subType": undefined, + "type": "string", + }, + Object { + "aggregatable": true, + "conflictDescriptions": undefined, + "count": 0, + "esTypes": Array [ + "_id", + ], + "format": undefined, + "lang": undefined, + "name": "_id", + "readFromDocValues": false, + "script": undefined, + "scripted": false, + "searchable": true, + "subType": undefined, + "type": "string", + }, + Object { + "aggregatable": true, + "conflictDescriptions": undefined, + "count": 0, + "esTypes": Array [ + "_type", + ], + "format": undefined, + "lang": undefined, + "name": "_type", + "readFromDocValues": false, + "script": undefined, + "scripted": false, + "searchable": true, + "subType": undefined, + "type": "string", + }, + Object { + "aggregatable": true, + "conflictDescriptions": undefined, + "count": 0, + "esTypes": Array [ + "_source", + ], + "format": undefined, + "lang": undefined, + "name": "_source", + "readFromDocValues": false, + "script": undefined, + "scripted": false, + "searchable": true, + "subType": undefined, + "type": "_source", + }, + Object { + "aggregatable": true, + "conflictDescriptions": undefined, + "count": 0, + "esTypes": Array [ + "text", + ], + "format": undefined, + "lang": undefined, + "name": "non-filterable", + "readFromDocValues": false, + "script": undefined, + "scripted": false, + "searchable": false, + "subType": undefined, + "type": "string", + }, + Object { + "aggregatable": false, + "conflictDescriptions": undefined, + "count": 0, + "esTypes": Array [ + "text", + ], + "format": undefined, + "lang": undefined, + "name": "non-sortable", + "readFromDocValues": false, + "script": undefined, + "scripted": false, + "searchable": false, + "subType": undefined, + "type": "string", + }, + Object { + "aggregatable": true, + "conflictDescriptions": undefined, + "count": 0, + "esTypes": Array [ + "conflict", + ], + "format": undefined, + "lang": undefined, + "name": "custom_user_field", + "readFromDocValues": true, + "script": undefined, + "scripted": false, + "searchable": true, + "subType": undefined, + "type": "conflict", + }, + Object { + "aggregatable": true, + "conflictDescriptions": undefined, + "count": 0, + "esTypes": Array [ + "text", + ], + "format": undefined, + "lang": "expression", + "name": "script string", + "readFromDocValues": false, + "script": "'i am a string'", + "scripted": true, + "searchable": true, + "subType": undefined, + "type": "string", + }, + Object { + "aggregatable": true, + "conflictDescriptions": undefined, + "count": 0, + "esTypes": Array [ + "long", + ], + "format": undefined, + "lang": "expression", + "name": "script number", + "readFromDocValues": false, + "script": "1234", + "scripted": true, + "searchable": true, + "subType": undefined, + "type": "number", + }, + Object { + "aggregatable": true, + "conflictDescriptions": undefined, + "count": 0, + "esTypes": Array [ + "date", + ], + "format": undefined, + "lang": "painless", + "name": "script date", + "readFromDocValues": false, + "script": "1234", + "scripted": true, + "searchable": true, + "subType": undefined, + "type": "date", + }, + Object { + "aggregatable": true, + "conflictDescriptions": undefined, + "count": 0, + "esTypes": Array [ + "murmur3", + ], + "format": undefined, + "lang": "expression", + "name": "script murmur3", + "readFromDocValues": false, + "script": "1234", + "scripted": true, + "searchable": true, + "subType": undefined, + "type": "murmur3", + }, + ], + "id": "test-pattern", + "sourceFilters": undefined, + "timeFieldName": "timestamp", + "title": "test-pattern", + "typeMeta": undefined, + "version": 2, +} +`; diff --git a/src/plugins/data/common/index_patterns/index_patterns/index.ts b/src/plugins/data/common/index_patterns/index_patterns/index.ts index 5fae08f3bb77..77527857ed0c 100644 --- a/src/plugins/data/common/index_patterns/index_patterns/index.ts +++ b/src/plugins/data/common/index_patterns/index_patterns/index.ts @@ -18,7 +18,6 @@ */ export * from './index_patterns_api_client'; -export * from './types'; export * from './_pattern_cache'; export * from './flatten_hit'; export * from './format_hit'; diff --git a/src/plugins/data/common/index_patterns/index_patterns/index_pattern.test.ts b/src/plugins/data/common/index_patterns/index_patterns/index_pattern.test.ts index cea476781ad3..ba8e4f6fb369 100644 --- a/src/plugins/data/common/index_patterns/index_patterns/index_pattern.test.ts +++ b/src/plugins/data/common/index_patterns/index_patterns/index_pattern.test.ts @@ -30,6 +30,10 @@ import { Field } from '../fields'; import { fieldFormatsMock } from '../../field_formats/mocks'; +class MockFieldFormatter {} + +fieldFormatsMock.getType = jest.fn().mockImplementation(() => MockFieldFormatter); + jest.mock('../../field_mapping', () => { const originalModule = jest.requireActual('../../field_mapping'); @@ -303,6 +307,29 @@ describe('IndexPattern', () => { }); }); + describe('toSpec', () => { + test('should match snapshot', () => { + indexPattern.fieldFormatMap.bytes = { + toJSON: () => ({ id: 'number', params: { pattern: '$0,0.[00]' } }), + }; + expect(indexPattern.toSpec()).toMatchSnapshot(); + }); + + test('can restore from spec', async () => { + indexPattern.fieldFormatMap.bytes = { + toJSON: () => ({ id: 'number', params: { pattern: '$0,0.[00]' } }), + }; + const spec = indexPattern.toSpec(); + const restoredPattern = await create(spec.id as string); + restoredPattern.initFromSpec(spec); + expect(restoredPattern.id).toEqual(indexPattern.id); + expect(restoredPattern.title).toEqual(indexPattern.title); + expect(restoredPattern.timeFieldName).toEqual(indexPattern.timeFieldName); + expect(restoredPattern.fields.length).toEqual(indexPattern.fields.length); + expect(restoredPattern.fieldFormatMap.bytes instanceof MockFieldFormatter).toEqual(true); + }); + }); + describe('popularizeField', () => { test('should increment the popularity count by default', () => { // const saveSpy = sinon.stub(indexPattern, 'save'); diff --git a/src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts b/src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts index cd39a965ae6f..e9ac5a09b9db 100644 --- a/src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts +++ b/src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts @@ -20,6 +20,7 @@ import _, { each, reject } from 'lodash'; import { i18n } from '@kbn/i18n'; import { SavedObjectsClientContract } from 'src/core/public'; +import { SavedObjectAttributes } from 'src/core/public'; import { DuplicateField, SavedObjectNotFound } from '../../../../kibana_utils/common'; import { @@ -36,11 +37,12 @@ import { createFieldsFetcher } from './_fields_fetcher'; import { formatHitProvider } from './format_hit'; import { flattenHitWrapper } from './flatten_hit'; import { IIndexPatternsApiClient } from '.'; -import { TypeMeta } from '.'; import { OnNotification, OnError } from '../types'; import { FieldFormatsStartCommon } from '../../field_formats'; import { PatternCache } from './_pattern_cache'; import { expandShorthand, FieldMappingSpec, MappingObject } from '../../field_mapping'; +import { IndexPatternSpec, TypeMeta, FieldSpec, SourceFilter } from '../types'; +import { SerializedFieldFormat } from '../../../../expressions/common'; const MAX_ATTEMPTS_TO_RESOLVE_CONFLICTS = 3; const type = 'index-pattern'; @@ -60,10 +62,9 @@ export class IndexPattern implements IIndexPattern { public id?: string; public title: string = ''; - public type?: string; public fieldFormatMap: any; public typeMeta?: TypeMeta; - public fields: IIndexPatternFieldList; + public fields: IIndexPatternFieldList & { toSpec: () => FieldSpec[] }; public timeFieldName: string | undefined; public formatHit: any; public formatField: any; @@ -74,7 +75,7 @@ export class IndexPattern implements IIndexPattern { private savedObjectsClient: SavedObjectsClientContract; private patternCache: PatternCache; private getConfig: any; - private sourceFilters?: []; + private sourceFilters?: SourceFilter[]; private originalBody: { [key: string]: any } = {}; public fieldsFetcher: any; // probably want to factor out any direct usage and change to private private shortDotsEnable: boolean = false; @@ -196,6 +197,35 @@ export class IndexPattern implements IIndexPattern { this.initFields(); } + public initFromSpec(spec: IndexPatternSpec) { + // create fieldFormatMap from field list + const fieldFormatMap: Record = {}; + if (_.isArray(spec.fields)) { + spec.fields.forEach((field: FieldSpec) => { + if (field.format) { + fieldFormatMap[field.name as string] = { ...field.format }; + } + }); + } + + this.version = spec.version; + + this.title = spec.title || ''; + this.timeFieldName = spec.timeFieldName; + this.sourceFilters = spec.sourceFilters; + + // ignoring this because the same thing happens elsewhere but via _.assign + // @ts-ignore + this.fields = spec.fields || []; + this.typeMeta = spec.typeMeta; + this.fieldFormatMap = _.mapValues(fieldFormatMap, (mapping) => { + return this.deserializeFieldFormatMap(mapping); + }); + + this.initFields(); + return this; + } + private updateFromElasticSearch(response: any, forceFieldRefresh: boolean = false) { if (!response.found) { throw new SavedObjectNotFound(type, this.id, 'management/kibana/indexPatterns'); @@ -206,15 +236,16 @@ export class IndexPattern implements IIndexPattern { return; } - response._source[name] = fieldMapping._deserialize(response._source[name]); + response[name] = fieldMapping._deserialize(response[name]); }); - // give index pattern all of the values in _source - _.assign(this, response._source); + // give index pattern all of the values + _.assign(this, response); if (!this.title && this.id) { this.title = this.id; } + this.version = response.version; return this.indexFields(forceFieldRefresh); } @@ -266,13 +297,11 @@ export class IndexPattern implements IIndexPattern { } const savedObject = await this.savedObjectsClient.get(type, this.id); - this.version = savedObject._version; const response = { - _id: savedObject.id, - _type: savedObject.type, - _source: _.cloneDeep(savedObject.attributes), + version: savedObject._version, found: savedObject._version ? true : false, + ...(_.cloneDeep(savedObject.attributes) as SavedObjectAttributes), }; // Do this before we attempt to update from ES since that call can potentially perform a save this.originalBody = this.prepBody(); @@ -283,6 +312,19 @@ export class IndexPattern implements IIndexPattern { return this; } + public toSpec(): IndexPatternSpec { + return { + id: this.id, + version: this.version, + + title: this.title, + timeFieldName: this.timeFieldName, + sourceFilters: this.sourceFilters, + fields: this.fields.toSpec(), + typeMeta: this.typeMeta, + }; + } + // Get the source filtering configuration for that index. getSourceFiltering() { return { diff --git a/src/plugins/data/common/index_patterns/index_patterns/index_patterns.ts b/src/plugins/data/common/index_patterns/index_patterns/index_patterns.ts index 22d1765d7934..5e51897d1337 100644 --- a/src/plugins/data/common/index_patterns/index_patterns/index_patterns.ts +++ b/src/plugins/data/common/index_patterns/index_patterns/index_patterns.ts @@ -32,12 +32,8 @@ import { createEnsureDefaultIndexPattern, EnsureDefaultIndexPattern, } from './ensure_default_index_pattern'; -import { - getIndexPatternFieldListCreator, - CreateIndexPatternFieldList, - Field, - FieldSpec, -} from '../fields'; +import { getIndexPatternFieldListCreator, CreateIndexPatternFieldList, Field } from '../fields'; +import { IndexPatternSpec, FieldSpec } from '../types'; import { OnNotification, OnError } from '../types'; import { FieldFormatsStartCommon } from '../../field_formats'; @@ -195,6 +191,21 @@ export class IndexPatternsService { return indexPatternCache.set(id, indexPattern); }; + specToIndexPattern(spec: IndexPatternSpec) { + const indexPattern = new IndexPattern(spec.id, { + getConfig: (cfg: any) => this.config.get(cfg), + savedObjectsClient: this.savedObjectsClient, + apiClient: this.apiClient, + patternCache: indexPatternCache, + fieldFormats: this.fieldFormats, + onNotification: this.onNotification, + onError: this.onError, + }); + + indexPattern.initFromSpec(spec); + return indexPattern; + } + make = (id?: string): Promise => { const indexPattern = new IndexPattern(id, { getConfig: (cfg: any) => this.config.get(cfg), diff --git a/src/plugins/data/common/index_patterns/index_patterns/types.ts b/src/plugins/data/common/index_patterns/index_patterns/types.ts deleted file mode 100644 index b2060dd1d48b..000000000000 --- a/src/plugins/data/common/index_patterns/index_patterns/types.ts +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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 type AggregationRestrictions = Record< - string, - { - agg?: string; - interval?: number; - fixed_interval?: string; - calendar_interval?: string; - delay?: string; - time_zone?: string; - } ->; - -export interface TypeMeta { - aggs?: Record; - [key: string]: any; -} diff --git a/src/plugins/data/common/index_patterns/types.ts b/src/plugins/data/common/index_patterns/types.ts index 7399bbbc10a7..94121a274d68 100644 --- a/src/plugins/data/common/index_patterns/types.ts +++ b/src/plugins/data/common/index_patterns/types.ts @@ -19,6 +19,8 @@ import { ToastInputFields, ErrorToastOptions } from 'src/core/public/notifications'; import { IFieldType } from './fields'; +import { SerializedFieldFormat } from '../../../expressions/common'; +import { KBN_FIELD_TYPES } from '..'; export interface IIndexPattern { [key: string]: any; @@ -51,3 +53,65 @@ export interface IndexPatternAttributes { export type OnNotification = (toastInputFields: ToastInputFields) => void; export type OnError = (error: Error, toastInputFields: ErrorToastOptions) => void; + +export type AggregationRestrictions = Record< + string, + { + agg?: string; + interval?: number; + fixed_interval?: string; + calendar_interval?: string; + delay?: string; + time_zone?: string; + } +>; + +export interface IFieldSubType { + multi?: { parent: string }; + nested?: { path: string }; +} + +export interface TypeMeta { + aggs?: Record; + [key: string]: any; +} + +export type FieldSpecConflictDescriptions = Record; + +// This should become FieldSpec once types are cleaned up +export interface FieldSpecExportFmt { + count?: number; + script?: string; + lang?: string; + conflictDescriptions?: FieldSpecConflictDescriptions; + name: string; + type: KBN_FIELD_TYPES; + esTypes?: string[]; + scripted: boolean; + searchable: boolean; + aggregatable: boolean; + readFromDocValues?: boolean; + subType?: IFieldSubType; + format?: SerializedFieldFormat; + indexed?: boolean; +} + +export interface FieldSpec { + [key: string]: any; + format?: SerializedFieldFormat; +} + +export interface IndexPatternSpec { + id?: string; + version?: string; + + title: string; + timeFieldName?: string; + sourceFilters?: SourceFilter[]; + fields?: FieldSpec[]; + typeMeta?: TypeMeta; +} + +export interface SourceFilter { + value: string; +} diff --git a/src/plugins/data/public/index.ts b/src/plugins/data/public/index.ts index 984ce18aa4d8..3665d9dc2b46 100644 --- a/src/plugins/data/public/index.ts +++ b/src/plugins/data/public/index.ts @@ -249,8 +249,6 @@ export { IndexPattern, IIndexPatternFieldList, Field as IndexPatternField, - TypeMeta as IndexPatternTypeMeta, - AggregationRestrictions as IndexPatternAggRestrictions, // TODO: exported only in stub_index_pattern test. Move into data plugin and remove export. getIndexPatternFieldListCreator, } from './index_patterns'; @@ -263,6 +261,8 @@ export { KBN_FIELD_TYPES, IndexPatternAttributes, UI_SETTINGS, + TypeMeta as IndexPatternTypeMeta, + AggregationRestrictions as IndexPatternAggRestrictions, } from '../common'; /* diff --git a/src/plugins/data/public/index_patterns/index.ts b/src/plugins/data/public/index_patterns/index.ts index 0a8397467807..2c540527f468 100644 --- a/src/plugins/data/public/index_patterns/index.ts +++ b/src/plugins/data/public/index_patterns/index.ts @@ -34,11 +34,4 @@ export { IIndexPatternFieldList, } from '../../common/index_patterns'; -// TODO: figure out how to replace IndexPatterns in get_inner_angular. -export { - IndexPatternsService, - IndexPatternsContract, - IndexPattern, - TypeMeta, - AggregationRestrictions, -} from './index_patterns'; +export { IndexPatternsService, IndexPatternsContract, IndexPattern } from './index_patterns'; diff --git a/src/plugins/data/public/public.api.md b/src/plugins/data/public/public.api.md index 31dc5b51a06f..25c9b0718050 100644 --- a/src/plugins/data/public/public.api.md +++ b/src/plugins/data/public/public.api.md @@ -902,6 +902,10 @@ export interface IFieldType { sortable?: boolean; // (undocumented) subType?: IFieldSubType; + // Warning: (ae-forgotten-export) The symbol "FieldSpec" needs to be exported by the entry point index.d.ts + // + // (undocumented) + toSpec?: () => FieldSpec; // (undocumented) type: string; // (undocumented) @@ -937,8 +941,6 @@ export interface IIndexPattern { // // @public (undocumented) export interface IIndexPatternFieldList extends Array { - // Warning: (ae-forgotten-export) The symbol "FieldSpec" needs to be exported by the entry point index.d.ts - // // (undocumented) add(field: FieldSpec): void; // (undocumented) @@ -993,7 +995,9 @@ export class IndexPattern implements IIndexPattern { // (undocumented) fieldFormatMap: any; // (undocumented) - fields: IIndexPatternFieldList; + fields: IIndexPatternFieldList & { + toSpec: () => FieldSpec[]; + }; // (undocumented) fieldsFetcher: any; // (undocumented) @@ -1036,6 +1040,10 @@ export class IndexPattern implements IIndexPattern { id?: string; // (undocumented) init(forceFieldRefresh?: boolean): Promise; + // Warning: (ae-forgotten-export) The symbol "IndexPatternSpec" needs to be exported by the entry point index.d.ts + // + // (undocumented) + initFromSpec(spec: IndexPatternSpec): this; // (undocumented) isTimeBased(): boolean; // (undocumented) @@ -1065,9 +1073,9 @@ export class IndexPattern implements IIndexPattern { // (undocumented) toJSON(): string | undefined; // (undocumented) - toString(): string; + toSpec(): IndexPatternSpec; // (undocumented) - type?: string; + toString(): string; // (undocumented) typeMeta?: IndexPatternTypeMeta; } @@ -1106,12 +1114,15 @@ export interface IndexPatternAttributes { export class IndexPatternField implements IFieldType { // (undocumented) $$spec: FieldSpec; + // Warning: (ae-forgotten-export) The symbol "FieldSpecExportFmt" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "FieldDependencies" needs to be exported by the entry point index.d.ts - constructor(indexPattern: IIndexPattern, spec: FieldSpec | IndexPatternField, shortDotsEnable: boolean, { fieldFormats, onNotification }: FieldDependencies); + constructor(indexPattern: IIndexPattern, spec: FieldSpecExportFmt | FieldSpec | IndexPatternField, shortDotsEnable: boolean, { fieldFormats, onNotification }: FieldDependencies); // (undocumented) aggregatable?: boolean; + // Warning: (ae-forgotten-export) The symbol "FieldSpecConflictDescriptions" needs to be exported by the entry point index.d.ts + // // (undocumented) - conflictDescriptions?: Record; + conflictDescriptions?: FieldSpecConflictDescriptions; // (undocumented) count?: number; // (undocumented) @@ -1141,6 +1152,8 @@ export class IndexPatternField implements IFieldType { // (undocumented) subType?: IFieldSubType; // (undocumented) + toSpec: () => FieldSpecExportFmt; + // (undocumented) type: string; // (undocumented) visualizable?: boolean; diff --git a/src/plugins/data/server/server.api.md b/src/plugins/data/server/server.api.md index 2ab0644f7237..136d960b52c3 100644 --- a/src/plugins/data/server/server.api.md +++ b/src/plugins/data/server/server.api.md @@ -392,6 +392,10 @@ export interface IFieldType { sortable?: boolean; // (undocumented) subType?: IFieldSubType; + // Warning: (ae-forgotten-export) The symbol "FieldSpec" needs to be exported by the entry point index.d.ts + // + // (undocumented) + toSpec?: () => FieldSpec; // (undocumented) type: string; // (undocumented) diff --git a/src/plugins/discover/public/application/components/sidebar/discover_field.test.tsx b/src/plugins/discover/public/application/components/sidebar/discover_field.test.tsx index 8c527475b748..099ec2e5b1ff 100644 --- a/src/plugins/discover/public/application/components/sidebar/discover_field.test.tsx +++ b/src/plugins/discover/public/application/components/sidebar/discover_field.test.tsx @@ -28,6 +28,7 @@ import { mountWithIntl } from 'test_utils/enzyme_helpers'; import { DiscoverField } from './discover_field'; import { coreMock } from '../../../../../../core/public/mocks'; import { IndexPatternField } from '../../../../../data/public'; +import { FieldSpecExportFmt } from '../../../../../data/common'; jest.mock('../../../kibana_services', () => ({ getServices: () => ({ @@ -74,6 +75,7 @@ function getComponent(selected = false, showDetails = false, useShortDots = fals format: null, routes: {}, $$spec: {}, + toSpec: () => (({} as unknown) as FieldSpecExportFmt), } as IndexPatternField; const props = {