-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Allow savedObjects types registration from NP #57430
Changes from 10 commits
af5ac5e
97f8c1e
cbf73b3
b5ad014
3b8cd43
9e7aa96
af8c10d
d3937c7
76f0dd4
1989e89
d2f1016
6857054
9422f06
e408a9c
c3efbb1
15e7646
9c93b40
6c8a015
18f5c05
7d1475f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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) > [kibana-plugin-server](./kibana-plugin-server.md) > [ISavedObjectTypeRegistry](./kibana-plugin-server.isavedobjecttyperegistry.md) | ||
|
||
## ISavedObjectTypeRegistry type | ||
|
||
See [SavedObjectTypeRegistry](./kibana-plugin-server.savedobjecttyperegistry.md) for documentation. | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
export declare type ISavedObjectTypeRegistry = Pick<SavedObjectTypeRegistry, 'getType' | 'getAllTypes' | 'getIndex' | 'isNamespaceAgnostic' | 'isHidden'>; | ||
``` |
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) > [kibana-plugin-server](./kibana-plugin-server.md) > [SavedObjectMigrationContext](./kibana-plugin-server.savedobjectmigrationcontext.md) > [log](./kibana-plugin-server.savedobjectmigrationcontext.log.md) | ||
|
||
## SavedObjectMigrationContext.log property | ||
|
||
logger instance to be used by the migration handler | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
log: SavedObjectsMigrationLogger; | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [SavedObjectMigrationContext](./kibana-plugin-server.savedobjectmigrationcontext.md) | ||
|
||
## SavedObjectMigrationContext interface | ||
|
||
Migration context provided when invoking a [migration handler](./kibana-plugin-server.savedobjectmigrationfn.md) | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
export interface SavedObjectMigrationContext | ||
``` | ||
|
||
## Properties | ||
|
||
| Property | Type | Description | | ||
| --- | --- | --- | | ||
| [log](./kibana-plugin-server.savedobjectmigrationcontext.log.md) | <code>SavedObjectsMigrationLogger</code> | logger instance to be used by the migration handler | | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -4,10 +4,26 @@ | |||||
|
||||||
## SavedObjectMigrationFn type | ||||||
|
||||||
A migration function defined for a [saved objects type](./kibana-plugin-server.savedobjectstype.md) used to migrate it's | ||||||
A migration function defined for a [saved objects type](./kibana-plugin-server.savedobjectstype.md) used to migrate it's to a given version | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit:
Suggested change
|
||||||
|
||||||
<b>Signature:</b> | ||||||
|
||||||
```typescript | ||||||
export declare type SavedObjectMigrationFn = (doc: SavedObjectUnsanitizedDoc, log: SavedObjectsMigrationLogger) => SavedObjectUnsanitizedDoc; | ||||||
export declare type SavedObjectMigrationFn = (doc: SavedObjectUnsanitizedDoc, context: SavedObjectMigrationContext) => SavedObjectUnsanitizedDoc; | ||||||
``` | ||||||
|
||||||
## Example | ||||||
|
||||||
|
||||||
```typescript | ||||||
const migrateProperty: SavedObjectMigrationFn = (doc, { log }) => { | ||||||
try { | ||||||
doc.attributes.someProp = migrateProperty(doc.attributes.someProp); | ||||||
} catch(e) { | ||||||
log.warn('Error migrating `someProp`'); | ||||||
} | ||||||
return doc; | ||||||
} | ||||||
|
||||||
``` | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
|
||
## SavedObjectsServiceSetup interface | ||
|
||
Saved Objects is Kibana's data persistence mechanism allowing plugins to use Elasticsearch for storing and querying state. The SavedObjectsServiceSetup API exposes methods for creating and registering Saved Object client wrappers. | ||
Saved Objects is Kibana's data persistence mechanism allowing plugins to use Elasticsearch for storing and querying state. The SavedObjectsServiceSetup API exposes methods for registering Saved Object types and creating and registering Saved Object client wrappers and factories | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That would be indeed better 😄 |
||
|
||
<b>Signature:</b> | ||
|
||
|
@@ -14,11 +14,9 @@ export interface SavedObjectsServiceSetup | |
|
||
## Remarks | ||
|
||
Note: The Saved Object setup API's should only be used for creating and registering client wrappers. Constructing a Saved Objects client or repository for use within your own plugin won't have any of the registered wrappers applied and is considered an anti-pattern. Use the Saved Objects client from the [SavedObjectsServiceStart\#getScopedClient](./kibana-plugin-server.savedobjectsservicestart.md) method or the [route handler context](./kibana-plugin-server.requesthandlercontext.md) instead. | ||
When plugins access the Saved Objects client, a new client is created using the factory provided to `setClientFactory` and wrapped by all wrappers registered through `addClientWrapper`<!-- -->. | ||
|
||
When plugins access the Saved Objects client, a new client is created using the factory provided to `setClientFactory` and wrapped by all wrappers registered through `addClientWrapper`<!-- -->. To create a factory or wrapper, plugins will have to construct a Saved Objects client. First create a repository by calling `scopedRepository` or `internalRepository` and then use this repository as the argument to the [SavedObjectsClient](./kibana-plugin-server.savedobjectsclient.md) constructor. | ||
|
||
## Example | ||
## Example 1 | ||
|
||
|
||
```ts | ||
|
@@ -34,10 +32,26 @@ export class Plugin() { | |
|
||
``` | ||
|
||
## Example 2 | ||
|
||
|
||
```ts | ||
import { SavedObjectsClient, CoreSetup } from 'src/core/server'; | ||
import { mySoType } from './saved_objects' | ||
|
||
export class Plugin() { | ||
setup: (core: CoreSetup) => { | ||
core.savedObjects.registerType(mySoType); | ||
} | ||
} | ||
|
||
``` | ||
|
||
## Properties | ||
|
||
| Property | Type | Description | | ||
| --- | --- | --- | | ||
| [addClientWrapper](./kibana-plugin-server.savedobjectsservicesetup.addclientwrapper.md) | <code>(priority: number, id: string, factory: SavedObjectsClientWrapperFactory) => void</code> | Add a [client wrapper factory](./kibana-plugin-server.savedobjectsclientwrapperfactory.md) with the given priority. | | ||
| [registerType](./kibana-plugin-server.savedobjectsservicesetup.registertype.md) | <code>(type: SavedObjectsType) => void</code> | Register a [savedObjects type](./kibana-plugin-server.savedobjectstype.md) definition.<!-- -->See the [mappings format](./kibana-plugin-server.savedobjectstypemappingdefinition.md) and [migration format](./kibana-plugin-server.savedobjectmigrationmap.md) for more details about these. | | ||
| [setClientFactoryProvider](./kibana-plugin-server.savedobjectsservicesetup.setclientfactoryprovider.md) | <code>(clientFactoryProvider: SavedObjectsClientFactoryProvider) => 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,60 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [SavedObjectsServiceSetup](./kibana-plugin-server.savedobjectsservicesetup.md) > [registerType](./kibana-plugin-server.savedobjectsservicesetup.registertype.md) | ||
|
||
## SavedObjectsServiceSetup.registerType property | ||
|
||
Register a [savedObjects type](./kibana-plugin-server.savedobjectstype.md) definition. | ||
|
||
See the [mappings format](./kibana-plugin-server.savedobjectstypemappingdefinition.md) and [migration format](./kibana-plugin-server.savedobjectmigrationmap.md) for more details about these. | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
registerType: (type: SavedObjectsType) => void; | ||
``` | ||
|
||
## Remarks | ||
|
||
The type definition is an aggregation of the legacy savedObjects `schema`<!-- -->, `mappings` and `migration` concepts. This API is the single entry point to register saved object types in the new platform. | ||
|
||
## Example | ||
|
||
|
||
```ts | ||
// src/plugins/my_plugin/server/saved_objects/types.ts | ||
import { SavedObjectsType } from 'src/core/server'; | ||
import * as migrations from './migrations'; | ||
|
||
export const myType: SavedObjectsType = { | ||
name: 'MyType', | ||
hidden: false, | ||
namespaceAgnostic: true, | ||
mappings: { | ||
properties: { | ||
textField: { | ||
type: 'text', | ||
}, | ||
boolField: { | ||
type: 'boolean', | ||
}, | ||
}, | ||
}, | ||
migrations: { | ||
'2.0.0': migrations.migrateToV2, | ||
'2.1.0': migrations.migrateToV2_1 | ||
}, | ||
}; | ||
|
||
// src/plugins/my_plugin/server/plugin.ts | ||
import { SavedObjectsClient, CoreSetup } from 'src/core/server'; | ||
import { myType } from './saved_objects'; | ||
|
||
export class Plugin() { | ||
setup: (core: CoreSetup) => { | ||
core.savedObjects.registerType(myType); | ||
} | ||
} | ||
|
||
``` | ||
|
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) > [kibana-plugin-server](./kibana-plugin-server.md) > [SavedObjectsServiceStart](./kibana-plugin-server.savedobjectsservicestart.md) > [getTypeRegistry](./kibana-plugin-server.savedobjectsservicestart.gettyperegistry.md) | ||
|
||
## SavedObjectsServiceStart.getTypeRegistry property | ||
|
||
Returns the [registry](./kibana-plugin-server.isavedobjecttyperegistry.md) containing all registered [savedObject types](./kibana-plugin-server.savedobjectstype.md) | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
getTypeRegistry: () => ISavedObjectTypeRegistry; | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.