From 4b52da34947e8fe6cd74e60e7f14435ad7d6f939 Mon Sep 17 00:00:00 2001 From: Chau Tran Date: Sun, 14 Feb 2021 11:32:08 -0600 Subject: [PATCH] feat(types): add mapWithArguments to typing definitions --- packages/types/src/core.ts | 38 ++++++++++++++++++++++++++++++++++- packages/types/src/enums.ts | 1 + packages/types/src/options.ts | 1 + 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/packages/types/src/core.ts b/packages/types/src/core.ts index 6938167af..d8cfc8a24 100644 --- a/packages/types/src/core.ts +++ b/packages/types/src/core.ts @@ -59,7 +59,8 @@ export type MemberMapReturnNoDefer< | FromValueReturn | ConvertUsingReturn | NullSubstitutionReturn - | IgnoreReturn; + | IgnoreReturn + | MapWithArgumentsReturn; export type PreConditionReturn< TSource extends Dictionary = any, @@ -146,6 +147,18 @@ export type NullSubstitutionReturn< export type IgnoreReturn = [type: TransformationType.Ignore]; +export type MapWithArgumentsReturn< + TSource extends Dictionary = any, + TDestination extends Dictionary = any, + TSelectorReturn = SelectorReturn +> = [ + type: TransformationType.MapWithArguments, + fn: ( + source: TSource, + extraArguments: Record + ) => TSelectorReturn +]; + export type MapInitializeReturn< TSource extends Dictionary = any, TDestination extends Dictionary = any, @@ -374,6 +387,15 @@ export interface CreateMapFluentFunction< memberMapFunction: IgnoreReturn ): CreateMapFluentFunction; + forMember>( + selector: Selector, + memberMapFunction: MapWithArgumentsReturn< + TSource, + TDestination, + TMemberType + > + ): CreateMapFluentFunction; + forMember>( selector: Selector, preConditionFunction: PreConditionReturn< @@ -458,6 +480,20 @@ export interface CreateMapFluentFunction< memberMapFunction: IgnoreReturn ): CreateMapFluentFunction; + forMember>( + selector: Selector, + preConditionFunction: PreConditionReturn< + TSource, + TDestination, + TMemberType + >, + memberMapFunction: MapWithArgumentsReturn< + TSource, + TDestination, + TMemberType + > + ): CreateMapFluentFunction; + forMember>( selector: Selector, mapDeferFn: MapDeferReturn diff --git a/packages/types/src/enums.ts b/packages/types/src/enums.ts index d7f84d663..7b365380a 100644 --- a/packages/types/src/enums.ts +++ b/packages/types/src/enums.ts @@ -8,6 +8,7 @@ export const enum TransformationType { MapInitialize, NullSubstitution, MapDefer, + MapWithArguments, } export const enum MappingClassId { diff --git a/packages/types/src/options.ts b/packages/types/src/options.ts index ca7b4d27f..63448f1e4 100644 --- a/packages/types/src/options.ts +++ b/packages/types/src/options.ts @@ -13,6 +13,7 @@ export interface MapOptions< > { beforeMap?: MapAction; afterMap?: MapAction; + extraArguments?: Record; } export interface MapArrayOptions<