Use explicit interface for SavedObjectsClientContract (#132795)

* No explicit interface for `SavedObjectsClientContract`

* fix doc, do not export the client class

* fix doc more

* fix import from plugins

* fix import from plugins bis

* update generated doc
This commit is contained in:
Pierre Gayvallet 2022-05-25 16:51:16 +02:00 committed by GitHub
parent c51fb17e4c
commit 4043c33be1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
36 changed files with 448 additions and 337 deletions

View file

@ -14,9 +14,8 @@ The plugin integrates with the core system via lifecycle events: `setup`<!-- -->
| Class | Description |
| --- | --- |
| [SavedObjectsClient](./kibana-plugin-core-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. |
| [ScopedHistory](./kibana-plugin-core-public.scopedhistory.md) | A wrapper around a <code>History</code> instance that is scoped to a particular base path of the history stack. Behaves similarly to the <code>basename</code> option except that this wrapper hides any history stack entries from outside the scope of this base path.<!-- -->This wrapper also allows Core and Plugins to share a single underlying global <code>History</code> instance without exposing the history of other applications.<!-- -->The [createSubHistory](./kibana-plugin-core-public.scopedhistory.createsubhistory.md) method is particularly useful for applications that contain any number of "sub-apps" which should not have access to the main application's history or basePath. |
| [SimpleSavedObject](./kibana-plugin-core-public.simplesavedobject.md) | This class is a very simple wrapper for SavedObjects loaded from the server with the [SavedObjectsClient](./kibana-plugin-core-public.savedobjectsclient.md)<!-- -->.<!-- -->It provides basic functionality for creating/saving/deleting saved objects, but doesn't include any type-specific implementations. |
| [SimpleSavedObject](./kibana-plugin-core-public.simplesavedobject.md) | This class is a very simple wrapper for SavedObjects loaded from the server with the [SavedObjectsClientContract](./kibana-plugin-core-public.savedobjectsclientcontract.md)<!-- -->.<!-- -->It provides basic functionality for creating/saving/deleting saved objects, but doesn't include any type-specific implementations. |
| [ToastsApi](./kibana-plugin-core-public.toastsapi.md) | Methods for adding and removing global toast messages. |
## Enumerations
@ -98,7 +97,7 @@ The plugin integrates with the core system via lifecycle events: `setup`<!-- -->
| [OverlayStart](./kibana-plugin-core-public.overlaystart.md) | |
| [Plugin\_2](./kibana-plugin-core-public.plugin_2.md) | The interface that should be returned by a <code>PluginInitializer</code>. |
| [PluginInitializerContext](./kibana-plugin-core-public.plugininitializercontext.md) | The available core services passed to a <code>PluginInitializer</code> |
| [ResolvedSimpleSavedObject](./kibana-plugin-core-public.resolvedsimplesavedobject.md) | This interface is a very simple wrapper for SavedObjects resolved from the server with the [SavedObjectsClient](./kibana-plugin-core-public.savedobjectsclient.md)<!-- -->. |
| [ResolvedSimpleSavedObject](./kibana-plugin-core-public.resolvedsimplesavedobject.md) | This interface is a very simple wrapper for SavedObjects resolved from the server with the [SavedObjectsClientContract](./kibana-plugin-core-public.savedobjectsclientcontract.md)<!-- -->. |
| [ResponseErrorBody](./kibana-plugin-core-public.responseerrorbody.md) | |
| [SavedObject](./kibana-plugin-core-public.savedobject.md) | |
| [SavedObjectAttributes](./kibana-plugin-core-public.savedobjectattributes.md) | The data for a Saved Object is stored as an object in the <code>attributes</code> property. |
@ -113,6 +112,7 @@ The plugin integrates with the core system via lifecycle events: `setup`<!-- -->
| [SavedObjectsBulkResolveResponse](./kibana-plugin-core-public.savedobjectsbulkresolveresponse.md) | |
| [SavedObjectsBulkUpdateObject](./kibana-plugin-core-public.savedobjectsbulkupdateobject.md) | |
| [SavedObjectsBulkUpdateOptions](./kibana-plugin-core-public.savedobjectsbulkupdateoptions.md) | |
| [SavedObjectsClientContract](./kibana-plugin-core-public.savedobjectsclientcontract.md) | The client-side SavedObjectsClient is a thin convenience library around the SavedObjects HTTP API for interacting with Saved Objects. |
| [SavedObjectsCollectMultiNamespaceReferencesResponse](./kibana-plugin-core-public.savedobjectscollectmultinamespacereferencesresponse.md) | The response when object references are collected. |
| [SavedObjectsCreateOptions](./kibana-plugin-core-public.savedobjectscreateoptions.md) | |
| [SavedObjectsFindOptions](./kibana-plugin-core-public.savedobjectsfindoptions.md) | |
@ -178,7 +178,6 @@ The plugin integrates with the core system via lifecycle events: `setup`<!-- -->
| [ResolveDeprecationResponse](./kibana-plugin-core-public.resolvedeprecationresponse.md) | |
| [SavedObjectAttribute](./kibana-plugin-core-public.savedobjectattribute.md) | Type definition for a Saved Object attribute value |
| [SavedObjectAttributeSingle](./kibana-plugin-core-public.savedobjectattributesingle.md) | Don't use this type, it's simply a helper type for [SavedObjectAttribute](./kibana-plugin-core-public.savedobjectattribute.md) |
| [SavedObjectsClientContract](./kibana-plugin-core-public.savedobjectsclientcontract.md) | SavedObjectsClientContract as implemented by the [SavedObjectsClient](./kibana-plugin-core-public.savedobjectsclient.md) |
| [SavedObjectsImportWarning](./kibana-plugin-core-public.savedobjectsimportwarning.md) | Composite type of all the possible types of import warnings.<!-- -->See [SavedObjectsImportSimpleWarning](./kibana-plugin-core-public.savedobjectsimportsimplewarning.md) and [SavedObjectsImportActionRequiredWarning](./kibana-plugin-core-public.savedobjectsimportactionrequiredwarning.md) for more details. |
| [SavedObjectsNamespaceType](./kibana-plugin-core-public.savedobjectsnamespacetype.md) | The namespace type dictates how a saved object can be interacted in relation to namespaces. Each type is mutually exclusive: \* single (default): This type of saved object is namespace-isolated, e.g., it exists in only one namespace. \* multiple: This type of saved object is shareable, e.g., it can exist in one or more namespaces. \* multiple-isolated: This type of saved object is namespace-isolated, e.g., it exists in only one namespace, but object IDs must be unique across all namespaces. This is intended to be an intermediate step when objects with a "single" namespace type are being converted to a "multiple" namespace type. In other words, objects with a "multiple-isolated" namespace type will be \*share-capable\*, but will not actually be shareable until the namespace type is changed to "multiple". \* agnostic: This type of saved object is global. |
| [StartServicesAccessor](./kibana-plugin-core-public.startservicesaccessor.md) | Allows plugins to get access to APIs available in start inside async handlers, such as [App.mount](./kibana-plugin-core-public.app.mount.md)<!-- -->. Promise will not resolve until Core and plugin dependencies have completed <code>start</code>. |

View file

@ -4,7 +4,7 @@
## ResolvedSimpleSavedObject interface
This interface is a very simple wrapper for SavedObjects resolved from the server with the [SavedObjectsClient](./kibana-plugin-core-public.savedobjectsclient.md)<!-- -->.
This interface is a very simple wrapper for SavedObjects resolved from the server with the [SavedObjectsClientContract](./kibana-plugin-core-public.savedobjectsclientcontract.md)<!-- -->.
<b>Signature:</b>

View file

@ -15,5 +15,5 @@ export interface SavedObjectsBulkResolveResponse<T = unknown>
| Property | Type | Description |
| --- | --- | --- |
| [resolved\_objects](./kibana-plugin-core-public.savedobjectsbulkresolveresponse.resolved_objects.md) | Array&lt;SavedObjectsResolveResponse&lt;T&gt;&gt; | |
| [resolved\_objects](./kibana-plugin-core-public.savedobjectsbulkresolveresponse.resolved_objects.md) | Array&lt;ResolvedSimpleSavedObject&lt;T&gt;&gt; | |

View file

@ -7,5 +7,5 @@
<b>Signature:</b>
```typescript
resolved_objects: Array<SavedObjectsResolveResponse<T>>;
resolved_objects: Array<ResolvedSimpleSavedObject<T>>;
```

View file

@ -1,13 +0,0 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-core-public](./kibana-plugin-core-public.md) &gt; [SavedObjectsClient](./kibana-plugin-core-public.savedobjectsclient.md) &gt; [bulkCreate](./kibana-plugin-core-public.savedobjectsclient.bulkcreate.md)
## SavedObjectsClient.bulkCreate property
Creates multiple documents at once
<b>Signature:</b>
```typescript
bulkCreate: (objects?: SavedObjectsBulkCreateObject[], options?: SavedObjectsBulkCreateOptions) => Promise<SavedObjectsBatchResponse<unknown>>;
```

View file

@ -1,21 +0,0 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-core-public](./kibana-plugin-core-public.md) &gt; [SavedObjectsClient](./kibana-plugin-core-public.savedobjectsclient.md) &gt; [bulkGet](./kibana-plugin-core-public.savedobjectsclient.bulkget.md)
## SavedObjectsClient.bulkGet property
Returns an array of objects by id
<b>Signature:</b>
```typescript
bulkGet: (objects?: Array<{
id: string;
type: string;
}>) => Promise<SavedObjectsBatchResponse<unknown>>;
```
## Example
bulkGet(\[ { id: 'one', type: 'config' }<!-- -->, { id: 'foo', type: 'index-pattern' } \])

