[Saved Objects] Adds support for custom Refresh settings on mutating operations (#48932)

Adds the ability to override the Refresh setting of mutating operations (Update, Delete, Bulk, Index) of Saved Objects.
This commit is contained in:
Gidi Meir Morris 2019-10-25 08:28:55 +01:00 committed by GitHub
parent 296fa8e722
commit 2ac82dec61
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 426 additions and 23 deletions

View file

@ -90,10 +90,12 @@ The plugin integrates with the core system via lifecycle events: `setup`<!-- -->
| [SavedObjectsBulkGetObject](./kibana-plugin-server.savedobjectsbulkgetobject.md) | |
| [SavedObjectsBulkResponse](./kibana-plugin-server.savedobjectsbulkresponse.md) | |
| [SavedObjectsBulkUpdateObject](./kibana-plugin-server.savedobjectsbulkupdateobject.md) | |
| [SavedObjectsBulkUpdateOptions](./kibana-plugin-server.savedobjectsbulkupdateoptions.md) | |
| [SavedObjectsBulkUpdateResponse](./kibana-plugin-server.savedobjectsbulkupdateresponse.md) | |
| [SavedObjectsClientProviderOptions](./kibana-plugin-server.savedobjectsclientprovideroptions.md) | Options to control the creation of the Saved Objects Client. |
| [SavedObjectsClientWrapperOptions](./kibana-plugin-server.savedobjectsclientwrapperoptions.md) | Options passed to each SavedObjectsClientWrapperFactory to aid in creating the wrapper instance. |
| [SavedObjectsCreateOptions](./kibana-plugin-server.savedobjectscreateoptions.md) | |
| [SavedObjectsDeleteOptions](./kibana-plugin-server.savedobjectsdeleteoptions.md) | |
| [SavedObjectsExportOptions](./kibana-plugin-server.savedobjectsexportoptions.md) | Options controlling the export operation. |
| [SavedObjectsExportResultDetails](./kibana-plugin-server.savedobjectsexportresultdetails.md) | Structure of the export result details entry |
| [SavedObjectsFindOptions](./kibana-plugin-server.savedobjectsfindoptions.md) | |
@ -149,6 +151,7 @@ The plugin integrates with the core system via lifecycle events: `setup`<!-- -->
| [LifecycleResponseFactory](./kibana-plugin-server.lifecycleresponsefactory.md) | Creates an object containing redirection or error response with error details, HTTP headers, and other data transmitted to the client. |
| [MIGRATION\_ASSISTANCE\_INDEX\_ACTION](./kibana-plugin-server.migration_assistance_index_action.md) | |
| [MIGRATION\_DEPRECATION\_LEVEL](./kibana-plugin-server.migration_deprecation_level.md) | |
| [MutatingOperationRefreshSetting](./kibana-plugin-server.mutatingoperationrefreshsetting.md) | Elasticsearch Refresh setting for mutating operation |
| [OnPostAuthHandler](./kibana-plugin-server.onpostauthhandler.md) | See [OnPostAuthToolkit](./kibana-plugin-server.onpostauthtoolkit.md)<!-- -->. |
| [OnPreAuthHandler](./kibana-plugin-server.onpreauthhandler.md) | See [OnPreAuthToolkit](./kibana-plugin-server.onpreauthtoolkit.md)<!-- -->. |
| [PluginInitializer](./kibana-plugin-server.plugininitializer.md) | The <code>plugin</code> export at the root of a plugin's <code>server</code> directory should conform to this interface. |

View file

@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-server](./kibana-plugin-server.md) &gt; [MutatingOperationRefreshSetting](./kibana-plugin-server.mutatingoperationrefreshsetting.md)
## MutatingOperationRefreshSetting type
Elasticsearch Refresh setting for mutating operation
<b>Signature:</b>
```typescript
export declare type MutatingOperationRefreshSetting = boolean | 'wait_for';
```

View file

