// License: LGPL-3.0-or-later // from https://github.com/mtraynham/lodash-joins/blob/c252b462981562451d85d1e09c8f273ce7fe06c5/lib/util/joinWrapper.ts import {Accessor, Join, Merger, NonMergeJoin} from '../typings'; import basicAccessor from './basicAccessor'; import basicMerger from './basicMerger'; /** * Wrap a join function to process inputs in a more succinct manner. */ /* eslint-disable @typescript-eslint/no-explicit-any,@typescript-eslint/consistent-type-assertions */ function joinWrapper( joinFn: NonMergeJoin ): NonMergeJoin; function joinWrapper( joinFn: NonMergeJoin ): NonMergeJoin; function joinWrapper( joinFn: Join ): Join; function joinWrapper( joinFn: Join ): Join; function joinWrapper( joinFn: Join ): Join { return ( a: LeftRow[], aAccessor: Accessor, b: RightRow[] = a, bAccessor: Accessor = aAccessor, merger: Merger = basicMerger ): MergeResult[] => { if (!a) { throw new Error('Missing required left array'); } else if (!aAccessor) { throw new Error('Missing required left accessor'); } return joinFn( a, basicAccessor(aAccessor), b, basicAccessor(bAccessor), merger ); }; } /* eslint-enable @typescript-eslint/no-explicit-any,@typescript-eslint/consistent-type-assertions */ export default joinWrapper;