diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern._constructor_.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern._constructor_.md
index 6574e7ee37926..0268846772f2c 100644
--- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern._constructor_.md
+++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern._constructor_.md
@@ -9,7 +9,7 @@ Constructs a new instance of the `IndexPattern` class
Signature:
```typescript
-constructor(id: string | undefined, { getConfig, savedObjectsClient, apiClient, patternCache, fieldFormats, onNotification, onError, }: IndexPatternDeps);
+constructor(id: string | undefined, { getConfig, savedObjectsClient, apiClient, patternCache, fieldFormats, onNotification, onError, uiSettingsValues, }: IndexPatternDeps);
```
## Parameters
@@ -17,5 +17,5 @@ constructor(id: string | undefined, { getConfig, savedObjectsClient, apiClient,
| Parameter | Type | Description |
| --- | --- | --- |
| id | string | undefined
| |
-| { getConfig, savedObjectsClient, apiClient, patternCache, fieldFormats, onNotification, onError, } | IndexPatternDeps
| |
+| { getConfig, savedObjectsClient, apiClient, patternCache, fieldFormats, onNotification, onError, uiSettingsValues, } | IndexPatternDeps
| |
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 d39b384c538f1..bc999a3bb48e3 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
@@ -14,7 +14,7 @@ export declare class IndexPattern implements IIndexPattern
| Constructor | Modifiers | Description |
| --- | --- | --- |
-| [(constructor)(id, { getConfig, savedObjectsClient, apiClient, patternCache, fieldFormats, onNotification, onError, })](./kibana-plugin-plugins-data-public.indexpattern._constructor_.md) | | Constructs a new instance of the IndexPattern
class |
+| [(constructor)(id, { getConfig, savedObjectsClient, apiClient, patternCache, fieldFormats, onNotification, onError, uiSettingsValues, })](./kibana-plugin-plugins-data-public.indexpattern._constructor_.md) | | Constructs a new instance of the IndexPattern
class |
## Properties
diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternattributes.fieldformatmap.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternattributes.fieldformatmap.md
new file mode 100644
index 0000000000000..9a454feab1e0e
--- /dev/null
+++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternattributes.fieldformatmap.md
@@ -0,0 +1,11 @@
+
+
+[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [IndexPatternAttributes](./kibana-plugin-plugins-data-public.indexpatternattributes.md) > [fieldFormatMap](./kibana-plugin-plugins-data-public.indexpatternattributes.fieldformatmap.md)
+
+## IndexPatternAttributes.fieldFormatMap property
+
+Signature:
+
+```typescript
+fieldFormatMap?: string;
+```
diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternattributes.intervalname.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternattributes.intervalname.md
new file mode 100644
index 0000000000000..5902496fcd0e7
--- /dev/null
+++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternattributes.intervalname.md
@@ -0,0 +1,11 @@
+
+
+[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [IndexPatternAttributes](./kibana-plugin-plugins-data-public.indexpatternattributes.md) > [intervalName](./kibana-plugin-plugins-data-public.indexpatternattributes.intervalname.md)
+
+## IndexPatternAttributes.intervalName property
+
+Signature:
+
+```typescript
+intervalName?: string;
+```
diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternattributes.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternattributes.md
index 39ae328c14501..eff2349f053ff 100644
--- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternattributes.md
+++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternattributes.md
@@ -20,7 +20,10 @@ export interface IndexPatternAttributes
| Property | Type | Description |
| --- | --- | --- |
+| [fieldFormatMap](./kibana-plugin-plugins-data-public.indexpatternattributes.fieldformatmap.md) | string
| |
| [fields](./kibana-plugin-plugins-data-public.indexpatternattributes.fields.md) | string
| |
+| [intervalName](./kibana-plugin-plugins-data-public.indexpatternattributes.intervalname.md) | string
| |
+| [sourceFilters](./kibana-plugin-plugins-data-public.indexpatternattributes.sourcefilters.md) | string
| |
| [timeFieldName](./kibana-plugin-plugins-data-public.indexpatternattributes.timefieldname.md) | string
| |
| [title](./kibana-plugin-plugins-data-public.indexpatternattributes.title.md) | string
| |
| [type](./kibana-plugin-plugins-data-public.indexpatternattributes.type.md) | string
| |
diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternattributes.sourcefilters.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternattributes.sourcefilters.md
new file mode 100644
index 0000000000000..43966112b97c3
--- /dev/null
+++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternattributes.sourcefilters.md
@@ -0,0 +1,11 @@
+
+
+[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [IndexPatternAttributes](./kibana-plugin-plugins-data-public.indexpatternattributes.md) > [sourceFilters](./kibana-plugin-plugins-data-public.indexpatternattributes.sourcefilters.md)
+
+## IndexPatternAttributes.sourceFilters property
+
+Signature:
+
+```typescript
+sourceFilters?: string;
+```
diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpatternattributes.fieldformatmap.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpatternattributes.fieldformatmap.md
new file mode 100644
index 0000000000000..84cc8c705ff59
--- /dev/null
+++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpatternattributes.fieldformatmap.md
@@ -0,0 +1,11 @@
+
+
+[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [IndexPatternAttributes](./kibana-plugin-plugins-data-server.indexpatternattributes.md) > [fieldFormatMap](./kibana-plugin-plugins-data-server.indexpatternattributes.fieldformatmap.md)
+
+## IndexPatternAttributes.fieldFormatMap property
+
+Signature:
+
+```typescript
+fieldFormatMap?: string;
+```
diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpatternattributes.intervalname.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpatternattributes.intervalname.md
new file mode 100644
index 0000000000000..77a0872546679
--- /dev/null
+++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpatternattributes.intervalname.md
@@ -0,0 +1,11 @@
+
+
+[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [IndexPatternAttributes](./kibana-plugin-plugins-data-server.indexpatternattributes.md) > [intervalName](./kibana-plugin-plugins-data-server.indexpatternattributes.intervalname.md)
+
+## IndexPatternAttributes.intervalName property
+
+Signature:
+
+```typescript
+intervalName?: string;
+```
diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpatternattributes.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpatternattributes.md
index 1fcc49796f59e..4a5b61f5c179b 100644
--- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpatternattributes.md
+++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpatternattributes.md
@@ -20,7 +20,10 @@ export interface IndexPatternAttributes
| Property | Type | Description |
| --- | --- | --- |
+| [fieldFormatMap](./kibana-plugin-plugins-data-server.indexpatternattributes.fieldformatmap.md) | string
| |
| [fields](./kibana-plugin-plugins-data-server.indexpatternattributes.fields.md) | string
| |
+| [intervalName](./kibana-plugin-plugins-data-server.indexpatternattributes.intervalname.md) | string
| |
+| [sourceFilters](./kibana-plugin-plugins-data-server.indexpatternattributes.sourcefilters.md) | string
| |
| [timeFieldName](./kibana-plugin-plugins-data-server.indexpatternattributes.timefieldname.md) | string
| |
| [title](./kibana-plugin-plugins-data-server.indexpatternattributes.title.md) | string
| |
| [type](./kibana-plugin-plugins-data-server.indexpatternattributes.type.md) | string
| |
diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpatternattributes.sourcefilters.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpatternattributes.sourcefilters.md
new file mode 100644
index 0000000000000..10223a6353f10
--- /dev/null
+++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpatternattributes.sourcefilters.md
@@ -0,0 +1,11 @@
+
+
+[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [IndexPatternAttributes](./kibana-plugin-plugins-data-server.indexpatternattributes.md) > [sourceFilters](./kibana-plugin-plugins-data-server.indexpatternattributes.sourcefilters.md)
+
+## IndexPatternAttributes.sourceFilters property
+
+Signature:
+
+```typescript
+sourceFilters?: string;
+```
diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.plugin.start.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.plugin.start.md
index 2c7a833ab641b..74bffc516725f 100644
--- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.plugin.start.md
+++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.plugin.start.md
@@ -12,6 +12,9 @@ start(core: CoreStart): {
fieldFormats: {
fieldFormatServiceFactory: (uiSettings: import("../../../core/server").IUiSettingsClient) => Promise;
};
+ indexPatterns: {
+ indexPatternsServiceFactory: (kibanaRequest: import("../../../core/server").KibanaRequest) => Promise;
+ };
};
```
@@ -28,5 +31,8 @@ start(core: CoreStart): {
fieldFormats: {
fieldFormatServiceFactory: (uiSettings: import("../../../core/server").IUiSettingsClient) => Promise;
};
+ indexPatterns: {
+ indexPatternsServiceFactory: (kibanaRequest: import("../../../core/server").KibanaRequest) => Promise;
+ };
}`
diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.pluginstart.indexpatterns.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.pluginstart.indexpatterns.md
new file mode 100644
index 0000000000000..02ed24e05bc10
--- /dev/null
+++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.pluginstart.indexpatterns.md
@@ -0,0 +1,11 @@
+
+
+[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [PluginStart](./kibana-plugin-plugins-data-server.pluginstart.md) > [indexPatterns](./kibana-plugin-plugins-data-server.pluginstart.indexpatterns.md)
+
+## PluginStart.indexPatterns property
+
+Signature:
+
+```typescript
+indexPatterns: IndexPatternsServiceStart;
+```
diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.pluginstart.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.pluginstart.md
index 1377d82123d41..b878a179657ed 100644
--- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.pluginstart.md
+++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.pluginstart.md
@@ -15,5 +15,6 @@ export interface DataPluginStart
| Property | Type | Description |
| --- | --- | --- |
| [fieldFormats](./kibana-plugin-plugins-data-server.pluginstart.fieldformats.md) | FieldFormatsStart
| |
+| [indexPatterns](./kibana-plugin-plugins-data-server.pluginstart.indexpatterns.md) | IndexPatternsServiceStart
| |
| [search](./kibana-plugin-plugins-data-server.pluginstart.search.md) | ISearchStart
| |
diff --git a/src/fixtures/stubbed_saved_object_index_pattern.js b/src/fixtures/stubbed_saved_object_index_pattern.ts
similarity index 87%
rename from src/fixtures/stubbed_saved_object_index_pattern.js
rename to src/fixtures/stubbed_saved_object_index_pattern.ts
index 8e0e230ef33dd..02e6cb85e341f 100644
--- a/src/fixtures/stubbed_saved_object_index_pattern.js
+++ b/src/fixtures/stubbed_saved_object_index_pattern.ts
@@ -17,13 +17,13 @@
* under the License.
*/
+// @ts-expect-error
import stubbedLogstashFields from './logstash_fields';
-import { SimpleSavedObject } from '../core/public';
const mockLogstashFields = stubbedLogstashFields();
-export function stubbedSavedObjectIndexPattern(id) {
- return new SimpleSavedObject(undefined, {
+export function stubbedSavedObjectIndexPattern(id: string | null = null) {
+ return {
id,
type: 'index-pattern',
attributes: {
@@ -32,5 +32,5 @@ export function stubbedSavedObjectIndexPattern(id) {
fields: mockLogstashFields,
},
version: 2,
- });
+ };
}
diff --git a/src/plugins/data/common/index_patterns/index.ts b/src/plugins/data/common/index_patterns/index.ts
index d26587efccc0f..51a642b775c29 100644
--- a/src/plugins/data/common/index_patterns/index.ts
+++ b/src/plugins/data/common/index_patterns/index.ts
@@ -19,3 +19,4 @@
export * from './fields';
export * from './types';
+export { IndexPatternsService } from './index_patterns';
diff --git a/src/plugins/data/common/index_patterns/index_patterns/_fields_fetcher.ts b/src/plugins/data/common/index_patterns/index_patterns/_fields_fetcher.ts
index 727c4d445688d..baeb1587d57a9 100644
--- a/src/plugins/data/common/index_patterns/index_patterns/_fields_fetcher.ts
+++ b/src/plugins/data/common/index_patterns/index_patterns/_fields_fetcher.ts
@@ -17,7 +17,8 @@
* under the License.
*/
-import { GetFieldsOptions, IIndexPatternsApiClient, IndexPattern } from '.';
+import { IndexPattern } from '.';
+import { GetFieldsOptions, IIndexPatternsApiClient } from '../types';
/** @internal */
export const createFieldsFetcher = (
diff --git a/src/plugins/data/common/index_patterns/index_patterns/ensure_default_index_pattern.ts b/src/plugins/data/common/index_patterns/index_patterns/ensure_default_index_pattern.ts
index 2737627bf1977..26f1a185ada3a 100644
--- a/src/plugins/data/common/index_patterns/index_patterns/ensure_default_index_pattern.ts
+++ b/src/plugins/data/common/index_patterns/index_patterns/ensure_default_index_pattern.ts
@@ -18,13 +18,13 @@
*/
import { contains } from 'lodash';
-import { CoreStart } from 'kibana/public';
import { IndexPatternsContract } from './index_patterns';
+import { UiSettingsCommon } from '../types';
export type EnsureDefaultIndexPattern = () => Promise | undefined;
export const createEnsureDefaultIndexPattern = (
- uiSettings: CoreStart['uiSettings'],
+ uiSettings: UiSettingsCommon,
onRedirectNoIndexPattern: () => Promise | void
) => {
/**
@@ -33,12 +33,12 @@ export const createEnsureDefaultIndexPattern = (
*/
return async function ensureDefaultIndexPattern(this: IndexPatternsContract) {
const patterns = await this.getIds();
- let defaultId = uiSettings.get('defaultIndex');
+ let defaultId = await uiSettings.get('defaultIndex');
let defined = !!defaultId;
const exists = contains(patterns, defaultId);
if (defined && !exists) {
- uiSettings.remove('defaultIndex');
+ await uiSettings.remove('defaultIndex');
defaultId = defined = false;
}
@@ -49,7 +49,7 @@ export const createEnsureDefaultIndexPattern = (
// If there is any index pattern created, set the first as default
if (patterns.length >= 1) {
defaultId = patterns[0];
- uiSettings.set('defaultIndex', defaultId);
+ await uiSettings.set('defaultIndex', defaultId);
} else {
return onRedirectNoIndexPattern();
}
diff --git a/src/plugins/data/common/index_patterns/index_patterns/index.ts b/src/plugins/data/common/index_patterns/index_patterns/index.ts
index 77527857ed0ca..31cd06b7dd0ea 100644
--- a/src/plugins/data/common/index_patterns/index_patterns/index.ts
+++ b/src/plugins/data/common/index_patterns/index_patterns/index.ts
@@ -17,7 +17,6 @@
* under the License.
*/
-export * from './index_patterns_api_client';
export * from './_pattern_cache';
export * from './flatten_hit';
export * from './format_hit';
diff --git a/src/plugins/data/common/index_patterns/index_patterns/index_pattern.test.ts b/src/plugins/data/common/index_patterns/index_patterns/index_pattern.test.ts
index ba8e4f6fb3695..7fb1210fe1f32 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
@@ -66,7 +66,7 @@ const savedObjectsClient = {
create: jest.fn(),
get: jest.fn().mockImplementation(() => object),
update: jest.fn().mockImplementation(async (type, id, body, { version }) => {
- if (object._version !== version) {
+ if (object.version !== version) {
throw new Object({
res: {
status: 409,
@@ -74,10 +74,10 @@ const savedObjectsClient = {
});
}
object.attributes.title = body.title;
- object._version += 'a';
+ object.version += 'a';
return {
- id: object._id,
- _version: object._version,
+ id: object.id,
+ version: object.version,
};
}),
};
@@ -109,6 +109,7 @@ function create(id: string, payload?: any): Promise {
fieldFormats: fieldFormatsMock,
onNotification: () => {},
onError: () => {},
+ uiSettingsValues: { shortDotsEnable: false, metaFields: [] },
});
setDocsourcePayload(id, payload);
@@ -382,8 +383,8 @@ describe('IndexPattern', () => {
test('should handle version conflicts', async () => {
setDocsourcePayload(null, {
- _id: 'foo',
- _version: 'foo',
+ id: 'foo',
+ version: 'foo',
attributes: {
title: 'something',
},
@@ -397,6 +398,7 @@ describe('IndexPattern', () => {
fieldFormats: fieldFormatsMock,
onNotification: () => {},
onError: () => {},
+ uiSettingsValues: { shortDotsEnable: false, metaFields: [] },
});
await pattern.init();
@@ -411,6 +413,7 @@ describe('IndexPattern', () => {
fieldFormats: fieldFormatsMock,
onNotification: () => {},
onError: () => {},
+ uiSettingsValues: { shortDotsEnable: false, metaFields: [] },
});
await samePattern.init();
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 e9ac5a09b9db3..bde550c660a32 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
@@ -19,25 +19,23 @@
import _, { each, reject } from 'lodash';
import { i18n } from '@kbn/i18n';
-import { SavedObjectsClientContract } from 'src/core/public';
-import { SavedObjectAttributes } from 'src/core/public';
+import { SavedObjectsClientCommon } from '../..';
import { DuplicateField, SavedObjectNotFound } from '../../../../kibana_utils/common';
-import {
- ES_FIELD_TYPES,
- KBN_FIELD_TYPES,
- IIndexPattern,
- IFieldType,
- UI_SETTINGS,
-} from '../../../common';
+import { ES_FIELD_TYPES, KBN_FIELD_TYPES, IIndexPattern, IFieldType } from '../../../common';
import { findByTitle } from '../utils';
import { IndexPatternMissingIndices } from '../lib';
import { Field, IIndexPatternFieldList, getIndexPatternFieldListCreator } from '../fields';
import { createFieldsFetcher } from './_fields_fetcher';
import { formatHitProvider } from './format_hit';
import { flattenHitWrapper } from './flatten_hit';
-import { IIndexPatternsApiClient } from '.';
-import { OnNotification, OnError } from '../types';
+import {
+ OnNotification,
+ OnError,
+ UiSettingsCommon,
+ IIndexPatternsApiClient,
+ IndexPatternAttributes,
+} from '../types';
import { FieldFormatsStartCommon } from '../../field_formats';
import { PatternCache } from './_pattern_cache';
import { expandShorthand, FieldMappingSpec, MappingObject } from '../../field_mapping';
@@ -45,16 +43,22 @@ import { IndexPatternSpec, TypeMeta, FieldSpec, SourceFilter } from '../types';
import { SerializedFieldFormat } from '../../../../expressions/common';
const MAX_ATTEMPTS_TO_RESOLVE_CONFLICTS = 3;
-const type = 'index-pattern';
+const savedObjectType = 'index-pattern';
+interface IUiSettingsValues {
+ [key: string]: any;
+ shortDotsEnable: any;
+ metaFields: any;
+}
interface IndexPatternDeps {
- getConfig: any;
- savedObjectsClient: SavedObjectsClientContract;
+ getConfig: UiSettingsCommon['get'];
+ savedObjectsClient: SavedObjectsClientCommon;
apiClient: IIndexPatternsApiClient;
patternCache: PatternCache;
fieldFormats: FieldFormatsStartCommon;
onNotification: OnNotification;
onError: OnError;
+ uiSettingsValues: IUiSettingsValues;
}
export class IndexPattern implements IIndexPattern {
@@ -72,9 +76,9 @@ export class IndexPattern implements IIndexPattern {
public metaFields: string[];
private version: string | undefined;
- private savedObjectsClient: SavedObjectsClientContract;
+ private savedObjectsClient: SavedObjectsClientCommon;
private patternCache: PatternCache;
- private getConfig: any;
+ private getConfig: UiSettingsCommon['get'];
private sourceFilters?: SourceFilter[];
private originalBody: { [key: string]: any } = {};
public fieldsFetcher: any; // probably want to factor out any direct usage and change to private
@@ -83,6 +87,7 @@ export class IndexPattern implements IIndexPattern {
private onNotification: OnNotification;
private onError: OnError;
private apiClient: IIndexPatternsApiClient;
+ private uiSettingsValues: IUiSettingsValues;
private mapping: MappingObject = expandShorthand({
title: ES_FIELD_TYPES.TEXT,
@@ -116,6 +121,7 @@ export class IndexPattern implements IIndexPattern {
fieldFormats,
onNotification,
onError,
+ uiSettingsValues,
}: IndexPatternDeps
) {
this.id = id;
@@ -127,9 +133,10 @@ export class IndexPattern implements IIndexPattern {
this.fieldFormats = fieldFormats;
this.onNotification = onNotification;
this.onError = onError;
+ this.uiSettingsValues = uiSettingsValues;
- this.shortDotsEnable = this.getConfig(UI_SETTINGS.SHORT_DOTS_ENABLE);
- this.metaFields = this.getConfig(UI_SETTINGS.META_FIELDS);
+ this.shortDotsEnable = uiSettingsValues.shortDotsEnable;
+ this.metaFields = uiSettingsValues.metaFields;
this.createFieldList = getIndexPatternFieldListCreator({
fieldFormats,
@@ -138,12 +145,8 @@ export class IndexPattern implements IIndexPattern {
this.fields = this.createFieldList(this, [], this.shortDotsEnable);
this.apiClient = apiClient;
- this.fieldsFetcher = createFieldsFetcher(
- this,
- apiClient,
- this.getConfig(UI_SETTINGS.META_FIELDS)
- );
- this.flattenHit = flattenHitWrapper(this, this.getConfig(UI_SETTINGS.META_FIELDS));
+ this.fieldsFetcher = createFieldsFetcher(this, apiClient, uiSettingsValues.metaFields);
+ this.flattenHit = flattenHitWrapper(this, uiSettingsValues.metaFields);
this.formatHit = formatHitProvider(
this,
fieldFormats.getDefaultInstance(KBN_FIELD_TYPES.STRING)
@@ -160,7 +163,13 @@ export class IndexPattern implements IIndexPattern {
private deserializeFieldFormatMap(mapping: any) {
const FieldFormat = this.fieldFormats.getType(mapping.id);
- return FieldFormat && new FieldFormat(mapping.params, this.getConfig);
+ return (
+ FieldFormat &&
+ new FieldFormat(
+ mapping.params,
+ (key: string) => this.uiSettingsValues[key]?.userValue || this.uiSettingsValues[key]?.value
+ )
+ );
}
private initFields(input?: any) {
@@ -228,7 +237,7 @@ export class IndexPattern implements IIndexPattern {
private updateFromElasticSearch(response: any, forceFieldRefresh: boolean = false) {
if (!response.found) {
- throw new SavedObjectNotFound(type, this.id, 'management/kibana/indexPatterns');
+ throw new SavedObjectNotFound(savedObjectType, this.id, 'management/kibana/indexPatterns');
}
_.forOwn(this.mapping, (fieldMapping: FieldMappingSpec, name: string | undefined) => {
@@ -296,12 +305,22 @@ export class IndexPattern implements IIndexPattern {
return this; // no id === no elasticsearch document
}
- const savedObject = await this.savedObjectsClient.get(type, this.id);
+ const savedObject = await this.savedObjectsClient.get(
+ savedObjectType,
+ this.id
+ );
const response = {
- version: savedObject._version,
- found: savedObject._version ? true : false,
- ...(_.cloneDeep(savedObject.attributes) as SavedObjectAttributes),
+ version: savedObject.version,
+ found: savedObject.version ? true : false,
+ title: savedObject.attributes.title,
+ timeFieldName: savedObject.attributes.timeFieldName,
+ intervalName: savedObject.attributes.intervalName,
+ fields: savedObject.attributes.fields,
+ sourceFilters: savedObject.attributes.sourceFilters,
+ fieldFormatMap: savedObject.attributes.fieldFormatMap,
+ typeMeta: savedObject.attributes.typeMeta,
+ type: savedObject.attributes.type,
};
// Do this before we attempt to update from ES since that call can potentially perform a save
this.originalBody = this.prepBody();
@@ -388,10 +407,10 @@ export class IndexPattern implements IIndexPattern {
field.count = count;
try {
- const res = await this.savedObjectsClient.update(type, this.id, this.prepBody(), {
+ const res = await this.savedObjectsClient.update(savedObjectType, this.id, this.prepBody(), {
version: this.version,
});
- this.version = res._version;
+ this.version = res.version;
} catch (e) {
// no need for an error message here
}
@@ -462,13 +481,17 @@ export class IndexPattern implements IIndexPattern {
fieldFormats: this.fieldFormats,
onNotification: this.onNotification,
onError: this.onError,
+ uiSettingsValues: {
+ shortDotsEnable: this.shortDotsEnable,
+ metaFields: this.metaFields,
+ },
});
await duplicatePattern.destroy();
}
const body = this.prepBody();
- const response = await this.savedObjectsClient.create(type, body, { id: this.id });
+ const response = await this.savedObjectsClient.create(savedObjectType, body, { id: this.id });
this.id = response.id;
return response.id;
@@ -496,10 +519,10 @@ export class IndexPattern implements IIndexPattern {
(key) => body[key] !== this.originalBody[key]
);
return this.savedObjectsClient
- .update(type, this.id, body, { version: this.version })
- .then((resp: any) => {
+ .update(savedObjectType, this.id, body, { version: this.version })
+ .then((resp) => {
this.id = resp.id;
- this.version = resp._version;
+ this.version = resp.version;
})
.catch((err) => {
if (
@@ -514,7 +537,12 @@ export class IndexPattern implements IIndexPattern {
fieldFormats: this.fieldFormats,
onNotification: this.onNotification,
onError: this.onError,
+ uiSettingsValues: {
+ shortDotsEnable: this.shortDotsEnable,
+ metaFields: this.metaFields,
+ },
});
+
return samePattern.init().then(() => {
// What keys changed from now and what the server returned
const updatedBody = samePattern.prepBody();
@@ -610,7 +638,7 @@ export class IndexPattern implements IIndexPattern {
destroy() {
if (this.id) {
this.patternCache.clear(this.id);
- return this.savedObjectsClient.delete(type, this.id);
+ return this.savedObjectsClient.delete(savedObjectType, this.id);
}
}
}
diff --git a/src/plugins/data/common/index_patterns/index_patterns/index_patterns.test.ts b/src/plugins/data/common/index_patterns/index_patterns/index_patterns.test.ts
index b0ecfc89d376b..2eb9744fc16b3 100644
--- a/src/plugins/data/common/index_patterns/index_patterns/index_patterns.test.ts
+++ b/src/plugins/data/common/index_patterns/index_patterns/index_patterns.test.ts
@@ -19,12 +19,14 @@
// eslint-disable-next-line max-classes-per-file
import { IndexPatternsService } from './index_patterns';
-import { SavedObjectsClientContract, SavedObjectsFindResponsePublic } from 'kibana/public';
-import { coreMock, httpServiceMock } from '../../../../../core/public/mocks';
import { fieldFormatsMock } from '../../field_formats/mocks';
+import {
+ UiSettingsCommon,
+ IIndexPatternsApiClient,
+ SavedObjectsClientCommon,
+ SavedObject,
+} from '../types';
-const core = coreMock.createStart();
-const http = httpServiceMock.createStartContract();
const fieldFormats = fieldFormatsMock;
jest.mock('./index_pattern', () => {
@@ -39,33 +41,26 @@ jest.mock('./index_pattern', () => {
};
});
-jest.mock('./index_patterns_api_client', () => {
- class IndexPatternsApiClient {
- getFieldsForWildcard = async () => ({});
- }
-
- return {
- IndexPatternsApiClient,
- };
-});
-
describe('IndexPatterns', () => {
let indexPatterns: IndexPatternsService;
- let savedObjectsClient: SavedObjectsClientContract;
+ let savedObjectsClient: SavedObjectsClientCommon;
beforeEach(() => {
- savedObjectsClient = {} as SavedObjectsClientContract;
+ savedObjectsClient = {} as SavedObjectsClientCommon;
savedObjectsClient.find = jest.fn(
() =>
- Promise.resolve({
- savedObjects: [{ id: 'id', attributes: { title: 'title' } }],
- }) as Promise>
+ Promise.resolve([{ id: 'id', attributes: { title: 'title' } }]) as Promise<
+ Array>
+ >
);
indexPatterns = new IndexPatternsService({
- uiSettings: core.uiSettings,
- savedObjectsClient,
- http,
+ uiSettings: ({
+ get: () => Promise.resolve(false),
+ getAll: () => {},
+ } as any) as UiSettingsCommon,
+ savedObjectsClient: (savedObjectsClient as unknown) as SavedObjectsClientCommon,
+ apiClient: {} as IIndexPatternsApiClient,
fieldFormats,
onNotification: () => {},
onError: () => {},
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 5e51897d13372..ef03ca8fe2d14 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
@@ -17,25 +17,26 @@
* under the License.
*/
-import {
- SavedObjectsClientContract,
- SimpleSavedObject,
- IUiSettingsClient,
- HttpStart,
- CoreStart,
-} from 'src/core/public';
+import { SavedObjectsClientCommon } from '../..';
import { createIndexPatternCache } from '.';
import { IndexPattern } from './index_pattern';
-import { IndexPatternsApiClient, GetFieldsOptions } from '.';
import {
createEnsureDefaultIndexPattern,
EnsureDefaultIndexPattern,
} from './ensure_default_index_pattern';
import { getIndexPatternFieldListCreator, CreateIndexPatternFieldList, Field } from '../fields';
-import { IndexPatternSpec, FieldSpec } from '../types';
-import { OnNotification, OnError } from '../types';
+import {
+ OnNotification,
+ OnError,
+ UiSettingsCommon,
+ IIndexPatternsApiClient,
+ GetFieldsOptions,
+ FieldSpec,
+ IndexPatternSpec,
+} from '../types';
import { FieldFormatsStartCommon } from '../../field_formats';
+import { UI_SETTINGS, SavedObject } from '../../../common';
const indexPatternCache = createIndexPatternCache();
@@ -46,20 +47,20 @@ export interface IndexPatternSavedObjectAttrs {
}
interface IndexPatternsServiceDeps {
- uiSettings: CoreStart['uiSettings'];
- savedObjectsClient: SavedObjectsClientContract;
- http: HttpStart;
+ uiSettings: UiSettingsCommon;
+ savedObjectsClient: SavedObjectsClientCommon;
+ apiClient: IIndexPatternsApiClient;
fieldFormats: FieldFormatsStartCommon;
onNotification: OnNotification;
onError: OnError;
- onRedirectNoIndexPattern: () => void;
+ onRedirectNoIndexPattern?: () => void;
}
export class IndexPatternsService {
- private config: IUiSettingsClient;
- private savedObjectsClient: SavedObjectsClientContract;
- private savedObjectsCache?: Array> | null;
- private apiClient: IndexPatternsApiClient;
+ private config: UiSettingsCommon;
+ private savedObjectsClient: SavedObjectsClientCommon;
+ private savedObjectsCache?: Array> | null;
+ private apiClient: IIndexPatternsApiClient;
private fieldFormats: FieldFormatsStartCommon;
private onNotification: OnNotification;
private onError: OnError;
@@ -74,13 +75,13 @@ export class IndexPatternsService {
constructor({
uiSettings,
savedObjectsClient,
- http,
+ apiClient,
fieldFormats,
onNotification,
onError,
- onRedirectNoIndexPattern,
+ onRedirectNoIndexPattern = () => {},
}: IndexPatternsServiceDeps) {
- this.apiClient = new IndexPatternsApiClient(http);
+ this.apiClient = apiClient;
this.config = uiSettings;
this.savedObjectsClient = savedObjectsClient;
this.fieldFormats = fieldFormats;
@@ -103,13 +104,11 @@ export class IndexPatternsService {
}
private async refreshSavedObjectsCache() {
- this.savedObjectsCache = (
- await this.savedObjectsClient.find({
- type: 'index-pattern',
- fields: ['title'],
- perPage: 10000,
- })
- ).savedObjects;
+ this.savedObjectsCache = await this.savedObjectsClient.find({
+ type: 'index-pattern',
+ fields: ['title'],
+ perPage: 10000,
+ });
}
getIds = async (refresh: boolean = false) => {
@@ -172,7 +171,7 @@ export class IndexPatternsService {
};
getDefault = async () => {
- const defaultIndexPatternId = this.config.get('defaultIndex');
+ const defaultIndexPatternId = await this.config.get('defaultIndex');
if (defaultIndexPatternId) {
return await this.get(defaultIndexPatternId);
}
@@ -191,7 +190,11 @@ export class IndexPatternsService {
return indexPatternCache.set(id, indexPattern);
};
- specToIndexPattern(spec: IndexPatternSpec) {
+ async specToIndexPattern(spec: IndexPatternSpec) {
+ const shortDotsEnable = await this.config.get(UI_SETTINGS.SHORT_DOTS_ENABLE);
+ const metaFields = await this.config.get(UI_SETTINGS.META_FIELDS);
+ const uiSettingsValues = await this.config.getAll();
+
const indexPattern = new IndexPattern(spec.id, {
getConfig: (cfg: any) => this.config.get(cfg),
savedObjectsClient: this.savedObjectsClient,
@@ -200,13 +203,18 @@ export class IndexPatternsService {
fieldFormats: this.fieldFormats,
onNotification: this.onNotification,
onError: this.onError,
+ uiSettingsValues: { ...uiSettingsValues, shortDotsEnable, metaFields },
});
indexPattern.initFromSpec(spec);
return indexPattern;
}
- make = (id?: string): Promise => {
+ async make(id?: string): Promise {
+ const shortDotsEnable = await this.config.get(UI_SETTINGS.SHORT_DOTS_ENABLE);
+ const metaFields = await this.config.get(UI_SETTINGS.META_FIELDS);
+ const uiSettingsValues = await this.config.getAll();
+
const indexPattern = new IndexPattern(id, {
getConfig: (cfg: any) => this.config.get(cfg),
savedObjectsClient: this.savedObjectsClient,
@@ -215,10 +223,11 @@ export class IndexPatternsService {
fieldFormats: this.fieldFormats,
onNotification: this.onNotification,
onError: this.onError,
+ uiSettingsValues: { ...uiSettingsValues, shortDotsEnable, metaFields },
});
return indexPattern.init();
- };
+ }
}
export type IndexPatternsContract = PublicMethodsOf;
diff --git a/src/plugins/data/common/index_patterns/lib/errors.ts b/src/plugins/data/common/index_patterns/lib/errors.ts
index 12efab7a2ca40..59019000f1924 100644
--- a/src/plugins/data/common/index_patterns/lib/errors.ts
+++ b/src/plugins/data/common/index_patterns/lib/errors.ts
@@ -19,7 +19,7 @@
/* eslint-disable */
-import { KbnError } from '../../../../kibana_utils/public';
+import { KbnError } from '../../../../kibana_utils/common/';
/**
* Tried to call a method that relies on SearchSource having an indexPattern assigned
diff --git a/src/plugins/data/common/index_patterns/types.ts b/src/plugins/data/common/index_patterns/types.ts
index 94121a274d686..4241df5718243 100644
--- a/src/plugins/data/common/index_patterns/types.ts
+++ b/src/plugins/data/common/index_patterns/types.ts
@@ -18,6 +18,8 @@
*/
import { ToastInputFields, ErrorToastOptions } from 'src/core/public/notifications';
+// eslint-disable-next-line
+import type { SavedObject } from 'src/core/server';
import { IFieldType } from './fields';
import { SerializedFieldFormat } from '../../../expressions/common';
import { KBN_FIELD_TYPES } from '..';
@@ -49,11 +51,61 @@ export interface IndexPatternAttributes {
title: string;
typeMeta: string;
timeFieldName?: string;
+ intervalName?: string;
+ sourceFilters?: string;
+ fieldFormatMap?: string;
}
export type OnNotification = (toastInputFields: ToastInputFields) => void;
export type OnError = (error: Error, toastInputFields: ErrorToastOptions) => void;
+export interface UiSettingsCommon {
+ get: (key: string) => Promise;
+ getAll: () => Promise>;
+ set: (key: string, value: any) => Promise;
+ remove: (key: string) => Promise;
+}
+
+export interface SavedObjectsClientCommonFindArgs {
+ type: string | string[];
+ fields?: string[];
+ perPage?: number;
+ search?: string;
+ searchFields?: string[];
+}
+
+export interface SavedObjectsClientCommon {
+ find: (options: SavedObjectsClientCommonFindArgs) => Promise>>;
+ get: (type: string, id: string) => Promise>;
+ update: (
+ type: string,
+ id: string,
+ attributes: Record,
+ options: Record
+ ) => Promise;
+ create: (
+ type: string,
+ attributes: Record,
+ options: Record
+ ) => Promise;
+ delete: (type: string, id: string) => Promise<{}>;
+}
+
+export interface GetFieldsOptions {
+ pattern?: string;
+ type?: string;
+ params?: any;
+ lookBack?: boolean;
+ metaFields?: string;
+}
+
+export interface IIndexPatternsApiClient {
+ getFieldsForTimePattern: (options: GetFieldsOptions) => Promise;
+ getFieldsForWildcard: (options: GetFieldsOptions) => Promise;
+}
+
+export type { SavedObject };
+
export type AggregationRestrictions = Record<
string,
{
diff --git a/src/plugins/data/common/index_patterns/utils.ts b/src/plugins/data/common/index_patterns/utils.ts
index c3f9af62f8c0e..d9e1cfa0d952a 100644
--- a/src/plugins/data/common/index_patterns/utils.ts
+++ b/src/plugins/data/common/index_patterns/utils.ts
@@ -18,24 +18,24 @@
*/
import { find } from 'lodash';
-import { SavedObjectsClientContract, SimpleSavedObject } from 'src/core/public';
+import { SavedObjectsClientCommon, SavedObject } from '..';
/**
* Returns an object matching a given title
*
- * @param client {SavedObjectsClientContract}
+ * @param client {SavedObjectsClientCommon}
* @param title {string}
- * @returns {Promise}
+ * @returns {Promise}
*/
export async function findByTitle(
- client: SavedObjectsClientContract,
+ client: SavedObjectsClientCommon,
title: string
-): Promise | void> {
+): Promise | void> {
if (!title) {
return Promise.resolve();
}
- const { savedObjects } = await client.find({
+ const savedObjects = await client.find({
type: 'index-pattern',
perPage: 10,
search: `"${title}"`,
@@ -45,6 +45,6 @@ export async function findByTitle(
return find(
savedObjects,
- (obj: SimpleSavedObject) => obj.get('title').toLowerCase() === title.toLowerCase()
+ (obj: SavedObject) => obj.attributes.title.toLowerCase() === title.toLowerCase()
);
}
diff --git a/src/plugins/data/public/index_patterns/index.ts b/src/plugins/data/public/index_patterns/index.ts
index 2c540527f468d..a6ee71c624f5a 100644
--- a/src/plugins/data/public/index_patterns/index.ts
+++ b/src/plugins/data/public/index_patterns/index.ts
@@ -34,4 +34,11 @@ export {
IIndexPatternFieldList,
} from '../../common/index_patterns';
-export { IndexPatternsService, IndexPatternsContract, IndexPattern } from './index_patterns';
+export {
+ IndexPatternsService,
+ IndexPatternsContract,
+ IndexPattern,
+ IndexPatternsApiClient,
+} from './index_patterns';
+export { UiSettingsPublicToCommon } from './ui_settings_wrapper';
+export { SavedObjectsClientPublicToCommon } from './saved_objects_client_wrapper';
diff --git a/src/plugins/data/public/index_patterns/index_patterns/index.ts b/src/plugins/data/public/index_patterns/index_patterns/index.ts
index 0db1c8c68b4ac..f63b48f877771 100644
--- a/src/plugins/data/public/index_patterns/index_patterns/index.ts
+++ b/src/plugins/data/public/index_patterns/index_patterns/index.ts
@@ -19,3 +19,4 @@
export * from '../../../common/index_patterns/index_patterns';
export * from './redirect_no_index_pattern';
+export * from './index_patterns_api_client';
diff --git a/src/plugins/data/common/index_patterns/index_patterns/index_patterns_api_client.test.mock.ts b/src/plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.test.mock.ts
similarity index 100%
rename from src/plugins/data/common/index_patterns/index_patterns/index_patterns_api_client.test.mock.ts
rename to src/plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.test.mock.ts
diff --git a/src/plugins/data/common/index_patterns/index_patterns/index_patterns_api_client.test.ts b/src/plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.test.ts
similarity index 100%
rename from src/plugins/data/common/index_patterns/index_patterns/index_patterns_api_client.test.ts
rename to src/plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.test.ts
diff --git a/src/plugins/data/common/index_patterns/index_patterns/index_patterns_api_client.ts b/src/plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.ts
similarity index 87%
rename from src/plugins/data/common/index_patterns/index_patterns/index_patterns_api_client.ts
rename to src/plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.ts
index cd189ccf0135b..377a3f7f91a50 100644
--- a/src/plugins/data/common/index_patterns/index_patterns/index_patterns_api_client.ts
+++ b/src/plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.ts
@@ -18,21 +18,12 @@
*/
import { HttpSetup } from 'src/core/public';
-import { IndexPatternMissingIndices } from '../lib';
+import { IndexPatternMissingIndices } from '../../../common/index_patterns/lib';
+import { GetFieldsOptions, IIndexPatternsApiClient } from '../../../common/index_patterns/types';
const API_BASE_URL: string = `/api/index_patterns/`;
-export interface GetFieldsOptions {
- pattern?: string;
- type?: string;
- params?: any;
- lookBack?: boolean;
- metaFields?: string;
-}
-
-export type IIndexPatternsApiClient = PublicMethodsOf;
-
-export class IndexPatternsApiClient {
+export class IndexPatternsApiClient implements IIndexPatternsApiClient {
private http: HttpSetup;
constructor(http: HttpSetup) {
@@ -53,7 +44,7 @@ export class IndexPatternsApiClient {
});
}
- _getUrl(path: string[]) {
+ private _getUrl(path: string[]) {
return API_BASE_URL + path.filter(Boolean).map(encodeURIComponent).join('/');
}
diff --git a/src/plugins/data/public/index_patterns/saved_objects_client_wrapper.ts b/src/plugins/data/public/index_patterns/saved_objects_client_wrapper.ts
new file mode 100644
index 0000000000000..8f1d02c5ffd54
--- /dev/null
+++ b/src/plugins/data/public/index_patterns/saved_objects_client_wrapper.ts
@@ -0,0 +1,67 @@
+/*
+ * 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 { omit } from 'lodash';
+import { SavedObjectsClient, SimpleSavedObject } from 'src/core/public';
+import {
+ SavedObjectsClientCommon,
+ SavedObjectsClientCommonFindArgs,
+ SavedObject,
+} from '../../common/index_patterns';
+
+type SOClient = Pick;
+
+const simpleSavedObjectToSavedObject = (
+ simpleSavedObject: SimpleSavedObject
+): SavedObject => ({
+ version: simpleSavedObject._version,
+ ...omit(simpleSavedObject, '_version'),
+});
+
+export class SavedObjectsClientPublicToCommon implements SavedObjectsClientCommon {
+ private savedObjectClient: SOClient;
+ constructor(savedObjectClient: SOClient) {
+ this.savedObjectClient = savedObjectClient;
+ }
+ async find(options: SavedObjectsClientCommonFindArgs) {
+ const response = (await this.savedObjectClient.find(options)).savedObjects;
+ return response.map>(simpleSavedObjectToSavedObject);
+ }
+
+ async get(type: string, id: string) {
+ const response = await this.savedObjectClient.get(type, id);
+ return simpleSavedObjectToSavedObject(response);
+ }
+ async update(
+ type: string,
+ id: string,
+ attributes: Record,
+ options: Record
+ ) {
+ const response = await this.savedObjectClient.update(type, id, attributes, options);
+ return simpleSavedObjectToSavedObject(response);
+ }
+ async create(type: string, attributes: Record, options: Record) {
+ const response = await this.savedObjectClient.create(type, attributes, options);
+ return simpleSavedObjectToSavedObject(response);
+ }
+ delete(type: string, id: string) {
+ return this.savedObjectClient.delete(type, id);
+ }
+}
diff --git a/src/plugins/data/public/index_patterns/ui_settings_wrapper.ts b/src/plugins/data/public/index_patterns/ui_settings_wrapper.ts
new file mode 100644
index 0000000000000..17fc88ddd674d
--- /dev/null
+++ b/src/plugins/data/public/index_patterns/ui_settings_wrapper.ts
@@ -0,0 +1,45 @@
+/*
+ * 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 { IUiSettingsClient } from 'src/core/public';
+import { UiSettingsCommon } from '../../common/index_patterns';
+
+export class UiSettingsPublicToCommon implements UiSettingsCommon {
+ private uiSettings: IUiSettingsClient;
+ constructor(uiSettings: IUiSettingsClient) {
+ this.uiSettings = uiSettings;
+ }
+ get(key: string) {
+ return Promise.resolve(this.uiSettings.get(key));
+ }
+
+ getAll() {
+ return Promise.resolve(this.uiSettings.getAll());
+ }
+
+ set(key: string, value: any) {
+ this.uiSettings.set(key, value);
+ return Promise.resolve();
+ }
+
+ remove(key: string) {
+ this.uiSettings.remove(key);
+ return Promise.resolve();
+ }
+}
diff --git a/src/plugins/data/public/plugin.ts b/src/plugins/data/public/plugin.ts
index 51f96f10aa7c7..d5929cb9cd564 100644
--- a/src/plugins/data/public/plugin.ts
+++ b/src/plugins/data/public/plugin.ts
@@ -40,7 +40,12 @@ import { SearchService } from './search/search_service';
import { FieldFormatsService } from './field_formats';
import { QueryService } from './query';
import { createIndexPatternSelect } from './ui/index_pattern_select';
-import { IndexPatternsService, onRedirectNoIndexPattern } from './index_patterns';
+import {
+ IndexPatternsService,
+ onRedirectNoIndexPattern,
+ IndexPatternsApiClient,
+ UiSettingsPublicToCommon,
+} from './index_patterns';
import {
setFieldFormats,
setHttp,
@@ -76,6 +81,7 @@ import {
ACTION_VALUE_CLICK,
ValueClickActionContext,
} from './actions/value_click_action';
+import { SavedObjectsClientPublicToCommon } from './index_patterns';
declare module '../../ui_actions/public' {
export interface ActionContextMapping {
@@ -164,9 +170,9 @@ export class DataPublicPlugin implements Plugin {
notifications.toasts.add(toastInputFields);
diff --git a/src/plugins/data/public/public.api.md b/src/plugins/data/public/public.api.md
index 0bb3fc3a3bf16..f2c7a907cda1d 100644
--- a/src/plugins/data/public/public.api.md
+++ b/src/plugins/data/public/public.api.md
@@ -66,8 +66,6 @@ import { GetSourceParams } from 'elasticsearch';
import { GetTemplateParams } from 'elasticsearch';
import { History } from 'history';
import { Href } from 'history';
-import { HttpSetup } from 'src/core/public';
-import { HttpStart } from 'src/core/public';
import { IconType } from '@elastic/eui';
import { IndexDocumentParams } from 'elasticsearch';
import { IndicesAnalyzeParams } from 'elasticsearch';
@@ -148,15 +146,15 @@ import { ReindexRethrottleParams } from 'elasticsearch';
import { RenderSearchTemplateParams } from 'elasticsearch';
import { Required } from '@kbn/utility-types';
import * as Rx from 'rxjs';
-import { SavedObject as SavedObject_2 } from 'src/core/public';
-import { SavedObjectsClientContract } from 'src/core/public';
+import { SavedObject } from 'src/core/server';
+import { SavedObject as SavedObject_3 } from 'src/core/public';
+import { SavedObjectsClientContract as SavedObjectsClientContract_3 } from 'src/core/public';
import { ScrollParams } from 'elasticsearch';
import { SearchParams } from 'elasticsearch';
import { SearchResponse as SearchResponse_2 } from 'elasticsearch';
import { SearchShardsParams } from 'elasticsearch';
import { SearchTemplateParams } from 'elasticsearch';
import { SerializedFieldFormat as SerializedFieldFormat_2 } from 'src/plugins/expressions/public';
-import { SimpleSavedObject } from 'src/core/public';
import { SnapshotCreateParams } from 'elasticsearch';
import { SnapshotCreateRepositoryParams } from 'elasticsearch';
import { SnapshotDeleteParams } from 'elasticsearch';
@@ -300,7 +298,7 @@ export const connectToQueryState: ({ timefilter: { timefil
// Warning: (ae-missing-release-tag) "createSavedQueryService" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
-export const createSavedQueryService: (savedObjectsClient: SavedObjectsClientContract) => SavedQueryService;
+export const createSavedQueryService: (savedObjectsClient: SavedObjectsClientContract_3) => SavedQueryService;
// Warning: (ae-missing-release-tag) "CustomFilter" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
@@ -982,7 +980,7 @@ export type IMetricAggType = MetricAggType;
// @public (undocumented)
export class IndexPattern implements IIndexPattern {
// Warning: (ae-forgotten-export) The symbol "IndexPatternDeps" needs to be exported by the entry point index.d.ts
- constructor(id: string | undefined, { getConfig, savedObjectsClient, apiClient, patternCache, fieldFormats, onNotification, onError, }: IndexPatternDeps);
+ constructor(id: string | undefined, { getConfig, savedObjectsClient, apiClient, patternCache, fieldFormats, onNotification, onError, uiSettingsValues, }: IndexPatternDeps);
// (undocumented)
[key: string]: any;
// (undocumented)
@@ -1097,9 +1095,15 @@ export type IndexPatternAggRestrictions = Record {
+export interface IndexPatternsServiceStart {
+ indexPatternsServiceFactory: (
+ kibanaRequest: KibanaRequest
+ ) => Promise;
+}
+
+export interface IndexPatternsServiceStartDeps {
+ fieldFormats: FieldFormatsStart;
+ logger: Logger;
+}
+
+export class IndexPatternsService implements Plugin {
public setup(core: CoreSetup) {
core.savedObjects.registerType(indexPatternSavedObjectType);
core.capabilities.registerProvider(capabilitiesProvider);
@@ -30,5 +46,28 @@ export class IndexPatternsService implements Plugin {
registerRoutes(core.http);
}
- public start() {}
+ public start(core: CoreStart, { fieldFormats, logger }: IndexPatternsServiceStartDeps) {
+ const { uiSettings, savedObjects } = core;
+
+ return {
+ indexPatternsServiceFactory: async (kibanaRequest: KibanaRequest) => {
+ const savedObjectsClient = savedObjects.getScopedClient(kibanaRequest);
+ const uiSettingsClient = uiSettings.asScopedToClient(savedObjectsClient);
+ const formats = await fieldFormats.fieldFormatServiceFactory(uiSettingsClient);
+
+ return new IndexPatternsCommonService({
+ uiSettings: new UiSettingsServerToCommon(uiSettingsClient),
+ savedObjectsClient: new SavedObjectsClientServerToCommon(savedObjectsClient),
+ apiClient: new IndexPatternsApiServer(),
+ fieldFormats: formats,
+ onError: (error) => {
+ logger.error(error);
+ },
+ onNotification: ({ title, text }) => {
+ logger.warn(`${title} : ${text}`);
+ },
+ });
+ },
+ };
+ }
}
diff --git a/src/plugins/data/server/index_patterns/mocks.ts b/src/plugins/data/server/index_patterns/mocks.ts
new file mode 100644
index 0000000000000..8f95afe3b3c9d
--- /dev/null
+++ b/src/plugins/data/server/index_patterns/mocks.ts
@@ -0,0 +1,24 @@
+/*
+ * 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 function createIndexPatternsStartMock() {
+ return {
+ indexPatternsServiceFactory: jest.fn(),
+ };
+}
diff --git a/src/plugins/data/server/index_patterns/saved_objects_client_wrapper.ts b/src/plugins/data/server/index_patterns/saved_objects_client_wrapper.ts
new file mode 100644
index 0000000000000..c82695b7cb2ba
--- /dev/null
+++ b/src/plugins/data/server/index_patterns/saved_objects_client_wrapper.ts
@@ -0,0 +1,53 @@
+/*
+ * 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 { SavedObjectsClientContract, SavedObject } from 'src/core/server';
+import {
+ SavedObjectsClientCommon,
+ SavedObjectsClientCommonFindArgs,
+} from '../../common/index_patterns';
+
+export class SavedObjectsClientServerToCommon implements SavedObjectsClientCommon {
+ private savedObjectClient: SavedObjectsClientContract;
+ constructor(savedObjectClient: SavedObjectsClientContract) {
+ this.savedObjectClient = savedObjectClient;
+ }
+ async find(options: SavedObjectsClientCommonFindArgs) {
+ const result = await this.savedObjectClient.find(options);
+ return result.saved_objects;
+ }
+
+ async get(type: string, id: string) {
+ return await this.savedObjectClient.get(type, id);
+ }
+ async update(
+ type: string,
+ id: string,
+ attributes: Record,
+ options: Record
+ ) {
+ return (await this.savedObjectClient.update(type, id, attributes, options)) as SavedObject;
+ }
+ async create(type: string, attributes: Record, options: Record) {
+ return await this.savedObjectClient.create(type, attributes, options);
+ }
+ delete(type: string, id: string) {
+ return this.savedObjectClient.delete(type, id);
+ }
+}
diff --git a/src/plugins/data/server/index_patterns/ui_settings_wrapper.ts b/src/plugins/data/server/index_patterns/ui_settings_wrapper.ts
new file mode 100644
index 0000000000000..34cdfdff0b80f
--- /dev/null
+++ b/src/plugins/data/server/index_patterns/ui_settings_wrapper.ts
@@ -0,0 +1,43 @@
+/*
+ * 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 { IUiSettingsClient } from 'src/core/server';
+import { UiSettingsCommon } from '../../common/index_patterns';
+
+export class UiSettingsServerToCommon implements UiSettingsCommon {
+ private uiSettings: IUiSettingsClient;
+ constructor(uiSettings: IUiSettingsClient) {
+ this.uiSettings = uiSettings;
+ }
+ get(key: string) {
+ return this.uiSettings.get(key);
+ }
+
+ getAll() {
+ return this.uiSettings.getAll();
+ }
+
+ set(key: string, value: any) {
+ return this.uiSettings.set(key, value);
+ }
+
+ remove(key: string) {
+ return this.uiSettings.remove(key);
+ }
+}
diff --git a/src/plugins/data/server/mocks.ts b/src/plugins/data/server/mocks.ts
index e2f2298234054..785e4a1ec41ab 100644
--- a/src/plugins/data/server/mocks.ts
+++ b/src/plugins/data/server/mocks.ts
@@ -19,6 +19,7 @@
import { createSearchSetupMock, createSearchStartMock } from './search/mocks';
import { createFieldFormatsSetupMock, createFieldFormatsStartMock } from './field_formats/mocks';
+import { createIndexPatternsStartMock } from './index_patterns/mocks';
function createSetupContract() {
return {
@@ -31,6 +32,7 @@ function createStartContract() {
return {
search: createSearchStartMock(),
fieldFormats: createFieldFormatsStartMock(),
+ indexPatterns: createIndexPatternsStartMock(),
};
}
diff --git a/src/plugins/data/server/plugin.ts b/src/plugins/data/server/plugin.ts
index 0edce458f1c6b..bcf1f4f8ab60b 100644
--- a/src/plugins/data/server/plugin.ts
+++ b/src/plugins/data/server/plugin.ts
@@ -17,9 +17,15 @@
* under the License.
*/
-import { PluginInitializerContext, CoreSetup, CoreStart, Plugin } from '../../../core/server';
+import {
+ PluginInitializerContext,
+ CoreSetup,
+ CoreStart,
+ Plugin,
+ Logger,
+} from '../../../core/server';
import { ConfigSchema } from '../config';
-import { IndexPatternsService } from './index_patterns';
+import { IndexPatternsService, IndexPatternsServiceStart } from './index_patterns';
import { ISearchSetup, ISearchStart } from './search';
import { SearchService } from './search/search_service';
import { QueryService } from './query/query_service';
@@ -38,6 +44,7 @@ export interface DataPluginSetup {
export interface DataPluginStart {
search: ISearchStart;
fieldFormats: FieldFormatsStart;
+ indexPatterns: IndexPatternsServiceStart;
}
export interface DataPluginSetupDependencies {
@@ -52,12 +59,14 @@ export class DataServerPlugin implements Plugin) {
this.searchService = new SearchService(initializerContext);
this.scriptsService = new ScriptsService();
this.kqlTelemetryService = new KqlTelemetryService(initializerContext);
this.autocompleteService = new AutocompleteService(initializerContext);
+ this.logger = initializerContext.logger.get('data');
}
public setup(
@@ -79,9 +88,14 @@ export class DataServerPlugin implements Plugin {
fieldFormats: {
fieldFormatServiceFactory: (uiSettings: import("../../../core/server").IUiSettingsClient) => Promise;
};
+ indexPatterns: {
+ indexPatternsServiceFactory: (kibanaRequest: import("../../../core/server").KibanaRequest) => Promise;
+ };
};
// (undocumented)
stop(): void;
@@ -681,6 +694,10 @@ export interface PluginStart {
//
// (undocumented)
fieldFormats: FieldFormatsStart;
+ // Warning: (ae-forgotten-export) The symbol "IndexPatternsServiceStart" needs to be exported by the entry point index.d.ts
+ //
+ // (undocumented)
+ indexPatterns: IndexPatternsServiceStart;
// (undocumented)
search: ISearchStart;
}
diff --git a/test/plugin_functional/config.js b/test/plugin_functional/config.js
index 078eb9ee88a8e..f51fb5e1bade4 100644
--- a/test/plugin_functional/config.js
+++ b/test/plugin_functional/config.js
@@ -38,6 +38,7 @@ export default async function ({ readConfigFile }) {
require.resolve('./test_suites/management'),
require.resolve('./test_suites/doc_views'),
require.resolve('./test_suites/application_links'),
+ require.resolve('./test_suites/data_plugin'),
],
services: {
...functionalConfig.get('services'),
diff --git a/test/plugin_functional/plugins/index_patterns/kibana.json b/test/plugin_functional/plugins/index_patterns/kibana.json
new file mode 100644
index 0000000000000..e098950dc9677
--- /dev/null
+++ b/test/plugin_functional/plugins/index_patterns/kibana.json
@@ -0,0 +1,9 @@
+{
+ "id": "index_patterns_test_plugin",
+ "version": "0.0.1",
+ "kibanaVersion": "kibana",
+ "configPath": ["index_patterns_test_plugin"],
+ "server": true,
+ "ui": false,
+ "requiredPlugins": ["data"]
+}
diff --git a/test/plugin_functional/plugins/index_patterns/package.json b/test/plugin_functional/plugins/index_patterns/package.json
new file mode 100644
index 0000000000000..eaba6ca624bd8
--- /dev/null
+++ b/test/plugin_functional/plugins/index_patterns/package.json
@@ -0,0 +1,17 @@
+{
+ "name": "index_patterns_test_plugin",
+ "version": "1.0.0",
+ "main": "target/test/plugin_functional/plugins/index_patterns_test_plugin",
+ "kibana": {
+ "version": "kibana",
+ "templateVersion": "1.0.0"
+ },
+ "license": "Apache-2.0",
+ "scripts": {
+ "kbn": "node ../../../../scripts/kbn.js",
+ "build": "rm -rf './target' && tsc"
+ },
+ "devDependencies": {
+ "typescript": "3.9.5"
+ }
+}
\ No newline at end of file
diff --git a/test/plugin_functional/plugins/index_patterns/server/index.ts b/test/plugin_functional/plugins/index_patterns/server/index.ts
new file mode 100644
index 0000000000000..0c99dd30c9cb6
--- /dev/null
+++ b/test/plugin_functional/plugins/index_patterns/server/index.ts
@@ -0,0 +1,30 @@
+/*
+ * 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 { PluginInitializer } from 'kibana/server';
+import {
+ IndexPatternsTestPlugin,
+ IndexPatternsTestPluginSetup,
+ IndexPatternsTestPluginStart,
+} from './plugin';
+
+export const plugin: PluginInitializer<
+ IndexPatternsTestPluginSetup,
+ IndexPatternsTestPluginStart
+> = () => new IndexPatternsTestPlugin();
diff --git a/test/plugin_functional/plugins/index_patterns/server/plugin.ts b/test/plugin_functional/plugins/index_patterns/server/plugin.ts
new file mode 100644
index 0000000000000..ffc70136ccffa
--- /dev/null
+++ b/test/plugin_functional/plugins/index_patterns/server/plugin.ts
@@ -0,0 +1,111 @@
+/*
+ * 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 { CoreSetup, Plugin } from 'kibana/server';
+import { schema } from '@kbn/config-schema';
+import { PluginStart as DataPluginStart } from '../../../../../src/plugins/data/server';
+
+export interface IndexPatternsTestStartDeps {
+ data: DataPluginStart;
+}
+
+export class IndexPatternsTestPlugin
+ implements
+ Plugin<
+ IndexPatternsTestPluginSetup,
+ IndexPatternsTestPluginStart,
+ {},
+ IndexPatternsTestStartDeps
+ > {
+ public setup(core: CoreSetup) {
+ const router = core.http.createRouter();
+
+ router.get(
+ { path: '/api/index-patterns-plugin/get-all', validate: false },
+ async (context, req, res) => {
+ const [, { data }] = await core.getStartServices();
+ const service = await data.indexPatterns.indexPatternsServiceFactory(req);
+ const ids = await service.getIds();
+ return res.ok({ body: ids });
+ }
+ );
+
+ router.get(
+ {
+ path: '/api/index-patterns-plugin/get/{id}',
+ validate: {
+ params: schema.object({
+ id: schema.string(),
+ }),
+ },
+ },
+ async (context, req, res) => {
+ const id = (req.params as Record).id;
+ const [, { data }] = await core.getStartServices();
+ const service = await data.indexPatterns.indexPatternsServiceFactory(req);
+ const ip = await service.get(id);
+ return res.ok({ body: ip.toSpec() });
+ }
+ );
+
+ router.get(
+ {
+ path: '/api/index-patterns-plugin/update/{id}',
+ validate: {
+ params: schema.object({
+ id: schema.string(),
+ }),
+ },
+ },
+ async (context, req, res) => {
+ const [, { data }] = await core.getStartServices();
+ const id = (req.params as Record).id;
+ const service = await data.indexPatterns.indexPatternsServiceFactory(req);
+ const ip = await service.get(id);
+ await ip.save();
+ return res.ok();
+ }
+ );
+
+ router.get(
+ {
+ path: '/api/index-patterns-plugin/delete/{id}',
+ validate: {
+ params: schema.object({
+ id: schema.string(),
+ }),
+ },
+ },
+ async (context, req, res) => {
+ const [, { data }] = await core.getStartServices();
+ const id = (req.params as Record).id;
+ const service = await data.indexPatterns.indexPatternsServiceFactory(req);
+ const ip = await service.get(id);
+ await ip.destroy();
+ return res.ok();
+ }
+ );
+ }
+
+ public start() {}
+ public stop() {}
+}
+
+export type IndexPatternsTestPluginSetup = ReturnType;
+export type IndexPatternsTestPluginStart = ReturnType;
diff --git a/test/plugin_functional/plugins/index_patterns/tsconfig.json b/test/plugin_functional/plugins/index_patterns/tsconfig.json
new file mode 100644
index 0000000000000..6f0c32ad30601
--- /dev/null
+++ b/test/plugin_functional/plugins/index_patterns/tsconfig.json
@@ -0,0 +1,14 @@
+{
+ "extends": "../../../../tsconfig.json",
+ "compilerOptions": {
+ "outDir": "./target",
+ "skipLibCheck": true
+ },
+ "include": [
+ "index.ts",
+ "server/**/*.ts",
+ "server/**/*.tsx",
+ "../../../../typings/**/*",
+ ],
+ "exclude": []
+}
diff --git a/test/plugin_functional/test_suites/data_plugin/index.ts b/test/plugin_functional/test_suites/data_plugin/index.ts
new file mode 100644
index 0000000000000..1c3f118135ffa
--- /dev/null
+++ b/test/plugin_functional/test_suites/data_plugin/index.ts
@@ -0,0 +1,25 @@
+/*
+ * 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.
+ */
+
+// @ts-expect-error
+export default function ({ loadTestFile }) {
+ describe('data plugin', () => {
+ loadTestFile(require.resolve('./index_patterns'));
+ });
+}
diff --git a/test/plugin_functional/test_suites/data_plugin/index_patterns.ts b/test/plugin_functional/test_suites/data_plugin/index_patterns.ts
new file mode 100644
index 0000000000000..481e9d76e3acc
--- /dev/null
+++ b/test/plugin_functional/test_suites/data_plugin/index_patterns.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.
+ */
+import expect from '@kbn/expect';
+import { PluginFunctionalProviderContext } from '../../services';
+import '../../plugins/core_provider_plugin/types';
+
+// eslint-disable-next-line import/no-default-export
+export default function ({ getService, getPageObjects }: PluginFunctionalProviderContext) {
+ const supertest = getService('supertest');
+ const esArchiver = getService('esArchiver');
+ const PageObjects = getPageObjects(['common', 'settings']);
+
+ describe('index patterns', function () {
+ let indexPatternId = '';
+ before(async () => {
+ await esArchiver.loadIfNeeded(
+ '../functional/fixtures/es_archiver/getting_started/shakespeare'
+ );
+ await PageObjects.common.navigateToApp('settings');
+ await PageObjects.settings.createIndexPattern('shakespeare', '');
+ });
+
+ it('can get all ids', async () => {
+ const body = await (await supertest.get('/api/index-patterns-plugin/get-all').expect(200))
+ .body;
+ indexPatternId = body[0];
+ expect(body.length > 0).to.equal(true);
+ });
+
+ it('can get index pattern by id', async () => {
+ const body = await (
+ await supertest.get(`/api/index-patterns-plugin/get/${indexPatternId}`).expect(200)
+ ).body;
+ expect(body.fields.length > 0).to.equal(true);
+ });
+
+ it('can update index pattern', async () => {
+ const body = await (
+ await supertest.get(`/api/index-patterns-plugin/update/${indexPatternId}`).expect(200)
+ ).body;
+ expect(body).to.eql({});
+ });
+
+ it('can delete index pattern', async () => {
+ await supertest.get(`/api/index-patterns-plugin/delete/${indexPatternId}`).expect(200);
+ });
+ });
+}
diff --git a/x-pack/plugins/maps/public/classes/layers/solution_layers/security/security_index_pattern_utils.ts b/x-pack/plugins/maps/public/classes/layers/solution_layers/security/security_index_pattern_utils.ts
index 141b9133505b7..6ba27322757bf 100644
--- a/x-pack/plugins/maps/public/classes/layers/solution_layers/security/security_index_pattern_utils.ts
+++ b/x-pack/plugins/maps/public/classes/layers/solution_layers/security/security_index_pattern_utils.ts
@@ -6,9 +6,6 @@
/* eslint-disable @typescript-eslint/consistent-type-definitions */
import minimatch from 'minimatch';
-import { SimpleSavedObject } from 'src/core/public';
-// eslint-disable-next-line @kbn/eslint/no-restricted-paths
-import { IndexPatternSavedObjectAttrs } from 'src/plugins/data/common/index_patterns/index_patterns/index_patterns';
import { getIndexPatternService, getUiSettings } from '../../../../kibana_services';
export type IndexPatternMeta = {
@@ -29,13 +26,13 @@ export async function getSecurityIndexPatterns(): Promise {
const indexPatternCache = await getIndexPatternService().getCache();
return indexPatternCache!
- .filter((savedObject: SimpleSavedObject) => {
+ .filter((savedObject) => {
return (securityIndexPatternTitles as string[]).some((indexPatternTitle) => {
// glob matching index pattern title
return minimatch(indexPatternTitle, savedObject?.attributes?.title);
});
})
- .map((savedObject: SimpleSavedObject) => {
+ .map((savedObject) => {
return {
id: savedObject.id,
title: savedObject.attributes.title,
diff --git a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/hooks/use_create_analytics_form/use_create_analytics_form.ts b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/hooks/use_create_analytics_form/use_create_analytics_form.ts
index 2de9a1dcadd4b..f95d2f572a406 100644
--- a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/hooks/use_create_analytics_form/use_create_analytics_form.ts
+++ b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/hooks/use_create_analytics_form/use_create_analytics_form.ts
@@ -8,7 +8,6 @@ import { useReducer } from 'react';
import { i18n } from '@kbn/i18n';
-import { SimpleSavedObject } from 'kibana/public';
import { getErrorMessage } from '../../../../../../../common/util/errors';
import { DeepReadonly } from '../../../../../../../common/types/common';
import { ml } from '../../../../../services/ml_api_service';
@@ -235,7 +234,7 @@ export const useCreateAnalyticsForm = (): CreateAnalyticsFormProps => {
// Set the index pattern titles which the user can choose as the source.
const indexPatternsMap: SourceIndexMap = {};
const savedObjects = (await mlContext.indexPatterns.getCache()) || [];
- savedObjects.forEach((obj: SimpleSavedObject>) => {
+ savedObjects.forEach((obj) => {
const title = obj?.attributes?.title;
if (title !== undefined) {
const id = obj?.id || '';