View file

@ -1,13 +0,0 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-core-public](./kibana-plugin-core-public.md) &gt; [SavedObjectsClient](./kibana-plugin-core-public.savedobjectsclient.md) &gt; [create](./kibana-plugin-core-public.savedobjectsclient.create.md)
## SavedObjectsClient.create property
Persists an object
<b>Signature:</b>
```typescript
create: <T = unknown>(type: string, attributes: T, options?: SavedObjectsCreateOptions) => Promise<SimpleSavedObject<T>>;
```

View file

@ -1,13 +0,0 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-core-public](./kibana-plugin-core-public.md) &gt; [SavedObjectsClient](./kibana-plugin-core-public.savedobjectsclient.md) &gt; [delete](./kibana-plugin-core-public.savedobjectsclient.delete.md)
## SavedObjectsClient.delete property
Deletes an object
<b>Signature:</b>
```typescript
delete: (type: string, id: string, options?: SavedObjectsDeleteOptions | undefined) => ReturnType<SavedObjectsApi['delete']>;
```

View file

@ -1,13 +0,0 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-core-public](./kibana-plugin-core-public.md) &gt; [SavedObjectsClient](./kibana-plugin-core-public.savedobjectsclient.md) &gt; [find](./kibana-plugin-core-public.savedobjectsclient.find.md)
## SavedObjectsClient.find property
Search for objects
<b>Signature:</b>
```typescript
find: <T = unknown, A = unknown>(options: SavedObjectsFindOptions) => Promise<SavedObjectsFindResponsePublic<T, unknown>>;
```

View file

@ -1,13 +0,0 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-core-public](./kibana-plugin-core-public.md) &gt; [SavedObjectsClient](./kibana-plugin-core-public.savedobjectsclient.md) &gt; [get](./kibana-plugin-core-public.savedobjectsclient.get.md)
## SavedObjectsClient.get property
Fetches a single object
<b>Signature:</b>
```typescript
get: <T = unknown>(type: string, id: string) => Promise<SimpleSavedObject<T>>;
```

View file

