From 8522e1dfbb31f84d27e5f92be81fd859480000f4 Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Wed, 26 Jun 2019 13:17:00 +0200 Subject: [PATCH 01/29] Move SavedObjectClient files to core/public --- src/core/public/index.ts | 2 ++ src/core/public/saved_objects/index.ts | 21 +++++++++++++++++++ .../saved_objects_client.test.ts | 0 .../saved_objects/saved_objects_client.ts | 12 ++++++++--- .../saved_objects/simple_saved_object.ts | 0 .../stubbed_saved_object_index_pattern.js | 2 +- .../components/saved_object_finder.tsx | 2 +- .../saved_objects/find_object_by_title.ts | 4 ++-- src/legacy/ui/public/saved_objects/index.ts | 4 ++-- .../saved_objects_client_provider.ts | 2 +- 10 files changed, 39 insertions(+), 10 deletions(-) create mode 100644 src/core/public/saved_objects/index.ts rename src/{legacy/ui => core}/public/saved_objects/saved_objects_client.test.ts (100%) rename src/{legacy/ui => core}/public/saved_objects/saved_objects_client.ts (96%) rename src/{legacy/ui => core}/public/saved_objects/simple_saved_object.ts (100%) diff --git a/src/core/public/index.ts b/src/core/public/index.ts index 2a88ebf86ab0c..ce3196a754626 100644 --- a/src/core/public/index.ts +++ b/src/core/public/index.ts @@ -70,6 +70,8 @@ import { DocLinksStart } from './doc_links'; export { CoreContext, CoreSystem } from './core_system'; export { RecursiveReadonly } from '../utils'; +export { SimpleSavedObject, SavedObjectsClient } from './saved_objects'; + /** * Core services exposed to the `Plugin` setup lifecycle * diff --git a/src/core/public/saved_objects/index.ts b/src/core/public/saved_objects/index.ts new file mode 100644 index 0000000000000..b55e58fd27bb8 --- /dev/null +++ b/src/core/public/saved_objects/index.ts @@ -0,0 +1,21 @@ +/* + * 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 { SavedObjectsClient } from './saved_objects_client'; +export { SimpleSavedObject } from './simple_saved_object'; diff --git a/src/legacy/ui/public/saved_objects/saved_objects_client.test.ts b/src/core/public/saved_objects/saved_objects_client.test.ts similarity index 100% rename from src/legacy/ui/public/saved_objects/saved_objects_client.test.ts rename to src/core/public/saved_objects/saved_objects_client.test.ts 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 96% 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..45b5d7e0efaf8 100644 --- a/src/legacy/ui/public/saved_objects/saved_objects_client.ts +++ b/src/core/public/saved_objects/saved_objects_client.ts @@ -28,9 +28,15 @@ import { SavedObjectsFindOptions, 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'; +import { kfetch, KFetchQuery } from '../../../legacy/ui/public/kfetch'; +import { + keysToCamelCaseShallow, + keysToSnakeCaseShallow, +} from '../../../legacy/ui/public/utils/case_conversion'; +import { + isAutoCreateIndexError, + showAutoCreateIndexErrorPage, +} from '../../../legacy/ui/public/error_auto_create_index/error_auto_create_index'; import { SimpleSavedObject } from './simple_saved_object'; interface RequestParams { 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 100% rename from src/legacy/ui/public/saved_objects/simple_saved_object.ts rename to src/core/public/saved_objects/simple_saved_object.ts 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/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..435d1ea1fbb82 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,8 +19,8 @@ import { find } from 'lodash'; import { SavedObjectAttributes } from 'src/core/server'; -import { SavedObjectsClient } from './saved_objects_client'; -import { SimpleSavedObject } from './simple_saved_object'; +import { SavedObjectsClient } from 'src/core/public'; +import { SimpleSavedObject } from 'src/core/public'; /** * Returns an object matching a given title diff --git a/src/legacy/ui/public/saved_objects/index.ts b/src/legacy/ui/public/saved_objects/index.ts index 31222bb9f5ebc..e2a1e2c342489 100644 --- a/src/legacy/ui/public/saved_objects/index.ts +++ b/src/legacy/ui/public/saved_objects/index.ts @@ -17,10 +17,10 @@ * under the License. */ -export { SavedObjectsClient } from './saved_objects_client'; +export { SavedObjectsClient } from 'src/core/public'; 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 { SimpleSavedObject } from 'src/core/public'; export { findObjectByTitle } from './find_object_by_title'; 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; From 2a3359247c3980ada4d885abbce1dd344544bc32 Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Thu, 27 Jun 2019 14:36:01 +0200 Subject: [PATCH 02/29] Initial SavedObjectsService in public Core --- .../public/kibana-plugin-public.corestart.md | 1 + ...na-plugin-public.corestart.savedobjects.md | 13 ++++ .../kibana-plugin-public.httpfetchquery.md | 12 ++++ .../core/public/kibana-plugin-public.md | 5 ++ ...public.savedobjectsclient.(constructor).md | 20 ++++++ ...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 | 37 ++++++++++ ...plugin-public.savedobjectsclient.update.md | 28 ++++++++ ...lugin-public.savedobjectsclientcontract.md | 13 ++++ ...-plugin-public.savedobjectsstart.client.md | 13 ++++ .../kibana-plugin-public.savedobjectsstart.md | 19 +++++ ...-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 +++ src/core/public/core_system.ts | 3 + src/core/public/http/http_service.mock.ts | 4 +- src/core/public/index.ts | 13 +++- src/core/public/legacy/legacy_service.test.ts | 3 + src/core/public/plugins/plugin_context.ts | 1 + .../public/plugins/plugins_service.test.ts | 2 + src/core/public/public.api.md | 71 +++++++++++++++++++ src/core/public/saved_objects/index.ts | 3 +- .../saved_objects/saved_objects_client.ts | 29 +++++--- .../saved_objects_service.mock.ts | 50 +++++++++++++ .../saved_objects/saved_objects_service.ts | 37 ++++++++++ .../saved_objects/simple_saved_object.ts | 9 +-- src/dev/run_check_core_api_changes.ts | 2 +- ...bject_client.js => saved_object_client.ts} | 11 +-- src/legacy/ui/public/chrome/index.d.ts | 4 +- src/legacy/ui/public/saved_objects/index.ts | 1 - 46 files changed, 699 insertions(+), 30 deletions(-) create mode 100644 docs/development/core/public/kibana-plugin-public.corestart.savedobjects.md create mode 100644 docs/development/core/public/kibana-plugin-public.httpfetchquery.md create mode 100644 docs/development/core/public/kibana-plugin-public.savedobjectsclient.(constructor).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.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.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 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/public/chrome/api/{saved_object_client.js => saved_object_client.ts} (75%) 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.httpfetchquery.md b/docs/development/core/public/kibana-plugin-public.httpfetchquery.md new file mode 100644 index 0000000000000..e09b22b074453 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.httpfetchquery.md @@ -0,0 +1,12 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [HttpFetchQuery](./kibana-plugin-public.httpfetchquery.md) + +## HttpFetchQuery interface + + +Signature: + +```typescript +export interface HttpFetchQuery +``` diff --git a/docs/development/core/public/kibana-plugin-public.md b/docs/development/core/public/kibana-plugin-public.md index 98b6a8703f543..ce4daabc75477 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) | The SavedObjectsClient class acts as a generic data fetcher and data saver for saved objects regardless of type. | +| [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) | | @@ -40,6 +42,7 @@ The plugin integrates with the core system via lifecycle events: `setup` | [ErrorToastOptions](./kibana-plugin-public.errortoastoptions.md) | | | [FatalErrorInfo](./kibana-plugin-public.fatalerrorinfo.md) | Represents the message and stack of a fatal Error | | [FatalErrorsSetup](./kibana-plugin-public.fatalerrorssetup.md) | FatalErrors stop the Kibana Public Core and displays a fatal error screen with details about the Kibana build and the error. | +| [HttpFetchQuery](./kibana-plugin-public.httpfetchquery.md) | | | [HttpInterceptor](./kibana-plugin-public.httpinterceptor.md) | | | [HttpServiceBase](./kibana-plugin-public.httpservicebase.md) | | | [I18nStart](./kibana-plugin-public.i18nstart.md) | I18nStart.Context is required by any localizable React component from @kbn/i18n and @elastic/eui packages and is supposed to be used as the topmost component for any i18n-compatible React tree. | @@ -50,6 +53,7 @@ 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 | +| [SavedObjectsStart](./kibana-plugin-public.savedobjectsstart.md) | | | [UiSettingsState](./kibana-plugin-public.uisettingsstate.md) | | ## Type Aliases @@ -62,6 +66,7 @@ The plugin integrates with the core system via lifecycle events: `setup` | [HttpStart](./kibana-plugin-public.httpstart.md) | | | [PluginInitializer](./kibana-plugin-public.plugininitializer.md) | The plugin export at the root of a plugin's public directory should conform to this interface. | | [RecursiveReadonly](./kibana-plugin-public.recursivereadonly.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.savedobjectsclient.(constructor).md b/docs/development/core/public/kibana-plugin-public.savedobjectsclient.(constructor).md new file mode 100644 index 0000000000000..8b04196536c18 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsclient.(constructor).md @@ -0,0 +1,20 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObjectsClient](./kibana-plugin-public.savedobjectsclient.md) > [(constructor)](./kibana-plugin-public.savedobjectsclient.(constructor).md) + +## SavedObjectsClient.(constructor) + +Constructs a new instance of the `SavedObjectsClient` class + +Signature: + +```typescript +constructor(http: HttpSetup); +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| http | HttpSetup | | + 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..43c532270ab2a --- /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?: BulkCreateOptions[], options?: HttpFetchQuery) => 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..8ccee3eb3ca8f --- /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..ae3598ae1f46d --- /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?: CreateOptions) => 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..8091711cacb8f --- /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?: SavedObjectsFindOptions) => 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..dc922ec74fe8b --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsclient.md @@ -0,0 +1,37 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObjectsClient](./kibana-plugin-public.savedobjectsclient.md) + +## SavedObjectsClient class + +The SavedObjectsClient class acts as a generic data fetcher and data saver for saved objects regardless of type. + +Signature: + +```typescript +export declare class SavedObjectsClient +``` + +## Constructors + +| Constructor | Modifiers | Description | +| --- | --- | --- | +| [(constructor)(http)](./kibana-plugin-public.savedobjectsclient.(constructor).md) | | Constructs a new instance of the SavedObjectsClient class | + +## Properties + +| Property | Modifiers | Type | Description | +| --- | --- | --- | --- | +| [bulkCreate](./kibana-plugin-public.savedobjectsclient.bulkcreate.md) | | (objects?: BulkCreateOptions<SavedObjectAttributes>[], options?: HttpFetchQuery) => Promise<BatchResponse<SavedObjectAttributes>> | Creates multiple documents at once | +| [bulkGet](./kibana-plugin-public.savedobjectsclient.bulkget.md) | | (objects?: {
id: string;
type: string;
}[]) => Promise<BatchResponse<SavedObjectAttributes>> | Returns an array of objects by id | +| [create](./kibana-plugin-public.savedobjectsclient.create.md) | | <T extends SavedObjectAttributes>(type: string, attributes: T, options?: CreateOptions) => 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?: SavedObjectsFindOptions) => Promise<FindResults<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 | + 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..f1ec383628020 --- /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 }?: UpdateOptions): Promise>; +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| type | string | | +| id | string | | +| attributes | T | | +| { version, migrationVersion, references } | UpdateOptions | | + +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.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.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/src/core/public/core_system.ts b/src/core/public/core_system.ts index f3f466df8a78e..eeedab58c5aec 100644 --- a/src/core/public/core_system.ts +++ b/src/core/public/core_system.ts @@ -34,6 +34,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'; interface Params { rootDomElement: HTMLElement; @@ -157,6 +158,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 SavedObjectsService.start({ http }); const i18n = await this.i18n.start(); const application = await this.application.start({ injectedMetadata }); @@ -192,6 +194,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 ce3196a754626..26bdf4872eca2 100644 --- a/src/core/public/index.ts +++ b/src/core/public/index.ts @@ -50,7 +50,7 @@ import { ChromeRecentlyAccessedHistoryItem, } from './chrome'; import { FatalErrorsSetup, FatalErrorInfo } from './fatal_errors'; -import { HttpServiceBase, HttpSetup, HttpStart, HttpInterceptor } from './http'; +import { HttpServiceBase, HttpSetup, HttpStart, HttpInterceptor, HttpFetchQuery } from './http'; import { I18nStart } from './i18n'; import { InjectedMetadataSetup, InjectedMetadataStart, LegacyNavLink } from './injected_metadata'; import { @@ -66,12 +66,12 @@ import { Plugin, PluginInitializer, PluginInitializerContext } from './plugins'; import { UiSettingsClient, UiSettingsState, UiSettingsClientContract } from './ui_settings'; import { ApplicationSetup, Capabilities, ApplicationStart } from './application'; import { DocLinksStart } from './doc_links'; +import { SavedObjectsClient, SimpleSavedObject, SavedObjectsClientContract } from './saved_objects'; +import { SavedObjectsStart } from './saved_objects/saved_objects_service'; export { CoreContext, CoreSystem } from './core_system'; export { RecursiveReadonly } from '../utils'; -export { SimpleSavedObject, SavedObjectsClient } from './saved_objects'; - /** * Core services exposed to the `Plugin` setup lifecycle * @@ -110,6 +110,8 @@ export interface CoreStart { docLinks: DocLinksStart; /** {@link HttpStart} */ http: HttpStart; + /** {@link SavedObjectsStart} */ + savedObjects: SavedObjectsStart; /** {@link I18nStart} */ i18n: I18nStart; /** {@link NotificationsStart} */ @@ -152,6 +154,7 @@ export { ErrorToastOptions, FatalErrorInfo, FatalErrorsSetup, + HttpFetchQuery, HttpInterceptor, HttpServiceBase, HttpSetup, @@ -165,6 +168,10 @@ export { Plugin, PluginInitializer, PluginInitializerContext, + SavedObjectsClient, + SavedObjectsClientContract, + SavedObjectsStart, + SimpleSavedObject, Toast, ToastInput, ToastsApi, diff --git a/src/core/public/legacy/legacy_service.test.ts b/src/core/public/legacy/legacy_service.test.ts index a514bf7154055..8ef854f16e8b1 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'; const applicationSetup = applicationServiceMock.createSetupContract(); const fatalErrorsSetup = fatalErrorsServiceMock.createSetupContract(); @@ -93,6 +94,7 @@ const injectedMetadataStart = injectedMetadataServiceMock.createStartContract(); const notificationsStart = notificationServiceMock.createStartContract(); const overlayStart = overlayServiceMock.createStartContract(); const uiSettingsStart = uiSettingsServiceMock.createStartContract(); +const savedObjectsStart = savedObjectsMock.createStartContract(); const defaultStartDeps = { core: { @@ -105,6 +107,7 @@ const defaultStartDeps = { notifications: notificationsStart, overlays: overlayStart, uiSettings: uiSettingsStart, + savedObjects: savedObjectsStart, }, targetDomElement: document.createElement('div'), plugins: {}, diff --git a/src/core/public/plugins/plugin_context.ts b/src/core/public/plugins/plugin_context.ts index 022c71492f383..94439db192b8e 100644 --- a/src/core/public/plugins/plugin_context.ts +++ b/src/core/public/plugins/plugin_context.ts @@ -107,5 +107,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 55e91bde27cb0..e0868ff60b1b9 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'; export let mockPluginInitializers: Map; @@ -89,6 +90,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 55f2a25210321..1ccae57ea2fa8 100644 --- a/src/core/public/public.api.md +++ b/src/core/public/public.api.md @@ -8,6 +8,11 @@ import { IconType } from '@elastic/eui'; import { Observable } from 'rxjs'; import React from 'react'; import * as Rx from 'rxjs'; +import { SavedObject } from 'src/core/server'; +import { SavedObjectAttributes } from 'src/core/server'; +import { SavedObjectReference } from 'src/core/server'; +import { SavedObjectsFindOptions } from 'src/core/server'; +import { SavedObjectsMigrationVersion } from 'src/core/server'; import { EuiGlobalToastListToast as Toast } from '@elastic/eui'; // @public (undocumented) @@ -199,6 +204,8 @@ export interface CoreStart { // (undocumented) overlays: OverlayStart; // (undocumented) + savedObjects: SavedObjectsStart; + // (undocumented) uiSettings: UiSettingsClientContract; } @@ -329,6 +336,12 @@ export interface FatalErrorsSetup { get$: () => Rx.Observable; } +// @public (undocumented) +export interface HttpFetchQuery { + // (undocumented) + [key: string]: string | number | boolean | undefined; +} + // @public (undocumented) export interface HttpInterceptor { // Warning: (ae-forgotten-export) The symbol "HttpInterceptController" needs to be exported by the entry point index.d.ts @@ -498,6 +511,64 @@ export type RecursiveReadonly = T extends (...args: any[]) => any ? T : T ext [K in keyof T]: RecursiveReadonly; }> : T; +// @public +export class SavedObjectsClient { + constructor(http: HttpSetup); + // Warning: (ae-forgotten-export) The symbol "BulkCreateOptions" needs to be exported by the entry point index.d.ts + // Warning: (ae-forgotten-export) The symbol "BatchResponse" needs to be exported by the entry point index.d.ts + bulkCreate: (objects?: BulkCreateOptions[], options?: HttpFetchQuery) => Promise>; + bulkGet: (objects?: { + id: string; + type: string; + }[]) => Promise>; + // Warning: (ae-forgotten-export) The symbol "CreateOptions" needs to be exported by the entry point index.d.ts + create: (type: string, attributes: T, options?: CreateOptions) => Promise>; + delete: (type: string, id: string) => Promise<{}>; + // Warning: (ae-forgotten-export) The symbol "FindResults" needs to be exported by the entry point index.d.ts + find: (options?: SavedObjectsFindOptions) => Promise>; + get: (type: string, id: string) => Promise>; + // Warning: (ae-forgotten-export) The symbol "UpdateOptions" needs to be exported by the entry point index.d.ts + update(type: string, id: string, attributes: T, { version, migrationVersion, references }?: UpdateOptions): Promise>; +} + +// @public +export type SavedObjectsClientContract = PublicMethodsOf; + +// @public (undocumented) +export interface SavedObjectsStart { + // (undocumented) + client: SavedObjectsClientContract; +} + +// @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 index b55e58fd27bb8..6e0893c469efa 100644 --- a/src/core/public/saved_objects/index.ts +++ b/src/core/public/saved_objects/index.ts @@ -17,5 +17,6 @@ * under the License. */ -export { SavedObjectsClient } from './saved_objects_client'; +export { SavedObjectsClient, SavedObjectsClientContract } from './saved_objects_client'; export { SimpleSavedObject } from './simple_saved_object'; +export { SavedObjectsStart } from './saved_objects_service'; diff --git a/src/core/public/saved_objects/saved_objects_client.ts b/src/core/public/saved_objects/saved_objects_client.ts index 45b5d7e0efaf8..2c9c4f06f5f41 100644 --- a/src/core/public/saved_objects/saved_objects_client.ts +++ b/src/core/public/saved_objects/saved_objects_client.ts @@ -28,7 +28,6 @@ import { SavedObjectsFindOptions, SavedObjectsMigrationVersion, } from 'src/core/server'; -import { kfetch, KFetchQuery } from '../../../legacy/ui/public/kfetch'; import { keysToCamelCaseShallow, keysToSnakeCaseShallow, @@ -38,11 +37,12 @@ import { showAutoCreateIndexErrorPage, } from '../../../legacy/ui/public/error_auto_create_index/error_auto_create_index'; import { SimpleSavedObject } from './simple_saved_object'; +import { HttpFetchQuery, HttpSetup } from '../http'; interface RequestParams { method: 'POST' | 'GET' | 'PUT' | 'DELETE'; path: string; - query?: KFetchQuery; + query?: HttpFetchQuery; body?: object; } @@ -97,15 +97,23 @@ const BATCH_INTERVAL = 100; const API_BASE_URL = '/api/saved_objects/'; +/** + * SavedObjectsClientContract as implemented by the {@link SavedObjectsClient} + * + * @public + */ +export type SavedObjectsClientContract = PublicMethodsOf; + /** * The SavedObjectsClient class acts as a generic data fetcher * and data saver for saved objects regardless of type. * - * 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: HttpSetup; + private batchQueue: BatchQueueEntry[]; + /** * Throttled processing of get requests into bulk requests at 100ms interval */ @@ -138,9 +146,8 @@ export class SavedObjectsClient { { leading: false } ); - private batchQueue: BatchQueueEntry[]; - - constructor() { + constructor(http: HttpSetup) { + this.http = http; this.batchQueue = []; } @@ -199,9 +206,9 @@ 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: BulkCreateOptions[] = [], options: HttpFetchQuery = {}) => { const path = this.getPath(['_bulk_create']); - const query = pick(options, ['overwrite']) as Pick; + const query = pick(options, ['overwrite']) as Pick; const request: ReturnType = this.request({ method: 'POST', @@ -362,6 +369,6 @@ export class SavedObjectsClient { return Promise.reject(new Error('body not permitted for GET requests')); } - return kfetch({ method, pathname: path, query, body: JSON.stringify(body) }); + return this.http.fetch(path, { method, query, body: JSON.stringify(body) }); } } 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..e280ce69f8b71 --- /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..4130e866998b4 --- /dev/null +++ b/src/core/public/saved_objects/saved_objects_service.ts @@ -0,0 +1,37 @@ +/* + * 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 { SavedObjectsClient, SavedObjectsClientContract } from './saved_objects_client'; + +/** + * @public + */ +export interface SavedObjectsStart { + /** {@link SavedObjectsClient} */ + client: SavedObjectsClientContract; +} + +export const SavedObjectsService: CoreService = { + setup: async function setup() {}, + start: async function start(http) { + return { client: new SavedObjectsClient(http) }; + }, + stop: async function stop() {}, +}; diff --git a/src/core/public/saved_objects/simple_saved_object.ts b/src/core/public/saved_objects/simple_saved_object.ts index 26488bdeb1ab1..8c4702792425e 100644 --- a/src/core/public/saved_objects/simple_saved_object.ts +++ b/src/core/public/saved_objects/simple_saved_object.ts @@ -22,12 +22,13 @@ import { SavedObject as SavedObjectType, SavedObjectAttributes } from 'src/core/ 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/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/legacy/ui/public/chrome/api/saved_object_client.js b/src/legacy/ui/public/chrome/api/saved_object_client.ts similarity index 75% rename from src/legacy/ui/public/chrome/api/saved_object_client.js rename to src/legacy/ui/public/chrome/api/saved_object_client.ts index 3c9643556d9a9..b42e74e5a5865 100644 --- a/src/legacy/ui/public/chrome/api/saved_object_client.js +++ b/src/legacy/ui/public/chrome/api/saved_object_client.ts @@ -17,12 +17,13 @@ * under the License. */ -import { SavedObjectsClient } from '../../saved_objects'; +import { npStart } from 'ui/new_platform'; +import { Chrome } from '..'; -export function initSavedObjectClient(chrome) { - const savedObjectClient = new SavedObjectsClient(); +const savedObjectsClient = npStart.core.savedObjects.client; - chrome.getSavedObjectsClient = function () { - return savedObjectClient; +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/saved_objects/index.ts b/src/legacy/ui/public/saved_objects/index.ts index e2a1e2c342489..1a57c9a0acf96 100644 --- a/src/legacy/ui/public/saved_objects/index.ts +++ b/src/legacy/ui/public/saved_objects/index.ts @@ -17,7 +17,6 @@ * under the License. */ -export { SavedObjectsClient } from 'src/core/public'; export { SavedObjectRegistryProvider } from './saved_object_registry'; export { SavedObjectsClientProvider } from './saved_objects_client_provider'; // @ts-ignore From 4a2cdb4eadcf4dc4b8b586b70f2bd3fa38dc1619 Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Fri, 28 Jun 2019 12:54:11 +0200 Subject: [PATCH 03/29] Public SavedObjectsClient tests --- .../saved_objects_client.test.ts | 487 ++++++++++-------- .../saved_objects/saved_objects_client.ts | 1 + .../saved_objects/saved_objects_service.ts | 2 +- 3 files changed, 261 insertions(+), 229 deletions(-) diff --git a/src/core/public/saved_objects/saved_objects_client.test.ts b/src/core/public/saved_objects/saved_objects_client.test.ts index fed3b8807cddd..0cbf4c7150082 100644 --- a/src/core/public/saved_objects/saved_objects_client.test.ts +++ b/src/core/public/saved_objects/saved_objects_client.test.ts @@ -17,12 +17,11 @@ * 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'; +import { httpServiceMock } from '../http/http_service.mock'; describe('SavedObjectsClient', () => { const doc = { @@ -32,272 +31,272 @@ describe('SavedObjectsClient', () => { version: 'foo', }; - let kfetchStub: sinon.SinonStub; + const http = httpServiceMock.createStartContract(); let savedObjectsClient: SavedObjectsClient; + beforeEach(() => { - kfetchStub = sinon.stub(); - require('ui/kfetch').kfetch = async (...args: any[]) => { - return kfetchStub(...args); - }; - savedObjectsClient = new SavedObjectsClient(); + savedObjectsClient = new SavedObjectsClient(http); + http.fetch.mockClear(); }); 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] })); + http.fetch.mockResolvedValue({ saved_objects: [doc] }); }); - test('returns a promise', () => { - expect(savedObjectsClient.get('index-pattern', 'logstash-*')).toBeInstanceOf(Promise); + 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('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('rejects if `id` parameter is undefined', () => { + return expect( + savedObjectsClient.get('index-pattern', undefined as any) + ).rejects.toMatchInlineSnapshot(`[Error: 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 SimpleSavedObject instance', async () => { + const response = savedObjectsClient.get(doc.type, doc.id); + await expect(response).resolves.toBeInstanceOf(SimpleSavedObject); - 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'); + const result = await response; + expect(result.type).toBe('config'); + expect(result.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'); - } + expect(http.fetch.mock.calls[0]).toMatchInlineSnapshot(` +Array [ + "/api/saved_objects/_bulk_get", + Object { + "body": "[{\\"id\\":\\"AVwSwFxtcMV38qjDZoQg\\",\\"type\\":\\"config\\"}]", + "method": "POST", + "query": undefined, + }, +] +`); + }); + + 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]` + ); }); }); describe('#delete', () => { beforeEach(() => { - kfetchStub - .withArgs({ - method: 'DELETE', - pathname: `/api/saved_objects/index-pattern/logstash-*`, - query: undefined, - body: undefined, - }) - .returns(Promise.resolve({})); + http.fetch.mockResolvedValue({}); }); - test('returns a promise', () => { - expect(savedObjectsClient.delete('index-pattern', 'logstash-*')).toBeInstanceOf(Promise); + 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('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('throws if `id` parameter is undefined', async () => { + expect( + savedObjectsClient.delete('index-pattern', undefined as any) + ).rejects.toMatchInlineSnapshot(`[Error: 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); + 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 requireMessage = 'requires type, id and attributes'; + const attributes = { foo: 'Foo', bar: 'Bar' }; + const options = { version: '1' }; 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); + http.fetch.mockResolvedValue({ type: 'index-pattern', attributes }); }); - 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('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('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('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('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('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', () => { - 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), - }) + 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 requireMessage = 'requires type and attributes'; + const attributes = { foo: 'Foo', bar: 'Bar' }; 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({})); + http.fetch.mockResolvedValue({ id: 'serverId', type: 'server-type', attributes }); + }); - savedObjectsClient.create('index-pattern', attributes, { id: 'myId' }); + test('rejects if `type` is undefined', async () => { + await expect( + savedObjectsClient.create(undefined as any, undefined as any) + ).rejects.toMatchInlineSnapshot(`[Error: requires type and attributes]`); + }); - sinon.assert.calledOnce(kfetchStub); - sinon.assert.calledWithExactly( - kfetchStub, - sinon.match({ - pathname: path, - }) - ); + 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', () => { - const attributes = { foo: 'Foo', bar: 'Bar' }; + 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); - - sinon.assert.calledOnce(kfetchStub); - sinon.assert.calledWithExactly( - kfetchStub, - sinon.match({ - pathname: sinon.match.string, - body: JSON.stringify({ 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(() => { - kfetchStub - .withArgs({ - method: 'POST', - pathname: `/api/saved_objects/_bulk_create`, - query: sinon.match.any, - body: sinon.match.any, - }) - .returns(Promise.resolve({ saved_objects: [doc] })); + http.fetch.mockResolvedValue({ saved_objects: [doc] }); }); - test('returns a promise', () => { - expect(savedObjectsClient.bulkCreate([doc], {})).toBeInstanceOf(Promise); - }); + test('resolves with array of SimpleSavedObject instances', async () => { + const response = savedObjectsClient.bulkCreate([doc]); + await expect(response).resolves.toHaveProperty('savedObjects'); - 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); + const result = await response; + expect(result.savedObjects).toHaveLength(1); + expect(result.savedObjects[0]).toBeInstanceOf(SimpleSavedObject); }); test('makes HTTP call', async () => { - await savedObjectsClient.bulkCreate([doc], {}); - sinon.assert.calledOnce(kfetchStub); + 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 {}, + }, + ], +] +`); + }); + + 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, + }, + }, + ], +] +`); }); }); @@ -305,53 +304,85 @@ describe('SavedObjectsClient', () => { const object = { id: 'logstash-*', type: 'index-pattern', title: 'Test' }; beforeEach(() => { - kfetchStub.returns(Promise.resolve({ saved_objects: [object] })); + http.fetch.mockResolvedValue({ saved_objects: [object], page: 0, perPage: 1, total: 1 }); }); - test('returns a promise', () => { - expect(savedObjectsClient.find()).toBeInstanceOf(Promise); + test('resolves with instances of SimpleSavedObjects', async () => { + const body = { type: 'index-pattern' }; + const resultP = savedObjectsClient.find(body); + 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('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 }, - }) - ); + expect(http.fetch.mock.calls).toMatchInlineSnapshot(` +Array [ + Array [ + "/api/saved_objects/_find", + Object { + "body": undefined, + "method": "GET", + "query": Object { + "invalid": true, + "type": "index-pattern", + }, + }, + ], +] +`); }); 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'] }, - }) - ); + expect(http.fetch.mock.calls).toMatchInlineSnapshot(` +Array [ + Array [ + "/api/saved_objects/_find", + Object { + "body": undefined, + "method": "GET", + "query": Object { + "fields": Array [ + "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 }, - }) - ); + expect(http.fetch.mock.calls).toMatchInlineSnapshot(` +Array [ + Array [ + "/api/saved_objects/_find", + Object { + "body": undefined, + "method": "GET", + "query": Object { + "page": 6, + "per_page": 10, + }, + }, + ], +] +`); }); }); }); diff --git a/src/core/public/saved_objects/saved_objects_client.ts b/src/core/public/saved_objects/saved_objects_client.ts index 2c9c4f06f5f41..3abc2a37859c5 100644 --- a/src/core/public/saved_objects/saved_objects_client.ts +++ b/src/core/public/saved_objects/saved_objects_client.ts @@ -207,6 +207,7 @@ export class SavedObjectsClient { * @returns The result of the create operation containing created saved objects. */ public bulkCreate = (objects: BulkCreateOptions[] = [], options: HttpFetchQuery = {}) => { + // TODO better options type const path = this.getPath(['_bulk_create']); const query = pick(options, ['overwrite']) as Pick; diff --git a/src/core/public/saved_objects/saved_objects_service.ts b/src/core/public/saved_objects/saved_objects_service.ts index 4130e866998b4..33e2796f52d87 100644 --- a/src/core/public/saved_objects/saved_objects_service.ts +++ b/src/core/public/saved_objects/saved_objects_service.ts @@ -30,7 +30,7 @@ export interface SavedObjectsStart { export const SavedObjectsService: CoreService = { setup: async function setup() {}, - start: async function start(http) { + start: async function start({ http }) { return { client: new SavedObjectsClient(http) }; }, stop: async function stop() {}, From 228715f092ba57b8653a54bccfa57e78c921a24b Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Fri, 28 Jun 2019 13:58:39 +0200 Subject: [PATCH 04/29] Import SimpleSavedObject from src/core/public --- .../public/discover/__tests__/directives/field_chooser.js | 2 +- .../ui/public/saved_objects/__tests__/find_object_by_title.js | 2 +- .../ui/public/saved_objects/__tests__/simple_saved_object.js | 2 +- src/legacy/ui/public/saved_objects/index.ts | 1 - 4 files changed, 3 insertions(+), 4 deletions(-) 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/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/index.ts b/src/legacy/ui/public/saved_objects/index.ts index 1a57c9a0acf96..8076213f62e9a 100644 --- a/src/legacy/ui/public/saved_objects/index.ts +++ b/src/legacy/ui/public/saved_objects/index.ts @@ -21,5 +21,4 @@ export { SavedObjectRegistryProvider } from './saved_object_registry'; export { SavedObjectsClientProvider } from './saved_objects_client_provider'; // @ts-ignore export { SavedObjectLoader } from './saved_object_loader'; -export { SimpleSavedObject } from 'src/core/public'; export { findObjectByTitle } from './find_object_by_title'; From dbffac249d2f01b35430ae94a49739a96d75d7db Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Mon, 1 Jul 2019 16:27:02 +0200 Subject: [PATCH 05/29] Use types from source files for kibana.d.ts --- kibana.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 }; From ed45d7a253d6dfe915a39092b89419dcc728b125 Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Tue, 2 Jul 2019 12:58:05 +0200 Subject: [PATCH 06/29] Add html raw loader to x-pack/jest --- x-pack/dev-tools/jest/create_jest_config.js | 1 + 1 file changed, 1 insertion(+) diff --git a/x-pack/dev-tools/jest/create_jest_config.js b/x-pack/dev-tools/jest/create_jest_config.js index fa8cae2b6b86e..006e5c1d31243 100644 --- a/x-pack/dev-tools/jest/create_jest_config.js +++ b/x-pack/dev-tools/jest/create_jest_config.js @@ -46,6 +46,7 @@ export function createJestConfig({ ], 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() From bf96e602e87f8d7e29c57f6914f14db504c1bcf7 Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Tue, 2 Jul 2019 13:56:49 +0200 Subject: [PATCH 07/29] Cleanup --- src/core/public/mocks.ts | 2 ++ src/core/public/saved_objects/saved_objects_client.test.ts | 1 - src/core/public/saved_objects/saved_objects_client.ts | 7 ++++--- .../public/embeddable/dashboard_container_factory.ts | 2 +- .../kibana/public/dashboard/migrations/migrations_730.ts | 2 +- 5 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/core/public/mocks.ts b/src/core/public/mocks.ts index b1312eaa228d2..7d16c303329a9 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'; export { chromeServiceMock } from './chrome/chrome_service.mock'; export { docLinksServiceMock } from './doc_links/doc_links_service.mock'; @@ -59,6 +60,7 @@ function createCoreStartMock() { notifications: notificationServiceMock.createStartContract(), overlays: overlayServiceMock.createStartContract(), uiSettings: uiSettingsServiceMock.createStartContract(), + savedObjects: savedObjectsMock.createStartContract(), }; return mock; diff --git a/src/core/public/saved_objects/saved_objects_client.test.ts b/src/core/public/saved_objects/saved_objects_client.test.ts index 0cbf4c7150082..698ba7ab048a1 100644 --- a/src/core/public/saved_objects/saved_objects_client.test.ts +++ b/src/core/public/saved_objects/saved_objects_client.test.ts @@ -17,7 +17,6 @@ * under the License. */ -import * as sinon from 'sinon'; import { SavedObjectsFindOptions } from 'src/core/server'; import { SavedObjectsClient } from './saved_objects_client'; import { SimpleSavedObject } from './simple_saved_object'; diff --git a/src/core/public/saved_objects/saved_objects_client.ts b/src/core/public/saved_objects/saved_objects_client.ts index 3abc2a37859c5..f3261597b6591 100644 --- a/src/core/public/saved_objects/saved_objects_client.ts +++ b/src/core/public/saved_objects/saved_objects_client.ts @@ -31,7 +31,7 @@ import { import { keysToCamelCaseShallow, keysToSnakeCaseShallow, -} from '../../../legacy/ui/public/utils/case_conversion'; +} from '../../../legacy/utils/case_conversion'; import { isAutoCreateIndexError, showAutoCreateIndexErrorPage, @@ -105,8 +105,9 @@ const API_BASE_URL = '/api/saved_objects/'; export type SavedObjectsClientContract = PublicMethodsOf; /** - * The SavedObjectsClient class acts as a generic data fetcher - * and data saver for saved objects regardless of type. + * Saved Objects is Kibana's data persisentence mechanism allowing plugins to + * use Elasticsearch for storing plugin state. The SavedObjectsClient is a thin + * "repository" for client-side plugins to interact with Saved Objects. * * @public */ 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/kibana/public/dashboard/migrations/migrations_730.ts b/src/legacy/core_plugins/kibana/public/dashboard/migrations/migrations_730.ts index ee28643f36446..a497a7ff44bd5 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 { Logger } from 'src/core/server/saved_objects/migrations/core/migration_logger'; import { DashboardDoc730ToLatest, DashboardDoc700To720 } from './types'; import { isDashboardDoc } from './is_dashboard_doc'; import { moveFiltersToQuery } from './move_filters_to_query'; From 411aeb3a2d243935d82c12c186e56957eb5f1b43 Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Tue, 2 Jul 2019 16:22:05 +0200 Subject: [PATCH 08/29] Drop case utilities and improve test coverage --- .../saved_objects_client.test.ts | 117 +++++++++++------- .../saved_objects/saved_objects_client.ts | 50 ++++++-- 2 files changed, 111 insertions(+), 56 deletions(-) diff --git a/src/core/public/saved_objects/saved_objects_client.test.ts b/src/core/public/saved_objects/saved_objects_client.test.ts index 698ba7ab048a1..d4914999ab96d 100644 --- a/src/core/public/saved_objects/saved_objects_client.test.ts +++ b/src/core/public/saved_objects/saved_objects_client.test.ts @@ -17,7 +17,6 @@ * under the License. */ -import { SavedObjectsFindOptions } from 'src/core/server'; import { SavedObjectsClient } from './saved_objects_client'; import { SimpleSavedObject } from './simple_saved_object'; import { httpServiceMock } from '../http/http_service.mock'; @@ -55,13 +54,11 @@ describe('SavedObjectsClient', () => { ).rejects.toMatchInlineSnapshot(`[Error: requires type and id]`); }); - 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'); + 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 () => { @@ -78,11 +75,35 @@ Array [ `); }); - 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('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'); }); }); @@ -273,7 +294,9 @@ Array [ Object { "body": "[{\\"id\\":\\"AVwSwFxtcMV38qjDZoQg\\",\\"type\\":\\"config\\",\\"attributes\\":{\\"title\\":\\"Example title\\"},\\"version\\":\\"foo\\"}]", "method": "POST", - "query": Object {}, + "query": Object { + "overwrite": false, + }, }, ], ] @@ -303,12 +326,12 @@ Array [ const object = { id: 'logstash-*', type: 'index-pattern', title: 'Test' }; beforeEach(() => { - http.fetch.mockResolvedValue({ saved_objects: [object], page: 0, perPage: 1, total: 1 }); + http.fetch.mockResolvedValue({ saved_objects: [object], page: 0, per_page: 1, total: 1 }); }); test('resolves with instances of SimpleSavedObjects', async () => { - const body = { type: 'index-pattern' }; - const resultP = savedObjectsClient.find(body); + const options = { type: 'index-pattern' }; + const resultP = savedObjectsClient.find(options); await expect(resultP).resolves.toHaveProperty('savedObjects'); const result = await resultP; @@ -319,31 +342,18 @@ Array [ expect(result.total).toBe(1); }); - test('accepts type', () => { - const body = { type: 'index-pattern', invalid: true }; + test('makes HTTP call translating options into snake case query parameters', () => { + const options = { + type: 'index-pattern', + search: 'what is the meaning of life?|life', + searchFields: ['title^5', 'body'], + page: 10, + perPage: 100, + fields: ['title'], + hasReference: { id: '1', type: 'reference' }, + }; - savedObjectsClient.find(body); - expect(http.fetch.mock.calls).toMatchInlineSnapshot(` -Array [ - Array [ - "/api/saved_objects/_find", - Object { - "body": undefined, - "method": "GET", - "query": Object { - "invalid": true, - "type": "index-pattern", - }, - }, - ], -] -`); - }); - - test('accepts fields', () => { - const body = { fields: ['title', 'description'] }; - - savedObjectsClient.find(body); + savedObjectsClient.find(options); expect(http.fetch.mock.calls).toMatchInlineSnapshot(` Array [ Array [ @@ -354,8 +364,19 @@ Array [ "query": Object { "fields": Array [ "title", - "description", ], + "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", + ], + "type": "index-pattern", }, }, ], @@ -363,9 +384,12 @@ Array [ `); }); - test('accepts pagination params', () => { - const options: SavedObjectsFindOptions = { perPage: 10, page: 6 }; + test('ignores invalid options', () => { + const options = { + invalid: true, + }; + // @ts-ignore savedObjectsClient.find(options); expect(http.fetch.mock.calls).toMatchInlineSnapshot(` Array [ @@ -374,10 +398,7 @@ Array [ Object { "body": undefined, "method": "GET", - "query": Object { - "page": 6, - "per_page": 10, - }, + "query": Object {}, }, ], ] diff --git a/src/core/public/saved_objects/saved_objects_client.ts b/src/core/public/saved_objects/saved_objects_client.ts index f3261597b6591..6fbf66e8694c1 100644 --- a/src/core/public/saved_objects/saved_objects_client.ts +++ b/src/core/public/saved_objects/saved_objects_client.ts @@ -28,10 +28,6 @@ import { SavedObjectsFindOptions, SavedObjectsMigrationVersion, } from 'src/core/server'; -import { - keysToCamelCaseShallow, - keysToSnakeCaseShallow, -} from '../../../legacy/utils/case_conversion'; import { isAutoCreateIndexError, showAutoCreateIndexErrorPage, @@ -220,7 +216,7 @@ export class SavedObjectsClient { }); return request.then(resp => { resp.saved_objects = resp.saved_objects.map(d => this.createSavedObject(d)); - return keysToCamelCaseShallow(resp) as BatchResponse; + return renameKeys({ saved_objects: 'savedObjects' }, resp) as BatchResponse; }); }; @@ -257,7 +253,18 @@ export class SavedObjectsClient { options: SavedObjectsFindOptions = {} ): Promise> => { const path = this.getPath(['_find']); - const query = keysToSnakeCaseShallow(options); + const query = renameKeys( + { + type: 'type', + search: 'search', + searchFields: 'search_fields', + page: 'page', + perPage: 'per_page', + fields: 'fields', + hasReference: 'has_reference', + }, + options + ); const request: ReturnType = this.request({ method: 'GET', @@ -266,7 +273,15 @@ export class SavedObjectsClient { }); return request.then(resp => { resp.saved_objects = resp.saved_objects.map(d => this.createSavedObject(d)); - return keysToCamelCaseShallow(resp) as FindResults; + return renameKeys( + { + saved_objects: 'savedObjects', + total: 'total', + per_page: 'perPage', + page: 'page', + }, + resp + ) as FindResults; }); }; @@ -314,7 +329,7 @@ export class SavedObjectsClient { }); return request.then(resp => { resp.saved_objects = resp.saved_objects.map(d => this.createSavedObject(d)); - return keysToCamelCaseShallow(resp) as BatchResponse; + return renameKeys({ saved_objects: 'savedObjects' }, resp) as BatchResponse; }); }; @@ -374,3 +389,22 @@ export class SavedObjectsClient { return this.http.fetch(path, { method, query, body: JSON.stringify(body) }); } } + +/** + * Returns a new object with the own properties of `obj`, but the + * keys renamed according to the `keysMap`. + * + * If a key is not found in `keysMap` it is omitted from the result. + * + * @param keysMap - a map of the form `{oldKey: newKey}` + * @param obj - the object whose own properties will be renamed + */ +const renameKeys = (keysMap: Record, obj: Record) => + Object.keys(obj).reduce((acc, key) => { + return typeof keysMap[key] === 'undefined' + ? acc + : { + ...acc, + ...{ [keysMap[key]]: obj[key] }, + }; + }, {}); From 5623353a85e6357844b4b5fb34d4b849b90b2264 Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Thu, 4 Jul 2019 12:01:26 +0200 Subject: [PATCH 09/29] Update types and documentation --- .../core/public/kibana-plugin-public.md | 15 +- ...na-plugin-public.savedobject.attributes.md | 11 + .../kibana-plugin-public.savedobject.error.md | 14 ++ .../kibana-plugin-public.savedobject.id.md | 11 + .../kibana-plugin-public.savedobject.md | 26 +++ ...gin-public.savedobject.migrationversion.md | 11 + ...na-plugin-public.savedobject.references.md | 11 + .../kibana-plugin-public.savedobject.type.md | 11 + ...na-plugin-public.savedobject.updated_at.md | 11 + ...ibana-plugin-public.savedobject.version.md | 11 + ...bana-plugin-public.savedobjectattribute.md | 12 ++ ...ana-plugin-public.savedobjectattributes.md | 12 ++ ...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 | 2 +- ...lugin-public.savedobjectsclient.bulkget.md | 2 +- ...plugin-public.savedobjectsclient.create.md | 2 +- ...a-plugin-public.savedobjectsclient.find.md | 2 +- ...kibana-plugin-public.savedobjectsclient.md | 10 +- ...plugin-public.savedobjectsclient.update.md | 4 +- ...gin-public.savedobjectscreateoptions.id.md | 13 ++ ...plugin-public.savedobjectscreateoptions.md | 22 ++ ...edobjectscreateoptions.migrationversion.md | 11 + ...lic.savedobjectscreateoptions.overwrite.md | 13 ++ ...ic.savedobjectscreateoptions.references.md | 11 + ...bjectsfindoptions.defaultsearchoperator.md | 11 + ...n-public.savedobjectsfindoptions.fields.md | 11 + ...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 | 11 + ...ic.savedobjectsfindoptions.searchfields.md | 13 ++ ...ublic.savedobjectsfindoptions.sortfield.md | 11 + ...ublic.savedobjectsfindoptions.sortorder.md | 11 + ...gin-public.savedobjectsfindoptions.type.md | 11 + ...-plugin-public.savedobjectsfindresponse.md | 21 ++ ...in-public.savedobjectsfindresponse.page.md | 11 + ...public.savedobjectsfindresponse.perpage.md | 11 + ...n-public.savedobjectsfindresponse.total.md | 11 + ...gin-public.savedobjectsmigrationversion.md | 25 +++ ...plugin-public.savedobjectsupdateoptions.md | 21 ++ ...edobjectsupdateoptions.migrationversion.md | 11 + ...ic.savedobjectsupdateoptions.references.md | 11 + ...ublic.savedobjectsupdateoptions.version.md | 11 + .../core/server/kibana-plugin-server.md | 5 +- ...bana-plugin-server.savedobjectattribute.md | 12 ++ ...lugin-server.savedobjectsclientcontract.md | 2 + ...gin-server.savedobjectsmigrationversion.md | 14 +- src/core/public/index.ts | 24 ++- src/core/public/public.api.md | 148 ++++++++++++-- src/core/public/saved_objects/index.ts | 18 +- .../saved_objects/saved_objects_client.ts | 84 +++++--- .../saved_objects/simple_saved_object.ts | 2 +- src/core/server/index.ts | 18 +- .../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 | 2 +- .../import/import_saved_objects.test.ts | 2 +- .../import/import_saved_objects.ts | 2 +- .../import/resolve_import_errors.test.ts | 2 +- .../import/resolve_import_errors.ts | 2 +- .../saved_objects/import/split_overwrites.ts | 2 +- .../import/validate_references.ts | 2 +- .../saved_objects/management/management.ts | 2 +- .../migrations/core/document_migrator.ts | 2 +- .../migrations/core/elastic_index.ts | 2 +- .../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 | 165 +-------------- src/core/server/saved_objects/types.ts | 190 ++++++++++++++++++ src/core/server/server.api.md | 5 +- src/core/server/types.ts | 20 ++ .../add_panel/add_panel_flyout.tsx | 3 +- 92 files changed, 1221 insertions(+), 258 deletions(-) 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.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.savedobjectsfindresponse.md create mode 100644 docs/development/core/public/kibana-plugin-public.savedobjectsfindresponse.page.md create mode 100644 docs/development/core/public/kibana-plugin-public.savedobjectsfindresponse.perpage.md create mode 100644 docs/development/core/public/kibana-plugin-public.savedobjectsfindresponse.total.md create mode 100644 docs/development/core/public/kibana-plugin-public.savedobjectsmigrationversion.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/server/kibana-plugin-server.savedobjectattribute.md create mode 100644 src/core/server/saved_objects/types.ts create mode 100644 src/core/server/types.ts diff --git a/docs/development/core/public/kibana-plugin-public.md b/docs/development/core/public/kibana-plugin-public.md index ce4daabc75477..b0f0ceb213030 100644 --- a/docs/development/core/public/kibana-plugin-public.md +++ b/docs/development/core/public/kibana-plugin-public.md @@ -14,7 +14,7 @@ The plugin integrates with the core system via lifecycle events: `setup` | Class | Description | | --- | --- | -| [SavedObjectsClient](./kibana-plugin-public.savedobjectsclient.md) | The SavedObjectsClient class acts as a generic data fetcher and data saver for saved objects regardless of type. | +| [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) | | @@ -53,7 +53,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) | | +| [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) | | +| [SavedObjectsFindResponse](./kibana-plugin-public.savedobjectsfindresponse.md) | | +| [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 @@ -66,6 +78,7 @@ The plugin integrates with the core system via lifecycle events: `setup` | [HttpStart](./kibana-plugin-public.httpstart.md) | | | [PluginInitializer](./kibana-plugin-public.plugininitializer.md) | The plugin export at the root of a plugin's public directory should conform to this interface. | | [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..8f6539149f4de --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobject.attributes.md @@ -0,0 +1,11 @@ + + +[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 + +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..443f0e084cfea --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobject.id.md @@ -0,0 +1,11 @@ + + +[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 + +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..8bbec643247b0 --- /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 | | +| [error](./kibana-plugin-public.savedobject.error.md) | {
message: string;
statusCode: number;
} | | +| [id](./kibana-plugin-public.savedobject.id.md) | string | | +| [migrationVersion](./kibana-plugin-public.savedobject.migrationversion.md) | SavedObjectsMigrationVersion | | +| [references](./kibana-plugin-public.savedobject.references.md) | SavedObjectReference[] | | +| [type](./kibana-plugin-public.savedobject.type.md) | string | | +| [updated\_at](./kibana-plugin-public.savedobject.updated_at.md) | string | | +| [version](./kibana-plugin-public.savedobject.version.md) | string | | + 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..f4e58b9feb233 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobject.migrationversion.md @@ -0,0 +1,11 @@ + + +[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 + +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..8ce965274637b --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobject.references.md @@ -0,0 +1,11 @@ + + +[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 + +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..c62698574efc8 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobject.type.md @@ -0,0 +1,11 @@ + + +[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 + +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..714bae575af1e --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobject.updated_at.md @@ -0,0 +1,11 @@ + + +[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 + +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..34f09d03037ad --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobject.version.md @@ -0,0 +1,11 @@ + + +[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 + +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..6b8cc20888559 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobjectattributes.md @@ -0,0 +1,12 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObjectAttributes](./kibana-plugin-public.savedobjectattributes.md) + +## SavedObjectAttributes interface + + +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 index 43c532270ab2a..426096d96c9ba 100644 --- a/docs/development/core/public/kibana-plugin-public.savedobjectsclient.bulkcreate.md +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsclient.bulkcreate.md @@ -9,5 +9,5 @@ Creates multiple documents at once Signature: ```typescript -bulkCreate: (objects?: BulkCreateOptions[], options?: HttpFetchQuery) => Promise>; +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 index 8ccee3eb3ca8f..fc8b3c8258f9c 100644 --- a/docs/development/core/public/kibana-plugin-public.savedobjectsclient.bulkget.md +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsclient.bulkget.md @@ -12,7 +12,7 @@ Returns an array of objects by id bulkGet: (objects?: { id: string; type: string; - }[]) => Promise>; + }[]) => Promise>; ``` ## Example diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsclient.create.md b/docs/development/core/public/kibana-plugin-public.savedobjectsclient.create.md index ae3598ae1f46d..d6366494f0037 100644 --- a/docs/development/core/public/kibana-plugin-public.savedobjectsclient.create.md +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsclient.create.md @@ -9,5 +9,5 @@ Persists an object Signature: ```typescript -create: (type: string, attributes: T, options?: CreateOptions) => Promise>; +create: (type: string, attributes: T, options?: SavedObjectsCreateOptions) => 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 index 8091711cacb8f..c78d9067eda3e 100644 --- a/docs/development/core/public/kibana-plugin-public.savedobjectsclient.find.md +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsclient.find.md @@ -9,5 +9,5 @@ Search for objects Signature: ```typescript -find: (options?: SavedObjectsFindOptions) => Promise>; +find: (options?: SavedObjectsFindOptions) => Promise>; ``` diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsclient.md b/docs/development/core/public/kibana-plugin-public.savedobjectsclient.md index dc922ec74fe8b..094261389fa35 100644 --- a/docs/development/core/public/kibana-plugin-public.savedobjectsclient.md +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsclient.md @@ -4,7 +4,7 @@ ## SavedObjectsClient class -The SavedObjectsClient class acts as a generic data fetcher and data saver for saved objects regardless of type. +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: @@ -22,11 +22,11 @@ export declare class SavedObjectsClient | Property | Modifiers | Type | Description | | --- | --- | --- | --- | -| [bulkCreate](./kibana-plugin-public.savedobjectsclient.bulkcreate.md) | | (objects?: BulkCreateOptions<SavedObjectAttributes>[], options?: HttpFetchQuery) => Promise<BatchResponse<SavedObjectAttributes>> | Creates multiple documents at once | -| [bulkGet](./kibana-plugin-public.savedobjectsclient.bulkget.md) | | (objects?: {
id: string;
type: string;
}[]) => Promise<BatchResponse<SavedObjectAttributes>> | Returns an array of objects by id | -| [create](./kibana-plugin-public.savedobjectsclient.create.md) | | <T extends SavedObjectAttributes>(type: string, attributes: T, options?: CreateOptions) => Promise<SimpleSavedObject<T>> | Persists an object | +| [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?: SavedObjectsFindOptions) => Promise<FindResults<T>> | Search for objects | +| [find](./kibana-plugin-public.savedobjectsclient.find.md) | | <T extends SavedObjectAttributes>(options?: SavedObjectsFindOptions) => Promise<SavedObjectsFindResponse<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 diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsclient.update.md b/docs/development/core/public/kibana-plugin-public.savedobjectsclient.update.md index f1ec383628020..5f87f46d6206f 100644 --- a/docs/development/core/public/kibana-plugin-public.savedobjectsclient.update.md +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsclient.update.md @@ -9,7 +9,7 @@ Updates an object Signature: ```typescript -update(type: string, id: string, attributes: T, { version, migrationVersion, references }?: UpdateOptions): Promise>; +update(type: string, id: string, attributes: T, { version, migrationVersion, references }?: SavedObjectsUpdateOptions): Promise>; ``` ## Parameters @@ -19,7 +19,7 @@ update(type: string, id: string, attributes: T, | type | string | | | id | string | | | attributes | T | | -| { version, migrationVersion, references } | UpdateOptions | | +| { version, migrationVersion, references } | SavedObjectsUpdateOptions | | Returns: 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..99d186dd294a6 --- /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 | | +| [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..c56b4b615e419 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobjectscreateoptions.migrationversion.md @@ -0,0 +1,11 @@ + + +[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 + +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..3e32a173e9d4a --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsfindoptions.fields.md @@ -0,0 +1,11 @@ + + +[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 + +Signature: + +```typescript +fields?: string[]; +``` 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..3418bb429c8e4 --- /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[] | | +| [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 | | +| [searchFields](./kibana-plugin-public.savedobjectsfindoptions.searchfields.md) | string[] | see Elasticsearch Simple Query String Query field 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..2b5866237c267 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsfindoptions.search.md @@ -0,0 +1,11 @@ + + +[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 + +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..41c62cca58c38 --- /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 + +see Elasticsearch Simple Query String Query field 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.savedobjectsfindresponse.md b/docs/development/core/public/kibana-plugin-public.savedobjectsfindresponse.md new file mode 100644 index 0000000000000..548c9ed3b05b9 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsfindresponse.md @@ -0,0 +1,21 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObjectsFindResponse](./kibana-plugin-public.savedobjectsfindresponse.md) + +## SavedObjectsFindResponse interface + + +Signature: + +```typescript +export interface SavedObjectsFindResponse extends SavedObjectsBatchResponse +``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [page](./kibana-plugin-public.savedobjectsfindresponse.page.md) | number | | +| [perPage](./kibana-plugin-public.savedobjectsfindresponse.perpage.md) | number | | +| [total](./kibana-plugin-public.savedobjectsfindresponse.total.md) | number | | + diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsfindresponse.page.md b/docs/development/core/public/kibana-plugin-public.savedobjectsfindresponse.page.md new file mode 100644 index 0000000000000..ce02d6c8c499f --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsfindresponse.page.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObjectsFindResponse](./kibana-plugin-public.savedobjectsfindresponse.md) > [page](./kibana-plugin-public.savedobjectsfindresponse.page.md) + +## SavedObjectsFindResponse.page property + +Signature: + +```typescript +page: number; +``` diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsfindresponse.perpage.md b/docs/development/core/public/kibana-plugin-public.savedobjectsfindresponse.perpage.md new file mode 100644 index 0000000000000..5cc6d1ca4903a --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsfindresponse.perpage.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObjectsFindResponse](./kibana-plugin-public.savedobjectsfindresponse.md) > [perPage](./kibana-plugin-public.savedobjectsfindresponse.perpage.md) + +## SavedObjectsFindResponse.perPage property + +Signature: + +```typescript +perPage: number; +``` diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsfindresponse.total.md b/docs/development/core/public/kibana-plugin-public.savedobjectsfindresponse.total.md new file mode 100644 index 0000000000000..67afdfaf4a734 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsfindresponse.total.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObjectsFindResponse](./kibana-plugin-public.savedobjectsfindresponse.md) > [total](./kibana-plugin-public.savedobjectsfindresponse.total.md) + +## SavedObjectsFindResponse.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..d901d65591ee3 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsmigrationversion.md @@ -0,0 +1,25 @@ + + +[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.savedobjectsupdateoptions.md b/docs/development/core/public/kibana-plugin-public.savedobjectsupdateoptions.md new file mode 100644 index 0000000000000..d555e927eecc1 --- /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 | | +| [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..dee541c9ca758 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsupdateoptions.migrationversion.md @@ -0,0 +1,11 @@ + + +[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 + +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/server/kibana-plugin-server.md b/docs/development/core/server/kibana-plugin-server.md index ab79f2b382909..7250c7a3e54f7 100644 --- a/docs/development/core/server/kibana-plugin-server.md +++ b/docs/development/core/server/kibana-plugin-server.md @@ -59,7 +59,7 @@ The plugin integrates with the core system via lifecycle events: `setup` | [SavedObjectsCreateOptions](./kibana-plugin-server.savedobjectscreateoptions.md) | | | [SavedObjectsFindOptions](./kibana-plugin-server.savedobjectsfindoptions.md) | | | [SavedObjectsFindResponse](./kibana-plugin-server.savedobjectsfindresponse.md) | | -| [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. | +| [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. | | [SavedObjectsService](./kibana-plugin-server.savedobjectsservice.md) | | | [SavedObjectsUpdateOptions](./kibana-plugin-server.savedobjectsupdateoptions.md) | | | [SavedObjectsUpdateResponse](./kibana-plugin-server.savedobjectsupdateresponse.md) | | @@ -83,6 +83,7 @@ The plugin integrates with the core system via lifecycle events: `setup` | [PluginName](./kibana-plugin-server.pluginname.md) | Dedicated type for plugin name/id that is supposed to make Map/Set/Arrays that use it as a key or value more obvious. | | [RecursiveReadonly](./kibana-plugin-server.recursivereadonly.md) | | | [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) | | 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.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.savedobjectsmigrationversion.md b/docs/development/core/server/kibana-plugin-server.savedobjectsmigrationversion.md index 434e46041cf7d..a7f652e4348bf 100644 --- a/docs/development/core/server/kibana-plugin-server.savedobjectsmigrationversion.md +++ b/docs/development/core/server/kibana-plugin-server.savedobjectsmigrationversion.md @@ -4,10 +4,22 @@ ## 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/src/core/public/index.ts b/src/core/public/index.ts index 26bdf4872eca2..7a5be9f12d3cd 100644 --- a/src/core/public/index.ts +++ b/src/core/public/index.ts @@ -66,11 +66,28 @@ import { Plugin, PluginInitializer, PluginInitializerContext } from './plugins'; import { UiSettingsClient, UiSettingsState, UiSettingsClientContract } from './ui_settings'; import { ApplicationSetup, Capabilities, ApplicationStart } from './application'; import { DocLinksStart } from './doc_links'; -import { SavedObjectsClient, SimpleSavedObject, SavedObjectsClientContract } from './saved_objects'; -import { SavedObjectsStart } from './saved_objects/saved_objects_service'; +import { SavedObjectsStart } from './saved_objects'; export { CoreContext, CoreSystem } from './core_system'; export { RecursiveReadonly } from '../utils'; +export { + SavedObjectsBatchResponse, + SavedObjectsBulkCreateObject, + SavedObjectsBulkCreateOptions, + SavedObjectsCreateOptions, + SavedObjectsFindResponse, + SavedObjectsUpdateOptions, + SavedObject, + SavedObjectAttribute, + SavedObjectAttributes, + SavedObjectReference, + SavedObjectsBaseOptions, + SavedObjectsFindOptions, + SavedObjectsMigrationVersion, + SavedObjectsClientContract, + SavedObjectsClient, + SimpleSavedObject, +} from './saved_objects'; /** * Core services exposed to the `Plugin` setup lifecycle @@ -168,10 +185,7 @@ export { Plugin, PluginInitializer, PluginInitializerContext, - SavedObjectsClient, - SavedObjectsClientContract, SavedObjectsStart, - SimpleSavedObject, Toast, ToastInput, ToastsApi, diff --git a/src/core/public/public.api.md b/src/core/public/public.api.md index 1ccae57ea2fa8..21edf446560ef 100644 --- a/src/core/public/public.api.md +++ b/src/core/public/public.api.md @@ -8,11 +8,6 @@ import { IconType } from '@elastic/eui'; import { Observable } from 'rxjs'; import React from 'react'; import * as Rx from 'rxjs'; -import { SavedObject } from 'src/core/server'; -import { SavedObjectAttributes } from 'src/core/server'; -import { SavedObjectReference } from 'src/core/server'; -import { SavedObjectsFindOptions } from 'src/core/server'; -import { SavedObjectsMigrationVersion } from 'src/core/server'; import { EuiGlobalToastListToast as Toast } from '@elastic/eui'; // @public (undocumented) @@ -511,35 +506,158 @@ export type RecursiveReadonly = T extends (...args: any[]) => any ? T : T ext [K in keyof T]: RecursiveReadonly; }> : T; +// @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 (undocumented) +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 { constructor(http: HttpSetup); - // Warning: (ae-forgotten-export) The symbol "BulkCreateOptions" needs to be exported by the entry point index.d.ts - // Warning: (ae-forgotten-export) The symbol "BatchResponse" needs to be exported by the entry point index.d.ts - bulkCreate: (objects?: BulkCreateOptions[], options?: HttpFetchQuery) => Promise>; + bulkCreate: (objects?: SavedObjectsBulkCreateObject[], options?: SavedObjectsBulkCreateOptions) => Promise>; bulkGet: (objects?: { id: string; type: string; - }[]) => Promise>; - // Warning: (ae-forgotten-export) The symbol "CreateOptions" needs to be exported by the entry point index.d.ts - create: (type: string, attributes: T, options?: CreateOptions) => Promise>; + }[]) => Promise>; + create: (type: string, attributes: T, options?: SavedObjectsCreateOptions) => Promise>; delete: (type: string, id: string) => Promise<{}>; - // Warning: (ae-forgotten-export) The symbol "FindResults" needs to be exported by the entry point index.d.ts - find: (options?: SavedObjectsFindOptions) => Promise>; + find: (options?: SavedObjectsFindOptions) => Promise>; get: (type: string, id: string) => Promise>; - // Warning: (ae-forgotten-export) The symbol "UpdateOptions" needs to be exported by the entry point index.d.ts - update(type: string, id: string, attributes: T, { version, migrationVersion, references }?: UpdateOptions): 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; + // (undocumented) + migrationVersion?: SavedObjectsMigrationVersion; + overwrite?: boolean; + // (undocumented) + references?: SavedObjectReference[]; +} + +// @public (undocumented) +export interface SavedObjectsFindOptions extends SavedObjectsBaseOptions { + // (undocumented) + defaultSearchOperator?: 'AND' | 'OR'; + // (undocumented) + fields?: string[]; + // (undocumented) + hasReference?: { + type: string; + id: string; + }; + // (undocumented) + page?: number; + // (undocumented) + perPage?: number; + // (undocumented) + search?: string; + searchFields?: string[]; + // (undocumented) + sortField?: string; + // (undocumented) + sortOrder?: string; + // (undocumented) + type?: string | string[]; +} + +// @public (undocumented) +export interface SavedObjectsFindResponse 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 { + // (undocumented) + migrationVersion?: SavedObjectsMigrationVersion; + // (undocumented) + references?: SavedObjectReference[]; + // (undocumented) + version?: string; +} + // @public export class SimpleSavedObject { constructor(client: SavedObjectsClient, { id, type, version, attributes, error, references, migrationVersion }: SavedObject); diff --git a/src/core/public/saved_objects/index.ts b/src/core/public/saved_objects/index.ts index 6e0893c469efa..a5f049a001f61 100644 --- a/src/core/public/saved_objects/index.ts +++ b/src/core/public/saved_objects/index.ts @@ -17,6 +17,22 @@ * under the License. */ -export { SavedObjectsClient, SavedObjectsClientContract } from './saved_objects_client'; +export { + SavedObject, + SavedObjectAttribute, + SavedObjectAttributes, + SavedObjectReference, + SavedObjectsBatchResponse, + SavedObjectsBaseOptions, + SavedObjectsBulkCreateObject, + SavedObjectsBulkCreateOptions, + SavedObjectsClient, + SavedObjectsClientContract, + SavedObjectsCreateOptions, + SavedObjectsFindOptions, + SavedObjectsFindResponse, + SavedObjectsMigrationVersion, + SavedObjectsUpdateOptions, +} from './saved_objects_client'; export { SimpleSavedObject } from './simple_saved_object'; export { SavedObjectsStart } from './saved_objects_service'; diff --git a/src/core/public/saved_objects/saved_objects_client.ts b/src/core/public/saved_objects/saved_objects_client.ts index 6fbf66e8694c1..501871e2cff2f 100644 --- a/src/core/public/saved_objects/saved_objects_client.ts +++ b/src/core/public/saved_objects/saved_objects_client.ts @@ -27,7 +27,8 @@ import { SavedObjectsClientContract as SavedObjectsApi, SavedObjectsFindOptions, SavedObjectsMigrationVersion, -} from 'src/core/server'; +} from '../../server'; +// TODO: Migrate to an error modal powered by the NP? import { isAutoCreateIndexError, showAutoCreateIndexErrorPage, @@ -35,6 +36,16 @@ import { import { SimpleSavedObject } from './simple_saved_object'; import { HttpFetchQuery, HttpSetup } from '../http'; +export { + SavedObject, + SavedObjectAttribute, + SavedObjectAttributes, + SavedObjectReference, + SavedObjectsBaseOptions, + SavedObjectsFindOptions, + SavedObjectsMigrationVersion, +} from '../../server'; + interface RequestParams { method: 'POST' | 'GET' | 'PUT' | 'DELETE'; path: string; @@ -42,31 +53,54 @@ interface RequestParams { body?: object; } -interface CreateOptions { +/** @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; 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; migrationVersion?: SavedObjectsMigrationVersion; references?: SavedObjectReference[]; } -interface BatchResponse { +/** @public */ +export interface SavedObjectsBatchResponse< + T extends SavedObjectAttributes = SavedObjectAttributes +> { savedObjects: Array>; } -interface FindResults - extends BatchResponse { +/** @public */ +export interface SavedObjectsFindResponse + extends SavedObjectsBatchResponse { total: number; perPage: number; page: number; @@ -102,8 +136,9 @@ export type SavedObjectsClientContract = PublicMethodsOf; /** * Saved Objects is Kibana's data persisentence mechanism allowing plugins to - * use Elasticsearch for storing plugin state. The SavedObjectsClient is a thin - * "repository" for client-side plugins to interact with Saved Objects. + * 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. * * @public */ @@ -151,18 +186,15 @@ export class SavedObjectsClient { /** * 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')); @@ -203,10 +235,12 @@ export class SavedObjectsClient { * @property {boolean} [options.overwrite=false] * @returns The result of the create operation containing created saved objects. */ - public bulkCreate = (objects: BulkCreateOptions[] = [], options: HttpFetchQuery = {}) => { - // TODO better options type + 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({ method: 'POST', @@ -216,7 +250,7 @@ export class SavedObjectsClient { }); return request.then(resp => { resp.saved_objects = resp.saved_objects.map(d => this.createSavedObject(d)); - return renameKeys({ saved_objects: 'savedObjects' }, resp) as BatchResponse; + return renameKeys({ saved_objects: 'savedObjects' }, resp) as SavedObjectsBatchResponse; }); }; @@ -251,7 +285,7 @@ export class SavedObjectsClient { */ public find = ( options: SavedObjectsFindOptions = {} - ): Promise> => { + ): Promise> => { const path = this.getPath(['_find']); const query = renameKeys( { @@ -281,7 +315,7 @@ export class SavedObjectsClient { page: 'page', }, resp - ) as FindResults; + ) as SavedObjectsFindResponse; }); }; @@ -329,7 +363,7 @@ export class SavedObjectsClient { }); return request.then(resp => { resp.saved_objects = resp.saved_objects.map(d => this.createSavedObject(d)); - return renameKeys({ saved_objects: 'savedObjects' }, resp) as BatchResponse; + return renameKeys({ saved_objects: 'savedObjects' }, resp) as SavedObjectsBatchResponse; }); }; @@ -348,7 +382,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')); diff --git a/src/core/public/saved_objects/simple_saved_object.ts b/src/core/public/saved_objects/simple_saved_object.ts index 8c4702792425e..92c228edd5e8e 100644 --- a/src/core/public/saved_objects/simple_saved_object.ts +++ b/src/core/public/saved_objects/simple_saved_object.ts @@ -18,7 +18,7 @@ */ 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'; /** diff --git a/src/core/server/index.ts b/src/core/server/index.ts index 4582f1362922f..902b1297725ff 100644 --- a/src/core/server/index.ts +++ b/src/core/server/index.ts @@ -87,22 +87,15 @@ export { } from './plugins'; export { - SavedObject, - SavedObjectAttributes, - SavedObjectReference, - SavedObjectsBaseOptions, SavedObjectsBulkCreateObject, SavedObjectsBulkGetObject, SavedObjectsBulkResponse, SavedObjectsClient, - SavedObjectsClientContract, SavedObjectsCreateOptions, SavedObjectsClientWrapperFactory, SavedObjectsClientWrapperOptions, SavedObjectsErrorHelpers, - SavedObjectsFindOptions, SavedObjectsFindResponse, - SavedObjectsMigrationVersion, SavedObjectsService, SavedObjectsUpdateOptions, SavedObjectsUpdateResponse, @@ -110,6 +103,17 @@ export { 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 e09780574a25c..a186544630c88 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 9a2548952de3d..3b0b80c08293a 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 ee9ce781ef9a5..92082f1ade89b 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 11add36e54fb6..23f86f1e886e1 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 { ImportError } 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 aacf8112f255a..cddcbb0d54376 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 { Retry } from './types'; export function createObjectsFilter(retries: Retry[]) { 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 6ae9562a1f3aa..e2488ebb27c0f 100644 --- a/src/core/server/saved_objects/import/extract_errors.ts +++ b/src/core/server/saved_objects/import/extract_errors.ts @@ -17,7 +17,7 @@ * under the License. */ -import { SavedObject } from '../service'; +import { SavedObject } from '../types'; import { ImportError } 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 80e5cc9a306f0..a15675f164b6f 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/import_saved_objects.ts b/src/core/server/saved_objects/import/import_saved_objects.ts index 10c1350c4c579..4ed1bd0a4c9db 100644 --- a/src/core/server/saved_objects/import/import_saved_objects.ts +++ b/src/core/server/saved_objects/import/import_saved_objects.ts @@ -22,7 +22,7 @@ import { collectSavedObjects } from './collect_saved_objects'; import { extractErrors } from './extract_errors'; import { ImportError } from './types'; import { validateReferences } from './validate_references'; -import { SavedObjectsClientContract } from '../'; +import { SavedObjectsClientContract } from '../types'; interface ImportSavedObjectsOptions { readStream: Readable; 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 d3f36852fd796..db610f67bcd31 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 5cd4d2fca740c..51a95b74d42e5 100644 --- a/src/core/server/saved_objects/import/resolve_import_errors.ts +++ b/src/core/server/saved_objects/import/resolve_import_errors.ts @@ -18,7 +18,7 @@ */ import { Readable } from 'stream'; -import { SavedObjectsClientContract } from '../'; +import { SavedObjectsClientContract } from '../../types'; 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 5609308f755f3..f0be58e978b6a 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 { Retry } from './types'; export function splitOverwrites(savedObjects: SavedObject[], retries: Retry[]) { diff --git a/src/core/server/saved_objects/import/validate_references.ts b/src/core/server/saved_objects/import/validate_references.ts index 2e3c1ef5293b3..4716fc09b0f1b 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 { ImportError } from './types'; const REF_TYPES_TO_VLIDATE = ['index-pattern', 'search']; 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..e7092b59524d0 100644 --- a/src/core/server/saved_objects/migrations/core/document_migrator.ts +++ b/src/core/server/saved_objects/migrations/core/document_migrator.ts @@ -65,7 +65,7 @@ import _ from 'lodash'; import cloneDeep from 'lodash.clonedeep'; import Semver from 'semver'; import { RawSavedObjectDoc } from '../../serialization'; -import { SavedObjectsMigrationVersion } from '../../'; +import { SavedObjectsMigrationVersion } from '../../types'; import { LogFn, Logger, MigrationLogger } from './migration_logger'; export type TransformFn = (doc: RawSavedObjectDoc, log?: Logger) => RawSavedObjectDoc; 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 9606a46edef95..9dbe74b92f583 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/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 eb41df3a19d2d..9aa582aebfea4 100644 --- a/src/core/server/saved_objects/service/lib/repository.ts +++ b/src/core/server/saved_objects/service/lib/repository.ts @@ -29,19 +29,21 @@ import { SavedObjectsSchema } from '../../schema'; import { KibanaMigrator } from '../../migrations'; 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 fc0a3ea64c7a4..fa88738cbca62 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'; export interface SavedObjectsClientWrapperOptions { client: SavedObjectsClientContract; 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..27d8a2e620194 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 @@ -65,24 +63,6 @@ export interface SavedObjectsBulkResponse saved_objects: Array>; } -/** - * - * @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'; -} - /** * * @public @@ -132,135 +112,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..ca0338a17d6c7 --- /dev/null +++ b/src/core/server/saved_objects/types.ts @@ -0,0 +1,190 @@ +/* + * 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[]; + +/** + * + * @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; +} + +/** + * + * @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'; +} + +/** + * + * @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 a6fbfebf9d947..ad32601026082 100644 --- a/src/core/server/server.api.md +++ b/src/core/server/server.api.md @@ -435,10 +435,11 @@ export interface SavedObject { version?: string; } +// @public (undocumented) +export type SavedObjectAttribute = string | number | boolean | null | undefined | SavedObjectAttributes | SavedObjectAttributes[]; + // @public (undocumented) 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[]; } diff --git a/src/core/server/types.ts b/src/core/server/types.ts new file mode 100644 index 0000000000000..6ffbb2193e92a --- /dev/null +++ b/src/core/server/types.ts @@ -0,0 +1,20 @@ +/* + * 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 * from './saved_objects/types'; 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'; From 84284e438ae4ebee422e131b1307d739bc3a66c0 Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Sat, 6 Jul 2019 15:52:16 +0200 Subject: [PATCH 10/29] Fix build breaking when importing directly from /server in /public --- src/core/public/saved_objects/saved_objects_client.ts | 4 ++-- src/core/public/saved_objects/simple_saved_object.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/public/saved_objects/saved_objects_client.ts b/src/core/public/saved_objects/saved_objects_client.ts index 501871e2cff2f..8d034ee692909 100644 --- a/src/core/public/saved_objects/saved_objects_client.ts +++ b/src/core/public/saved_objects/saved_objects_client.ts @@ -27,7 +27,7 @@ import { SavedObjectsClientContract as SavedObjectsApi, SavedObjectsFindOptions, SavedObjectsMigrationVersion, -} from '../../server'; +} from '../../server/types'; // TODO: Migrate to an error modal powered by the NP? import { isAutoCreateIndexError, @@ -44,7 +44,7 @@ export { SavedObjectsBaseOptions, SavedObjectsFindOptions, SavedObjectsMigrationVersion, -} from '../../server'; +} from '../../server/types'; interface RequestParams { method: 'POST' | 'GET' | 'PUT' | 'DELETE'; diff --git a/src/core/public/saved_objects/simple_saved_object.ts b/src/core/public/saved_objects/simple_saved_object.ts index 92c228edd5e8e..8f342f72c60ee 100644 --- a/src/core/public/saved_objects/simple_saved_object.ts +++ b/src/core/public/saved_objects/simple_saved_object.ts @@ -18,7 +18,7 @@ */ import { get, has, set } from 'lodash'; -import { SavedObject as SavedObjectType, SavedObjectAttributes } from '../../server'; +import { SavedObject as SavedObjectType, SavedObjectAttributes } from '../../server/types'; import { SavedObjectsClient } from './saved_objects_client'; /** From ef42149faffb80123bbfaf8bc4173833f91da421 Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Wed, 17 Jul 2019 15:08:41 +0100 Subject: [PATCH 11/29] Ensure that all option paramaters are picked and renamed --- .../saved_objects/saved_objects_client.ts | 35 +++++++++++++------ 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/src/core/public/saved_objects/saved_objects_client.ts b/src/core/public/saved_objects/saved_objects_client.ts index 8d034ee692909..c62dca341ada1 100644 --- a/src/core/public/saved_objects/saved_objects_client.ts +++ b/src/core/public/saved_objects/saved_objects_client.ts @@ -46,6 +46,8 @@ export { SavedObjectsMigrationVersion, } from '../../server/types'; +type PromiseType> = T extends Promise ? U : never; + interface RequestParams { method: 'POST' | 'GET' | 'PUT' | 'DELETE'; path: string; @@ -250,7 +252,10 @@ export class SavedObjectsClient { }); return request.then(resp => { resp.saved_objects = resp.saved_objects.map(d => this.createSavedObject(d)); - return renameKeys({ saved_objects: 'savedObjects' }, resp) as SavedObjectsBatchResponse; + return pickAndRenameKeys>>( + { saved_objects: 'savedObjects' }, + resp + ) as SavedObjectsBatchResponse; }); }; @@ -287,15 +292,19 @@ export class SavedObjectsClient { options: SavedObjectsFindOptions = {} ): Promise> => { const path = this.getPath(['_find']); - const query = renameKeys( + const query = pickAndRenameKeys( { - type: 'type', - search: 'search', - searchFields: 'search_fields', - page: 'page', - perPage: 'per_page', + defaultSearchOperator: 'defaultSearchOperator', fields: 'fields', hasReference: 'has_reference', + namespace: 'namespace', + page: 'page', + perPage: 'per_page', + search: 'search', + searchFields: 'search_fields', + sortField: 'sortField', + sortOrder: 'sortOrder', + type: 'type', }, options ); @@ -307,7 +316,7 @@ export class SavedObjectsClient { }); return request.then(resp => { resp.saved_objects = resp.saved_objects.map(d => this.createSavedObject(d)); - return renameKeys( + return pickAndRenameKeys>>( { saved_objects: 'savedObjects', total: 'total', @@ -363,7 +372,10 @@ export class SavedObjectsClient { }); return request.then(resp => { resp.saved_objects = resp.saved_objects.map(d => this.createSavedObject(d)); - return renameKeys({ saved_objects: 'savedObjects' }, resp) as SavedObjectsBatchResponse; + return pickAndRenameKeys>>( + { saved_objects: 'savedObjects' }, + resp + ) as SavedObjectsBatchResponse; }); }; @@ -433,7 +445,10 @@ export class SavedObjectsClient { * @param keysMap - a map of the form `{oldKey: newKey}` * @param obj - the object whose own properties will be renamed */ -const renameKeys = (keysMap: Record, obj: Record) => +const pickAndRenameKeys = >( + keysMap: Record, + obj: Record +) => Object.keys(obj).reduce((acc, key) => { return typeof keysMap[key] === 'undefined' ? acc From 9b2dc2702ca4e93a301c83426781dbfd769d1f01 Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Thu, 18 Jul 2019 12:25:36 +0100 Subject: [PATCH 12/29] Fix option mapping and introduce stronger types --- ...a-plugin-public.savedobjectsclient.find.md | 2 +- ...kibana-plugin-public.savedobjectsclient.md | 2 +- src/core/public/public.api.md | 2 +- .../saved_objects_client.test.ts | 278 +++++++++--------- .../saved_objects/saved_objects_client.ts | 37 +-- 5 files changed, 165 insertions(+), 156 deletions(-) diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsclient.find.md b/docs/development/core/public/kibana-plugin-public.savedobjectsclient.find.md index c78d9067eda3e..0d30ee1954624 100644 --- a/docs/development/core/public/kibana-plugin-public.savedobjectsclient.find.md +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsclient.find.md @@ -9,5 +9,5 @@ Search for objects Signature: ```typescript -find: (options?: SavedObjectsFindOptions) => Promise>; +find: (options?: Pick) => Promise>; ``` diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsclient.md b/docs/development/core/public/kibana-plugin-public.savedobjectsclient.md index 094261389fa35..10384e708628e 100644 --- a/docs/development/core/public/kibana-plugin-public.savedobjectsclient.md +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsclient.md @@ -26,7 +26,7 @@ export declare class SavedObjectsClient | [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?: SavedObjectsFindOptions) => Promise<SavedObjectsFindResponse<T>> | Search for objects | +| [find](./kibana-plugin-public.savedobjectsclient.find.md) | | <T extends SavedObjectAttributes>(options?: Pick<SavedObjectFindOptionsServer, "search" | "type" | "defaultSearchOperator" | "searchFields" | "sortField" | "hasReference" | "page" | "perPage" | "fields">) => Promise<SavedObjectsFindResponse<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 diff --git a/src/core/public/public.api.md b/src/core/public/public.api.md index 21edf446560ef..08895b30a458f 100644 --- a/src/core/public/public.api.md +++ b/src/core/public/public.api.md @@ -582,7 +582,7 @@ export class SavedObjectsClient { }[]) => Promise>; create: (type: string, attributes: T, options?: SavedObjectsCreateOptions) => Promise>; delete: (type: string, id: string) => Promise<{}>; - find: (options?: SavedObjectsFindOptions) => Promise>; + find: (options?: Pick) => Promise>; get: (type: string, id: string) => Promise>; update(type: string, id: string, attributes: T, { version, migrationVersion, references }?: SavedObjectsUpdateOptions): Promise>; } diff --git a/src/core/public/saved_objects/saved_objects_client.test.ts b/src/core/public/saved_objects/saved_objects_client.test.ts index d4914999ab96d..9fc66aeca2451 100644 --- a/src/core/public/saved_objects/saved_objects_client.test.ts +++ b/src/core/public/saved_objects/saved_objects_client.test.ts @@ -64,15 +64,15 @@ describe('SavedObjectsClient', () => { 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, - }, -] -`); + 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 () => { @@ -84,17 +84,17 @@ Array [ 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, - }, - ], -] -`); + 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 () => { @@ -127,15 +127,15 @@ Array [ 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, - }, -] -`); + Array [ + "/api/saved_objects/index-pattern/logstash-*", + Object { + "body": undefined, + "method": "DELETE", + "query": undefined, + }, + ] + `); }); }); @@ -168,17 +168,17 @@ Array [ 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, - }, - ], -] -`); + 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 () => { @@ -230,37 +230,37 @@ Array [ 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, - }, - }, - ], -] -`); + 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, - }, - }, - ], -] -`); + 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 () => { @@ -288,37 +288,37 @@ Array [ 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, - }, - }, - ], -] -`); + 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, - }, - }, - ], -] -`); + 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, + }, + }, + ], + ] + `); }); }); @@ -342,67 +342,73 @@ Array [ expect(result.total).toBe(1); }); - test('makes HTTP call translating options into snake case query parameters', () => { + test('makes HTTP call correctly mapping options into snake case query parameters', () => { const options = { - type: 'index-pattern', - search: 'what is the meaning of life?|life', - searchFields: ['title^5', 'body'], - page: 10, - perPage: 100, + 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 { - "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", - ], - "type": "index-pattern", - }, - }, - ], -] -`); + 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 {}, - }, - ], -] -`); + Array [ + Array [ + "/api/saved_objects/_find", + Object { + "body": undefined, + "method": "GET", + "query": Object {}, + }, + ], + ] + `); }); }); }); diff --git a/src/core/public/saved_objects/saved_objects_client.ts b/src/core/public/saved_objects/saved_objects_client.ts index c62dca341ada1..f8b608393230a 100644 --- a/src/core/public/saved_objects/saved_objects_client.ts +++ b/src/core/public/saved_objects/saved_objects_client.ts @@ -25,7 +25,7 @@ import { SavedObjectAttributes, SavedObjectReference, SavedObjectsClientContract as SavedObjectsApi, - SavedObjectsFindOptions, + SavedObjectsFindOptions as SavedObjectFindOptionsServer, SavedObjectsMigrationVersion, } from '../../server/types'; // TODO: Migrate to an error modal powered by the NP? @@ -36,6 +36,8 @@ import { import { SimpleSavedObject } from './simple_saved_object'; import { HttpFetchQuery, HttpSetup } from '../http'; +type SavedObjectsFindOptions = Omit; + export { SavedObject, SavedObjectAttribute, @@ -252,10 +254,10 @@ export class SavedObjectsClient { }); return request.then(resp => { resp.saved_objects = resp.saved_objects.map(d => this.createSavedObject(d)); - return pickAndRenameKeys>>( - { saved_objects: 'savedObjects' }, - resp - ) as SavedObjectsBatchResponse; + return pickAndRenameKeys< + PromiseType>, + SavedObjectsBatchResponse + >({ saved_objects: 'savedObjects' }, resp) as SavedObjectsBatchResponse; }); }; @@ -292,18 +294,16 @@ export class SavedObjectsClient { options: SavedObjectsFindOptions = {} ): Promise> => { const path = this.getPath(['_find']); - const query = pickAndRenameKeys( + const query = pickAndRenameKeys( { - defaultSearchOperator: 'defaultSearchOperator', + defaultSearchOperator: 'default_search_operator', fields: 'fields', hasReference: 'has_reference', - namespace: 'namespace', page: 'page', perPage: 'per_page', search: 'search', searchFields: 'search_fields', - sortField: 'sortField', - sortOrder: 'sortOrder', + sortField: 'sort_field', type: 'type', }, options @@ -316,7 +316,10 @@ export class SavedObjectsClient { }); return request.then(resp => { resp.saved_objects = resp.saved_objects.map(d => this.createSavedObject(d)); - return pickAndRenameKeys>>( + return pickAndRenameKeys< + PromiseType>, + SavedObjectsFindResponse + >( { saved_objects: 'savedObjects', total: 'total', @@ -372,10 +375,10 @@ export class SavedObjectsClient { }); return request.then(resp => { resp.saved_objects = resp.saved_objects.map(d => this.createSavedObject(d)); - return pickAndRenameKeys>>( - { saved_objects: 'savedObjects' }, - resp - ) as SavedObjectsBatchResponse; + return pickAndRenameKeys< + PromiseType>, + SavedObjectsBatchResponse + >({ saved_objects: 'savedObjects' }, resp) as SavedObjectsBatchResponse; }); }; @@ -445,8 +448,8 @@ export class SavedObjectsClient { * @param keysMap - a map of the form `{oldKey: newKey}` * @param obj - the object whose own properties will be renamed */ -const pickAndRenameKeys = >( - keysMap: Record, +const pickAndRenameKeys = , U extends Record>( + keysMap: Record, obj: Record ) => Object.keys(obj).reduce((acc, key) => { From 66ebe87bad592c63d6fcd9c89afc1bfa4bcda79e Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Thu, 18 Jul 2019 12:28:11 +0100 Subject: [PATCH 13/29] Eslint: allow imports from src/core/*/types --- .eslintrc.js | 1 + 1 file changed, 1 insertion(+) diff --git a/.eslintrc.js b/.eslintrc.js index 019f93d91b555..6f89ab585b341 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -146,6 +146,7 @@ module.exports = { 'src/core/server/**/*', '!src/core/server/index.ts', '!src/core/server/mocks.ts', + '!src/core/server/types.ts', '!src/core/server/*.test.mocks.ts', 'src/plugins/**/public/**/*', From dc1fc9b1bcca726990ea1513a6e036eb3b6bfe36 Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Fri, 19 Jul 2019 16:22:56 +0100 Subject: [PATCH 14/29] Add compatibility layer for kfetch vs http.fetch error responses --- src/core/public/saved_objects/saved_objects_client.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/core/public/saved_objects/saved_objects_client.ts b/src/core/public/saved_objects/saved_objects_client.ts index f8b608393230a..8aa6accb84a4c 100644 --- a/src/core/public/saved_objects/saved_objects_client.ts +++ b/src/core/public/saved_objects/saved_objects_client.ts @@ -435,7 +435,14 @@ export class SavedObjectsClient { return Promise.reject(new Error('body not permitted for GET requests')); } - return this.http.fetch(path, { method, query, body: JSON.stringify(body) }); + return this.http.fetch(path, { method, query, body: JSON.stringify(body) }).catch(err => { + // To ensure we don't break backwards compatibility, we keep the old + // kfetch error format of `{res: {status: number}}` whereas `http.fetch` + // uses `{response: {status: number}}` + + const kfetchError = Object.assign(err, { res: err.response }); + return Promise.reject(kfetchError); + }); } } From 40ffbc0367ca13bc9c364897b4ff39d3ecb354ba Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Mon, 29 Jul 2019 11:39:49 +0200 Subject: [PATCH 15/29] Improve documentation --- .../core/public/kibana-plugin-public.md | 2 +- ...na-plugin-public.savedobject.attributes.md | 2 ++ .../kibana-plugin-public.savedobject.id.md | 2 ++ .../kibana-plugin-public.savedobject.md | 14 +++++++------- ...gin-public.savedobject.migrationversion.md | 2 ++ ...na-plugin-public.savedobject.references.md | 2 ++ .../kibana-plugin-public.savedobject.type.md | 2 ++ ...na-plugin-public.savedobject.updated_at.md | 2 ++ ...ibana-plugin-public.savedobject.version.md | 2 ++ ...ana-plugin-public.savedobjectattributes.md | 1 + ...n-public.savedobjectsfindoptions.fields.md | 7 +++++++ ...a-plugin-public.savedobjectsfindoptions.md | 6 +++--- ...n-public.savedobjectsfindoptions.search.md | 2 ++ ...ic.savedobjectsfindoptions.searchfields.md | 2 +- ...gin-public.savedobjectsmigrationversion.md | 9 +-------- .../core/server/kibana-plugin-server.md | 2 +- ...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 ++ ...ana-plugin-server.savedobjectattributes.md | 1 + ...n-server.savedobjectsfindoptions.fields.md | 7 +++++++ ...a-plugin-server.savedobjectsfindoptions.md | 6 +++--- ...n-server.savedobjectsfindoptions.search.md | 2 ++ ...er.savedobjectsfindoptions.searchfields.md | 2 +- ...gin-server.savedobjectsmigrationversion.md | 9 +-------- src/core/public/public.api.md | 11 +---------- src/core/server/saved_objects/types.ts | 19 ++++++++++++++++--- src/core/server/server.api.md | 11 +---------- 33 files changed, 92 insertions(+), 63 deletions(-) diff --git a/docs/development/core/public/kibana-plugin-public.md b/docs/development/core/public/kibana-plugin-public.md index e07d2f744092c..0df67da361a60 100644 --- a/docs/development/core/public/kibana-plugin-public.md +++ b/docs/development/core/public/kibana-plugin-public.md @@ -60,7 +60,7 @@ The plugin integrates with the core system via lifecycle events: `setup` | [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) | | +| [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) | | diff --git a/docs/development/core/public/kibana-plugin-public.savedobject.attributes.md b/docs/development/core/public/kibana-plugin-public.savedobject.attributes.md index 8f6539149f4de..f9d39c15fcff4 100644 --- a/docs/development/core/public/kibana-plugin-public.savedobject.attributes.md +++ b/docs/development/core/public/kibana-plugin-public.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/public/kibana-plugin-public.savedobject.id.md b/docs/development/core/public/kibana-plugin-public.savedobject.id.md index 443f0e084cfea..7b54e0a7c2a74 100644 --- a/docs/development/core/public/kibana-plugin-public.savedobject.id.md +++ b/docs/development/core/public/kibana-plugin-public.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/public/kibana-plugin-public.savedobject.md b/docs/development/core/public/kibana-plugin-public.savedobject.md index 8bbec643247b0..9bf0149f0854e 100644 --- a/docs/development/core/public/kibana-plugin-public.savedobject.md +++ b/docs/development/core/public/kibana-plugin-public.savedobject.md @@ -15,12 +15,12 @@ export interface SavedObject | Property | Type | Description | | --- | --- | --- | -| [attributes](./kibana-plugin-public.savedobject.attributes.md) | T | | +| [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 | | -| [migrationVersion](./kibana-plugin-public.savedobject.migrationversion.md) | SavedObjectsMigrationVersion | | -| [references](./kibana-plugin-public.savedobject.references.md) | SavedObjectReference[] | | -| [type](./kibana-plugin-public.savedobject.type.md) | string | | -| [updated\_at](./kibana-plugin-public.savedobject.updated_at.md) | string | | -| [version](./kibana-plugin-public.savedobject.version.md) | string | | +| [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 index f4e58b9feb233..d07b664f11ff2 100644 --- a/docs/development/core/public/kibana-plugin-public.savedobject.migrationversion.md +++ b/docs/development/core/public/kibana-plugin-public.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/public/kibana-plugin-public.savedobject.references.md b/docs/development/core/public/kibana-plugin-public.savedobject.references.md index 8ce965274637b..3c3ecdd283b5f 100644 --- a/docs/development/core/public/kibana-plugin-public.savedobject.references.md +++ b/docs/development/core/public/kibana-plugin-public.savedobject.references.md @@ -4,6 +4,8 @@ ## SavedObject.references property +A reference to another saved object. + Signature: ```typescript diff --git a/docs/development/core/public/kibana-plugin-public.savedobject.type.md b/docs/development/core/public/kibana-plugin-public.savedobject.type.md index c62698574efc8..2bce5b8a15634 100644 --- a/docs/development/core/public/kibana-plugin-public.savedobject.type.md +++ b/docs/development/core/public/kibana-plugin-public.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/public/kibana-plugin-public.savedobject.updated_at.md b/docs/development/core/public/kibana-plugin-public.savedobject.updated_at.md index 714bae575af1e..861128c69ae2a 100644 --- a/docs/development/core/public/kibana-plugin-public.savedobject.updated_at.md +++ b/docs/development/core/public/kibana-plugin-public.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/public/kibana-plugin-public.savedobject.version.md b/docs/development/core/public/kibana-plugin-public.savedobject.version.md index 34f09d03037ad..26356f444f2ca 100644 --- a/docs/development/core/public/kibana-plugin-public.savedobject.version.md +++ b/docs/development/core/public/kibana-plugin-public.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/public/kibana-plugin-public.savedobjectattributes.md b/docs/development/core/public/kibana-plugin-public.savedobjectattributes.md index 6b8cc20888559..4a9e096cc25b7 100644 --- a/docs/development/core/public/kibana-plugin-public.savedobjectattributes.md +++ b/docs/development/core/public/kibana-plugin-public.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/public/kibana-plugin-public.savedobjectsfindoptions.fields.md b/docs/development/core/public/kibana-plugin-public.savedobjectsfindoptions.fields.md index 3e32a173e9d4a..20cbf04418222 100644 --- a/docs/development/core/public/kibana-plugin-public.savedobjectsfindoptions.fields.md +++ b/docs/development/core/public/kibana-plugin-public.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/public/kibana-plugin-public.savedobjectsfindoptions.md b/docs/development/core/public/kibana-plugin-public.savedobjectsfindoptions.md index 3418bb429c8e4..f90c60ebdd0dc 100644 --- a/docs/development/core/public/kibana-plugin-public.savedobjectsfindoptions.md +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsfindoptions.md @@ -16,12 +16,12 @@ export interface SavedObjectsFindOptions extends SavedObjectsBaseOptions | Property | Type | Description | | --- | --- | --- | | [defaultSearchOperator](./kibana-plugin-public.savedobjectsfindoptions.defaultsearchoperator.md) | 'AND' | 'OR' | | -| [fields](./kibana-plugin-public.savedobjectsfindoptions.fields.md) | string[] | | +| [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 | | -| [searchFields](./kibana-plugin-public.savedobjectsfindoptions.searchfields.md) | string[] | see Elasticsearch Simple Query String Query field argument for more information | +| [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.search.md b/docs/development/core/public/kibana-plugin-public.savedobjectsfindoptions.search.md index 2b5866237c267..f8f95e5329826 100644 --- a/docs/development/core/public/kibana-plugin-public.savedobjectsfindoptions.search.md +++ b/docs/development/core/public/kibana-plugin-public.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/public/kibana-plugin-public.savedobjectsfindoptions.searchfields.md b/docs/development/core/public/kibana-plugin-public.savedobjectsfindoptions.searchfields.md index 41c62cca58c38..5e97ef00b4417 100644 --- a/docs/development/core/public/kibana-plugin-public.savedobjectsfindoptions.searchfields.md +++ b/docs/development/core/public/kibana-plugin-public.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/public/kibana-plugin-public.savedobjectsmigrationversion.md b/docs/development/core/public/kibana-plugin-public.savedobjectsmigrationversion.md index d901d65591ee3..675adb9498c50 100644 --- a/docs/development/core/public/kibana-plugin-public.savedobjectsmigrationversion.md +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsmigrationversion.md @@ -14,12 +14,5 @@ export interface SavedObjectsMigrationVersion ## Example - -``` -migrationVersion: { - dashboard: '7.1.1', - space: '6.6.6', -} - -``` +migrationVersion: { dashboard: '7.1.1', space: '6.6.6', } diff --git a/docs/development/core/server/kibana-plugin-server.md b/docs/development/core/server/kibana-plugin-server.md index c9afda9956bd6..5716f16810792 100644 --- a/docs/development/core/server/kibana-plugin-server.md +++ b/docs/development/core/server/kibana-plugin-server.md @@ -51,7 +51,7 @@ The plugin integrates with the core system via lifecycle events: `setup` | [PluginsServiceStart](./kibana-plugin-server.pluginsservicestart.md) | | | [RouteConfigOptions](./kibana-plugin-server.routeconfigoptions.md) | Route specific configuration. | | [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) | | 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.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.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.savedobjectsmigrationversion.md b/docs/development/core/server/kibana-plugin-server.savedobjectsmigrationversion.md index a7f652e4348bf..b7f9c8fd8fe98 100644 --- a/docs/development/core/server/kibana-plugin-server.savedobjectsmigrationversion.md +++ b/docs/development/core/server/kibana-plugin-server.savedobjectsmigrationversion.md @@ -14,12 +14,5 @@ export interface SavedObjectsMigrationVersion ## Example - -``` -migrationVersion: { - dashboard: '7.1.1', - space: '6.6.6', -} - -``` +migrationVersion: { dashboard: '7.1.1', space: '6.6.6', } diff --git a/src/core/public/public.api.md b/src/core/public/public.api.md index b970ef0e2e9cb..618b975864f76 100644 --- a/src/core/public/public.api.md +++ b/src/core/public/public.api.md @@ -578,31 +578,24 @@ export type RecursiveReadonly = T extends (...args: any[]) => any ? T : T ext // @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 (undocumented) +// @public export interface SavedObjectAttributes { // (undocumented) [key: string]: SavedObjectAttribute | SavedObjectAttribute[]; @@ -674,7 +667,6 @@ export interface SavedObjectsCreateOptions { export interface SavedObjectsFindOptions extends SavedObjectsBaseOptions { // (undocumented) defaultSearchOperator?: 'AND' | 'OR'; - // (undocumented) fields?: string[]; // (undocumented) hasReference?: { @@ -685,7 +677,6 @@ export interface SavedObjectsFindOptions extends SavedObjectsBaseOptions { page?: number; // (undocumented) perPage?: number; - // (undocumented) search?: string; searchFields?: string[]; // (undocumented) diff --git a/src/core/server/saved_objects/types.ts b/src/core/server/saved_objects/types.ts index ca0338a17d6c7..0966874aa435b 100644 --- a/src/core/server/saved_objects/types.ts +++ b/src/core/server/saved_objects/types.ts @@ -27,12 +27,10 @@ import { SavedObjectsClient } from './service/saved_objects_client'; * value. * * @example - * ``` * migrationVersion: { * dashboard: '7.1.1', * space: '6.6.6', * } - * ``` * * @public */ @@ -54,6 +52,8 @@ export type SavedObjectAttribute = | SavedObjectAttributes[]; /** + * The data for a Saved Object is stored in the `attributes` key as either an + * object or an array of objects. * * @public */ @@ -66,16 +66,23 @@ export interface SavedObjectAttributes { * @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; } @@ -100,9 +107,15 @@ export interface SavedObjectsFindOptions extends SavedObjectsBaseOptions { 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; - /** 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 */ searchFields?: string[]; hasReference?: { type: string; id: string }; defaultSearchOperator?: 'AND' | 'OR'; diff --git a/src/core/server/server.api.md b/src/core/server/server.api.md index 3400121b9ce82..60e61a43121d6 100644 --- a/src/core/server/server.api.md +++ b/src/core/server/server.api.md @@ -414,31 +414,24 @@ 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 (undocumented) +// @public export interface SavedObjectAttributes { // (undocumented) [key: string]: SavedObjectAttribute | SavedObjectAttribute[]; @@ -595,7 +588,6 @@ export class SavedObjectsErrorHelpers { export interface SavedObjectsFindOptions extends SavedObjectsBaseOptions { // (undocumented) defaultSearchOperator?: 'AND' | 'OR'; - // (undocumented) fields?: string[]; // (undocumented) hasReference?: { @@ -606,7 +598,6 @@ export interface SavedObjectsFindOptions extends SavedObjectsBaseOptions { page?: number; // (undocumented) perPage?: number; - // (undocumented) search?: string; searchFields?: string[]; // (undocumented) From 75f837a859c8b3083050d6780263b7fc7a8ece92 Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Mon, 29 Jul 2019 12:26:22 +0200 Subject: [PATCH 16/29] Expose SavedObjectsMigrationLogger --- .../core/server/kibana-plugin-server.md | 1 + ...erver.savedobjectsmigrationlogger.debug.md | 11 ++++++++++ ...server.savedobjectsmigrationlogger.info.md | 11 ++++++++++ ...ugin-server.savedobjectsmigrationlogger.md | 21 +++++++++++++++++++ ...ver.savedobjectsmigrationlogger.warning.md | 11 ++++++++++ src/core/server/index.ts | 3 ++- src/core/server/saved_objects/index.ts | 2 ++ .../migrations/core/document_migrator.ts | 19 +++++++++++++---- .../migrations/core/migration_context.ts | 4 ++-- .../migrations/core/migration_coordinator.ts | 6 +++--- .../migrations/core/migration_logger.ts | 5 +++-- src/core/server/server.api.md | 10 +++++++++ .../dashboard/migrations/migrations_730.ts | 4 ++-- 13 files changed, 94 insertions(+), 14 deletions(-) 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 diff --git a/docs/development/core/server/kibana-plugin-server.md b/docs/development/core/server/kibana-plugin-server.md index 5716f16810792..3a0001f8685b7 100644 --- a/docs/development/core/server/kibana-plugin-server.md +++ b/docs/development/core/server/kibana-plugin-server.md @@ -61,6 +61,7 @@ The plugin integrates with the core system via lifecycle events: `setup` | [SavedObjectsCreateOptions](./kibana-plugin-server.savedobjectscreateoptions.md) | | | [SavedObjectsFindOptions](./kibana-plugin-server.savedobjectsfindoptions.md) | | | [SavedObjectsFindResponse](./kibana-plugin-server.savedobjectsfindresponse.md) | | +| [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. | | [SavedObjectsService](./kibana-plugin-server.savedobjectsservice.md) | | 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/src/core/server/index.ts b/src/core/server/index.ts index 2959208f9cbd3..6b5ea6ea9079c 100644 --- a/src/core/server/index.ts +++ b/src/core/server/index.ts @@ -91,11 +91,12 @@ export { SavedObjectsBulkGetObject, SavedObjectsBulkResponse, SavedObjectsClient, - SavedObjectsCreateOptions, SavedObjectsClientWrapperFactory, SavedObjectsClientWrapperOptions, + SavedObjectsCreateOptions, SavedObjectsErrorHelpers, SavedObjectsFindResponse, + SavedObjectsMigrationLogger, SavedObjectsRawDoc, SavedObjectsSchema, SavedObjectsSerializer, diff --git a/src/core/server/saved_objects/index.ts b/src/core/server/saved_objects/index.ts index 623c722eb95b1..8921f537ac331 100644 --- a/src/core/server/saved_objects/index.ts +++ b/src/core/server/saved_objects/index.ts @@ -24,3 +24,5 @@ export { SavedObjectsSchema } from './schema'; export { SavedObjectsManagement } from './management'; export { SavedObjectsSerializer, RawDoc as SavedObjectsRawDoc } from './serialization'; + +export { SavedObjectsMigrationLogger } from './migrations/core/migration_logger'; 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 e7092b59524d0..0576f1d22199f 100644 --- a/src/core/server/saved_objects/migrations/core/document_migrator.ts +++ b/src/core/server/saved_objects/migrations/core/document_migrator.ts @@ -66,9 +66,12 @@ import cloneDeep from 'lodash.clonedeep'; import Semver from 'semver'; import { RawSavedObjectDoc } from '../../serialization'; import { SavedObjectsMigrationVersion } from '../../types'; -import { LogFn, Logger, MigrationLogger } from './migration_logger'; +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/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/server.api.md b/src/core/server/server.api.md index 60e61a43121d6..a056aa86296ed 100644 --- a/src/core/server/server.api.md +++ b/src/core/server/server.api.md @@ -620,6 +620,16 @@ export interface SavedObjectsFindResponse total: number; } +// @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/legacy/core_plugins/kibana/public/dashboard/migrations/migrations_730.ts b/src/legacy/core_plugins/kibana/public/dashboard/migrations/migrations_730.ts index a497a7ff44bd5..451920d892f16 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 'src/core/server/saved_objects/migrations/core/migration_logger'; +import { SavedObjectsMigrationLogger } from 'src/core/server'; import { DashboardDoc730ToLatest, DashboardDoc700To720 } from './types'; import { isDashboardDoc } from './is_dashboard_doc'; import { moveFiltersToQuery } from './move_filters_to_query'; @@ -28,7 +28,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 From 73e601f2bc0554175002d7732f6df8ce92652964 Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Mon, 29 Jul 2019 14:01:34 +0200 Subject: [PATCH 17/29] Documentation and type tweaks --- src/core/public/saved_objects/saved_objects_client.ts | 5 +++-- .../server/saved_objects/service/saved_objects_client.ts | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/core/public/saved_objects/saved_objects_client.ts b/src/core/public/saved_objects/saved_objects_client.ts index 8aa6accb84a4c..cca3b1b74b3b3 100644 --- a/src/core/public/saved_objects/saved_objects_client.ts +++ b/src/core/public/saved_objects/saved_objects_client.ts @@ -36,7 +36,7 @@ import { import { SimpleSavedObject } from './simple_saved_object'; import { HttpFetchQuery, HttpSetup } from '../http'; -type SavedObjectsFindOptions = Omit; +export type SavedObjectsFindOptions = Omit; export { SavedObject, @@ -44,7 +44,6 @@ export { SavedObjectAttributes, SavedObjectReference, SavedObjectsBaseOptions, - SavedObjectsFindOptions, SavedObjectsMigrationVersion, } from '../../server/types'; @@ -65,6 +64,7 @@ export interface SavedObjectsCreateOptions { 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[]; } @@ -91,6 +91,7 @@ export interface SavedObjectsBulkCreateOptions { /** @public */ export interface SavedObjectsUpdateOptions { version?: string; + /** {@inheritDoc SavedObjectsMigrationVersion} */ migrationVersion?: SavedObjectsMigrationVersion; references?: SavedObjectReference[]; } 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 27d8a2e620194..3b1a0beef40da 100644 --- a/src/core/server/saved_objects/service/saved_objects_client.ts +++ b/src/core/server/saved_objects/service/saved_objects_client.ts @@ -39,6 +39,7 @@ export interface SavedObjectsCreateOptions extends SavedObjectsBaseOptions { id?: string; /** Overwrite existing documents (defaults to false) */ overwrite?: boolean; + /** {@inheritDoc SavedObjectsMigrationVersion} */ migrationVersion?: SavedObjectsMigrationVersion; references?: SavedObjectReference[]; } @@ -52,6 +53,7 @@ export interface SavedObjectsBulkCreateObject Date: Mon, 29 Jul 2019 15:46:32 +0200 Subject: [PATCH 18/29] Revert type changes from 73e601f and update api docs --- .../public/kibana-plugin-public.savedobjectscreateoptions.md | 2 +- ...plugin-public.savedobjectscreateoptions.migrationversion.md | 2 ++ .../public/kibana-plugin-public.savedobjectsupdateoptions.md | 2 +- ...plugin-public.savedobjectsupdateoptions.migrationversion.md | 2 ++ .../kibana-plugin-server.savedobjectsbulkcreateobject.md | 2 +- ...gin-server.savedobjectsbulkcreateobject.migrationversion.md | 2 ++ .../server/kibana-plugin-server.savedobjectscreateoptions.md | 2 +- ...plugin-server.savedobjectscreateoptions.migrationversion.md | 2 ++ src/core/public/public.api.md | 2 -- src/core/public/saved_objects/saved_objects_client.ts | 3 ++- src/core/server/server.api.md | 2 -- 11 files changed, 14 insertions(+), 9 deletions(-) diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectscreateoptions.md b/docs/development/core/public/kibana-plugin-public.savedobjectscreateoptions.md index 99d186dd294a6..08090c0f8d8c3 100644 --- a/docs/development/core/public/kibana-plugin-public.savedobjectscreateoptions.md +++ b/docs/development/core/public/kibana-plugin-public.savedobjectscreateoptions.md @@ -16,7 +16,7 @@ export interface SavedObjectsCreateOptions | 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 | | +| [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 index c56b4b615e419..5bc6b62f6680e 100644 --- a/docs/development/core/public/kibana-plugin-public.savedobjectscreateoptions.migrationversion.md +++ b/docs/development/core/public/kibana-plugin-public.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/public/kibana-plugin-public.savedobjectsupdateoptions.md b/docs/development/core/public/kibana-plugin-public.savedobjectsupdateoptions.md index d555e927eecc1..800a78d65486b 100644 --- a/docs/development/core/public/kibana-plugin-public.savedobjectsupdateoptions.md +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsupdateoptions.md @@ -15,7 +15,7 @@ export interface SavedObjectsUpdateOptions | Property | Type | Description | | --- | --- | --- | -| [migrationVersion](./kibana-plugin-public.savedobjectsupdateoptions.migrationversion.md) | SavedObjectsMigrationVersion | | +| [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 index dee541c9ca758..e5fe20acd3994 100644 --- a/docs/development/core/public/kibana-plugin-public.savedobjectsupdateoptions.migrationversion.md +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsupdateoptions.migrationversion.md @@ -4,6 +4,8 @@ ## 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 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.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/src/core/public/public.api.md b/src/core/public/public.api.md index 618b975864f76..5c413ed5d6bd1 100644 --- a/src/core/public/public.api.md +++ b/src/core/public/public.api.md @@ -656,7 +656,6 @@ export type SavedObjectsClientContract = PublicMethodsOf; // @public (undocumented) export interface SavedObjectsCreateOptions { id?: string; - // (undocumented) migrationVersion?: SavedObjectsMigrationVersion; overwrite?: boolean; // (undocumented) @@ -711,7 +710,6 @@ export interface SavedObjectsStart { // @public (undocumented) export interface SavedObjectsUpdateOptions { - // (undocumented) migrationVersion?: SavedObjectsMigrationVersion; // (undocumented) references?: SavedObjectReference[]; diff --git a/src/core/public/saved_objects/saved_objects_client.ts b/src/core/public/saved_objects/saved_objects_client.ts index cca3b1b74b3b3..2eb29d3aad9ef 100644 --- a/src/core/public/saved_objects/saved_objects_client.ts +++ b/src/core/public/saved_objects/saved_objects_client.ts @@ -36,7 +36,7 @@ import { import { SimpleSavedObject } from './simple_saved_object'; import { HttpFetchQuery, HttpSetup } from '../http'; -export type SavedObjectsFindOptions = Omit; +type SavedObjectsFindOptions = Omit; export { SavedObject, @@ -44,6 +44,7 @@ export { SavedObjectAttributes, SavedObjectReference, SavedObjectsBaseOptions, + SavedObjectsFindOptions, SavedObjectsMigrationVersion, } from '../../server/types'; diff --git a/src/core/server/server.api.md b/src/core/server/server.api.md index a056aa86296ed..6f7b8fd1ad687 100644 --- a/src/core/server/server.api.md +++ b/src/core/server/server.api.md @@ -458,7 +458,6 @@ export interface SavedObjectsBulkCreateObject { // @public (undocumented) export interface SavedObjectsCreateOptions extends SavedObjectsBaseOptions { id?: string; - // (undocumented) migrationVersion?: SavedObjectsMigrationVersion; overwrite?: boolean; // (undocumented) From 18f3f36e56a1e6d4eed97e7de4f31395da8bc312 Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Wed, 31 Jul 2019 14:03:44 +0200 Subject: [PATCH 19/29] Refactor request into savedObjectFetch + test --- .../saved_objects_client.test.ts | 25 +++++++++ .../saved_objects/saved_objects_client.ts | 53 +++++++------------ 2 files changed, 44 insertions(+), 34 deletions(-) diff --git a/src/core/public/saved_objects/saved_objects_client.test.ts b/src/core/public/saved_objects/saved_objects_client.test.ts index 9fc66aeca2451..62986e2c57724 100644 --- a/src/core/public/saved_objects/saved_objects_client.test.ts +++ b/src/core/public/saved_objects/saved_objects_client.test.ts @@ -411,4 +411,29 @@ describe('SavedObjectsClient', () => { `); }); }); + + 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", + }, + "response": Object { + "ok": false, + "redirected": false, + "status": 409, + "statusText": "Conflict", + }, + } + `); + }); }); diff --git a/src/core/public/saved_objects/saved_objects_client.ts b/src/core/public/saved_objects/saved_objects_client.ts index 2eb29d3aad9ef..02090acb98298 100644 --- a/src/core/public/saved_objects/saved_objects_client.ts +++ b/src/core/public/saved_objects/saved_objects_client.ts @@ -34,7 +34,7 @@ import { showAutoCreateIndexErrorPage, } from '../../../legacy/ui/public/error_auto_create_index/error_auto_create_index'; import { SimpleSavedObject } from './simple_saved_object'; -import { HttpFetchQuery, HttpSetup } from '../http'; +import { HttpSetup, HttpFetchOptions } from '../http'; type SavedObjectsFindOptions = Omit; @@ -50,13 +50,6 @@ export { type PromiseType> = T extends Promise ? U : never; -interface RequestParams { - method: 'POST' | 'GET' | 'PUT' | 'DELETE'; - path: string; - query?: HttpFetchQuery; - body?: object; -} - /** @public */ export interface SavedObjectsCreateOptions { /** @@ -211,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 @@ -248,11 +240,10 @@ export class SavedObjectsClient { const path = this.getPath(['_bulk_create']); 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)); @@ -275,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' }); }; /** @@ -311,9 +302,8 @@ export class SavedObjectsClient { options ); - const request: ReturnType = this.request({ + const request: ReturnType = this.savedObjectsFetch(path, { method: 'GET', - path, query, }); return request.then(resp => { @@ -370,10 +360,9 @@ 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)); @@ -413,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); }); @@ -432,16 +420,13 @@ 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 this.http.fetch(path, { method, query, body: JSON.stringify(body) }).catch(err => { - // To ensure we don't break backwards compatibility, we keep the old - // kfetch error format of `{res: {status: number}}` whereas `http.fetch` - // uses `{response: {status: number}}` - + /** + * 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 }); return Promise.reject(kfetchError); }); From a1e8858242adcf13dff19fc982c9f3f95424b6a1 Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Wed, 31 Jul 2019 14:05:47 +0200 Subject: [PATCH 20/29] Make legacy SavedObject compatible with http.fetch exceptions --- src/legacy/ui/public/saved_objects/saved_object.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/legacy/ui/public/saved_objects/saved_object.js b/src/legacy/ui/public/saved_objects/saved_object.js index 28ae065dbd986..d04b00ce81ee8 100644 --- a/src/legacy/ui/public/saved_objects/saved_object.js +++ b/src/legacy/ui/public/saved_objects/saved_object.js @@ -396,7 +396,7 @@ export function SavedObjectProvider(Promise, Private, confirmModalPromise, index return savedObjectsClient.create(esType, source, options) .catch(err => { // record exists, confirm overwriting - if (_.get(err, 'res.status') === 409) { + if (_.get(err, 'response.status') === 409) { const confirmMessage = i18n.translate('common.ui.savedObjects.confirmModal.overwriteConfirmationMessage', { defaultMessage: 'Are you sure you want to overwrite {title}?', values: { title: this.title } From 6011cbda3a42253c04c0e7204e0b28e55f55ebcf Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Thu, 1 Aug 2019 10:39:45 +0200 Subject: [PATCH 21/29] Fix types and tests --- src/legacy/ui/public/index_patterns/_index_pattern.ts | 9 +++++---- src/legacy/ui/public/index_patterns/index_patterns.ts | 7 +++---- .../ui/public/saved_objects/__tests__/saved_object.js | 2 +- .../ui/public/saved_objects/find_object_by_title.ts | 6 +++--- 4 files changed, 12 insertions(+), 12 deletions(-) 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__/saved_object.js b/src/legacy/ui/public/saved_objects/__tests__/saved_object.js index bbb7580c0a5a3..a18113f546bc0 100644 --- a/src/legacy/ui/public/saved_objects/__tests__/saved_object.js +++ b/src/legacy/ui/public/saved_objects/__tests__/saved_object.js @@ -82,7 +82,7 @@ describe('Saved Object', function () { } const mock409FetchError = { - res: { status: 409 } + response: { status: 409 } }; beforeEach(ngMock.module( 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 435d1ea1fbb82..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 'src/core/public'; +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> { From 6119a33232790fb2b631535405e0a9445e30fc8d Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Thu, 1 Aug 2019 16:05:50 +0200 Subject: [PATCH 22/29] simple_saved_object import from src/core/server --- src/core/public/saved_objects/simple_saved_object.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/public/saved_objects/simple_saved_object.ts b/src/core/public/saved_objects/simple_saved_object.ts index 8f342f72c60ee..92c228edd5e8e 100644 --- a/src/core/public/saved_objects/simple_saved_object.ts +++ b/src/core/public/saved_objects/simple_saved_object.ts @@ -18,7 +18,7 @@ */ import { get, has, set } from 'lodash'; -import { SavedObject as SavedObjectType, SavedObjectAttributes } from '../../server/types'; +import { SavedObject as SavedObjectType, SavedObjectAttributes } from '../../server'; import { SavedObjectsClient } from './saved_objects_client'; /** From fc3bfa6341f876fd6f080e697256977761a7cb94 Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Thu, 1 Aug 2019 16:13:15 +0200 Subject: [PATCH 23/29] server imports from root instead of server/types --- .eslintrc.js | 1 - src/core/public/saved_objects/index.ts | 16 +++++++++------- .../public/saved_objects/saved_objects_client.ts | 13 ++----------- 3 files changed, 11 insertions(+), 19 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index c413f27ba454d..5ff1aba1f3ff7 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -146,7 +146,6 @@ module.exports = { 'src/core/server/**/*', '!src/core/server/index.ts', '!src/core/server/mocks.ts', - '!src/core/server/types.ts', '!src/core/server/*.test.mocks.ts', 'src/plugins/**/public/**/*', diff --git a/src/core/public/saved_objects/index.ts b/src/core/public/saved_objects/index.ts index a5f049a001f61..5a95f1115f222 100644 --- a/src/core/public/saved_objects/index.ts +++ b/src/core/public/saved_objects/index.ts @@ -18,21 +18,23 @@ */ export { - SavedObject, - SavedObjectAttribute, - SavedObjectAttributes, - SavedObjectReference, SavedObjectsBatchResponse, - SavedObjectsBaseOptions, SavedObjectsBulkCreateObject, SavedObjectsBulkCreateOptions, SavedObjectsClient, SavedObjectsClientContract, SavedObjectsCreateOptions, - SavedObjectsFindOptions, SavedObjectsFindResponse, - SavedObjectsMigrationVersion, 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.ts b/src/core/public/saved_objects/saved_objects_client.ts index 02090acb98298..2b7adcbce8e47 100644 --- a/src/core/public/saved_objects/saved_objects_client.ts +++ b/src/core/public/saved_objects/saved_objects_client.ts @@ -27,7 +27,8 @@ import { SavedObjectsClientContract as SavedObjectsApi, SavedObjectsFindOptions as SavedObjectFindOptionsServer, SavedObjectsMigrationVersion, -} from '../../server/types'; +} from '../../server'; + // TODO: Migrate to an error modal powered by the NP? import { isAutoCreateIndexError, @@ -38,16 +39,6 @@ import { HttpSetup, HttpFetchOptions } from '../http'; type SavedObjectsFindOptions = Omit; -export { - SavedObject, - SavedObjectAttribute, - SavedObjectAttributes, - SavedObjectReference, - SavedObjectsBaseOptions, - SavedObjectsFindOptions, - SavedObjectsMigrationVersion, -} from '../../server/types'; - type PromiseType> = T extends Promise ? U : never; /** @public */ From ed9a17ce05ac0860b861e2f140769cfa103ab570 Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Mon, 5 Aug 2019 12:47:45 +0200 Subject: [PATCH 24/29] Make SavedObjectsService a class --- ...public.savedobjectsclient.(constructor).md | 20 ------------------- ...kibana-plugin-public.savedobjectsclient.md | 10 ++++------ src/core/public/core_system.ts | 4 +++- src/core/public/public.api.md | 3 ++- .../saved_objects/saved_objects_client.ts | 7 ++++--- .../saved_objects_service.mock.ts | 2 +- .../saved_objects/saved_objects_service.ts | 13 ++++++------ 7 files changed, 21 insertions(+), 38 deletions(-) delete mode 100644 docs/development/core/public/kibana-plugin-public.savedobjectsclient.(constructor).md diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsclient.(constructor).md b/docs/development/core/public/kibana-plugin-public.savedobjectsclient.(constructor).md deleted file mode 100644 index 8b04196536c18..0000000000000 --- a/docs/development/core/public/kibana-plugin-public.savedobjectsclient.(constructor).md +++ /dev/null @@ -1,20 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObjectsClient](./kibana-plugin-public.savedobjectsclient.md) > [(constructor)](./kibana-plugin-public.savedobjectsclient.(constructor).md) - -## SavedObjectsClient.(constructor) - -Constructs a new instance of the `SavedObjectsClient` class - -Signature: - -```typescript -constructor(http: HttpSetup); -``` - -## Parameters - -| Parameter | Type | Description | -| --- | --- | --- | -| http | HttpSetup | | - diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsclient.md b/docs/development/core/public/kibana-plugin-public.savedobjectsclient.md index 10384e708628e..1b846a3d35d14 100644 --- a/docs/development/core/public/kibana-plugin-public.savedobjectsclient.md +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsclient.md @@ -12,12 +12,6 @@ Saved Objects is Kibana's data persisentence mechanism allowing plugins to use E export declare class SavedObjectsClient ``` -## Constructors - -| Constructor | Modifiers | Description | -| --- | --- | --- | -| [(constructor)(http)](./kibana-plugin-public.savedobjectsclient.(constructor).md) | | Constructs a new instance of the SavedObjectsClient class | - ## Properties | Property | Modifiers | Type | Description | @@ -35,3 +29,7 @@ export declare class SavedObjectsClient | --- | --- | --- | | [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/src/core/public/core_system.ts b/src/core/public/core_system.ts index d9da6db0e9d6d..c26ced7fbfe9e 100644 --- a/src/core/public/core_system.ts +++ b/src/core/public/core_system.ts @@ -67,6 +67,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; @@ -104,6 +105,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(); @@ -169,7 +171,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 SavedObjectsService.start({ http }); + const savedObjects = await this.savedObjects.start({ http }); const i18n = await this.i18n.start(); const application = await this.application.start({ injectedMetadata }); diff --git a/src/core/public/public.api.md b/src/core/public/public.api.md index 39524d7ffee0e..eb2443e4e319d 100644 --- a/src/core/public/public.api.md +++ b/src/core/public/public.api.md @@ -665,7 +665,8 @@ export interface SavedObjectsBulkCreateOptions { // @public export class SavedObjectsClient { - constructor(http: HttpSetup); + // @internal + constructor(http: HttpServiceBase); bulkCreate: (objects?: SavedObjectsBulkCreateObject[], options?: SavedObjectsBulkCreateOptions) => Promise>; bulkGet: (objects?: { id: string; diff --git a/src/core/public/saved_objects/saved_objects_client.ts b/src/core/public/saved_objects/saved_objects_client.ts index 2b7adcbce8e47..63eb094042f5e 100644 --- a/src/core/public/saved_objects/saved_objects_client.ts +++ b/src/core/public/saved_objects/saved_objects_client.ts @@ -35,7 +35,7 @@ import { showAutoCreateIndexErrorPage, } from '../../../legacy/ui/public/error_auto_create_index/error_auto_create_index'; import { SimpleSavedObject } from './simple_saved_object'; -import { HttpSetup, HttpFetchOptions } from '../http'; +import { HttpFetchOptions, HttpServiceBase } from '../http'; type SavedObjectsFindOptions = Omit; @@ -133,7 +133,7 @@ export type SavedObjectsClientContract = PublicMethodsOf; * @public */ export class SavedObjectsClient { - private http: HttpSetup; + private http: HttpServiceBase; private batchQueue: BatchQueueEntry[]; /** @@ -168,7 +168,8 @@ export class SavedObjectsClient { { leading: false } ); - constructor(http: HttpSetup) { + /** @internal */ + constructor(http: HttpServiceBase) { this.http = http; this.batchQueue = []; } diff --git a/src/core/public/saved_objects/saved_objects_service.mock.ts b/src/core/public/saved_objects/saved_objects_service.mock.ts index e280ce69f8b71..feace09806a97 100644 --- a/src/core/public/saved_objects/saved_objects_service.mock.ts +++ b/src/core/public/saved_objects/saved_objects_service.mock.ts @@ -35,7 +35,7 @@ const createStartContractMock = () => { }; const createMock = () => { - const mocked: jest.Mocked = { + const mocked: jest.Mocked = { setup: jest.fn(), start: jest.fn(), stop: jest.fn(), diff --git a/src/core/public/saved_objects/saved_objects_service.ts b/src/core/public/saved_objects/saved_objects_service.ts index 33e2796f52d87..bb91c6f340c0b 100644 --- a/src/core/public/saved_objects/saved_objects_service.ts +++ b/src/core/public/saved_objects/saved_objects_service.ts @@ -18,6 +18,7 @@ */ import { CoreService } from 'src/core/types'; +import { CoreStart } from 'src/core/public'; import { SavedObjectsClient, SavedObjectsClientContract } from './saved_objects_client'; /** @@ -28,10 +29,10 @@ export interface SavedObjectsStart { client: SavedObjectsClientContract; } -export const SavedObjectsService: CoreService = { - setup: async function setup() {}, - start: async function start({ http }) { +export class SavedObjectsService implements CoreService { + public async setup() {} + public async start({ http }: { http: CoreStart['http'] }): Promise { return { client: new SavedObjectsClient(http) }; - }, - stop: async function stop() {}, -}; + } + public async stop() {} +} From f783b7839d8df242fd0149da87df7314f2ba1f39 Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Mon, 5 Aug 2019 14:04:46 +0200 Subject: [PATCH 25/29] Don't pick unkown keys from server response --- .../saved_objects/saved_objects_client.ts | 51 ++++++++----------- 1 file changed, 22 insertions(+), 29 deletions(-) diff --git a/src/core/public/saved_objects/saved_objects_client.ts b/src/core/public/saved_objects/saved_objects_client.ts index 63eb094042f5e..4287cf541e8a8 100644 --- a/src/core/public/saved_objects/saved_objects_client.ts +++ b/src/core/public/saved_objects/saved_objects_client.ts @@ -239,7 +239,7 @@ export class SavedObjectsClient { }); return request.then(resp => { resp.saved_objects = resp.saved_objects.map(d => this.createSavedObject(d)); - return pickAndRenameKeys< + return renameKeys< PromiseType>, SavedObjectsBatchResponse >({ saved_objects: 'savedObjects' }, resp) as SavedObjectsBatchResponse; @@ -279,20 +279,20 @@ export class SavedObjectsClient { options: SavedObjectsFindOptions = {} ): Promise> => { const path = this.getPath(['_find']); - const query = pickAndRenameKeys( - { - defaultSearchOperator: 'default_search_operator', - fields: 'fields', - hasReference: 'has_reference', - page: 'page', - perPage: 'per_page', - search: 'search', - searchFields: 'search_fields', - sortField: 'sort_field', - type: 'type', - }, - 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.savedObjectsFetch(path, { method: 'GET', @@ -300,10 +300,7 @@ export class SavedObjectsClient { }); return request.then(resp => { resp.saved_objects = resp.saved_objects.map(d => this.createSavedObject(d)); - return pickAndRenameKeys< - PromiseType>, - SavedObjectsFindResponse - >( + return renameKeys>, SavedObjectsFindResponse>( { saved_objects: 'savedObjects', total: 'total', @@ -358,7 +355,7 @@ export class SavedObjectsClient { }); return request.then(resp => { resp.saved_objects = resp.saved_objects.map(d => this.createSavedObject(d)); - return pickAndRenameKeys< + return renameKeys< PromiseType>, SavedObjectsBatchResponse >({ saved_objects: 'savedObjects' }, resp) as SavedObjectsBatchResponse; @@ -429,20 +426,16 @@ export class SavedObjectsClient { * Returns a new object with the own properties of `obj`, but the * keys renamed according to the `keysMap`. * - * If a key is not found in `keysMap` it is omitted from the result. - * * @param keysMap - a map of the form `{oldKey: newKey}` * @param obj - the object whose own properties will be renamed */ -const pickAndRenameKeys = , U extends Record>( +const renameKeys = , U extends Record>( keysMap: Record, obj: Record ) => Object.keys(obj).reduce((acc, key) => { - return typeof keysMap[key] === 'undefined' - ? acc - : { - ...acc, - ...{ [keysMap[key]]: obj[key] }, - }; + return { + ...acc, + ...{ [keysMap[key] || key]: obj[key] }, + }; }, {}); From 53f68004654028b25878ced7792ed9f06773d4c3 Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Mon, 5 Aug 2019 14:20:19 +0200 Subject: [PATCH 26/29] Rename SavedObjectsFindResponse to SavedObjectsFindResponsePublic --- .../core/public/kibana-plugin-public.md | 2 +- ...a-plugin-public.savedobjectsclient.find.md | 2 +- ...kibana-plugin-public.savedobjectsclient.md | 2 +- ...-plugin-public.savedobjectsfindresponse.md | 21 ---------------- ...in-public.savedobjectsfindresponse.page.md | 11 --------- ...public.savedobjectsfindresponse.perpage.md | 11 --------- ...n-public.savedobjectsfindresponse.total.md | 11 --------- ...n-public.savedobjectsfindresponsepublic.md | 24 +++++++++++++++++++ ...lic.savedobjectsfindresponsepublic.page.md | 11 +++++++++ ....savedobjectsfindresponsepublic.perpage.md | 11 +++++++++ ...ic.savedobjectsfindresponsepublic.total.md | 11 +++++++++ .../core/server/kibana-plugin-server.md | 2 +- ...-plugin-server.savedobjectsfindresponse.md | 3 +++ src/core/public/index.ts | 2 +- src/core/public/public.api.md | 6 ++--- src/core/public/saved_objects/index.ts | 2 +- .../saved_objects/saved_objects_client.ts | 23 +++++++++++++----- .../service/saved_objects_client.ts | 4 ++++ src/core/server/server.api.md | 2 +- 19 files changed, 91 insertions(+), 70 deletions(-) delete mode 100644 docs/development/core/public/kibana-plugin-public.savedobjectsfindresponse.md delete mode 100644 docs/development/core/public/kibana-plugin-public.savedobjectsfindresponse.page.md delete mode 100644 docs/development/core/public/kibana-plugin-public.savedobjectsfindresponse.perpage.md delete mode 100644 docs/development/core/public/kibana-plugin-public.savedobjectsfindresponse.total.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 diff --git a/docs/development/core/public/kibana-plugin-public.md b/docs/development/core/public/kibana-plugin-public.md index 797c47daece64..858f3a1713910 100644 --- a/docs/development/core/public/kibana-plugin-public.md +++ b/docs/development/core/public/kibana-plugin-public.md @@ -70,7 +70,7 @@ The plugin integrates with the core system via lifecycle events: `setup` | [SavedObjectsBulkCreateOptions](./kibana-plugin-public.savedobjectsbulkcreateoptions.md) | | | [SavedObjectsCreateOptions](./kibana-plugin-public.savedobjectscreateoptions.md) | | | [SavedObjectsFindOptions](./kibana-plugin-public.savedobjectsfindoptions.md) | | -| [SavedObjectsFindResponse](./kibana-plugin-public.savedobjectsfindresponse.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) | | diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsclient.find.md b/docs/development/core/public/kibana-plugin-public.savedobjectsclient.find.md index 0d30ee1954624..20b9ff35779f9 100644 --- a/docs/development/core/public/kibana-plugin-public.savedobjectsclient.find.md +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsclient.find.md @@ -9,5 +9,5 @@ Search for objects Signature: ```typescript -find: (options?: Pick) => Promise>; +find: (options?: Pick) => Promise>; ``` diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsclient.md b/docs/development/core/public/kibana-plugin-public.savedobjectsclient.md index 1b846a3d35d14..d0de26bb9b0a1 100644 --- a/docs/development/core/public/kibana-plugin-public.savedobjectsclient.md +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsclient.md @@ -20,7 +20,7 @@ export declare class SavedObjectsClient | [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<SavedObjectsFindResponse<T>> | Search for objects | +| [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 diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsfindresponse.md b/docs/development/core/public/kibana-plugin-public.savedobjectsfindresponse.md deleted file mode 100644 index 548c9ed3b05b9..0000000000000 --- a/docs/development/core/public/kibana-plugin-public.savedobjectsfindresponse.md +++ /dev/null @@ -1,21 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObjectsFindResponse](./kibana-plugin-public.savedobjectsfindresponse.md) - -## SavedObjectsFindResponse interface - - -Signature: - -```typescript -export interface SavedObjectsFindResponse extends SavedObjectsBatchResponse -``` - -## Properties - -| Property | Type | Description | -| --- | --- | --- | -| [page](./kibana-plugin-public.savedobjectsfindresponse.page.md) | number | | -| [perPage](./kibana-plugin-public.savedobjectsfindresponse.perpage.md) | number | | -| [total](./kibana-plugin-public.savedobjectsfindresponse.total.md) | number | | - diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsfindresponse.page.md b/docs/development/core/public/kibana-plugin-public.savedobjectsfindresponse.page.md deleted file mode 100644 index ce02d6c8c499f..0000000000000 --- a/docs/development/core/public/kibana-plugin-public.savedobjectsfindresponse.page.md +++ /dev/null @@ -1,11 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObjectsFindResponse](./kibana-plugin-public.savedobjectsfindresponse.md) > [page](./kibana-plugin-public.savedobjectsfindresponse.page.md) - -## SavedObjectsFindResponse.page property - -Signature: - -```typescript -page: number; -``` diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsfindresponse.perpage.md b/docs/development/core/public/kibana-plugin-public.savedobjectsfindresponse.perpage.md deleted file mode 100644 index 5cc6d1ca4903a..0000000000000 --- a/docs/development/core/public/kibana-plugin-public.savedobjectsfindresponse.perpage.md +++ /dev/null @@ -1,11 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObjectsFindResponse](./kibana-plugin-public.savedobjectsfindresponse.md) > [perPage](./kibana-plugin-public.savedobjectsfindresponse.perpage.md) - -## SavedObjectsFindResponse.perPage property - -Signature: - -```typescript -perPage: number; -``` diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsfindresponse.total.md b/docs/development/core/public/kibana-plugin-public.savedobjectsfindresponse.total.md deleted file mode 100644 index 67afdfaf4a734..0000000000000 --- a/docs/development/core/public/kibana-plugin-public.savedobjectsfindresponse.total.md +++ /dev/null @@ -1,11 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [SavedObjectsFindResponse](./kibana-plugin-public.savedobjectsfindresponse.md) > [total](./kibana-plugin-public.savedobjectsfindresponse.total.md) - -## SavedObjectsFindResponse.total property - -Signature: - -```typescript -total: number; -``` 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/server/kibana-plugin-server.md b/docs/development/core/server/kibana-plugin-server.md index 510bc052dbd41..bf14590f3032f 100644 --- a/docs/development/core/server/kibana-plugin-server.md +++ b/docs/development/core/server/kibana-plugin-server.md @@ -73,7 +73,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. | 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/src/core/public/index.ts b/src/core/public/index.ts index 781c66ebcf28a..8966668070690 100644 --- a/src/core/public/index.ts +++ b/src/core/public/index.ts @@ -76,7 +76,7 @@ export { SavedObjectsBulkCreateObject, SavedObjectsBulkCreateOptions, SavedObjectsCreateOptions, - SavedObjectsFindResponse, + SavedObjectsFindResponsePublic, SavedObjectsUpdateOptions, SavedObject, SavedObjectAttribute, diff --git a/src/core/public/public.api.md b/src/core/public/public.api.md index eb2443e4e319d..722c69cf2f36f 100644 --- a/src/core/public/public.api.md +++ b/src/core/public/public.api.md @@ -674,7 +674,7 @@ export class SavedObjectsClient { }[]) => Promise>; create: (type: string, attributes: T, options?: SavedObjectsCreateOptions) => Promise>; delete: (type: string, id: string) => Promise<{}>; - find: (options?: Pick) => Promise>; + find: (options?: Pick) => Promise>; get: (type: string, id: string) => Promise>; update(type: string, id: string, attributes: T, { version, migrationVersion, references }?: SavedObjectsUpdateOptions): Promise>; } @@ -715,8 +715,8 @@ export interface SavedObjectsFindOptions extends SavedObjectsBaseOptions { type?: string | string[]; } -// @public (undocumented) -export interface SavedObjectsFindResponse extends SavedObjectsBatchResponse { +// @public +export interface SavedObjectsFindResponsePublic extends SavedObjectsBatchResponse { // (undocumented) page: number; // (undocumented) diff --git a/src/core/public/saved_objects/index.ts b/src/core/public/saved_objects/index.ts index 5a95f1115f222..f82112c7a65bd 100644 --- a/src/core/public/saved_objects/index.ts +++ b/src/core/public/saved_objects/index.ts @@ -24,7 +24,7 @@ export { SavedObjectsClient, SavedObjectsClientContract, SavedObjectsCreateOptions, - SavedObjectsFindResponse, + SavedObjectsFindResponsePublic, SavedObjectsUpdateOptions, } from './saved_objects_client'; export { SimpleSavedObject } from './simple_saved_object'; diff --git a/src/core/public/saved_objects/saved_objects_client.ts b/src/core/public/saved_objects/saved_objects_client.ts index 4287cf541e8a8..de4154474616e 100644 --- a/src/core/public/saved_objects/saved_objects_client.ts +++ b/src/core/public/saved_objects/saved_objects_client.ts @@ -88,9 +88,17 @@ export interface SavedObjectsBatchResponse< savedObjects: Array>; } -/** @public */ -export interface SavedObjectsFindResponse - extends SavedObjectsBatchResponse { +/** + * 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; @@ -277,7 +285,7 @@ export class SavedObjectsClient { */ public find = ( options: SavedObjectsFindOptions = {} - ): Promise> => { + ): Promise> => { const path = this.getPath(['_find']); const renameMap = { defaultSearchOperator: 'default_search_operator', @@ -300,7 +308,10 @@ export class SavedObjectsClient { }); return request.then(resp => { resp.saved_objects = resp.saved_objects.map(d => this.createSavedObject(d)); - return renameKeys>, SavedObjectsFindResponse>( + return renameKeys< + PromiseType>, + SavedObjectsFindResponsePublic + >( { saved_objects: 'savedObjects', total: 'total', @@ -308,7 +319,7 @@ export class SavedObjectsClient { page: 'page', }, resp - ) as SavedObjectsFindResponse; + ) as SavedObjectsFindResponsePublic; }); }; 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 3b1a0beef40da..039579c5a2d14 100644 --- a/src/core/server/saved_objects/service/saved_objects_client.ts +++ b/src/core/server/saved_objects/service/saved_objects_client.ts @@ -66,6 +66,10 @@ export interface SavedObjectsBulkResponse } /** + * Return type of the Saved Objects `find()` method. + * + * *Note*: this type is different between the Public and Server Saved Objects + * clients. * * @public */ diff --git a/src/core/server/server.api.md b/src/core/server/server.api.md index 09aef5cd33667..9f5d143220e27 100644 --- a/src/core/server/server.api.md +++ b/src/core/server/server.api.md @@ -741,7 +741,7 @@ export interface SavedObjectsFindOptions extends SavedObjectsBaseOptions { type?: string | string[]; } -// @public (undocumented) +// @public export interface SavedObjectsFindResponse { // (undocumented) page: number; From 61705ca3611bccefe12e0a6569f7c3b8c6abaa67 Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Mon, 5 Aug 2019 14:35:55 +0200 Subject: [PATCH 27/29] Remove err.response from SavedObjects fetch errors --- src/core/public/saved_objects/saved_objects_client.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/core/public/saved_objects/saved_objects_client.ts b/src/core/public/saved_objects/saved_objects_client.ts index de4154474616e..eca73e8dab8e2 100644 --- a/src/core/public/saved_objects/saved_objects_client.ts +++ b/src/core/public/saved_objects/saved_objects_client.ts @@ -423,11 +423,15 @@ export class SavedObjectsClient { /** * 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}}` + * uses `{response: {status: number}}`. + * + * TODO: Introduce error helper functions to make it easier to change + * the internal shape of errors. */ 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); }); } From 2f3976bc5b95a57f5a90a1a8b1b20ecd904ca0c5 Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Mon, 5 Aug 2019 15:07:54 +0200 Subject: [PATCH 28/29] Revert "Remove err.response from SavedObjects fetch errors" This reverts commit 61705ca3611bccefe12e0a6569f7c3b8c6abaa67. --- src/core/public/saved_objects/saved_objects_client.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/core/public/saved_objects/saved_objects_client.ts b/src/core/public/saved_objects/saved_objects_client.ts index eca73e8dab8e2..de4154474616e 100644 --- a/src/core/public/saved_objects/saved_objects_client.ts +++ b/src/core/public/saved_objects/saved_objects_client.ts @@ -423,15 +423,11 @@ export class SavedObjectsClient { /** * 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}}`. - * - * TODO: Introduce error helper functions to make it easier to change - * the internal shape of errors. + * 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); }); } From 92582b914b311363eed1e9b171ede39360958865 Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Mon, 5 Aug 2019 15:31:37 +0200 Subject: [PATCH 29/29] Don't introduce err.response until we deprecate err.res --- src/core/public/saved_objects/saved_objects_client.test.ts | 6 ------ src/core/public/saved_objects/saved_objects_client.ts | 3 ++- .../ui/public/saved_objects/__tests__/saved_object.js | 2 +- src/legacy/ui/public/saved_objects/saved_object.js | 2 +- 4 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/core/public/saved_objects/saved_objects_client.test.ts b/src/core/public/saved_objects/saved_objects_client.test.ts index 62986e2c57724..4c0fe90a5bfbd 100644 --- a/src/core/public/saved_objects/saved_objects_client.test.ts +++ b/src/core/public/saved_objects/saved_objects_client.test.ts @@ -427,12 +427,6 @@ describe('SavedObjectsClient', () => { "status": 409, "statusText": "Conflict", }, - "response": Object { - "ok": false, - "redirected": false, - "status": 409, - "statusText": "Conflict", - }, } `); }); diff --git a/src/core/public/saved_objects/saved_objects_client.ts b/src/core/public/saved_objects/saved_objects_client.ts index de4154474616e..b0768826159cc 100644 --- a/src/core/public/saved_objects/saved_objects_client.ts +++ b/src/core/public/saved_objects/saved_objects_client.ts @@ -423,11 +423,12 @@ export class SavedObjectsClient { /** * 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}}` + * 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); }); } diff --git a/src/legacy/ui/public/saved_objects/__tests__/saved_object.js b/src/legacy/ui/public/saved_objects/__tests__/saved_object.js index a18113f546bc0..bbb7580c0a5a3 100644 --- a/src/legacy/ui/public/saved_objects/__tests__/saved_object.js +++ b/src/legacy/ui/public/saved_objects/__tests__/saved_object.js @@ -82,7 +82,7 @@ describe('Saved Object', function () { } const mock409FetchError = { - response: { status: 409 } + res: { status: 409 } }; beforeEach(ngMock.module( diff --git a/src/legacy/ui/public/saved_objects/saved_object.js b/src/legacy/ui/public/saved_objects/saved_object.js index d04b00ce81ee8..28ae065dbd986 100644 --- a/src/legacy/ui/public/saved_objects/saved_object.js +++ b/src/legacy/ui/public/saved_objects/saved_object.js @@ -396,7 +396,7 @@ export function SavedObjectProvider(Promise, Private, confirmModalPromise, index return savedObjectsClient.create(esType, source, options) .catch(err => { // record exists, confirm overwriting - if (_.get(err, 'response.status') === 409) { + if (_.get(err, 'res.status') === 409) { const confirmMessage = i18n.translate('common.ui.savedObjects.confirmModal.overwriteConfirmationMessage', { defaultMessage: 'Are you sure you want to overwrite {title}?', values: { title: this.title }