Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add savedObjects mappings API to core #55825

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
234 changes: 234 additions & 0 deletions docs/development/core/server/kibana-plugin-server.md

Large diffs are not rendered by default.

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-server](./kibana-plugin-server.md) &gt; [SavedObjectsComplexFieldMapping](./kibana-plugin-server.savedobjectscomplexfieldmapping.md) &gt; [dynamic](./kibana-plugin-server.savedobjectscomplexfieldmapping.dynamic.md)

## SavedObjectsComplexFieldMapping.dynamic property

<b>Signature:</b>

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

[Home](./index.md) &gt; [kibana-plugin-server](./kibana-plugin-server.md) &gt; [SavedObjectsComplexFieldMapping](./kibana-plugin-server.savedobjectscomplexfieldmapping.md)

## SavedObjectsComplexFieldMapping interface


<b>Signature:</b>

```typescript
export interface SavedObjectsComplexFieldMapping
```

## Properties

| Property | Type | Description |
| --- | --- | --- |
| [dynamic](./kibana-plugin-server.savedobjectscomplexfieldmapping.dynamic.md) | <code>string</code> | |
| [properties](./kibana-plugin-server.savedobjectscomplexfieldmapping.properties.md) | <code>SavedObjectsMappingProperties</code> | |
| [type](./kibana-plugin-server.savedobjectscomplexfieldmapping.type.md) | <code>string</code> | |

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-server](./kibana-plugin-server.md) &gt; [SavedObjectsComplexFieldMapping](./kibana-plugin-server.savedobjectscomplexfieldmapping.md) &gt; [properties](./kibana-plugin-server.savedobjectscomplexfieldmapping.properties.md)

## SavedObjectsComplexFieldMapping.properties property

<b>Signature:</b>

```typescript
properties: SavedObjectsMappingProperties;
```
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-server](./kibana-plugin-server.md) &gt; [SavedObjectsComplexFieldMapping](./kibana-plugin-server.savedobjectscomplexfieldmapping.md) &gt; [type](./kibana-plugin-server.savedobjectscomplexfieldmapping.type.md)

## SavedObjectsComplexFieldMapping.type property

<b>Signature:</b>

```typescript
type?: 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-server](./kibana-plugin-server.md) &gt; [SavedObjectsCoreFieldMapping](./kibana-plugin-server.savedobjectscorefieldmapping.md) &gt; [enabled](./kibana-plugin-server.savedobjectscorefieldmapping.enabled.md)

## SavedObjectsCoreFieldMapping.enabled property

<b>Signature:</b>

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

[Home](./index.md) &gt; [kibana-plugin-server](./kibana-plugin-server.md) &gt; [SavedObjectsCoreFieldMapping](./kibana-plugin-server.savedobjectscorefieldmapping.md) &gt; [fields](./kibana-plugin-server.savedobjectscorefieldmapping.fields.md)

## SavedObjectsCoreFieldMapping.fields property

<b>Signature:</b>

```typescript
fields?: {
[subfield: string]: {
type: 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-server](./kibana-plugin-server.md) &gt; [SavedObjectsCoreFieldMapping](./kibana-plugin-server.savedobjectscorefieldmapping.md) &gt; [index](./kibana-plugin-server.savedobjectscorefieldmapping.index.md)

## SavedObjectsCoreFieldMapping.index property

<b>Signature:</b>

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

[Home](./index.md) &gt; [kibana-plugin-server](./kibana-plugin-server.md) &gt; [SavedObjectsCoreFieldMapping](./kibana-plugin-server.savedobjectscorefieldmapping.md)

## SavedObjectsCoreFieldMapping interface


<b>Signature:</b>

```typescript
export interface SavedObjectsCoreFieldMapping
```

## Properties

| Property | Type | Description |
| --- | --- | --- |
| [enabled](./kibana-plugin-server.savedobjectscorefieldmapping.enabled.md) | <code>boolean</code> | |
| [fields](./kibana-plugin-server.savedobjectscorefieldmapping.fields.md) | <code>{</code><br/><code> [subfield: string]: {</code><br/><code> type: string;</code><br/><code> };</code><br/><code> }</code> | |
| [index](./kibana-plugin-server.savedobjectscorefieldmapping.index.md) | <code>boolean</code> | |
| [type](./kibana-plugin-server.savedobjectscorefieldmapping.type.md) | <code>string</code> | |

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-server](./kibana-plugin-server.md) &gt; [SavedObjectsCoreFieldMapping](./kibana-plugin-server.savedobjectscorefieldmapping.md) &gt; [type](./kibana-plugin-server.savedobjectscorefieldmapping.type.md)

