From 4729fb2309f8a470452ce2f4fa95b3a4640c1b32 Mon Sep 17 00:00:00 2001 From: Sam Noel Date: Fri, 7 Jul 2023 09:22:05 -0400 Subject: [PATCH] merge changes --- package.json | 2 +- src/search.ts | 21 +++++++++++++-------- test/search.test.ts | 4 ++-- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 2757d14..6184341 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@qlever-llc/trellis-data-manager", - "version": "0.1.3", + "version": "0.1.4", "description": "A microservice for managing trellis master data elements.", "main": "dist/index.js", "type": "module", diff --git a/src/search.ts b/src/search.ts index 387730b..22e50de 100644 --- a/src/search.ts +++ b/src/search.ts @@ -361,17 +361,24 @@ export class Search { path: `/${from}`, })) as unknown as { data: Element }; - // Combine the two elements generically; take the union of the content, but - // take the TO values over the FROM values; concat the externalIds - await this.oada.put({ - path: `/${to}`, - data: { + // Provide an opportunity for some additional merge steps + const data = this.merge ? await this.merge(this.oada, job) + // Combine the two elements generically; take the union of the content, but + // take the TO values over the FROM values; concat the externalIds + : { ...fromElement, ...toElement, externalIds: Array.from(new Set(toElement.externalIds ?? [])).concat( fromElement.externalIds ?? [] ), - }, + }; + await this.oada.put({ + path: `/${to}`, + data, + }); + await this.setItem({ + pointer: data.masterid.replace(/^resources\//, ''), + item: data, }); // Delete the element to fail over any queries during the merge @@ -383,8 +390,6 @@ export class Search { // Optimistic removal await this.removeItemExpand({ pointer: fromKey }); await this.removeItem({ pointer: fromKey }); - // Provide an opportunity for some additional merge steps - if (this.merge) await this.merge(this.oada, job); } async update(job: { diff --git a/test/search.test.ts b/test/search.test.ts index c9e038f..e5e11b7 100644 --- a/test/search.test.ts +++ b/test/search.test.ts @@ -425,8 +425,8 @@ test('Generate should throw if an input external id is already in use', async (t t.true(err?.message.startsWith('The supplied External IDs are already in use: sap:12345678')); }); -test('Merge should take two entries and make them one', async (t) => { - t.timeout(25_000); +test.only('Merge should take two entries and make them one', async (t) => { + t.timeout(30_000); search.indexObject = {}; search.setCollection(search.indexObject);