-
-
Notifications
You must be signed in to change notification settings - Fork 90
/
map-with.ts
34 lines (33 loc) · 852 Bytes
/
map-with.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import type {
Dictionary,
MapWithReturn,
SelectorReturn,
} from '@automapper/types';
import {
Fn,
TransformationType,
Unpacked,
ValueSelector,
} from '@automapper/types';
export function mapWith<
TSource extends Dictionary<TSource> = any,
TDestination extends Dictionary<TDestination> = any,
TSelectorReturn = SelectorReturn<TDestination>
>(
withDestination: Fn<Unpacked<unknown | TSelectorReturn>>,
withSourceValue: ValueSelector<TSource>,
withSource: Fn<unknown>
): MapWithReturn<TSource, TDestination, TSelectorReturn> {
return [
TransformationType.MapWith,
(source, mapper) => {
const sourceValue = withSourceValue(source);
return mapper.map(
sourceValue as Dictionary<unknown>,
withDestination() as string,
withSource() as string
);
},
withSourceValue,
];
}