## SavedObjectsCoreFieldMapping.type property

<b>Signature:</b>

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

[Home](./index.md) &gt; [kibana-plugin-server](./kibana-plugin-server.md) &gt; [SavedObjectsFieldMapping](./kibana-plugin-server.savedobjectsfieldmapping.md)

## SavedObjectsFieldMapping type

Describe a [saved object type mapping](./kibana-plugin-server.savedobjectstypemappingdefinition.md) field.

<b>Signature:</b>

```typescript
export declare type SavedObjectsFieldMapping = SavedObjectsCoreFieldMapping | SavedObjectsComplexFieldMapping;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-server](./kibana-plugin-server.md) &gt; [SavedObjectsMappingProperties](./kibana-plugin-server.savedobjectsmappingproperties.md)

## SavedObjectsMappingProperties interface

Describe the fields of a [saved object type](./kibana-plugin-server.savedobjectstypemappingdefinition.md)<!-- -->.

<b>Signature:</b>

```typescript
export interface SavedObjectsMappingProperties
```
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ export class Plugin() { setup: (core: CoreSetup) =<!-- -->&gt; { core.savedObjec
| Property | Type | Description |
| --- | --- | --- |
| [addClientWrapper](./kibana-plugin-server.savedobjectsservicesetup.addclientwrapper.md) | <code>(priority: number, id: string, factory: SavedObjectsClientWrapperFactory) =&gt; void</code> | Add a [client wrapper factory](./kibana-plugin-server.savedobjectsclientwrapperfactory.md) with the given priority. |
| [registerMappings](./kibana-plugin-server.savedobjectsservicesetup.registermappings.md) | <code>(mappings: SavedObjectsTypeMappingDefinitions) =&gt; void</code> | TODO: doc + exemple |
| [setClientFactoryProvider](./kibana-plugin-server.savedobjectsservicesetup.setclientfactoryprovider.md) | <code>(clientFactoryProvider: SavedObjectsClientFactoryProvider) =&gt; void</code> | Set the default [factory provider](./kibana-plugin-server.savedobjectsclientfactoryprovider.md) for creating Saved Objects clients. Only one provider can be set, subsequent calls to this method will fail. |

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

[Home](./index.md) &gt; [kibana-plugin-server](./kibana-plugin-server.md) &gt; [SavedObjectsServiceSetup](./kibana-plugin-server.savedobjectsservicesetup.md) &gt; [registerMappings](./kibana-plugin-server.savedobjectsservicesetup.registermappings.md)

## SavedObjectsServiceSetup.registerMappings property

TODO: doc + exemple

<b>Signature:</b>

```typescript
registerMappings: (mappings: SavedObjectsTypeMappingDefinitions) => void;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-server](./kibana-plugin-server.md) &gt; [SavedObjectsTypeMappingDefinition](./kibana-plugin-server.savedobjectstypemappingdefinition.md)

## SavedObjectsTypeMappingDefinition interface

Describe a saved object type mapping.

<b>Signature:</b>

```typescript
export interface SavedObjectsTypeMappingDefinition
```

## Example


```ts
const typeDefinition: SavedObjectsTypeMappingDefinition = {
properties: {
enabled: {
type: "boolean"
},
sendUsageFrom: {
ignore_above: 256,
type: "keyword"
},
lastReported: {
type: "date"
},
lastVersionChecked: {
ignore_above: 256,
type: "keyword"
},
}
}

```

## Properties

| Property | Type | Description |
| --- | --- | --- |
| [properties](./kibana-plugin-server.savedobjectstypemappingdefinition.properties.md) | <code>SavedObjectsMappingProperties</code> | |

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-server](./kibana-plugin-server.md) &gt; [SavedObjectsTypeMappingDefinition](./kibana-plugin-server.savedobjectstypemappingdefinition.md) &gt; [properties](./kibana-plugin-server.savedobjectstypemappingdefinition.properties.md)

## SavedObjectsTypeMappingDefinition.properties property

<b>Signature:</b>

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

[Home](./index.md) &gt; [kibana-plugin-server](./kibana-plugin-server.md) &gt; [SavedObjectsTypeMappingDefinitions](./kibana-plugin-server.savedobjectstypemappingdefinitions.md)

## SavedObjectsTypeMappingDefinitions interface

A map of [saved object type mappings](./kibana-plugin-server.savedobjectstypemappingdefinition.md)

<b>Signature:</b>

```typescript
export interface SavedObjectsTypeMappingDefinitions
```

## Example