@ -1,38 +0,0 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-core-public](./kibana-plugin-core-public.md) &gt; [SavedObjectsClient](./kibana-plugin-core-public.savedobjectsclient.md)
## SavedObjectsClient class
Saved Objects is Kibana's data persisentence mechanism allowing plugins to use Elasticsearch for storing plugin state. The client-side SavedObjectsClient is a thin convenience library around the SavedObjects HTTP API for interacting with Saved Objects.
<b>Signature:</b>
```typescript
export declare class SavedObjectsClient
```
## 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.
## Properties
| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [bulkCreate](./kibana-plugin-core-public.savedobjectsclient.bulkcreate.md) | | (objects?: SavedObjectsBulkCreateObject\[\], options?: SavedObjectsBulkCreateOptions) =&gt; Promise&lt;SavedObjectsBatchResponse&lt;unknown&gt;&gt; | Creates multiple documents at once |
| [bulkGet](./kibana-plugin-core-public.savedobjectsclient.bulkget.md) | | (objects?: Array&lt;{ id: string; type: string; }&gt;) =&gt; Promise&lt;SavedObjectsBatchResponse&lt;unknown&gt;&gt; | Returns an array of objects by id |
| [bulkResolve](./kibana-plugin-core-public.savedobjectsclient.bulkresolve.md) | | &lt;T = unknown&gt;(objects?: Array&lt;{ id: string; type: string; }&gt;) =&gt; Promise&lt;{ resolved\_objects: ResolvedSimpleSavedObject&lt;T&gt;\[\]; }&gt; | Resolves an array of objects by id, using any legacy URL aliases if they exist |
| [create](./kibana-plugin-core-public.savedobjectsclient.create.md) | | &lt;T = unknown&gt;(type: string, attributes: T, options?: SavedObjectsCreateOptions) =&gt; Promise&lt;SimpleSavedObject&lt;T&gt;&gt; | Persists an object |
| [delete](./kibana-plugin-core-public.savedobjectsclient.delete.md) | | (type: string, id: string, options?: SavedObjectsDeleteOptions \| undefined) =&gt; ReturnType&lt;SavedObjectsApi\['delete'\]&gt; | Deletes an object |
| [find](./kibana-plugin-core-public.savedobjectsclient.find.md) | | &lt;T = unknown, A = unknown&gt;(options: SavedObjectsFindOptions) =&gt; Promise&lt;SavedObjectsFindResponsePublic&lt;T, unknown&gt;&gt; | Search for objects |
| [get](./kibana-plugin-core-public.savedobjectsclient.get.md) | | &lt;T = unknown&gt;(type: string, id: string) =&gt; Promise&lt;SimpleSavedObject&lt;T&gt;&gt; | Fetches a single object |
| [resolve](./kibana-plugin-core-public.savedobjectsclient.resolve.md) | | &lt;T = unknown&gt;(type: string, id: string) =&gt; Promise&lt;ResolvedSimpleSavedObject&lt;T&gt;&gt; | Resolves a single object |
## Methods
| Method | Modifiers | Description |
| --- | --- | --- |
| [bulkUpdate(objects)](./kibana-plugin-core-public.savedobjectsclient.bulkupdate.md) | | Update multiple documents at once |
| [update(type, id, attributes, { version, references, upsert })](./kibana-plugin-core-public.savedobjectsclient.update.md) | | Updates an object |

View file

@ -1,13 +0,0 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-core-public](./kibana-plugin-core-public.md) &gt; [SavedObjectsClient](./kibana-plugin-core-public.savedobjectsclient.md) &gt; [resolve](./kibana-plugin-core-public.savedobjectsclient.resolve.md)
## SavedObjectsClient.resolve property
Resolves a single object
<b>Signature:</b>
```typescript
resolve: <T = unknown>(type: string, id: string) => Promise<ResolvedSimpleSavedObject<T>>;
```

View file

@ -1,28 +0,0 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-core-public](./kibana-plugin-core-public.md) &gt; [SavedObjectsClient](./kibana-plugin-core-public.savedobjectsclient.md) &gt; [update](./kibana-plugin-core-public.savedobjectsclient.update.md)
## SavedObjectsClient.update() method
Updates an object
<b>Signature:</b>
```typescript
update<T = unknown>(type: string, id: string, attributes: T, { version, references, upsert }?: SavedObjectsUpdateOptions): Promise<SimpleSavedObject<T>>;
```
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| type | string | |
| id | string | |
| attributes | T | |
| { version, references, upsert } | SavedObjectsUpdateOptions | |
<b>Returns:</b>
Promise&lt;SimpleSavedObject&lt;T&gt;&gt;

View file

@ -0,0 +1,27 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-core-public](./kibana-plugin-core-public.md) &gt; [SavedObjectsClientContract](./kibana-plugin-core-public.savedobjectsclientcontract.md) &gt; [bulkCreate](./kibana-plugin-core-public.savedobjectsclientcontract.bulkcreate.md)
## SavedObjectsClientContract.bulkCreate() method
Creates multiple documents at once
<b>Signature:</b>
```typescript
bulkCreate(objects: SavedObjectsBulkCreateObject[], options?: SavedObjectsBulkCreateOptions): Promise<SavedObjectsBatchResponse<unknown>>;
```
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| objects | SavedObjectsBulkCreateObject\[\] | |
| options | SavedObjectsBulkCreateOptions | |
<b>Returns:</b>
Promise&lt;SavedObjectsBatchResponse&lt;unknown&gt;&gt;
The result of the create operation containing created saved objects.

View file

@ -0,0 +1,33 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-core-public](./kibana-plugin-core-public.md) &gt; [SavedObjectsClientContract](./kibana-plugin-core-public.savedobjectsclientcontract.md) &gt; [bulkGet](./kibana-plugin-core-public.savedobjectsclientcontract.bulkget.md)
## SavedObjectsClientContract.bulkGet() method
Returns an array of objects by id
<b>Signature:</b>
```typescript
bulkGet(objects: Array<{
id: string;
type: string;
}>): Promise<SavedObjectsBatchResponse<unknown>>;
```
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| objects | Array&lt;{ id: string; type: string; }&gt; | an array ids, or an array of objects containing id and optionally type |
<b>Returns:</b>
Promise&lt;SavedObjectsBatchResponse&lt;unknown&gt;&gt;
The saved objects with the given type and ids requested
## Example
bulkGet(\[ { id: 'one', type: 'config' }<!-- -->, { id: 'foo', type: 'index-pattern' } \])

View file

@ -1,22 +1,32 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-core-public](./kibana-plugin-core-public.md) &gt; [SavedObjectsClient](./kibana-plugin-core-public.savedobjectsclient.md) &gt; [bulkResolve](./kibana-plugin-core-public.savedobjectsclient.bulkresolve.md)
[Home](./index.md) &gt; [kibana-plugin-core-public](./kibana-plugin-core-public.md) &gt; [SavedObjectsClientContract](./kibana-plugin-core-public.savedobjectsclientcontract.md) &gt; [bulkResolve](./kibana-plugin-core-public.savedobjectsclientcontract.bulkresolve.md)
## SavedObjectsClient.bulkResolve property
## SavedObjectsClientContract.bulkResolve() method
Resolves an array of objects by id, using any legacy URL aliases if they exist
<b>Signature:</b>
```typescript
bulkResolve: <T = unknown>(objects?: Array<{
bulkResolve<T = unknown>(objects: Array<{
id: string;
type: string;
}>) => Promise<{
resolved_objects: ResolvedSimpleSavedObject<T>[];
}>;
}>): Promise<SavedObjectsBulkResolveResponse<T>>;
```
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| objects | Array&lt;{ id: string; type: string; }&gt; | an array of objects containing id, type |
<b>Returns:</b>
Promise&lt;SavedObjectsBulkResolveResponse&lt;T&gt;&gt;
The bulk resolve result for the saved objects for the given types and ids.
## Example
bulkResolve(\[ { id: 'one', type: 'config' }<!-- -->, { id: 'foo', type: 'index-pattern' } \])