@ -0,0 +1,19 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-server](./kibana-plugin-server.md) &gt; [SavedObjectsBulkUpdateOptions](./kibana-plugin-server.savedobjectsbulkupdateoptions.md)
## SavedObjectsBulkUpdateOptions interface
<b>Signature:</b>
```typescript
export interface SavedObjectsBulkUpdateOptions extends SavedObjectsBaseOptions
```
## Properties
| Property | Type | Description |
| --- | --- | --- |
| [refresh](./kibana-plugin-server.savedobjectsbulkupdateoptions.refresh.md) | <code>MutatingOperationRefreshSetting</code> | The Elasticsearch Refresh setting for this operation |

View file

@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-server](./kibana-plugin-server.md) &gt; [SavedObjectsBulkUpdateOptions](./kibana-plugin-server.savedobjectsbulkupdateoptions.md) &gt; [refresh](./kibana-plugin-server.savedobjectsbulkupdateoptions.refresh.md)
## SavedObjectsBulkUpdateOptions.refresh property
The Elasticsearch Refresh setting for this operation
<b>Signature:</b>
```typescript
refresh?: MutatingOperationRefreshSetting;
```

View file

@ -9,7 +9,7 @@ Bulk Updates multiple SavedObject at once
<b>Signature:</b>
```typescript
bulkUpdate<T extends SavedObjectAttributes = any>(objects: Array<SavedObjectsBulkUpdateObject<T>>, options?: SavedObjectsBaseOptions): Promise<SavedObjectsBulkUpdateResponse<T>>;
bulkUpdate<T extends SavedObjectAttributes = any>(objects: Array<SavedObjectsBulkUpdateObject<T>>, options?: SavedObjectsBulkUpdateOptions): Promise<SavedObjectsBulkUpdateResponse<T>>;
```
## Parameters
@ -17,7 +17,7 @@ bulkUpdate<T extends SavedObjectAttributes = any>(objects: Array<SavedObjectsBul
| Parameter | Type | Description |
| --- | --- | --- |
| objects | <code>Array&lt;SavedObjectsBulkUpdateObject&lt;T&gt;&gt;</code> | |
| options | <code>SavedObjectsBaseOptions</code> | |
| options | <code>SavedObjectsBulkUpdateOptions</code> | |
<b>Returns:</b>

View file

@ -9,7 +9,7 @@ Deletes a SavedObject
<b>Signature:</b>
```typescript
delete(type: string, id: string, options?: SavedObjectsBaseOptions): Promise<{}>;
delete(type: string, id: string, options?: SavedObjectsDeleteOptions): Promise<{}>;
```
## Parameters
@ -18,7 +18,7 @@ delete(type: string, id: string, options?: SavedObjectsBaseOptions): Promise<{}>
| --- | --- | --- |
| type | <code>string</code> | |
| id | <code>string</code> | |
| options | <code>SavedObjectsBaseOptions</code> | |
| options | <code>SavedObjectsDeleteOptions</code> | |
<b>Returns:</b>

View file

@ -19,4 +19,5 @@ export interface SavedObjectsCreateOptions extends SavedObjectsBaseOptions
| [migrationVersion](./kibana-plugin-server.savedobjectscreateoptions.migrationversion.md) | <code>SavedObjectsMigrationVersion</code> | 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) | <code>boolean</code> | Overwrite existing documents (defaults to false) |
| [references](./kibana-plugin-server.savedobjectscreateoptions.references.md) | <code>SavedObjectReference[]</code> | |
| [refresh](./kibana-plugin-server.savedobjectscreateoptions.refresh.md) | <code>MutatingOperationRefreshSetting</code> | The Elasticsearch Refresh setting for this operation |

View file

@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-server](./kibana-plugin-server.md) &gt; [SavedObjectsCreateOptions](./kibana-plugin-server.savedobjectscreateoptions.md) &gt; [refresh](./kibana-plugin-server.savedobjectscreateoptions.refresh.md)
## SavedObjectsCreateOptions.refresh property
The Elasticsearch Refresh setting for this operation
<b>Signature:</b>
```typescript
refresh?: MutatingOperationRefreshSetting;
```

