Skip to content

Commit

Permalink
merge changes
Browse files Browse the repository at this point in the history
  • Loading branch information
sanoel committed Jul 7, 2023
1 parent 3902284 commit 4729fb2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
21 changes: 13 additions & 8 deletions src/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,17 +361,24 @@ export class Search<Element extends ElementBase> {
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
Expand All @@ -383,8 +390,6 @@ export class Search<Element extends ElementBase> {
// 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: {
Expand Down
4 changes: 2 additions & 2 deletions test/search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 4729fb2

Please sign in to comment.