View file

@ -1,15 +1,15 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-core-public](./kibana-plugin-core-public.md) &gt; [SavedObjectsClient](./kibana-plugin-core-public.savedobjectsclient.md) &gt; [bulkUpdate](./kibana-plugin-core-public.savedobjectsclient.bulkupdate.md)
[Home](./index.md) &gt; [kibana-plugin-core-public](./kibana-plugin-core-public.md) &gt; [SavedObjectsClientContract](./kibana-plugin-core-public.savedobjectsclientcontract.md) &gt; [bulkUpdate](./kibana-plugin-core-public.savedobjectsclientcontract.bulkupdate.md)
## SavedObjectsClient.bulkUpdate() method
## SavedObjectsClientContract.bulkUpdate() method
Update multiple documents at once
<b>Signature:</b>
```typescript
bulkUpdate<T = unknown>(objects?: SavedObjectsBulkUpdateObject[]): Promise<SavedObjectsBatchResponse<T>>;
bulkUpdate<T = unknown>(objects: SavedObjectsBulkUpdateObject[]): Promise<SavedObjectsBatchResponse<T>>;
```
## Parameters

View file

@ -0,0 +1,26 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-core-public](./kibana-plugin-core-public.md) &gt; [SavedObjectsClientContract](./kibana-plugin-core-public.savedobjectsclientcontract.md) &gt; [create](./kibana-plugin-core-public.savedobjectsclientcontract.create.md)
## SavedObjectsClientContract.create() method
Persists an object
<b>Signature:</b>
```typescript
create<T = unknown>(type: string, attributes: T, options?: SavedObjectsCreateOptions): Promise<SimpleSavedObject<T>>;
```
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| type | string | |
| attributes | T | |
| options | SavedObjectsCreateOptions | |
<b>Returns:</b>
Promise&lt;SimpleSavedObject&lt;T&gt;&gt;

View file

@ -0,0 +1,26 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-core-public](./kibana-plugin-core-public.md) &gt; [SavedObjectsClientContract](./kibana-plugin-core-public.savedobjectsclientcontract.md) &gt; [delete](./kibana-plugin-core-public.savedobjectsclientcontract.delete.md)
## SavedObjectsClientContract.delete() method
Deletes an object
<b>Signature:</b>
```typescript
delete(type: string, id: string, options?: SavedObjectsDeleteOptions): Promise<{}>;
```
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| type | string | |
| id | string | |
| options | SavedObjectsDeleteOptions | |
<b>Returns:</b>
Promise&lt;{}&gt;

View file

@ -0,0 +1,26 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-core-public](./kibana-plugin-core-public.md) &gt; [SavedObjectsClientContract](./kibana-plugin-core-public.savedobjectsclientcontract.md) &gt; [find](./kibana-plugin-core-public.savedobjectsclientcontract.find.md)
## SavedObjectsClientContract.find() method
Search for objects
<b>Signature:</b>
```typescript
find<T = unknown, A = unknown>(options: SavedObjectsFindOptions): Promise<SavedObjectsFindResponsePublic<T>>;
```
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| options | SavedObjectsFindOptions | {<!-- -->string<!-- -->} options.type {<!-- -->string<!-- -->} options.search {<!-- -->string<!-- -->} options.searchFields - see Elasticsearch Simple Query String Query field argument for more information {<!-- -->integer<!-- -->} \[options.page=1\] {<!-- -->integer<!-- -->} \[options.perPage=20\] {<!-- -->array<!-- -->} options.fields {<!-- -->object<!-- -->} \[options.hasReference\] - { type, id } |
<b>Returns:</b>
Promise&lt;SavedObjectsFindResponsePublic&lt;T&gt;&gt;
A find result with objects matching the specified search.

View file

@ -0,0 +1,27 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-core-public](./kibana-plugin-core-public.md) &gt; [SavedObjectsClientContract](./kibana-plugin-core-public.savedobjectsclientcontract.md) &gt; [get](./kibana-plugin-core-public.savedobjectsclientcontract.get.md)
## SavedObjectsClientContract.get() method
Fetches a single object
<b>Signature:</b>
```typescript
get<T = unknown>(type: string, id: string): Promise<SimpleSavedObject<T>>;
```
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| type | string | |
| id | string | |
<b>Returns:</b>
Promise&lt;SimpleSavedObject&lt;T&gt;&gt;
The saved object for the given type and id.

View file

@ -2,12 +2,28 @@
[Home](./index.md) &gt; [kibana-plugin-core-public](./kibana-plugin-core-public.md) &gt; [SavedObjectsClientContract](./kibana-plugin-core-public.savedobjectsclientcontract.md)
## SavedObjectsClientContract type
## SavedObjectsClientContract interface
SavedObjectsClientContract as implemented by the [SavedObjectsClient](./kibana-plugin-core-public.savedobjectsclient.md)
The client-side SavedObjectsClient is a thin convenience library around the SavedObjects HTTP API for interacting with Saved Objects.
<b>Signature:</b>
```typescript
export declare type SavedObjectsClientContract = PublicMethodsOf<SavedObjectsClient>;
export interface SavedObjectsClientContract
```
## Methods
| Method | Description |
| --- | --- |
| [bulkCreate(objects, options)](./kibana-plugin-core-public.savedobjectsclientcontract.bulkcreate.md) | Creates multiple documents at once |
| [bulkGet(objects)](./kibana-plugin-core-public.savedobjectsclientcontract.bulkget.md) | Returns an array of objects by id |
| [bulkResolve(objects)](./kibana-plugin-core-public.savedobjectsclientcontract.bulkresolve.md) | Resolves an array of objects by id, using any legacy URL aliases if they exist |
| [bulkUpdate(objects)](./kibana-plugin-core-public.savedobjectsclientcontract.bulkupdate.md) | Update multiple documents at once |
| [create(type, attributes, options)](./kibana-plugin-core-public.savedobjectsclientcontract.create.md) | Persists an object |
| [delete(type, id, options)](./kibana-plugin-core-public.savedobjectsclientcontract.delete.md) | Deletes an object |
| [find(options)](./kibana-plugin-core-public.savedobjectsclientcontract.find.md) | Search for objects |
| [get(type, id)](./kibana-plugin-core-public.savedobjectsclientcontract.get.md) | Fetches a single object |
| [resolve(type, id)](./kibana-plugin-core-public.savedobjectsclientcontract.resolve.md) | Resolves a single object |
| [update(type, id, attributes, options)](./kibana-plugin-core-public.savedobjectsclientcontract.update.md) | Updates an object |

View file

