Skip to content

Commit

Permalink
Index patterns - Server API (#69105)
Browse files Browse the repository at this point in the history
* index patterns on the server
  • Loading branch information
mattkime authored Jun 30, 2020
1 parent 04b8d10 commit 2fe0051
Show file tree
Hide file tree
Showing 53 changed files with 945 additions and 158 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ Constructs a new instance of the `IndexPattern` class
<b>Signature:</b>

```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

| Parameter | Type | Description |
| --- | --- | --- |
| id | <code>string &#124; undefined</code> | |
| { getConfig, savedObjectsClient, apiClient, patternCache, fieldFormats, onNotification, onError, } | <code>IndexPatternDeps</code> | |
| { getConfig, savedObjectsClient, apiClient, patternCache, fieldFormats, onNotification, onError, uiSettingsValues, } | <code>IndexPatternDeps</code> | |

Original file line number Diff line number Diff line change
Expand Up @@ -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 <code>IndexPattern</code> 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 <code>IndexPattern</code> class |
## Properties
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) &gt; [IndexPatternAttributes](./kibana-plugin-plugins-data-public.indexpatternattributes.md) &gt; [fieldFormatMap](./kibana-plugin-plugins-data-public.indexpatternattributes.fieldformatmap.md)

## IndexPatternAttributes.fieldFormatMap property

<b>Signature:</b>

```typescript
fieldFormatMap?: string;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) &gt; [IndexPatternAttributes](./kibana-plugin-plugins-data-public.indexpatternattributes.md) &gt; [intervalName](./kibana-plugin-plugins-data-public.indexpatternattributes.intervalname.md)

## IndexPatternAttributes.intervalName property

<b>Signature:</b>

```typescript
intervalName?: string;
```
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ export interface IndexPatternAttributes

| Property | Type | Description |
| --- | --- | --- |
| [fieldFormatMap](./kibana-plugin-plugins-data-public.indexpatternattributes.fieldformatmap.md) | <code>string</code> | |
| [fields](./kibana-plugin-plugins-data-public.indexpatternattributes.fields.md) | <code>string</code> | |
| [intervalName](./kibana-plugin-plugins-data-public.indexpatternattributes.intervalname.md) | <code>string</code> | |
| [sourceFilters](./kibana-plugin-plugins-data-public.indexpatternattributes.sourcefilters.md) | <code>string</code> | |
| [timeFieldName](./kibana-plugin-plugins-data-public.indexpatternattributes.timefieldname.md) | <code>string</code> | |
| [title](./kibana-plugin-plugins-data-public.indexpatternattributes.title.md) | <code>string</code> | |
| [type](./kibana-plugin-plugins-data-public.indexpatternattributes.type.md) | <code>string</code> | |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) &gt; [IndexPatternAttributes](./kibana-plugin-plugins-data-public.indexpatternattributes.md) &gt; [sourceFilters](./kibana-plugin-plugins-data-public.indexpatternattributes.sourcefilters.md)

## IndexPatternAttributes.sourceFilters property

<b>Signature:</b>

```typescript
sourceFilters?: string;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) &gt; [IndexPatternAttributes](./kibana-plugin-plugins-data-server.indexpatternattributes.md) &gt; [fieldFormatMap](./kibana-plugin-plugins-data-server.indexpatternattributes.fieldformatmap.md)

## IndexPatternAttributes.fieldFormatMap property

<b>Signature:</b>

```typescript
fieldFormatMap?: string;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) &gt; [IndexPatternAttributes](./kibana-plugin-plugins-data-server.indexpatternattributes.md) &gt; [intervalName](./kibana-plugin-plugins-data-server.indexpatternattributes.intervalname.md)

## IndexPatternAttributes.intervalName property

<b>Signature:</b>

```typescript
intervalName?: string;
```
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ export interface IndexPatternAttributes

| Property | Type | Description |
| --- | --- | --- |
| [fieldFormatMap](./kibana-plugin-plugins-data-server.indexpatternattributes.fieldformatmap.md) | <code>string</code> | |
| [fields](./kibana-plugin-plugins-data-server.indexpatternattributes.fields.md) | <code>string</code> | |
| [intervalName](./kibana-plugin-plugins-data-server.indexpatternattributes.intervalname.md) | <code>string</code> | |
| [sourceFilters](./kibana-plugin-plugins-data-server.indexpatternattributes.sourcefilters.md) | <code>string</code> | |
| [timeFieldName](./kibana-plugin-plugins-data-server.indexpatternattributes.timefieldname.md) | <code>string</code> | |
| [title](./kibana-plugin-plugins-data-server.indexpatternattributes.title.md) | <code>string</code> | |
| [type](./kibana-plugin-plugins-data-server.indexpatternattributes.type.md) | <code>string</code> | |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) &gt; [IndexPatternAttributes](./kibana-plugin-plugins-data-server.indexpatternattributes.md) &gt; [sourceFilters](./kibana-plugin-plugins-data-server.indexpatternattributes.sourcefilters.md)

