From e137477b5a00b8c83e63acda1121c1d2ee10541c Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Tue, 6 Aug 2019 20:53:05 +0200 Subject: [PATCH] [Core] Public saved objects client (#39891) * Move SavedObjectClient files to core/public * Initial SavedObjectsService in public Core * Public SavedObjectsClient tests * Import SimpleSavedObject from src/core/public * Use types from source files for kibana.d.ts * Add html raw loader to x-pack/jest * Cleanup * Drop case utilities and improve test coverage * Update types and documentation * Fix build breaking when importing directly from /server in /public * Ensure that all option paramaters are picked and renamed * Fix option mapping and introduce stronger types * Eslint: allow imports from src/core/*/types * Add compatibility layer for kfetch vs http.fetch error responses * Improve documentation * Expose SavedObjectsMigrationLogger * Documentation and type tweaks * Revert type changes from 73e601f and update api docs * Refactor request into savedObjectFetch + test * Make legacy SavedObject compatible with http.fetch exceptions * Fix types and tests * simple_saved_object import from src/core/server * server imports from root instead of server/types * Make SavedObjectsService a class * Don't pick unkown keys from server response * Rename SavedObjectsFindResponse to SavedObjectsFindResponsePublic * Remove err.response from SavedObjects fetch errors * Revert "Remove err.response from SavedObjects fetch errors" This reverts commit 61705ca3611bccefe12e0a6569f7c3b8c6abaa67. * Don't introduce err.response until we deprecate err.res --- .../public/kibana-plugin-public.corestart.md | 1 + ...na-plugin-public.corestart.savedobjects.md | 13 + .../core/public/kibana-plugin-public.md | 17 + ...na-plugin-public.savedobject.attributes.md | 13 + .../kibana-plugin-public.savedobject.error.md | 14 + .../kibana-plugin-public.savedobject.id.md | 13 + .../kibana-plugin-public.savedobject.md | 26 ++ ...gin-public.savedobject.migrationversion.md | 13 + ...na-plugin-public.savedobject.references.md | 13 + .../kibana-plugin-public.savedobject.type.md | 13 + ...na-plugin-public.savedobject.updated_at.md | 13 + ...ibana-plugin-public.savedobject.version.md | 13 + ...bana-plugin-public.savedobjectattribute.md | 12 + ...ana-plugin-public.savedobjectattributes.md | 13 + ...a-plugin-public.savedobjectreference.id.md | 11 + ...bana-plugin-public.savedobjectreference.md | 22 + ...plugin-public.savedobjectreference.name.md | 11 + ...plugin-public.savedobjectreference.type.md | 11 + ...a-plugin-public.savedobjectsbaseoptions.md | 19 + ...ublic.savedobjectsbaseoptions.namespace.md | 13 + ...plugin-public.savedobjectsbatchresponse.md | 19 + ....savedobjectsbatchresponse.savedobjects.md | 11 + ...savedobjectsbulkcreateobject.attributes.md | 11 + ...gin-public.savedobjectsbulkcreateobject.md | 19 + ...ublic.savedobjectsbulkcreateobject.type.md | 11 + ...in-public.savedobjectsbulkcreateoptions.md | 19 + ...savedobjectsbulkcreateoptions.overwrite.md | 13 + ...in-public.savedobjectsclient.bulkcreate.md | 13 + ...lugin-public.savedobjectsclient.bulkget.md | 21 + ...plugin-public.savedobjectsclient.create.md | 13 + ...plugin-public.savedobjectsclient.delete.md | 13 + ...a-plugin-public.savedobjectsclient.find.md | 13 + ...na-plugin-public.savedobjectsclient.get.md | 13 + ...kibana-plugin-public.savedobjectsclient.md | 35 ++ ...plugin-public.savedobjectsclient.update.md | 28 ++ ...lugin-public.savedobjectsclientcontract.md | 13 + ...gin-public.savedobjectscreateoptions.id.md | 13 + ...plugin-public.savedobjectscreateoptions.md | 22 + ...edobjectscreateoptions.migrationversion.md | 13 + ...lic.savedobjectscreateoptions.overwrite.md | 13 + ...ic.savedobjectscreateoptions.references.md | 11 + ...bjectsfindoptions.defaultsearchoperator.md | 11 + ...n-public.savedobjectsfindoptions.fields.md | 18 + ...ic.savedobjectsfindoptions.hasreference.md | 14 + ...a-plugin-public.savedobjectsfindoptions.md | 28 ++ ...gin-public.savedobjectsfindoptions.page.md | 11 + ...-public.savedobjectsfindoptions.perpage.md | 11 + ...n-public.savedobjectsfindoptions.search.md | 13 + ...ic.savedobjectsfindoptions.searchfields.md | 13 + ...ublic.savedobjectsfindoptions.sortfield.md | 11 + ...ublic.savedobjectsfindoptions.sortorder.md | 11 + ...gin-public.savedobjectsfindoptions.type.md | 11 + ...n-public.savedobjectsfindresponsepublic.md | 24 + ...lic.savedobjectsfindresponsepublic.page.md | 11 + ....savedobjectsfindresponsepublic.perpage.md | 11 + ...ic.savedobjectsfindresponsepublic.total.md | 11 + ...gin-public.savedobjectsmigrationversion.md | 18 + ...-plugin-public.savedobjectsstart.client.md | 13 + .../kibana-plugin-public.savedobjectsstart.md | 19 + ...plugin-public.savedobjectsupdateoptions.md | 21 + ...edobjectsupdateoptions.migrationversion.md | 13 + ...ic.savedobjectsupdateoptions.references.md | 11 + ...ublic.savedobjectsupdateoptions.version.md | 11 + ...-public.simplesavedobject.(constructor).md | 21 + ...lugin-public.simplesavedobject._version.md | 11 + ...gin-public.simplesavedobject.attributes.md | 11 + ...-plugin-public.simplesavedobject.delete.md | 15 + ...a-plugin-public.simplesavedobject.error.md | 11 + ...ana-plugin-public.simplesavedobject.get.md | 22 + ...ana-plugin-public.simplesavedobject.has.md | 22 + ...bana-plugin-public.simplesavedobject.id.md | 11 + .../kibana-plugin-public.simplesavedobject.md | 44 ++ ...blic.simplesavedobject.migrationversion.md | 11 + ...gin-public.simplesavedobject.references.md | 11 + ...na-plugin-public.simplesavedobject.save.md | 15 + ...ana-plugin-public.simplesavedobject.set.md | 23 + ...na-plugin-public.simplesavedobject.type.md | 11 + .../core/server/kibana-plugin-server.md | 10 +- ...na-plugin-server.savedobject.attributes.md | 2 + .../kibana-plugin-server.savedobject.id.md | 2 + .../kibana-plugin-server.savedobject.md | 14 +- ...gin-server.savedobject.migrationversion.md | 2 + ...na-plugin-server.savedobject.references.md | 2 + .../kibana-plugin-server.savedobject.type.md | 2 + ...na-plugin-server.savedobject.updated_at.md | 2 + ...ibana-plugin-server.savedobject.version.md | 2 + ...bana-plugin-server.savedobjectattribute.md | 12 + ...ana-plugin-server.savedobjectattributes.md | 1 + ...gin-server.savedobjectsbulkcreateobject.md | 2 +- ...bjectsbulkcreateobject.migrationversion.md | 2 + ...lugin-server.savedobjectsclientcontract.md | 2 + ...plugin-server.savedobjectscreateoptions.md | 2 +- ...edobjectscreateoptions.migrationversion.md | 2 + ...n-server.savedobjectsfindoptions.fields.md | 7 + ...a-plugin-server.savedobjectsfindoptions.md | 6 +- ...n-server.savedobjectsfindoptions.search.md | 2 + ...er.savedobjectsfindoptions.searchfields.md | 2 +- ...-plugin-server.savedobjectsfindresponse.md | 3 + ...erver.savedobjectsmigrationlogger.debug.md | 11 + ...server.savedobjectsmigrationlogger.info.md | 11 + ...ugin-server.savedobjectsmigrationlogger.md | 21 + ...ver.savedobjectsmigrationlogger.warning.md | 11 + ...gin-server.savedobjectsmigrationversion.md | 7 +- kibana.d.ts | 4 +- src/core/public/core_system.ts | 5 + src/core/public/http/http_service.mock.ts | 4 +- src/core/public/index.ts | 23 + src/core/public/legacy/legacy_service.test.ts | 3 + src/core/public/mocks.ts | 2 + src/core/public/plugins/plugin_context.ts | 1 + .../public/plugins/plugins_service.test.ts | 2 + src/core/public/public.api.md | 173 +++++++ src/core/public/saved_objects/index.ts | 40 ++ .../saved_objects_client.test.ts | 433 ++++++++++++++++++ .../saved_objects/saved_objects_client.ts | 218 ++++++--- .../saved_objects_service.mock.ts | 50 ++ .../saved_objects/saved_objects_service.ts | 38 ++ .../saved_objects/simple_saved_object.ts | 11 +- src/core/server/index.ts | 41 +- .../export/get_sorted_objects_for_export.ts | 2 +- .../inject_nested_depdendencies.test.ts | 2 +- .../export/inject_nested_depdendencies.ts | 2 +- .../saved_objects/export/sort_objects.ts | 2 +- .../import/collect_saved_objects.ts | 2 +- .../import/create_objects_filter.ts | 2 +- .../import/extract_errors.test.ts | 2 +- .../saved_objects/import/extract_errors.ts | 3 +- .../import/import_saved_objects.test.ts | 2 +- .../import/resolve_import_errors.test.ts | 2 +- .../import/resolve_import_errors.ts | 1 - .../saved_objects/import/split_overwrites.ts | 2 +- src/core/server/saved_objects/import/types.ts | 2 +- .../import/validate_references.ts | 2 +- src/core/server/saved_objects/index.ts | 2 + .../saved_objects/management/management.ts | 2 +- .../migrations/core/document_migrator.ts | 21 +- .../migrations/core/elastic_index.ts | 2 +- .../migrations/core/migration_context.ts | 4 +- .../migrations/core/migration_coordinator.ts | 6 +- .../migrations/core/migration_logger.ts | 5 +- .../saved_objects/serialization/index.ts | 5 +- .../saved_objects/service/lib/repository.ts | 12 +- .../service/lib/scoped_client_provider.ts | 2 +- .../service/saved_objects_client.mock.ts | 2 +- .../service/saved_objects_client.ts | 169 +------ src/core/server/saved_objects/types.ts | 203 ++++++++ src/core/server/server.api.md | 28 +- src/core/server/types.ts | 2 +- .../server/types.ts~master} | 10 +- src/dev/run_check_core_api_changes.ts | 2 +- .../stubbed_saved_object_index_pattern.js | 2 +- .../embeddable/dashboard_container_factory.ts | 2 +- .../add_panel/add_panel_flyout.tsx | 3 +- .../dashboard/migrations/migrations_730.ts | 4 +- .../__tests__/directives/field_chooser.js | 2 +- .../public/chrome/api/saved_object_client.ts | 29 ++ src/legacy/ui/public/chrome/index.d.ts | 4 +- .../public/index_patterns/_index_pattern.ts | 9 +- .../public/index_patterns/index_patterns.ts | 7 +- .../__tests__/find_object_by_title.js | 2 +- .../__tests__/simple_saved_object.js | 2 +- .../components/saved_object_finder.tsx | 2 +- .../saved_objects/find_object_by_title.ts | 8 +- src/legacy/ui/public/saved_objects/index.ts | 2 - .../saved_objects_client.test.ts | 357 --------------- .../saved_objects_client_provider.ts | 2 +- x-pack/dev-tools/jest/create_jest_config.js | 1 + 167 files changed, 2586 insertions(+), 712 deletions(-) create mode 100644 docs/development/core/public/kibana-plugin-public.corestart.savedobjects.md create mode 100644 docs/development/core/public/kibana-plugin-public.savedobject.attributes.md create mode 100644 docs/development/core/public/kibana-plugin-public.savedobject.error.md create mode 100644 docs/development/core/public/kibana-plugin-public.savedobject.id.md create mode 100644 docs/development/core/public/kibana-plugin-public.savedobject.md create mode 100644 docs/development/core/public/kibana-plugin-public.savedobject.migrationversion.md create mode 100644 docs/development/core/public/kibana-plugin-public.savedobject.references.md create mode 100644 docs/development/core/public/kibana-plugin-public.savedobject.type.md create mode 100644 docs/development/core/public/kibana-plugin-public.savedobject.updated_at.md create mode 100644 docs/development/core/public/kibana-plugin-public.savedobject.version.md create mode 100644 docs/development/core/public/kibana-plugin-public.savedobjectattribute.md create mode 100644 docs/development/core/public/kibana-plugin-public.savedobjectattributes.md create mode 100644 docs/development/core/public/kibana-plugin-public.savedobjectreference.id.md create mode 100644 docs/development/core/public/kibana-plugin-public.savedobjectreference.md create mode 100644 docs/development/core/public/kibana-plugin-public.savedobjectreference.name.md create mode 100644 docs/development/core/public/kibana-plugin-public.savedobjectreference.type.md create mode 100644 docs/development/core/public/kibana-plugin-public.savedobjectsbaseoptions.md create mode 100644 docs/development/core/public/kibana-plugin-public.savedobjectsbaseoptions.namespace.md create mode 100644 docs/development/core/public/kibana-plugin-public.savedobjectsbatchresponse.md create mode 100644 docs/development/core/public/kibana-plugin-public.savedobjectsbatchresponse.savedobjects.md create mode 100644 docs/development/core/public/kibana-plugin-public.savedobjectsbulkcreateobject.attributes.md create mode 100644 docs/development/core/public/kibana-plugin-public.savedobjectsbulkcreateobject.md create mode 100644 docs/development/core/public/kibana-plugin-public.savedobjectsbulkcreateobject.type.md create mode 100644 docs/development/core/public/kibana-plugin-public.savedobjectsbulkcreateoptions.md create mode 100644 docs/development/core/public/kibana-plugin-public.savedobjectsbulkcreateoptions.overwrite.md create mode 100644 docs/development/core/public/kibana-plugin-public.savedobjectsclient.bulkcreate.md create mode 100644 docs/development/core/public/kibana-plugin-public.savedobjectsclient.bulkget.md create mode 100644 docs/development/core/public/kibana-plugin-public.savedobjectsclient.create.md create mode 100644 docs/development/core/public/kibana-plugin-public.savedobjectsclient.delete.md create mode 100644 docs/development/core/public/kibana-plugin-public.savedobjectsclient.find.md create mode 100644 docs/development/core/public/kibana-plugin-public.savedobjectsclient.get.md create mode 100644 docs/development/core/public/kibana-plugin-public.savedobjectsclient.md create mode 100644 docs/development/core/public/kibana-plugin-public.savedobjectsclient.update.md create mode 100644 docs/development/core/public/kibana-plugin-public.savedobjectsclientcontract.md create mode 100644 docs/development/core/public/kibana-plugin-public.savedobjectscreateoptions.id.md create mode 100644 docs/development/core/public/kibana-plugin-public.savedobjectscreateoptions.md create mode 100644 docs/development/core/public/kibana-plugin-public.savedobjectscreateoptions.migrationversion.md create mode 100644 docs/development/core/public/kibana-plugin-public.savedobjectscreateoptions.overwrite.md create mode 100644 docs/development/core/public/kibana-plugin-public.savedobjectscreateoptions.references.md create mode 100644 docs/development/core/public/kibana-plugin-public.savedobjectsfindoptions.defaultsearchoperator.md create mode 100644 docs/development/core/public/kibana-plugin-public.savedobjectsfindoptions.fields.md create mode 100644 docs/development/core/public/kibana-plugin-public.savedobjectsfindoptions.hasreference.md create mode 100644 docs/development/core/public/kibana-plugin-public.savedobjectsfindoptions.md create mode 100644 docs/development/core/public/kibana-plugin-public.savedobjectsfindoptions.page.md create mode 100644 docs/development/core/public/kibana-plugin-public.savedobjectsfindoptions.perpage.md create mode 100644 docs/development/core/public/kibana-plugin-public.savedobjectsfindoptions.search.md create mode 100644 docs/development/core/public/kibana-plugin-public.savedobjectsfindoptions.searchfields.md create mode 100644 docs/development/core/public/kibana-plugin-public.savedobjectsfindoptions.sortfield.md create mode 100644 docs/development/core/public/kibana-plugin-public.savedobjectsfindoptions.sortorder.md create mode 100644 docs/development/core/public/kibana-plugin-public.savedobjectsfindoptions.type.md create mode 100644 docs/development/core/public/kibana-plugin-public.savedobjectsfindresponsepublic.md create mode 100644 docs/development/core/public/kibana-plugin-public.savedobjectsfindresponsepublic.page.md create mode 100644 docs/development/core/public/kibana-plugin-public.savedobjectsfindresponsepublic.perpage.md create mode 100644 docs/development/core/public/kibana-plugin-public.savedobjectsfindresponsepublic.total.md create mode 100644 docs/development/core/public/kibana-plugin-public.savedobjectsmigrationversion.md create mode 100644 docs/development/core/public/kibana-plugin-public.savedobjectsstart.client.md create mode 100644 docs/development/core/public/kibana-plugin-public.savedobjectsstart.md create mode 100644 docs/development/core/public/kibana-plugin-public.savedobjectsupdateoptions.md create mode 100644 docs/development/core/public/kibana-plugin-public.savedobjectsupdateoptions.migrationversion.md create mode 100644 docs/development/core/public/kibana-plugin-public.savedobjectsupdateoptions.references.md create mode 100644 docs/development/core/public/kibana-plugin-public.savedobjectsupdateoptions.version.md create mode 100644 docs/development/core/public/kibana-plugin-public.simplesavedobject.(constructor).md create mode 100644 docs/development/core/public/kibana-plugin-public.simplesavedobject._version.md create mode 100644 docs/development/core/public/kibana-plugin-public.simplesavedobject.attributes.md create mode 100644 docs/development/core/public/kibana-plugin-public.simplesavedobject.delete.md create mode 100644 docs/development/core/public/kibana-plugin-public.simplesavedobject.error.md create mode 100644 docs/development/core/public/kibana-plugin-public.simplesavedobject.get.md create mode 100644 docs/development/core/public/kibana-plugin-public.simplesavedobject.has.md create mode 100644 docs/development/core/public/kibana-plugin-public.simplesavedobject.id.md create mode 100644 docs/development/core/public/kibana-plugin-public.simplesavedobject.md create mode 100644 docs/development/core/public/kibana-plugin-public.simplesavedobject.migrationversion.md create mode 100644 docs/development/core/public/kibana-plugin-public.simplesavedobject.references.md create mode 100644 docs/development/core/public/kibana-plugin-public.simplesavedobject.save.md create mode 100644 docs/development/core/public/kibana-plugin-public.simplesavedobject.set.md create mode 100644 docs/development/core/public/kibana-plugin-public.simplesavedobject.type.md create mode 100644 docs/development/core/server/kibana-plugin-server.savedobjectattribute.md create mode 100644 docs/development/core/server/kibana-plugin-server.savedobjectsmigrationlogger.debug.md create mode 100644 docs/development/core/server/kibana-plugin-server.savedobjectsmigrationlogger.info.md create mode 100644 docs/development/core/server/kibana-plugin-server.savedobjectsmigrationlogger.md create mode 100644 docs/development/core/server/kibana-plugin-server.savedobjectsmigrationlogger.warning.md create mode 100644 src/core/public/saved_objects/index.ts create mode 100644 src/core/public/saved_objects/saved_objects_client.test.ts rename src/{legacy/ui => core}/public/saved_objects/saved_objects_client.ts (58%) create mode 100644 src/core/public/saved_objects/saved_objects_service.mock.ts create mode 100644 src/core/public/saved_objects/saved_objects_service.ts rename src/{legacy/ui => core}/public/saved_objects/simple_saved_object.ts (90%) create mode 100644 src/core/server/saved_objects/types.ts rename src/{legacy/ui/public/chrome/api/saved_object_client.js => core/server/types.ts~master} (76%) create mode 100644 src/legacy/ui/public/chrome/api/saved_object_client.ts delete mode 100644 src/legacy/ui/public/saved_objects/saved_objects_client.test.ts diff --git a/docs/development/core/public/kibana-plugin-public.corestart.md b/docs/development/core/public/kibana-plugin-public.corestart.md index d22bcb09a1054..446e458735214 100644 --- a/docs/development/core/public/kibana-plugin-public.corestart.md +++ b/docs/development/core/public/kibana-plugin-public.corestart.md @@ -23,5 +23,6 @@ export interface CoreStart | [i18n](./kibana-plugin-public.corestart.i18n.md) | I18nStart | [I18nStart](./kibana-plugin-public.i18nstart.md) | | [notifications](./kibana-plugin-public.corestart.notifications.md) | NotificationsStart | [NotificationsStart](./kibana-plugin-public.notificationsstart.md) | | [overlays](./kibana-plugin-public.corestart.overlays.md) | OverlayStart | [OverlayStart](./kibana-plugin-public.overlaystart.md) | +| [savedObjects](./kibana-plugin-public.corestart.savedobjects.md) | SavedObjectsStart | [SavedObjectsStart](./kibana-plugin-public.savedobjectsstart.md) | | [uiSettings](./kibana-plugin-public.corestart.uisettings.md) | UiSettingsClientContract | [UiSettingsClient](./kibana-plugin-public.uisettingsclient.md) | diff --git a/docs/development/core/public/kibana-plugin-public.corestart.savedobjects.md b/docs/development/core/public/kibana-plugin-public.corestart.savedobjects.md new file mode 100644 index 0000000000000..5e6e0e33c7f80 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.corestart.savedobjects.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [CoreStart](./kibana-plugin-public.corestart.md) > [savedObjects](./kibana-plugin-public.corestart.savedobjects.md) + +## CoreStart.savedObjects property + +[SavedObjectsStart](./kibana-plugin-public.savedobjectsstart.md) + +Signature: + +```typescript +savedObjects: SavedObjectsStart; +``` diff --git a/docs/development/core/public/kibana-plugin-public.md b/docs/development/core/public/kibana-plugin-public.md index afd22ecf174b4..5fda9f9159306 100644 --- a/docs/development/core/public/kibana-plugin-public.md +++ b/docs/development/core/public/kibana-plugin-public.md @@ -14,6 +14,8 @@ The plugin integrates with the core system via lifecycle events: `setup` | Class | Description | | --- | --- | +| [SavedObjectsClient](./kibana-plugin-public.savedobjectsclient.md) | Saved Objects is Kibana's data persisentence mechanism allowing plugins to use Elasticsearch for storing plugin state. The client-side SavedObjectsClient is a thin convenience library around the SavedObjects HTTP API for interacting with Saved Objects. | +| [SimpleSavedObject](./kibana-plugin-public.simplesavedobject.md) | This class is a very simple wrapper for SavedObjects loaded from the server with the [SavedObjectsClient](./kibana-plugin-public.savedobjectsclient.md).It provides basic functionality for creating/saving/deleting saved objects, but doesn't include any type-specific implementations. | | [ToastsApi](./kibana-plugin-public.toastsapi.md) | | | [UiSettingsClient](./kibana-plugin-public.uisettingsclient.md) | | @@ -59,6 +61,19 @@ The plugin integrates with the core system via lifecycle events: `setup` | [OverlayStart](./kibana-plugin-public.overlaystart.md) | | | [Plugin](./kibana-plugin-public.plugin.md) | The interface that should be returned by a PluginInitializer. | | [PluginInitializerContext](./kibana-plugin-public.plugininitializercontext.md) | The available core services passed to a PluginInitializer | +| [SavedObject](./kibana-plugin-public.savedobject.md) | | +| [SavedObjectAttributes](./kibana-plugin-public.savedobjectattributes.md) | The data for a Saved Object is stored in the attributes key as either an object or an array of objects. | +| [SavedObjectReference](./kibana-plugin-public.savedobjectreference.md) | A reference to another saved object. | +| [SavedObjectsBaseOptions](./kibana-plugin-public.savedobjectsbaseoptions.md) | | +| [SavedObjectsBatchResponse](./kibana-plugin-public.savedobjectsbatchresponse.md) | | +| [SavedObjectsBulkCreateObject](./kibana-plugin-public.savedobjectsbulkcreateobject.md) | | +| [SavedObjectsBulkCreateOptions](./kibana-plugin-public.savedobjectsbulkcreateoptions.md) | | +| [SavedObjectsCreateOptions](./kibana-plugin-public.savedobjectscreateoptions.md) | | +| [SavedObjectsFindOptions](./kibana-plugin-public.savedobjectsfindoptions.md) | | +| [SavedObjectsFindResponsePublic](./kibana-plugin-public.savedobjectsfindresponsepublic.md) | Return type of the Saved Objects find() method.\*Note\*: this type is different between the Public and Server Saved Objects clients. | +| [SavedObjectsMigrationVersion](./kibana-plugin-public.savedobjectsmigrationversion.md) | Information about the migrations that have been applied to this SavedObject. When Kibana starts up, KibanaMigrator detects outdated documents and migrates them based on this value. For each migration that has been applied, the plugin's name is used as a key and the latest migration version as the value. | +| [SavedObjectsStart](./kibana-plugin-public.savedobjectsstart.md) | | +| [SavedObjectsUpdateOptions](./kibana-plugin-public.savedobjectsupdateoptions.md) | | | [UiSettingsState](./kibana-plugin-public.uisettingsstate.md) | | ## Type Aliases @@ -76,6 +91,8 @@ The plugin integrates with the core system via lifecycle events: `setup` | [PluginInitializer](./kibana-plugin-public.plugininitializer.md) | The plugin export at the root of a plugin's public directory should conform to this interface. | | [PluginOpaqueId](./kibana-plugin-public.pluginopaqueid.md) | | | [RecursiveReadonly](./kibana-plugin-public.recursivereadonly.md) | | +| [SavedObjectAttribute](./kibana-plugin-public.savedobjectattribute.md) | | +| [SavedObjectsClientContract](./kibana-plugin-public.savedobjectsclientcontract.md) | SavedObjectsClientContract as implemented by the [SavedObjectsClient](./kibana-plugin-public.savedobjectsclient.md) | | [ToastInput](./kibana-plugin-public.toastinput.md) | | | [UiSettingsClientContract](./kibana-plugin-public.uisettingsclientcontract.md) | [UiSettingsClient](./kibana-plugin-public.uisettingsclient.md) | diff --git a/docs/development/core/public/kibana-plugin-public.savedobject.attributes.md b/docs/development/core/public/kibana-plugin-public.savedobject.attributes.md new file mode 100644 index 0000000000000..f9d39c15fcff4 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobject.attributes.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObject](./kibana-plugin-public.savedobject.md) > [attributes](./kibana-plugin-public.savedobject.attributes.md) + +## SavedObject.attributes property + +The data for a Saved Object is stored in the `attributes` key as either an object or an array of objects. + +Signature: + +```typescript +attributes: T; +``` diff --git a/docs/development/core/public/kibana-plugin-public.savedobject.error.md b/docs/development/core/public/kibana-plugin-public.savedobject.error.md new file mode 100644 index 0000000000000..1d00863ef6ecf --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobject.error.md @@ -0,0 +1,14 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObject](./kibana-plugin-public.savedobject.md) > [error](./kibana-plugin-public.savedobject.error.md) + +## SavedObject.error property + +Signature: + +```typescript +error?: { + message: string; + statusCode: number; + }; +``` diff --git a/docs/development/core/public/kibana-plugin-public.savedobject.id.md b/docs/development/core/public/kibana-plugin-public.savedobject.id.md new file mode 100644 index 0000000000000..7b54e0a7c2a74 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobject.id.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObject](./kibana-plugin-public.savedobject.md) > [id](./kibana-plugin-public.savedobject.id.md) + +## SavedObject.id property + +The ID of this Saved Object, guaranteed to be unique for all objects of the same `type` + +Signature: + +```typescript +id: string; +``` diff --git a/docs/development/core/public/kibana-plugin-public.savedobject.md b/docs/development/core/public/kibana-plugin-public.savedobject.md new file mode 100644 index 0000000000000..9bf0149f0854e --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobject.md @@ -0,0 +1,26 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObject](./kibana-plugin-public.savedobject.md) + +## SavedObject interface + + +Signature: + +```typescript +export interface SavedObject +``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [attributes](./kibana-plugin-public.savedobject.attributes.md) | T | The data for a Saved Object is stored in the attributes key as either an object or an array of objects. | +| [error](./kibana-plugin-public.savedobject.error.md) | {
message: string;
statusCode: number;
} | | +| [id](./kibana-plugin-public.savedobject.id.md) | string | The ID of this Saved Object, guaranteed to be unique for all objects of the same type | +| [migrationVersion](./kibana-plugin-public.savedobject.migrationversion.md) | SavedObjectsMigrationVersion | Information about the migrations that have been applied to this SavedObject. When Kibana starts up, KibanaMigrator detects outdated documents and migrates them based on this value. For each migration that has been applied, the plugin's name is used as a key and the latest migration version as the value. | +| [references](./kibana-plugin-public.savedobject.references.md) | SavedObjectReference[] | A reference to another saved object. | +| [type](./kibana-plugin-public.savedobject.type.md) | string | The type of Saved Object. Each plugin can define it's own custom Saved Object types. | +| [updated\_at](./kibana-plugin-public.savedobject.updated_at.md) | string | Timestamp of the last time this document had been updated. | +| [version](./kibana-plugin-public.savedobject.version.md) | string | An opaque version number which changes on each successful write operation. Can be used for implementing optimistic concurrency control. | + diff --git a/docs/development/core/public/kibana-plugin-public.savedobject.migrationversion.md b/docs/development/core/public/kibana-plugin-public.savedobject.migrationversion.md new file mode 100644 index 0000000000000..d07b664f11ff2 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobject.migrationversion.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObject](./kibana-plugin-public.savedobject.md) > [migrationVersion](./kibana-plugin-public.savedobject.migrationversion.md) + +## SavedObject.migrationVersion property + +Information about the migrations that have been applied to this SavedObject. When Kibana starts up, KibanaMigrator detects outdated documents and migrates them based on this value. For each migration that has been applied, the plugin's name is used as a key and the latest migration version as the value. + +Signature: + +```typescript +migrationVersion?: SavedObjectsMigrationVersion; +``` diff --git a/docs/development/core/public/kibana-plugin-public.savedobject.references.md b/docs/development/core/public/kibana-plugin-public.savedobject.references.md new file mode 100644 index 0000000000000..3c3ecdd283b5f --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobject.references.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObject](./kibana-plugin-public.savedobject.md) > [references](./kibana-plugin-public.savedobject.references.md) + +## SavedObject.references property + +A reference to another saved object. + +Signature: + +```typescript +references: SavedObjectReference[]; +``` diff --git a/docs/development/core/public/kibana-plugin-public.savedobject.type.md b/docs/development/core/public/kibana-plugin-public.savedobject.type.md new file mode 100644 index 0000000000000..2bce5b8a15634 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobject.type.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObject](./kibana-plugin-public.savedobject.md) > [type](./kibana-plugin-public.savedobject.type.md) + +## SavedObject.type property + +The type of Saved Object. Each plugin can define it's own custom Saved Object types. + +Signature: + +```typescript +type: string; +``` diff --git a/docs/development/core/public/kibana-plugin-public.savedobject.updated_at.md b/docs/development/core/public/kibana-plugin-public.savedobject.updated_at.md new file mode 100644 index 0000000000000..861128c69ae2a --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobject.updated_at.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObject](./kibana-plugin-public.savedobject.md) > [updated\_at](./kibana-plugin-public.savedobject.updated_at.md) + +## SavedObject.updated\_at property + +Timestamp of the last time this document had been updated. + +Signature: + +```typescript +updated_at?: string; +``` diff --git a/docs/development/core/public/kibana-plugin-public.savedobject.version.md b/docs/development/core/public/kibana-plugin-public.savedobject.version.md new file mode 100644 index 0000000000000..26356f444f2ca --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobject.version.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObject](./kibana-plugin-public.savedobject.md) > [version](./kibana-plugin-public.savedobject.version.md) + +## SavedObject.version property + +An opaque version number which changes on each successful write operation. Can be used for implementing optimistic concurrency control. + +Signature: + +```typescript +version?: string; +``` diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectattribute.md b/docs/development/core/public/kibana-plugin-public.savedobjectattribute.md new file mode 100644 index 0000000000000..f8d51390863eb --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobjectattribute.md @@ -0,0 +1,12 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObjectAttribute](./kibana-plugin-public.savedobjectattribute.md) + +## SavedObjectAttribute type + + +Signature: + +```typescript +export declare type SavedObjectAttribute = string | number | boolean | null | undefined | SavedObjectAttributes | SavedObjectAttributes[]; +``` diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectattributes.md b/docs/development/core/public/kibana-plugin-public.savedobjectattributes.md new file mode 100644 index 0000000000000..4a9e096cc25b7 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobjectattributes.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObjectAttributes](./kibana-plugin-public.savedobjectattributes.md) + +## SavedObjectAttributes interface + +The data for a Saved Object is stored in the `attributes` key as either an object or an array of objects. + +Signature: + +```typescript +export interface SavedObjectAttributes +``` diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectreference.id.md b/docs/development/core/public/kibana-plugin-public.savedobjectreference.id.md new file mode 100644 index 0000000000000..27b820607f860 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobjectreference.id.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObjectReference](./kibana-plugin-public.savedobjectreference.md) > [id](./kibana-plugin-public.savedobjectreference.id.md) + +## SavedObjectReference.id property + +Signature: + +```typescript +id: string; +``` diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectreference.md b/docs/development/core/public/kibana-plugin-public.savedobjectreference.md new file mode 100644 index 0000000000000..7ae05e24a5d89 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobjectreference.md @@ -0,0 +1,22 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObjectReference](./kibana-plugin-public.savedobjectreference.md) + +## SavedObjectReference interface + +A reference to another saved object. + +Signature: + +```typescript +export interface SavedObjectReference +``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [id](./kibana-plugin-public.savedobjectreference.id.md) | string | | +| [name](./kibana-plugin-public.savedobjectreference.name.md) | string | | +| [type](./kibana-plugin-public.savedobjectreference.type.md) | string | | + diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectreference.name.md b/docs/development/core/public/kibana-plugin-public.savedobjectreference.name.md new file mode 100644 index 0000000000000..104a8c313b528 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobjectreference.name.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObjectReference](./kibana-plugin-public.savedobjectreference.md) > [name](./kibana-plugin-public.savedobjectreference.name.md) + +## SavedObjectReference.name property + +Signature: + +```typescript +name: string; +``` diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectreference.type.md b/docs/development/core/public/kibana-plugin-public.savedobjectreference.type.md new file mode 100644 index 0000000000000..5b55a18becab7 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobjectreference.type.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObjectReference](./kibana-plugin-public.savedobjectreference.md) > [type](./kibana-plugin-public.savedobjectreference.type.md) + +## SavedObjectReference.type property + +Signature: + +```typescript +type: string; +``` diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsbaseoptions.md b/docs/development/core/public/kibana-plugin-public.savedobjectsbaseoptions.md new file mode 100644 index 0000000000000..00ea2fd158291 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsbaseoptions.md @@ -0,0 +1,19 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObjectsBaseOptions](./kibana-plugin-public.savedobjectsbaseoptions.md) + +## SavedObjectsBaseOptions interface + + +Signature: + +```typescript +export interface SavedObjectsBaseOptions +``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [namespace](./kibana-plugin-public.savedobjectsbaseoptions.namespace.md) | string | Specify the namespace for this operation | + diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsbaseoptions.namespace.md b/docs/development/core/public/kibana-plugin-public.savedobjectsbaseoptions.namespace.md new file mode 100644 index 0000000000000..fb8d0d957a275 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsbaseoptions.namespace.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObjectsBaseOptions](./kibana-plugin-public.savedobjectsbaseoptions.md) > [namespace](./kibana-plugin-public.savedobjectsbaseoptions.namespace.md) + +## SavedObjectsBaseOptions.namespace property + +Specify the namespace for this operation + +Signature: + +```typescript +namespace?: string; +``` diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsbatchresponse.md b/docs/development/core/public/kibana-plugin-public.savedobjectsbatchresponse.md new file mode 100644 index 0000000000000..2ccddb8f71bd6 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsbatchresponse.md @@ -0,0 +1,19 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObjectsBatchResponse](./kibana-plugin-public.savedobjectsbatchresponse.md) + +## SavedObjectsBatchResponse interface + + +Signature: + +```typescript +export interface SavedObjectsBatchResponse +``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [savedObjects](./kibana-plugin-public.savedobjectsbatchresponse.savedobjects.md) | Array<SimpleSavedObject<T>> | | + diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsbatchresponse.savedobjects.md b/docs/development/core/public/kibana-plugin-public.savedobjectsbatchresponse.savedobjects.md new file mode 100644 index 0000000000000..f83b6268431c7 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsbatchresponse.savedobjects.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObjectsBatchResponse](./kibana-plugin-public.savedobjectsbatchresponse.md) > [savedObjects](./kibana-plugin-public.savedobjectsbatchresponse.savedobjects.md) + +## SavedObjectsBatchResponse.savedObjects property + +Signature: + +```typescript +savedObjects: Array>; +``` diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsbulkcreateobject.attributes.md b/docs/development/core/public/kibana-plugin-public.savedobjectsbulkcreateobject.attributes.md new file mode 100644 index 0000000000000..e3f7e0d676087 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsbulkcreateobject.attributes.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObjectsBulkCreateObject](./kibana-plugin-public.savedobjectsbulkcreateobject.md) > [attributes](./kibana-plugin-public.savedobjectsbulkcreateobject.attributes.md) + +## SavedObjectsBulkCreateObject.attributes property + +Signature: + +```typescript +attributes: T; +``` diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsbulkcreateobject.md b/docs/development/core/public/kibana-plugin-public.savedobjectsbulkcreateobject.md new file mode 100644 index 0000000000000..8f95c0533dded --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsbulkcreateobject.md @@ -0,0 +1,19 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObjectsBulkCreateObject](./kibana-plugin-public.savedobjectsbulkcreateobject.md) + +## SavedObjectsBulkCreateObject interface + +Signature: + +```typescript +export interface SavedObjectsBulkCreateObject extends SavedObjectsCreateOptions +``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [attributes](./kibana-plugin-public.savedobjectsbulkcreateobject.attributes.md) | T | | +| [type](./kibana-plugin-public.savedobjectsbulkcreateobject.type.md) | string | | + diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsbulkcreateobject.type.md b/docs/development/core/public/kibana-plugin-public.savedobjectsbulkcreateobject.type.md new file mode 100644 index 0000000000000..37497b9178782 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsbulkcreateobject.type.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObjectsBulkCreateObject](./kibana-plugin-public.savedobjectsbulkcreateobject.md) > [type](./kibana-plugin-public.savedobjectsbulkcreateobject.type.md) + +## SavedObjectsBulkCreateObject.type property + +Signature: + +```typescript +type: string; +``` diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsbulkcreateoptions.md b/docs/development/core/public/kibana-plugin-public.savedobjectsbulkcreateoptions.md new file mode 100644 index 0000000000000..697084d8eee38 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsbulkcreateoptions.md @@ -0,0 +1,19 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObjectsBulkCreateOptions](./kibana-plugin-public.savedobjectsbulkcreateoptions.md) + +## SavedObjectsBulkCreateOptions interface + + +Signature: + +```typescript +export interface SavedObjectsBulkCreateOptions +``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [overwrite](./kibana-plugin-public.savedobjectsbulkcreateoptions.overwrite.md) | boolean | If a document with the given id already exists, overwrite it's contents (default=false). | + diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsbulkcreateoptions.overwrite.md b/docs/development/core/public/kibana-plugin-public.savedobjectsbulkcreateoptions.overwrite.md new file mode 100644 index 0000000000000..e3b425da892b2 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsbulkcreateoptions.overwrite.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObjectsBulkCreateOptions](./kibana-plugin-public.savedobjectsbulkcreateoptions.md) > [overwrite](./kibana-plugin-public.savedobjectsbulkcreateoptions.overwrite.md) + +## SavedObjectsBulkCreateOptions.overwrite property + +If a document with the given `id` already exists, overwrite it's contents (default=false). + +Signature: + +```typescript +overwrite?: boolean; +``` diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsclient.bulkcreate.md b/docs/development/core/public/kibana-plugin-public.savedobjectsclient.bulkcreate.md new file mode 100644 index 0000000000000..426096d96c9ba --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsclient.bulkcreate.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObjectsClient](./kibana-plugin-public.savedobjectsclient.md) > [bulkCreate](./kibana-plugin-public.savedobjectsclient.bulkcreate.md) + +## SavedObjectsClient.bulkCreate property + +Creates multiple documents at once + +Signature: + +```typescript +bulkCreate: (objects?: SavedObjectsBulkCreateObject[], options?: SavedObjectsBulkCreateOptions) => Promise>; +``` diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsclient.bulkget.md b/docs/development/core/public/kibana-plugin-public.savedobjectsclient.bulkget.md new file mode 100644 index 0000000000000..fc8b3c8258f9c --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsclient.bulkget.md @@ -0,0 +1,21 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObjectsClient](./kibana-plugin-public.savedobjectsclient.md) > [bulkGet](./kibana-plugin-public.savedobjectsclient.bulkget.md) + +## SavedObjectsClient.bulkGet property + +Returns an array of objects by id + +Signature: + +```typescript +bulkGet: (objects?: { + id: string; + type: string; + }[]) => Promise>; +``` + +## Example + +bulkGet(\[ { id: 'one', type: 'config' }, { id: 'foo', type: 'index-pattern' } \]) + diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsclient.create.md b/docs/development/core/public/kibana-plugin-public.savedobjectsclient.create.md new file mode 100644 index 0000000000000..d6366494f0037 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsclient.create.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObjectsClient](./kibana-plugin-public.savedobjectsclient.md) > [create](./kibana-plugin-public.savedobjectsclient.create.md) + +## SavedObjectsClient.create property + +Persists an object + +Signature: + +```typescript +create: (type: string, attributes: T, options?: SavedObjectsCreateOptions) => Promise>; +``` diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsclient.delete.md b/docs/development/core/public/kibana-plugin-public.savedobjectsclient.delete.md new file mode 100644 index 0000000000000..03658cbd9fcfd --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsclient.delete.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObjectsClient](./kibana-plugin-public.savedobjectsclient.md) > [delete](./kibana-plugin-public.savedobjectsclient.delete.md) + +## SavedObjectsClient.delete property + +Deletes an object + +Signature: + +```typescript +delete: (type: string, id: string) => Promise<{}>; +``` diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsclient.find.md b/docs/development/core/public/kibana-plugin-public.savedobjectsclient.find.md new file mode 100644 index 0000000000000..20b9ff35779f9 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsclient.find.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObjectsClient](./kibana-plugin-public.savedobjectsclient.md) > [find](./kibana-plugin-public.savedobjectsclient.find.md) + +## SavedObjectsClient.find property + +Search for objects + +Signature: + +```typescript +find: (options?: Pick) => Promise>; +``` diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsclient.get.md b/docs/development/core/public/kibana-plugin-public.savedobjectsclient.get.md new file mode 100644 index 0000000000000..88500f4e3a269 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsclient.get.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObjectsClient](./kibana-plugin-public.savedobjectsclient.md) > [get](./kibana-plugin-public.savedobjectsclient.get.md) + +## SavedObjectsClient.get property + +Fetches a single object + +Signature: + +```typescript +get: (type: string, id: string) => Promise>; +``` diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsclient.md b/docs/development/core/public/kibana-plugin-public.savedobjectsclient.md new file mode 100644 index 0000000000000..d0de26bb9b0a1 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsclient.md @@ -0,0 +1,35 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObjectsClient](./kibana-plugin-public.savedobjectsclient.md) + +## SavedObjectsClient class + +Saved Objects is Kibana's data persisentence mechanism allowing plugins to use Elasticsearch for storing plugin state. The client-side SavedObjectsClient is a thin convenience library around the SavedObjects HTTP API for interacting with Saved Objects. + +Signature: + +```typescript +export declare class SavedObjectsClient +``` + +## Properties + +| Property | Modifiers | Type | Description | +| --- | --- | --- | --- | +| [bulkCreate](./kibana-plugin-public.savedobjectsclient.bulkcreate.md) | | (objects?: SavedObjectsBulkCreateObject<SavedObjectAttributes>[], options?: SavedObjectsBulkCreateOptions) => Promise<SavedObjectsBatchResponse<SavedObjectAttributes>> | Creates multiple documents at once | +| [bulkGet](./kibana-plugin-public.savedobjectsclient.bulkget.md) | | (objects?: {
id: string;
type: string;
}[]) => Promise<SavedObjectsBatchResponse<SavedObjectAttributes>> | Returns an array of objects by id | +| [create](./kibana-plugin-public.savedobjectsclient.create.md) | | <T extends SavedObjectAttributes>(type: string, attributes: T, options?: SavedObjectsCreateOptions) => Promise<SimpleSavedObject<T>> | Persists an object | +| [delete](./kibana-plugin-public.savedobjectsclient.delete.md) | | (type: string, id: string) => Promise<{}> | Deletes an object | +| [find](./kibana-plugin-public.savedobjectsclient.find.md) | | <T extends SavedObjectAttributes>(options?: Pick<SavedObjectFindOptionsServer, "search" | "type" | "defaultSearchOperator" | "searchFields" | "sortField" | "hasReference" | "page" | "perPage" | "fields">) => Promise<SavedObjectsFindResponsePublic<T>> | Search for objects | +| [get](./kibana-plugin-public.savedobjectsclient.get.md) | | <T extends SavedObjectAttributes>(type: string, id: string) => Promise<SimpleSavedObject<T>> | Fetches a single object | + +## Methods + +| Method | Modifiers | Description | +| --- | --- | --- | +| [update(type, id, attributes, { version, migrationVersion, references })](./kibana-plugin-public.savedobjectsclient.update.md) | | Updates an object | + +## Remarks + +The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the `SavedObjectsClient` class. + diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsclient.update.md b/docs/development/core/public/kibana-plugin-public.savedobjectsclient.update.md new file mode 100644 index 0000000000000..5f87f46d6206f --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsclient.update.md @@ -0,0 +1,28 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObjectsClient](./kibana-plugin-public.savedobjectsclient.md) > [update](./kibana-plugin-public.savedobjectsclient.update.md) + +## SavedObjectsClient.update() method + +Updates an object + +Signature: + +```typescript +update(type: string, id: string, attributes: T, { version, migrationVersion, references }?: SavedObjectsUpdateOptions): Promise>; +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| type | string | | +| id | string | | +| attributes | T | | +| { version, migrationVersion, references } | SavedObjectsUpdateOptions | | + +Returns: + +`Promise>` + + diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsclientcontract.md b/docs/development/core/public/kibana-plugin-public.savedobjectsclientcontract.md new file mode 100644 index 0000000000000..876f3164feec2 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsclientcontract.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObjectsClientContract](./kibana-plugin-public.savedobjectsclientcontract.md) + +## SavedObjectsClientContract type + +SavedObjectsClientContract as implemented by the [SavedObjectsClient](./kibana-plugin-public.savedobjectsclient.md) + +Signature: + +```typescript +export declare type SavedObjectsClientContract = PublicMethodsOf; +``` diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectscreateoptions.id.md b/docs/development/core/public/kibana-plugin-public.savedobjectscreateoptions.id.md new file mode 100644 index 0000000000000..fc0532a10d639 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobjectscreateoptions.id.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObjectsCreateOptions](./kibana-plugin-public.savedobjectscreateoptions.md) > [id](./kibana-plugin-public.savedobjectscreateoptions.id.md) + +## SavedObjectsCreateOptions.id property + +(Not recommended) Specify an id instead of having the saved objects service generate one for you. + +Signature: + +```typescript +id?: string; +``` diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectscreateoptions.md b/docs/development/core/public/kibana-plugin-public.savedobjectscreateoptions.md new file mode 100644 index 0000000000000..08090c0f8d8c3 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobjectscreateoptions.md @@ -0,0 +1,22 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObjectsCreateOptions](./kibana-plugin-public.savedobjectscreateoptions.md) + +## SavedObjectsCreateOptions interface + + +Signature: + +```typescript +export interface SavedObjectsCreateOptions +``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [id](./kibana-plugin-public.savedobjectscreateoptions.id.md) | string | (Not recommended) Specify an id instead of having the saved objects service generate one for you. | +| [migrationVersion](./kibana-plugin-public.savedobjectscreateoptions.migrationversion.md) | SavedObjectsMigrationVersion | Information about the migrations that have been applied to this SavedObject. When Kibana starts up, KibanaMigrator detects outdated documents and migrates them based on this value. For each migration that has been applied, the plugin's name is used as a key and the latest migration version as the value. | +| [overwrite](./kibana-plugin-public.savedobjectscreateoptions.overwrite.md) | boolean | If a document with the given id already exists, overwrite it's contents (default=false). | +| [references](./kibana-plugin-public.savedobjectscreateoptions.references.md) | SavedObjectReference[] | | + diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectscreateoptions.migrationversion.md b/docs/development/core/public/kibana-plugin-public.savedobjectscreateoptions.migrationversion.md new file mode 100644 index 0000000000000..5bc6b62f6680e --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobjectscreateoptions.migrationversion.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObjectsCreateOptions](./kibana-plugin-public.savedobjectscreateoptions.md) > [migrationVersion](./kibana-plugin-public.savedobjectscreateoptions.migrationversion.md) + +## SavedObjectsCreateOptions.migrationVersion property + +Information about the migrations that have been applied to this SavedObject. When Kibana starts up, KibanaMigrator detects outdated documents and migrates them based on this value. For each migration that has been applied, the plugin's name is used as a key and the latest migration version as the value. + +Signature: + +```typescript +migrationVersion?: SavedObjectsMigrationVersion; +``` diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectscreateoptions.overwrite.md b/docs/development/core/public/kibana-plugin-public.savedobjectscreateoptions.overwrite.md new file mode 100644 index 0000000000000..d83541fc9e874 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobjectscreateoptions.overwrite.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObjectsCreateOptions](./kibana-plugin-public.savedobjectscreateoptions.md) > [overwrite](./kibana-plugin-public.savedobjectscreateoptions.overwrite.md) + +## SavedObjectsCreateOptions.overwrite property + +If a document with the given `id` already exists, overwrite it's contents (default=false). + +Signature: + +```typescript +overwrite?: boolean; +``` diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectscreateoptions.references.md b/docs/development/core/public/kibana-plugin-public.savedobjectscreateoptions.references.md new file mode 100644 index 0000000000000..f6bcd47a3e8d5 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobjectscreateoptions.references.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObjectsCreateOptions](./kibana-plugin-public.savedobjectscreateoptions.md) > [references](./kibana-plugin-public.savedobjectscreateoptions.references.md) + +## SavedObjectsCreateOptions.references property + +Signature: + +```typescript +references?: SavedObjectReference[]; +``` diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsfindoptions.defaultsearchoperator.md b/docs/development/core/public/kibana-plugin-public.savedobjectsfindoptions.defaultsearchoperator.md new file mode 100644 index 0000000000000..181e2bb237c53 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsfindoptions.defaultsearchoperator.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObjectsFindOptions](./kibana-plugin-public.savedobjectsfindoptions.md) > [defaultSearchOperator](./kibana-plugin-public.savedobjectsfindoptions.defaultsearchoperator.md) + +## SavedObjectsFindOptions.defaultSearchOperator property + +Signature: + +```typescript +defaultSearchOperator?: 'AND' | 'OR'; +``` diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsfindoptions.fields.md b/docs/development/core/public/kibana-plugin-public.savedobjectsfindoptions.fields.md new file mode 100644 index 0000000000000..20cbf04418222 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsfindoptions.fields.md @@ -0,0 +1,18 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObjectsFindOptions](./kibana-plugin-public.savedobjectsfindoptions.md) > [fields](./kibana-plugin-public.savedobjectsfindoptions.fields.md) + +## SavedObjectsFindOptions.fields property + +An array of fields to include in the results + +Signature: + +```typescript +fields?: string[]; +``` + +## Example + +SavedObjects.find({type: 'dashboard', fields: \['attributes.name', 'attributes.location'\]}) + diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsfindoptions.hasreference.md b/docs/development/core/public/kibana-plugin-public.savedobjectsfindoptions.hasreference.md new file mode 100644 index 0000000000000..63f65d22cc33b --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsfindoptions.hasreference.md @@ -0,0 +1,14 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObjectsFindOptions](./kibana-plugin-public.savedobjectsfindoptions.md) > [hasReference](./kibana-plugin-public.savedobjectsfindoptions.hasreference.md) + +## SavedObjectsFindOptions.hasReference property + +Signature: + +```typescript +hasReference?: { + type: string; + id: string; + }; +``` diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsfindoptions.md b/docs/development/core/public/kibana-plugin-public.savedobjectsfindoptions.md new file mode 100644 index 0000000000000..f90c60ebdd0dc --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsfindoptions.md @@ -0,0 +1,28 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObjectsFindOptions](./kibana-plugin-public.savedobjectsfindoptions.md) + +## SavedObjectsFindOptions interface + + +Signature: + +```typescript +export interface SavedObjectsFindOptions extends SavedObjectsBaseOptions +``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [defaultSearchOperator](./kibana-plugin-public.savedobjectsfindoptions.defaultsearchoperator.md) | 'AND' | 'OR' | | +| [fields](./kibana-plugin-public.savedobjectsfindoptions.fields.md) | string[] | An array of fields to include in the results | +| [hasReference](./kibana-plugin-public.savedobjectsfindoptions.hasreference.md) | {
type: string;
id: string;
} | | +| [page](./kibana-plugin-public.savedobjectsfindoptions.page.md) | number | | +| [perPage](./kibana-plugin-public.savedobjectsfindoptions.perpage.md) | number | | +| [search](./kibana-plugin-public.savedobjectsfindoptions.search.md) | string | Search documents using the Elasticsearch Simple Query String syntax. See Elasticsearch Simple Query String query argument for more information | +| [searchFields](./kibana-plugin-public.savedobjectsfindoptions.searchfields.md) | string[] | The fields to perform the parsed query against. See Elasticsearch Simple Query String fields argument for more information | +| [sortField](./kibana-plugin-public.savedobjectsfindoptions.sortfield.md) | string | | +| [sortOrder](./kibana-plugin-public.savedobjectsfindoptions.sortorder.md) | string | | +| [type](./kibana-plugin-public.savedobjectsfindoptions.type.md) | string | string[] | | + diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsfindoptions.page.md b/docs/development/core/public/kibana-plugin-public.savedobjectsfindoptions.page.md new file mode 100644 index 0000000000000..982005adb2454 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsfindoptions.page.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObjectsFindOptions](./kibana-plugin-public.savedobjectsfindoptions.md) > [page](./kibana-plugin-public.savedobjectsfindoptions.page.md) + +## SavedObjectsFindOptions.page property + +Signature: + +```typescript +page?: number; +``` diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsfindoptions.perpage.md b/docs/development/core/public/kibana-plugin-public.savedobjectsfindoptions.perpage.md new file mode 100644 index 0000000000000..3c61f690d82c0 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsfindoptions.perpage.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObjectsFindOptions](./kibana-plugin-public.savedobjectsfindoptions.md) > [perPage](./kibana-plugin-public.savedobjectsfindoptions.perpage.md) + +## SavedObjectsFindOptions.perPage property + +Signature: + +```typescript +perPage?: number; +``` diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsfindoptions.search.md b/docs/development/core/public/kibana-plugin-public.savedobjectsfindoptions.search.md new file mode 100644 index 0000000000000..f8f95e5329826 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsfindoptions.search.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObjectsFindOptions](./kibana-plugin-public.savedobjectsfindoptions.md) > [search](./kibana-plugin-public.savedobjectsfindoptions.search.md) + +## SavedObjectsFindOptions.search property + +Search documents using the Elasticsearch Simple Query String syntax. See Elasticsearch Simple Query String `query` argument for more information + +Signature: + +```typescript +search?: string; +``` diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsfindoptions.searchfields.md b/docs/development/core/public/kibana-plugin-public.savedobjectsfindoptions.searchfields.md new file mode 100644 index 0000000000000..5e97ef00b4417 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsfindoptions.searchfields.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObjectsFindOptions](./kibana-plugin-public.savedobjectsfindoptions.md) > [searchFields](./kibana-plugin-public.savedobjectsfindoptions.searchfields.md) + +## SavedObjectsFindOptions.searchFields property + +The fields to perform the parsed query against. See Elasticsearch Simple Query String `fields` argument for more information + +Signature: + +```typescript +searchFields?: string[]; +``` diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsfindoptions.sortfield.md b/docs/development/core/public/kibana-plugin-public.savedobjectsfindoptions.sortfield.md new file mode 100644 index 0000000000000..14ab40894cecd --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsfindoptions.sortfield.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObjectsFindOptions](./kibana-plugin-public.savedobjectsfindoptions.md) > [sortField](./kibana-plugin-public.savedobjectsfindoptions.sortfield.md) + +## SavedObjectsFindOptions.sortField property + +Signature: + +```typescript +sortField?: string; +``` diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsfindoptions.sortorder.md b/docs/development/core/public/kibana-plugin-public.savedobjectsfindoptions.sortorder.md new file mode 100644 index 0000000000000..b1e58658c0083 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsfindoptions.sortorder.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObjectsFindOptions](./kibana-plugin-public.savedobjectsfindoptions.md) > [sortOrder](./kibana-plugin-public.savedobjectsfindoptions.sortorder.md) + +## SavedObjectsFindOptions.sortOrder property + +Signature: + +```typescript +sortOrder?: string; +``` diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsfindoptions.type.md b/docs/development/core/public/kibana-plugin-public.savedobjectsfindoptions.type.md new file mode 100644 index 0000000000000..6706e8344a1e3 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsfindoptions.type.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObjectsFindOptions](./kibana-plugin-public.savedobjectsfindoptions.md) > [type](./kibana-plugin-public.savedobjectsfindoptions.type.md) + +## SavedObjectsFindOptions.type property + +Signature: + +```typescript +type?: string | string[]; +``` diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsfindresponsepublic.md b/docs/development/core/public/kibana-plugin-public.savedobjectsfindresponsepublic.md new file mode 100644 index 0000000000000..61a2daa59f16a --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsfindresponsepublic.md @@ -0,0 +1,24 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObjectsFindResponsePublic](./kibana-plugin-public.savedobjectsfindresponsepublic.md) + +## SavedObjectsFindResponsePublic interface + +Return type of the Saved Objects `find()` method. + +\*Note\*: this type is different between the Public and Server Saved Objects clients. + +Signature: + +```typescript +export interface SavedObjectsFindResponsePublic extends SavedObjectsBatchResponse +``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [page](./kibana-plugin-public.savedobjectsfindresponsepublic.page.md) | number | | +| [perPage](./kibana-plugin-public.savedobjectsfindresponsepublic.perpage.md) | number | | +| [total](./kibana-plugin-public.savedobjectsfindresponsepublic.total.md) | number | | + diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsfindresponsepublic.page.md b/docs/development/core/public/kibana-plugin-public.savedobjectsfindresponsepublic.page.md new file mode 100644 index 0000000000000..20e96d1e0df40 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsfindresponsepublic.page.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObjectsFindResponsePublic](./kibana-plugin-public.savedobjectsfindresponsepublic.md) > [page](./kibana-plugin-public.savedobjectsfindresponsepublic.page.md) + +## SavedObjectsFindResponsePublic.page property + +Signature: + +```typescript +page: number; +``` diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsfindresponsepublic.perpage.md b/docs/development/core/public/kibana-plugin-public.savedobjectsfindresponsepublic.perpage.md new file mode 100644 index 0000000000000..f706f9cb03b26 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsfindresponsepublic.perpage.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObjectsFindResponsePublic](./kibana-plugin-public.savedobjectsfindresponsepublic.md) > [perPage](./kibana-plugin-public.savedobjectsfindresponsepublic.perpage.md) + +## SavedObjectsFindResponsePublic.perPage property + +Signature: + +```typescript +perPage: number; +``` diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsfindresponsepublic.total.md b/docs/development/core/public/kibana-plugin-public.savedobjectsfindresponsepublic.total.md new file mode 100644 index 0000000000000..0a44c73436a2c --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsfindresponsepublic.total.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObjectsFindResponsePublic](./kibana-plugin-public.savedobjectsfindresponsepublic.md) > [total](./kibana-plugin-public.savedobjectsfindresponsepublic.total.md) + +## SavedObjectsFindResponsePublic.total property + +Signature: + +```typescript +total: number; +``` diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsmigrationversion.md b/docs/development/core/public/kibana-plugin-public.savedobjectsmigrationversion.md new file mode 100644 index 0000000000000..675adb9498c50 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsmigrationversion.md @@ -0,0 +1,18 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObjectsMigrationVersion](./kibana-plugin-public.savedobjectsmigrationversion.md) + +## SavedObjectsMigrationVersion interface + +Information about the migrations that have been applied to this SavedObject. When Kibana starts up, KibanaMigrator detects outdated documents and migrates them based on this value. For each migration that has been applied, the plugin's name is used as a key and the latest migration version as the value. + +Signature: + +```typescript +export interface SavedObjectsMigrationVersion +``` + +## Example + +migrationVersion: { dashboard: '7.1.1', space: '6.6.6', } + diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsstart.client.md b/docs/development/core/public/kibana-plugin-public.savedobjectsstart.client.md new file mode 100644 index 0000000000000..d3e0da7a414b0 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsstart.client.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObjectsStart](./kibana-plugin-public.savedobjectsstart.md) > [client](./kibana-plugin-public.savedobjectsstart.client.md) + +## SavedObjectsStart.client property + +[SavedObjectsClient](./kibana-plugin-public.savedobjectsclient.md) + +Signature: + +```typescript +client: SavedObjectsClientContract; +``` diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsstart.md b/docs/development/core/public/kibana-plugin-public.savedobjectsstart.md new file mode 100644 index 0000000000000..07a70f306cd26 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsstart.md @@ -0,0 +1,19 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObjectsStart](./kibana-plugin-public.savedobjectsstart.md) + +## SavedObjectsStart interface + + +Signature: + +```typescript +export interface SavedObjectsStart +``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [client](./kibana-plugin-public.savedobjectsstart.client.md) | SavedObjectsClientContract | [SavedObjectsClient](./kibana-plugin-public.savedobjectsclient.md) | + diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsupdateoptions.md b/docs/development/core/public/kibana-plugin-public.savedobjectsupdateoptions.md new file mode 100644 index 0000000000000..800a78d65486b --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsupdateoptions.md @@ -0,0 +1,21 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObjectsUpdateOptions](./kibana-plugin-public.savedobjectsupdateoptions.md) + +## SavedObjectsUpdateOptions interface + + +Signature: + +```typescript +export interface SavedObjectsUpdateOptions +``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [migrationVersion](./kibana-plugin-public.savedobjectsupdateoptions.migrationversion.md) | SavedObjectsMigrationVersion | Information about the migrations that have been applied to this SavedObject. When Kibana starts up, KibanaMigrator detects outdated documents and migrates them based on this value. For each migration that has been applied, the plugin's name is used as a key and the latest migration version as the value. | +| [references](./kibana-plugin-public.savedobjectsupdateoptions.references.md) | SavedObjectReference[] | | +| [version](./kibana-plugin-public.savedobjectsupdateoptions.version.md) | string | | + diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsupdateoptions.migrationversion.md b/docs/development/core/public/kibana-plugin-public.savedobjectsupdateoptions.migrationversion.md new file mode 100644 index 0000000000000..e5fe20acd3994 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsupdateoptions.migrationversion.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObjectsUpdateOptions](./kibana-plugin-public.savedobjectsupdateoptions.md) > [migrationVersion](./kibana-plugin-public.savedobjectsupdateoptions.migrationversion.md) + +## SavedObjectsUpdateOptions.migrationVersion property + +Information about the migrations that have been applied to this SavedObject. When Kibana starts up, KibanaMigrator detects outdated documents and migrates them based on this value. For each migration that has been applied, the plugin's name is used as a key and the latest migration version as the value. + +Signature: + +```typescript +migrationVersion?: SavedObjectsMigrationVersion; +``` diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsupdateoptions.references.md b/docs/development/core/public/kibana-plugin-public.savedobjectsupdateoptions.references.md new file mode 100644 index 0000000000000..eda84ec8e0bfa --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsupdateoptions.references.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObjectsUpdateOptions](./kibana-plugin-public.savedobjectsupdateoptions.md) > [references](./kibana-plugin-public.savedobjectsupdateoptions.references.md) + +## SavedObjectsUpdateOptions.references property + +Signature: + +```typescript +references?: SavedObjectReference[]; +``` diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsupdateoptions.version.md b/docs/development/core/public/kibana-plugin-public.savedobjectsupdateoptions.version.md new file mode 100644 index 0000000000000..9aacfa9124016 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsupdateoptions.version.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObjectsUpdateOptions](./kibana-plugin-public.savedobjectsupdateoptions.md) > [version](./kibana-plugin-public.savedobjectsupdateoptions.version.md) + +## SavedObjectsUpdateOptions.version property + +Signature: + +```typescript +version?: string; +``` diff --git a/docs/development/core/public/kibana-plugin-public.simplesavedobject.(constructor).md b/docs/development/core/public/kibana-plugin-public.simplesavedobject.(constructor).md new file mode 100644 index 0000000000000..e22154bc795fd --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.simplesavedobject.(constructor).md @@ -0,0 +1,21 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SimpleSavedObject](./kibana-plugin-public.simplesavedobject.md) > [(constructor)](./kibana-plugin-public.simplesavedobject.(constructor).md) + +## SimpleSavedObject.(constructor) + +Constructs a new instance of the `SimpleSavedObject` class + +Signature: + +```typescript +constructor(client: SavedObjectsClient, { id, type, version, attributes, error, references, migrationVersion }: SavedObjectType); +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| client | SavedObjectsClient | | +| { id, type, version, attributes, error, references, migrationVersion } | SavedObjectType<T> | | + diff --git a/docs/development/core/public/kibana-plugin-public.simplesavedobject._version.md b/docs/development/core/public/kibana-plugin-public.simplesavedobject._version.md new file mode 100644 index 0000000000000..7cbe08b8de760 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.simplesavedobject._version.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SimpleSavedObject](./kibana-plugin-public.simplesavedobject.md) > [\_version](./kibana-plugin-public.simplesavedobject._version.md) + +## SimpleSavedObject.\_version property + +Signature: + +```typescript +_version?: SavedObjectType['version']; +``` diff --git a/docs/development/core/public/kibana-plugin-public.simplesavedobject.attributes.md b/docs/development/core/public/kibana-plugin-public.simplesavedobject.attributes.md new file mode 100644 index 0000000000000..1c57136a1952e --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.simplesavedobject.attributes.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SimpleSavedObject](./kibana-plugin-public.simplesavedobject.md) > [attributes](./kibana-plugin-public.simplesavedobject.attributes.md) + +## SimpleSavedObject.attributes property + +Signature: + +```typescript +attributes: T; +``` diff --git a/docs/development/core/public/kibana-plugin-public.simplesavedobject.delete.md b/docs/development/core/public/kibana-plugin-public.simplesavedobject.delete.md new file mode 100644 index 0000000000000..8a04acfedec62 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.simplesavedobject.delete.md @@ -0,0 +1,15 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SimpleSavedObject](./kibana-plugin-public.simplesavedobject.md) > [delete](./kibana-plugin-public.simplesavedobject.delete.md) + +## SimpleSavedObject.delete() method + +Signature: + +```typescript +delete(): Promise<{}>; +``` +Returns: + +`Promise<{}>` + diff --git a/docs/development/core/public/kibana-plugin-public.simplesavedobject.error.md b/docs/development/core/public/kibana-plugin-public.simplesavedobject.error.md new file mode 100644 index 0000000000000..0b4f914ac92e8 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.simplesavedobject.error.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SimpleSavedObject](./kibana-plugin-public.simplesavedobject.md) > [error](./kibana-plugin-public.simplesavedobject.error.md) + +## SimpleSavedObject.error property + +Signature: + +```typescript +error: SavedObjectType['error']; +``` diff --git a/docs/development/core/public/kibana-plugin-public.simplesavedobject.get.md b/docs/development/core/public/kibana-plugin-public.simplesavedobject.get.md new file mode 100644 index 0000000000000..39a899e4a6cd3 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.simplesavedobject.get.md @@ -0,0 +1,22 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SimpleSavedObject](./kibana-plugin-public.simplesavedobject.md) > [get](./kibana-plugin-public.simplesavedobject.get.md) + +## SimpleSavedObject.get() method + +Signature: + +```typescript +get(key: string): any; +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| key | string | | + +Returns: + +`any` + diff --git a/docs/development/core/public/kibana-plugin-public.simplesavedobject.has.md b/docs/development/core/public/kibana-plugin-public.simplesavedobject.has.md new file mode 100644 index 0000000000000..5f3019d55c3f6 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.simplesavedobject.has.md @@ -0,0 +1,22 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SimpleSavedObject](./kibana-plugin-public.simplesavedobject.md) > [has](./kibana-plugin-public.simplesavedobject.has.md) + +## SimpleSavedObject.has() method + +Signature: + +```typescript +has(key: string): boolean; +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| key | string | | + +Returns: + +`boolean` + diff --git a/docs/development/core/public/kibana-plugin-public.simplesavedobject.id.md b/docs/development/core/public/kibana-plugin-public.simplesavedobject.id.md new file mode 100644 index 0000000000000..ed97976c4100f --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.simplesavedobject.id.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SimpleSavedObject](./kibana-plugin-public.simplesavedobject.md) > [id](./kibana-plugin-public.simplesavedobject.id.md) + +## SimpleSavedObject.id property + +Signature: + +```typescript +id: SavedObjectType['id']; +``` diff --git a/docs/development/core/public/kibana-plugin-public.simplesavedobject.md b/docs/development/core/public/kibana-plugin-public.simplesavedobject.md new file mode 100644 index 0000000000000..a40a04c17a582 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.simplesavedobject.md @@ -0,0 +1,44 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SimpleSavedObject](./kibana-plugin-public.simplesavedobject.md) + +## SimpleSavedObject class + +This class is a very simple wrapper for SavedObjects loaded from the server with the [SavedObjectsClient](./kibana-plugin-public.savedobjectsclient.md). + +It provides basic functionality for creating/saving/deleting saved objects, but doesn't include any type-specific implementations. + +Signature: + +```typescript +export declare class SimpleSavedObject +``` + +## Constructors + +| Constructor | Modifiers | Description | +| --- | --- | --- | +| [(constructor)(client, { id, type, version, attributes, error, references, migrationVersion })](./kibana-plugin-public.simplesavedobject.(constructor).md) | | Constructs a new instance of the SimpleSavedObject class | + +## Properties + +| Property | Modifiers | Type | Description | +| --- | --- | --- | --- | +| [\_version](./kibana-plugin-public.simplesavedobject._version.md) | | SavedObjectType<T>['version'] | | +| [attributes](./kibana-plugin-public.simplesavedobject.attributes.md) | | T | | +| [error](./kibana-plugin-public.simplesavedobject.error.md) | | SavedObjectType<T>['error'] | | +| [id](./kibana-plugin-public.simplesavedobject.id.md) | | SavedObjectType<T>['id'] | | +| [migrationVersion](./kibana-plugin-public.simplesavedobject.migrationversion.md) | | SavedObjectType<T>['migrationVersion'] | | +| [references](./kibana-plugin-public.simplesavedobject.references.md) | | SavedObjectType<T>['references'] | | +| [type](./kibana-plugin-public.simplesavedobject.type.md) | | SavedObjectType<T>['type'] | | + +## Methods + +| Method | Modifiers | Description | +| --- | --- | --- | +| [delete()](./kibana-plugin-public.simplesavedobject.delete.md) | | | +| [get(key)](./kibana-plugin-public.simplesavedobject.get.md) | | | +| [has(key)](./kibana-plugin-public.simplesavedobject.has.md) | | | +| [save()](./kibana-plugin-public.simplesavedobject.save.md) | | | +| [set(key, value)](./kibana-plugin-public.simplesavedobject.set.md) | | | + diff --git a/docs/development/core/public/kibana-plugin-public.simplesavedobject.migrationversion.md b/docs/development/core/public/kibana-plugin-public.simplesavedobject.migrationversion.md new file mode 100644 index 0000000000000..6f7b3af03099d --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.simplesavedobject.migrationversion.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SimpleSavedObject](./kibana-plugin-public.simplesavedobject.md) > [migrationVersion](./kibana-plugin-public.simplesavedobject.migrationversion.md) + +## SimpleSavedObject.migrationVersion property + +Signature: + +```typescript +migrationVersion: SavedObjectType['migrationVersion']; +``` diff --git a/docs/development/core/public/kibana-plugin-public.simplesavedobject.references.md b/docs/development/core/public/kibana-plugin-public.simplesavedobject.references.md new file mode 100644 index 0000000000000..159f855538f62 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.simplesavedobject.references.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SimpleSavedObject](./kibana-plugin-public.simplesavedobject.md) > [references](./kibana-plugin-public.simplesavedobject.references.md) + +## SimpleSavedObject.references property + +Signature: + +```typescript +references: SavedObjectType['references']; +``` diff --git a/docs/development/core/public/kibana-plugin-public.simplesavedobject.save.md b/docs/development/core/public/kibana-plugin-public.simplesavedobject.save.md new file mode 100644 index 0000000000000..05f8880fbcdd6 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.simplesavedobject.save.md @@ -0,0 +1,15 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SimpleSavedObject](./kibana-plugin-public.simplesavedobject.md) > [save](./kibana-plugin-public.simplesavedobject.save.md) + +## SimpleSavedObject.save() method + +Signature: + +```typescript +save(): Promise>; +``` +Returns: + +`Promise>` + diff --git a/docs/development/core/public/kibana-plugin-public.simplesavedobject.set.md b/docs/development/core/public/kibana-plugin-public.simplesavedobject.set.md new file mode 100644 index 0000000000000..ce3f9c5919d7c --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.simplesavedobject.set.md @@ -0,0 +1,23 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SimpleSavedObject](./kibana-plugin-public.simplesavedobject.md) > [set](./kibana-plugin-public.simplesavedobject.set.md) + +## SimpleSavedObject.set() method + +Signature: + +```typescript +set(key: string, value: any): T; +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| key | string | | +| value | any | | + +Returns: + +`T` + diff --git a/docs/development/core/public/kibana-plugin-public.simplesavedobject.type.md b/docs/development/core/public/kibana-plugin-public.simplesavedobject.type.md new file mode 100644 index 0000000000000..b004c70013d6d --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.simplesavedobject.type.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SimpleSavedObject](./kibana-plugin-public.simplesavedobject.md) > [type](./kibana-plugin-public.simplesavedobject.type.md) + +## SimpleSavedObject.type property + +Signature: + +```typescript +type: SavedObjectType['type']; +``` diff --git a/docs/development/core/server/kibana-plugin-server.md b/docs/development/core/server/kibana-plugin-server.md index 295c94574ab6a..bf56b1d2380ab 100644 --- a/docs/development/core/server/kibana-plugin-server.md +++ b/docs/development/core/server/kibana-plugin-server.md @@ -63,7 +63,7 @@ The plugin integrates with the core system via lifecycle events: `setup` | [RouteConfig](./kibana-plugin-server.routeconfig.md) | Route specific configuration. | | [RouteConfigOptions](./kibana-plugin-server.routeconfigoptions.md) | Additional route options. | | [SavedObject](./kibana-plugin-server.savedobject.md) | | -| [SavedObjectAttributes](./kibana-plugin-server.savedobjectattributes.md) | | +| [SavedObjectAttributes](./kibana-plugin-server.savedobjectattributes.md) | The data for a Saved Object is stored in the attributes key as either an object or an array of objects. | | [SavedObjectReference](./kibana-plugin-server.savedobjectreference.md) | A reference to another saved object. | | [SavedObjectsBaseOptions](./kibana-plugin-server.savedobjectsbaseoptions.md) | | | [SavedObjectsBulkCreateObject](./kibana-plugin-server.savedobjectsbulkcreateobject.md) | | @@ -74,7 +74,7 @@ The plugin integrates with the core system via lifecycle events: `setup` | [SavedObjectsCreateOptions](./kibana-plugin-server.savedobjectscreateoptions.md) | | | [SavedObjectsExportOptions](./kibana-plugin-server.savedobjectsexportoptions.md) | Options controlling the export operation. | | [SavedObjectsFindOptions](./kibana-plugin-server.savedobjectsfindoptions.md) | | -| [SavedObjectsFindResponse](./kibana-plugin-server.savedobjectsfindresponse.md) | | +| [SavedObjectsFindResponse](./kibana-plugin-server.savedobjectsfindresponse.md) | Return type of the Saved Objects find() method.\*Note\*: this type is different between the Public and Server Saved Objects clients. | | [SavedObjectsImportConflictError](./kibana-plugin-server.savedobjectsimportconflicterror.md) | Represents a failure to import due to a conflict. | | [SavedObjectsImportError](./kibana-plugin-server.savedobjectsimporterror.md) | Represents a failure to import. | | [SavedObjectsImportMissingReferencesError](./kibana-plugin-server.savedobjectsimportmissingreferenceserror.md) | Represents a failure to import due to missing references. | @@ -83,7 +83,8 @@ The plugin integrates with the core system via lifecycle events: `setup` | [SavedObjectsImportRetry](./kibana-plugin-server.savedobjectsimportretry.md) | Describes a retry operation for importing a saved object. | | [SavedObjectsImportUnknownError](./kibana-plugin-server.savedobjectsimportunknownerror.md) | Represents a failure to import due to an unknown reason. | | [SavedObjectsImportUnsupportedTypeError](./kibana-plugin-server.savedobjectsimportunsupportedtypeerror.md) | Represents a failure to import due to having an unsupported saved object type. | -| [SavedObjectsMigrationVersion](./kibana-plugin-server.savedobjectsmigrationversion.md) | A dictionary of saved object type -> version used to determine what migrations need to be applied to a saved object. | +| [SavedObjectsMigrationLogger](./kibana-plugin-server.savedobjectsmigrationlogger.md) | | +| [SavedObjectsMigrationVersion](./kibana-plugin-server.savedobjectsmigrationversion.md) | Information about the migrations that have been applied to this SavedObject. When Kibana starts up, KibanaMigrator detects outdated documents and migrates them based on this value. For each migration that has been applied, the plugin's name is used as a key and the latest migration version as the value. | | [SavedObjectsRawDoc](./kibana-plugin-server.savedobjectsrawdoc.md) | A raw document as represented directly in the saved object index. | | [SavedObjectsResolveImportErrorsOptions](./kibana-plugin-server.savedobjectsresolveimporterrorsoptions.md) | Options to control the "resolve import" operation. | | [SavedObjectsService](./kibana-plugin-server.savedobjectsservice.md) | | @@ -125,6 +126,7 @@ The plugin integrates with the core system via lifecycle events: `setup` | [RequestHandler](./kibana-plugin-server.requesthandler.md) | A function executed when route path matched requested resource path. Request handler is expected to return a result of one of [KibanaResponseFactory](./kibana-plugin-server.kibanaresponsefactory.md) functions. | | [ResponseError](./kibana-plugin-server.responseerror.md) | Error message and optional data send to the client in case of error. | | [RouteMethod](./kibana-plugin-server.routemethod.md) | The set of common HTTP methods supported by Kibana routing. | -| [SavedObjectsClientContract](./kibana-plugin-server.savedobjectsclientcontract.md) | \#\# SavedObjectsClient errorsSince the SavedObjectsClient has its hands in everything we are a little paranoid about the way we present errors back to to application code. Ideally, all errors will be either:1. Caused by bad implementation (ie. undefined is not a function) and as such unpredictable 2. An error that has been classified and decorated appropriately by the decorators in [SavedObjectsErrorHelpers](./kibana-plugin-server.savedobjectserrorhelpers.md)Type 1 errors are inevitable, but since all expected/handle-able errors should be Type 2 the isXYZError() helpers exposed at SavedObjectsErrorHelpers should be used to understand and manage error responses from the SavedObjectsClient.Type 2 errors are decorated versions of the source error, so if the elasticsearch client threw an error it will be decorated based on its type. That means that rather than looking for error.body.error.type or doing substring checks on error.body.error.reason, just use the helpers to understand the meaning of the error:\`\`\`js if (SavedObjectsErrorHelpers.isNotFoundError(error)) { // handle 404 }if (SavedObjectsErrorHelpers.isNotAuthorizedError(error)) { // 401 handling should be automatic, but in case you wanted to know }// always rethrow the error unless you handle it throw error; \`\`\`\#\#\# 404s from missing indexFrom the perspective of application code and APIs the SavedObjectsClient is a black box that persists objects. One of the internal details that users have no control over is that we use an elasticsearch index for persistance and that index might be missing.At the time of writing we are in the process of transitioning away from the operating assumption that the SavedObjects index is always available. Part of this transition is handling errors resulting from an index missing. These used to trigger a 500 error in most cases, and in others cause 404s with different error messages.From my (Spencer) perspective, a 404 from the SavedObjectsApi is a 404; The object the request/call was targeting could not be found. This is why \#14141 takes special care to ensure that 404 errors are generic and don't distinguish between index missing or document missing.\#\#\# 503s from missing indexUnlike all other methods, create requests are supposed to succeed even when the Kibana index does not exist because it will be automatically created by elasticsearch. When that is not the case it is because Elasticsearch's action.auto_create_index setting prevents it from being created automatically so we throw a special 503 with the intention of informing the user that their Elasticsearch settings need to be updated.See [SavedObjectsErrorHelpers](./kibana-plugin-server.savedobjectserrorhelpers.md) | +| [SavedObjectAttribute](./kibana-plugin-server.savedobjectattribute.md) | | +| [SavedObjectsClientContract](./kibana-plugin-server.savedobjectsclientcontract.md) | Saved Objects is Kibana's data persisentence mechanism allowing plugins to use Elasticsearch for storing plugin state.\#\# SavedObjectsClient errorsSince the SavedObjectsClient has its hands in everything we are a little paranoid about the way we present errors back to to application code. Ideally, all errors will be either:1. Caused by bad implementation (ie. undefined is not a function) and as such unpredictable 2. An error that has been classified and decorated appropriately by the decorators in [SavedObjectsErrorHelpers](./kibana-plugin-server.savedobjectserrorhelpers.md)Type 1 errors are inevitable, but since all expected/handle-able errors should be Type 2 the isXYZError() helpers exposed at SavedObjectsErrorHelpers should be used to understand and manage error responses from the SavedObjectsClient.Type 2 errors are decorated versions of the source error, so if the elasticsearch client threw an error it will be decorated based on its type. That means that rather than looking for error.body.error.type or doing substring checks on error.body.error.reason, just use the helpers to understand the meaning of the error:\`\`\`js if (SavedObjectsErrorHelpers.isNotFoundError(error)) { // handle 404 }if (SavedObjectsErrorHelpers.isNotAuthorizedError(error)) { // 401 handling should be automatic, but in case you wanted to know }// always rethrow the error unless you handle it throw error; \`\`\`\#\#\# 404s from missing indexFrom the perspective of application code and APIs the SavedObjectsClient is a black box that persists objects. One of the internal details that users have no control over is that we use an elasticsearch index for persistance and that index might be missing.At the time of writing we are in the process of transitioning away from the operating assumption that the SavedObjects index is always available. Part of this transition is handling errors resulting from an index missing. These used to trigger a 500 error in most cases, and in others cause 404s with different error messages.From my (Spencer) perspective, a 404 from the SavedObjectsApi is a 404; The object the request/call was targeting could not be found. This is why \#14141 takes special care to ensure that 404 errors are generic and don't distinguish between index missing or document missing.\#\#\# 503s from missing indexUnlike all other methods, create requests are supposed to succeed even when the Kibana index does not exist because it will be automatically created by elasticsearch. When that is not the case it is because Elasticsearch's action.auto_create_index setting prevents it from being created automatically so we throw a special 503 with the intention of informing the user that their Elasticsearch settings need to be updated.See [SavedObjectsErrorHelpers](./kibana-plugin-server.savedobjectserrorhelpers.md) | | [SavedObjectsClientWrapperFactory](./kibana-plugin-server.savedobjectsclientwrapperfactory.md) | Describes the factory used to create instances of Saved Objects Client Wrappers. | diff --git a/docs/development/core/server/kibana-plugin-server.savedobject.attributes.md b/docs/development/core/server/kibana-plugin-server.savedobject.attributes.md index b58408fe5f6b6..c3d521aa7bc2c 100644 --- a/docs/development/core/server/kibana-plugin-server.savedobject.attributes.md +++ b/docs/development/core/server/kibana-plugin-server.savedobject.attributes.md @@ -4,6 +4,8 @@ ## SavedObject.attributes property +The data for a Saved Object is stored in the `attributes` key as either an object or an array of objects. + Signature: ```typescript diff --git a/docs/development/core/server/kibana-plugin-server.savedobject.id.md b/docs/development/core/server/kibana-plugin-server.savedobject.id.md index f0ee1e9770f85..cc0127eb6ab04 100644 --- a/docs/development/core/server/kibana-plugin-server.savedobject.id.md +++ b/docs/development/core/server/kibana-plugin-server.savedobject.id.md @@ -4,6 +4,8 @@ ## SavedObject.id property +The ID of this Saved Object, guaranteed to be unique for all objects of the same `type` + Signature: ```typescript diff --git a/docs/development/core/server/kibana-plugin-server.savedobject.md b/docs/development/core/server/kibana-plugin-server.savedobject.md index 3b2417c56d5e5..1514980588746 100644 --- a/docs/development/core/server/kibana-plugin-server.savedobject.md +++ b/docs/development/core/server/kibana-plugin-server.savedobject.md @@ -15,12 +15,12 @@ export interface SavedObject | Property | Type | Description | | --- | --- | --- | -| [attributes](./kibana-plugin-server.savedobject.attributes.md) | T | | +| [attributes](./kibana-plugin-server.savedobject.attributes.md) | T | The data for a Saved Object is stored in the attributes key as either an object or an array of objects. | | [error](./kibana-plugin-server.savedobject.error.md) | {
message: string;
statusCode: number;
} | | -| [id](./kibana-plugin-server.savedobject.id.md) | string | | -| [migrationVersion](./kibana-plugin-server.savedobject.migrationversion.md) | SavedObjectsMigrationVersion | | -| [references](./kibana-plugin-server.savedobject.references.md) | SavedObjectReference[] | | -| [type](./kibana-plugin-server.savedobject.type.md) | string | | -| [updated\_at](./kibana-plugin-server.savedobject.updated_at.md) | string | | -| [version](./kibana-plugin-server.savedobject.version.md) | string | | +| [id](./kibana-plugin-server.savedobject.id.md) | string | The ID of this Saved Object, guaranteed to be unique for all objects of the same type | +| [migrationVersion](./kibana-plugin-server.savedobject.migrationversion.md) | SavedObjectsMigrationVersion | Information about the migrations that have been applied to this SavedObject. When Kibana starts up, KibanaMigrator detects outdated documents and migrates them based on this value. For each migration that has been applied, the plugin's name is used as a key and the latest migration version as the value. | +| [references](./kibana-plugin-server.savedobject.references.md) | SavedObjectReference[] | A reference to another saved object. | +| [type](./kibana-plugin-server.savedobject.type.md) | string | The type of Saved Object. Each plugin can define it's own custom Saved Object types. | +| [updated\_at](./kibana-plugin-server.savedobject.updated_at.md) | string | Timestamp of the last time this document had been updated. | +| [version](./kibana-plugin-server.savedobject.version.md) | string | An opaque version number which changes on each successful write operation. Can be used for implementing optimistic concurrency control. | diff --git a/docs/development/core/server/kibana-plugin-server.savedobject.migrationversion.md b/docs/development/core/server/kibana-plugin-server.savedobject.migrationversion.md index f9150a96b22cb..63c353a8b2e75 100644 --- a/docs/development/core/server/kibana-plugin-server.savedobject.migrationversion.md +++ b/docs/development/core/server/kibana-plugin-server.savedobject.migrationversion.md @@ -4,6 +4,8 @@ ## SavedObject.migrationVersion property +Information about the migrations that have been applied to this SavedObject. When Kibana starts up, KibanaMigrator detects outdated documents and migrates them based on this value. For each migration that has been applied, the plugin's name is used as a key and the latest migration version as the value. + Signature: ```typescript diff --git a/docs/development/core/server/kibana-plugin-server.savedobject.references.md b/docs/development/core/server/kibana-plugin-server.savedobject.references.md index 08476527a446d..22d4c84e9bcad 100644 --- a/docs/development/core/server/kibana-plugin-server.savedobject.references.md +++ b/docs/development/core/server/kibana-plugin-server.savedobject.references.md @@ -4,6 +4,8 @@ ## SavedObject.references property +A reference to another saved object. + Signature: ```typescript diff --git a/docs/development/core/server/kibana-plugin-server.savedobject.type.md b/docs/development/core/server/kibana-plugin-server.savedobject.type.md index 172de52d305f7..0498b2d780484 100644 --- a/docs/development/core/server/kibana-plugin-server.savedobject.type.md +++ b/docs/development/core/server/kibana-plugin-server.savedobject.type.md @@ -4,6 +4,8 @@ ## SavedObject.type property +The type of Saved Object. Each plugin can define it's own custom Saved Object types. + Signature: ```typescript diff --git a/docs/development/core/server/kibana-plugin-server.savedobject.updated_at.md b/docs/development/core/server/kibana-plugin-server.savedobject.updated_at.md index 0de1b1a0e816f..bf57cbc08dbb4 100644 --- a/docs/development/core/server/kibana-plugin-server.savedobject.updated_at.md +++ b/docs/development/core/server/kibana-plugin-server.savedobject.updated_at.md @@ -4,6 +4,8 @@ ## SavedObject.updated\_at property +Timestamp of the last time this document had been updated. + Signature: ```typescript diff --git a/docs/development/core/server/kibana-plugin-server.savedobject.version.md b/docs/development/core/server/kibana-plugin-server.savedobject.version.md index 25fbd536fcc38..a1c2f2c6c3b44 100644 --- a/docs/development/core/server/kibana-plugin-server.savedobject.version.md +++ b/docs/development/core/server/kibana-plugin-server.savedobject.version.md @@ -4,6 +4,8 @@ ## SavedObject.version property +An opaque version number which changes on each successful write operation. Can be used for implementing optimistic concurrency control. + Signature: ```typescript diff --git a/docs/development/core/server/kibana-plugin-server.savedobjectattribute.md b/docs/development/core/server/kibana-plugin-server.savedobjectattribute.md new file mode 100644 index 0000000000000..6a6c7c4d36bc6 --- /dev/null +++ b/docs/development/core/server/kibana-plugin-server.savedobjectattribute.md @@ -0,0 +1,12 @@ + + +[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [SavedObjectAttribute](./kibana-plugin-server.savedobjectattribute.md) + +## SavedObjectAttribute type + + +Signature: + +```typescript +export declare type SavedObjectAttribute = string | number | boolean | null | undefined | SavedObjectAttributes | SavedObjectAttributes[]; +``` diff --git a/docs/development/core/server/kibana-plugin-server.savedobjectattributes.md b/docs/development/core/server/kibana-plugin-server.savedobjectattributes.md index b629d8fad0c7b..7ff1247e89f2d 100644 --- a/docs/development/core/server/kibana-plugin-server.savedobjectattributes.md +++ b/docs/development/core/server/kibana-plugin-server.savedobjectattributes.md @@ -4,6 +4,7 @@ ## SavedObjectAttributes interface +The data for a Saved Object is stored in the `attributes` key as either an object or an array of objects. Signature: diff --git a/docs/development/core/server/kibana-plugin-server.savedobjectsbulkcreateobject.md b/docs/development/core/server/kibana-plugin-server.savedobjectsbulkcreateobject.md index 056de4b634b50..bae275777310a 100644 --- a/docs/development/core/server/kibana-plugin-server.savedobjectsbulkcreateobject.md +++ b/docs/development/core/server/kibana-plugin-server.savedobjectsbulkcreateobject.md @@ -17,7 +17,7 @@ export interface SavedObjectsBulkCreateObjectT | | | [id](./kibana-plugin-server.savedobjectsbulkcreateobject.id.md) | string | | -| [migrationVersion](./kibana-plugin-server.savedobjectsbulkcreateobject.migrationversion.md) | SavedObjectsMigrationVersion | | +| [migrationVersion](./kibana-plugin-server.savedobjectsbulkcreateobject.migrationversion.md) | SavedObjectsMigrationVersion | Information about the migrations that have been applied to this SavedObject. When Kibana starts up, KibanaMigrator detects outdated documents and migrates them based on this value. For each migration that has been applied, the plugin's name is used as a key and the latest migration version as the value. | | [references](./kibana-plugin-server.savedobjectsbulkcreateobject.references.md) | SavedObjectReference[] | | | [type](./kibana-plugin-server.savedobjectsbulkcreateobject.type.md) | string | | diff --git a/docs/development/core/server/kibana-plugin-server.savedobjectsbulkcreateobject.migrationversion.md b/docs/development/core/server/kibana-plugin-server.savedobjectsbulkcreateobject.migrationversion.md index 9b33ab9a1b077..6065988a8d0fc 100644 --- a/docs/development/core/server/kibana-plugin-server.savedobjectsbulkcreateobject.migrationversion.md +++ b/docs/development/core/server/kibana-plugin-server.savedobjectsbulkcreateobject.migrationversion.md @@ -4,6 +4,8 @@ ## SavedObjectsBulkCreateObject.migrationVersion property +Information about the migrations that have been applied to this SavedObject. When Kibana starts up, KibanaMigrator detects outdated documents and migrates them based on this value. For each migration that has been applied, the plugin's name is used as a key and the latest migration version as the value. + Signature: ```typescript diff --git a/docs/development/core/server/kibana-plugin-server.savedobjectsclientcontract.md b/docs/development/core/server/kibana-plugin-server.savedobjectsclientcontract.md index 3603904c2f89c..ae948b090146b 100644 --- a/docs/development/core/server/kibana-plugin-server.savedobjectsclientcontract.md +++ b/docs/development/core/server/kibana-plugin-server.savedobjectsclientcontract.md @@ -4,6 +4,8 @@ ## SavedObjectsClientContract type +Saved Objects is Kibana's data persisentence mechanism allowing plugins to use Elasticsearch for storing plugin state. + \#\# SavedObjectsClient errors Since the SavedObjectsClient has its hands in everything we are a little paranoid about the way we present errors back to to application code. Ideally, all errors will be either: diff --git a/docs/development/core/server/kibana-plugin-server.savedobjectscreateoptions.md b/docs/development/core/server/kibana-plugin-server.savedobjectscreateoptions.md index 61d65bfbf7b90..16549e420ac01 100644 --- a/docs/development/core/server/kibana-plugin-server.savedobjectscreateoptions.md +++ b/docs/development/core/server/kibana-plugin-server.savedobjectscreateoptions.md @@ -16,7 +16,7 @@ export interface SavedObjectsCreateOptions extends SavedObjectsBaseOptions | Property | Type | Description | | --- | --- | --- | | [id](./kibana-plugin-server.savedobjectscreateoptions.id.md) | string | (not recommended) Specify an id for the document | -| [migrationVersion](./kibana-plugin-server.savedobjectscreateoptions.migrationversion.md) | SavedObjectsMigrationVersion | | +| [migrationVersion](./kibana-plugin-server.savedobjectscreateoptions.migrationversion.md) | SavedObjectsMigrationVersion | Information about the migrations that have been applied to this SavedObject. When Kibana starts up, KibanaMigrator detects outdated documents and migrates them based on this value. For each migration that has been applied, the plugin's name is used as a key and the latest migration version as the value. | | [overwrite](./kibana-plugin-server.savedobjectscreateoptions.overwrite.md) | boolean | Overwrite existing documents (defaults to false) | | [references](./kibana-plugin-server.savedobjectscreateoptions.references.md) | SavedObjectReference[] | | diff --git a/docs/development/core/server/kibana-plugin-server.savedobjectscreateoptions.migrationversion.md b/docs/development/core/server/kibana-plugin-server.savedobjectscreateoptions.migrationversion.md index fcbec639312e6..33432b1138d91 100644 --- a/docs/development/core/server/kibana-plugin-server.savedobjectscreateoptions.migrationversion.md +++ b/docs/development/core/server/kibana-plugin-server.savedobjectscreateoptions.migrationversion.md @@ -4,6 +4,8 @@ ## SavedObjectsCreateOptions.migrationVersion property +Information about the migrations that have been applied to this SavedObject. When Kibana starts up, KibanaMigrator detects outdated documents and migrates them based on this value. For each migration that has been applied, the plugin's name is used as a key and the latest migration version as the value. + Signature: ```typescript diff --git a/docs/development/core/server/kibana-plugin-server.savedobjectsfindoptions.fields.md b/docs/development/core/server/kibana-plugin-server.savedobjectsfindoptions.fields.md index 6d2cac4f14439..394363abb5d4d 100644 --- a/docs/development/core/server/kibana-plugin-server.savedobjectsfindoptions.fields.md +++ b/docs/development/core/server/kibana-plugin-server.savedobjectsfindoptions.fields.md @@ -4,8 +4,15 @@ ## SavedObjectsFindOptions.fields property +An array of fields to include in the results + Signature: ```typescript fields?: string[]; ``` + +## Example + +SavedObjects.find({type: 'dashboard', fields: \['attributes.name', 'attributes.location'\]}) + diff --git a/docs/development/core/server/kibana-plugin-server.savedobjectsfindoptions.md b/docs/development/core/server/kibana-plugin-server.savedobjectsfindoptions.md index 140b447c0002a..ad81c439d902c 100644 --- a/docs/development/core/server/kibana-plugin-server.savedobjectsfindoptions.md +++ b/docs/development/core/server/kibana-plugin-server.savedobjectsfindoptions.md @@ -16,12 +16,12 @@ export interface SavedObjectsFindOptions extends SavedObjectsBaseOptions | Property | Type | Description | | --- | --- | --- | | [defaultSearchOperator](./kibana-plugin-server.savedobjectsfindoptions.defaultsearchoperator.md) | 'AND' | 'OR' | | -| [fields](./kibana-plugin-server.savedobjectsfindoptions.fields.md) | string[] | | +| [fields](./kibana-plugin-server.savedobjectsfindoptions.fields.md) | string[] | An array of fields to include in the results | | [hasReference](./kibana-plugin-server.savedobjectsfindoptions.hasreference.md) | {
type: string;
id: string;
} | | | [page](./kibana-plugin-server.savedobjectsfindoptions.page.md) | number | | | [perPage](./kibana-plugin-server.savedobjectsfindoptions.perpage.md) | number | | -| [search](./kibana-plugin-server.savedobjectsfindoptions.search.md) | string | | -| [searchFields](./kibana-plugin-server.savedobjectsfindoptions.searchfields.md) | string[] | see Elasticsearch Simple Query String Query field argument for more information | +| [search](./kibana-plugin-server.savedobjectsfindoptions.search.md) | string | Search documents using the Elasticsearch Simple Query String syntax. See Elasticsearch Simple Query String query argument for more information | +| [searchFields](./kibana-plugin-server.savedobjectsfindoptions.searchfields.md) | string[] | The fields to perform the parsed query against. See Elasticsearch Simple Query String fields argument for more information | | [sortField](./kibana-plugin-server.savedobjectsfindoptions.sortfield.md) | string | | | [sortOrder](./kibana-plugin-server.savedobjectsfindoptions.sortorder.md) | string | | | [type](./kibana-plugin-server.savedobjectsfindoptions.type.md) | string | string[] | | diff --git a/docs/development/core/server/kibana-plugin-server.savedobjectsfindoptions.search.md b/docs/development/core/server/kibana-plugin-server.savedobjectsfindoptions.search.md index 7dca45e58123f..a29dda1892918 100644 --- a/docs/development/core/server/kibana-plugin-server.savedobjectsfindoptions.search.md +++ b/docs/development/core/server/kibana-plugin-server.savedobjectsfindoptions.search.md @@ -4,6 +4,8 @@ ## SavedObjectsFindOptions.search property +Search documents using the Elasticsearch Simple Query String syntax. See Elasticsearch Simple Query String `query` argument for more information + Signature: ```typescript diff --git a/docs/development/core/server/kibana-plugin-server.savedobjectsfindoptions.searchfields.md b/docs/development/core/server/kibana-plugin-server.savedobjectsfindoptions.searchfields.md index fdd157299c144..2505bac8aec49 100644 --- a/docs/development/core/server/kibana-plugin-server.savedobjectsfindoptions.searchfields.md +++ b/docs/development/core/server/kibana-plugin-server.savedobjectsfindoptions.searchfields.md @@ -4,7 +4,7 @@ ## SavedObjectsFindOptions.searchFields property -see Elasticsearch Simple Query String Query field argument for more information +The fields to perform the parsed query against. See Elasticsearch Simple Query String `fields` argument for more information Signature: diff --git a/docs/development/core/server/kibana-plugin-server.savedobjectsfindresponse.md b/docs/development/core/server/kibana-plugin-server.savedobjectsfindresponse.md index e4f7d15042985..23299e22d8004 100644 --- a/docs/development/core/server/kibana-plugin-server.savedobjectsfindresponse.md +++ b/docs/development/core/server/kibana-plugin-server.savedobjectsfindresponse.md @@ -4,6 +4,9 @@ ## SavedObjectsFindResponse interface +Return type of the Saved Objects `find()` method. + +\*Note\*: this type is different between the Public and Server Saved Objects clients. Signature: diff --git a/docs/development/core/server/kibana-plugin-server.savedobjectsmigrationlogger.debug.md b/docs/development/core/server/kibana-plugin-server.savedobjectsmigrationlogger.debug.md new file mode 100644 index 0000000000000..be44bc7422d6c --- /dev/null +++ b/docs/development/core/server/kibana-plugin-server.savedobjectsmigrationlogger.debug.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [SavedObjectsMigrationLogger](./kibana-plugin-server.savedobjectsmigrationlogger.md) > [debug](./kibana-plugin-server.savedobjectsmigrationlogger.debug.md) + +## SavedObjectsMigrationLogger.debug property + +Signature: + +```typescript +debug: (msg: string) => void; +``` diff --git a/docs/development/core/server/kibana-plugin-server.savedobjectsmigrationlogger.info.md b/docs/development/core/server/kibana-plugin-server.savedobjectsmigrationlogger.info.md new file mode 100644 index 0000000000000..f8bbd5e4e6250 --- /dev/null +++ b/docs/development/core/server/kibana-plugin-server.savedobjectsmigrationlogger.info.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [SavedObjectsMigrationLogger](./kibana-plugin-server.savedobjectsmigrationlogger.md) > [info](./kibana-plugin-server.savedobjectsmigrationlogger.info.md) + +## SavedObjectsMigrationLogger.info property + +Signature: + +```typescript +info: (msg: string) => void; +``` diff --git a/docs/development/core/server/kibana-plugin-server.savedobjectsmigrationlogger.md b/docs/development/core/server/kibana-plugin-server.savedobjectsmigrationlogger.md new file mode 100644 index 0000000000000..9e21cb0641baf --- /dev/null +++ b/docs/development/core/server/kibana-plugin-server.savedobjectsmigrationlogger.md @@ -0,0 +1,21 @@ + + +[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [SavedObjectsMigrationLogger](./kibana-plugin-server.savedobjectsmigrationlogger.md) + +## SavedObjectsMigrationLogger interface + + +Signature: + +```typescript +export interface SavedObjectsMigrationLogger +``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [debug](./kibana-plugin-server.savedobjectsmigrationlogger.debug.md) | (msg: string) => void | | +| [info](./kibana-plugin-server.savedobjectsmigrationlogger.info.md) | (msg: string) => void | | +| [warning](./kibana-plugin-server.savedobjectsmigrationlogger.warning.md) | (msg: string) => void | | + diff --git a/docs/development/core/server/kibana-plugin-server.savedobjectsmigrationlogger.warning.md b/docs/development/core/server/kibana-plugin-server.savedobjectsmigrationlogger.warning.md new file mode 100644 index 0000000000000..978090f9fc885 --- /dev/null +++ b/docs/development/core/server/kibana-plugin-server.savedobjectsmigrationlogger.warning.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [SavedObjectsMigrationLogger](./kibana-plugin-server.savedobjectsmigrationlogger.md) > [warning](./kibana-plugin-server.savedobjectsmigrationlogger.warning.md) + +## SavedObjectsMigrationLogger.warning property + +Signature: + +```typescript +warning: (msg: string) => void; +``` diff --git a/docs/development/core/server/kibana-plugin-server.savedobjectsmigrationversion.md b/docs/development/core/server/kibana-plugin-server.savedobjectsmigrationversion.md index 434e46041cf7d..b7f9c8fd8fe98 100644 --- a/docs/development/core/server/kibana-plugin-server.savedobjectsmigrationversion.md +++ b/docs/development/core/server/kibana-plugin-server.savedobjectsmigrationversion.md @@ -4,10 +4,15 @@ ## SavedObjectsMigrationVersion interface -A dictionary of saved object type -> version used to determine what migrations need to be applied to a saved object. +Information about the migrations that have been applied to this SavedObject. When Kibana starts up, KibanaMigrator detects outdated documents and migrates them based on this value. For each migration that has been applied, the plugin's name is used as a key and the latest migration version as the value. Signature: ```typescript export interface SavedObjectsMigrationVersion ``` + +## Example + +migrationVersion: { dashboard: '7.1.1', space: '6.6.6', } + diff --git a/kibana.d.ts b/kibana.d.ts index 45cf4405a8edc..e0b20f6fa28af 100644 --- a/kibana.d.ts +++ b/kibana.d.ts @@ -20,8 +20,8 @@ /** * All exports from TS source files (where the implementation is actually done in TS). */ -import * as Public from 'target/types/public'; -import * as Server from 'target/types/server'; +import * as Public from 'src/core/public'; +import * as Server from 'src/core/server'; export { Public, Server }; diff --git a/src/core/public/core_system.ts b/src/core/public/core_system.ts index 2451feff1b4b0..7782c93c7bbb1 100644 --- a/src/core/public/core_system.ts +++ b/src/core/public/core_system.ts @@ -35,6 +35,7 @@ import { ApplicationService } from './application'; import { mapToObject } from '../utils/'; import { DocLinksService } from './doc_links'; import { RenderingService } from './rendering'; +import { SavedObjectsService } from './saved_objects/saved_objects_service'; import { ContextService } from './context'; interface Params { @@ -64,6 +65,7 @@ export class CoreSystem { private readonly legacyPlatform: LegacyPlatformService; private readonly notifications: NotificationsService; private readonly http: HttpService; + private readonly savedObjects: SavedObjectsService; private readonly uiSettings: UiSettingsService; private readonly chrome: ChromeService; private readonly i18n: I18nService; @@ -101,6 +103,7 @@ export class CoreSystem { this.notifications = new NotificationsService(); this.http = new HttpService(); + this.savedObjects = new SavedObjectsService(); this.uiSettings = new UiSettingsService(); this.overlay = new OverlayService(); this.application = new ApplicationService(); @@ -166,6 +169,7 @@ export class CoreSystem { const injectedMetadata = await this.injectedMetadata.start(); const docLinks = await this.docLinks.start({ injectedMetadata }); const http = await this.http.start({ injectedMetadata, fatalErrors: this.fatalErrorsSetup }); + const savedObjects = await this.savedObjects.start({ http }); const i18n = await this.i18n.start(); const application = await this.application.start({ injectedMetadata }); @@ -201,6 +205,7 @@ export class CoreSystem { chrome, docLinks, http, + savedObjects, i18n, injectedMetadata, notifications, diff --git a/src/core/public/http/http_service.mock.ts b/src/core/public/http/http_service.mock.ts index bcc94086e2a10..4ce84f8ab38d1 100644 --- a/src/core/public/http/http_service.mock.ts +++ b/src/core/public/http/http_service.mock.ts @@ -46,8 +46,8 @@ const createServiceMock = (): ServiceSetupMockType => ({ removeAllInterceptors: jest.fn(), }); -const createSetupContractMock = () => createServiceMock(); -const createStartContractMock = () => createServiceMock(); +const createSetupContractMock = createServiceMock; +const createStartContractMock = createServiceMock; const createMock = () => { const mocked: jest.Mocked> = { diff --git a/src/core/public/index.ts b/src/core/public/index.ts index 78e7160656f05..abc922ff97c1d 100644 --- a/src/core/public/index.ts +++ b/src/core/public/index.ts @@ -66,10 +66,30 @@ import { Plugin, PluginInitializer, PluginInitializerContext, PluginOpaqueId } f import { UiSettingsClient, UiSettingsState, UiSettingsClientContract } from './ui_settings'; import { ApplicationSetup, Capabilities, ApplicationStart } from './application'; import { DocLinksStart } from './doc_links'; +import { SavedObjectsStart } from './saved_objects'; import { IContextContainer, IContextProvider, ContextSetup, IContextHandler } from './context'; export { CoreContext, CoreSystem } from './core_system'; export { RecursiveReadonly } from '../utils'; +export { + SavedObjectsBatchResponse, + SavedObjectsBulkCreateObject, + SavedObjectsBulkCreateOptions, + SavedObjectsCreateOptions, + SavedObjectsFindResponsePublic, + SavedObjectsUpdateOptions, + SavedObject, + SavedObjectAttribute, + SavedObjectAttributes, + SavedObjectReference, + SavedObjectsBaseOptions, + SavedObjectsFindOptions, + SavedObjectsMigrationVersion, + SavedObjectsClientContract, + SavedObjectsClient, + SimpleSavedObject, +} from './saved_objects'; + export { HttpServiceBase, HttpHeadersInit, @@ -124,6 +144,8 @@ export interface CoreStart { docLinks: DocLinksStart; /** {@link HttpStart} */ http: HttpStart; + /** {@link SavedObjectsStart} */ + savedObjects: SavedObjectsStart; /** {@link I18nStart} */ i18n: I18nStart; /** {@link NotificationsStart} */ @@ -181,6 +203,7 @@ export { Plugin, PluginInitializer, PluginInitializerContext, + SavedObjectsStart, PluginOpaqueId, Toast, ToastInput, diff --git a/src/core/public/legacy/legacy_service.test.ts b/src/core/public/legacy/legacy_service.test.ts index 5f1c4e1cf6bf9..eb5b3e90f1a52 100644 --- a/src/core/public/legacy/legacy_service.test.ts +++ b/src/core/public/legacy/legacy_service.test.ts @@ -58,6 +58,7 @@ import { uiSettingsServiceMock } from '../ui_settings/ui_settings_service.mock'; import { LegacyPlatformService } from './legacy_service'; import { applicationServiceMock } from '../application/application_service.mock'; import { docLinksServiceMock } from '../doc_links/doc_links_service.mock'; +import { savedObjectsMock } from '../saved_objects/saved_objects_service.mock'; import { contextServiceMock } from '../context/context_service.mock'; const applicationSetup = applicationServiceMock.createSetupContract(); @@ -96,6 +97,7 @@ const injectedMetadataStart = injectedMetadataServiceMock.createStartContract(); const notificationsStart = notificationServiceMock.createStartContract(); const overlayStart = overlayServiceMock.createStartContract(); const uiSettingsStart = uiSettingsServiceMock.createStartContract(); +const savedObjectsStart = savedObjectsMock.createStartContract(); const defaultStartDeps = { core: { @@ -108,6 +110,7 @@ const defaultStartDeps = { notifications: notificationsStart, overlays: overlayStart, uiSettings: uiSettingsStart, + savedObjects: savedObjectsStart, }, targetDomElement: document.createElement('div'), plugins: {}, diff --git a/src/core/public/mocks.ts b/src/core/public/mocks.ts index 3682d86168dcd..0f3a01c793ae3 100644 --- a/src/core/public/mocks.ts +++ b/src/core/public/mocks.ts @@ -26,6 +26,7 @@ import { i18nServiceMock } from './i18n/i18n_service.mock'; import { notificationServiceMock } from './notifications/notifications_service.mock'; import { overlayServiceMock } from './overlays/overlay_service.mock'; import { uiSettingsServiceMock } from './ui_settings/ui_settings_service.mock'; +import { savedObjectsMock } from './saved_objects/saved_objects_service.mock'; import { contextServiceMock } from './context/context_service.mock'; export { chromeServiceMock } from './chrome/chrome_service.mock'; @@ -61,6 +62,7 @@ function createCoreStartMock() { notifications: notificationServiceMock.createStartContract(), overlays: overlayServiceMock.createStartContract(), uiSettings: uiSettingsServiceMock.createStartContract(), + savedObjects: savedObjectsMock.createStartContract(), }; return mock; diff --git a/src/core/public/plugins/plugin_context.ts b/src/core/public/plugins/plugin_context.ts index 75e31192e0de7..66cb7c4a1171e 100644 --- a/src/core/public/plugins/plugin_context.ts +++ b/src/core/public/plugins/plugin_context.ts @@ -115,5 +115,6 @@ export function createPluginStartContext< notifications: deps.notifications, overlays: deps.overlays, uiSettings: deps.uiSettings, + savedObjects: deps.savedObjects, }; } diff --git a/src/core/public/plugins/plugins_service.test.ts b/src/core/public/plugins/plugins_service.test.ts index bc3fe95cf4c9c..2b689e45b4f1a 100644 --- a/src/core/public/plugins/plugins_service.test.ts +++ b/src/core/public/plugins/plugins_service.test.ts @@ -43,6 +43,7 @@ import { injectedMetadataServiceMock } from '../injected_metadata/injected_metad import { httpServiceMock } from '../http/http_service.mock'; import { CoreSetup, CoreStart } from '..'; import { docLinksServiceMock } from '../doc_links/doc_links_service.mock'; +import { savedObjectsMock } from '../saved_objects/saved_objects_service.mock'; import { contextServiceMock } from '../context/context_service.mock'; export let mockPluginInitializers: Map; @@ -92,6 +93,7 @@ beforeEach(() => { notifications: notificationServiceMock.createStartContract(), overlays: overlayServiceMock.createStartContract(), uiSettings: uiSettingsServiceMock.createStartContract(), + savedObjects: savedObjectsMock.createStartContract(), }; mockStartContext = { ...omit(mockStartDeps, 'injectedMetadata'), diff --git a/src/core/public/public.api.md b/src/core/public/public.api.md index 26c2670141da6..077dfac06de3a 100644 --- a/src/core/public/public.api.md +++ b/src/core/public/public.api.md @@ -211,6 +211,8 @@ export interface CoreStart { // (undocumented) overlays: OverlayStart; // (undocumented) + savedObjects: SavedObjectsStart; + // (undocumented) uiSettings: UiSettingsClientContract; } @@ -604,6 +606,177 @@ export type RecursiveReadonly = T extends (...args: any[]) => any ? T : T ext [K in keyof T]: RecursiveReadonly; }> : T; +// @public (undocumented) +export interface SavedObject { + attributes: T; + // (undocumented) + error?: { + message: string; + statusCode: number; + }; + id: string; + migrationVersion?: SavedObjectsMigrationVersion; + references: SavedObjectReference[]; + type: string; + updated_at?: string; + version?: string; +} + +// @public (undocumented) +export type SavedObjectAttribute = string | number | boolean | null | undefined | SavedObjectAttributes | SavedObjectAttributes[]; + +// @public +export interface SavedObjectAttributes { + // (undocumented) + [key: string]: SavedObjectAttribute | SavedObjectAttribute[]; +} + +// @public +export interface SavedObjectReference { + // (undocumented) + id: string; + // (undocumented) + name: string; + // (undocumented) + type: string; +} + +// @public (undocumented) +export interface SavedObjectsBaseOptions { + namespace?: string; +} + +// @public (undocumented) +export interface SavedObjectsBatchResponse { + // (undocumented) + savedObjects: Array>; +} + +// @public (undocumented) +export interface SavedObjectsBulkCreateObject extends SavedObjectsCreateOptions { + // (undocumented) + attributes: T; + // (undocumented) + type: string; +} + +// @public (undocumented) +export interface SavedObjectsBulkCreateOptions { + overwrite?: boolean; +} + +// @public +export class SavedObjectsClient { + // @internal + constructor(http: HttpServiceBase); + bulkCreate: (objects?: SavedObjectsBulkCreateObject[], options?: SavedObjectsBulkCreateOptions) => Promise>; + bulkGet: (objects?: { + id: string; + type: string; + }[]) => Promise>; + create: (type: string, attributes: T, options?: SavedObjectsCreateOptions) => Promise>; + delete: (type: string, id: string) => Promise<{}>; + find: (options?: Pick) => Promise>; + get: (type: string, id: string) => Promise>; + update(type: string, id: string, attributes: T, { version, migrationVersion, references }?: SavedObjectsUpdateOptions): Promise>; +} + +// @public +export type SavedObjectsClientContract = PublicMethodsOf; + +// @public (undocumented) +export interface SavedObjectsCreateOptions { + id?: string; + migrationVersion?: SavedObjectsMigrationVersion; + overwrite?: boolean; + // (undocumented) + references?: SavedObjectReference[]; +} + +// @public (undocumented) +export interface SavedObjectsFindOptions extends SavedObjectsBaseOptions { + // (undocumented) + defaultSearchOperator?: 'AND' | 'OR'; + fields?: string[]; + // (undocumented) + hasReference?: { + type: string; + id: string; + }; + // (undocumented) + page?: number; + // (undocumented) + perPage?: number; + search?: string; + searchFields?: string[]; + // (undocumented) + sortField?: string; + // (undocumented) + sortOrder?: string; + // (undocumented) + type?: string | string[]; +} + +// @public +export interface SavedObjectsFindResponsePublic extends SavedObjectsBatchResponse { + // (undocumented) + page: number; + // (undocumented) + perPage: number; + // (undocumented) + total: number; +} + +// @public +export interface SavedObjectsMigrationVersion { + // (undocumented) + [pluginName: string]: string; +} + +// @public (undocumented) +export interface SavedObjectsStart { + // (undocumented) + client: SavedObjectsClientContract; +} + +// @public (undocumented) +export interface SavedObjectsUpdateOptions { + migrationVersion?: SavedObjectsMigrationVersion; + // (undocumented) + references?: SavedObjectReference[]; + // (undocumented) + version?: string; +} + +// @public +export class SimpleSavedObject { + constructor(client: SavedObjectsClient, { id, type, version, attributes, error, references, migrationVersion }: SavedObject); + // (undocumented) + attributes: T; + // (undocumented) + delete(): Promise<{}>; + // (undocumented) + error: SavedObject['error']; + // (undocumented) + get(key: string): any; + // (undocumented) + has(key: string): boolean; + // (undocumented) + id: SavedObject['id']; + // (undocumented) + migrationVersion: SavedObject['migrationVersion']; + // (undocumented) + references: SavedObject['references']; + // (undocumented) + save(): Promise>; + // (undocumented) + set(key: string, value: any): T; + // (undocumented) + type: SavedObject['type']; + // (undocumented) + _version?: SavedObject['version']; +} + export { Toast } // Warning: (ae-forgotten-export) The symbol "ToastInputFields" needs to be exported by the entry point index.d.ts diff --git a/src/core/public/saved_objects/index.ts b/src/core/public/saved_objects/index.ts new file mode 100644 index 0000000000000..f82112c7a65bd --- /dev/null +++ b/src/core/public/saved_objects/index.ts @@ -0,0 +1,40 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +export { + SavedObjectsBatchResponse, + SavedObjectsBulkCreateObject, + SavedObjectsBulkCreateOptions, + SavedObjectsClient, + SavedObjectsClientContract, + SavedObjectsCreateOptions, + SavedObjectsFindResponsePublic, + SavedObjectsUpdateOptions, +} from './saved_objects_client'; +export { SimpleSavedObject } from './simple_saved_object'; +export { SavedObjectsStart } from './saved_objects_service'; +export { + SavedObject, + SavedObjectAttribute, + SavedObjectAttributes, + SavedObjectReference, + SavedObjectsBaseOptions, + SavedObjectsFindOptions, + SavedObjectsMigrationVersion, +} from '../../server/types'; diff --git a/src/core/public/saved_objects/saved_objects_client.test.ts b/src/core/public/saved_objects/saved_objects_client.test.ts new file mode 100644 index 0000000000000..4c0fe90a5bfbd --- /dev/null +++ b/src/core/public/saved_objects/saved_objects_client.test.ts @@ -0,0 +1,433 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { SavedObjectsClient } from './saved_objects_client'; +import { SimpleSavedObject } from './simple_saved_object'; +import { httpServiceMock } from '../http/http_service.mock'; + +describe('SavedObjectsClient', () => { + const doc = { + id: 'AVwSwFxtcMV38qjDZoQg', + type: 'config', + attributes: { title: 'Example title' }, + version: 'foo', + }; + + const http = httpServiceMock.createStartContract(); + let savedObjectsClient: SavedObjectsClient; + + beforeEach(() => { + savedObjectsClient = new SavedObjectsClient(http); + http.fetch.mockClear(); + }); + + describe('#get', () => { + beforeEach(() => { + http.fetch.mockResolvedValue({ saved_objects: [doc] }); + }); + + test('rejects if `type` parameter is undefined', () => { + return expect( + savedObjectsClient.get(undefined as any, undefined as any) + ).rejects.toMatchInlineSnapshot(`[Error: requires type and id]`); + }); + + test('rejects if `id` parameter is undefined', () => { + return expect( + savedObjectsClient.get('index-pattern', undefined as any) + ).rejects.toMatchInlineSnapshot(`[Error: requires type and id]`); + }); + + test('rejects when HTTP call fails', () => { + http.fetch.mockRejectedValue(new Error('Request failed')); + return expect(savedObjectsClient.get(doc.type, doc.id)).rejects.toMatchInlineSnapshot( + `[Error: Request failed]` + ); + }); + + test('makes HTTP call', async () => { + await savedObjectsClient.get(doc.type, doc.id); + expect(http.fetch.mock.calls[0]).toMatchInlineSnapshot(` + Array [ + "/api/saved_objects/_bulk_get", + Object { + "body": "[{\\"id\\":\\"AVwSwFxtcMV38qjDZoQg\\",\\"type\\":\\"config\\"}]", + "method": "POST", + "query": undefined, + }, + ] + `); + }); + + test('batches several #get calls into a single HTTP call', async () => { + // Await #get call to ensure batchQueue is empty and throttle has reset + await savedObjectsClient.get('type2', doc.id); + http.fetch.mockClear(); + + // Make two #get calls right after one another + savedObjectsClient.get('type1', doc.id); + await savedObjectsClient.get('type0', doc.id); + expect(http.fetch.mock.calls).toMatchInlineSnapshot(` + Array [ + Array [ + "/api/saved_objects/_bulk_get", + Object { + "body": "[{\\"id\\":\\"AVwSwFxtcMV38qjDZoQg\\",\\"type\\":\\"type1\\"},{\\"id\\":\\"AVwSwFxtcMV38qjDZoQg\\",\\"type\\":\\"type0\\"}]", + "method": "POST", + "query": undefined, + }, + ], + ] + `); + }); + + test('resolves with SimpleSavedObject instance', async () => { + const response = savedObjectsClient.get(doc.type, doc.id); + await expect(response).resolves.toBeInstanceOf(SimpleSavedObject); + + const result = await response; + expect(result.type).toBe('config'); + expect(result.get('title')).toBe('Example title'); + }); + }); + + describe('#delete', () => { + beforeEach(() => { + http.fetch.mockResolvedValue({}); + }); + + test('rejects if `type` parameter is undefined', async () => { + expect( + savedObjectsClient.delete(undefined as any, undefined as any) + ).rejects.toMatchInlineSnapshot(`[Error: requires type and id]`); + }); + + test('throws if `id` parameter is undefined', async () => { + expect( + savedObjectsClient.delete('index-pattern', undefined as any) + ).rejects.toMatchInlineSnapshot(`[Error: requires type and id]`); + }); + + test('makes HTTP call', async () => { + await expect(savedObjectsClient.delete('index-pattern', 'logstash-*')).resolves.toEqual({}); + expect(http.fetch.mock.calls[0]).toMatchInlineSnapshot(` + Array [ + "/api/saved_objects/index-pattern/logstash-*", + Object { + "body": undefined, + "method": "DELETE", + "query": undefined, + }, + ] + `); + }); + }); + + describe('#update', () => { + const attributes = { foo: 'Foo', bar: 'Bar' }; + const options = { version: '1' }; + + beforeEach(() => { + http.fetch.mockResolvedValue({ type: 'index-pattern', attributes }); + }); + + test('rejects if `type` is undefined', async () => { + expect( + savedObjectsClient.update(undefined as any, undefined as any, undefined as any) + ).rejects.toMatchInlineSnapshot(`[Error: requires type, id and attributes]`); + }); + + test('rejects if `id` is undefined', async () => { + expect( + savedObjectsClient.update('index-pattern', undefined as any, undefined as any) + ).rejects.toMatchInlineSnapshot(`[Error: requires type, id and attributes]`); + }); + + test('rejects if `attributes` is undefined', async () => { + expect( + savedObjectsClient.update('index-pattern', 'logstash-*', undefined as any) + ).rejects.toMatchInlineSnapshot(`[Error: requires type, id and attributes]`); + }); + + test('makes HTTP call', () => { + savedObjectsClient.update('index-pattern', 'logstash-*', attributes, options); + expect(http.fetch.mock.calls).toMatchInlineSnapshot(` + Array [ + Array [ + "/api/saved_objects/index-pattern/logstash-*", + Object { + "body": "{\\"attributes\\":{\\"foo\\":\\"Foo\\",\\"bar\\":\\"Bar\\"},\\"version\\":\\"1\\"}", + "method": "PUT", + "query": undefined, + }, + ], + ] + `); + }); + + test('rejects when HTTP call fails', async () => { + http.fetch.mockRejectedValueOnce(new Error('Request failed')); + await expect( + savedObjectsClient.update('index-pattern', 'logstash-*', attributes, options) + ).rejects.toMatchInlineSnapshot(`[Error: Request failed]`); + }); + + test('resolves with SimpleSavedObject instance', async () => { + const response = savedObjectsClient.update( + 'index-pattern', + 'logstash-*', + attributes, + options + ); + await expect(response).resolves.toBeInstanceOf(SimpleSavedObject); + + const result = await response; + expect(result.type).toBe('index-pattern'); + expect(result.get('foo')).toBe('Foo'); + }); + }); + + describe('#create', () => { + const attributes = { foo: 'Foo', bar: 'Bar' }; + + beforeEach(() => { + http.fetch.mockResolvedValue({ id: 'serverId', type: 'server-type', attributes }); + }); + + test('rejects if `type` is undefined', async () => { + await expect( + savedObjectsClient.create(undefined as any, undefined as any) + ).rejects.toMatchInlineSnapshot(`[Error: requires type and attributes]`); + }); + + test('resolves with SimpleSavedObject instance', async () => { + const response = savedObjectsClient.create('index-pattern', attributes, { id: 'myId' }); + await expect(response).resolves.toBeInstanceOf(SimpleSavedObject); + + const result = await response; + + expect(result.type).toBe('server-type'); + expect(result.id).toBe('serverId'); + expect(result.attributes).toBe(attributes); + }); + + test('makes HTTP call with ID', () => { + savedObjectsClient.create('index-pattern', attributes, { id: 'myId' }); + expect(http.fetch.mock.calls).toMatchInlineSnapshot(` + Array [ + Array [ + "/api/saved_objects/index-pattern/myId", + Object { + "body": "{\\"attributes\\":{\\"foo\\":\\"Foo\\",\\"bar\\":\\"Bar\\"}}", + "method": "POST", + "query": Object { + "overwrite": undefined, + }, + }, + ], + ] + `); + }); + + test('makes HTTP call without ID', () => { + savedObjectsClient.create('index-pattern', attributes); + expect(http.fetch.mock.calls).toMatchInlineSnapshot(` + Array [ + Array [ + "/api/saved_objects/index-pattern", + Object { + "body": "{\\"attributes\\":{\\"foo\\":\\"Foo\\",\\"bar\\":\\"Bar\\"}}", + "method": "POST", + "query": Object { + "overwrite": undefined, + }, + }, + ], + ] + `); + }); + + test('rejects when HTTP call fails', async () => { + http.fetch.mockRejectedValueOnce(new Error('Request failed')); + await expect( + savedObjectsClient.create('index-pattern', attributes, { id: 'myId' }) + ).rejects.toMatchInlineSnapshot(`[Error: Request failed]`); + }); + }); + + describe('#bulk_create', () => { + beforeEach(() => { + http.fetch.mockResolvedValue({ saved_objects: [doc] }); + }); + + test('resolves with array of SimpleSavedObject instances', async () => { + const response = savedObjectsClient.bulkCreate([doc]); + await expect(response).resolves.toHaveProperty('savedObjects'); + + const result = await response; + expect(result.savedObjects).toHaveLength(1); + expect(result.savedObjects[0]).toBeInstanceOf(SimpleSavedObject); + }); + + test('makes HTTP call', async () => { + await savedObjectsClient.bulkCreate([doc]); + expect(http.fetch.mock.calls).toMatchInlineSnapshot(` + Array [ + Array [ + "/api/saved_objects/_bulk_create", + Object { + "body": "[{\\"id\\":\\"AVwSwFxtcMV38qjDZoQg\\",\\"type\\":\\"config\\",\\"attributes\\":{\\"title\\":\\"Example title\\"},\\"version\\":\\"foo\\"}]", + "method": "POST", + "query": Object { + "overwrite": false, + }, + }, + ], + ] + `); + }); + + test('makes HTTP call with overwrite query paramater', async () => { + await savedObjectsClient.bulkCreate([doc], { overwrite: true }); + expect(http.fetch.mock.calls).toMatchInlineSnapshot(` + Array [ + Array [ + "/api/saved_objects/_bulk_create", + Object { + "body": "[{\\"id\\":\\"AVwSwFxtcMV38qjDZoQg\\",\\"type\\":\\"config\\",\\"attributes\\":{\\"title\\":\\"Example title\\"},\\"version\\":\\"foo\\"}]", + "method": "POST", + "query": Object { + "overwrite": true, + }, + }, + ], + ] + `); + }); + }); + + describe('#find', () => { + const object = { id: 'logstash-*', type: 'index-pattern', title: 'Test' }; + + beforeEach(() => { + http.fetch.mockResolvedValue({ saved_objects: [object], page: 0, per_page: 1, total: 1 }); + }); + + test('resolves with instances of SimpleSavedObjects', async () => { + const options = { type: 'index-pattern' }; + const resultP = savedObjectsClient.find(options); + await expect(resultP).resolves.toHaveProperty('savedObjects'); + + const result = await resultP; + expect(result.savedObjects).toHaveLength(1); + expect(result.savedObjects[0]).toBeInstanceOf(SimpleSavedObject); + expect(result.page).toBe(0); + expect(result.perPage).toBe(1); + expect(result.total).toBe(1); + }); + + test('makes HTTP call correctly mapping options into snake case query parameters', () => { + const options = { + defaultSearchOperator: 'OR' as const, + fields: ['title'], + hasReference: { id: '1', type: 'reference' }, + page: 10, + perPage: 100, + search: 'what is the meaning of life?|life', + searchFields: ['title^5', 'body'], + sortField: 'sort_field', + type: 'index-pattern', + }; + + savedObjectsClient.find(options); + expect(http.fetch.mock.calls).toMatchInlineSnapshot(` + Array [ + Array [ + "/api/saved_objects/_find", + Object { + "body": undefined, + "method": "GET", + "query": Object { + "default_search_operator": "OR", + "fields": Array [ + "title", + ], + "has_reference": Object { + "id": "1", + "type": "reference", + }, + "page": 10, + "per_page": 100, + "search": "what is the meaning of life?|life", + "search_fields": Array [ + "title^5", + "body", + ], + "sort_field": "sort_field", + "type": "index-pattern", + }, + }, + ], + ] + `); + }); + + test('ignores invalid options', () => { + const options = { + invalid: true, + namespace: 'default', + sortOrder: 'sort', // Not currently supported by API + }; + + // @ts-ignore + savedObjectsClient.find(options); + expect(http.fetch.mock.calls).toMatchInlineSnapshot(` + Array [ + Array [ + "/api/saved_objects/_find", + Object { + "body": undefined, + "method": "GET", + "query": Object {}, + }, + ], + ] + `); + }); + }); + + it('maintains backwards compatibility by transforming http.fetch errors to be compatible with kfetch errors', () => { + const err = { + response: { ok: false, redirected: false, status: 409, statusText: 'Conflict' }, + body: 'response body', + }; + http.fetch.mockRejectedValue(err); + return expect(savedObjectsClient.get(doc.type, doc.id)).rejects.toMatchInlineSnapshot(` + Object { + "body": "response body", + "res": Object { + "ok": false, + "redirected": false, + "status": 409, + "statusText": "Conflict", + }, + } + `); + }); +}); diff --git a/src/legacy/ui/public/saved_objects/saved_objects_client.ts b/src/core/public/saved_objects/saved_objects_client.ts similarity index 58% rename from src/legacy/ui/public/saved_objects/saved_objects_client.ts rename to src/core/public/saved_objects/saved_objects_client.ts index d8fb3af1c66ac..b0768826159cc 100644 --- a/src/legacy/ui/public/saved_objects/saved_objects_client.ts +++ b/src/core/public/saved_objects/saved_objects_client.ts @@ -25,46 +25,80 @@ import { SavedObjectAttributes, SavedObjectReference, SavedObjectsClientContract as SavedObjectsApi, - SavedObjectsFindOptions, + SavedObjectsFindOptions as SavedObjectFindOptionsServer, SavedObjectsMigrationVersion, -} from 'src/core/server'; -import { isAutoCreateIndexError, showAutoCreateIndexErrorPage } from '../error_auto_create_index'; -import { kfetch, KFetchQuery } from '../kfetch'; -import { keysToCamelCaseShallow, keysToSnakeCaseShallow } from '../utils/case_conversion'; +} from '../../server'; + +// TODO: Migrate to an error modal powered by the NP? +import { + isAutoCreateIndexError, + showAutoCreateIndexErrorPage, +} from '../../../legacy/ui/public/error_auto_create_index/error_auto_create_index'; import { SimpleSavedObject } from './simple_saved_object'; +import { HttpFetchOptions, HttpServiceBase } from '../http'; -interface RequestParams { - method: 'POST' | 'GET' | 'PUT' | 'DELETE'; - path: string; - query?: KFetchQuery; - body?: object; -} +type SavedObjectsFindOptions = Omit; -interface CreateOptions { +type PromiseType> = T extends Promise ? U : never; + +/** @public */ +export interface SavedObjectsCreateOptions { + /** + * (Not recommended) Specify an id instead of having the saved objects service generate one for you. + */ id?: string; + /** If a document with the given `id` already exists, overwrite it's contents (default=false). */ overwrite?: boolean; + /** {@inheritDoc SavedObjectsMigrationVersion} */ migrationVersion?: SavedObjectsMigrationVersion; references?: SavedObjectReference[]; } -interface BulkCreateOptions - extends CreateOptions { +/** + * @param type - Create a SavedObject of the given type + * @param attributes - Create a SavedObject with the given attributes + * + * @public + */ +export interface SavedObjectsBulkCreateObject< + T extends SavedObjectAttributes = SavedObjectAttributes +> extends SavedObjectsCreateOptions { type: string; attributes: T; } -interface UpdateOptions { +/** @public */ +export interface SavedObjectsBulkCreateOptions { + /** If a document with the given `id` already exists, overwrite it's contents (default=false). */ + overwrite?: boolean; +} + +/** @public */ +export interface SavedObjectsUpdateOptions { version?: string; + /** {@inheritDoc SavedObjectsMigrationVersion} */ migrationVersion?: SavedObjectsMigrationVersion; references?: SavedObjectReference[]; } -interface BatchResponse { +/** @public */ +export interface SavedObjectsBatchResponse< + T extends SavedObjectAttributes = SavedObjectAttributes +> { savedObjects: Array>; } -interface FindResults - extends BatchResponse { +/** + * Return type of the Saved Objects `find()` method. + * + * *Note*: this type is different between the Public and Server Saved Objects + * clients. + * + * @public + */ +export interface SavedObjectsFindResponsePublic< + T extends SavedObjectAttributes = SavedObjectAttributes +> extends SavedObjectsBatchResponse { total: number; perPage: number; page: number; @@ -92,14 +126,24 @@ const BATCH_INTERVAL = 100; const API_BASE_URL = '/api/saved_objects/'; /** - * The SavedObjectsClient class acts as a generic data fetcher - * and data saver for saved objects regardless of type. + * SavedObjectsClientContract as implemented by the {@link SavedObjectsClient} + * + * @public + */ +export type SavedObjectsClientContract = PublicMethodsOf; + +/** + * Saved Objects is Kibana's data persisentence mechanism allowing plugins to + * use Elasticsearch for storing plugin state. The client-side + * SavedObjectsClient is a thin convenience library around the SavedObjects + * HTTP API for interacting with Saved Objects. * - * If possible, this class should be used to load saved objects - * instead of the SavedObjectLoader class which implements some - * additional functionality. + * @public */ export class SavedObjectsClient { + private http: HttpServiceBase; + private batchQueue: BatchQueueEntry[]; + /** * Throttled processing of get requests into bulk requests at 100ms interval */ @@ -132,27 +176,24 @@ export class SavedObjectsClient { { leading: false } ); - private batchQueue: BatchQueueEntry[]; - - constructor() { + /** @internal */ + constructor(http: HttpServiceBase) { + this.http = http; this.batchQueue = []; } /** * Persists an object * - * @param {string} type - * @param {object} [attributes={}] - * @param {object} [options={}] - * @property {string} [options.id] - force id on creation, not recommended - * @property {boolean} [options.overwrite=false] - * @property {object} [options.migrationVersion] + * @param type + * @param attributes + * @param options * @returns */ public create = ( type: string, attributes: T, - options: CreateOptions = {} + options: SavedObjectsCreateOptions = {} ): Promise> => { if (!type || !attributes) { return Promise.reject(new Error('requires type and attributes')); @@ -163,15 +204,14 @@ export class SavedObjectsClient { overwrite: options.overwrite, }; - const createRequest: Promise> = this.request({ + const createRequest: Promise> = this.savedObjectsFetch(path, { method: 'POST', - path, query, - body: { + body: JSON.stringify({ attributes, migrationVersion: options.migrationVersion, references: options.references, - }, + }), }); return createRequest @@ -193,19 +233,24 @@ export class SavedObjectsClient { * @property {boolean} [options.overwrite=false] * @returns The result of the create operation containing created saved objects. */ - public bulkCreate = (objects: BulkCreateOptions[] = [], options: KFetchQuery = {}) => { + public bulkCreate = ( + objects: SavedObjectsBulkCreateObject[] = [], + options: SavedObjectsBulkCreateOptions = { overwrite: false } + ) => { const path = this.getPath(['_bulk_create']); - const query = pick(options, ['overwrite']) as Pick; + const query = { overwrite: options.overwrite }; - const request: ReturnType = this.request({ + const request: ReturnType = this.savedObjectsFetch(path, { method: 'POST', - path, query, - body: objects, + body: JSON.stringify(objects), }); return request.then(resp => { resp.saved_objects = resp.saved_objects.map(d => this.createSavedObject(d)); - return keysToCamelCaseShallow(resp) as BatchResponse; + return renameKeys< + PromiseType>, + SavedObjectsBatchResponse + >({ saved_objects: 'savedObjects' }, resp) as SavedObjectsBatchResponse; }); }; @@ -221,7 +266,7 @@ export class SavedObjectsClient { return Promise.reject(new Error('requires type and id')); } - return this.request({ method: 'DELETE', path: this.getPath([type, id]) }); + return this.savedObjectsFetch(this.getPath([type, id]), { method: 'DELETE' }); }; /** @@ -240,18 +285,41 @@ export class SavedObjectsClient { */ public find = ( options: SavedObjectsFindOptions = {} - ): Promise> => { + ): Promise> => { const path = this.getPath(['_find']); - const query = keysToSnakeCaseShallow(options); + const renameMap = { + defaultSearchOperator: 'default_search_operator', + fields: 'fields', + hasReference: 'has_reference', + page: 'page', + perPage: 'per_page', + search: 'search', + searchFields: 'search_fields', + sortField: 'sort_field', + type: 'type', + }; + + const renamedQuery = renameKeys(renameMap, options); + const query = pick.apply(null, [renamedQuery, ...Object.values(renameMap)]); - const request: ReturnType = this.request({ + const request: ReturnType = this.savedObjectsFetch(path, { method: 'GET', - path, query, }); return request.then(resp => { resp.saved_objects = resp.saved_objects.map(d => this.createSavedObject(d)); - return keysToCamelCaseShallow(resp) as FindResults; + return renameKeys< + PromiseType>, + SavedObjectsFindResponsePublic + >( + { + saved_objects: 'savedObjects', + total: 'total', + per_page: 'perPage', + page: 'page', + }, + resp + ) as SavedObjectsFindResponsePublic; }); }; @@ -292,14 +360,16 @@ export class SavedObjectsClient { const path = this.getPath(['_bulk_get']); const filteredObjects = objects.map(obj => pick(obj, ['id', 'type'])); - const request: ReturnType = this.request({ + const request: ReturnType = this.savedObjectsFetch(path, { method: 'POST', - path, - body: filteredObjects, + body: JSON.stringify(filteredObjects), }); return request.then(resp => { resp.saved_objects = resp.saved_objects.map(d => this.createSavedObject(d)); - return keysToCamelCaseShallow(resp) as BatchResponse; + return renameKeys< + PromiseType>, + SavedObjectsBatchResponse + >({ saved_objects: 'savedObjects' }, resp) as SavedObjectsBatchResponse; }); }; @@ -318,7 +388,7 @@ export class SavedObjectsClient { type: string, id: string, attributes: T, - { version, migrationVersion, references }: UpdateOptions = {} + { version, migrationVersion, references }: SavedObjectsUpdateOptions = {} ): Promise> { if (!type || !id || !attributes) { return Promise.reject(new Error('requires type, id and attributes')); @@ -332,10 +402,9 @@ export class SavedObjectsClient { version, }; - return this.request({ + return this.savedObjectsFetch(path, { method: 'PUT', - path, - body, + body: JSON.stringify(body), }).then((resp: SavedObject) => { return this.createSavedObject(resp); }); @@ -351,11 +420,34 @@ export class SavedObjectsClient { return resolveUrl(API_BASE_URL, join(...path)); } - private request({ method, path, query, body }: RequestParams) { - if (method === 'GET' && body) { - return Promise.reject(new Error('body not permitted for GET requests')); - } - - return kfetch({ method, pathname: path, query, body: JSON.stringify(body) }); + /** + * To ensure we don't break backwards compatibility, savedObjectsFetch keeps + * the old kfetch error format of `{res: {status: number}}` whereas `http.fetch` + * uses `{response: {status: number}}`. + */ + private savedObjectsFetch(path: string, { method, query, body }: HttpFetchOptions) { + return this.http.fetch(path, { method, query, body }).catch(err => { + const kfetchError = Object.assign(err, { res: err.response }); + delete kfetchError.response; + return Promise.reject(kfetchError); + }); } } + +/** + * Returns a new object with the own properties of `obj`, but the + * keys renamed according to the `keysMap`. + * + * @param keysMap - a map of the form `{oldKey: newKey}` + * @param obj - the object whose own properties will be renamed + */ +const renameKeys = , U extends Record>( + keysMap: Record, + obj: Record +) => + Object.keys(obj).reduce((acc, key) => { + return { + ...acc, + ...{ [keysMap[key] || key]: obj[key] }, + }; + }, {}); diff --git a/src/core/public/saved_objects/saved_objects_service.mock.ts b/src/core/public/saved_objects/saved_objects_service.mock.ts new file mode 100644 index 0000000000000..feace09806a97 --- /dev/null +++ b/src/core/public/saved_objects/saved_objects_service.mock.ts @@ -0,0 +1,50 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { SavedObjectsService, SavedObjectsStart } from './saved_objects_service'; + +const createStartContractMock = () => { + const mock: jest.Mocked = { + client: { + create: jest.fn(), + bulkCreate: jest.fn(), + delete: jest.fn(), + bulkGet: jest.fn(), + find: jest.fn(), + get: jest.fn(), + update: jest.fn(), + }, + }; + return mock; +}; + +const createMock = () => { + const mocked: jest.Mocked = { + setup: jest.fn(), + start: jest.fn(), + stop: jest.fn(), + }; + mocked.start.mockReturnValue(Promise.resolve(createStartContractMock())); + return mocked; +}; + +export const savedObjectsMock = { + create: createMock, + createStartContract: createStartContractMock, +}; diff --git a/src/core/public/saved_objects/saved_objects_service.ts b/src/core/public/saved_objects/saved_objects_service.ts new file mode 100644 index 0000000000000..bb91c6f340c0b --- /dev/null +++ b/src/core/public/saved_objects/saved_objects_service.ts @@ -0,0 +1,38 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { CoreService } from 'src/core/types'; +import { CoreStart } from 'src/core/public'; +import { SavedObjectsClient, SavedObjectsClientContract } from './saved_objects_client'; + +/** + * @public + */ +export interface SavedObjectsStart { + /** {@link SavedObjectsClient} */ + client: SavedObjectsClientContract; +} + +export class SavedObjectsService implements CoreService { + public async setup() {} + public async start({ http }: { http: CoreStart['http'] }): Promise { + return { client: new SavedObjectsClient(http) }; + } + public async stop() {} +} diff --git a/src/legacy/ui/public/saved_objects/simple_saved_object.ts b/src/core/public/saved_objects/simple_saved_object.ts similarity index 90% rename from src/legacy/ui/public/saved_objects/simple_saved_object.ts rename to src/core/public/saved_objects/simple_saved_object.ts index 26488bdeb1ab1..92c228edd5e8e 100644 --- a/src/legacy/ui/public/saved_objects/simple_saved_object.ts +++ b/src/core/public/saved_objects/simple_saved_object.ts @@ -18,16 +18,17 @@ */ import { get, has, set } from 'lodash'; -import { SavedObject as SavedObjectType, SavedObjectAttributes } from 'src/core/server'; +import { SavedObject as SavedObjectType, SavedObjectAttributes } from '../../server'; import { SavedObjectsClient } from './saved_objects_client'; /** - * This class is a very simple wrapper for SavedObjects loaded from the server. + * This class is a very simple wrapper for SavedObjects loaded from the server + * with the {@link SavedObjectsClient}. * - * It provides basic functionality for updating/deleting/etc. saved objects but - * doesn't include any type-specific implementations. + * It provides basic functionality for creating/saving/deleting saved objects, + * but doesn't include any type-specific implementations. * - * For more sophisiticated use cases, the SavedObject class implements additional functions + * @public */ export class SimpleSavedObject { public attributes: T; diff --git a/src/core/server/index.ts b/src/core/server/index.ts index 424f1730683e4..65b986a1d78c5 100644 --- a/src/core/server/index.ts +++ b/src/core/server/index.ts @@ -105,43 +105,48 @@ export { } from './plugins'; export { - SavedObject, - SavedObjectAttributes, - SavedObjectReference, - SavedObjectsBaseOptions, SavedObjectsBulkCreateObject, SavedObjectsBulkGetObject, SavedObjectsBulkResponse, SavedObjectsClient, - SavedObjectsClientContract, - SavedObjectsCreateOptions, SavedObjectsClientProviderOptions, SavedObjectsClientWrapperFactory, SavedObjectsClientWrapperOptions, + SavedObjectsCreateOptions, SavedObjectsErrorHelpers, - SavedObjectsFindOptions, - SavedObjectsFindResponse, - SavedObjectsMigrationVersion, - SavedObjectsRawDoc, - SavedObjectsSchema, - SavedObjectsSerializer, - SavedObjectsService, - SavedObjectsUpdateOptions, - SavedObjectsUpdateResponse, SavedObjectsExportOptions, - SavedObjectsImportError, + SavedObjectsFindResponse, SavedObjectsImportConflictError, + SavedObjectsImportError, SavedObjectsImportMissingReferencesError, - SavedObjectsImportUnknownError, - SavedObjectsImportUnsupportedTypeError, SavedObjectsImportOptions, SavedObjectsImportResponse, SavedObjectsImportRetry, + SavedObjectsImportUnknownError, + SavedObjectsImportUnsupportedTypeError, + SavedObjectsMigrationLogger, + SavedObjectsRawDoc, SavedObjectsResolveImportErrorsOptions, + SavedObjectsSchema, + SavedObjectsSerializer, + SavedObjectsService, + SavedObjectsUpdateOptions, + SavedObjectsUpdateResponse, } from './saved_objects'; export { RecursiveReadonly } from '../utils'; +export { + SavedObject, + SavedObjectAttribute, + SavedObjectAttributes, + SavedObjectReference, + SavedObjectsBaseOptions, + SavedObjectsClientContract, + SavedObjectsFindOptions, + SavedObjectsMigrationVersion, +} from './types'; + /** * Context passed to the plugins `setup` method. * diff --git a/src/core/server/saved_objects/export/get_sorted_objects_for_export.ts b/src/core/server/saved_objects/export/get_sorted_objects_for_export.ts index d8513bcfe72d3..08795e9fc7738 100644 --- a/src/core/server/saved_objects/export/get_sorted_objects_for_export.ts +++ b/src/core/server/saved_objects/export/get_sorted_objects_for_export.ts @@ -19,7 +19,7 @@ import Boom from 'boom'; import { createListStream } from '../../../../legacy/utils/streams'; -import { SavedObjectsClientContract } from '../'; +import { SavedObjectsClientContract } from '../types'; import { injectNestedDependencies } from './inject_nested_depdendencies'; import { sortObjects } from './sort_objects'; diff --git a/src/core/server/saved_objects/export/inject_nested_depdendencies.test.ts b/src/core/server/saved_objects/export/inject_nested_depdendencies.test.ts index 2fa06550727f0..4613553fbd301 100644 --- a/src/core/server/saved_objects/export/inject_nested_depdendencies.test.ts +++ b/src/core/server/saved_objects/export/inject_nested_depdendencies.test.ts @@ -17,7 +17,7 @@ * under the License. */ -import { SavedObject } from '../service/saved_objects_client'; +import { SavedObject } from '../types'; import { getObjectReferencesToFetch, injectNestedDependencies, diff --git a/src/core/server/saved_objects/export/inject_nested_depdendencies.ts b/src/core/server/saved_objects/export/inject_nested_depdendencies.ts index 82cb3e3cfe115..279b06f955571 100644 --- a/src/core/server/saved_objects/export/inject_nested_depdendencies.ts +++ b/src/core/server/saved_objects/export/inject_nested_depdendencies.ts @@ -18,7 +18,7 @@ */ import Boom from 'boom'; -import { SavedObject, SavedObjectsClientContract } from '../service/saved_objects_client'; +import { SavedObject, SavedObjectsClientContract } from '../types'; export function getObjectReferencesToFetch(savedObjectsMap: Map) { const objectsToFetch = new Map(); diff --git a/src/core/server/saved_objects/export/sort_objects.ts b/src/core/server/saved_objects/export/sort_objects.ts index 84640db3635e9..522146737d9cf 100644 --- a/src/core/server/saved_objects/export/sort_objects.ts +++ b/src/core/server/saved_objects/export/sort_objects.ts @@ -18,7 +18,7 @@ */ import Boom from 'boom'; -import { SavedObject } from '../service/saved_objects_client'; +import { SavedObject } from '../types'; export function sortObjects(savedObjects: SavedObject[]): SavedObject[] { const path = new Set(); diff --git a/src/core/server/saved_objects/import/collect_saved_objects.ts b/src/core/server/saved_objects/import/collect_saved_objects.ts index fa2938109f6e7..65ffd4d9a1d57 100644 --- a/src/core/server/saved_objects/import/collect_saved_objects.ts +++ b/src/core/server/saved_objects/import/collect_saved_objects.ts @@ -24,7 +24,7 @@ import { createMapStream, createPromiseFromStreams, } from '../../../../legacy/utils/streams'; -import { SavedObject } from '../service'; +import { SavedObject } from '../types'; import { createLimitStream } from './create_limit_stream'; import { SavedObjectsImportError } from './types'; diff --git a/src/core/server/saved_objects/import/create_objects_filter.ts b/src/core/server/saved_objects/import/create_objects_filter.ts index 684e44944002b..c48cded00f1ec 100644 --- a/src/core/server/saved_objects/import/create_objects_filter.ts +++ b/src/core/server/saved_objects/import/create_objects_filter.ts @@ -17,7 +17,7 @@ * under the License. */ -import { SavedObject } from '../service'; +import { SavedObject } from '../types'; import { SavedObjectsImportRetry } from './types'; export function createObjectsFilter(retries: SavedObjectsImportRetry[]) { diff --git a/src/core/server/saved_objects/import/extract_errors.test.ts b/src/core/server/saved_objects/import/extract_errors.test.ts index ad2b1467923a6..f97cc661c0bca 100644 --- a/src/core/server/saved_objects/import/extract_errors.test.ts +++ b/src/core/server/saved_objects/import/extract_errors.test.ts @@ -17,7 +17,7 @@ * under the License. */ -import { SavedObject } from '../service'; +import { SavedObject } from '../types'; import { extractErrors } from './extract_errors'; describe('extractErrors()', () => { diff --git a/src/core/server/saved_objects/import/extract_errors.ts b/src/core/server/saved_objects/import/extract_errors.ts index 4c001cf8acf64..725e935f6e21d 100644 --- a/src/core/server/saved_objects/import/extract_errors.ts +++ b/src/core/server/saved_objects/import/extract_errors.ts @@ -16,8 +16,7 @@ * specific language governing permissions and limitations * under the License. */ - -import { SavedObject } from '../service'; +import { SavedObject } from '../types'; import { SavedObjectsImportError } from './types'; export function extractErrors( diff --git a/src/core/server/saved_objects/import/import_saved_objects.test.ts b/src/core/server/saved_objects/import/import_saved_objects.test.ts index 6ba4304574f49..194756462fc78 100644 --- a/src/core/server/saved_objects/import/import_saved_objects.test.ts +++ b/src/core/server/saved_objects/import/import_saved_objects.test.ts @@ -18,7 +18,7 @@ */ import { Readable } from 'stream'; -import { SavedObject } from '../service'; +import { SavedObject } from '../types'; import { importSavedObjects } from './import_saved_objects'; describe('importSavedObjects()', () => { diff --git a/src/core/server/saved_objects/import/resolve_import_errors.test.ts b/src/core/server/saved_objects/import/resolve_import_errors.test.ts index 783b0d6a61be6..9d0e133c5951c 100644 --- a/src/core/server/saved_objects/import/resolve_import_errors.test.ts +++ b/src/core/server/saved_objects/import/resolve_import_errors.test.ts @@ -18,7 +18,7 @@ */ import { Readable } from 'stream'; -import { SavedObject } from '../service'; +import { SavedObject } from '../types'; import { resolveImportErrors } from './resolve_import_errors'; describe('resolveImportErrors()', () => { diff --git a/src/core/server/saved_objects/import/resolve_import_errors.ts b/src/core/server/saved_objects/import/resolve_import_errors.ts index c04827dc98ab5..6f56f283b4aec 100644 --- a/src/core/server/saved_objects/import/resolve_import_errors.ts +++ b/src/core/server/saved_objects/import/resolve_import_errors.ts @@ -16,7 +16,6 @@ * specific language governing permissions and limitations * under the License. */ - import { collectSavedObjects } from './collect_saved_objects'; import { createObjectsFilter } from './create_objects_filter'; import { extractErrors } from './extract_errors'; diff --git a/src/core/server/saved_objects/import/split_overwrites.ts b/src/core/server/saved_objects/import/split_overwrites.ts index f49b634c8d9f2..192d43e9edb24 100644 --- a/src/core/server/saved_objects/import/split_overwrites.ts +++ b/src/core/server/saved_objects/import/split_overwrites.ts @@ -17,7 +17,7 @@ * under the License. */ -import { SavedObject } from '../service'; +import { SavedObject } from '../types'; import { SavedObjectsImportRetry } from './types'; export function splitOverwrites(savedObjects: SavedObject[], retries: SavedObjectsImportRetry[]) { diff --git a/src/core/server/saved_objects/import/types.ts b/src/core/server/saved_objects/import/types.ts index cc16a1697d9a0..44046378a7b97 100644 --- a/src/core/server/saved_objects/import/types.ts +++ b/src/core/server/saved_objects/import/types.ts @@ -18,7 +18,7 @@ */ import { Readable } from 'stream'; -import { SavedObjectsClientContract } from '../service'; +import { SavedObjectsClientContract } from '../types'; /** * Describes a retry operation for importing a saved object. diff --git a/src/core/server/saved_objects/import/validate_references.ts b/src/core/server/saved_objects/import/validate_references.ts index ad3f73b68f6e0..4d9ee59f9df15 100644 --- a/src/core/server/saved_objects/import/validate_references.ts +++ b/src/core/server/saved_objects/import/validate_references.ts @@ -18,7 +18,7 @@ */ import Boom from 'boom'; -import { SavedObject, SavedObjectsClientContract } from '../'; +import { SavedObject, SavedObjectsClientContract } from '../types'; import { SavedObjectsImportError } from './types'; const REF_TYPES_TO_VLIDATE = ['index-pattern', 'search']; diff --git a/src/core/server/saved_objects/index.ts b/src/core/server/saved_objects/index.ts index ef0362e0eb915..1a667d6978f1a 100644 --- a/src/core/server/saved_objects/index.ts +++ b/src/core/server/saved_objects/index.ts @@ -28,3 +28,5 @@ export * from './import'; export { getSortedObjectsForExport, SavedObjectsExportOptions } from './export'; export { SavedObjectsSerializer, RawDoc as SavedObjectsRawDoc } from './serialization'; + +export { SavedObjectsMigrationLogger } from './migrations/core/migration_logger'; diff --git a/src/core/server/saved_objects/management/management.ts b/src/core/server/saved_objects/management/management.ts index c2c6789615b70..7b5274da91fc8 100644 --- a/src/core/server/saved_objects/management/management.ts +++ b/src/core/server/saved_objects/management/management.ts @@ -17,7 +17,7 @@ * under the License. */ -import { SavedObject } from '../service'; +import { SavedObject } from '../types'; interface SavedObjectsManagementTypeDefinition { isImportableAndExportable?: boolean; diff --git a/src/core/server/saved_objects/migrations/core/document_migrator.ts b/src/core/server/saved_objects/migrations/core/document_migrator.ts index 578fe49b2d3cc..0576f1d22199f 100644 --- a/src/core/server/saved_objects/migrations/core/document_migrator.ts +++ b/src/core/server/saved_objects/migrations/core/document_migrator.ts @@ -65,10 +65,13 @@ import _ from 'lodash'; import cloneDeep from 'lodash.clonedeep'; import Semver from 'semver'; import { RawSavedObjectDoc } from '../../serialization'; -import { SavedObjectsMigrationVersion } from '../../'; -import { LogFn, Logger, MigrationLogger } from './migration_logger'; +import { SavedObjectsMigrationVersion } from '../../types'; +import { LogFn, SavedObjectsMigrationLogger, MigrationLogger } from './migration_logger'; -export type TransformFn = (doc: RawSavedObjectDoc, log?: Logger) => RawSavedObjectDoc; +export type TransformFn = ( + doc: RawSavedObjectDoc, + log?: SavedObjectsMigrationLogger +) => RawSavedObjectDoc; type ValidateDoc = (doc: RawSavedObjectDoc) => void; @@ -204,7 +207,10 @@ function validateMigrationDefinition(migrations: MigrationDefinition) { * From: { type: { version: fn } } * To: { type: { latestVersion: string, transforms: [{ version: string, transform: fn }] } } */ -function buildActiveMigrations(migrations: MigrationDefinition, log: Logger): ActiveMigrations { +function buildActiveMigrations( + migrations: MigrationDefinition, + log: SavedObjectsMigrationLogger +): ActiveMigrations { return _.mapValues(migrations, (versions, prop) => { const transforms = Object.entries(versions) .map(([version, transform]) => ({ @@ -293,7 +299,12 @@ function markAsUpToDate(doc: RawSavedObjectDoc, migrations: ActiveMigrations) { * If a specific transform function fails, this tacks on a bit of information * about the document and transform that caused the failure. */ -function wrapWithTry(version: string, prop: string, transform: TransformFn, log: Logger) { +function wrapWithTry( + version: string, + prop: string, + transform: TransformFn, + log: SavedObjectsMigrationLogger +) { return function tryTransformDoc(doc: RawSavedObjectDoc) { try { const result = transform(doc, log); diff --git a/src/core/server/saved_objects/migrations/core/elastic_index.ts b/src/core/server/saved_objects/migrations/core/elastic_index.ts index da76905d1c65c..e7621d88f78ee 100644 --- a/src/core/server/saved_objects/migrations/core/elastic_index.ts +++ b/src/core/server/saved_objects/migrations/core/elastic_index.ts @@ -24,7 +24,7 @@ import _ from 'lodash'; import { IndexMapping } from '../../mappings'; -import { SavedObjectsMigrationVersion } from '../../'; +import { SavedObjectsMigrationVersion } from '../../types'; import { AliasAction, CallCluster, NotFound, RawDoc, ShardsInfo } from './call_cluster'; const settings = { number_of_shards: 1, auto_expand_replicas: '0-1' }; diff --git a/src/core/server/saved_objects/migrations/core/migration_context.ts b/src/core/server/saved_objects/migrations/core/migration_context.ts index a151a8d37a524..633bccf8aceec 100644 --- a/src/core/server/saved_objects/migrations/core/migration_context.ts +++ b/src/core/server/saved_objects/migrations/core/migration_context.ts @@ -30,7 +30,7 @@ import { buildActiveMappings } from './build_active_mappings'; import { CallCluster } from './call_cluster'; import { VersionedTransformer } from './document_migrator'; import { fetchInfo, FullIndexInfo } from './elastic_index'; -import { LogFn, Logger, MigrationLogger } from './migration_logger'; +import { LogFn, SavedObjectsMigrationLogger, MigrationLogger } from './migration_logger'; export interface MigrationOpts { batchSize: number; @@ -57,7 +57,7 @@ export interface Context { source: FullIndexInfo; dest: FullIndexInfo; documentMigrator: VersionedTransformer; - log: Logger; + log: SavedObjectsMigrationLogger; batchSize: number; pollInterval: number; scrollDuration: string; diff --git a/src/core/server/saved_objects/migrations/core/migration_coordinator.ts b/src/core/server/saved_objects/migrations/core/migration_coordinator.ts index c424b88335a98..ddd82edd93448 100644 --- a/src/core/server/saved_objects/migrations/core/migration_coordinator.ts +++ b/src/core/server/saved_objects/migrations/core/migration_coordinator.ts @@ -35,7 +35,7 @@ */ import _ from 'lodash'; -import { Logger } from './migration_logger'; +import { SavedObjectsMigrationLogger } from './migration_logger'; const DEFAULT_POLL_INTERVAL = 15000; @@ -52,7 +52,7 @@ export type MigrationResult = interface Opts { runMigration: () => Promise; isMigrated: () => Promise; - log: Logger; + log: SavedObjectsMigrationLogger; pollInterval?: number; } @@ -86,7 +86,7 @@ export async function coordinateMigration(opts: Opts): Promise * and is the cue for us to fall into a polling loop, waiting for some * other Kibana instance to complete the migration. */ -function handleIndexExists(error: any, log: Logger) { +function handleIndexExists(error: any, log: SavedObjectsMigrationLogger) { const isIndexExistsError = _.get(error, 'body.error.type') === 'resource_already_exists_exception'; if (!isIndexExistsError) { diff --git a/src/core/server/saved_objects/migrations/core/migration_logger.ts b/src/core/server/saved_objects/migrations/core/migration_logger.ts index 8b9e3f0a21ac3..9c98b7d85a8d8 100644 --- a/src/core/server/saved_objects/migrations/core/migration_logger.ts +++ b/src/core/server/saved_objects/migrations/core/migration_logger.ts @@ -24,13 +24,14 @@ export type LogFn = (path: string[], message: string) => void; -export interface Logger { +/** @public */ +export interface SavedObjectsMigrationLogger { debug: (msg: string) => void; info: (msg: string) => void; warning: (msg: string) => void; } -export class MigrationLogger implements Logger { +export class MigrationLogger implements SavedObjectsMigrationLogger { private log: LogFn; constructor(log: LogFn) { diff --git a/src/core/server/saved_objects/serialization/index.ts b/src/core/server/saved_objects/serialization/index.ts index 86a448ba8a5be..bd875db2001f4 100644 --- a/src/core/server/saved_objects/serialization/index.ts +++ b/src/core/server/saved_objects/serialization/index.ts @@ -27,10 +27,7 @@ import uuid from 'uuid'; import { SavedObjectsSchema } from '../schema'; import { decodeVersion, encodeVersion } from '../version'; -import { - SavedObjectsMigrationVersion, - SavedObjectReference, -} from '../service/saved_objects_client'; +import { SavedObjectsMigrationVersion, SavedObjectReference } from '../types'; /** * A raw document as represented directly in the saved object index. diff --git a/src/core/server/saved_objects/service/lib/repository.ts b/src/core/server/saved_objects/service/lib/repository.ts index 35b5eedb2da6e..e93d9e4047501 100644 --- a/src/core/server/saved_objects/service/lib/repository.ts +++ b/src/core/server/saved_objects/service/lib/repository.ts @@ -30,19 +30,21 @@ import { KibanaMigrator } from '../../migrations'; import { Config } from '../../../config'; import { SavedObjectsSerializer, SanitizedSavedObjectDoc, RawDoc } from '../../serialization'; import { - SavedObject, - SavedObjectAttributes, - SavedObjectsBaseOptions, SavedObjectsBulkCreateObject, SavedObjectsBulkGetObject, SavedObjectsBulkResponse, SavedObjectsCreateOptions, - SavedObjectsFindOptions, SavedObjectsFindResponse, - SavedObjectsMigrationVersion, SavedObjectsUpdateOptions, SavedObjectsUpdateResponse, } from '../saved_objects_client'; +import { + SavedObject, + SavedObjectAttributes, + SavedObjectsBaseOptions, + SavedObjectsFindOptions, + SavedObjectsMigrationVersion, +} from '../../types'; // BEWARE: The SavedObjectClient depends on the implementation details of the SavedObjectsRepository // so any breaking changes to this repository are considered breaking changes to the SavedObjectsClient. diff --git a/src/core/server/saved_objects/service/lib/scoped_client_provider.ts b/src/core/server/saved_objects/service/lib/scoped_client_provider.ts index e0ca16e254e18..0e93f9c443f14 100644 --- a/src/core/server/saved_objects/service/lib/scoped_client_provider.ts +++ b/src/core/server/saved_objects/service/lib/scoped_client_provider.ts @@ -17,7 +17,7 @@ * under the License. */ import { PriorityCollection } from './priority_collection'; -import { SavedObjectsClientContract } from '..'; +import { SavedObjectsClientContract } from '../../types'; /** * Options passed to each SavedObjectsClientWrapperFactory to aid in creating the wrapper instance. diff --git a/src/core/server/saved_objects/service/saved_objects_client.mock.ts b/src/core/server/saved_objects/service/saved_objects_client.mock.ts index 4d1ceeaf552b6..60bd5f96ff94d 100644 --- a/src/core/server/saved_objects/service/saved_objects_client.mock.ts +++ b/src/core/server/saved_objects/service/saved_objects_client.mock.ts @@ -17,7 +17,7 @@ * under the License. */ -import { SavedObjectsClientContract } from './saved_objects_client'; +import { SavedObjectsClientContract } from '../types'; import { SavedObjectsErrorHelpers } from './lib/errors'; const create = (): jest.Mocked => ({ diff --git a/src/core/server/saved_objects/service/saved_objects_client.ts b/src/core/server/saved_objects/service/saved_objects_client.ts index adc25a6d045e9..039579c5a2d14 100644 --- a/src/core/server/saved_objects/service/saved_objects_client.ts +++ b/src/core/server/saved_objects/service/saved_objects_client.ts @@ -18,20 +18,18 @@ */ import { SavedObjectsRepository } from './lib'; - +import { + SavedObject, + SavedObjectAttributes, + SavedObjectReference, + SavedObjectsMigrationVersion, + SavedObjectsBaseOptions, + SavedObjectsFindOptions, +} from '../types'; import { SavedObjectsErrorHelpers } from './lib/errors'; type Omit = Pick>; -/** - * - * @public - */ -export interface SavedObjectsBaseOptions { - /** Specify the namespace for this operation */ - namespace?: string; -} - /** * * @public @@ -41,6 +39,7 @@ export interface SavedObjectsCreateOptions extends SavedObjectsBaseOptions { id?: string; /** Overwrite existing documents (defaults to false) */ overwrite?: boolean; + /** {@inheritDoc SavedObjectsMigrationVersion} */ migrationVersion?: SavedObjectsMigrationVersion; references?: SavedObjectReference[]; } @@ -54,6 +53,7 @@ export interface SavedObjectsBulkCreateObject } /** + * Return type of the Saved Objects `find()` method. * - * @public - */ -export interface SavedObjectsFindOptions extends SavedObjectsBaseOptions { - type?: string | string[]; - page?: number; - perPage?: number; - sortField?: string; - sortOrder?: string; - fields?: string[]; - search?: string; - /** see Elasticsearch Simple Query String Query field argument for more information */ - searchFields?: string[]; - hasReference?: { type: string; id: string }; - defaultSearchOperator?: 'AND' | 'OR'; -} - -/** + * *Note*: this type is different between the Public and Server Saved Objects + * clients. * * @public */ @@ -132,135 +118,6 @@ export interface SavedObjectsUpdateResponse; } -/** - * A dictionary of saved object type -> version used to determine - * what migrations need to be applied to a saved object. - * - * @public - */ -export interface SavedObjectsMigrationVersion { - [pluginName: string]: string; -} - -/** - * - * @public - */ -export type SavedObjectAttribute = - | string - | number - | boolean - | null - | undefined - | SavedObjectAttributes - | SavedObjectAttributes[]; - -/** - * - * @public - */ -export interface SavedObjectAttributes { - [key: string]: SavedObjectAttribute | SavedObjectAttribute[]; -} - -/** - * - * @public - */ -export interface SavedObject { - id: string; - type: string; - version?: string; - updated_at?: string; - error?: { - message: string; - statusCode: number; - }; - attributes: T; - references: SavedObjectReference[]; - migrationVersion?: SavedObjectsMigrationVersion; -} - -/** - * A reference to another saved object. - * - * @public - */ -export interface SavedObjectReference { - name: string; - type: string; - id: string; -} - -/** - * ## SavedObjectsClient errors - * - * Since the SavedObjectsClient has its hands in everything we - * are a little paranoid about the way we present errors back to - * to application code. Ideally, all errors will be either: - * - * 1. Caused by bad implementation (ie. undefined is not a function) and - * as such unpredictable - * 2. An error that has been classified and decorated appropriately - * by the decorators in {@link SavedObjectsErrorHelpers} - * - * Type 1 errors are inevitable, but since all expected/handle-able errors - * should be Type 2 the `isXYZError()` helpers exposed at - * `SavedObjectsErrorHelpers` should be used to understand and manage error - * responses from the `SavedObjectsClient`. - * - * Type 2 errors are decorated versions of the source error, so if - * the elasticsearch client threw an error it will be decorated based - * on its type. That means that rather than looking for `error.body.error.type` or - * doing substring checks on `error.body.error.reason`, just use the helpers to - * understand the meaning of the error: - * - * ```js - * if (SavedObjectsErrorHelpers.isNotFoundError(error)) { - * // handle 404 - * } - * - * if (SavedObjectsErrorHelpers.isNotAuthorizedError(error)) { - * // 401 handling should be automatic, but in case you wanted to know - * } - * - * // always rethrow the error unless you handle it - * throw error; - * ``` - * - * ### 404s from missing index - * - * From the perspective of application code and APIs the SavedObjectsClient is - * a black box that persists objects. One of the internal details that users have - * no control over is that we use an elasticsearch index for persistance and that - * index might be missing. - * - * At the time of writing we are in the process of transitioning away from the - * operating assumption that the SavedObjects index is always available. Part of - * this transition is handling errors resulting from an index missing. These used - * to trigger a 500 error in most cases, and in others cause 404s with different - * error messages. - * - * From my (Spencer) perspective, a 404 from the SavedObjectsApi is a 404; The - * object the request/call was targeting could not be found. This is why #14141 - * takes special care to ensure that 404 errors are generic and don't distinguish - * between index missing or document missing. - * - * ### 503s from missing index - * - * Unlike all other methods, create requests are supposed to succeed even when - * the Kibana index does not exist because it will be automatically created by - * elasticsearch. When that is not the case it is because Elasticsearch's - * `action.auto_create_index` setting prevents it from being created automatically - * so we throw a special 503 with the intention of informing the user that their - * Elasticsearch settings need to be updated. - * - * See {@link SavedObjectsErrorHelpers} - * - * @public - */ -export type SavedObjectsClientContract = Pick; - /** * * @internal diff --git a/src/core/server/saved_objects/types.ts b/src/core/server/saved_objects/types.ts new file mode 100644 index 0000000000000..0966874aa435b --- /dev/null +++ b/src/core/server/saved_objects/types.ts @@ -0,0 +1,203 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { SavedObjectsClient } from './service/saved_objects_client'; + +/** + * Information about the migrations that have been applied to this SavedObject. + * When Kibana starts up, KibanaMigrator detects outdated documents and + * migrates them based on this value. For each migration that has been applied, + * the plugin's name is used as a key and the latest migration version as the + * value. + * + * @example + * migrationVersion: { + * dashboard: '7.1.1', + * space: '6.6.6', + * } + * + * @public + */ +export interface SavedObjectsMigrationVersion { + [pluginName: string]: string; +} + +/** + * + * @public + */ +export type SavedObjectAttribute = + | string + | number + | boolean + | null + | undefined + | SavedObjectAttributes + | SavedObjectAttributes[]; + +/** + * The data for a Saved Object is stored in the `attributes` key as either an + * object or an array of objects. + * + * @public + */ +export interface SavedObjectAttributes { + [key: string]: SavedObjectAttribute | SavedObjectAttribute[]; +} + +/** + * + * @public + */ +export interface SavedObject { + /** The ID of this Saved Object, guaranteed to be unique for all objects of the same `type` */ + id: string; + /** The type of Saved Object. Each plugin can define it's own custom Saved Object types. */ + type: string; + /** An opaque version number which changes on each successful write operation. Can be used for implementing optimistic concurrency control. */ + version?: string; + /** Timestamp of the last time this document had been updated. */ + updated_at?: string; + error?: { + message: string; + statusCode: number; + }; + /** {@inheritdoc SavedObjectAttributes} */ + attributes: T; + /** {@inheritdoc SavedObjectReference} */ + references: SavedObjectReference[]; + /** {@inheritdoc SavedObjectsMigrationVersion} */ + migrationVersion?: SavedObjectsMigrationVersion; +} + +/** + * A reference to another saved object. + * + * @public + */ +export interface SavedObjectReference { + name: string; + type: string; + id: string; +} + +/** + * + * @public + */ +export interface SavedObjectsFindOptions extends SavedObjectsBaseOptions { + type?: string | string[]; + page?: number; + perPage?: number; + sortField?: string; + sortOrder?: string; + /** + * An array of fields to include in the results + * @example + * SavedObjects.find({type: 'dashboard', fields: ['attributes.name', 'attributes.location']}) + */ + fields?: string[]; + /** Search documents using the Elasticsearch Simple Query String syntax. See Elasticsearch Simple Query String `query` argument for more information */ + search?: string; + /** The fields to perform the parsed query against. See Elasticsearch Simple Query String `fields` argument for more information */ + searchFields?: string[]; + hasReference?: { type: string; id: string }; + defaultSearchOperator?: 'AND' | 'OR'; +} + +/** + * + * @public + */ +export interface SavedObjectsBaseOptions { + /** Specify the namespace for this operation */ + namespace?: string; +} + +/** + * Saved Objects is Kibana's data persisentence mechanism allowing plugins to + * use Elasticsearch for storing plugin state. + * + * ## SavedObjectsClient errors + * + * Since the SavedObjectsClient has its hands in everything we + * are a little paranoid about the way we present errors back to + * to application code. Ideally, all errors will be either: + * + * 1. Caused by bad implementation (ie. undefined is not a function) and + * as such unpredictable + * 2. An error that has been classified and decorated appropriately + * by the decorators in {@link SavedObjectsErrorHelpers} + * + * Type 1 errors are inevitable, but since all expected/handle-able errors + * should be Type 2 the `isXYZError()` helpers exposed at + * `SavedObjectsErrorHelpers` should be used to understand and manage error + * responses from the `SavedObjectsClient`. + * + * Type 2 errors are decorated versions of the source error, so if + * the elasticsearch client threw an error it will be decorated based + * on its type. That means that rather than looking for `error.body.error.type` or + * doing substring checks on `error.body.error.reason`, just use the helpers to + * understand the meaning of the error: + * + * ```js + * if (SavedObjectsErrorHelpers.isNotFoundError(error)) { + * // handle 404 + * } + * + * if (SavedObjectsErrorHelpers.isNotAuthorizedError(error)) { + * // 401 handling should be automatic, but in case you wanted to know + * } + * + * // always rethrow the error unless you handle it + * throw error; + * ``` + * + * ### 404s from missing index + * + * From the perspective of application code and APIs the SavedObjectsClient is + * a black box that persists objects. One of the internal details that users have + * no control over is that we use an elasticsearch index for persistance and that + * index might be missing. + * + * At the time of writing we are in the process of transitioning away from the + * operating assumption that the SavedObjects index is always available. Part of + * this transition is handling errors resulting from an index missing. These used + * to trigger a 500 error in most cases, and in others cause 404s with different + * error messages. + * + * From my (Spencer) perspective, a 404 from the SavedObjectsApi is a 404; The + * object the request/call was targeting could not be found. This is why #14141 + * takes special care to ensure that 404 errors are generic and don't distinguish + * between index missing or document missing. + * + * ### 503s from missing index + * + * Unlike all other methods, create requests are supposed to succeed even when + * the Kibana index does not exist because it will be automatically created by + * elasticsearch. When that is not the case it is because Elasticsearch's + * `action.auto_create_index` setting prevents it from being created automatically + * so we throw a special 503 with the intention of informing the user that their + * Elasticsearch settings need to be updated. + * + * See {@link SavedObjectsErrorHelpers} + * + * @public + */ +export type SavedObjectsClientContract = Pick; diff --git a/src/core/server/server.api.md b/src/core/server/server.api.md index b345677b5e89e..dd889ea1995e0 100644 --- a/src/core/server/server.api.md +++ b/src/core/server/server.api.md @@ -549,31 +549,25 @@ export class Router { // @public (undocumented) export interface SavedObject { - // (undocumented) attributes: T; // (undocumented) error?: { message: string; statusCode: number; }; - // (undocumented) id: string; - // (undocumented) migrationVersion?: SavedObjectsMigrationVersion; - // (undocumented) references: SavedObjectReference[]; - // (undocumented) type: string; - // (undocumented) updated_at?: string; - // (undocumented) version?: string; } // @public (undocumented) +export type SavedObjectAttribute = string | number | boolean | null | undefined | SavedObjectAttributes | SavedObjectAttributes[]; + +// @public export interface SavedObjectAttributes { - // Warning: (ae-forgotten-export) The symbol "SavedObjectAttribute" needs to be exported by the entry point index.d.ts - // // (undocumented) [key: string]: SavedObjectAttribute | SavedObjectAttribute[]; } @@ -599,7 +593,6 @@ export interface SavedObjectsBulkCreateObject { // @public (undocumented) export interface SavedObjectsCreateOptions extends SavedObjectsBaseOptions { id?: string; - // (undocumented) migrationVersion?: SavedObjectsMigrationVersion; overwrite?: boolean; // (undocumented) @@ -750,7 +742,6 @@ export interface SavedObjectsExportOptions { export interface SavedObjectsFindOptions extends SavedObjectsBaseOptions { // (undocumented) defaultSearchOperator?: 'AND' | 'OR'; - // (undocumented) fields?: string[]; // (undocumented) hasReference?: { @@ -761,7 +752,6 @@ export interface SavedObjectsFindOptions extends SavedObjectsBaseOptions { page?: number; // (undocumented) perPage?: number; - // (undocumented) search?: string; searchFields?: string[]; // (undocumented) @@ -772,7 +762,7 @@ export interface SavedObjectsFindOptions extends SavedObjectsBaseOptions { type?: string | string[]; } -// @public (undocumented) +// @public export interface SavedObjectsFindResponse { // (undocumented) page: number; @@ -876,6 +866,16 @@ export interface SavedObjectsImportUnsupportedTypeError { type: 'unsupported_type'; } +// @public (undocumented) +export interface SavedObjectsMigrationLogger { + // (undocumented) + debug: (msg: string) => void; + // (undocumented) + info: (msg: string) => void; + // (undocumented) + warning: (msg: string) => void; +} + // @public export interface SavedObjectsMigrationVersion { // (undocumented) diff --git a/src/core/server/types.ts b/src/core/server/types.ts index 9b55da17a40a8..d712c804d45d1 100644 --- a/src/core/server/types.ts +++ b/src/core/server/types.ts @@ -18,5 +18,5 @@ */ /** This module is intended for consumption by public to avoid import issues with server-side code */ - export { PluginOpaqueId } from './plugins/types'; +export * from './saved_objects/types'; diff --git a/src/legacy/ui/public/chrome/api/saved_object_client.js b/src/core/server/types.ts~master similarity index 76% rename from src/legacy/ui/public/chrome/api/saved_object_client.js rename to src/core/server/types.ts~master index 3c9643556d9a9..9b55da17a40a8 100644 --- a/src/legacy/ui/public/chrome/api/saved_object_client.js +++ b/src/core/server/types.ts~master @@ -17,12 +17,6 @@ * under the License. */ -import { SavedObjectsClient } from '../../saved_objects'; +/** This module is intended for consumption by public to avoid import issues with server-side code */ -export function initSavedObjectClient(chrome) { - const savedObjectClient = new SavedObjectsClient(); - - chrome.getSavedObjectsClient = function () { - return savedObjectClient; - }; -} +export { PluginOpaqueId } from './plugins/types'; diff --git a/src/dev/run_check_core_api_changes.ts b/src/dev/run_check_core_api_changes.ts index f17f6c2e5efb2..4d0be7f388466 100644 --- a/src/dev/run_check_core_api_changes.ts +++ b/src/dev/run_check_core_api_changes.ts @@ -39,7 +39,7 @@ const apiExtractorConfig = (folder: string): ExtractorConfig => { tsconfigFilePath: '/tsconfig.json', }, projectFolder: path.resolve('./'), - mainEntryPointFilePath: `target/types/${folder}/index.d.ts`, + mainEntryPointFilePath: `target/types/core/${folder}/index.d.ts`, apiReport: { enabled: true, reportFileName: `${folder}.api.md`, diff --git a/src/fixtures/stubbed_saved_object_index_pattern.js b/src/fixtures/stubbed_saved_object_index_pattern.js index a983391328134..e737b2563823e 100644 --- a/src/fixtures/stubbed_saved_object_index_pattern.js +++ b/src/fixtures/stubbed_saved_object_index_pattern.js @@ -18,7 +18,7 @@ */ import stubbedLogstashFields from './logstash_fields'; -import { SimpleSavedObject } from '../legacy/ui/public/saved_objects/simple_saved_object'; +import { SimpleSavedObject } from '../core/public'; const mockLogstashFields = stubbedLogstashFields(); diff --git a/src/legacy/core_plugins/dashboard_embeddable_container/public/embeddable/dashboard_container_factory.ts b/src/legacy/core_plugins/dashboard_embeddable_container/public/embeddable/dashboard_container_factory.ts index 648204bf987e8..b7f5b948697d2 100644 --- a/src/legacy/core_plugins/dashboard_embeddable_container/public/embeddable/dashboard_container_factory.ts +++ b/src/legacy/core_plugins/dashboard_embeddable_container/public/embeddable/dashboard_container_factory.ts @@ -19,7 +19,7 @@ import { i18n } from '@kbn/i18n'; import { SavedObjectMetaData } from 'ui/saved_objects/components/saved_object_finder'; -import { SavedObjectAttributes } from 'target/types/server'; +import { SavedObjectAttributes } from 'src/core/server'; import { ContainerOutput, embeddableFactories, diff --git a/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/add_panel/add_panel_flyout.tsx b/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/add_panel/add_panel_flyout.tsx index 42fca6c721b0c..557ed941bbfab 100644 --- a/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/add_panel/add_panel_flyout.tsx +++ b/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/add_panel/add_panel_flyout.tsx @@ -38,8 +38,7 @@ import { EuiText, } from '@elastic/eui'; -// eslint-disable-next-line @kbn/eslint/no-restricted-paths -import { SavedObjectAttributes } from 'src/core/server/saved_objects'; +import { SavedObjectAttributes } from 'src/core/server'; import { EmbeddableFactoryNotFoundError } from '../../../../embeddables/embeddable_factory_not_found_error'; import { IContainer } from '../../../../containers'; diff --git a/src/legacy/core_plugins/kibana/public/dashboard/migrations/migrations_730.ts b/src/legacy/core_plugins/kibana/public/dashboard/migrations/migrations_730.ts index cbb695a564190..5300811a6dab9 100644 --- a/src/legacy/core_plugins/kibana/public/dashboard/migrations/migrations_730.ts +++ b/src/legacy/core_plugins/kibana/public/dashboard/migrations/migrations_730.ts @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -import { Logger } from 'target/types/server/saved_objects/migrations/core/migration_logger'; +import { SavedObjectsMigrationLogger } from 'src/core/server'; import { inspect } from 'util'; import { DashboardDoc730ToLatest, DashboardDoc700To720 } from './types'; import { isDashboardDoc } from './is_dashboard_doc'; @@ -29,7 +29,7 @@ export function migrations730( [key: string]: unknown; } | DashboardDoc700To720, - logger: Logger + logger: SavedObjectsMigrationLogger ): DashboardDoc730ToLatest | { [key: string]: unknown } { if (!isDashboardDoc(doc)) { // NOTE: we should probably throw an error here... but for now following suit and in the diff --git a/src/legacy/core_plugins/kibana/public/discover/__tests__/directives/field_chooser.js b/src/legacy/core_plugins/kibana/public/discover/__tests__/directives/field_chooser.js index f76a0ab72b212..e316dd3254cc0 100644 --- a/src/legacy/core_plugins/kibana/public/discover/__tests__/directives/field_chooser.js +++ b/src/legacy/core_plugins/kibana/public/discover/__tests__/directives/field_chooser.js @@ -27,7 +27,7 @@ import 'ui/private'; import '../../components/field_chooser/field_chooser'; import FixturesHitsProvider from 'fixtures/hits'; import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern'; -import { SimpleSavedObject } from 'ui/saved_objects'; +import { SimpleSavedObject } from '../../../../../../../core/public'; // Load the kibana app dependencies. diff --git a/src/legacy/ui/public/chrome/api/saved_object_client.ts b/src/legacy/ui/public/chrome/api/saved_object_client.ts new file mode 100644 index 0000000000000..b42e74e5a5865 --- /dev/null +++ b/src/legacy/ui/public/chrome/api/saved_object_client.ts @@ -0,0 +1,29 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { npStart } from 'ui/new_platform'; +import { Chrome } from '..'; + +const savedObjectsClient = npStart.core.savedObjects.client; + +export function initSavedObjectClient(chrome: Chrome) { + chrome.getSavedObjectsClient = function() { + return savedObjectsClient; + }; +} diff --git a/src/legacy/ui/public/chrome/index.d.ts b/src/legacy/ui/public/chrome/index.d.ts index e464cc5168182..ec2975e665379 100644 --- a/src/legacy/ui/public/chrome/index.d.ts +++ b/src/legacy/ui/public/chrome/index.d.ts @@ -17,8 +17,8 @@ * under the License. */ +import { SavedObjectsClientContract } from 'src/core/public'; import { ChromeBrand } from '../../../../core/public'; -import { SavedObjectsClient } from '../saved_objects'; import { BadgeApi } from './api/badge'; import { BreadcrumbsApi } from './api/breadcrumbs'; import { HelpExtensionApi } from './api/help_extension'; @@ -37,7 +37,7 @@ declare interface Chrome extends ChromeNavLinks { getBasePath(): string; getXsrfToken(): string; getKibanaVersion(): string; - getSavedObjectsClient(): SavedObjectsClient; + getSavedObjectsClient(): SavedObjectsClientContract; getUiSettingsClient(): any; setVisible(visible: boolean): any; getInjected(key: string, defaultValue?: any): any; diff --git a/src/legacy/ui/public/index_patterns/_index_pattern.ts b/src/legacy/ui/public/index_patterns/_index_pattern.ts index 09623f75442ed..a15a5be57d49e 100644 --- a/src/legacy/ui/public/index_patterns/_index_pattern.ts +++ b/src/legacy/ui/public/index_patterns/_index_pattern.ts @@ -26,9 +26,10 @@ import { fieldFormats } from 'ui/registry/field_formats'; // @ts-ignore import { expandShorthand } from 'ui/utils/mapping_setup'; import { toastNotifications } from 'ui/notify'; -import { findObjectByTitle, SavedObjectsClient } from 'ui/saved_objects'; - +import { findObjectByTitle } from 'ui/saved_objects'; import { IndexPatternsApiClient } from 'ui/index_patterns/index_patterns_api_client'; +import { SavedObjectsClientContract } from 'src/core/public'; + import { IndexPatternMissingIndices } from './errors'; import { getRoutes } from './get_routes'; import { FieldList } from './_field_list'; @@ -75,7 +76,7 @@ export class IndexPattern implements StaticIndexPattern { public metaFields: string[]; private version: string | undefined; - private savedObjectsClient: SavedObjectsClient; + private savedObjectsClient: SavedObjectsClientContract; private patternCache: any; private getConfig: any; private sourceFilters?: []; @@ -108,7 +109,7 @@ export class IndexPattern implements StaticIndexPattern { constructor( id: string | undefined, getConfig: any, - savedObjectsClient: SavedObjectsClient, + savedObjectsClient: SavedObjectsClientContract, apiClient: IndexPatternsApiClient, patternCache: any ) { diff --git a/src/legacy/ui/public/index_patterns/index_patterns.ts b/src/legacy/ui/public/index_patterns/index_patterns.ts index 6f22c1c2a73ea..f1cbc45fd9ff1 100644 --- a/src/legacy/ui/public/index_patterns/index_patterns.ts +++ b/src/legacy/ui/public/index_patterns/index_patterns.ts @@ -17,14 +17,13 @@ * under the License. */ +import { SavedObjectsClientContract, SimpleSavedObject, UiSettingsClient } from 'src/core/public'; // @ts-ignore import { fieldFormats } from '../registry/field_formats'; import { IndexPattern } from './_index_pattern'; import { createIndexPatternCache } from './_pattern_cache'; import { IndexPatternsApiClient } from './index_patterns_api_client'; -import { SavedObjectsClient, SimpleSavedObject } from '../saved_objects'; -import { UiSettingsClient } from '../../../../core/public'; const indexPatternCache = createIndexPatternCache(); const apiClient = new IndexPatternsApiClient(); @@ -33,10 +32,10 @@ export class IndexPatterns { fieldFormats: fieldFormats; private config: UiSettingsClient; - private savedObjectsClient: SavedObjectsClient; + private savedObjectsClient: SavedObjectsClientContract; private savedObjectsCache?: Array> | null; - constructor(config: UiSettingsClient, savedObjectsClient: SavedObjectsClient) { + constructor(config: UiSettingsClient, savedObjectsClient: SavedObjectsClientContract) { this.config = config; this.savedObjectsClient = savedObjectsClient; } diff --git a/src/legacy/ui/public/saved_objects/__tests__/find_object_by_title.js b/src/legacy/ui/public/saved_objects/__tests__/find_object_by_title.js index 6539f8c034136..766ed44a4c0fe 100644 --- a/src/legacy/ui/public/saved_objects/__tests__/find_object_by_title.js +++ b/src/legacy/ui/public/saved_objects/__tests__/find_object_by_title.js @@ -20,7 +20,7 @@ import sinon from 'sinon'; import expect from '@kbn/expect'; import { findObjectByTitle } from '../find_object_by_title'; -import { SimpleSavedObject } from '../simple_saved_object'; +import { SimpleSavedObject } from '../../../../../core/public'; describe('findObjectByTitle', () => { const sandbox = sinon.createSandbox(); diff --git a/src/legacy/ui/public/saved_objects/__tests__/simple_saved_object.js b/src/legacy/ui/public/saved_objects/__tests__/simple_saved_object.js index a6583b97972ab..f2fc9bfe232e2 100644 --- a/src/legacy/ui/public/saved_objects/__tests__/simple_saved_object.js +++ b/src/legacy/ui/public/saved_objects/__tests__/simple_saved_object.js @@ -19,7 +19,7 @@ import sinon from 'sinon'; import expect from '@kbn/expect'; -import { SimpleSavedObject } from '../simple_saved_object'; +import { SimpleSavedObject } from '../../../../../core/public'; describe('SimpleSavedObject', () => { it('persists type and id', () => { diff --git a/src/legacy/ui/public/saved_objects/components/saved_object_finder.tsx b/src/legacy/ui/public/saved_objects/components/saved_object_finder.tsx index a5930ee38a662..9169286fb4171 100644 --- a/src/legacy/ui/public/saved_objects/components/saved_object_finder.tsx +++ b/src/legacy/ui/public/saved_objects/components/saved_object_finder.tsx @@ -46,7 +46,7 @@ import { Direction } from '@elastic/eui/src/services/sort/sort_direction'; import { i18n } from '@kbn/i18n'; import { SavedObjectAttributes } from 'src/core/server'; -import { SimpleSavedObject } from '../simple_saved_object'; +import { SimpleSavedObject } from 'src/core/public'; // TODO the typings for EuiListGroup are incorrect - maxWidth is missing. This can be removed when the types are adjusted const FixedEuiListGroup = (EuiListGroup as any) as React.FunctionComponent< diff --git a/src/legacy/ui/public/saved_objects/find_object_by_title.ts b/src/legacy/ui/public/saved_objects/find_object_by_title.ts index e27326249f5c9..d6f11bcb80956 100644 --- a/src/legacy/ui/public/saved_objects/find_object_by_title.ts +++ b/src/legacy/ui/public/saved_objects/find_object_by_title.ts @@ -19,19 +19,19 @@ import { find } from 'lodash'; import { SavedObjectAttributes } from 'src/core/server'; -import { SavedObjectsClient } from './saved_objects_client'; -import { SimpleSavedObject } from './simple_saved_object'; +import { SavedObjectsClientContract } from 'src/core/public'; +import { SimpleSavedObject } from 'src/core/public'; /** * Returns an object matching a given title * - * @param savedObjectsClient {SavedObjectsClient} + * @param savedObjectsClient {SavedObjectsClientContract} * @param type {string} * @param title {string} * @returns {Promise} */ export function findObjectByTitle( - savedObjectsClient: SavedObjectsClient, + savedObjectsClient: SavedObjectsClientContract, type: string, title: string ): Promise | void> { diff --git a/src/legacy/ui/public/saved_objects/index.ts b/src/legacy/ui/public/saved_objects/index.ts index 31222bb9f5ebc..8076213f62e9a 100644 --- a/src/legacy/ui/public/saved_objects/index.ts +++ b/src/legacy/ui/public/saved_objects/index.ts @@ -17,10 +17,8 @@ * under the License. */ -export { SavedObjectsClient } from './saved_objects_client'; export { SavedObjectRegistryProvider } from './saved_object_registry'; export { SavedObjectsClientProvider } from './saved_objects_client_provider'; // @ts-ignore export { SavedObjectLoader } from './saved_object_loader'; -export { SimpleSavedObject } from './simple_saved_object'; export { findObjectByTitle } from './find_object_by_title'; diff --git a/src/legacy/ui/public/saved_objects/saved_objects_client.test.ts b/src/legacy/ui/public/saved_objects/saved_objects_client.test.ts deleted file mode 100644 index fed3b8807cddd..0000000000000 --- a/src/legacy/ui/public/saved_objects/saved_objects_client.test.ts +++ /dev/null @@ -1,357 +0,0 @@ -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -jest.mock('ui/kfetch', () => ({})); - -import * as sinon from 'sinon'; -import { SavedObjectsFindOptions } from 'src/core/server'; -import { SavedObjectsClient } from './saved_objects_client'; -import { SimpleSavedObject } from './simple_saved_object'; - -describe('SavedObjectsClient', () => { - const doc = { - id: 'AVwSwFxtcMV38qjDZoQg', - type: 'config', - attributes: { title: 'Example title' }, - version: 'foo', - }; - - let kfetchStub: sinon.SinonStub; - let savedObjectsClient: SavedObjectsClient; - beforeEach(() => { - kfetchStub = sinon.stub(); - require('ui/kfetch').kfetch = async (...args: any[]) => { - return kfetchStub(...args); - }; - savedObjectsClient = new SavedObjectsClient(); - }); - - describe('#get', () => { - beforeEach(() => { - kfetchStub - .withArgs({ - method: 'POST', - pathname: `/api/saved_objects/_bulk_get`, - query: undefined, - body: sinon.match.any, - }) - .returns(Promise.resolve({ saved_objects: [doc] })); - }); - - test('returns a promise', () => { - expect(savedObjectsClient.get('index-pattern', 'logstash-*')).toBeInstanceOf(Promise); - }); - - test('requires type', async () => { - try { - await savedObjectsClient.get(undefined as any, undefined as any); - fail('should have error'); - } catch (e) { - expect(e.message).toBe('requires type and id'); - } - }); - - test('requires id', async () => { - try { - await savedObjectsClient.get('index-pattern', undefined as any); - fail('should have error'); - } catch (e) { - expect(e.message).toBe('requires type and id'); - } - }); - - test('resolves with instantiated SavedObject', async () => { - const response = await savedObjectsClient.get(doc.type, doc.id); - expect(response).toBeInstanceOf(SimpleSavedObject); - expect(response.type).toBe('config'); - expect(response.get('title')).toBe('Example title'); - }); - - test('makes HTTP call', async () => { - await savedObjectsClient.get(doc.type, doc.id); - sinon.assert.calledOnce(kfetchStub); - }); - - test('handles HTTP call when it fails', async () => { - kfetchStub - .withArgs({ - method: 'POST', - pathname: `/api/saved_objects/_bulk_get`, - query: undefined, - body: sinon.match.any, - }) - .rejects(new Error('Request failed')); - try { - await savedObjectsClient.get(doc.type, doc.id); - throw new Error('should have error'); - } catch (e) { - expect(e.message).toBe('Request failed'); - } - }); - }); - - describe('#delete', () => { - beforeEach(() => { - kfetchStub - .withArgs({ - method: 'DELETE', - pathname: `/api/saved_objects/index-pattern/logstash-*`, - query: undefined, - body: undefined, - }) - .returns(Promise.resolve({})); - }); - - test('returns a promise', () => { - expect(savedObjectsClient.delete('index-pattern', 'logstash-*')).toBeInstanceOf(Promise); - }); - - test('requires type', async () => { - try { - await savedObjectsClient.delete(undefined as any, undefined as any); - fail('should have error'); - } catch (e) { - expect(e.message).toBe('requires type and id'); - } - }); - - test('requires id', async () => { - try { - await savedObjectsClient.delete('index-pattern', undefined as any); - fail('should have error'); - } catch (e) { - expect(e.message).toBe('requires type and id'); - } - }); - - test('makes HTTP call', () => { - savedObjectsClient.delete('index-pattern', 'logstash-*'); - sinon.assert.calledOnce(kfetchStub); - }); - }); - - describe('#update', () => { - const requireMessage = 'requires type, id and attributes'; - - beforeEach(() => { - kfetchStub - .withArgs({ - method: 'PUT', - pathname: `/api/saved_objects/index-pattern/logstash-*`, - query: undefined, - body: sinon.match.any, - }) - .returns(Promise.resolve({ data: 'api-response' })); - }); - - test('returns a promise', () => { - expect(savedObjectsClient.update('index-pattern', 'logstash-*', {})).toBeInstanceOf(Promise); - }); - - test('requires type', async () => { - try { - await savedObjectsClient.update(undefined as any, undefined as any, undefined as any); - fail('should have error'); - } catch (e) { - expect(e.message).toBe(requireMessage); - } - }); - - test('requires id', async () => { - try { - await savedObjectsClient.update('index-pattern', undefined as any, undefined as any); - fail('should have error'); - } catch (e) { - expect(e.message).toBe(requireMessage); - } - }); - - test('requires attributes', async () => { - try { - await savedObjectsClient.update('index-pattern', 'logstash-*', undefined as any); - fail('should have error'); - } catch (e) { - expect(e.message).toBe(requireMessage); - } - }); - - test('makes HTTP call', () => { - const attributes = { foo: 'Foo', bar: 'Bar' }; - const body = { attributes, version: 'foo' }; - const options = { version: 'foo' }; - - savedObjectsClient.update('index-pattern', 'logstash-*', attributes, options); - sinon.assert.calledOnce(kfetchStub); - sinon.assert.calledWithExactly( - kfetchStub, - sinon.match({ - body: JSON.stringify(body), - }) - ); - }); - }); - - describe('#create', () => { - const requireMessage = 'requires type and attributes'; - - beforeEach(() => { - kfetchStub - .withArgs({ - method: 'POST', - pathname: `/api/saved_objects/index-pattern`, - query: undefined, - body: sinon.match.any, - }) - .returns(Promise.resolve({})); - }); - - test('returns a promise', () => { - expect(savedObjectsClient.create('index-pattern', {})).toBeInstanceOf(Promise); - }); - - test('requires type', async () => { - try { - await savedObjectsClient.create(undefined as any, undefined as any); - fail('should have error'); - } catch (e) { - expect(e.message).toBe(requireMessage); - } - }); - - test('allows for id to be provided', () => { - const attributes = { foo: 'Foo', bar: 'Bar' }; - const path = `/api/saved_objects/index-pattern/myId`; - kfetchStub - .withArgs({ - method: 'POST', - pathname: path, - query: undefined, - body: sinon.match.any, - }) - .returns(Promise.resolve({})); - - savedObjectsClient.create('index-pattern', attributes, { id: 'myId' }); - - sinon.assert.calledOnce(kfetchStub); - sinon.assert.calledWithExactly( - kfetchStub, - sinon.match({ - pathname: path, - }) - ); - }); - - test('makes HTTP call', () => { - const attributes = { foo: 'Foo', bar: 'Bar' }; - savedObjectsClient.create('index-pattern', attributes); - - sinon.assert.calledOnce(kfetchStub); - sinon.assert.calledWithExactly( - kfetchStub, - sinon.match({ - pathname: sinon.match.string, - body: JSON.stringify({ attributes }), - }) - ); - }); - }); - - describe('#bulk_create', () => { - beforeEach(() => { - kfetchStub - .withArgs({ - method: 'POST', - pathname: `/api/saved_objects/_bulk_create`, - query: sinon.match.any, - body: sinon.match.any, - }) - .returns(Promise.resolve({ saved_objects: [doc] })); - }); - - test('returns a promise', () => { - expect(savedObjectsClient.bulkCreate([doc], {})).toBeInstanceOf(Promise); - }); - - test('resolves with instantiated SavedObjects', async () => { - const response = await savedObjectsClient.bulkCreate([doc], {}); - expect(response).toHaveProperty('savedObjects'); - expect(response.savedObjects.length).toBe(1); - expect(response.savedObjects[0]).toBeInstanceOf(SimpleSavedObject); - }); - - test('makes HTTP call', async () => { - await savedObjectsClient.bulkCreate([doc], {}); - sinon.assert.calledOnce(kfetchStub); - }); - }); - - describe('#find', () => { - const object = { id: 'logstash-*', type: 'index-pattern', title: 'Test' }; - - beforeEach(() => { - kfetchStub.returns(Promise.resolve({ saved_objects: [object] })); - }); - - test('returns a promise', () => { - expect(savedObjectsClient.find()).toBeInstanceOf(Promise); - }); - - test('accepts type', () => { - const body = { type: 'index-pattern', invalid: true }; - - savedObjectsClient.find(body); - sinon.assert.calledOnce(kfetchStub); - sinon.assert.calledWithExactly( - kfetchStub, - sinon.match({ - pathname: `/api/saved_objects/_find`, - query: { type: 'index-pattern', invalid: true }, - }) - ); - }); - - test('accepts fields', () => { - const body = { fields: ['title', 'description'] }; - - savedObjectsClient.find(body); - sinon.assert.calledOnce(kfetchStub); - sinon.assert.calledWithExactly( - kfetchStub, - sinon.match({ - pathname: `/api/saved_objects/_find`, - query: { fields: ['title', 'description'] }, - }) - ); - }); - - test('accepts pagination params', () => { - const options: SavedObjectsFindOptions = { perPage: 10, page: 6 }; - - savedObjectsClient.find(options); - sinon.assert.calledOnce(kfetchStub); - sinon.assert.alwaysCalledWith( - kfetchStub, - sinon.match({ - pathname: `/api/saved_objects/_find`, - query: { per_page: 10, page: 6 }, - }) - ); - }); - }); -}); diff --git a/src/legacy/ui/public/saved_objects/saved_objects_client_provider.ts b/src/legacy/ui/public/saved_objects/saved_objects_client_provider.ts index 1ef0d07135fd5..0375eb21c19f0 100644 --- a/src/legacy/ui/public/saved_objects/saved_objects_client_provider.ts +++ b/src/legacy/ui/public/saved_objects/saved_objects_client_provider.ts @@ -17,9 +17,9 @@ * under the License. */ +import { SavedObjectsClient } from 'src/core/public'; import chrome from '../chrome'; import { PromiseService } from '../promises'; -import { SavedObjectsClient } from './saved_objects_client'; type Args any> = T extends (...args: infer X) => any ? X : never; diff --git a/x-pack/dev-tools/jest/create_jest_config.js b/x-pack/dev-tools/jest/create_jest_config.js index f5f1a5ceac695..e2cb873f54fd0 100644 --- a/x-pack/dev-tools/jest/create_jest_config.js +++ b/x-pack/dev-tools/jest/create_jest_config.js @@ -35,6 +35,7 @@ export function createJestConfig({ kibanaDirectory, xPackKibanaDirectory }) { testMatch: ['**/*.test.{js,ts,tsx}'], transform: { '^.+\\.(js|tsx?)$': `${kibanaDirectory}/src/dev/jest/babel_transform.js`, + '^.+\\.html?$': 'jest-raw-loader', }, transformIgnorePatterns: [ // ignore all node_modules except @elastic/eui which requires babel transforms to handle dynamic import()