@ -0,0 +1,29 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-core-public](./kibana-plugin-core-public.md) &gt; [SavedObjectsClientContract](./kibana-plugin-core-public.savedobjectsclientcontract.md) &gt; [resolve](./kibana-plugin-core-public.savedobjectsclientcontract.resolve.md)
## SavedObjectsClientContract.resolve() method
Resolves a single object
<b>Signature:</b>
```typescript
resolve<T = unknown>(type: string, id: string): Promise<ResolvedSimpleSavedObject<T>>;
```
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| type | string | |
| id | string | |
<b>Returns:</b>
Promise&lt;ResolvedSimpleSavedObject&lt;T&gt;&gt;
The resolve result for the saved object for the given type and id.
Saved objects that Kibana fails to find are replaced with an error object and an "exactMatch" outcome. The rationale behind the outcome is that "exactMatch" is the default outcome, and the outcome only changes if an alias is found. This behavior for the `resolve` API is unique to the public client, which batches individual calls with `bulkResolve` under the hood. We don't throw an error in that case for legacy compatibility reasons.

View file

@ -0,0 +1,28 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-core-public](./kibana-plugin-core-public.md) &gt; [SavedObjectsClientContract](./kibana-plugin-core-public.savedobjectsclientcontract.md) &gt; [update](./kibana-plugin-core-public.savedobjectsclientcontract.update.md)
## SavedObjectsClientContract.update() method
Updates an object
<b>Signature:</b>
```typescript
update<T = unknown>(type: string, id: string, attributes: T, options?: SavedObjectsUpdateOptions): Promise<SimpleSavedObject<T>>;
```
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| type | string | |
| id | string | |
| attributes | T | |
| options | SavedObjectsUpdateOptions | {<!-- -->integer<!-- -->} options.version - ensures version matches that of persisted object {<!-- -->object<!-- -->} options.migrationVersion - The optional migrationVersion of this document |
<b>Returns:</b>
Promise&lt;SimpleSavedObject&lt;T&gt;&gt;

View file

@ -4,7 +4,7 @@
## SavedObjectsStart.client property
[SavedObjectsClient](./kibana-plugin-core-public.savedobjectsclient.md)
[SavedObjectsClientContract](./kibana-plugin-core-public.savedobjectsclientcontract.md)
<b>Signature:</b>

View file

@ -15,5 +15,5 @@ export interface SavedObjectsStart
| Property | Type | Description |
| --- | --- | --- |
| [client](./kibana-plugin-core-public.savedobjectsstart.client.md) | SavedObjectsClientContract | [SavedObjectsClient](./kibana-plugin-core-public.savedobjectsclient.md) |
| [client](./kibana-plugin-core-public.savedobjectsstart.client.md) | SavedObjectsClientContract | [SavedObjectsClientContract](./kibana-plugin-core-public.savedobjectsclientcontract.md) |

View file

@ -4,7 +4,7 @@
## SimpleSavedObject class
This class is a very simple wrapper for SavedObjects loaded from the server with the [SavedObjectsClient](./kibana-plugin-core-public.savedobjectsclient.md)<!-- -->.
This class is a very simple wrapper for SavedObjects loaded from the server with the [SavedObjectsClientContract](./kibana-plugin-core-public.savedobjectsclientcontract.md)<!-- -->.
It provides basic functionality for creating/saving/deleting saved objects, but doesn't include any type-specific implementations.

View file