## IndexPatternAttributes.sourceFilters property

<b>Signature:</b>

```typescript
sourceFilters?: string;
```
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ start(core: CoreStart): {
fieldFormats: {
fieldFormatServiceFactory: (uiSettings: import("../../../core/server").IUiSettingsClient) => Promise<import("../common").FieldFormatsRegistry>;
};
indexPatterns: {
indexPatternsServiceFactory: (kibanaRequest: import("../../../core/server").KibanaRequest<unknown, unknown, unknown, any>) => Promise<import("../common").IndexPatternsService>;
};
};
```

Expand All @@ -28,5 +31,8 @@ start(core: CoreStart): {
fieldFormats: {
fieldFormatServiceFactory: (uiSettings: import("../../../core/server").IUiSettingsClient) => Promise<import("../common").FieldFormatsRegistry>;
};
indexPatterns: {
indexPatternsServiceFactory: (kibanaRequest: import("../../../core/server").KibanaRequest<unknown, unknown, unknown, any>) => Promise<import("../common").IndexPatternsService>;
};
}`

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) &gt; [PluginStart](./kibana-plugin-plugins-data-server.pluginstart.md) &gt; [indexPatterns](./kibana-plugin-plugins-data-server.pluginstart.indexpatterns.md)

## PluginStart.indexPatterns property

<b>Signature:</b>

```typescript
indexPatterns: IndexPatternsServiceStart;
```
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ export interface DataPluginStart
| Property | Type | Description |
| --- | --- | --- |
| [fieldFormats](./kibana-plugin-plugins-data-server.pluginstart.fieldformats.md) | <code>FieldFormatsStart</code> | |
| [indexPatterns](./kibana-plugin-plugins-data-server.pluginstart.indexpatterns.md) | <code>IndexPatternsServiceStart</code> | |
| [search](./kibana-plugin-plugins-data-server.pluginstart.search.md) | <code>ISearchStart</code> | |

Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -32,5 +32,5 @@ export function stubbedSavedObjectIndexPattern(id) {
fields: mockLogstashFields,
},
version: 2,
});
};
}
1 change: 1 addition & 0 deletions src/plugins/data/common/index_patterns/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@

export * from './fields';
export * from './types';
export { IndexPatternsService } from './index_patterns';
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
* under the License.
*/

import { GetFieldsOptions, IIndexPatternsApiClient, IndexPattern } from '.';
import { IndexPattern } from '.';
import { GetFieldsOptions, IIndexPatternsApiClient } from '../types';

/** @internal */
export const createFieldsFetcher = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<unknown> | undefined;

export const createEnsureDefaultIndexPattern = (
uiSettings: CoreStart['uiSettings'],
uiSettings: UiSettingsCommon,
onRedirectNoIndexPattern: () => Promise<unknown> | void
) => {
/**
Expand All @@ -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;
}

Expand All @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,18 @@ 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,
},
});
}
object.attributes.title = body.title;
object._version += 'a';
object.version += 'a';
return {
id: object._id,
_version: object._version,
id: object.id,
version: object.version,
};
}),
};
Expand Down Expand Up @@ -109,6 +109,7 @@ function create(id: string, payload?: any): Promise<IndexPattern> {
fieldFormats: fieldFormatsMock,
onNotification: () => {},
onError: () => {},
uiSettingsValues: { shortDotsEnable: false, metaFields: [] },
});

setDocsourcePayload(id, payload);
Expand Down Expand Up @@ -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',
},
Expand All @@ -397,6 +398,7 @@ describe('IndexPattern', () => {
fieldFormats: fieldFormatsMock,
onNotification: () => {},
onError: () => {},
uiSettingsValues: { shortDotsEnable: false, metaFields: [] },
});
await pattern.init();

Expand All @@ -411,6 +413,7 @@ describe('IndexPattern', () => {
fieldFormats: fieldFormatsMock,
onNotification: () => {},
onError: () => {},
uiSettingsValues: { shortDotsEnable: false, metaFields: [] },
});
await samePattern.init();

Expand Down
Loading

0 comments on commit 2fe0051

Please sign in to comment.