```ts
const mappings: SavedObjectsTypeMappingDefinitions = {
someType: {
properties: {
enabled: {
type: "boolean"
},
field: {
type: "keyword"
},
},
},
anotherType: {
properties: {
enabled: {
type: "boolean"
},
lastReported: {
type: "date"
},
},
},

}

```
This is the format for a `mappings.json` savedObject mapping file.

6 changes: 6 additions & 0 deletions src/core/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,12 @@ export {
SavedObjectsRepository,
SavedObjectsDeleteByNamespaceOptions,
SavedObjectsIncrementCounterOptions,
SavedObjectsComplexFieldMapping,
SavedObjectsCoreFieldMapping,
SavedObjectsFieldMapping,
SavedObjectsTypeMappingDefinitions,
SavedObjectsTypeMappingDefinition,
SavedObjectsMappingProperties,
} from './saved_objects';

export {
Expand Down
7 changes: 6 additions & 1 deletion src/core/server/legacy/legacy_service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ type LegacyServiceMock = jest.Mocked<PublicMethodsOf<LegacyService> & { legacyId

const createDiscoverPluginsMock = (): LegacyServiceDiscoverPlugins => ({
pluginSpecs: [],
uiExports: {} as any,
uiExports: {
savedObjectSchemas: {},
savedObjectMappings: [],
savedObjectMigrations: {},
savedObjectValidations: {},
},
navLinks: [],
pluginExtendedConfig: {
get: jest.fn(),
Expand Down
1 change: 1 addition & 0 deletions src/core/server/legacy/legacy_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ export class LegacyService implements CoreService {
savedObjects: {
setClientFactoryProvider: setupDeps.core.savedObjects.setClientFactoryProvider,
addClientWrapper: setupDeps.core.savedObjects.addClientWrapper,
registerMappings: setupDeps.core.savedObjects.registerMappings.bind(null, 'legacy'),
},
uiSettings: {
register: setupDeps.core.uiSettings.register,
Expand Down
10 changes: 9 additions & 1 deletion src/core/server/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,20 @@ function createCoreSetupMock() {
const uiSettingsMock = {
register: uiSettingsServiceMock.createSetupContract().register,
};

const savedObjectsService = savedObjectsServiceMock.createSetupContract();
const savedObjectMock: jest.Mocked<CoreSetup['savedObjects']> = {
addClientWrapper: savedObjectsService.addClientWrapper,
setClientFactoryProvider: savedObjectsService.setClientFactoryProvider,
registerMappings: jest.fn(),
};

const mock: CoreSetupMockType = {
capabilities: capabilitiesServiceMock.createSetupContract(),
context: contextServiceMock.createSetupContract(),
elasticsearch: elasticsearchServiceMock.createSetup(),
http: httpMock,
savedObjects: savedObjectsServiceMock.createSetupContract(),
savedObjects: savedObjectMock,
uiSettings: uiSettingsMock,
uuid: uuidServiceMock.createSetupContract(),
getStartServices: jest
Expand Down
1 change: 1 addition & 0 deletions src/core/server/plugins/plugin_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ export function createPluginSetupContext<TPlugin, TPluginDependencies>(
savedObjects: {
setClientFactoryProvider: deps.savedObjects.setClientFactoryProvider,
addClientWrapper: deps.savedObjects.addClientWrapper,
registerMappings: deps.savedObjects.registerMappings.bind(null, plugin.name),
},
uiSettings: {
register: deps.uiSettings.register,
Expand Down
9 changes: 9 additions & 0 deletions src/core/server/saved_objects/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,13 @@ export {
SavedObjectsDeleteByNamespaceOptions,
} from './service/lib/repository';

export {
SavedObjectsCoreFieldMapping,
SavedObjectsComplexFieldMapping,
SavedObjectsFieldMapping,
SavedObjectsMappingProperties,
SavedObjectsTypeMappingDefinition,
SavedObjectsTypeMappingDefinitions,
} from './mappings';

export { config } from './saved_objects_config';
12 changes: 8 additions & 4 deletions src/core/server/saved_objects/mappings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@
*/
export { getTypes, getProperty, getRootProperties, getRootPropertiesObjects } from './lib';
export {
FieldMapping,
MappingMeta,
MappingProperties,
SavedObjectsComplexFieldMapping,
SavedObjectsCoreFieldMapping,
SavedObjectsTypeMapping,
SavedObjectsTypeMappingDefinition,
SavedObjectsTypeMappingDefinitions,
SavedObjectsMappingProperties,
SavedObjectsFieldMapping,
IndexMappingMeta,
IndexMapping,
SavedObjectsMapping,
} from './types';
Loading