@ -11,7 +11,7 @@ import {
EmbeddableStart,
CONTEXT_MENU_TRIGGER,
} from '@kbn/embeddable-plugin/public';
import { Plugin, CoreSetup, CoreStart, SavedObjectsClient } from '@kbn/core/public';
import { Plugin, CoreSetup, CoreStart, SavedObjectsClientContract } from '@kbn/core/public';
import { UiActionsStart } from '@kbn/ui-actions-plugin/public';
import {
HelloWorldEmbeddableFactory,
@ -62,7 +62,7 @@ export interface EmbeddableExamplesSetupDependencies {
export interface EmbeddableExamplesStartDependencies {
embeddable: EmbeddableStart;
savedObjectsClient: SavedObjectsClient;
savedObjectsClient: SavedObjectsClientContract;
}
interface ExampleEmbeddableFactories {

View file

@ -136,7 +136,6 @@ export type {
SavedObjectsFindOptionsReference,
SavedObjectsMigrationVersion,
SavedObjectsClientContract,
SavedObjectsClient,
SavedObjectsImportResponse,
SavedObjectsImportSuccess,
SavedObjectsImportConflictError,

View file

@ -8,13 +8,9 @@
import { Action } from 'history';
import { AnalyticsClient } from '@kbn/analytics-client';
import Boom from '@hapi/boom';
import type { ButtonColor } from '@elastic/eui';
import { ByteSizeValue } from '@kbn/config-schema';
import type { Client } from '@elastic/elasticsearch';
import { ConfigPath } from '@kbn/config';
import { ContextProviderOpts } from '@kbn/analytics-client';
import { DetailedPeerCertificate } from 'tls';
import type { DocLinks } from '@kbn/doc-links';
import { EnvironmentMode } from '@kbn/config';
import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
@ -31,35 +27,25 @@ import { EventTypeOpts } from '@kbn/analytics-client';
import { History as History_2 } from 'history';
import { Href } from 'history';
import { IconType } from '@elastic/eui';
import { IncomingHttpHeaders } from 'http';
import { IShipper } from '@kbn/analytics-client';
import { Location as Location_2 } from 'history';
import { LocationDescriptorObject } from 'history';
import { Logger } from '@kbn/logging';
import { LogMeta } from '@kbn/logging';
import { MaybePromise } from '@kbn/utility-types';
import { ObjectType } from '@kbn/config-schema';
import { Observable } from 'rxjs';
import { OptInConfig } from '@kbn/analytics-client';
import { PackageInfo } from '@kbn/config';
import { Path } from 'history';
import { PeerCertificate } from 'tls';
import type { PublicMethodsOf } from '@kbn/utility-types';
import { default as React_2 } from 'react';
import { RecursiveReadonly } from '@kbn/utility-types';
import { Request as Request_2 } from '@hapi/hapi';
import * as Rx from 'rxjs';
import { SchemaTypeError } from '@kbn/config-schema';
import { ShipperClassConstructor } from '@kbn/analytics-client';
import { TelemetryCounter } from '@kbn/analytics-client';
import { TelemetryCounterType } from '@kbn/analytics-client';
import type { ThemeVersion } from '@kbn/ui-shared-deps-npm';
import { TransitionPromptHook } from 'history';
import { Type } from '@kbn/config-schema';
import { TypeOf } from '@kbn/config-schema';
import { UiCounterMetricType } from '@kbn/analytics';
import { UnregisterCallback } from 'history';
import { URL as URL_2 } from 'url';
// @internal (undocumented)
export function __kbnBootstrap__(): Promise<void>;
@ -1131,7 +1117,7 @@ export interface SavedObjectsBulkResolveObject {
// @public (undocumented)
export interface SavedObjectsBulkResolveResponse<T = unknown> {
// (undocumented)
resolved_objects: Array<SavedObjectsResolveResponse<T>>;
resolved_objects: Array<ResolvedSimpleSavedObject<T>>;
}
// @public (undocumented)
@ -1155,35 +1141,27 @@ export interface SavedObjectsBulkUpdateOptions {
}
// @public
export class SavedObjectsClient {
// @internal
constructor(http: HttpSetup);
bulkCreate: (objects?: SavedObjectsBulkCreateObject[], options?: SavedObjectsBulkCreateOptions) => Promise<SavedObjectsBatchResponse<unknown>>;
bulkGet: (objects?: Array<{
export interface SavedObjectsClientContract {
bulkCreate(objects: SavedObjectsBulkCreateObject[], options?: SavedObjectsBulkCreateOptions): Promise<SavedObjectsBatchResponse<unknown>>;
bulkGet(objects: Array<{
id: string;
type: string;
}>) => Promise<SavedObjectsBatchResponse<unknown>>;
bulkResolve: <T = unknown>(objects?: Array<{
}>): Promise<SavedObjectsBatchResponse<unknown>>;
bulkResolve<T = unknown>(objects: Array<{
id: string;
type: string;
}>) => Promise<{
resolved_objects: ResolvedSimpleSavedObject<T>[];
}>;
bulkUpdate<T = unknown>(objects?: SavedObjectsBulkUpdateObject[]): Promise<SavedObjectsBatchResponse<T>>;
create: <T = unknown>(type: string, attributes: T, options?: SavedObjectsCreateOptions) => Promise<SimpleSavedObject<T>>;
}>): Promise<SavedObjectsBulkResolveResponse<T>>;
bulkUpdate<T = unknown>(objects: SavedObjectsBulkUpdateObject[]): Promise<SavedObjectsBatchResponse<T>>;
create<T = unknown>(type: string, attributes: T, options?: SavedObjectsCreateOptions): Promise<SimpleSavedObject<T>>;
// Warning: (ae-forgotten-export) The symbol "SavedObjectsDeleteOptions" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "SavedObjectsClientContract" needs to be exported by the entry point index.d.ts
delete: (type: string, id: string, options?: SavedObjectsDeleteOptions | undefined) => ReturnType<SavedObjectsClientContract_2['delete']>;
delete(type: string, id: string, options?: SavedObjectsDeleteOptions): Promise<{}>;
// Warning: (ae-forgotten-export) The symbol "SavedObjectsFindOptions" needs to be exported by the entry point index.d.ts
find: <T = unknown, A = unknown>(options: SavedObjectsFindOptions_2) => Promise<SavedObjectsFindResponsePublic<T, unknown>>;
get: <T = unknown>(type: string, id: string) => Promise<SimpleSavedObject<T>>;
resolve: <T = unknown>(type: string, id: string) => Promise<ResolvedSimpleSavedObject<T>>;
update<T = unknown>(type: string, id: string, attributes: T, { version, references, upsert }?: SavedObjectsUpdateOptions): Promise<SimpleSavedObject<T>>;
find<T = unknown, A = unknown>(options: SavedObjectsFindOptions_2): Promise<SavedObjectsFindResponsePublic<T>>;
get<T = unknown>(type: string, id: string): Promise<SimpleSavedObject<T>>;
resolve<T = unknown>(type: string, id: string): Promise<ResolvedSimpleSavedObject<T>>;
update<T = unknown>(type: string, id: string, attributes: T, options?: SavedObjectsUpdateOptions): Promise<SimpleSavedObject<T>>;
}
// @public
export type SavedObjectsClientContract = PublicMethodsOf<SavedObjectsClient>;
// @public
export interface SavedObjectsCollectMultiNamespaceReferencesResponse {
// (undocumented)
@ -1219,7 +1197,7 @@ export interface SavedObjectsFindOptions {
// (undocumented)
perPage?: number;
// Warning: (ae-forgotten-export) The symbol "SavedObjectsPitParams" needs to be exported by the entry point index.d.ts
// Warning: (ae-unresolved-link) The @link reference could not be resolved: No member was found with name "openPointInTimeForType"
// Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "kibana" does not have an export "SavedObjectsClient"
pit?: SavedObjectsPitParams;
preference?: string;
rootSearchFields?: string[];

View file

@ -18,6 +18,7 @@ export type {
SavedObjectsFindResponsePublic,
SavedObjectsUpdateOptions,
SavedObjectsBulkUpdateOptions,
SavedObjectsBulkResolveResponse,
} from './saved_objects_client';
export { SimpleSavedObject } from './simple_saved_object';
export type { ResolvedSimpleSavedObject } from './types';
@ -43,7 +44,6 @@ export type {
SavedObjectReferenceWithContext,
SavedObjectsCollectMultiNamespaceReferencesResponse,
SavedObjectsBulkResolveObject,
SavedObjectsBulkResolveResponse,
SavedObjectsResolveResponse,
} from '../../server';

View file

@ -7,12 +7,11 @@
*/
import { pick, throttle, cloneDeep } from 'lodash';
import type { PublicMethodsOf } from '@kbn/utility-types';
import {
SavedObject,
SavedObjectReference,
SavedObjectsBulkResolveResponse,
SavedObjectsBulkResolveResponse as SavedObjectsBulkResolveResponseServer,
SavedObjectsClientContract as SavedObjectsApi,
SavedObjectsFindOptions as SavedObjectFindOptionsServer,
SavedObjectsMigrationVersion,
@ -96,6 +95,11 @@ export interface SavedObjectsDeleteOptions {
force?: boolean;
}
/** @public */
export interface SavedObjectsBulkResolveResponse<T = unknown> {
resolved_objects: Array<ResolvedSimpleSavedObject<T>>;
}
/**
* Return type of the Saved Objects `find()` method.
*
@ -118,6 +122,7 @@ interface BatchGetQueueEntry {
resolve: <T = unknown>(value: SimpleSavedObject<T> | SavedObject<T>) => void;
reject: (reason?: any) => void;
}
interface BatchResolveQueueEntry {
type: string;
id: string;
@ -140,11 +145,140 @@ const BATCH_INTERVAL = 100;
const API_BASE_URL = '/api/saved_objects/';
/**
* SavedObjectsClientContract as implemented by the {@link SavedObjectsClient}
* The client-side SavedObjectsClient is a thin convenience library around the SavedObjects
* HTTP API for interacting with Saved Objects.
*
* @public
*/
export type SavedObjectsClientContract = PublicMethodsOf<SavedObjectsClient>;
export interface SavedObjectsClientContract {
/**
* Persists an object
*/
create<T = unknown>(
type: string,
attributes: T,
options?: SavedObjectsCreateOptions
): Promise<SimpleSavedObject<T>>;
/**
* Creates multiple documents at once
* @returns The result of the create operation containing created saved objects.
*/
bulkCreate(
objects: SavedObjectsBulkCreateObject[],
options?: SavedObjectsBulkCreateOptions
): Promise<SavedObjectsBatchResponse<unknown>>;
/**
* Deletes an object
*/
delete(type: string, id: string, options?: SavedObjectsDeleteOptions): Promise<{}>;
/**
* Search for objects
*
* @param {object} [options={}]
* @property {string} options.type
* @property {string} options.search
* @property {string} options.searchFields - see Elasticsearch Simple Query String
* Query field argument for more information
* @property {integer} [options.page=1]
* @property {integer} [options.perPage=20]
* @property {array} options.fields
* @property {object} [options.hasReference] - { type, id }
* @returns A find result with objects matching the specified search.
*/
find<T = unknown, A = unknown>(
options: SavedObjectsFindOptions
): Promise<SavedObjectsFindResponsePublic<T>>;
/**
* Fetches a single object
*
* @param {string} type
* @param {string} id
* @returns The saved object for the given type and id.
*/
get<T = unknown>(type: string, id: string): Promise<SimpleSavedObject<T>>;
/**
* Returns an array of objects by id
*
* @param {array} objects - an array ids, or an array of objects containing id and optionally type
* @returns The saved objects with the given type and ids requested
* @example
*
* bulkGet([
* { id: 'one', type: 'config' },
* { id: 'foo', type: 'index-pattern' }
* ])
*/
bulkGet(
objects: Array<{ id: string; type: string }>
): Promise<SavedObjectsBatchResponse<unknown>>;
/**
* Resolves a single object
*
* @param {string} type
* @param {string} id
* @returns The resolve result for the saved object for the given type and id.
*
* @note Saved objects that Kibana fails to find are replaced with an error object and an "exactMatch" outcome. The rationale behind the
* outcome is that "exactMatch" is the default outcome, and the outcome only changes if an alias is found. This behavior for the `resolve`
* API is unique to the public client, which batches individual calls with `bulkResolve` under the hood. We don't throw an error in that
* case for legacy compatibility reasons.
*/
resolve<T = unknown>(type: string, id: string): Promise<ResolvedSimpleSavedObject<T>>;
/**
* Resolves an array of objects by id, using any legacy URL aliases if they exist
*
* @param objects - an array of objects containing id, type
* @returns The bulk resolve result for the saved objects for the given types and ids.
* @example
*
* bulkResolve([
* { id: 'one', type: 'config' },
* { id: 'foo', type: 'index-pattern' }
* ])
*
* @note Saved objects that Kibana fails to find are replaced with an error object and an "exactMatch" outcome. The rationale behind the
* outcome is that "exactMatch" is the default outcome, and the outcome only changes if an alias is found. The `resolve` method in the
* public client uses `bulkResolve` under the hood, so it behaves the same way.
*/
bulkResolve<T = unknown>(
objects: Array<{ id: string; type: string }>
): Promise<SavedObjectsBulkResolveResponse<T>>;
/**
* Updates an object
*
* @param {string} type
* @param {string} id
* @param {object} attributes
* @param {object} options
* @prop {integer} options.version - ensures version matches that of persisted object
* @prop {object} options.migrationVersion - The optional migrationVersion of this document
* @returns
*/
update<T = unknown>(
type: string,
id: string,
attributes: T,
options?: SavedObjectsUpdateOptions
): Promise<SimpleSavedObject<T>>;
/**
* Update multiple documents at once
*
* @param {array} objects - [{ type, id, attributes, options: { version, references } }]
* @returns The result of the update operation containing both failed and updated saved objects.
*/
bulkUpdate<T = unknown>(
objects: SavedObjectsBulkUpdateObject[]
): Promise<SavedObjectsBatchResponse<T>>;
}
interface ObjectTypeAndId {
id: string;
@ -182,14 +316,14 @@ const getObjectsToResolve = (queue: BatchResolveQueueEntry[]) => {
};
/**
* Saved Objects is Kibana's data persisentence mechanism allowing plugins to
* Saved Objects is Kibana's data persistence 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.
*
* @public
* @internal
*/
export class SavedObjectsClient {
export class SavedObjectsClient implements SavedObjectsClientContract {
private http: HttpSetup;
private batchGetQueue: BatchGetQueueEntry[];
private batchResolveQueue: BatchResolveQueueEntry[];
@ -270,14 +404,6 @@ export class SavedObjectsClient {
this.batchResolveQueue = [];
}
/**
* Persists an object
*
* @param type
* @param attributes
* @param options
* @returns
*/
public create = <T = unknown>(
type: string,
attributes: T,
@ -334,13 +460,6 @@ export class SavedObjectsClient {
});
};
/**
* Deletes an object
*
* @param type
* @param id
* @returns
*/
public delete = (
type: string,
id: string,
@ -357,20 +476,6 @@ export class SavedObjectsClient {
return this.savedObjectsFetch(this.getPath([type, id]), { method: 'DELETE', query });
};
/**
* Search for objects
*
* @param {object} [options={}]
* @property {string} options.type
* @property {string} options.search
* @property {string} options.searchFields - see Elasticsearch Simple Query String
* Query field argument for more information
* @property {integer} [options.page=1]
* @property {integer} [options.perPage=20]
* @property {array} options.fields
* @property {object} [options.hasReference] - { type, id }
* @returns A find result with objects matching the specified search.
*/
public find = <T = unknown, A = unknown>(
options: SavedObjectsFindOptions
): Promise<SavedObjectsFindResponsePublic<T>> => {
@ -431,13 +536,6 @@ export class SavedObjectsClient {
});
};
/**
* Fetches a single object
*
* @param {string} type
* @param {string} id
* @returns The saved object for the given type and id.
*/
public get = <T = unknown>(type: string, id: string): Promise<SimpleSavedObject<T>> => {
if (!type || !id) {
return Promise.reject(new Error('requires type and id'));
@ -449,18 +547,6 @@ export class SavedObjectsClient {
});
};
/**
* Returns an array of objects by id
*
* @param {array} objects - an array ids, or an array of objects containing id and optionally type
* @returns The saved objects with the given type and ids requested
* @example
*
* bulkGet([
* { id: 'one', type: 'config' },
* { id: 'foo', type: 'index-pattern' }
* ])
*/
public bulkGet = (objects: Array<{ id: string; type: string }> = []) => {
const filteredObjects = objects.map((obj) => pick(obj, ['id', 'type']));
return this.performBulkGet(filteredObjects).then((resp) => {
@ -481,18 +567,6 @@ export class SavedObjectsClient {
return request;
}
/**
* Resolves a single object
*
* @param {string} type
* @param {string} id
* @returns The resolve result for the saved object for the given type and id.
*
* @note Saved objects that Kibana fails to find are replaced with an error object and an "exactMatch" outcome. The rationale behind the
* outcome is that "exactMatch" is the default outcome, and the outcome only changes if an alias is found. This behavior for the `resolve`
* API is unique to the public client, which batches individual calls with `bulkResolve` under the hood. We don't throw an error in that
* case for legacy compatibility reasons.
*/
public resolve = <T = unknown>(
type: string,
id: string
@ -507,22 +581,6 @@ export class SavedObjectsClient {
});
};
/**
* Resolves an array of objects by id, using any legacy URL aliases if they exist
*
* @param objects - an array of objects containing id, type
* @returns The bulk resolve result for the saved objects for the given types and ids.
* @example
*
* bulkResolve([
* { id: 'one', type: 'config' },
* { id: 'foo', type: 'index-pattern' }
* ])
*
* @note Saved objects that Kibana fails to find are replaced with an error object and an "exactMatch" outcome. The rationale behind the
* outcome is that "exactMatch" is the default outcome, and the outcome only changes if an alias is found. The `resolve` method in the
* public client uses `bulkResolve` under the hood, so it behaves the same way.
*/
public bulkResolve = async <T = unknown>(objects: Array<{ id: string; type: string }> = []) => {
const filteredObjects = objects.map(({ type, id }) => ({ type, id }));
const response = await this.performBulkResolve<T>(filteredObjects);
@ -535,24 +593,16 @@ export class SavedObjectsClient {
private async performBulkResolve<T>(objects: ObjectTypeAndId[]) {
const path = this.getPath(['_bulk_resolve']);
const request: Promise<SavedObjectsBulkResolveResponse<T>> = this.savedObjectsFetch(path, {
method: 'POST',
body: JSON.stringify(objects),
});
const request: Promise<SavedObjectsBulkResolveResponseServer<T>> = this.savedObjectsFetch(
path,
{
method: 'POST',
body: JSON.stringify(objects),
}
);
return request;
}
/**
* Updates an object
*
* @param {string} type
* @param {string} id
* @param {object} attributes
* @param {object} options
* @prop {integer} options.version - ensures version matches that of persisted object
* @prop {object} options.migrationVersion - The optional migrationVersion of this document
* @returns
*/
public update<T = unknown>(
type: string,
id: string,
@ -579,12 +629,6 @@ export class SavedObjectsClient {
});
}
/**
* Update multiple documents at once
*
* @param {array} objects - [{ type, id, attributes, options: { version, references } }]
* @returns The result of the update operation containing both failed and updated saved objects.
*/
public bulkUpdate<T = unknown>(objects: SavedObjectsBulkUpdateObject[] = []) {
const path = this.getPath(['_bulk_update']);

View file

@ -14,7 +14,7 @@ import { SavedObjectsClient, SavedObjectsClientContract } from './saved_objects_
* @public
*/
export interface SavedObjectsStart {
/** {@link SavedObjectsClient} */
/** {@link SavedObjectsClientContract} */
client: SavedObjectsClientContract;
}

View file

@ -13,7 +13,7 @@ import { SavedObjectsClientContract } from './saved_objects_client';
/**
* This class is a very simple wrapper for SavedObjects loaded from the server
* with the {@link SavedObjectsClient}.
* with the {@link SavedObjectsClientContract}.
*
* It provides basic functionality for creating/saving/deleting saved objects,
* but doesn't include any type-specific implementations.

View file

@ -11,7 +11,7 @@ import { SimpleSavedObject } from './simple_saved_object';
/**
* This interface is a very simple wrapper for SavedObjects resolved from the server
* with the {@link SavedObjectsClient}.
* with the {@link SavedObjectsClientContract}.
*
* @public
*/

View file

@ -7,7 +7,7 @@
*/
import { omit } from 'lodash';
import { SavedObjectsClient, SimpleSavedObject } from '@kbn/core/public';
import { SavedObjectsClientContract, SimpleSavedObject } from '@kbn/core/public';
import {
SavedObjectsClientCommon,
SavedObjectsClientCommonFindArgs,
@ -15,7 +15,10 @@ import {
DataViewSavedObjectConflictError,
} from '../common';
type SOClient = Pick<SavedObjectsClient, 'find' | 'resolve' | 'update' | 'create' | 'delete'>;
type SOClient = Pick<
SavedObjectsClientContract,
'find' | 'resolve' | 'update' | 'create' | 'delete'
>;
const simpleSavedObjectToSavedObject = <T>(simpleSavedObject: SimpleSavedObject): SavedObject<T> =>
({
@ -25,9 +28,11 @@ const simpleSavedObjectToSavedObject = <T>(simpleSavedObject: SimpleSavedObject)
export class SavedObjectsClientPublicToCommon implements SavedObjectsClientCommon {
private savedObjectClient: SOClient;
constructor(savedObjectClient: SOClient) {
this.savedObjectClient = savedObjectClient;
}
async find<T = unknown>(options: SavedObjectsClientCommonFindArgs) {
const response = (await this.savedObjectClient.find<T>(options)).savedObjects;
return response.map<SavedObject<T>>(simpleSavedObjectToSavedObject);
@ -40,6 +45,7 @@ export class SavedObjectsClientPublicToCommon implements SavedObjectsClientCommo
}
return simpleSavedObjectToSavedObject<T>(response.saved_object);
}
async update(
type: string,
id: string,
@ -49,10 +55,12 @@ export class SavedObjectsClientPublicToCommon implements SavedObjectsClientCommo
const response = await this.savedObjectClient.update(type, id, attributes, options);
return simpleSavedObjectToSavedObject(response);
}
async create(type: string, attributes: Record<string, any>, options: Record<string, any>) {
const response = await this.savedObjectClient.create(type, attributes, options);
return simpleSavedObjectToSavedObject(response);
}
delete(type: string, id: string) {
return this.savedObjectClient.delete(type, id, { force: true });
}