diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS
index 1d0f6fc50ee9b..b4563dd1f9a9c 100644
--- a/.github/CODEOWNERS
+++ b/.github/CODEOWNERS
@@ -209,8 +209,19 @@ x-pack/plugins/telemetry_collection_xpack/schema/xpack_plugins.json @elastic/kib
/x-pack/test/functional_with_es_ssl/fixtures/plugins/alerts/ @elastic/kibana-alerting-services
# Enterprise Search
-/x-pack/plugins/enterprise_search/ @elastic/app-search-frontend @elastic/workplace-search-frontend
-/x-pack/test/functional_enterprise_search/ @elastic/app-search-frontend @elastic/workplace-search-frontend
+# Shared
+/x-pack/plugins/enterprise_search/ @elastic/enterprise-search-frontend
+/x-pack/test/functional_enterprise_search/ @elastic/enterprise-search-frontend
+# App Search
+/x-pack/plugins/enterprise_search/public/applications/app_search @elastic/app-search-frontend
+/x-pack/plugins/enterprise_search/server/routes/app_search @elastic/app-search-frontend
+/x-pack/plugins/enterprise_search/server/collectors/app_search @elastic/app-search-frontend
+/x-pack/plugins/enterprise_search/server/saved_objects/app_search @elastic/app-search-frontend
+# Workplace Search
+/x-pack/plugins/enterprise_search/public/applications/workplace_search @elastic/workplace-search-frontend
+/x-pack/plugins/enterprise_search/server/routes/workplace_search @elastic/workplace-search-frontend
+/x-pack/plugins/enterprise_search/server/collectors/workplace_search @elastic/workplace-search-frontend
+/x-pack/plugins/enterprise_search/server/saved_objects/workplace_search @elastic/workplace-search-frontend
# Elasticsearch UI
/src/plugins/dev_tools/ @elastic/es-ui
diff --git a/NOTICE.txt b/NOTICE.txt
index e1552852d0349..d689abf4c4e05 100644
--- a/NOTICE.txt
+++ b/NOTICE.txt
@@ -281,6 +281,13 @@ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+---
+This product includes code in the function applyCubicBezierStyles that was
+inspired by a public Codepen, which was available under a "MIT" license.
+
+Copyright (c) 2020 by Guillaume (https://codepen.io/guillaumethomas/pen/xxbbBKO)
+MIT License http://www.opensource.org/licenses/mit-license
+
---
This product includes code that is adapted from mapbox-gl-js, which is
available under a "BSD-3-Clause" license.
diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist._constructor_.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist._constructor_.md
deleted file mode 100644
index 9f9613a5a68f7..0000000000000
--- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist._constructor_.md
+++ /dev/null
@@ -1,23 +0,0 @@
-
-
-[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [FieldList](./kibana-plugin-plugins-data-public.fieldlist.md) > [(constructor)](./kibana-plugin-plugins-data-public.fieldlist._constructor_.md)
-
-## FieldList.(constructor)
-
-Constructs a new instance of the `FieldList` class
-
-Signature:
-
-```typescript
-constructor(indexPattern: IndexPattern, specs?: FieldSpec[], shortDotsEnable?: boolean, onNotification?: OnNotification);
-```
-
-## Parameters
-
-| Parameter | Type | Description |
-| --- | --- | --- |
-| indexPattern | IndexPattern
| |
-| specs | FieldSpec[]
| |
-| shortDotsEnable | boolean
| |
-| onNotification | OnNotification
| |
-
diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.add.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.add.md
deleted file mode 100644
index ae3d82f0cc3ea..0000000000000
--- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.add.md
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
-[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [FieldList](./kibana-plugin-plugins-data-public.fieldlist.md) > [add](./kibana-plugin-plugins-data-public.fieldlist.add.md)
-
-## FieldList.add property
-
-Signature:
-
-```typescript
-readonly add: (field: FieldSpec) => void;
-```
diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.getall.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.getall.md
deleted file mode 100644
index da29a4de9acc8..0000000000000
--- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.getall.md
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
-[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [FieldList](./kibana-plugin-plugins-data-public.fieldlist.md) > [getAll](./kibana-plugin-plugins-data-public.fieldlist.getall.md)
-
-## FieldList.getAll property
-
-Signature:
-
-```typescript
-readonly getAll: () => IndexPatternField[];
-```
diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.getbyname.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.getbyname.md
deleted file mode 100644
index af368d003423a..0000000000000
--- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.getbyname.md
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
-[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [FieldList](./kibana-plugin-plugins-data-public.fieldlist.md) > [getByName](./kibana-plugin-plugins-data-public.fieldlist.getbyname.md)
-
-## FieldList.getByName property
-
-Signature:
-
-```typescript
-readonly getByName: (name: IndexPatternField['name']) => IndexPatternField | undefined;
-```
diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.getbytype.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.getbytype.md
deleted file mode 100644
index 16bae3ee7c555..0000000000000
--- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.getbytype.md
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
-[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [FieldList](./kibana-plugin-plugins-data-public.fieldlist.md) > [getByType](./kibana-plugin-plugins-data-public.fieldlist.getbytype.md)
-
-## FieldList.getByType property
-
-Signature:
-
-```typescript
-readonly getByType: (type: IndexPatternField['type']) => any[];
-```
diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.md
index 012b069430290..79bcaf9700cf0 100644
--- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.md
+++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.md
@@ -1,32 +1,11 @@
-[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [FieldList](./kibana-plugin-plugins-data-public.fieldlist.md)
+[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [fieldList](./kibana-plugin-plugins-data-public.fieldlist.md)
-## FieldList class
+## fieldList variable
Signature:
```typescript
-export declare class FieldList extends Array implements IIndexPatternFieldList
+fieldList: (specs?: FieldSpec[], shortDotsEnable?: boolean) => IIndexPatternFieldList
```
-
-## Constructors
-
-| Constructor | Modifiers | Description |
-| --- | --- | --- |
-| [(constructor)(indexPattern, specs, shortDotsEnable, onNotification)](./kibana-plugin-plugins-data-public.fieldlist._constructor_.md) | | Constructs a new instance of the FieldList
class |
-
-## Properties
-
-| Property | Modifiers | Type | Description |
-| --- | --- | --- | --- |
-| [add](./kibana-plugin-plugins-data-public.fieldlist.add.md) | | (field: FieldSpec) => void
| |
-| [getAll](./kibana-plugin-plugins-data-public.fieldlist.getall.md) | | () => IndexPatternField[]
| |
-| [getByName](./kibana-plugin-plugins-data-public.fieldlist.getbyname.md) | | (name: IndexPatternField['name']) => IndexPatternField | undefined
| |
-| [getByType](./kibana-plugin-plugins-data-public.fieldlist.getbytype.md) | | (type: IndexPatternField['type']) => any[]
| |
-| [remove](./kibana-plugin-plugins-data-public.fieldlist.remove.md) | | (field: IFieldType) => void
| |
-| [removeAll](./kibana-plugin-plugins-data-public.fieldlist.removeall.md) | | () => void
| |
-| [replaceAll](./kibana-plugin-plugins-data-public.fieldlist.replaceall.md) | | (specs: FieldSpec[]) => void
| |
-| [toSpec](./kibana-plugin-plugins-data-public.fieldlist.tospec.md) | | () => {
count: number;
script: string | undefined;
lang: string | undefined;
conflictDescriptions: Record<string, string[]> | undefined;
name: string;
type: string;
esTypes: string[] | undefined;
scripted: boolean;
searchable: boolean;
aggregatable: boolean;
readFromDocValues: boolean;
subType: import("../types").IFieldSubType | undefined;
format: any;
}[]
| |
-| [update](./kibana-plugin-plugins-data-public.fieldlist.update.md) | | (field: FieldSpec) => void
| |
-
diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.remove.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.remove.md
deleted file mode 100644
index 149410adb3550..0000000000000
--- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.remove.md
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
-[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [FieldList](./kibana-plugin-plugins-data-public.fieldlist.md) > [remove](./kibana-plugin-plugins-data-public.fieldlist.remove.md)
-
-## FieldList.remove property
-
-Signature:
-
-```typescript
-readonly remove: (field: IFieldType) => void;
-```
diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.removeall.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.removeall.md
deleted file mode 100644
index 92a45349ad005..0000000000000
--- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.removeall.md
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
-[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [FieldList](./kibana-plugin-plugins-data-public.fieldlist.md) > [removeAll](./kibana-plugin-plugins-data-public.fieldlist.removeall.md)
-
-## FieldList.removeAll property
-
-Signature:
-
-```typescript
-readonly removeAll: () => void;
-```
diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.replaceall.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.replaceall.md
deleted file mode 100644
index 5330440e6b96a..0000000000000
--- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.replaceall.md
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
-[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [FieldList](./kibana-plugin-plugins-data-public.fieldlist.md) > [replaceAll](./kibana-plugin-plugins-data-public.fieldlist.replaceall.md)
-
-## FieldList.replaceAll property
-
-Signature:
-
-```typescript
-readonly replaceAll: (specs: FieldSpec[]) => void;
-```
diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.tospec.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.tospec.md
deleted file mode 100644
index e646339feb495..0000000000000
--- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.tospec.md
+++ /dev/null
@@ -1,25 +0,0 @@
-
-
-[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [FieldList](./kibana-plugin-plugins-data-public.fieldlist.md) > [toSpec](./kibana-plugin-plugins-data-public.fieldlist.tospec.md)
-
-## FieldList.toSpec property
-
-Signature:
-
-```typescript
-readonly toSpec: () => {
- count: number;
- script: string | undefined;
- lang: string | undefined;
- conflictDescriptions: Record | undefined;
- name: string;
- type: string;
- esTypes: string[] | undefined;
- scripted: boolean;
- searchable: boolean;
- aggregatable: boolean;
- readFromDocValues: boolean;
- subType: import("../types").IFieldSubType | undefined;
- format: any;
- }[];
-```
diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.update.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.update.md
deleted file mode 100644
index c718e47b31b50..0000000000000
--- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.update.md
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
-[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [FieldList](./kibana-plugin-plugins-data-public.fieldlist.md) > [update](./kibana-plugin-plugins-data-public.fieldlist.update.md)
-
-## FieldList.update property
-
-Signature:
-
-```typescript
-readonly update: (field: FieldSpec) => void;
-```
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 6f42fb32fdb7b..3ff2afafcc514 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,7 +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
| |
+| [toSpec](./kibana-plugin-plugins-data-public.ifieldtype.tospec.md) | (options?: {
getFormatterForField?: IndexPattern['getFormatterForField'];
}) => 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
index 1fb4084c25d34..52238ea2a00ca 100644
--- 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
@@ -7,5 +7,7 @@
Signature:
```typescript
-toSpec?: () => FieldSpec;
+toSpec?: (options?: {
+ getFormatterForField?: IndexPattern['getFormatterForField'];
+ }) => FieldSpec;
```
diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.iindexpatternfieldlist.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.iindexpatternfieldlist.md
index b068c4804c0dd..b1e13ffaabd07 100644
--- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.iindexpatternfieldlist.md
+++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.iindexpatternfieldlist.md
@@ -21,5 +21,6 @@ export interface IIndexPatternFieldList extends Array
| [remove(field)](./kibana-plugin-plugins-data-public.iindexpatternfieldlist.remove.md) | |
| [removeAll()](./kibana-plugin-plugins-data-public.iindexpatternfieldlist.removeall.md) | |
| [replaceAll(specs)](./kibana-plugin-plugins-data-public.iindexpatternfieldlist.replaceall.md) | |
+| [toSpec(options)](./kibana-plugin-plugins-data-public.iindexpatternfieldlist.tospec.md) | |
| [update(field)](./kibana-plugin-plugins-data-public.iindexpatternfieldlist.update.md) | |
diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.iindexpatternfieldlist.tospec.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.iindexpatternfieldlist.tospec.md
new file mode 100644
index 0000000000000..fd20f2944c5be
--- /dev/null
+++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.iindexpatternfieldlist.tospec.md
@@ -0,0 +1,24 @@
+
+
+[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [IIndexPatternFieldList](./kibana-plugin-plugins-data-public.iindexpatternfieldlist.md) > [toSpec](./kibana-plugin-plugins-data-public.iindexpatternfieldlist.tospec.md)
+
+## IIndexPatternFieldList.toSpec() method
+
+Signature:
+
+```typescript
+toSpec(options?: {
+ getFormatterForField?: IndexPattern['getFormatterForField'];
+ }): FieldSpec[];
+```
+
+## Parameters
+
+| Parameter | Type | Description |
+| --- | --- | --- |
+| options | {
getFormatterForField?: IndexPattern['getFormatterForField'];
}
| |
+
+Returns:
+
+`FieldSpec[]`
+
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 37db063e284ec..4c53af3f8970e 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
@@ -61,7 +61,5 @@ export declare class IndexPattern implements IIndexPattern
| [refreshFields()](./kibana-plugin-plugins-data-public.indexpattern.refreshfields.md) | | |
| [removeScriptedField(fieldName)](./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.tojson.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.tojson.md
deleted file mode 100644
index 0ae04bb424d44..0000000000000
--- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.tojson.md
+++ /dev/null
@@ -1,15 +0,0 @@
-
-
-[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [IndexPattern](./kibana-plugin-plugins-data-public.indexpattern.md) > [toJSON](./kibana-plugin-plugins-data-public.indexpattern.tojson.md)
-
-## IndexPattern.toJSON() method
-
-Signature:
-
-```typescript
-toJSON(): string | undefined;
-```
-Returns:
-
-`string | undefined`
-
diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.tostring.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.tostring.md
deleted file mode 100644
index a10b549a7b9eb..0000000000000
--- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.tostring.md
+++ /dev/null
@@ -1,15 +0,0 @@
-
-
-[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [IndexPattern](./kibana-plugin-plugins-data-public.indexpattern.md) > [toString](./kibana-plugin-plugins-data-public.indexpattern.tostring.md)
-
-## IndexPattern.toString() method
-
-Signature:
-
-```typescript
-toString(): string;
-```
-Returns:
-
-`string`
-
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 10b65bdccdf87..5d467a7a9cbce 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,15 +9,13 @@ Constructs a new instance of the `IndexPatternField` class
Signature:
```typescript
-constructor(indexPattern: IndexPattern, spec: FieldSpec, displayName: string, onNotification: OnNotification);
+constructor(spec: FieldSpec, displayName: string);
```
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
-| indexPattern | IndexPattern
| |
| spec | FieldSpec
| |
| displayName | string
| |
-| onNotification | OnNotification
| |
diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.format.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.format.md
deleted file mode 100644
index f28d5b1bca7e5..0000000000000
--- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.format.md
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
-[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [IndexPatternField](./kibana-plugin-plugins-data-public.indexpatternfield.md) > [format](./kibana-plugin-plugins-data-public.indexpatternfield.format.md)
-
-## IndexPatternField.format property
-
-Signature:
-
-```typescript
-get format(): FieldFormat;
-```
diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.indexpattern.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.indexpattern.md
deleted file mode 100644
index 3d145cce9d07d..0000000000000
--- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.indexpattern.md
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
-[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [IndexPatternField](./kibana-plugin-plugins-data-public.indexpatternfield.md) > [indexPattern](./kibana-plugin-plugins-data-public.indexpatternfield.indexpattern.md)
-
-## IndexPatternField.indexPattern property
-
-Signature:
-
-```typescript
-readonly indexPattern: IndexPattern;
-```
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 713b29ea3a3d3..215188ffa2607 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
@@ -14,7 +14,7 @@ export declare class IndexPatternField implements IFieldType
| Constructor | Modifiers | Description |
| --- | --- | --- |
-| [(constructor)(indexPattern, spec, displayName, onNotification)](./kibana-plugin-plugins-data-public.indexpatternfield._constructor_.md) | | Constructs a new instance of the IndexPatternField
class |
+| [(constructor)(spec, displayName)](./kibana-plugin-plugins-data-public.indexpatternfield._constructor_.md) | | Constructs a new instance of the IndexPatternField
class |
## Properties
@@ -26,8 +26,6 @@ export declare class IndexPatternField implements IFieldType
| [displayName](./kibana-plugin-plugins-data-public.indexpatternfield.displayname.md) | | string
| |
| [esTypes](./kibana-plugin-plugins-data-public.indexpatternfield.estypes.md) | | string[] | undefined
| |
| [filterable](./kibana-plugin-plugins-data-public.indexpatternfield.filterable.md) | | boolean
| |
-| [format](./kibana-plugin-plugins-data-public.indexpatternfield.format.md) | | FieldFormat
| |
-| [indexPattern](./kibana-plugin-plugins-data-public.indexpatternfield.indexpattern.md) | | IndexPattern
| |
| [lang](./kibana-plugin-plugins-data-public.indexpatternfield.lang.md) | | string | undefined
| |
| [name](./kibana-plugin-plugins-data-public.indexpatternfield.name.md) | | string
| |
| [readFromDocValues](./kibana-plugin-plugins-data-public.indexpatternfield.readfromdocvalues.md) | | boolean
| |
@@ -45,5 +43,5 @@ export declare class IndexPatternField implements IFieldType
| Method | Modifiers | Description |
| --- | --- | --- |
| [toJSON()](./kibana-plugin-plugins-data-public.indexpatternfield.tojson.md) | | |
-| [toSpec()](./kibana-plugin-plugins-data-public.indexpatternfield.tospec.md) | | |
+| [toSpec({ getFormatterForField, })](./kibana-plugin-plugins-data-public.indexpatternfield.tospec.md) | | |
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
index 5037cb0049e82..1d80c90991f55 100644
--- 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
@@ -7,7 +7,9 @@
Signature:
```typescript
-toSpec(): {
+toSpec({ getFormatterForField, }?: {
+ getFormatterForField?: IndexPattern['getFormatterForField'];
+ }): {
count: number;
script: string | undefined;
lang: string | undefined;
@@ -20,9 +22,19 @@ toSpec(): {
aggregatable: boolean;
readFromDocValues: boolean;
subType: import("../types").IFieldSubType | undefined;
- format: any;
+ format: {
+ id: any;
+ params: any;
+ } | undefined;
};
```
+
+## Parameters
+
+| Parameter | Type | Description |
+| --- | --- | --- |
+| { getFormatterForField, } | {
getFormatterForField?: IndexPattern['getFormatterForField'];
}
| |
+
Returns:
`{
@@ -38,6 +50,9 @@ toSpec(): {
aggregatable: boolean;
readFromDocValues: boolean;
subType: import("../types").IFieldSubType | undefined;
- format: any;
+ format: {
+ id: any;
+ params: any;
+ } | undefined;
}`
diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.md
index 09702df4fdb54..0ab86e0f4dab2 100644
--- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.md
+++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.md
@@ -10,7 +10,6 @@
| --- | --- |
| [AggParamType](./kibana-plugin-plugins-data-public.aggparamtype.md) | |
| [FieldFormat](./kibana-plugin-plugins-data-public.fieldformat.md) | |
-| [FieldList](./kibana-plugin-plugins-data-public.fieldlist.md) | |
| [FilterManager](./kibana-plugin-plugins-data-public.filtermanager.md) | |
| [IndexPattern](./kibana-plugin-plugins-data-public.indexpattern.md) | |
| [IndexPatternField](./kibana-plugin-plugins-data-public.indexpatternfield.md) | |
@@ -103,6 +102,7 @@
| [expandShorthand](./kibana-plugin-plugins-data-public.expandshorthand.md) | |
| [extractSearchSourceReferences](./kibana-plugin-plugins-data-public.extractsearchsourcereferences.md) | |
| [fieldFormats](./kibana-plugin-plugins-data-public.fieldformats.md) | |
+| [fieldList](./kibana-plugin-plugins-data-public.fieldlist.md) | |
| [FilterBar](./kibana-plugin-plugins-data-public.filterbar.md) | |
| [getKbnTypeNames](./kibana-plugin-plugins-data-public.getkbntypenames.md) | Get the esTypes known by all kbnFieldTypes {Array} |
| [indexPatterns](./kibana-plugin-plugins-data-public.indexpatterns.md) | |
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 77a2954428f8d..d106f3a35a91c 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,7 +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
| |
+| [toSpec](./kibana-plugin-plugins-data-server.ifieldtype.tospec.md) | (options?: {
getFormatterForField?: IndexPattern['getFormatterForField'];
}) => 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
index d1863bebce4f0..6f8ee9d9eebf0 100644
--- 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
@@ -7,5 +7,7 @@
Signature:
```typescript
-toSpec?: () => FieldSpec;
+toSpec?: (options?: {
+ getFormatterForField?: IndexPattern['getFormatterForField'];
+ }) => FieldSpec;
```
diff --git a/docs/settings/alert-action-settings.asciidoc b/docs/settings/alert-action-settings.asciidoc
index e02c7f212277e..88858c36643ec 100644
--- a/docs/settings/alert-action-settings.asciidoc
+++ b/docs/settings/alert-action-settings.asciidoc
@@ -37,12 +37,12 @@ You can configure the following settings in the `kibana.yml` file.
[cols="2*<"]
|===
-| `xpack.actions.whitelistedHosts`
+| `xpack.actions.whitelistedHosts` {ess-icon}
| A list of hostnames that {kib} is allowed to connect to when built-in actions are triggered. It defaults to `[*]`, allowing any host, but keep in mind the potential for SSRF attacks when hosts are not explicitly whitelisted. An empty list `[]` can be used to block built-in actions from making any external connections. +
+
Note that hosts associated with built-in actions, such as Slack and PagerDuty, are not automatically whitelisted. If you are not using the default `[*]` setting, you must ensure that the corresponding endpoints are whitelisted as well.
-| `xpack.actions.enabledActionTypes`
+| `xpack.actions.enabledActionTypes` {ess-icon}
| A list of action types that are enabled. It defaults to `[*]`, enabling all types. The names for built-in {kib} action types are prefixed with a `.` and include: `.server-log`, `.slack`, `.email`, `.index`, `.pagerduty`, and `.webhook`. An empty list `[]` will disable all action types. +
+
Disabled action types will not appear as an option when creating new connectors, but existing connectors and actions of that type will remain in {kib} and will not function.
diff --git a/packages/kbn-es-archiver/src/lib/streams/concat_stream.test.js b/packages/kbn-es-archiver/src/lib/streams/concat_stream.test.js
new file mode 100644
index 0000000000000..1498334013d1a
--- /dev/null
+++ b/packages/kbn-es-archiver/src/lib/streams/concat_stream.test.js
@@ -0,0 +1,74 @@
+/*
+ * 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.
+ */
+
+import { createListStream, createPromiseFromStreams, createConcatStream } from './';
+
+describe('concatStream', () => {
+ test('accepts an initial value', async () => {
+ const output = await createPromiseFromStreams([
+ createListStream([1, 2, 3]),
+ createConcatStream([0]),
+ ]);
+
+ expect(output).toEqual([0, 1, 2, 3]);
+ });
+
+ describe(`combines using the previous value's concat method`, () => {
+ test('works with strings', async () => {
+ const output = await createPromiseFromStreams([
+ createListStream(['a', 'b', 'c']),
+ createConcatStream(),
+ ]);
+ expect(output).toEqual('abc');
+ });
+
+ test('works with arrays', async () => {
+ const output = await createPromiseFromStreams([
+ createListStream([[1], [2, 3, 4], [10]]),
+ createConcatStream(),
+ ]);
+ expect(output).toEqual([1, 2, 3, 4, 10]);
+ });
+
+ test('works with a mixture, starting with array', async () => {
+ const output = await createPromiseFromStreams([
+ createListStream([[], 1, 2, 3, 4, [5, 6, 7]]),
+ createConcatStream(),
+ ]);
+ expect(output).toEqual([1, 2, 3, 4, 5, 6, 7]);
+ });
+
+ test('fails when the value does not have a concat method', async () => {
+ let promise;
+ try {
+ promise = createPromiseFromStreams([createListStream([1, '1']), createConcatStream()]);
+ } catch (err) {
+ throw new Error('createPromiseFromStreams() should not fail synchronously');
+ }
+
+ try {
+ await promise;
+ throw new Error('Promise should have rejected');
+ } catch (err) {
+ expect(err).toBeInstanceOf(Error);
+ expect(err.message).toContain('concat');
+ }
+ });
+ });
+});
diff --git a/packages/kbn-es-archiver/src/lib/streams/concat_stream.ts b/packages/kbn-es-archiver/src/lib/streams/concat_stream.ts
new file mode 100644
index 0000000000000..03dd894067afc
--- /dev/null
+++ b/packages/kbn-es-archiver/src/lib/streams/concat_stream.ts
@@ -0,0 +1,41 @@
+/*
+ * 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.
+ */
+
+import { createReduceStream } from './reduce_stream';
+
+/**
+ * Creates a Transform stream that consumes all provided
+ * values and concatenates them using each values `concat`
+ * method.
+ *
+ * Concatenate strings:
+ * createListStream(['f', 'o', 'o'])
+ * .pipe(createConcatStream())
+ * .on('data', console.log)
+ * // logs "foo"
+ *
+ * Concatenate values into an array:
+ * createListStream([1,2,3])
+ * .pipe(createConcatStream([]))
+ * .on('data', console.log)
+ * // logs "[1,2,3]"
+ */
+export function createConcatStream(initial: any) {
+ return createReduceStream((acc, chunk) => acc.concat(chunk), initial);
+}
diff --git a/packages/kbn-es-archiver/src/lib/streams/concat_stream_providers.test.js b/packages/kbn-es-archiver/src/lib/streams/concat_stream_providers.test.js
new file mode 100644
index 0000000000000..b742a770b70c8
--- /dev/null
+++ b/packages/kbn-es-archiver/src/lib/streams/concat_stream_providers.test.js
@@ -0,0 +1,66 @@
+/*
+ * 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.
+ */
+
+import { Readable } from 'stream';
+
+import { concatStreamProviders } from './concat_stream_providers';
+import { createListStream } from './list_stream';
+import { createConcatStream } from './concat_stream';
+import { createPromiseFromStreams } from './promise_from_streams';
+
+describe('concatStreamProviders() helper', () => {
+ test('writes the data from an array of stream providers into a destination stream in order', async () => {
+ const results = await createPromiseFromStreams([
+ concatStreamProviders([
+ () => createListStream(['foo', 'bar']),
+ () => createListStream(['baz']),
+ () => createListStream(['bug']),
+ ]),
+ createConcatStream(''),
+ ]);
+
+ expect(results).toBe('foobarbazbug');
+ });
+
+ test('emits the errors from a sub-stream to the destination', async () => {
+ const dest = concatStreamProviders([
+ () => createListStream(['foo', 'bar']),
+ () =>
+ new Readable({
+ read() {
+ this.emit('error', new Error('foo'));
+ },
+ }),
+ ]);
+
+ const errorListener = jest.fn();
+ dest.on('error', errorListener);
+
+ await expect(createPromiseFromStreams([dest])).rejects.toThrowErrorMatchingInlineSnapshot(
+ `"foo"`
+ );
+ expect(errorListener.mock.calls).toMatchInlineSnapshot(`
+Array [
+ Array [
+ [Error: foo],
+ ],
+]
+`);
+ });
+});
diff --git a/packages/kbn-es-archiver/src/lib/streams/concat_stream_providers.ts b/packages/kbn-es-archiver/src/lib/streams/concat_stream_providers.ts
new file mode 100644
index 0000000000000..4794d76cc7f84
--- /dev/null
+++ b/packages/kbn-es-archiver/src/lib/streams/concat_stream_providers.ts
@@ -0,0 +1,60 @@
+/*
+ * 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.
+ */
+
+import { PassThrough, TransformOptions } from 'stream';
+
+/**
+ * Write the data and errors from a list of stream providers
+ * to a single stream in order. Stream providers are only
+ * called right before they will be consumed, and only one
+ * provider will be active at a time.
+ */
+export function concatStreamProviders(
+ sourceProviders: Array<() => NodeJS.ReadableStream>,
+ options: TransformOptions = {}
+) {
+ const destination = new PassThrough(options);
+ const queue = sourceProviders.slice();
+
+ (function pipeNext() {
+ const provider = queue.shift();
+
+ if (!provider) {
+ return;
+ }
+
+ const source = provider();
+ const isLast = !queue.length;
+
+ // if there are more sources to pipe, hook
+ // into the source completion
+ if (!isLast) {
+ source.once('end', pipeNext);
+ }
+
+ source
+ // proxy errors from the source to the destination
+ .once('error', (error) => destination.emit('error', error))
+ // pipe the source to the destination but only proxy the
+ // end event if this is the last source
+ .pipe(destination, { end: isLast });
+ })();
+
+ return destination;
+}
diff --git a/packages/kbn-es-archiver/src/lib/streams/filter_stream.test.ts b/packages/kbn-es-archiver/src/lib/streams/filter_stream.test.ts
new file mode 100644
index 0000000000000..28b7f2588628e
--- /dev/null
+++ b/packages/kbn-es-archiver/src/lib/streams/filter_stream.test.ts
@@ -0,0 +1,77 @@
+/*
+ * 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.
+ */
+
+import {
+ createConcatStream,
+ createFilterStream,
+ createListStream,
+ createPromiseFromStreams,
+} from './';
+
+describe('createFilterStream()', () => {
+ test('calls the function with each item in the source stream', async () => {
+ const filter = jest.fn().mockReturnValue(true);
+
+ await createPromiseFromStreams([createListStream(['a', 'b', 'c']), createFilterStream(filter)]);
+
+ expect(filter).toMatchInlineSnapshot(`
+ [MockFunction] {
+ "calls": Array [
+ Array [
+ "a",
+ ],
+ Array [
+ "b",
+ ],
+ Array [
+ "c",
+ ],
+ ],
+ "results": Array [
+ Object {
+ "type": "return",
+ "value": true,
+ },
+ Object {
+ "type": "return",
+ "value": true,
+ },
+ Object {
+ "type": "return",
+ "value": true,
+ },
+ ],
+ }
+ `);
+ });
+
+ test('send the filtered values on the output stream', async () => {
+ const result = await createPromiseFromStreams([
+ createListStream([1, 2, 3]),
+ createFilterStream((n) => n % 2 === 0),
+ createConcatStream([]),
+ ]);
+
+ expect(result).toMatchInlineSnapshot(`
+ Array [
+ 2,
+ ]
+ `);
+ });
+});
diff --git a/packages/kbn-es-archiver/src/lib/streams/filter_stream.ts b/packages/kbn-es-archiver/src/lib/streams/filter_stream.ts
new file mode 100644
index 0000000000000..738b9d5793d06
--- /dev/null
+++ b/packages/kbn-es-archiver/src/lib/streams/filter_stream.ts
@@ -0,0 +1,33 @@
+/*
+ * 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.
+ */
+
+import { Transform } from 'stream';
+
+export function createFilterStream(fn: (obj: T) => boolean) {
+ return new Transform({
+ objectMode: true,
+ async transform(obj, _, done) {
+ const canPushDownStream = fn(obj);
+ if (canPushDownStream) {
+ this.push(obj);
+ }
+ done();
+ },
+ });
+}
diff --git a/packages/kbn-es-archiver/src/lib/streams/index.ts b/packages/kbn-es-archiver/src/lib/streams/index.ts
new file mode 100644
index 0000000000000..447d1ed5b1c53
--- /dev/null
+++ b/packages/kbn-es-archiver/src/lib/streams/index.ts
@@ -0,0 +1,29 @@
+/*
+ * 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 { concatStreamProviders } from './concat_stream_providers';
+export { createIntersperseStream } from './intersperse_stream';
+export { createSplitStream } from './split_stream';
+export { createListStream } from './list_stream';
+export { createReduceStream } from './reduce_stream';
+export { createPromiseFromStreams } from './promise_from_streams';
+export { createConcatStream } from './concat_stream';
+export { createMapStream } from './map_stream';
+export { createReplaceStream } from './replace_stream';
+export { createFilterStream } from './filter_stream';
diff --git a/packages/kbn-es-archiver/src/lib/streams/intersperse_stream.test.js b/packages/kbn-es-archiver/src/lib/streams/intersperse_stream.test.js
new file mode 100644
index 0000000000000..e11b36d77106a
--- /dev/null
+++ b/packages/kbn-es-archiver/src/lib/streams/intersperse_stream.test.js
@@ -0,0 +1,54 @@
+/*
+ * 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.
+ */
+
+import {
+ createPromiseFromStreams,
+ createListStream,
+ createIntersperseStream,
+ createConcatStream,
+} from './';
+
+describe('intersperseStream', () => {
+ test('places the intersperse value between each provided value', async () => {
+ expect(
+ await createPromiseFromStreams([
+ createListStream(['to', 'be', 'or', 'not', 'to', 'be']),
+ createIntersperseStream(' '),
+ createConcatStream(),
+ ])
+ ).toBe('to be or not to be');
+ });
+
+ test('emits values as soon as possible, does not needlessly buffer', async () => {
+ const str = createIntersperseStream('y');
+ const onData = jest.fn();
+ str.on('data', onData);
+
+ str.write('a');
+ expect(onData).toHaveBeenCalledTimes(1);
+ expect(onData.mock.calls[0]).toEqual(['a']);
+ onData.mockClear();
+
+ str.write('b');
+ expect(onData).toHaveBeenCalledTimes(2);
+ expect(onData.mock.calls[0]).toEqual(['y']);
+ expect(onData).toHaveBeenCalledTimes(2);
+ expect(onData.mock.calls[1]).toEqual(['b']);
+ });
+});
diff --git a/packages/kbn-es-archiver/src/lib/streams/intersperse_stream.ts b/packages/kbn-es-archiver/src/lib/streams/intersperse_stream.ts
new file mode 100644
index 0000000000000..eb2e3d3087d4a
--- /dev/null
+++ b/packages/kbn-es-archiver/src/lib/streams/intersperse_stream.ts
@@ -0,0 +1,61 @@
+/*
+ * 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.
+ */
+
+import { Transform } from 'stream';
+
+/**
+ * Create a Transform stream that receives values in object mode,
+ * and intersperses a chunk between each object received.
+ *
+ * This is useful for writing lists:
+ *
+ * createListStream(['foo', 'bar'])
+ * .pipe(createIntersperseStream('\n'))
+ * .pipe(process.stdout) // outputs "foo\nbar"
+ *
+ * Combine with a concat stream to get "join" like functionality:
+ *
+ * await createPromiseFromStreams([
+ * createListStream(['foo', 'bar']),
+ * createIntersperseStream(' '),
+ * createConcatStream()
+ * ]) // produces a single value "foo bar"
+ */
+export function createIntersperseStream(intersperseChunk: any) {
+ let first = true;
+
+ return new Transform({
+ writableObjectMode: true,
+ readableObjectMode: true,
+ transform(chunk, _, callback) {
+ try {
+ if (first) {
+ first = false;
+ } else {
+ this.push(intersperseChunk);
+ }
+
+ this.push(chunk);
+ callback(undefined);
+ } catch (err) {
+ callback(err);
+ }
+ },
+ });
+}
diff --git a/packages/kbn-es-archiver/src/lib/streams/list_stream.test.js b/packages/kbn-es-archiver/src/lib/streams/list_stream.test.js
new file mode 100644
index 0000000000000..12e20696b0510
--- /dev/null
+++ b/packages/kbn-es-archiver/src/lib/streams/list_stream.test.js
@@ -0,0 +1,44 @@
+/*
+ * 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.
+ */
+
+import { createListStream } from './';
+
+describe('listStream', () => {
+ test('provides the values in the initial list', async () => {
+ const str = createListStream([1, 2, 3, 4]);
+ const onData = jest.fn();
+ str.on('data', onData);
+
+ await new Promise((resolve) => str.on('end', resolve));
+
+ expect(onData).toHaveBeenCalledTimes(4);
+ expect(onData.mock.calls[0]).toEqual([1]);
+ expect(onData.mock.calls[1]).toEqual([2]);
+ expect(onData.mock.calls[2]).toEqual([3]);
+ expect(onData.mock.calls[3]).toEqual([4]);
+ });
+
+ test('does not modify the list passed', async () => {
+ const list = [1, 2, 3, 4];
+ const str = createListStream(list);
+ str.resume();
+ await new Promise((resolve) => str.on('end', resolve));
+ expect(list).toEqual([1, 2, 3, 4]);
+ });
+});
diff --git a/packages/kbn-es-archiver/src/lib/streams/list_stream.ts b/packages/kbn-es-archiver/src/lib/streams/list_stream.ts
new file mode 100644
index 0000000000000..c061b969b3c09
--- /dev/null
+++ b/packages/kbn-es-archiver/src/lib/streams/list_stream.ts
@@ -0,0 +1,41 @@
+/*
+ * 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.
+ */
+
+import { Readable } from 'stream';
+
+/**
+ * Create a Readable stream that provides the items
+ * from a list as objects to subscribers
+ */
+export function createListStream(items: any | any[] = []) {
+ const queue: any[] = [].concat(items);
+
+ return new Readable({
+ objectMode: true,
+ read(size) {
+ queue.splice(0, size).forEach((item) => {
+ this.push(item);
+ });
+
+ if (!queue.length) {
+ this.push(null);
+ }
+ },
+ });
+}
diff --git a/packages/kbn-es-archiver/src/lib/streams/map_stream.test.js b/packages/kbn-es-archiver/src/lib/streams/map_stream.test.js
new file mode 100644
index 0000000000000..d86da178f0c1b
--- /dev/null
+++ b/packages/kbn-es-archiver/src/lib/streams/map_stream.test.js
@@ -0,0 +1,61 @@
+/*
+ * 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.
+ */
+
+import { delay } from 'bluebird';
+
+import { createPromiseFromStreams } from './promise_from_streams';
+import { createListStream } from './list_stream';
+import { createMapStream } from './map_stream';
+import { createConcatStream } from './concat_stream';
+
+describe('createMapStream()', () => {
+ test('calls the function with each item in the source stream', async () => {
+ const mapper = jest.fn();
+
+ await createPromiseFromStreams([createListStream(['a', 'b', 'c']), createMapStream(mapper)]);
+
+ expect(mapper).toHaveBeenCalledTimes(3);
+ expect(mapper).toHaveBeenCalledWith('a', 0);
+ expect(mapper).toHaveBeenCalledWith('b', 1);
+ expect(mapper).toHaveBeenCalledWith('c', 2);
+ });
+
+ test('send the return value from the mapper on the output stream', async () => {
+ const result = await createPromiseFromStreams([
+ createListStream([1, 2, 3]),
+ createMapStream((n) => n * 100),
+ createConcatStream([]),
+ ]);
+
+ expect(result).toEqual([100, 200, 300]);
+ });
+
+ test('supports async mappers', async () => {
+ const result = await createPromiseFromStreams([
+ createListStream([1, 2, 3]),
+ createMapStream(async (n, i) => {
+ await delay(n);
+ return n * i;
+ }),
+ createConcatStream([]),
+ ]);
+
+ expect(result).toEqual([0, 2, 6]);
+ });
+});
diff --git a/packages/kbn-es-archiver/src/lib/streams/map_stream.ts b/packages/kbn-es-archiver/src/lib/streams/map_stream.ts
new file mode 100644
index 0000000000000..e88c512a38653
--- /dev/null
+++ b/packages/kbn-es-archiver/src/lib/streams/map_stream.ts
@@ -0,0 +1,36 @@
+/*
+ * 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.
+ */
+
+import { Transform } from 'stream';
+
+export function createMapStream(fn: (chunk: any, i: number) => T | Promise) {
+ let i = 0;
+
+ return new Transform({
+ objectMode: true,
+ async transform(value, _, done) {
+ try {
+ this.push(await fn(value, i++));
+ done();
+ } catch (err) {
+ done(err);
+ }
+ },
+ });
+}
diff --git a/packages/kbn-es-archiver/src/lib/streams/promise_from_streams.test.js b/packages/kbn-es-archiver/src/lib/streams/promise_from_streams.test.js
new file mode 100644
index 0000000000000..e4d9835106f12
--- /dev/null
+++ b/packages/kbn-es-archiver/src/lib/streams/promise_from_streams.test.js
@@ -0,0 +1,136 @@
+/*
+ * 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.
+ */
+
+import { Readable, Writable, Duplex, Transform } from 'stream';
+
+import { createListStream, createPromiseFromStreams, createReduceStream } from './';
+
+describe('promiseFromStreams', () => {
+ test('pipes together an array of streams', async () => {
+ const str1 = createListStream([1, 2, 3]);
+ const str2 = createReduceStream((acc, n) => acc + n, 0);
+ const sumPromise = new Promise((resolve) => str2.once('data', resolve));
+ createPromiseFromStreams([str1, str2]);
+ await new Promise((resolve) => str2.once('end', resolve));
+ expect(await sumPromise).toBe(6);
+ });
+
+ describe('last stream is writable', () => {
+ test('waits for the last stream to finish writing', async () => {
+ let written = '';
+
+ await createPromiseFromStreams([
+ createListStream(['a']),
+ new Writable({
+ write(chunk, enc, cb) {
+ setTimeout(() => {
+ written += chunk;
+ cb();
+ }, 100);
+ },
+ }),
+ ]);
+
+ expect(written).toBe('a');
+ });
+
+ test('resolves to undefined', async () => {
+ const result = await createPromiseFromStreams([
+ createListStream(['a']),
+ new Writable({
+ write(chunk, enc, cb) {
+ cb();
+ },
+ }),
+ ]);
+
+ expect(result).toBe(undefined);
+ });
+ });
+
+ describe('last stream is readable', () => {
+ test(`resolves to it's final value`, async () => {
+ const result = await createPromiseFromStreams([createListStream(['a', 'b', 'c'])]);
+
+ expect(result).toBe('c');
+ });
+ });
+
+ describe('last stream is duplex', () => {
+ test('waits for writing and resolves to final value', async () => {
+ let written = '';
+
+ const duplexReadQueue = [];
+ const duplexItemsToPush = ['foo', 'bar', null];
+ const result = await createPromiseFromStreams([
+ createListStream(['a', 'b', 'c']),
+ new Duplex({
+ async read() {
+ const result = await duplexReadQueue.shift();
+ this.push(result);
+ },
+
+ write(chunk, enc, cb) {
+ duplexReadQueue.push(
+ new Promise((resolve) => {
+ setTimeout(() => {
+ written += chunk;
+ cb();
+ resolve(duplexItemsToPush.shift());
+ }, 50);
+ })
+ );
+ },
+ }).setEncoding('utf8'),
+ ]);
+
+ expect(written).toEqual('abc');
+ expect(result).toBe('bar');
+ });
+ });
+
+ describe('error handling', () => {
+ test('read stream gets destroyed when transform stream fails', async () => {
+ let destroyCalled = false;
+ const readStream = new Readable({
+ read() {
+ this.push('a');
+ this.push('b');
+ this.push('c');
+ this.push(null);
+ },
+ destroy() {
+ destroyCalled = true;
+ },
+ });
+ const transformStream = new Transform({
+ transform(chunk, enc, done) {
+ done(new Error('Test error'));
+ },
+ });
+ try {
+ await createPromiseFromStreams([readStream, transformStream]);
+ throw new Error('Should fail');
+ } catch (e) {
+ expect(e.message).toBe('Test error');
+ expect(destroyCalled).toBe(true);
+ }
+ });
+ });
+});
diff --git a/packages/kbn-es-archiver/src/lib/streams/promise_from_streams.ts b/packages/kbn-es-archiver/src/lib/streams/promise_from_streams.ts
new file mode 100644
index 0000000000000..fefb18be14780
--- /dev/null
+++ b/packages/kbn-es-archiver/src/lib/streams/promise_from_streams.ts
@@ -0,0 +1,64 @@
+/*
+ * 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.
+ */
+
+/**
+ * Take an array of streams, pipe the output
+ * from each one into the next, listening for
+ * errors from any of the streams, and then resolve
+ * the promise once the final stream has finished
+ * writing/reading.
+ *
+ * If the last stream is readable, it's final value
+ * will be provided as the promise value.
+ *
+ * Errors emitted from any stream will cause
+ * the promise to be rejected with that error.
+ */
+
+import { pipeline, Writable } from 'stream';
+import { promisify } from 'util';
+
+const asyncPipeline = promisify(pipeline);
+
+export async function createPromiseFromStreams(streams: any): Promise {
+ let finalChunk: any;
+ const last = streams[streams.length - 1];
+ if (typeof last.read !== 'function' && streams.length === 1) {
+ // For a nicer error than what stream.pipeline throws
+ throw new Error('A minimum of 2 streams is required when a non-readable stream is given');
+ }
+ if (typeof last.read === 'function') {
+ // We are pushing a writable stream to capture the last chunk
+ streams.push(
+ new Writable({
+ // Use object mode even when "last" stream isn't. This allows to
+ // capture the last chunk as-is.
+ objectMode: true,
+ write(chunk, _, done) {
+ finalChunk = chunk;
+ done();
+ },
+ })
+ );
+ }
+
+ await asyncPipeline(...(streams as [any]));
+
+ return finalChunk;
+}
diff --git a/packages/kbn-es-archiver/src/lib/streams/reduce_stream.test.js b/packages/kbn-es-archiver/src/lib/streams/reduce_stream.test.js
new file mode 100644
index 0000000000000..2c073f67f82a8
--- /dev/null
+++ b/packages/kbn-es-archiver/src/lib/streams/reduce_stream.test.js
@@ -0,0 +1,84 @@
+/*
+ * 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.
+ */
+
+import { createReduceStream, createPromiseFromStreams, createListStream } from './';
+
+const promiseFromEvent = (name, emitter) =>
+ new Promise((resolve) => emitter.on(name, () => resolve(name)));
+
+describe('reduceStream', () => {
+ test('calls the reducer for each item provided', async () => {
+ const stub = jest.fn();
+ await createPromiseFromStreams([
+ createListStream([1, 2, 3]),
+ createReduceStream((val, chunk, enc) => {
+ stub(val, chunk, enc);
+ return chunk;
+ }, 0),
+ ]);
+ expect(stub).toHaveBeenCalledTimes(3);
+ expect(stub.mock.calls[0]).toEqual([0, 1, 'utf8']);
+ expect(stub.mock.calls[1]).toEqual([1, 2, 'utf8']);
+ expect(stub.mock.calls[2]).toEqual([2, 3, 'utf8']);
+ });
+
+ test('provides the return value of the last iteration of the reducer', async () => {
+ const result = await createPromiseFromStreams([
+ createListStream('abcdefg'.split('')),
+ createReduceStream((acc) => acc + 1, 0),
+ ]);
+ expect(result).toBe(7);
+ });
+
+ test('emits an error if an iteration fails', async () => {
+ const reduce = createReduceStream((acc, i) => expect(i).toBe(1), 0);
+ const errorEvent = promiseFromEvent('error', reduce);
+
+ reduce.write(1);
+ reduce.write(2);
+ reduce.resume();
+ await errorEvent;
+ });
+
+ test('stops calling the reducer if an iteration fails, emits no data', async () => {
+ const reducer = jest.fn((acc, i) => {
+ if (i < 100) return acc + i;
+ else throw new Error(i);
+ });
+ const reduce$ = createReduceStream(reducer, 0);
+
+ const dataStub = jest.fn();
+ const errorStub = jest.fn();
+ reduce$.on('data', dataStub);
+ reduce$.on('error', errorStub);
+ const endEvent = promiseFromEvent('end', reduce$);
+
+ reduce$.write(1);
+ reduce$.write(2);
+ reduce$.write(300);
+ reduce$.write(400);
+ reduce$.write(1000);
+ reduce$.end();
+
+ await endEvent;
+ expect(reducer).toHaveBeenCalledTimes(3);
+ expect(dataStub).toHaveBeenCalledTimes(0);
+ expect(errorStub).toHaveBeenCalledTimes(1);
+ });
+});
diff --git a/packages/kbn-es-archiver/src/lib/streams/reduce_stream.ts b/packages/kbn-es-archiver/src/lib/streams/reduce_stream.ts
new file mode 100644
index 0000000000000..d9458e9a11c33
--- /dev/null
+++ b/packages/kbn-es-archiver/src/lib/streams/reduce_stream.ts
@@ -0,0 +1,77 @@
+/*
+ * 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.
+ */
+
+import { Transform } from 'stream';
+
+/**
+ * Create a transform stream that consumes each chunk it receives
+ * and passes it to the reducer, which will return the new value
+ * for the stream. Once all chunks have been received the reduce
+ * stream provides the result of final call to the reducer to
+ * subscribers.
+ */
+export function createReduceStream(
+ reducer: (acc: any, chunk: any, env: string) => any,
+ initial: any
+) {
+ let i = -1;
+ let value = initial;
+
+ // if the reducer throws an error then the value is
+ // considered invalid and the stream will never provide
+ // it to subscribers. We will also stop calling the
+ // reducer for any new data that is provided to us
+ let failed = false;
+
+ if (typeof reducer !== 'function') {
+ throw new TypeError('reducer must be a function');
+ }
+
+ return new Transform({
+ readableObjectMode: true,
+ writableObjectMode: true,
+ async transform(chunk, enc, callback) {
+ try {
+ if (failed) {
+ return callback();
+ }
+
+ i += 1;
+ if (i === 0 && initial === undefined) {
+ value = chunk;
+ } else {
+ value = await reducer(value, chunk, enc);
+ }
+
+ callback();
+ } catch (err) {
+ failed = true;
+ callback(err);
+ }
+ },
+
+ flush(callback) {
+ if (!failed) {
+ this.push(value);
+ }
+
+ callback();
+ },
+ });
+}
diff --git a/packages/kbn-es-archiver/src/lib/streams/replace_stream.test.js b/packages/kbn-es-archiver/src/lib/streams/replace_stream.test.js
new file mode 100644
index 0000000000000..01b89f93e5af0
--- /dev/null
+++ b/packages/kbn-es-archiver/src/lib/streams/replace_stream.test.js
@@ -0,0 +1,130 @@
+/*
+ * 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.
+ */
+
+import {
+ createReplaceStream,
+ createConcatStream,
+ createPromiseFromStreams,
+ createListStream,
+ createMapStream,
+} from './';
+
+async function concatToString(streams) {
+ return await createPromiseFromStreams([
+ ...streams,
+ createMapStream((buff) => buff.toString('utf8')),
+ createConcatStream(''),
+ ]);
+}
+
+describe('replaceStream', () => {
+ test('produces buffers when it receives buffers', async () => {
+ const chunks = await createPromiseFromStreams([
+ createListStream([Buffer.from('foo'), Buffer.from('bar')]),
+ createReplaceStream('o', '0'),
+ createConcatStream([]),
+ ]);
+
+ chunks.forEach((chunk) => {
+ expect(chunk).toBeInstanceOf(Buffer);
+ });
+ });
+
+ test('produces buffers when it receives strings', async () => {
+ const chunks = await createPromiseFromStreams([
+ createListStream(['foo', 'bar']),
+ createReplaceStream('o', '0'),
+ createConcatStream([]),
+ ]);
+
+ chunks.forEach((chunk) => {
+ expect(chunk).toBeInstanceOf(Buffer);
+ });
+ });
+
+ test('expects toReplace to be a string', () => {
+ expect(() => createReplaceStream(Buffer.from('foo'))).toThrowError(/be a string/);
+ });
+
+ test('replaces multiple single-char instances in a single chunk', async () => {
+ expect(
+ await concatToString([
+ createListStream([Buffer.from('f00 bar')]),
+ createReplaceStream('0', 'o'),
+ ])
+ ).toBe('foo bar');
+ });
+
+ test('replaces multiple single-char instances in multiple chunks', async () => {
+ expect(
+ await concatToString([
+ createListStream([Buffer.from('f0'), Buffer.from('0 bar')]),
+ createReplaceStream('0', 'o'),
+ ])
+ ).toBe('foo bar');
+ });
+
+ test('replaces single multi-char instances in single chunks', async () => {
+ expect(
+ await concatToString([
+ createListStream([Buffer.from('f0'), Buffer.from('0 bar')]),
+ createReplaceStream('0', 'o'),
+ ])
+ ).toBe('foo bar');
+ });
+
+ test('replaces multiple multi-char instances in single chunks', async () => {
+ expect(
+ await concatToString([
+ createListStream([Buffer.from('foo ba'), Buffer.from('r b'), Buffer.from('az bar')]),
+ createReplaceStream('bar', '*'),
+ ])
+ ).toBe('foo * baz *');
+ });
+
+ test('replaces multi-char instance that stretches multiple chunks', async () => {
+ expect(
+ await concatToString([
+ createListStream([
+ Buffer.from('foo supe'),
+ Buffer.from('rcalifra'),
+ Buffer.from('gilistic'),
+ Buffer.from('expialid'),
+ Buffer.from('ocious bar'),
+ ]),
+ createReplaceStream('supercalifragilisticexpialidocious', '*'),
+ ])
+ ).toBe('foo * bar');
+ });
+
+ test('ignores missing multi-char instance', async () => {
+ expect(
+ await concatToString([
+ createListStream([
+ Buffer.from('foo supe'),
+ Buffer.from('rcalifra'),
+ Buffer.from('gili stic'),
+ Buffer.from('expialid'),
+ Buffer.from('ocious bar'),
+ ]),
+ createReplaceStream('supercalifragilisticexpialidocious', '*'),
+ ])
+ ).toBe('foo supercalifragili sticexpialidocious bar');
+ });
+});
diff --git a/packages/kbn-es-archiver/src/lib/streams/replace_stream.ts b/packages/kbn-es-archiver/src/lib/streams/replace_stream.ts
new file mode 100644
index 0000000000000..fe2ba1fcdf31c
--- /dev/null
+++ b/packages/kbn-es-archiver/src/lib/streams/replace_stream.ts
@@ -0,0 +1,84 @@
+/*
+ * 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.
+ */
+
+import { Transform } from 'stream';
+
+export function createReplaceStream(toReplace: string, replacement: string) {
+ if (typeof toReplace !== 'string') {
+ throw new TypeError('toReplace must be a string');
+ }
+
+ let buffer = Buffer.alloc(0);
+ return new Transform({
+ objectMode: false,
+ async transform(value, _, done) {
+ try {
+ buffer = Buffer.concat([buffer, value], buffer.length + value.length);
+
+ while (true) {
+ // try to find the next instance of `toReplace` in buffer
+ const index = buffer.indexOf(toReplace);
+
+ // if there is no next instance, break
+ if (index === -1) {
+ break;
+ }
+
+ // flush everything to the left of the next instance
+ // of `toReplace`
+ this.push(buffer.slice(0, index));
+
+ // then flush an instance of `replacement`
+ this.push(replacement);
+
+ // and finally update the buffer to include everything
+ // to the right of `toReplace`, dropping to replace from the buffer
+ buffer = buffer.slice(index + toReplace.length);
+ }
+
+ // until now we have only flushed data that is to the left
+ // of a discovered instance of `toReplace`. If `toReplace` is
+ // never found this would lead to us buffering the entire stream.
+ //
+ // Instead, we only keep enough buffer to complete a potentially
+ // partial instance of `toReplace`
+ if (buffer.length > toReplace.length) {
+ // the entire buffer except the last `toReplace.length` bytes
+ // so that if all but one byte from `toReplace` is in the buffer,
+ // and the next chunk delivers the necessary byte, the buffer will then
+ // contain a complete `toReplace` token.
+ this.push(buffer.slice(0, buffer.length - toReplace.length));
+ buffer = buffer.slice(-toReplace.length);
+ }
+
+ done();
+ } catch (err) {
+ done(err);
+ }
+ },
+
+ flush(callback) {
+ if (buffer.length) {
+ this.push(buffer);
+ }
+
+ callback();
+ },
+ });
+}
diff --git a/packages/kbn-es-archiver/src/lib/streams/split_stream.test.js b/packages/kbn-es-archiver/src/lib/streams/split_stream.test.js
new file mode 100644
index 0000000000000..e0736d220ba5c
--- /dev/null
+++ b/packages/kbn-es-archiver/src/lib/streams/split_stream.test.js
@@ -0,0 +1,71 @@
+/*
+ * 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.
+ */
+
+import { createSplitStream, createConcatStream, createPromiseFromStreams } from './';
+
+async function split(stream, input) {
+ const concat = createConcatStream();
+ concat.write([]);
+ stream.pipe(concat);
+ const output = createPromiseFromStreams([concat]);
+
+ input.forEach((i) => {
+ stream.write(i);
+ });
+ stream.end();
+
+ return await output;
+}
+
+describe('splitStream', () => {
+ test('splits buffers, produces strings', async () => {
+ const output = await split(createSplitStream('&'), [Buffer.from('foo&bar')]);
+ expect(output).toEqual(['foo', 'bar']);
+ });
+
+ test('supports mixed input', async () => {
+ const output = await split(createSplitStream('&'), [Buffer.from('foo&b'), 'ar']);
+ expect(output).toEqual(['foo', 'bar']);
+ });
+
+ test('supports buffer split chunks', async () => {
+ const output = await split(createSplitStream(Buffer.from('&')), ['foo&b', 'ar']);
+ expect(output).toEqual(['foo', 'bar']);
+ });
+
+ test('splits provided values by a delimiter', async () => {
+ const output = await split(createSplitStream('&'), ['foo&b', 'ar']);
+ expect(output).toEqual(['foo', 'bar']);
+ });
+
+ test('handles multi-character delimiters', async () => {
+ const output = await split(createSplitStream('oo'), ['foo&b', 'ar']);
+ expect(output).toEqual(['f', '&bar']);
+ });
+
+ test('handles delimiters that span multiple chunks', async () => {
+ const output = await split(createSplitStream('ba'), ['foo&b', 'ar']);
+ expect(output).toEqual(['foo&', 'r']);
+ });
+
+ test('produces an empty chunk if the split char is at the end of the input', async () => {
+ const output = await split(createSplitStream('&bar'), ['foo&b', 'ar']);
+ expect(output).toEqual(['foo', '']);
+ });
+});
diff --git a/packages/kbn-es-archiver/src/lib/streams/split_stream.ts b/packages/kbn-es-archiver/src/lib/streams/split_stream.ts
new file mode 100644
index 0000000000000..1c9b59449bd92
--- /dev/null
+++ b/packages/kbn-es-archiver/src/lib/streams/split_stream.ts
@@ -0,0 +1,71 @@
+/*
+ * 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.
+ */
+
+import { Transform } from 'stream';
+
+/**
+ * Creates a Transform stream that consumes a stream of Buffers
+ * and produces a stream of strings (in object mode) by splitting
+ * the received bytes using the splitChunk.
+ *
+ * Ways this is behaves like String#split:
+ * - instances of splitChunk are removed from the input
+ * - splitChunk can be on any size
+ * - if there are no bytes found after the last splitChunk
+ * a final empty chunk is emitted
+ *
+ * Ways this deviates from String#split:
+ * - splitChunk cannot be a regexp
+ * - an empty string or Buffer will not produce a stream of individual
+ * bytes like `string.split('')` would
+ */
+export function createSplitStream(splitChunk: string) {
+ let unsplitBuffer = Buffer.alloc(0);
+
+ return new Transform({
+ writableObjectMode: false,
+ readableObjectMode: true,
+ transform(chunk, _, callback) {
+ try {
+ let i;
+ let toSplit = Buffer.concat([unsplitBuffer, chunk]);
+ while ((i = toSplit.indexOf(splitChunk)) !== -1) {
+ const slice = toSplit.slice(0, i);
+ toSplit = toSplit.slice(i + splitChunk.length);
+ this.push(slice.toString('utf8'));
+ }
+
+ unsplitBuffer = toSplit;
+ callback(undefined);
+ } catch (err) {
+ callback(err);
+ }
+ },
+
+ flush(callback) {
+ try {
+ this.push(unsplitBuffer.toString('utf8'));
+
+ callback(undefined);
+ } catch (err) {
+ callback(err);
+ }
+ },
+ });
+}
diff --git a/packages/kbn-pm/dist/index.js b/packages/kbn-pm/dist/index.js
index eb2d0d2581a34..9a3bb1c687032 100644
--- a/packages/kbn-pm/dist/index.js
+++ b/packages/kbn-pm/dist/index.js
@@ -27651,6 +27651,7 @@ var eos = function(stream, opts, callback) {
var rs = stream._readableState;
var readable = opts.readable || (opts.readable !== false && stream.readable);
var writable = opts.writable || (opts.writable !== false && stream.writable);
+ var cancelled = false;
var onlegacyfinish = function() {
if (!stream.writable) onfinish();
@@ -27675,8 +27676,13 @@ var eos = function(stream, opts, callback) {
};
var onclose = function() {
- if (readable && !(rs && rs.ended)) return callback.call(stream, new Error('premature close'));
- if (writable && !(ws && ws.ended)) return callback.call(stream, new Error('premature close'));
+ process.nextTick(onclosenexttick);
+ };
+
+ var onclosenexttick = function() {
+ if (cancelled) return;
+ if (readable && !(rs && (rs.ended && !rs.destroyed))) return callback.call(stream, new Error('premature close'));
+ if (writable && !(ws && (ws.ended && !ws.destroyed))) return callback.call(stream, new Error('premature close'));
};
var onrequest = function() {
@@ -27701,6 +27707,7 @@ var eos = function(stream, opts, callback) {
stream.on('close', onclose);
return function() {
+ cancelled = true;
stream.removeListener('complete', onfinish);
stream.removeListener('abort', onclose);
stream.removeListener('request', onrequest);
diff --git a/src/core/public/public.api.md b/src/core/public/public.api.md
index bacbd6e757114..cc37a3c7c0924 100644
--- a/src/core/public/public.api.md
+++ b/src/core/public/public.api.md
@@ -7,6 +7,7 @@
import { Action } from 'history';
import { ApiResponse } from '@elastic/elasticsearch/lib/Transport';
import Boom from 'boom';
+import { ErrorToastOptions as ErrorToastOptions_2 } from 'src/core/public/notifications';
import { EuiBreadcrumb } from '@elastic/eui';
import { EuiButtonEmptyProps } from '@elastic/eui';
import { EuiConfirmModalProps } from '@elastic/eui';
@@ -27,7 +28,9 @@ import { PublicUiSettingsParams as PublicUiSettingsParams_2 } from 'src/core/ser
import React from 'react';
import { RecursiveReadonly } from '@kbn/utility-types';
import * as Rx from 'rxjs';
+import { SavedObject as SavedObject_2 } from 'src/core/server';
import { ShallowPromise } from '@kbn/utility-types';
+import { ToastInputFields as ToastInputFields_2 } from 'src/core/public/notifications';
import { TransportRequestOptions } from '@elastic/elasticsearch/lib/Transport';
import { TransportRequestParams } from '@elastic/elasticsearch/lib/Transport';
import { TransportRequestPromise } from '@elastic/elasticsearch/lib/Transport';
diff --git a/src/core/server/server.api.md b/src/core/server/server.api.md
index 05afad5a4f7a4..2128eb077211f 100644
--- a/src/core/server/server.api.md
+++ b/src/core/server/server.api.md
@@ -40,6 +40,7 @@ import { DeleteScriptParams } from 'elasticsearch';
import { DeleteTemplateParams } from 'elasticsearch';
import { DetailedPeerCertificate } from 'tls';
import { Duration } from 'moment';
+import { ErrorToastOptions } from 'src/core/public/notifications';
import { ExistsParams } from 'elasticsearch';
import { ExplainParams } from 'elasticsearch';
import { FieldStatsParams } from 'elasticsearch';
@@ -118,6 +119,7 @@ import { RenderSearchTemplateParams } from 'elasticsearch';
import { Request } from 'hapi';
import { ResponseObject } from 'hapi';
import { ResponseToolkit } from 'hapi';
+import { SavedObject as SavedObject_2 } from 'src/core/server';
import { SchemaTypeError } from '@kbn/config-schema';
import { ScrollParams } from 'elasticsearch';
import { SearchParams } from 'elasticsearch';
@@ -141,6 +143,7 @@ import { TasksCancelParams } from 'elasticsearch';
import { TasksGetParams } from 'elasticsearch';
import { TasksListParams } from 'elasticsearch';
import { TermvectorsParams } from 'elasticsearch';
+import { ToastInputFields } from 'src/core/public/notifications';
import { TransportRequestOptions } from '@elastic/elasticsearch/lib/Transport';
import { TransportRequestParams } from '@elastic/elasticsearch/lib/Transport';
import { TransportRequestPromise } from '@elastic/elasticsearch/lib/Transport';
diff --git a/src/dev/notice/generate_notice_from_source.ts b/src/dev/notice/generate_notice_from_source.ts
index 0bef5bc5f32d4..9f7eb9d9e1aa4 100644
--- a/src/dev/notice/generate_notice_from_source.ts
+++ b/src/dev/notice/generate_notice_from_source.ts
@@ -41,7 +41,7 @@ interface Options {
* into the repository.
*/
export async function generateNoticeFromSource({ productName, directory, log }: Options) {
- const globs = ['**/*.{js,less,css,ts}'];
+ const globs = ['**/*.{js,less,css,ts,tsx}'];
const options = {
cwd: directory,
diff --git a/src/plugins/data/common/es_query/filters/get_display_value.ts b/src/plugins/data/common/es_query/filters/get_display_value.ts
index 10b4dab3f46ef..28ba0ab629e8f 100644
--- a/src/plugins/data/common/es_query/filters/get_display_value.ts
+++ b/src/plugins/data/common/es_query/filters/get_display_value.ts
@@ -17,30 +17,26 @@
* under the License.
*/
-import { get } from 'lodash';
import { i18n } from '@kbn/i18n';
-import { IIndexPattern, IFieldType } from '../..';
+import { IIndexPattern } from '../..';
import { getIndexPatternFromFilter } from './get_index_pattern_from_filter';
import { Filter } from '../filters';
function getValueFormatter(indexPattern?: IIndexPattern, key?: string) {
- if (!indexPattern || !key) return;
+ // checking getFormatterForField exists because there is at least once case where an index pattern
+ // is an object rather than an IndexPattern class
+ if (!indexPattern || !indexPattern.getFormatterForField || !key) return;
- let format = get(indexPattern, ['fields', 'byName', key, 'format']);
- if (!format && (indexPattern.fields as any).getByName) {
- // TODO: Why is indexPatterns sometimes a map and sometimes an array?
- const field: IFieldType = (indexPattern.fields as any).getByName(key);
- if (!field) {
- throw new Error(
- i18n.translate('data.filter.filterBar.fieldNotFound', {
- defaultMessage: 'Field {key} not found in index pattern {indexPattern}',
- values: { key, indexPattern: indexPattern.title },
- })
- );
- }
- format = field.format;
+ const field = indexPattern.fields.find((f) => f.name === key);
+ if (!field) {
+ throw new Error(
+ i18n.translate('data.filter.filterBar.fieldNotFound', {
+ defaultMessage: 'Field {key} not found in index pattern {indexPattern}',
+ values: { key, indexPattern: indexPattern.title },
+ })
+ );
}
- return format;
+ return indexPattern.getFormatterForField(field);
}
export function getDisplayValueFromFilter(filter: Filter, indexPatterns: IIndexPattern[]): string {
diff --git a/src/plugins/data/common/field_formats/converters/source.ts b/src/plugins/data/common/field_formats/converters/source.ts
index 9c81bb011e127..e7dce82c725d2 100644
--- a/src/plugins/data/common/field_formats/converters/source.ts
+++ b/src/plugins/data/common/field_formats/converters/source.ts
@@ -60,7 +60,7 @@ export class SourceFormat extends FieldFormat {
textConvert: TextContextTypeConvert = (value) => JSON.stringify(value);
htmlConvert: HtmlContextTypeConvert = (value, options = {}) => {
- const { field, hit } = options;
+ const { field, hit, indexPattern } = options;
if (!field) {
const converter = this.getConverterFor('text') as Function;
@@ -69,7 +69,7 @@ export class SourceFormat extends FieldFormat {
}
const highlights = (hit && hit.highlight) || {};
- const formatted = field.indexPattern.formatHit(hit);
+ const formatted = indexPattern.formatHit(hit);
const highlightPairs: any[] = [];
const sourcePairs: any[] = [];
const isShortDots = this.getConfig!(UI_SETTINGS.SHORT_DOTS_ENABLE);
diff --git a/src/plugins/data/common/field_formats/field_formats_registry.ts b/src/plugins/data/common/field_formats/field_formats_registry.ts
index 4b46adf399363..dbc3693c99779 100644
--- a/src/plugins/data/common/field_formats/field_formats_registry.ts
+++ b/src/plugins/data/common/field_formats/field_formats_registry.ts
@@ -181,11 +181,11 @@ export class FieldFormatsRegistry {
* @param {ES_FIELD_TYPES[]} esTypes
* @return {FieldFormat}
*/
- getDefaultInstancePlain(
+ getDefaultInstancePlain = (
fieldType: KBN_FIELD_TYPES,
esTypes?: ES_FIELD_TYPES[],
params: Record = {}
- ): FieldFormat {
+ ): FieldFormat => {
const conf = this.getDefaultConfig(fieldType, esTypes);
const instanceParams = {
...conf.params,
@@ -193,7 +193,7 @@ export class FieldFormatsRegistry {
};
return this.getInstance(conf.id, instanceParams);
- }
+ };
/**
* Returns a cache key built by the given variables for caching in memoized
* Where esType contains fieldType, fieldType is returned
diff --git a/src/plugins/data/common/field_formats/types.ts b/src/plugins/data/common/field_formats/types.ts
index daa44b2b0f85b..af956a20c0dc5 100644
--- a/src/plugins/data/common/field_formats/types.ts
+++ b/src/plugins/data/common/field_formats/types.ts
@@ -27,6 +27,7 @@ export type FieldFormatsContentType = 'html' | 'text';
/** @internal **/
export interface HtmlContextTypeOptions {
field?: any;
+ indexPattern?: any;
hit?: Record;
}
diff --git a/packages/kbn-es-archiver/src/lib/streams.ts b/src/plugins/data/common/index_patterns/errors.ts
similarity index 74%
rename from packages/kbn-es-archiver/src/lib/streams.ts
rename to src/plugins/data/common/index_patterns/errors.ts
index a90afbe0c4d25..3d92bae1968fb 100644
--- a/packages/kbn-es-archiver/src/lib/streams.ts
+++ b/src/plugins/data/common/index_patterns/errors.ts
@@ -17,4 +17,13 @@
* under the License.
*/
-export * from '../../../../src/legacy/utils/streams';
+import { FieldSpec } from './types';
+
+export class FieldTypeUnknownError extends Error {
+ public readonly fieldSpec: FieldSpec;
+ constructor(message: string, spec: FieldSpec) {
+ super(message);
+ this.name = 'FieldTypeUnknownError';
+ this.fieldSpec = spec;
+ }
+}
diff --git a/src/plugins/data/common/index_patterns/fields/__snapshots__/index_pattern_field.test.ts.snap b/src/plugins/data/common/index_patterns/fields/__snapshots__/index_pattern_field.test.ts.snap
index e61593f6bfb27..4279dd320ad62 100644
--- a/src/plugins/data/common/index_patterns/fields/__snapshots__/index_pattern_field.test.ts.snap
+++ b/src/plugins/data/common/index_patterns/fields/__snapshots__/index_pattern_field.test.ts.snap
@@ -14,7 +14,7 @@ Object {
},
"count": 1,
"esTypes": Array [
- "type",
+ "text",
],
"lang": "lang",
"name": "name",
@@ -30,7 +30,7 @@ Object {
"path": "path",
},
},
- "type": "type",
+ "type": "string",
}
`;
@@ -48,7 +48,7 @@ Object {
},
"count": 1,
"esTypes": Array [
- "type",
+ "text",
],
"format": Object {
"id": "number",
@@ -70,6 +70,6 @@ Object {
"path": "path",
},
},
- "type": "type",
+ "type": "string",
}
`;
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 d2489a5d1f7e3..4cf6075869851 100644
--- a/src/plugins/data/common/index_patterns/fields/field_list.ts
+++ b/src/plugins/data/common/index_patterns/fields/field_list.ts
@@ -35,6 +35,7 @@ export interface IIndexPatternFieldList extends Array {
removeAll(): void;
replaceAll(specs: FieldSpec[]): void;
update(field: FieldSpec): void;
+ toSpec(options?: { getFormatterForField?: IndexPattern['getFormatterForField'] }): FieldSpec[];
}
export type CreateIndexPatternFieldList = (
@@ -44,87 +45,79 @@ export type CreateIndexPatternFieldList = (
onNotification?: OnNotification
) => IIndexPatternFieldList;
-export class FieldList extends Array implements IIndexPatternFieldList {
- private byName: FieldMap = new Map();
- private groups: Map = new Map();
- private indexPattern: IndexPattern;
- private shortDotsEnable: boolean;
- private onNotification: OnNotification;
- private setByName = (field: IndexPatternField) => this.byName.set(field.name, field);
- private setByGroup = (field: IndexPatternField) => {
- if (typeof this.groups.get(field.type) === 'undefined') {
- this.groups.set(field.type, new Map());
+// extending the array class and using a constructor doesn't work well
+// when calling filter and similar so wrapping in a callback.
+// to be removed in the future
+export const fieldList = (
+ specs: FieldSpec[] = [],
+ shortDotsEnable = false
+): IIndexPatternFieldList => {
+ class FldList extends Array implements IIndexPatternFieldList {
+ private byName: FieldMap = new Map();
+ private groups: Map = new Map();
+ private setByName = (field: IndexPatternField) => this.byName.set(field.name, field);
+ private setByGroup = (field: IndexPatternField) => {
+ if (typeof this.groups.get(field.type) === 'undefined') {
+ this.groups.set(field.type, new Map());
+ }
+ this.groups.get(field.type)!.set(field.name, field);
+ };
+ private removeByGroup = (field: IFieldType) => this.groups.get(field.type)!.delete(field.name);
+ private calcDisplayName = (name: string) =>
+ shortDotsEnable ? shortenDottedString(name) : name;
+ constructor() {
+ super();
+ specs.map((field) => this.add(field));
}
- this.groups.get(field.type)!.set(field.name, field);
- };
- private removeByGroup = (field: IFieldType) => this.groups.get(field.type)!.delete(field.name);
- private calcDisplayName = (name: string) =>
- this.shortDotsEnable ? shortenDottedString(name) : name;
- constructor(
- indexPattern: IndexPattern,
- specs: FieldSpec[] = [],
- shortDotsEnable = false,
- onNotification: OnNotification = () => {}
- ) {
- super();
- this.indexPattern = indexPattern;
- this.shortDotsEnable = shortDotsEnable;
- this.onNotification = onNotification;
- specs.map((field) => this.add(field));
- }
+ public readonly getAll = () => [...this.byName.values()];
+ public readonly getByName = (name: IndexPatternField['name']) => this.byName.get(name);
+ public readonly getByType = (type: IndexPatternField['type']) => [
+ ...(this.groups.get(type) || new Map()).values(),
+ ];
+ public readonly add = (field: FieldSpec) => {
+ const newField = new IndexPatternField(field, this.calcDisplayName(field.name));
+ this.push(newField);
+ this.setByName(newField);
+ this.setByGroup(newField);
+ };
- public readonly getAll = () => [...this.byName.values()];
- public readonly getByName = (name: IndexPatternField['name']) => this.byName.get(name);
- public readonly getByType = (type: IndexPatternField['type']) => [
- ...(this.groups.get(type) || new Map()).values(),
- ];
- public readonly add = (field: FieldSpec) => {
- const newField = new IndexPatternField(
- this.indexPattern,
- field,
- this.calcDisplayName(field.name),
- this.onNotification
- );
- this.push(newField);
- this.setByName(newField);
- this.setByGroup(newField);
- };
+ public readonly remove = (field: IFieldType) => {
+ this.removeByGroup(field);
+ this.byName.delete(field.name);
- public readonly remove = (field: IFieldType) => {
- this.removeByGroup(field);
- this.byName.delete(field.name);
+ const fieldIndex = findIndex(this, { name: field.name });
+ this.splice(fieldIndex, 1);
+ };
- const fieldIndex = findIndex(this, { name: field.name });
- this.splice(fieldIndex, 1);
- };
+ public readonly update = (field: FieldSpec) => {
+ const newField = new IndexPatternField(field, this.calcDisplayName(field.name));
+ const index = this.findIndex((f) => f.name === newField.name);
+ this.splice(index, 1, newField);
+ this.setByName(newField);
+ this.removeByGroup(newField);
+ this.setByGroup(newField);
+ };
- public readonly update = (field: FieldSpec) => {
- const newField = new IndexPatternField(
- this.indexPattern,
- field,
- this.calcDisplayName(field.name),
- this.onNotification
- );
- const index = this.findIndex((f) => f.name === newField.name);
- this.splice(index, 1, newField);
- this.setByName(newField);
- this.removeByGroup(newField);
- this.setByGroup(newField);
- };
+ public readonly removeAll = () => {
+ this.length = 0;
+ this.byName.clear();
+ this.groups.clear();
+ };
- public readonly removeAll = () => {
- this.length = 0;
- this.byName.clear();
- this.groups.clear();
- };
+ public readonly replaceAll = (spcs: FieldSpec[]) => {
+ this.removeAll();
+ spcs.forEach(this.add);
+ };
- public readonly replaceAll = (specs: FieldSpec[]) => {
- this.removeAll();
- specs.forEach(this.add);
- };
+ public toSpec({
+ getFormatterForField,
+ }: {
+ getFormatterForField?: IndexPattern['getFormatterForField'];
+ } = {}) {
+ return [...this.map((field) => field.toSpec({ getFormatterForField }))];
+ }
+ }
- public readonly toSpec = () => {
- return [...this.map((field) => field.toSpec())];
- };
-}
+ return new FldList();
+};
diff --git a/src/plugins/data/common/index_patterns/fields/index_pattern_field.test.ts b/src/plugins/data/common/index_patterns/fields/index_pattern_field.test.ts
index 0cd0fe8324809..3c4fac81c2c7c 100644
--- a/src/plugins/data/common/index_patterns/fields/index_pattern_field.test.ts
+++ b/src/plugins/data/common/index_patterns/fields/index_pattern_field.test.ts
@@ -19,7 +19,7 @@
import { IndexPatternField } from './index_pattern_field';
import { IndexPattern } from '../index_patterns';
-import { KBN_FIELD_TYPES } from '../../../common';
+import { KBN_FIELD_TYPES, FieldFormat } from '../../../common';
import { FieldSpec } from '../types';
describe('Field', function () {
@@ -28,21 +28,16 @@ describe('Field', function () {
}
function getField(values = {}) {
- return new IndexPatternField(
- fieldValues.indexPattern as IndexPattern,
- { ...fieldValues, ...values },
- 'displayName',
- () => {}
- );
+ return new IndexPatternField({ ...fieldValues, ...values }, 'displayName');
}
const fieldValues = {
name: 'name',
- type: 'type',
+ type: 'string',
script: 'script',
lang: 'lang',
count: 1,
- esTypes: ['type'],
+ esTypes: ['text'],
aggregatable: true,
filterable: true,
searchable: true,
@@ -125,7 +120,7 @@ describe('Field', function () {
const fieldB = getField({ indexed: true, type: KBN_FIELD_TYPES.STRING });
expect(fieldB.sortable).toEqual(true);
- const fieldC = getField({ indexed: false });
+ const fieldC = getField({ indexed: false, aggregatable: false, scripted: false });
expect(fieldC.sortable).toEqual(false);
});
@@ -139,31 +134,26 @@ describe('Field', function () {
const fieldC = getField({ indexed: true, type: KBN_FIELD_TYPES.STRING });
expect(fieldC.filterable).toEqual(true);
- const fieldD = getField({ scripted: false, indexed: false });
+ const fieldD = getField({ scripted: false, indexed: false, searchable: false });
expect(fieldD.filterable).toEqual(false);
});
it('exports the property to JSON', () => {
- const field = new IndexPatternField(
- { fieldFormatMap: { name: {} } } as IndexPattern,
- fieldValues,
- 'displayName',
- () => {}
- );
+ const field = new IndexPatternField(fieldValues, 'displayName');
expect(flatten(field)).toMatchSnapshot();
});
it('spec snapshot', () => {
- const field = new IndexPatternField(
- {
- fieldFormatMap: {
- name: { toJSON: () => ({ id: 'number', params: { pattern: '$0,0.[00]' } }) },
- },
- } as IndexPattern,
- fieldValues,
- 'displayName',
- () => {}
- );
- expect(field.toSpec()).toMatchSnapshot();
+ const field = new IndexPatternField(fieldValues, 'displayName');
+ const getFormatterForField = () =>
+ ({
+ toJSON: () => ({
+ id: 'number',
+ params: {
+ pattern: '$0,0.[00]',
+ },
+ }),
+ } as FieldFormat);
+ expect(field.toSpec({ getFormatterForField })).toMatchSnapshot();
});
});
diff --git a/src/plugins/data/common/index_patterns/fields/index_pattern_field.ts b/src/plugins/data/common/index_patterns/fields/index_pattern_field.ts
index 965f1a7f63065..7f72bfe55c7cd 100644
--- a/src/plugins/data/common/index_patterns/fields/index_pattern_field.ts
+++ b/src/plugins/data/common/index_patterns/fields/index_pattern_field.ts
@@ -20,40 +20,27 @@
import { i18n } from '@kbn/i18n';
import { KbnFieldType, getKbnFieldType } from '../../kbn_field_types';
import { KBN_FIELD_TYPES } from '../../kbn_field_types/types';
-import { FieldFormat } from '../../field_formats';
import { IFieldType } from './types';
-import { OnNotification, FieldSpec } from '../types';
-
-import { IndexPattern } from '../index_patterns';
+import { FieldSpec, IndexPattern } from '../..';
+import { FieldTypeUnknownError } from '../errors';
export class IndexPatternField implements IFieldType {
readonly spec: FieldSpec;
// not writable or serialized
- readonly indexPattern: IndexPattern;
readonly displayName: string;
private readonly kbnFieldType: KbnFieldType;
- constructor(
- indexPattern: IndexPattern,
- spec: FieldSpec,
- displayName: string,
- onNotification: OnNotification
- ) {
- this.indexPattern = indexPattern;
+ constructor(spec: FieldSpec, displayName: string) {
this.spec = { ...spec, type: spec.name === '_source' ? '_source' : spec.type };
this.displayName = displayName;
this.kbnFieldType = getKbnFieldType(spec.type);
if (spec.type && this.kbnFieldType?.name === KBN_FIELD_TYPES.UNKNOWN) {
- const title = i18n.translate('data.indexPatterns.unknownFieldHeader', {
- values: { type: spec.type },
- defaultMessage: 'Unknown field type {type}',
- });
- const text = i18n.translate('data.indexPatterns.unknownFieldErrorMessage', {
- values: { name: spec.name, title: indexPattern.title },
- defaultMessage: 'Field {name} in indexPattern {title} is using an unknown field type.',
+ const msg = i18n.translate('data.indexPatterns.unknownFieldTypeErrorMsg', {
+ values: { type: spec.type, name: spec.name },
+ defaultMessage: `Field '{name}' Unknown field type '{type}'`,
});
- onNotification({ title, text, color: 'danger', iconType: 'alert' });
+ throw new FieldTypeUnknownError(msg, spec);
}
}
@@ -143,10 +130,6 @@ export class IndexPatternField implements IFieldType {
return this.aggregatable;
}
- public get format(): FieldFormat {
- return this.indexPattern.getFormatterForField(this);
- }
-
public toJSON() {
return {
count: this.count,
@@ -165,7 +148,11 @@ export class IndexPatternField implements IFieldType {
};
}
- public toSpec() {
+ public toSpec({
+ getFormatterForField,
+ }: {
+ getFormatterForField?: IndexPattern['getFormatterForField'];
+ } = {}) {
return {
count: this.count,
script: this.script,
@@ -179,7 +166,7 @@ export class IndexPatternField implements IFieldType {
aggregatable: this.aggregatable,
readFromDocValues: this.readFromDocValues,
subType: this.subType,
- format: this.indexPattern?.fieldFormatMap[this.name]?.toJSON() || undefined,
+ format: getFormatterForField ? getFormatterForField(this).toJSON() : undefined,
};
}
}
diff --git a/src/plugins/data/common/index_patterns/fields/types.ts b/src/plugins/data/common/index_patterns/fields/types.ts
index 558b5b57dce40..5814760601a67 100644
--- a/src/plugins/data/common/index_patterns/fields/types.ts
+++ b/src/plugins/data/common/index_patterns/fields/types.ts
@@ -17,7 +17,7 @@
* under the License.
*/
-import { FieldSpec, IFieldSubType } from '../types';
+import { FieldSpec, IFieldSubType, IndexPattern } from '../..';
export interface IFieldType {
name: string;
@@ -38,5 +38,5 @@ export interface IFieldType {
subType?: IFieldSubType;
displayName?: string;
format?: any;
- toSpec?: () => FieldSpec;
+ toSpec?: (options?: { getFormatterForField?: IndexPattern['getFormatterForField'] }) => FieldSpec;
}
diff --git a/src/plugins/data/common/index_patterns/index.ts b/src/plugins/data/common/index_patterns/index.ts
index 51a642b775c29..08f478404be2c 100644
--- a/src/plugins/data/common/index_patterns/index.ts
+++ b/src/plugins/data/common/index_patterns/index.ts
@@ -20,3 +20,5 @@
export * from './fields';
export * from './types';
export { IndexPatternsService } from './index_patterns';
+export type { IndexPattern } from './index_patterns';
+export * from './errors';
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
index 047ac836a87d1..a0c380ec55bf6 100644
--- 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
@@ -32,7 +32,12 @@ Object {
"esTypes": Array [
"boolean",
],
- "format": undefined,
+ "format": Object {
+ "id": "number",
+ "params": Object {
+ "pattern": "$0,0.[00]",
+ },
+ },
"lang": undefined,
"name": "ssl",
"readFromDocValues": true,
@@ -49,7 +54,12 @@ Object {
"esTypes": Array [
"date",
],
- "format": undefined,
+ "format": Object {
+ "id": "number",
+ "params": Object {
+ "pattern": "$0,0.[00]",
+ },
+ },
"lang": undefined,
"name": "@timestamp",
"readFromDocValues": true,
@@ -66,7 +76,12 @@ Object {
"esTypes": Array [
"date",
],
- "format": undefined,
+ "format": Object {
+ "id": "number",
+ "params": Object {
+ "pattern": "$0,0.[00]",
+ },
+ },
"lang": undefined,
"name": "time",
"readFromDocValues": true,
@@ -83,7 +98,12 @@ Object {
"esTypes": Array [
"keyword",
],
- "format": undefined,
+ "format": Object {
+ "id": "number",
+ "params": Object {
+ "pattern": "$0,0.[00]",
+ },
+ },
"lang": undefined,
"name": "@tags",
"readFromDocValues": true,
@@ -100,7 +120,12 @@ Object {
"esTypes": Array [
"date",
],
- "format": undefined,
+ "format": Object {
+ "id": "number",
+ "params": Object {
+ "pattern": "$0,0.[00]",
+ },
+ },
"lang": undefined,
"name": "utc_time",
"readFromDocValues": true,
@@ -117,7 +142,12 @@ Object {
"esTypes": Array [
"integer",
],
- "format": undefined,
+ "format": Object {
+ "id": "number",
+ "params": Object {
+ "pattern": "$0,0.[00]",
+ },
+ },
"lang": undefined,
"name": "phpmemory",
"readFromDocValues": true,
@@ -134,7 +164,12 @@ Object {
"esTypes": Array [
"ip",
],
- "format": undefined,
+ "format": Object {
+ "id": "number",
+ "params": Object {
+ "pattern": "$0,0.[00]",
+ },
+ },
"lang": undefined,
"name": "ip",
"readFromDocValues": true,
@@ -151,7 +186,12 @@ Object {
"esTypes": Array [
"attachment",
],
- "format": undefined,
+ "format": Object {
+ "id": "number",
+ "params": Object {
+ "pattern": "$0,0.[00]",
+ },
+ },
"lang": undefined,
"name": "request_body",
"readFromDocValues": true,
@@ -168,7 +208,12 @@ Object {
"esTypes": Array [
"geo_point",
],
- "format": undefined,
+ "format": Object {
+ "id": "number",
+ "params": Object {
+ "pattern": "$0,0.[00]",
+ },
+ },
"lang": undefined,
"name": "point",
"readFromDocValues": true,
@@ -185,7 +230,12 @@ Object {
"esTypes": Array [
"geo_shape",
],
- "format": undefined,
+ "format": Object {
+ "id": "number",
+ "params": Object {
+ "pattern": "$0,0.[00]",
+ },
+ },
"lang": undefined,
"name": "area",
"readFromDocValues": false,
@@ -202,7 +252,12 @@ Object {
"esTypes": Array [
"murmur3",
],
- "format": undefined,
+ "format": Object {
+ "id": "number",
+ "params": Object {
+ "pattern": "$0,0.[00]",
+ },
+ },
"lang": undefined,
"name": "hashed",
"readFromDocValues": false,
@@ -219,7 +274,12 @@ Object {
"esTypes": Array [
"geo_point",
],
- "format": undefined,
+ "format": Object {
+ "id": "number",
+ "params": Object {
+ "pattern": "$0,0.[00]",
+ },
+ },
"lang": undefined,
"name": "geo.coordinates",
"readFromDocValues": true,
@@ -236,7 +296,12 @@ Object {
"esTypes": Array [
"text",
],
- "format": undefined,
+ "format": Object {
+ "id": "number",
+ "params": Object {
+ "pattern": "$0,0.[00]",
+ },
+ },
"lang": undefined,
"name": "extension",
"readFromDocValues": false,
@@ -253,7 +318,12 @@ Object {
"esTypes": Array [
"keyword",
],
- "format": undefined,
+ "format": Object {
+ "id": "number",
+ "params": Object {
+ "pattern": "$0,0.[00]",
+ },
+ },
"lang": undefined,
"name": "extension.keyword",
"readFromDocValues": true,
@@ -274,7 +344,12 @@ Object {
"esTypes": Array [
"text",
],
- "format": undefined,
+ "format": Object {
+ "id": "number",
+ "params": Object {
+ "pattern": "$0,0.[00]",
+ },
+ },
"lang": undefined,
"name": "machine.os",
"readFromDocValues": false,
@@ -291,7 +366,12 @@ Object {
"esTypes": Array [
"keyword",
],
- "format": undefined,
+ "format": Object {
+ "id": "number",
+ "params": Object {
+ "pattern": "$0,0.[00]",
+ },
+ },
"lang": undefined,
"name": "machine.os.raw",
"readFromDocValues": true,
@@ -312,7 +392,12 @@ Object {
"esTypes": Array [
"keyword",
],
- "format": undefined,
+ "format": Object {
+ "id": "number",
+ "params": Object {
+ "pattern": "$0,0.[00]",
+ },
+ },
"lang": undefined,
"name": "geo.src",
"readFromDocValues": true,
@@ -329,7 +414,12 @@ Object {
"esTypes": Array [
"_id",
],
- "format": undefined,
+ "format": Object {
+ "id": "number",
+ "params": Object {
+ "pattern": "$0,0.[00]",
+ },
+ },
"lang": undefined,
"name": "_id",
"readFromDocValues": false,
@@ -346,7 +436,12 @@ Object {
"esTypes": Array [
"_type",
],
- "format": undefined,
+ "format": Object {
+ "id": "number",
+ "params": Object {
+ "pattern": "$0,0.[00]",
+ },
+ },
"lang": undefined,
"name": "_type",
"readFromDocValues": false,
@@ -363,7 +458,12 @@ Object {
"esTypes": Array [
"_source",
],
- "format": undefined,
+ "format": Object {
+ "id": "number",
+ "params": Object {
+ "pattern": "$0,0.[00]",
+ },
+ },
"lang": undefined,
"name": "_source",
"readFromDocValues": false,
@@ -380,7 +480,12 @@ Object {
"esTypes": Array [
"text",
],
- "format": undefined,
+ "format": Object {
+ "id": "number",
+ "params": Object {
+ "pattern": "$0,0.[00]",
+ },
+ },
"lang": undefined,
"name": "non-filterable",
"readFromDocValues": false,
@@ -397,7 +502,12 @@ Object {
"esTypes": Array [
"text",
],
- "format": undefined,
+ "format": Object {
+ "id": "number",
+ "params": Object {
+ "pattern": "$0,0.[00]",
+ },
+ },
"lang": undefined,
"name": "non-sortable",
"readFromDocValues": false,
@@ -414,7 +524,12 @@ Object {
"esTypes": Array [
"conflict",
],
- "format": undefined,
+ "format": Object {
+ "id": "number",
+ "params": Object {
+ "pattern": "$0,0.[00]",
+ },
+ },
"lang": undefined,
"name": "custom_user_field",
"readFromDocValues": true,
@@ -431,7 +546,12 @@ Object {
"esTypes": Array [
"text",
],
- "format": undefined,
+ "format": Object {
+ "id": "number",
+ "params": Object {
+ "pattern": "$0,0.[00]",
+ },
+ },
"lang": "expression",
"name": "script string",
"readFromDocValues": false,
@@ -448,7 +568,12 @@ Object {
"esTypes": Array [
"long",
],
- "format": undefined,
+ "format": Object {
+ "id": "number",
+ "params": Object {
+ "pattern": "$0,0.[00]",
+ },
+ },
"lang": "expression",
"name": "script number",
"readFromDocValues": false,
@@ -465,7 +590,12 @@ Object {
"esTypes": Array [
"date",
],
- "format": undefined,
+ "format": Object {
+ "id": "number",
+ "params": Object {
+ "pattern": "$0,0.[00]",
+ },
+ },
"lang": "painless",
"name": "script date",
"readFromDocValues": false,
@@ -482,7 +612,12 @@ Object {
"esTypes": Array [
"murmur3",
],
- "format": undefined,
+ "format": Object {
+ "id": "number",
+ "params": Object {
+ "pattern": "$0,0.[00]",
+ },
+ },
"lang": "expression",
"name": "script murmur3",
"readFromDocValues": false,
diff --git a/src/plugins/data/common/index_patterns/index_patterns/format_hit.ts b/src/plugins/data/common/index_patterns/index_patterns/format_hit.ts
index a0597ed4b9026..b47fef107258a 100644
--- a/src/plugins/data/common/index_patterns/index_patterns/format_hit.ts
+++ b/src/plugins/data/common/index_patterns/index_patterns/format_hit.ts
@@ -34,9 +34,9 @@ export function formatHitProvider(indexPattern: IndexPattern, defaultFormat: any
type: FieldFormatsContentType = 'html'
) {
const field = indexPattern.fields.getByName(fieldName);
- const format = field ? field.format : defaultFormat;
+ const format = field ? indexPattern.getFormatterForField(field) : defaultFormat;
- return format.convert(val, type, { field, hit });
+ return format.convert(val, type, { field, hit, indexPattern });
}
function formatHit(hit: Record, type: string = 'html') {
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 f7e1156170f03..f037a71b508a2 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
@@ -29,6 +29,7 @@ import { stubbedSavedObjectIndexPattern } from '../../../../../fixtures/stubbed_
import { IndexPatternField } from '../fields';
import { fieldFormatsMock } from '../../field_formats/mocks';
+import { FieldFormat } from '../..';
class MockFieldFormatter {}
@@ -150,8 +151,6 @@ describe('IndexPattern', () => {
expect(indexPattern).toHaveProperty('getNonScriptedFields');
expect(indexPattern).toHaveProperty('addScriptedField');
expect(indexPattern).toHaveProperty('removeScriptedField');
- expect(indexPattern).toHaveProperty('toString');
- expect(indexPattern).toHaveProperty('toJSON');
expect(indexPattern).toHaveProperty('save');
// properties
@@ -170,7 +169,6 @@ describe('IndexPattern', () => {
test('should have expected properties on fields', function () {
expect(indexPattern.fields[0]).toHaveProperty('displayName');
expect(indexPattern.fields[0]).toHaveProperty('filterable');
- expect(indexPattern.fields[0]).toHaveProperty('format');
expect(indexPattern.fields[0]).toHaveProperty('sortable');
expect(indexPattern.fields[0]).toHaveProperty('scripted');
});
@@ -319,16 +317,18 @@ describe('IndexPattern', () => {
describe('toSpec', () => {
test('should match snapshot', () => {
- indexPattern.fieldFormatMap.bytes = {
+ const formatter = {
toJSON: () => ({ id: 'number', params: { pattern: '$0,0.[00]' } }),
- };
+ } as FieldFormat;
+ indexPattern.getFormatterForField = () => formatter;
expect(indexPattern.toSpec()).toMatchSnapshot();
});
test('can restore from spec', async () => {
- indexPattern.fieldFormatMap.bytes = {
+ const formatter = {
toJSON: () => ({ id: 'number', params: { pattern: '$0,0.[00]' } }),
- };
+ } as FieldFormat;
+ indexPattern.getFormatterForField = () => formatter;
const spec = indexPattern.toSpec();
const restoredPattern = await create(spec.id as string);
restoredPattern.initFromSpec(spec);
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 ea91a9bb14e1f..2feeb5441ab83 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
@@ -26,11 +26,12 @@ import {
ES_FIELD_TYPES,
KBN_FIELD_TYPES,
IIndexPattern,
+ FieldTypeUnknownError,
FieldFormatNotFoundError,
} from '../../../common';
import { findByTitle } from '../utils';
import { IndexPatternMissingIndices } from '../lib';
-import { IndexPatternField, IIndexPatternFieldList, FieldList } from '../fields';
+import { IndexPatternField, IIndexPatternFieldList, fieldList } from '../fields';
import { createFieldsFetcher } from './_fields_fetcher';
import { formatHitProvider } from './format_hit';
import { flattenHitWrapper } from './flatten_hit';
@@ -125,8 +126,7 @@ export class IndexPattern implements IIndexPattern {
this.shortDotsEnable = shortDotsEnable;
this.metaFields = metaFields;
-
- this.fields = new FieldList(this, [], this.shortDotsEnable, this.onNotification);
+ this.fields = fieldList([], this.shortDotsEnable);
this.apiClient = apiClient;
this.fieldsFetcher = createFieldsFetcher(this, apiClient, metaFields);
@@ -138,6 +138,22 @@ export class IndexPattern implements IIndexPattern {
this.formatField = this.formatHit.formatField;
}
+ private unknownFieldErrorNotification(
+ fieldType: string,
+ fieldName: string,
+ indexPatternTitle: string
+ ) {
+ const title = i18n.translate('data.indexPatterns.unknownFieldHeader', {
+ values: { type: fieldType },
+ defaultMessage: 'Unknown field type {type}',
+ });
+ const text = i18n.translate('data.indexPatterns.unknownFieldErrorMessage', {
+ values: { name: fieldName, title: indexPatternTitle },
+ defaultMessage: 'Field {name} in indexPattern {title} is using an unknown field type.',
+ });
+ this.onNotification({ title, text, color: 'danger', iconType: 'alert' });
+ }
+
private serializeFieldFormatMap(flat: any, format: string, field: string | undefined) {
if (format && field) {
flat[field] = format;
@@ -181,7 +197,15 @@ export class IndexPattern implements IIndexPattern {
await this.refreshFields();
} else {
if (specs) {
- this.fields.replaceAll(specs);
+ try {
+ this.fields.replaceAll(specs);
+ } catch (err) {
+ if (err instanceof FieldTypeUnknownError) {
+ this.unknownFieldErrorNotification(err.fieldSpec.name, err.fieldSpec.type, this.title);
+ } else {
+ throw err;
+ }
+ }
}
}
}
@@ -203,7 +227,15 @@ export class IndexPattern implements IIndexPattern {
this.timeFieldName = spec.timeFieldName;
this.sourceFilters = spec.sourceFilters;
- this.fields.replaceAll(spec.fields || []);
+ try {
+ this.fields.replaceAll(spec.fields || []);
+ } catch (err) {
+ if (err instanceof FieldTypeUnknownError) {
+ this.unknownFieldErrorNotification(err.fieldSpec.name, err.fieldSpec.type, this.title);
+ } else {
+ throw err;
+ }
+ }
this.typeMeta = spec.typeMeta;
this.fieldFormatMap = _.mapValues(fieldFormatMap, (mapping) => {
@@ -322,7 +354,7 @@ export class IndexPattern implements IIndexPattern {
title: this.title,
timeFieldName: this.timeFieldName,
sourceFilters: this.sourceFilters,
- fields: this.fields.toSpec(),
+ fields: this.fields.toSpec({ getFormatterForField: this.getFormatterForField.bind(this) }),
typeMeta: this.typeMeta,
};
}
@@ -342,19 +374,27 @@ export class IndexPattern implements IIndexPattern {
throw new DuplicateField(name);
}
- this.fields.add({
- name,
- script,
- type: fieldType,
- scripted: true,
- lang,
- aggregatable: true,
- searchable: true,
- count: 0,
- readFromDocValues: false,
- });
+ try {
+ this.fields.add({
+ name,
+ script,
+ type: fieldType,
+ scripted: true,
+ lang,
+ aggregatable: true,
+ searchable: true,
+ count: 0,
+ readFromDocValues: false,
+ });
+ } catch (err) {
+ if (err instanceof FieldTypeUnknownError) {
+ this.unknownFieldErrorNotification(err.fieldSpec.name, err.fieldSpec.type, this.title);
+ } else {
+ throw err;
+ }
- await this.save();
+ await this.save();
+ }
}
removeScriptedField(fieldName: string) {
@@ -572,7 +612,15 @@ export class IndexPattern implements IIndexPattern {
async _fetchFields() {
const fields = await this.fieldsFetcher.fetch(this);
const scripted = this.getScriptedFields().map((field) => field.spec);
- this.fields.replaceAll([...fields, ...scripted]);
+ try {
+ this.fields.replaceAll([...fields, ...scripted]);
+ } catch (err) {
+ if (err instanceof FieldTypeUnknownError) {
+ this.unknownFieldErrorNotification(err.fieldSpec.name, err.fieldSpec.type, this.title);
+ } else {
+ throw err;
+ }
+ }
}
refreshFields() {
@@ -602,12 +650,4 @@ export class IndexPattern implements IIndexPattern {
});
});
}
-
- toJSON() {
- return this.id;
- }
-
- toString() {
- return '' + this.toJSON();
- }
}
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 0ad9ae8f2014f..fe0d14b2d9c19 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
@@ -25,7 +25,6 @@ import {
createEnsureDefaultIndexPattern,
EnsureDefaultIndexPattern,
} from './ensure_default_index_pattern';
-import { IndexPatternField } from '../fields';
import {
OnNotification,
OnError,
@@ -86,15 +85,6 @@ export class IndexPatternsService {
);
}
- public createField(
- indexPattern: IndexPattern,
- spec: IndexPatternField['spec'],
- displayName: string,
- onNotification: OnNotification
- ) {
- return new IndexPatternField(indexPattern, spec, displayName, onNotification);
- }
-
private async refreshSavedObjectsCache() {
this.savedObjectsCache = await this.savedObjectsClient.find({
type: 'index-pattern',
diff --git a/src/plugins/data/common/search/aggs/agg_config.test.ts b/src/plugins/data/common/search/aggs/agg_config.test.ts
index a443eacee731c..f6fcc29805dc4 100644
--- a/src/plugins/data/common/search/aggs/agg_config.test.ts
+++ b/src/plugins/data/common/search/aggs/agg_config.test.ts
@@ -25,8 +25,7 @@ import { AggType } from './agg_type';
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';
-import { IIndexPatternFieldList } from '../../index_patterns/fields';
+import { IndexPattern, IndexPatternField, IIndexPatternFieldList } from '../../index_patterns';
describe('AggConfig', () => {
let indexPattern: IndexPattern;
@@ -67,6 +66,9 @@ describe('AggConfig', () => {
getByName: (name: string) => fields.find((f) => f.name === name),
filter: () => fields,
} as unknown) as IndexPattern['fields'],
+ getFormatterForField: (field: IndexPatternField) => ({
+ toJSON: () => ({}),
+ }),
} as IndexPattern;
typesRegistry = mockAggTypesRegistry();
});
diff --git a/src/plugins/data/common/search/aggs/agg_type.test.ts b/src/plugins/data/common/search/aggs/agg_type.test.ts
index bf1136159dfe8..16a5586858ab9 100644
--- a/src/plugins/data/common/search/aggs/agg_type.test.ts
+++ b/src/plugins/data/common/search/aggs/agg_type.test.ts
@@ -147,6 +147,9 @@ describe('AggType Class', () => {
},
},
},
+ aggConfigs: {
+ indexPattern: { getFormatterForField: () => ({ toJSON: () => ({ id: 'format' }) }) },
+ },
} as unknown) as IAggConfig;
const aggType = new AggType({
name: 'name',
diff --git a/src/plugins/data/common/search/aggs/agg_type.ts b/src/plugins/data/common/search/aggs/agg_type.ts
index 2ee604c1bf25d..1e3839038b0f7 100644
--- a/src/plugins/data/common/search/aggs/agg_type.ts
+++ b/src/plugins/data/common/search/aggs/agg_type.ts
@@ -271,7 +271,9 @@ export class AggType<
this.getSerializedFormat =
config.getSerializedFormat ||
((agg: TAggConfig) => {
- return agg.params.field ? agg.params.field.format.toJSON() : {};
+ return agg.params.field
+ ? agg.aggConfigs.indexPattern.getFormatterForField(agg.params.field).toJSON()
+ : {};
});
this.getValue = config.getValue || ((agg: TAggConfig, bucket: any) => {});
diff --git a/src/plugins/data/common/search/aggs/buckets/_terms_other_bucket_helper.ts b/src/plugins/data/common/search/aggs/buckets/_terms_other_bucket_helper.ts
index 1a7deafb548ae..7c09d2e64e8b7 100644
--- a/src/plugins/data/common/search/aggs/buckets/_terms_other_bucket_helper.ts
+++ b/src/plugins/data/common/search/aggs/buckets/_terms_other_bucket_helper.ts
@@ -140,7 +140,7 @@ export const buildOtherBucketAgg = (
const bucketAggs = aggConfigs.aggs.filter((agg) => agg.type.type === AggGroupNames.Buckets);
const index = bucketAggs.findIndex((agg) => agg.id === aggWithOtherBucket.id);
const aggs = aggConfigs.toDsl();
- const indexPattern = aggWithOtherBucket.params.field.indexPattern;
+ const indexPattern = aggWithOtherBucket.aggConfigs.indexPattern;
// create filters aggregation
const filterAgg = aggConfigs.createAggConfig(
@@ -211,7 +211,7 @@ export const buildOtherBucketAgg = (
filters.push(
buildExistsFilter(
aggWithOtherBucket.params.field,
- aggWithOtherBucket.params.field.indexPattern
+ aggWithOtherBucket.aggConfigs.indexPattern
)
);
}
@@ -264,7 +264,7 @@ export const mergeOtherBucketAggResponse = (
const phraseFilter = buildPhrasesFilter(
otherAgg.params.field,
requestFilterTerms,
- otherAgg.params.field.indexPattern
+ otherAgg.aggConfigs.indexPattern
);
phraseFilter.meta.negate = true;
bucket.filters = [phraseFilter];
@@ -276,7 +276,7 @@ export const mergeOtherBucketAggResponse = (
)
) {
bucket.filters.push(
- buildExistsFilter(otherAgg.params.field, otherAgg.params.field.indexPattern)
+ buildExistsFilter(otherAgg.params.field, otherAgg.aggConfigs.indexPattern)
);
}
aggResultBuckets.push(bucket);
diff --git a/src/plugins/data/common/search/aggs/buckets/create_filter/histogram.test.ts b/src/plugins/data/common/search/aggs/buckets/create_filter/histogram.test.ts
index b57d530ef40e8..dc1d0ec0a152f 100644
--- a/src/plugins/data/common/search/aggs/buckets/create_filter/histogram.test.ts
+++ b/src/plugins/data/common/search/aggs/buckets/create_filter/histogram.test.ts
@@ -40,6 +40,7 @@ describe('AggConfig Filters', () => {
getByName: () => field,
filter: () => [field],
},
+ getFormatterForField: () => new BytesFormat({}, getConfig),
} as any;
return new AggConfigs(
diff --git a/src/plugins/data/common/search/aggs/buckets/create_filter/range.test.ts b/src/plugins/data/common/search/aggs/buckets/create_filter/range.test.ts
index 30af970f55aa9..b53ae44c05075 100644
--- a/src/plugins/data/common/search/aggs/buckets/create_filter/range.test.ts
+++ b/src/plugins/data/common/search/aggs/buckets/create_filter/range.test.ts
@@ -30,7 +30,6 @@ describe('AggConfig Filters', () => {
const getAggConfigs = () => {
const field = {
name: 'bytes',
- format: new BytesFormat({}, getConfig),
};
const indexPattern = {
@@ -40,6 +39,7 @@ describe('AggConfig Filters', () => {
getByName: () => field,
filter: () => [field],
},
+ getFormatterForField: () => new BytesFormat({}, getConfig),
} as any;
return new AggConfigs(
diff --git a/src/plugins/data/common/search/aggs/buckets/create_filter/terms.ts b/src/plugins/data/common/search/aggs/buckets/create_filter/terms.ts
index 95de19b96abd4..ccd1cf6e358b4 100644
--- a/src/plugins/data/common/search/aggs/buckets/create_filter/terms.ts
+++ b/src/plugins/data/common/search/aggs/buckets/create_filter/terms.ts
@@ -27,7 +27,7 @@ import {
export const createFilterTerms = (aggConfig: IBucketAggConfig, key: string, params: any) => {
const field = aggConfig.params.field;
- const indexPattern = field.indexPattern;
+ const indexPattern = aggConfig.aggConfigs.indexPattern;
if (key === '__other__') {
const terms = params.terms;
diff --git a/src/plugins/data/common/search/aggs/buckets/date_range.ts b/src/plugins/data/common/search/aggs/buckets/date_range.ts
index eda35a77afa5f..f9a3acb990fbf 100644
--- a/src/plugins/data/common/search/aggs/buckets/date_range.ts
+++ b/src/plugins/data/common/search/aggs/buckets/date_range.ts
@@ -58,7 +58,9 @@ export const getDateRangeBucketAgg = ({
getSerializedFormat(agg) {
return {
id: 'date_range',
- params: agg.params.field ? agg.params.field.format.toJSON() : {},
+ params: agg.params.field
+ ? agg.aggConfigs.indexPattern.getFormatterForField(agg.params.field).toJSON()
+ : {},
};
},
makeLabel(aggConfig) {
diff --git a/src/plugins/data/common/search/aggs/buckets/ip_range.ts b/src/plugins/data/common/search/aggs/buckets/ip_range.ts
index 46e0b62d0f8d7..d0a6174b011fc 100644
--- a/src/plugins/data/common/search/aggs/buckets/ip_range.ts
+++ b/src/plugins/data/common/search/aggs/buckets/ip_range.ts
@@ -59,7 +59,9 @@ export const getIpRangeBucketAgg = () =>
getSerializedFormat(agg) {
return {
id: 'ip_range',
- params: agg.params.field ? agg.params.field.format.toJSON() : {},
+ params: agg.params.field
+ ? agg.aggConfigs.indexPattern.getFormatterForField(agg.params.field).toJSON()
+ : {},
};
},
makeLabel(aggConfig) {
diff --git a/src/plugins/data/common/search/aggs/buckets/range.test.ts b/src/plugins/data/common/search/aggs/buckets/range.test.ts
index b23b03db6a9ec..b8241e04ea1ee 100644
--- a/src/plugins/data/common/search/aggs/buckets/range.test.ts
+++ b/src/plugins/data/common/search/aggs/buckets/range.test.ts
@@ -27,12 +27,6 @@ describe('Range Agg', () => {
const getAggConfigs = () => {
const field = {
name: 'bytes',
- format: new NumberFormat(
- {
- pattern: '0,0.[000] b',
- },
- getConfig
- ),
};
const indexPattern = {
@@ -42,6 +36,13 @@ describe('Range Agg', () => {
getByName: () => field,
filter: () => [field],
},
+ getFormatterForField: () =>
+ new NumberFormat(
+ {
+ pattern: '0,0.[000] b',
+ },
+ getConfig
+ ),
} as any;
return new AggConfigs(
diff --git a/src/plugins/data/common/search/aggs/buckets/range.ts b/src/plugins/data/common/search/aggs/buckets/range.ts
index 91a357b635950..169b234845274 100644
--- a/src/plugins/data/common/search/aggs/buckets/range.ts
+++ b/src/plugins/data/common/search/aggs/buckets/range.ts
@@ -78,7 +78,9 @@ export const getRangeBucketAgg = ({ getFieldFormatsStart }: RangeBucketAggDepend
return key;
},
getSerializedFormat(agg) {
- const format = agg.params.field ? agg.params.field.format.toJSON() : {};
+ const format = agg.params.field
+ ? agg.aggConfigs.indexPattern.getFormatterForField(agg.params.field).toJSON()
+ : { id: undefined, params: undefined };
return {
id: 'range',
params: {
diff --git a/src/plugins/data/common/search/aggs/buckets/terms.ts b/src/plugins/data/common/search/aggs/buckets/terms.ts
index 5c8483cf21369..1363d38748c8b 100644
--- a/src/plugins/data/common/search/aggs/buckets/terms.ts
+++ b/src/plugins/data/common/search/aggs/buckets/terms.ts
@@ -82,7 +82,9 @@ export const getTermsBucketAgg = () =>
return agg.getFieldDisplayName() + ': ' + params.order.text;
},
getSerializedFormat(agg) {
- const format = agg.params.field ? agg.params.field.format.toJSON() : {};
+ const format = agg.params.field
+ ? agg.aggConfigs.indexPattern.getFormatterForField(agg.params.field).toJSON()
+ : { id: undefined, params: undefined };
return {
id: 'terms',
params: {
diff --git a/src/plugins/data/common/search/aggs/metrics/parent_pipeline.test.ts b/src/plugins/data/common/search/aggs/metrics/parent_pipeline.test.ts
index c6bba56f73ec7..4815ab0ac56dc 100644
--- a/src/plugins/data/common/search/aggs/metrics/parent_pipeline.test.ts
+++ b/src/plugins/data/common/search/aggs/metrics/parent_pipeline.test.ts
@@ -66,9 +66,6 @@ describe('parent pipeline aggs', function () {
) => {
const field = {
name: 'field',
- format: {
- toJSON: () => ({ id: 'bytes' }),
- },
};
const indexPattern = {
id: '1234',
@@ -77,6 +74,9 @@ describe('parent pipeline aggs', function () {
getByName: () => field,
filter: () => [field],
},
+ getFormatterForField: () => ({
+ toJSON: () => ({ id: 'bytes' }),
+ }),
} as any;
const aggConfigs = new AggConfigs(
diff --git a/src/plugins/data/common/search/aggs/metrics/sibling_pipeline.test.ts b/src/plugins/data/common/search/aggs/metrics/sibling_pipeline.test.ts
index a157d225c839c..32737f7b7237d 100644
--- a/src/plugins/data/common/search/aggs/metrics/sibling_pipeline.test.ts
+++ b/src/plugins/data/common/search/aggs/metrics/sibling_pipeline.test.ts
@@ -72,6 +72,9 @@ describe('sibling pipeline aggs', () => {
getByName: () => field,
filter: () => [field],
},
+ getFormatterForField: () => ({
+ toJSON: () => ({ id: 'bytes' }),
+ }),
} as any;
const aggConfigs = new AggConfigs(
diff --git a/src/plugins/data/public/actions/filters/create_filters_from_value_click.test.ts b/src/plugins/data/public/actions/filters/create_filters_from_value_click.test.ts
index a3b9b0b344823..2ad20c3807819 100644
--- a/src/plugins/data/public/actions/filters/create_filters_from_value_click.test.ts
+++ b/src/plugins/data/public/actions/filters/create_filters_from_value_click.test.ts
@@ -30,11 +30,7 @@ import { ValueClickContext } from '../../../../embeddable/public';
const mockField = {
name: 'bytes',
- indexPattern: {
- id: 'logstash-*',
- },
filterable: true,
- format: new fieldFormats.BytesFormat({}, (() => {}) as FieldFormatsGetConfigFn),
};
describe('createFiltersFromValueClick', () => {
@@ -81,6 +77,8 @@ describe('createFiltersFromValueClick', () => {
getByName: () => mockField,
filter: () => [mockField],
},
+ getFormatterForField: () =>
+ new fieldFormats.BytesFormat({}, (() => {}) as FieldFormatsGetConfigFn),
}),
} as unknown) as IndexPatternsContract);
});
diff --git a/src/plugins/data/public/index.ts b/src/plugins/data/public/index.ts
index 27b16c57ffecf..a9714a95ff338 100644
--- a/src/plugins/data/public/index.ts
+++ b/src/plugins/data/public/index.ts
@@ -262,7 +262,7 @@ export {
UI_SETTINGS,
TypeMeta as IndexPatternTypeMeta,
AggregationRestrictions as IndexPatternAggRestrictions,
- FieldList,
+ fieldList,
} from '../common';
/*
diff --git a/src/plugins/data/public/public.api.md b/src/plugins/data/public/public.api.md
index 0c4465ae7f4b9..e72fea160cc28 100644
--- a/src/plugins/data/public/public.api.md
+++ b/src/plugins/data/public/public.api.md
@@ -604,46 +604,11 @@ export type FieldFormatsContentType = 'html' | 'text';
// @public (undocumented)
export type FieldFormatsGetConfigFn = GetConfigFn;
-// Warning: (ae-missing-release-tag) "FieldList" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
+// Warning: (ae-forgotten-export) The symbol "FieldSpec" needs to be exported by the entry point index.d.ts
+// Warning: (ae-missing-release-tag) "fieldList" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
-export class FieldList extends Array implements IIndexPatternFieldList {
- // Warning: (ae-forgotten-export) The symbol "FieldSpec" needs to be exported by the entry point index.d.ts
- // Warning: (ae-forgotten-export) The symbol "OnNotification" needs to be exported by the entry point index.d.ts
- constructor(indexPattern: IndexPattern, specs?: FieldSpec[], shortDotsEnable?: boolean, onNotification?: OnNotification);
- // (undocumented)
- readonly add: (field: FieldSpec) => void;
- // (undocumented)
- readonly getAll: () => IndexPatternField[];
- // (undocumented)
- readonly getByName: (name: IndexPatternField['name']) => IndexPatternField | undefined;
- // (undocumented)
- readonly getByType: (type: IndexPatternField['type']) => any[];
- // (undocumented)
- readonly remove: (field: IFieldType) => void;
- // (undocumented)
- readonly removeAll: () => void;
- // (undocumented)
- readonly replaceAll: (specs: FieldSpec[]) => void;
- // (undocumented)
- readonly toSpec: () => {
- count: number;
- script: string | undefined;
- lang: string | undefined;
- conflictDescriptions: Record | undefined;
- name: string;
- type: string;
- esTypes: string[] | undefined;
- scripted: boolean;
- searchable: boolean;
- aggregatable: boolean;
- readFromDocValues: boolean;
- subType: import("../types").IFieldSubType | undefined;
- format: any;
- }[];
- // (undocumented)
- readonly update: (field: FieldSpec) => void;
-}
+export const fieldList: (specs?: FieldSpec[], shortDotsEnable?: boolean) => IIndexPatternFieldList;
// @public (undocumented)
export interface FieldMappingSpec {
@@ -868,7 +833,9 @@ export interface IFieldType {
// (undocumented)
subType?: IFieldSubType;
// (undocumented)
- toSpec?: () => FieldSpec;
+ toSpec?: (options?: {
+ getFormatterForField?: IndexPattern['getFormatterForField'];
+ }) => FieldSpec;
// (undocumented)
type: string;
// (undocumented)
@@ -919,6 +886,10 @@ export interface IIndexPatternFieldList extends Array {
// (undocumented)
replaceAll(specs: FieldSpec[]): void;
// (undocumented)
+ toSpec(options?: {
+ getFormatterForField?: IndexPattern['getFormatterForField'];
+ }): FieldSpec[];
+ // (undocumented)
update(field: FieldSpec): void;
}
@@ -1051,12 +1022,8 @@ export class IndexPattern implements IIndexPattern {
// (undocumented)
title: string;
// (undocumented)
- toJSON(): string | undefined;
- // (undocumented)
toSpec(): IndexPatternSpec;
// (undocumented)
- toString(): string;
- // (undocumented)
type: string | undefined;
// (undocumented)
typeMeta?: IndexPatternTypeMeta;
@@ -1100,7 +1067,7 @@ export interface IndexPatternAttributes {
//
// @public (undocumented)
export class IndexPatternField implements IFieldType {
- constructor(indexPattern: IndexPattern, spec: FieldSpec, displayName: string, onNotification: OnNotification);
+ constructor(spec: FieldSpec, displayName: string);
// (undocumented)
get aggregatable(): boolean;
// (undocumented)
@@ -1116,10 +1083,6 @@ export class IndexPatternField implements IFieldType {
// (undocumented)
get filterable(): boolean;
// (undocumented)
- get format(): FieldFormat;
- // (undocumented)
- readonly indexPattern: IndexPattern;
- // (undocumented)
get lang(): string | undefined;
set lang(lang: string | undefined);
// (undocumented)
@@ -1155,7 +1118,9 @@ export class IndexPatternField implements IFieldType {
subType: import("../types").IFieldSubType | undefined;
};
// (undocumented)
- toSpec(): {
+ toSpec({ getFormatterForField, }?: {
+ getFormatterForField?: IndexPattern['getFormatterForField'];
+ }): {
count: number;
script: string | undefined;
lang: string | undefined;
@@ -1168,7 +1133,10 @@ export class IndexPatternField implements IFieldType {
aggregatable: boolean;
readFromDocValues: boolean;
subType: import("../types").IFieldSubType | undefined;
- format: any;
+ format: {
+ id: any;
+ params: any;
+ } | undefined;
};
// (undocumented)
get type(): string;
diff --git a/src/plugins/data/public/search/expressions/create_filter.test.ts b/src/plugins/data/public/search/expressions/create_filter.test.ts
index 7968c80628531..7cc336a1c20e9 100644
--- a/src/plugins/data/public/search/expressions/create_filter.test.ts
+++ b/src/plugins/data/public/search/expressions/create_filter.test.ts
@@ -52,6 +52,7 @@ describe('createFilter', () => {
getByName: () => field,
filter: () => [field],
},
+ getFormatterForField: () => new BytesFormat({}, (() => {}) as FieldFormatsGetConfigFn),
} as any;
return new AggConfigs(
diff --git a/src/plugins/data/server/server.api.md b/src/plugins/data/server/server.api.md
index 9f114f2132009..9497a41b45ff9 100644
--- a/src/plugins/data/server/server.api.md
+++ b/src/plugins/data/server/server.api.md
@@ -565,7 +565,9 @@ export interface IFieldType {
// Warning: (ae-forgotten-export) The symbol "FieldSpec" needs to be exported by the entry point index.d.ts
//
// (undocumented)
- toSpec?: () => FieldSpec;
+ toSpec?: (options?: {
+ getFormatterForField?: IndexPattern['getFormatterForField'];
+ }) => FieldSpec;
// (undocumented)
type: string;
// (undocumented)
@@ -1063,6 +1065,7 @@ export function usageProvider(core: CoreSetup_2): SearchUsage;
// Warnings were encountered during analysis:
//
+// src/plugins/data/common/index_patterns/fields/types.ts:41:25 - (ae-forgotten-export) The symbol "IndexPattern" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:40:23 - (ae-forgotten-export) The symbol "buildCustomFilter" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:40:23 - (ae-forgotten-export) The symbol "buildFilter" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:71:21 - (ae-forgotten-export) The symbol "getEsQueryConfig" needs to be exported by the entry point index.d.ts
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 6d1238e02c7fb..b03b37da40908 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
@@ -62,7 +62,6 @@ function getComponent(selected = false, showDetails = false, useShortDots = fals
);
const field = new IndexPatternField(
- indexPattern,
{
name: 'bytes',
type: 'number',
@@ -73,8 +72,7 @@ function getComponent(selected = false, showDetails = false, useShortDots = fals
aggregatable: true,
readFromDocValues: true,
},
- 'bytes',
- () => {}
+ 'bytes'
);
const props = {
diff --git a/src/plugins/discover/public/application/components/sidebar/discover_sidebar.tsx b/src/plugins/discover/public/application/components/sidebar/discover_sidebar.tsx
index 1f27766a1756d..361c0707fef6b 100644
--- a/src/plugins/discover/public/application/components/sidebar/discover_sidebar.tsx
+++ b/src/plugins/discover/public/application/components/sidebar/discover_sidebar.tsx
@@ -111,8 +111,8 @@ export function DiscoverSidebar({
);
const getDetailsByField = useCallback(
- (ipField: IndexPatternField) => getDetails(ipField, hits, columns),
- [hits, columns]
+ (ipField: IndexPatternField) => getDetails(ipField, hits, columns, selectedIndexPattern),
+ [hits, columns, selectedIndexPattern]
);
const popularLimit = services.uiSettings.get(FIELDS_LIMIT_SETTING);
diff --git a/src/plugins/discover/public/application/components/sidebar/lib/field_calculator.js b/src/plugins/discover/public/application/components/sidebar/lib/field_calculator.js
index e055d644e1f91..0ee279ac5b727 100644
--- a/src/plugins/discover/public/application/components/sidebar/lib/field_calculator.js
+++ b/src/plugins/discover/public/application/components/sidebar/lib/field_calculator.js
@@ -20,9 +20,9 @@
import _ from 'lodash';
import { i18n } from '@kbn/i18n';
-function getFieldValues(hits, field) {
+function getFieldValues(hits, field, indexPattern) {
const name = field.name;
- const flattenHit = field.indexPattern.flattenHit;
+ const flattenHit = indexPattern.flattenHit;
return _.map(hits, function (hit) {
return flattenHit(hit)[name];
});
@@ -49,7 +49,7 @@ function getFieldValueCounts(params) {
};
}
- const allValues = getFieldValues(params.hits, params.field);
+ const allValues = getFieldValues(params.hits, params.field, params.indexPattern);
let counts;
const missing = _countMissing(allValues);
diff --git a/src/plugins/discover/public/application/components/sidebar/lib/field_calculator.test.ts b/src/plugins/discover/public/application/components/sidebar/lib/field_calculator.test.ts
index 87401818c4907..8746883a5d968 100644
--- a/src/plugins/discover/public/application/components/sidebar/lib/field_calculator.test.ts
+++ b/src/plugins/discover/public/application/components/sidebar/lib/field_calculator.test.ts
@@ -148,7 +148,8 @@ describe('fieldCalculator', function () {
it('Should return an array of values for _source fields', function () {
const extensions = fieldCalculator.getFieldValues(
hits,
- indexPattern.fields.getByName('extension')
+ indexPattern.fields.getByName('extension'),
+ indexPattern
);
expect(extensions).toBeInstanceOf(Array);
expect(
@@ -160,7 +161,11 @@ describe('fieldCalculator', function () {
});
it('Should return an array of values for core meta fields', function () {
- const types = fieldCalculator.getFieldValues(hits, indexPattern.fields.getByName('_type'));
+ const types = fieldCalculator.getFieldValues(
+ hits,
+ indexPattern.fields.getByName('_type'),
+ indexPattern
+ );
expect(types).toBeInstanceOf(Array);
expect(
_.filter(types, function (v) {
@@ -172,12 +177,13 @@ describe('fieldCalculator', function () {
});
describe('getFieldValueCounts', function () {
- let params: { hits: any; field: any; count: number };
+ let params: { hits: any; field: any; count: number; indexPattern: IndexPattern };
beforeEach(function () {
params = {
hits: _.cloneDeep(realHits),
field: indexPattern.fields.getByName('extension'),
count: 3,
+ indexPattern,
};
});
diff --git a/src/plugins/discover/public/application/components/sidebar/lib/get_details.ts b/src/plugins/discover/public/application/components/sidebar/lib/get_details.ts
index 41d3393672474..13051f88c9591 100644
--- a/src/plugins/discover/public/application/components/sidebar/lib/get_details.ts
+++ b/src/plugins/discover/public/application/components/sidebar/lib/get_details.ts
@@ -19,17 +19,19 @@
// @ts-ignore
import { fieldCalculator } from './field_calculator';
-import { IndexPatternField } from '../../../../../../data/public';
+import { IndexPattern, IndexPatternField } from '../../../../../../data/public';
export function getDetails(
field: IndexPatternField,
hits: Array>,
- columns: string[]
+ columns: string[],
+ indexPattern: IndexPattern
) {
const details = {
...fieldCalculator.getFieldValueCounts({
hits,
field,
+ indexPattern,
count: 5,
grouped: false,
}),
@@ -37,7 +39,7 @@ export function getDetails(
};
if (details.buckets) {
for (const bucket of details.buckets) {
- bucket.display = field.format.convert(bucket.value);
+ bucket.display = indexPattern.getFormatterForField(field).convert(bucket.value);
}
}
return details;
diff --git a/src/plugins/discover/public/application/components/sidebar/lib/get_index_pattern_field_list.ts b/src/plugins/discover/public/application/components/sidebar/lib/get_index_pattern_field_list.ts
index 00e00aa8e2991..c96a8f5ce17b9 100644
--- a/src/plugins/discover/public/application/components/sidebar/lib/get_index_pattern_field_list.ts
+++ b/src/plugins/discover/public/application/components/sidebar/lib/get_index_pattern_field_list.ts
@@ -31,6 +31,7 @@ export function getIndexPatternFieldList(
difference(fieldNamesInDocs, fieldNamesInIndexPattern).forEach((unknownFieldName) => {
unknownTypes.push({
+ displayName: String(unknownFieldName),
name: String(unknownFieldName),
type: 'unknown',
} as IndexPatternField);
diff --git a/src/plugins/home/public/application/application.tsx b/src/plugins/home/public/application/application.tsx
index 5d71bf8651d88..a4a158bc7dbde 100644
--- a/src/plugins/home/public/application/application.tsx
+++ b/src/plugins/home/public/application/application.tsx
@@ -47,6 +47,13 @@ export const renderApp = async (
chrome.setBreadcrumbs([{ text: homeTitle }]);
+ // dispatch synthetic hash change event to update hash history objects
+ // this is necessary because hash updates triggered by using popState won't trigger this event naturally.
+ // This must be called before the app is mounted to avoid call this after the redirect to default app logic kicks in
+ const unlisten = history.listen((location) => {
+ window.dispatchEvent(new HashChangeEvent('hashchange'));
+ });
+
render(
@@ -54,12 +61,6 @@ export const renderApp = async (
element
);
- // dispatch synthetic hash change event to update hash history objects
- // this is necessary because hash updates triggered by using popState won't trigger this event naturally.
- const unlisten = history.listen(() => {
- window.dispatchEvent(new HashChangeEvent('hashchange'));
- });
-
return () => {
unmountComponentAtNode(element);
unlisten();
diff --git a/src/plugins/index_pattern_management/public/components/edit_index_pattern/indexed_fields_table/__snapshots__/indexed_fields_table.test.tsx.snap b/src/plugins/index_pattern_management/public/components/edit_index_pattern/indexed_fields_table/__snapshots__/indexed_fields_table.test.tsx.snap
index 47cabc4df662f..45253f6ad27c0 100644
--- a/src/plugins/index_pattern_management/public/components/edit_index_pattern/indexed_fields_table/__snapshots__/indexed_fields_table.test.tsx.snap
+++ b/src/plugins/index_pattern_management/public/components/edit_index_pattern/indexed_fields_table/__snapshots__/indexed_fields_table.test.tsx.snap
@@ -15,13 +15,10 @@ exports[`IndexedFieldsTable should filter based on the query bar 1`] = `
"displayName": "Elastic",
"excluded": false,
"format": undefined,
- "indexPattern": Object {
- "getNonScriptedFields": [Function],
- },
"info": Array [],
"name": "Elastic",
"searchable": true,
- "type": "name",
+ "type": "string",
},
]
}
@@ -44,9 +41,6 @@ exports[`IndexedFieldsTable should filter based on the type filter 1`] = `
"displayName": "timestamp",
"excluded": false,
"format": undefined,
- "indexPattern": Object {
- "getNonScriptedFields": [Function],
- },
"info": Array [],
"name": "timestamp",
"type": "date",
@@ -72,21 +66,15 @@ exports[`IndexedFieldsTable should render normally 1`] = `
"displayName": "Elastic",
"excluded": false,
"format": undefined,
- "indexPattern": Object {
- "getNonScriptedFields": [Function],
- },
"info": Array [],
"name": "Elastic",
"searchable": true,
- "type": "name",
+ "type": "string",
},
Object {
"displayName": "timestamp",
"excluded": false,
"format": undefined,
- "indexPattern": Object {
- "getNonScriptedFields": [Function],
- },
"info": Array [],
"name": "timestamp",
"type": "date",
@@ -95,9 +83,6 @@ exports[`IndexedFieldsTable should render normally 1`] = `
"displayName": "conflictingField",
"excluded": false,
"format": undefined,
- "indexPattern": Object {
- "getNonScriptedFields": [Function],
- },
"info": Array [],
"name": "conflictingField",
"type": "conflict",
diff --git a/src/plugins/index_pattern_management/public/components/edit_index_pattern/indexed_fields_table/indexed_fields_table.test.tsx b/src/plugins/index_pattern_management/public/components/edit_index_pattern/indexed_fields_table/indexed_fields_table.test.tsx
index 411bbe23e4761..319b9b2b3fce2 100644
--- a/src/plugins/index_pattern_management/public/components/edit_index_pattern/indexed_fields_table/indexed_fields_table.test.tsx
+++ b/src/plugins/index_pattern_management/public/components/edit_index_pattern/indexed_fields_table/indexed_fields_table.test.tsx
@@ -19,7 +19,7 @@
import React from 'react';
import { shallow } from 'enzyme';
-import { IndexPatternField, IIndexPattern, IndexPattern } from 'src/plugins/data/public';
+import { IndexPatternField, IIndexPattern } from 'src/plugins/data/public';
import { IndexedFieldsTable } from './indexed_fields_table';
jest.mock('@elastic/eui', () => ({
@@ -47,10 +47,8 @@ const indexPattern = ({
const mockFieldToIndexPatternField = (spec: Record) => {
return new IndexPatternField(
- indexPattern as IndexPattern,
(spec as unknown) as IndexPatternField['spec'],
- spec.displayName as string,
- () => {}
+ spec.displayName as string
);
};
@@ -59,7 +57,7 @@ const fields = [
name: 'Elastic',
displayName: 'Elastic',
searchable: true,
- type: 'name',
+ type: 'string',
},
{ name: 'timestamp', displayName: 'timestamp', type: 'date' },
{ name: 'conflictingField', displayName: 'conflictingField', type: 'conflict' },
diff --git a/src/plugins/index_pattern_management/public/components/edit_index_pattern/indexed_fields_table/indexed_fields_table.tsx b/src/plugins/index_pattern_management/public/components/edit_index_pattern/indexed_fields_table/indexed_fields_table.tsx
index 90f81a88b3da0..23977aac7fa7a 100644
--- a/src/plugins/index_pattern_management/public/components/edit_index_pattern/indexed_fields_table/indexed_fields_table.tsx
+++ b/src/plugins/index_pattern_management/public/components/edit_index_pattern/indexed_fields_table/indexed_fields_table.tsx
@@ -77,7 +77,6 @@ export class IndexedFieldsTable extends Component<
return {
...field.spec,
displayName: field.displayName,
- indexPattern: field.indexPattern,
format: getFieldFormat(indexPattern, field.name),
excluded: fieldWildcardMatch ? fieldWildcardMatch(field.name) : false,
info: helpers.getFieldInfo && helpers.getFieldInfo(indexPattern, field),
diff --git a/src/plugins/index_pattern_management/public/components/edit_index_pattern/tabs/tabs.tsx b/src/plugins/index_pattern_management/public/components/edit_index_pattern/tabs/tabs.tsx
index 6c9d6db8de130..3bc9cd34f2984 100644
--- a/src/plugins/index_pattern_management/public/components/edit_index_pattern/tabs/tabs.tsx
+++ b/src/plugins/index_pattern_management/public/components/edit_index_pattern/tabs/tabs.tsx
@@ -176,7 +176,7 @@ export function Tabs({ indexPattern, fields, history, location }: TabsProps) {
indexedFieldTypeFilter={indexedFieldTypeFilter}
helpers={{
redirectToRoute: (field: IndexPatternField) => {
- history.push(getPath(field));
+ history.push(getPath(field, indexPattern));
},
getFieldInfo: indexPatternManagementStart.list.getFieldInfo,
}}
@@ -195,7 +195,7 @@ export function Tabs({ indexPattern, fields, history, location }: TabsProps) {
scriptedFieldLanguageFilter={scriptedFieldLanguageFilter}
helpers={{
redirectToRoute: (field: IndexPatternField) => {
- history.push(getPath(field));
+ history.push(getPath(field, indexPattern));
},
}}
onRemoveField={refreshFilters}
diff --git a/src/plugins/index_pattern_management/public/components/edit_index_pattern/tabs/utils.ts b/src/plugins/index_pattern_management/public/components/edit_index_pattern/tabs/utils.ts
index b422de93de7a9..91c5cc1afdb49 100644
--- a/src/plugins/index_pattern_management/public/components/edit_index_pattern/tabs/utils.ts
+++ b/src/plugins/index_pattern_management/public/components/edit_index_pattern/tabs/utils.ts
@@ -116,8 +116,8 @@ export function getTabs(
return tabs;
}
-export function getPath(field: IndexPatternField) {
- return `/patterns/${field.indexPattern?.id}/field/${field.name}`;
+export function getPath(field: IndexPatternField, indexPattern: IndexPattern) {
+ return `/patterns/${indexPattern?.id}/field/${field.name}`;
}
const allTypesDropDown = i18n.translate(
diff --git a/src/plugins/index_pattern_management/public/components/field_editor/field_editor.test.tsx b/src/plugins/index_pattern_management/public/components/field_editor/field_editor.test.tsx
index 96d3fc549ece0..b0385a61a72ac 100644
--- a/src/plugins/index_pattern_management/public/components/field_editor/field_editor.test.tsx
+++ b/src/plugins/index_pattern_management/public/components/field_editor/field_editor.test.tsx
@@ -138,12 +138,12 @@ describe('FieldEditor', () => {
name: 'test',
script: 'doc.test.value',
};
- fieldList.push(testField as IndexPatternField);
+ fieldList.push((testField as unknown) as IndexPatternField);
indexPattern.fields.getByName = (name) => {
const flds = {
[testField.name]: testField,
};
- return flds[name] as IndexPatternField;
+ return (flds[name] as unknown) as IndexPatternField;
};
const component = createComponentWithContext(
@@ -173,7 +173,7 @@ describe('FieldEditor', () => {
const flds = {
[testField.name]: testField,
};
- return flds[name] as IndexPatternField;
+ return (flds[name] as unknown) as IndexPatternField;
};
const component = createComponentWithContext(
diff --git a/src/plugins/input_control_vis/public/control/control.ts b/src/plugins/input_control_vis/public/control/control.ts
index 91e8f1b26164b..da2dc7bab7cf7 100644
--- a/src/plugins/input_control_vis/public/control/control.ts
+++ b/src/plugins/input_control_vis/public/control/control.ts
@@ -81,9 +81,10 @@ export abstract class Control {
abstract destroy(): void;
format = (value: any) => {
+ const indexPattern = this.filterManager.getIndexPattern();
const field = this.filterManager.getField();
- if (field?.format?.convert) {
- return field.format.convert(value);
+ if (field) {
+ return indexPattern.getFormatterForField(field).convert(value);
}
return value;
diff --git a/src/plugins/visualizations/public/wizard/__snapshots__/new_vis_modal.test.tsx.snap b/src/plugins/visualizations/public/wizard/__snapshots__/new_vis_modal.test.tsx.snap
index 6aed16e937713..3c4c983efa9fa 100644
--- a/src/plugins/visualizations/public/wizard/__snapshots__/new_vis_modal.test.tsx.snap
+++ b/src/plugins/visualizations/public/wizard/__snapshots__/new_vis_modal.test.tsx.snap
@@ -248,7 +248,7 @@ exports[`NewVisModal filter for visualization types should render as expected 1`