diff --git a/src/core/server/saved_objects/service/lib/repository.test.js b/src/core/server/saved_objects/service/lib/repository.test.js index 4be4c65c111f2..b470ddf8b8cc4 100644 --- a/src/core/server/saved_objects/service/lib/repository.test.js +++ b/src/core/server/saved_objects/service/lib/repository.test.js @@ -555,7 +555,7 @@ describe('SavedObjectsRepository', () => { if_primary_term: mockVersionProps._primary_term, }; - expectClientCallArgsAction([obj1WithSeq, obj2], { method: 'index' }); + expectClusterCallArgsAction([obj1WithSeq, obj2], { method: 'index' }); }); it(`should use the ES create method if ID is defined and overwrite=false`, async () => { @@ -1489,9 +1489,8 @@ describe('SavedObjectsRepository', () => { it(`should use the ES index with version if ID and version are defined and overwrite=true`, async () => { await createSuccess(type, attributes, { id, overwrite: true, version: mockVersion }); - expect(client.index).toHaveBeenCalled(); - - expect(client.index.mock.calls[0][0]).toMatchObject({ + expectClusterCalls('index'); + expectClusterCallArgs({ if_seq_no: mockVersionProps._seq_no, if_primary_term: mockVersionProps._primary_term, }); diff --git a/src/core/server/saved_objects/service/lib/repository.ts b/src/core/server/saved_objects/service/lib/repository.ts index ce9be015a7928..173c0c34b9457 100644 --- a/src/core/server/saved_objects/service/lib/repository.ts +++ b/src/core/server/saved_objects/service/lib/repository.ts @@ -137,11 +137,11 @@ export class SavedObjectsRepository { injectedConstructor: any = SavedObjectsRepository ): ISavedObjectsRepository { const mappings = migrator.getActiveMappings(); - const allTypes = typeRegistry.getAllTypes().map(t => t.name); + const allTypes = typeRegistry.getAllTypes().map((t) => t.name); const serializer = new SavedObjectsSerializer(typeRegistry); - const visibleTypes = allTypes.filter(type => !typeRegistry.isHidden(type)); + const visibleTypes = allTypes.filter((type) => !typeRegistry.isHidden(type)); - const missingTypeMappings = includedHiddenTypes.filter(type => !allTypes.includes(type)); + const missingTypeMappings = includedHiddenTypes.filter((type) => !allTypes.includes(type)); if (missingTypeMappings.length > 0) { throw new Error( `Missing mappings for saved objects types: '${missingTypeMappings.join(', ')}'` @@ -287,7 +287,7 @@ export class SavedObjectsRepository { const time = this._getCurrentTime(); let bulkGetRequestIndexCounter = 0; - const expectedResults: Either[] = objects.map(object => { + const expectedResults: Either[] = objects.map((object) => { if (!this._allowedTypes.includes(object.type)) { return { tag: 'Left' as 'Left', @@ -334,7 +334,7 @@ export class SavedObjectsRepository { let bulkRequestIndexCounter = 0; const bulkCreateParams: object[] = []; - const expectedBulkResults: Either[] = expectedResults.map(expectedBulkGetResult => { + const expectedBulkResults: Either[] = expectedResults.map((expectedBulkGetResult) => { if (isLeft(expectedBulkGetResult)) { return expectedBulkGetResult; } @@ -412,7 +412,7 @@ export class SavedObjectsRepository { : undefined; return { - saved_objects: expectedBulkResults.map(expectedResult => { + saved_objects: expectedBulkResults.map((expectedResult) => { if (isLeft(expectedResult)) { return expectedResult.error as any; } @@ -464,7 +464,7 @@ export class SavedObjectsRepository { preflightResult = await this.preflightCheckIncludesNamespace(type, id, namespace); const existingNamespaces = getSavedObjectNamespaces(undefined, preflightResult); const remainingNamespaces = existingNamespaces?.filter( - x => x !== getNamespaceString(namespace) + (x) => x !== getNamespaceString(namespace) ); if (remainingNamespaces?.length) { @@ -541,7 +541,7 @@ export class SavedObjectsRepository { const { refresh = DEFAULT_REFRESH_SETTING } = options; const allTypes = Object.keys(getRootPropertiesObjects(this._mappings)); - const typesToUpdate = allTypes.filter(type => !this._registry.isNamespaceAgnostic(type)); + const typesToUpdate = allTypes.filter((type) => !this._registry.isNamespaceAgnostic(type)); const updateOptions = { index: this.getIndicesForTypes(typesToUpdate), @@ -612,7 +612,7 @@ export class SavedObjectsRepository { } const types = Array.isArray(type) ? type : [type]; - const allowedTypes = types.filter(t => this._allowedTypes.includes(t)); + const allowedTypes = types.filter((t) => this._allowedTypes.includes(t)); if (allowedTypes.length === 0) { return { page, @@ -719,7 +719,7 @@ export class SavedObjectsRepository { } let bulkGetRequestIndexCounter = 0; - const expectedBulkGetResults: Either[] = objects.map(object => { + const expectedBulkGetResults: Either[] = objects.map((object) => { const { type, id, fields } = object; if (!this._allowedTypes.includes(type)) { @@ -761,7 +761,7 @@ export class SavedObjectsRepository { : undefined; return { - saved_objects: expectedBulkGetResults.map(expectedResult => { + saved_objects: expectedBulkGetResults.map((expectedResult) => { if (isLeft(expectedResult)) { return expectedResult.error as any; } @@ -1014,7 +1014,7 @@ export class SavedObjectsRepository { const preflightResult = await this.preflightCheckIncludesNamespace(type, id, namespace); const existingNamespaces = getSavedObjectNamespaces(undefined, preflightResult); // if there are somehow no existing namespaces, allow the operation to proceed and delete this saved object - const remainingNamespaces = existingNamespaces?.filter(x => !namespaces.includes(x)); + const remainingNamespaces = existingNamespaces?.filter((x) => !namespaces.includes(x)); if (remainingNamespaces?.length) { // if there is 1 or more namespace remaining, update the saved object @@ -1090,7 +1090,7 @@ export class SavedObjectsRepository { const { namespace } = options; let bulkGetRequestIndexCounter = 0; - const expectedBulkGetResults: Either[] = objects.map(object => { + const expectedBulkGetResults: Either[] = objects.map((object) => { const { type, id } = object; if (!this._allowedTypes.includes(type)) { @@ -1146,7 +1146,7 @@ export class SavedObjectsRepository { let bulkUpdateRequestIndexCounter = 0; const bulkUpdateParams: object[] = []; const expectedBulkUpdateResults: Either[] = expectedBulkGetResults.map( - expectedBulkGetResult => { + (expectedBulkGetResult) => { if (isLeft(expectedBulkGetResult)) { return expectedBulkGetResult; } @@ -1211,7 +1211,7 @@ export class SavedObjectsRepository { : {}; return { - saved_objects: expectedBulkUpdateResults.map(expectedResult => { + saved_objects: expectedBulkUpdateResults.map((expectedResult) => { if (isLeft(expectedResult)) { return expectedResult.error as any; } @@ -1364,7 +1364,7 @@ export class SavedObjectsRepository { * @param types The types whose indices should be retrieved */ private getIndicesForTypes(types: string[]) { - return unique(types.map(t => this.getIndexForType(t))); + return unique(types.map((t) => this.getIndexForType(t))); } private _getCurrentTime() {