Skip to content

Commit

Permalink
fix merging duplicates of complex fieldPaths
Browse files Browse the repository at this point in the history
  • Loading branch information
josephkmh committed Jan 10, 2023
1 parent 6ac4dc6 commit d193819
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,21 @@ describe(`${mergeFieldPathArrays.name}`, () => {
{ fieldPath: FIELD_THREE },
]);
});

it("merges two arrays of complex fieldPaths without duplicates", () => {
const arr1 = [{ fieldPath: [...FIELD_ONE, ...FIELD_TWO] }, { fieldPath: [...FIELD_TWO, ...FIELD_THREE] }];
const arr2 = [
{ fieldPath: [...FIELD_ONE, ...FIELD_TWO] },
{ fieldPath: [...FIELD_TWO, ...FIELD_THREE] },
{ fieldPath: [...FIELD_ONE, ...FIELD_THREE] },
];

expect(mergeFieldPathArrays(arr1, arr2)).toEqual([
{ fieldPath: [...FIELD_ONE, ...FIELD_TWO] },
{ fieldPath: [...FIELD_TWO, ...FIELD_THREE] },
{ fieldPath: [...FIELD_ONE, ...FIELD_THREE] },
]);
});
});

describe(`${updateCursorField.name}`, () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@ import { AirbyteStreamConfiguration, SelectedFieldInfo } from "core/request/Airb
* Merges arrays of SelectedFieldInfo, ensuring there are no duplicates
*/
export function mergeFieldPathArrays(...args: SelectedFieldInfo[][]): SelectedFieldInfo[] {
const set = new Set<string[]>();
const set = new Set<string>();

args.forEach((array) =>
array.forEach((selectedFieldInfo) => {
if (selectedFieldInfo.fieldPath) {
set.add(selectedFieldInfo.fieldPath);
const key = JSON.stringify(selectedFieldInfo.fieldPath);
set.add(key);
}
})
);

return Array.from(set).map((fieldPath) => ({ fieldPath }));
return Array.from(set).map((key) => ({ fieldPath: JSON.parse(key) }));
}

/**
Expand Down

0 comments on commit d193819

Please sign in to comment.