File tree Expand file tree Collapse file tree 3 files changed +45
-2
lines changed Expand file tree Collapse file tree 3 files changed +45
-2
lines changed Original file line number Diff line number Diff line change 77 - [ Applications] ( #applications )
88 - [ Services] ( #services )
99 - [ Usage Collection] ( #usage-collection )
10+ - [ Saved Objects Types] ( #saved-objects-types )
1011
1112## Plugin Structure
1213
@@ -31,6 +32,9 @@ my_plugin/
3132 │ └── index.ts
3233 ├── collectors
3334 │ └── register.ts
35+ ├── saved_objects
36+ │ ├── index.ts
37+ │ └── my_type.ts
3438 ├── services
3539 │ ├── my_service
3640 │ │ └── index.ts
@@ -259,6 +263,45 @@ export function registerMyPluginUsageCollector(usageCollection?: UsageCollection
259263}
260264```
261265
266+ ### Saved Objects Types
267+
268+ Saved object type definitions should be defined in their own ` server/saved_objects ` directory.
269+
270+ The folder should contain a file per type, named after the snake_case name of the type, and an ` index.ts ` file exporting all the types.
271+
272+ ``` typescript
273+ // src/plugins/my-plugin/server/saved_objects/my_type.ts
274+ import { SavedObjectsType } from ' src/core/server' ;
275+
276+ export const myType: SavedObjectsType = {
277+ name: ' my-type' ,
278+ hidden: false ,
279+ namespaceAgnostic: true ,
280+ mappings: {
281+ properties: {
282+ someField: {
283+ type: ' text' ,
284+ },
285+ anotherField: {
286+ type: ' text' ,
287+ },
288+ },
289+ },
290+ migrations: {
291+ ' 1.0.0' : migrateFirstTypeToV1 ,
292+ ' 2.0.0' : migrateFirstTypeToV2 ,
293+ },
294+ };
295+ ```
296+
297+ ``` typescript
298+ // src/plugins/my-plugin/server/saved_objects/index.ts
299+
300+ export { myType } from ' ./my_type' ;
301+ ```
302+
303+ Migration example from the legacy format is available in ` src/core/MIGRATION_EXAMPLES.md#saved-objects-types `
304+
262305### Naming conventions
263306
264307Export start and setup contracts as ` MyPluginStart ` and ` MyPluginSetup ` .
Original file line number Diff line number Diff line change @@ -889,7 +889,7 @@ export class MyPlugin implements Plugin {
889889
890890### Changes in structure compared to legacy
891891
892- The NP ` registerType ` expected input is very close to the legacy format, However there are some minor changes:
892+ The NP ` registerType ` expected input is very close to the legacy format. However, there are some minor changes:
893893
894894- The ` schema .isNamespaceAgnostic ` property has been renamed: ` SavedObjectsType .namespaceAgnostic `
895895
Original file line number Diff line number Diff line change @@ -195,7 +195,7 @@ describe('convertLegacyTypes', () => {
195195 expect ( Object . keys ( converted [ 1 ] ! . migrations ! ) ) . toEqual ( Object . keys ( migrationsB ) ) ;
196196 } ) ;
197197
198- it ( 'migrates the migration to the new format' , ( ) => {
198+ it ( 'converts the migration to the new format' , ( ) => {
199199 const legacyMigration = jest . fn ( ) ;
200200 const migrationsA = {
201201 '1.0.0' : legacyMigration ,
You can’t perform that action at this time.
0 commit comments