|
56 | 56 | - [On the server side](#on-the-server-side) |
57 | 57 | - [On the client side](#on-the-client-side) |
58 | 58 | - [Updates an application navlink at runtime](#updates-an-app-navlink-at-runtime) |
| 59 | + - [Migrate my plugin's savedObjects definitions](#migrate-saved-object-definitions) |
| 60 | + - [Mappings](#migrate-saved-object-mappings) |
59 | 61 |
|
60 | 62 | Make no mistake, it is going to take a lot of work to move certain plugins to the new platform. Our target is to migrate the entire repo over to the new platform throughout 7.x and to remove the legacy plugin system no later than 8.0, and this is only possible if teams start on the effort now. |
61 | 63 |
|
@@ -1205,6 +1207,7 @@ In server code, `core` can be accessed from either `server.newPlatform` or `kbnS |
1205 | 1207 | | `request.getSavedObjectsClient` | [`context.core.savedObjects.client`](/docs/development/core/server/kibana-plugin-server.requesthandlercontext.core.md) | | |
1206 | 1208 | | `request.getUiSettingsService` | [`context.uiSettings.client`](/docs/development/core/server/kibana-plugin-server.iuisettingsclient.md) | | |
1207 | 1209 | | `kibana.Plugin.deprecations` | [Handle plugin configuration deprecations](#handle-plugin-config-deprecations) and [`PluginConfigDescriptor.deprecations`](docs/development/core/server/kibana-plugin-server.pluginconfigdescriptor.md) | Deprecations from New Platform are not applied to legacy configuration | |
| 1210 | +| `kibana.Plugin.mappings` | [Migrate my plugin's savedObjects definitions](#migrate-saved-object-definitions) and [`SavedObjectServices.registerMappings`](docs/development/core/server/kibana-plugin-server.savedobjectsservicesetup.registermappings.md) | Deprecations from New Platform are not applied to legacy configuration | |
1208 | 1211 |
|
1209 | 1212 | _See also: [Server's CoreSetup API Docs](/docs/development/core/server/kibana-plugin-server.coresetup.md)_ |
1210 | 1213 |
|
@@ -1654,4 +1657,105 @@ export class MyPlugin implements Plugin { |
1654 | 1657 | tooltip: 'Application disabled', |
1655 | 1658 | }) |
1656 | 1659 | } |
| 1660 | +``` |
| 1661 | +
|
| 1662 | +### Migrate my plugin's savedObjects definitions |
| 1663 | +
|
| 1664 | +Legacy plugins were using the `uiExports` in their plugin definition to define their saved object mappings, schema and migrations. |
| 1665 | +
|
| 1666 | +```js |
| 1667 | +import mappings from './mappings.json'; |
| 1668 | +import { migrations } from './migrations'; |
| 1669 | + |
| 1670 | +new kibana.Plugin({ |
| 1671 | + init(server){ |
| 1672 | + // [...] |
| 1673 | + }, |
| 1674 | + uiExports: { |
| 1675 | + mappings, |
| 1676 | + migrations, |
| 1677 | + savedObjectSchemas: { |
| 1678 | + 'sample-data-telemetry': { |
| 1679 | + isNamespaceAgnostic: true, |
| 1680 | + }, |
| 1681 | + 'kql-telemetry': { |
| 1682 | + isNamespaceAgnostic: true, |
| 1683 | + }, |
| 1684 | + }, |
| 1685 | + }, |
| 1686 | +}) |
| 1687 | +``` |
| 1688 | +
|
| 1689 | +In the new platform, all these registration are to be performed programmatically during your plugin's `setup` phase, |
| 1690 | +using the core `savedObjects` service APIs. |
| 1691 | + |
| 1692 | +#### Mappings |
| 1693 | +
|
| 1694 | +For mapping, `savedObjects.registerMappings` should be used. It expects a mappings definition in the exact same |
| 1695 | +format they were in legacy. |
| 1696 | +
|
| 1697 | +```js |
| 1698 | +import mappings from './mappings.json'; |
| 1699 | + |
| 1700 | +new kibana.Plugin({ |
| 1701 | + uiExports: { |
| 1702 | + mappings, |
| 1703 | + }, |
| 1704 | +}) |
| 1705 | +``` |
| 1706 | +
|
| 1707 | +Would become: |
| 1708 | +
|
| 1709 | +```typescript |
| 1710 | +import mappings from './mappings.json'; |
| 1711 | + |
| 1712 | +export class MyPlugin implements Plugin { |
| 1713 | + setup({ savedObjects }) { |
| 1714 | + savedObjects.registerMappings(mappings as SavedObjectsTypeMappingDefinitions); |
| 1715 | + } |
| 1716 | +``` |
| 1717 | +
|
| 1718 | +Note: in new platform, there are now proper typescript types for the saved objects mappings. It's strongly |
| 1719 | +advised to convert your json mapping file to typescript to ensure correct typings: |
| 1720 | +
|
| 1721 | +```json |
| 1722 | +// my-plugin/server/mappings.json |
| 1723 | +{ |
| 1724 | + "my-type": { |
| 1725 | + "properties": { |
| 1726 | + "afield": { |
| 1727 | + "type": "text" |
| 1728 | + } |
| 1729 | + } |
| 1730 | + } |
| 1731 | +} |
| 1732 | +``` |
| 1733 | +
|
| 1734 | +should be converted to a ts file |
| 1735 | +
|
| 1736 | +```typescript |
| 1737 | +// my-plugin/server/mappings.ts |
| 1738 | +import { SavedObjectsTypeMappingDefinitions } from 'src/core/server'; |
| 1739 | + |
| 1740 | +export const mappings: SavedObjectsTypeMappingDefinitions = { |
| 1741 | + 'my-type': { |
| 1742 | + properties: { |
| 1743 | + afield: { |
| 1744 | + type: "text" |
| 1745 | + } |
| 1746 | + } |
| 1747 | + } |
| 1748 | +} |
| 1749 | +``` |
| 1750 | +
|
| 1751 | +The usage would then become: |
| 1752 | +
|
| 1753 | +```typescript |
| 1754 | +import { mappings } from './mappings'; |
| 1755 | + |
| 1756 | +export class MyPlugin implements Plugin { |
| 1757 | + setup({ savedObjects }) { |
| 1758 | + savedObjects.registerMappings(mappings); |
| 1759 | + } |
| 1760 | +} |
1657 | 1761 | ``` |
0 commit comments