View file

@ -0,0 +1,19 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-server](./kibana-plugin-server.md) &gt; [SavedObjectsDeleteOptions](./kibana-plugin-server.savedobjectsdeleteoptions.md)
## SavedObjectsDeleteOptions interface
<b>Signature:</b>
```typescript
export interface SavedObjectsDeleteOptions extends SavedObjectsBaseOptions
```
## Properties
| Property | Type | Description |
| --- | --- | --- |
| [refresh](./kibana-plugin-server.savedobjectsdeleteoptions.refresh.md) | <code>MutatingOperationRefreshSetting</code> | The Elasticsearch Refresh setting for this operation |

View file

@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-server](./kibana-plugin-server.md) &gt; [SavedObjectsDeleteOptions](./kibana-plugin-server.savedobjectsdeleteoptions.md) &gt; [refresh](./kibana-plugin-server.savedobjectsdeleteoptions.refresh.md)
## SavedObjectsDeleteOptions.refresh property
The Elasticsearch Refresh setting for this operation
<b>Signature:</b>
```typescript
refresh?: MutatingOperationRefreshSetting;
```

View file

@ -16,5 +16,6 @@ export interface SavedObjectsUpdateOptions extends SavedObjectsBaseOptions
| Property | Type | Description |
| --- | --- | --- |
| [references](./kibana-plugin-server.savedobjectsupdateoptions.references.md) | <code>SavedObjectReference[]</code> | A reference to another saved object. |
| [refresh](./kibana-plugin-server.savedobjectsupdateoptions.refresh.md) | <code>MutatingOperationRefreshSetting</code> | The Elasticsearch Refresh setting for this operation |
| [version](./kibana-plugin-server.savedobjectsupdateoptions.version.md) | <code>string</code> | An opaque version number which changes on each successful write operation. Can be used for implementing optimistic concurrency control. |

View file

@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [kibana-plugin-server](./kibana-plugin-server.md) &gt; [SavedObjectsUpdateOptions](./kibana-plugin-server.savedobjectsupdateoptions.md) &gt; [refresh](./kibana-plugin-server.savedobjectsupdateoptions.refresh.md)
## SavedObjectsUpdateOptions.refresh property
The Elasticsearch Refresh setting for this operation
<b>Signature:</b>
```typescript
refresh?: MutatingOperationRefreshSetting;
```

View file

