Skip to content

Commit

Permalink
feat(types): add mapWithArguments to typing definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
nartc committed Feb 14, 2021
1 parent 2732300 commit 4b52da3
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
38 changes: 37 additions & 1 deletion packages/types/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ export type MemberMapReturnNoDefer<
| FromValueReturn<TSource, TDestination, TSelectorReturn>
| ConvertUsingReturn<TSource>
| NullSubstitutionReturn<TSource, TDestination, TSelectorReturn>
| IgnoreReturn;
| IgnoreReturn
| MapWithArgumentsReturn<TSource, TDestination, TSelectorReturn>;

export type PreConditionReturn<
TSource extends Dictionary<TSource> = any,
Expand Down Expand Up @@ -146,6 +147,18 @@ export type NullSubstitutionReturn<

export type IgnoreReturn = [type: TransformationType.Ignore];

export type MapWithArgumentsReturn<
TSource extends Dictionary<TSource> = any,
TDestination extends Dictionary<TDestination> = any,
TSelectorReturn = SelectorReturn<TDestination>
> = [
type: TransformationType.MapWithArguments,
fn: (
source: TSource,
extraArguments: Record<string, unknown>
) => TSelectorReturn
];

export type MapInitializeReturn<
TSource extends Dictionary<TSource> = any,
TDestination extends Dictionary<TDestination> = any,
Expand Down Expand Up @@ -374,6 +387,15 @@ export interface CreateMapFluentFunction<
memberMapFunction: IgnoreReturn
): CreateMapFluentFunction<TSource, TDestination>;

forMember<TMemberType = SelectorReturn<TDestination>>(
selector: Selector<TDestination, TMemberType>,
memberMapFunction: MapWithArgumentsReturn<
TSource,
TDestination,
TMemberType
>
): CreateMapFluentFunction<TSource, TDestination>;

forMember<TMemberType = SelectorReturn<TDestination>>(
selector: Selector<TDestination, TMemberType>,
preConditionFunction: PreConditionReturn<
Expand Down Expand Up @@ -458,6 +480,20 @@ export interface CreateMapFluentFunction<
memberMapFunction: IgnoreReturn
): CreateMapFluentFunction<TSource, TDestination>;

forMember<TMemberType = SelectorReturn<TDestination>>(
selector: Selector<TDestination, TMemberType>,
preConditionFunction: PreConditionReturn<
TSource,
TDestination,
TMemberType
>,
memberMapFunction: MapWithArgumentsReturn<
TSource,
TDestination,
TMemberType
>
): CreateMapFluentFunction<TSource, TDestination>;

forMember<TMemberType = SelectorReturn<TDestination>>(
selector: Selector<TDestination, TMemberType>,
mapDeferFn: MapDeferReturn<TSource, TDestination, TMemberType>
Expand Down
1 change: 1 addition & 0 deletions packages/types/src/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const enum TransformationType {
MapInitialize,
NullSubstitution,
MapDefer,
MapWithArguments,
}

export const enum MappingClassId {
Expand Down
1 change: 1 addition & 0 deletions packages/types/src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface MapOptions<
> {
beforeMap?: MapAction<TSource, TDestination>;
afterMap?: MapAction<TSource, TDestination>;
extraArguments?: Record<string, unknown>;
}

export interface MapArrayOptions<
Expand Down

0 comments on commit 4b52da3

Please sign in to comment.