@ -139,6 +139,7 @@ export {
SavedObjectsBulkCreateObject,
SavedObjectsBulkGetObject,
SavedObjectsBulkUpdateObject,
SavedObjectsBulkUpdateOptions,
SavedObjectsBulkResponse,
SavedObjectsBulkUpdateResponse,
SavedObjectsClient,
@ -166,6 +167,7 @@ export {
SavedObjectsLegacyService,
SavedObjectsUpdateOptions,
SavedObjectsUpdateResponse,
SavedObjectsDeleteOptions,
} from './saved_objects';
export {
@ -184,6 +186,7 @@ export {
SavedObjectAttributeSingle,
SavedObjectReference,
SavedObjectsBaseOptions,
MutatingOperationRefreshSetting,
SavedObjectsClientContract,
SavedObjectsFindOptions,
SavedObjectsMigrationVersion,

View file

@ -417,6 +417,32 @@ describe('SavedObjectsRepository', () => {
});
});
it('defaults to a refresh setting of `wait_for`', async () => {
await savedObjectsRepository.create('index-pattern', {
id: 'logstash-*',
title: 'Logstash',
});
expect(callAdminCluster).toHaveBeenCalledTimes(1);
expect(callAdminCluster.mock.calls[0][1]).toMatchObject({
refresh: 'wait_for'
});
});
it('accepts custom refresh settings', async () => {
await savedObjectsRepository.create('index-pattern', {
id: 'logstash-*',
title: 'Logstash',
}, {
refresh: true
});
expect(callAdminCluster).toHaveBeenCalledTimes(1);
expect(callAdminCluster.mock.calls[0][1]).toMatchObject({
refresh: true
});
});
it('should use create action if ID defined and overwrite=false', async () => {
await savedObjectsRepository.create(
'index-pattern',
@ -645,6 +671,61 @@ describe('SavedObjectsRepository', () => {
expect(onBeforeWrite).toHaveBeenCalledTimes(1);
});
it('defaults to a refresh setting of `wait_for`', async () => {
callAdminCluster.mockReturnValue({
items: [
{ create: { type: 'config', id: 'config:one', _primary_term: 1, _seq_no: 1 } },
],
});
await savedObjectsRepository.bulkCreate([
{
type: 'config',
id: 'one',
attributes: { title: 'Test One' },
references: [{ name: 'ref_0', type: 'test', id: '1' }],
}
]);
expect(callAdminCluster).toHaveBeenCalledTimes(1);
expect(callAdminCluster.mock.calls[0][1]).toMatchObject({
refresh: 'wait_for'
});
});
it('accepts a custom refresh setting', async () => {
callAdminCluster.mockReturnValue({
items: [
{ create: { type: 'config', id: 'config:one', _primary_term: 1, _seq_no: 1 } },
{ create: { type: 'index-pattern', id: 'config:two', _primary_term: 1, _seq_no: 1 } },
],
});
await savedObjectsRepository.bulkCreate([
{
type: 'config',
id: 'one',
attributes: { title: 'Test One' },
references: [{ name: 'ref_0', type: 'test', id: '1' }],
},
{
type: 'index-pattern',
id: 'two',
attributes: { title: 'Test Two' },
references: [{ name: 'ref_0', type: 'test', id: '2' }],
},
], {
refresh: true
});
expect(callAdminCluster).toHaveBeenCalledTimes(1);
expect(callAdminCluster.mock.calls[0][1]).toMatchObject({
refresh: true
});
});
it('migrates the docs', async () => {
callAdminCluster.mockReturnValue({
items: [
@ -1087,6 +1168,28 @@ describe('SavedObjectsRepository', () => {
expect(onBeforeWrite).toHaveBeenCalledTimes(1);
});
it('defaults to a refresh setting of `wait_for`', async () => {
callAdminCluster.mockReturnValue({ result: 'deleted' });
await savedObjectsRepository.delete('globaltype', 'logstash-*');
expect(callAdminCluster).toHaveBeenCalledTimes(1);
expect(callAdminCluster.mock.calls[0][1]).toMatchObject({
refresh: 'wait_for'
});
});
it(`accepts a custom refresh setting`, async () => {
callAdminCluster.mockReturnValue({ result: 'deleted' });
await savedObjectsRepository.delete('globaltype', 'logstash-*', {
refresh: false
});
expect(callAdminCluster).toHaveBeenCalledTimes(1);
expect(callAdminCluster.mock.calls[0][1]).toMatchObject({
refresh: false,
});
});
});
describe('#deleteByNamespace', () => {
@ -1126,6 +1229,26 @@ describe('SavedObjectsRepository', () => {
refresh: 'wait_for',
});
});
it('defaults to a refresh setting of `wait_for`', async () => {
callAdminCluster.mockReturnValue(deleteByQueryResults);
await savedObjectsRepository.deleteByNamespace('my-namespace');
expect(callAdminCluster).toHaveBeenCalledTimes(1);
expect(callAdminCluster.mock.calls[0][1]).toMatchObject({
refresh: 'wait_for',
});
});
it('accepts a custom refresh setting', async () => {
callAdminCluster.mockReturnValue(deleteByQueryResults);
await savedObjectsRepository.deleteByNamespace('my-namespace', { refresh: true });
expect(callAdminCluster).toHaveBeenCalledTimes(1);
expect(callAdminCluster.mock.calls[0][1]).toMatchObject({
refresh: true,
});
});
});
describe('#find', () => {
@ -1984,6 +2107,40 @@ describe('SavedObjectsRepository', () => {
expect(onBeforeWrite).toHaveBeenCalledTimes(1);
});
it('defaults to a refresh setting of `wait_for`', async () => {
await savedObjectsRepository.update(
'globaltype',
'foo',
{
name: 'bar',
}
);
expect(callAdminCluster).toHaveBeenCalledTimes(1);
expect(callAdminCluster.mock.calls[0][1]).toMatchObject({
refresh: 'wait_for'
});
});
it('accepts a custom refresh setting', async () => {
await savedObjectsRepository.update(
'globaltype',
'foo',
{
name: 'bar',
},
{
refresh: true,
namespace: 'foo-namespace',
}
);
expect(callAdminCluster).toHaveBeenCalledTimes(1);
expect(callAdminCluster.mock.calls[0][1]).toMatchObject({
refresh: true
});
});
});
describe('#bulkUpdate', () => {
@ -2284,6 +2441,44 @@ describe('SavedObjectsRepository', () => {
});
});
it('defaults to a refresh setting of `wait_for`', async () => {
const objects = [
{
type: 'index-pattern',
id: `logstash-no-ref`,
attributes: { title: `Testing no-ref` },
references: []
}
];
mockValidResponse(objects);
await savedObjectsRepository.bulkUpdate(objects);
expect(callAdminCluster).toHaveBeenCalledTimes(1);
expect(callAdminCluster.mock.calls[0][1]).toMatchObject({ refresh: 'wait_for' });
});
it('accepts a custom refresh setting', async () => {
const objects = [
{
type: 'index-pattern',
id: `logstash-no-ref`,
attributes: { title: `Testing no-ref` },
references: []
}
];
mockValidResponse(objects);
await savedObjectsRepository.bulkUpdate(objects, { refresh: true });
expect(callAdminCluster).toHaveBeenCalledTimes(1);
expect(callAdminCluster.mock.calls[0][1]).toMatchObject({ refresh: true });
});
it(`prepends namespace to the id but doesn't add namespace to body when providing namespace for namespaced type`, async () => {
const objects = [
@ -2526,6 +2721,29 @@ describe('SavedObjectsRepository', () => {
});
});
it('defaults to a refresh setting of `wait_for`', async () => {
await savedObjectsRepository.incrementCounter('config', 'doesnotexist', 'buildNum', {
namespace: 'foo-namespace'
});
expect(callAdminCluster).toHaveBeenCalledTimes(1);
expect(callAdminCluster.mock.calls[0][1]).toMatchObject({
refresh: 'wait_for'
});
});
it('accepts a custom refresh setting', async () => {
await savedObjectsRepository.incrementCounter('config', 'doesnotexist', 'buildNum', {
namespace: 'foo-namespace',
refresh: true
});
expect(callAdminCluster).toHaveBeenCalledTimes(1);
expect(callAdminCluster.mock.calls[0][1]).toMatchObject({
refresh: true
});
});
it(`prepends namespace to the id but doesn't add namespace to body when providing namespace for namespaced type`, async () => {
await savedObjectsRepository.incrementCounter('config', '6.0.0-alpha1', 'buildNum', {
namespace: 'foo-namespace',

View file

@ -40,6 +40,9 @@ import {
SavedObjectsUpdateOptions,
SavedObjectsUpdateResponse,
SavedObjectsBulkUpdateObject,
SavedObjectsBulkUpdateOptions,
SavedObjectsDeleteOptions,
SavedObjectsDeleteByNamespaceOptions,
} from '../saved_objects_client';
import {
SavedObject,
@ -47,6 +50,7 @@ import {
SavedObjectsBaseOptions,
SavedObjectsFindOptions,
SavedObjectsMigrationVersion,
MutatingOperationRefreshSetting,
} from '../../types';
import { validateConvertFilterToKueryNode } from './filter_utils';
@ -83,8 +87,12 @@ export interface SavedObjectsRepositoryOptions {
export interface IncrementCounterOptions extends SavedObjectsBaseOptions {
migrationVersion?: SavedObjectsMigrationVersion;
/** The Elasticsearch Refresh setting for this operation */
refresh?: MutatingOperationRefreshSetting;
}
const DEFAULT_REFRESH_SETTING = 'wait_for';
export class SavedObjectsRepository {
private _migrator: KibanaMigrator;
private _index: string;
@ -154,7 +162,14 @@ export class SavedObjectsRepository {
attributes: T,
options: SavedObjectsCreateOptions = {}
): Promise<SavedObject<T>> {
const { id, migrationVersion, overwrite = false, namespace, references = [] } = options;
const {
id,
migrationVersion,
overwrite = false,
namespace,
references = [],
refresh = DEFAULT_REFRESH_SETTING,
} = options;
if (!this._allowedTypes.includes(type)) {
throw SavedObjectsErrorHelpers.createUnsupportedTypeError(type);
@ -179,7 +194,7 @@ export class SavedObjectsRepository {
const response = await this._writeToCluster(method, {
id: raw._id,
index: this.getIndexForType(type),
refresh: 'wait_for',
refresh,
body: raw._source,
});
@ -210,7 +225,7 @@ export class SavedObjectsRepository {
objects: Array<SavedObjectsBulkCreateObject<T>>,
options: SavedObjectsCreateOptions = {}
): Promise<SavedObjectsBulkResponse<T>> {
const { namespace, overwrite = false } = options;
const { namespace, overwrite = false, refresh = DEFAULT_REFRESH_SETTING } = options;
const time = this._getCurrentTime();
const bulkCreateParams: object[] = [];
@ -256,7 +271,7 @@ export class SavedObjectsRepository {
});
const esResponse = await this._writeToCluster('bulk', {
refresh: 'wait_for',
refresh,
body: bulkCreateParams,
});
@ -308,17 +323,17 @@ export class SavedObjectsRepository {
* @property {string} [options.namespace]
* @returns {promise}
*/
async delete(type: string, id: string, options: SavedObjectsBaseOptions = {}): Promise<{}> {
async delete(type: string, id: string, options: SavedObjectsDeleteOptions = {}): Promise<{}> {
if (!this._allowedTypes.includes(type)) {
throw SavedObjectsErrorHelpers.createGenericNotFoundError();
}
const { namespace } = options;
const { namespace, refresh = DEFAULT_REFRESH_SETTING } = options;
const response = await this._writeToCluster('delete', {
id: this._serializer.generateRawId(namespace, type, id),
index: this.getIndexForType(type),
refresh: 'wait_for',
refresh,
ignore: [404],
});
@ -345,11 +360,16 @@ export class SavedObjectsRepository {
* @param {string} namespace
* @returns {promise} - { took, timed_out, total, deleted, batches, version_conflicts, noops, retries, failures }
*/
async deleteByNamespace(namespace: string): Promise<any> {
async deleteByNamespace(
namespace: string,
options: SavedObjectsDeleteByNamespaceOptions = {}
): Promise<any> {
if (!namespace || typeof namespace !== 'string') {
throw new TypeError(`namespace is required, and must be a string`);
}
const { refresh = DEFAULT_REFRESH_SETTING } = options;
const allTypes = Object.keys(getRootPropertiesObjects(this._mappings));
const typesToDelete = allTypes.filter(type => !this._schema.isNamespaceAgnostic(type));
@ -357,7 +377,7 @@ export class SavedObjectsRepository {
const esOptions = {
index: this.getIndicesForTypes(typesToDelete),
ignore: [404],
refresh: 'wait_for',
refresh,
body: {
conflicts: 'proceed',
...getSearchDsl(this._mappings, this._schema, {
@ -626,7 +646,7 @@ export class SavedObjectsRepository {
throw SavedObjectsErrorHelpers.createGenericNotFoundError(type, id);
}
const { version, namespace, references } = options;
const { version, namespace, references, refresh = DEFAULT_REFRESH_SETTING } = options;
const time = this._getCurrentTime();
@ -643,7 +663,7 @@ export class SavedObjectsRepository {
id: this._serializer.generateRawId(namespace, type, id),
index: this.getIndexForType(type),
...(version && decodeRequestVersion(version)),
refresh: 'wait_for',
refresh,
ignore: [404],
body: {
doc,
@ -675,7 +695,7 @@ export class SavedObjectsRepository {
*/
async bulkUpdate<T extends SavedObjectAttributes = any>(
objects: Array<SavedObjectsBulkUpdateObject<T>>,
options: SavedObjectsBaseOptions = {}
options: SavedObjectsBulkUpdateOptions = {}
): Promise<SavedObjectsBulkUpdateResponse<T>> {
const time = this._getCurrentTime();
const bulkUpdateParams: object[] = [];
@ -729,9 +749,10 @@ export class SavedObjectsRepository {
return { tag: 'Right' as 'Right', value: expectedResult };
});
const { refresh = DEFAULT_REFRESH_SETTING } = options;
const esResponse = bulkUpdateParams.length
? await this._writeToCluster('bulk', {
refresh: 'wait_for',
refresh,
body: bulkUpdateParams,
})
: {};
@ -794,7 +815,7 @@ export class SavedObjectsRepository {
throw SavedObjectsErrorHelpers.createUnsupportedTypeError(type);
}
const { migrationVersion, namespace } = options;
const { migrationVersion, namespace, refresh = DEFAULT_REFRESH_SETTING } = options;
const time = this._getCurrentTime();
@ -811,7 +832,7 @@ export class SavedObjectsRepository {
const response = await this._writeToCluster('update', {
id: this._serializer.generateRawId(namespace, type, id),
index: this.getIndexForType(type),
refresh: 'wait_for',
refresh,
_source: true,
body: {
script: {

View file

@ -24,6 +24,7 @@ import {
SavedObjectReference,
SavedObjectsMigrationVersion,
SavedObjectsBaseOptions,
MutatingOperationRefreshSetting,
SavedObjectsFindOptions,
} from '../types';
import { SavedObjectsErrorHelpers } from './lib/errors';
@ -40,6 +41,8 @@ export interface SavedObjectsCreateOptions extends SavedObjectsBaseOptions {
/** {@inheritDoc SavedObjectsMigrationVersion} */
migrationVersion?: SavedObjectsMigrationVersion;
references?: SavedObjectReference[];
/** The Elasticsearch Refresh setting for this operation */
refresh?: MutatingOperationRefreshSetting;
}
/**
@ -101,6 +104,35 @@ export interface SavedObjectsUpdateOptions extends SavedObjectsBaseOptions {
version?: string;
/** {@inheritdoc SavedObjectReference} */
references?: SavedObjectReference[];
/** The Elasticsearch Refresh setting for this operation */
refresh?: MutatingOperationRefreshSetting;
}
/**
*
* @public
*/
export interface SavedObjectsBulkUpdateOptions extends SavedObjectsBaseOptions {
/** The Elasticsearch Refresh setting for this operation */
refresh?: MutatingOperationRefreshSetting;
}
/**
*
* @public
*/
export interface SavedObjectsDeleteOptions extends SavedObjectsBaseOptions {
/** The Elasticsearch Refresh setting for this operation */
refresh?: MutatingOperationRefreshSetting;
}
/**
*
* @public
*/
export interface SavedObjectsDeleteByNamespaceOptions extends SavedObjectsBaseOptions {
/** The Elasticsearch Refresh setting for this operation */
refresh?: MutatingOperationRefreshSetting;
}
/**
@ -189,7 +221,7 @@ export class SavedObjectsClient {
* @param id
* @param options
*/
async delete(type: string, id: string, options: SavedObjectsBaseOptions = {}) {
async delete(type: string, id: string, options: SavedObjectsDeleteOptions = {}) {
return await this._repository.delete(type, id, options);
}
@ -260,7 +292,7 @@ export class SavedObjectsClient {
*/
async bulkUpdate<T extends SavedObjectAttributes = any>(
objects: Array<SavedObjectsBulkUpdateObject<T>>,
options?: SavedObjectsBaseOptions
options?: SavedObjectsBulkUpdateOptions
): Promise<SavedObjectsBulkUpdateResponse<T>> {
return await this._repository.bulkUpdate(objects, options);
}

View file

@ -142,6 +142,12 @@ export interface SavedObjectsBaseOptions {
namespace?: string;
}
/**
* Elasticsearch Refresh setting for mutating operation
* @public
*/
export type MutatingOperationRefreshSetting = boolean | 'wait_for';
/**
* Saved Objects is Kibana's data persisentence mechanism allowing plugins to
* use Elasticsearch for storing plugin state.

View file

@ -942,6 +942,9 @@ export type MIGRATION_ASSISTANCE_INDEX_ACTION = 'upgrade' | 'reindex';
// @public (undocumented)
export type MIGRATION_DEPRECATION_LEVEL = 'none' | 'info' | 'warning' | 'critical';
// @public
export type MutatingOperationRefreshSetting = boolean | 'wait_for';
// Warning: (ae-forgotten-export) The symbol "OnPostAuthResult" needs to be exported by the entry point index.d.ts
//
// @public
@ -1196,6 +1199,11 @@ export interface SavedObjectsBulkUpdateObject<T extends SavedObjectAttributes =
type: string;
}
// @public (undocumented)
export interface SavedObjectsBulkUpdateOptions extends SavedObjectsBaseOptions {
refresh?: MutatingOperationRefreshSetting;
}
// @public (undocumented)
export interface SavedObjectsBulkUpdateResponse<T extends SavedObjectAttributes = any> {
// (undocumented)
@ -1208,9 +1216,9 @@ export class SavedObjectsClient {
constructor(repository: SavedObjectsRepository);
bulkCreate<T extends SavedObjectAttributes = any>(objects: Array<SavedObjectsBulkCreateObject<T>>, options?: SavedObjectsCreateOptions): Promise<SavedObjectsBulkResponse<T>>;
bulkGet<T extends SavedObjectAttributes = any>(objects?: SavedObjectsBulkGetObject[], options?: SavedObjectsBaseOptions): Promise<SavedObjectsBulkResponse<T>>;
bulkUpdate<T extends SavedObjectAttributes = any>(objects: Array<SavedObjectsBulkUpdateObject<T>>, options?: SavedObjectsBaseOptions): Promise<SavedObjectsBulkUpdateResponse<T>>;
bulkUpdate<T extends SavedObjectAttributes = any>(objects: Array<SavedObjectsBulkUpdateObject<T>>, options?: SavedObjectsBulkUpdateOptions): Promise<SavedObjectsBulkUpdateResponse<T>>;
create<T extends SavedObjectAttributes = any>(type: string, attributes: T, options?: SavedObjectsCreateOptions): Promise<SavedObject<T>>;
delete(type: string, id: string, options?: SavedObjectsBaseOptions): Promise<{}>;
delete(type: string, id: string, options?: SavedObjectsDeleteOptions): Promise<{}>;
// (undocumented)
errors: typeof SavedObjectsErrorHelpers;
// (undocumented)
@ -1247,6 +1255,12 @@ export interface SavedObjectsCreateOptions extends SavedObjectsBaseOptions {
overwrite?: boolean;
// (undocumented)
references?: SavedObjectReference[];
refresh?: MutatingOperationRefreshSetting;
}
// @public (undocumented)
export interface SavedObjectsDeleteOptions extends SavedObjectsBaseOptions {
refresh?: MutatingOperationRefreshSetting;
}
// @public (undocumented)
@ -1554,6 +1568,7 @@ export class SavedObjectsSerializer {
// @public (undocumented)
export interface SavedObjectsUpdateOptions extends SavedObjectsBaseOptions {
references?: SavedObjectReference[];
refresh?: MutatingOperationRefreshSetting;
version?: string;
}