From f261296c3150f59d9719e8361f9898de7b4b6e4a Mon Sep 17 00:00:00 2001 From: Rafael M Ximenes Date: Tue, 8 Nov 2016 17:56:12 -0200 Subject: [PATCH] New behaviour to nested objects with defined classes. Auto mapping will remove missing properties in destination object that exists in source object --- src/js/AsyncAutoMapper.js | 4 + src/js/AsyncAutoMapper.js.map | 2 +- src/js/AutoMapper.js.map | 2 +- src/js/AutoMapperBase.js | 22 +- src/js/AutoMapperBase.js.map | 2 +- src/js/AutoMapperHelper.js.map | 2 +- src/js/AutoMapperValidator.js.map | 2 +- src/js/Profile.js.map | 2 +- src/js/TypeConverter.js.map | 2 +- .../CamelCaseNamingConvention.js.map | 2 +- .../PascalCaseNamingConvention.js.map | 2 +- src/ts/AsyncAutoMapper.ts | 19 +- src/ts/AutoMapper.ts | 32 +- src/ts/AutoMapperBase.ts | 154 +++++---- test/tests/js/automapper-createmap-specs.js | 178 +++++++--- test/tests/js/automapper-initialize-specs.js | 29 +- test/tests/js/automapper-map-specs.js | 55 +++ test/tests/ts/automapper-createmap-specs.ts | 321 +++++++++++------- test/tests/ts/automapper-initialize-specs.ts | 58 +++- test/tests/ts/automapper-map-specs.ts | 63 +++- 20 files changed, 673 insertions(+), 280 deletions(-) diff --git a/src/js/AsyncAutoMapper.js b/src/js/AsyncAutoMapper.js index 1506d03..cb59b5c 100644 --- a/src/js/AsyncAutoMapper.js +++ b/src/js/AsyncAutoMapper.js @@ -20,10 +20,14 @@ var AutoMapperJs; _super.call(this); AsyncAutoMapper.asyncInstance = this; } + AsyncAutoMapper.prototype.createMap = function (sourceKeyOrType, destinationKeyOrType) { + throw new Error('Not implemented method'); + }; AsyncAutoMapper.prototype.createMapForMember = function (property, func, metadata) { var _this = this; var mapping = property.metadata.mapping; mapping.async = true; + //noinspection TypeScriptValidateTypes mapping.mapItemFunction = function (m, srcObj, dstObj, cb) { return _this.mapItem(m, srcObj, dstObj, cb); }; property.async = true; property.conversionValuesAndFunctions.push(func); diff --git a/src/js/AsyncAutoMapper.js.map b/src/js/AsyncAutoMapper.js.map index 29a1a32..6f32367 100644 --- a/src/js/AsyncAutoMapper.js.map +++ b/src/js/AsyncAutoMapper.js.map @@ -1 +1 @@ -{"version":3,"sources":["AsyncAutoMapper.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAC9D,sCAAsC;AACtC,yCAAyC;AACzC,4CAA4C;AAC5C,+CAA+C;;;;;;AAE/C,IAAO,YAAY,CA8LlB;AA9LD,WAAO,YAAY,EAAC,CAAC;IACjB,YAAY,CAAC;IAEb;;OAEG;IACH;QAAqC,mCAAc;QAG/C;YACI,iBAAO,CAAC;YACR,eAAe,CAAC,aAAa,GAAG,IAAI,CAAC;QACzC,CAAC;QAEM,4CAAkB,GAAzB,UAA0B,QAAmB,EACnB,IAAwE,EACxE,QAAgC;YAF1D,iBASC;YANS,uCAAO,CAAuB;YAEpC,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC;YACrB,OAAO,CAAC,eAAe,GAAG,UAAC,CAAW,EAAE,MAAW,EAAE,MAAW,EAAE,EAAgB,IAAK,OAAA,KAAI,CAAC,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC,EAAnC,CAAmC,CAAC;YAC3H,QAAQ,CAAC,KAAK,GAAG,IAAI,CAAC;YACtB,QAAQ,CAAC,4BAA4B,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACrD,CAAC;QAEM,+CAAqB,GAA5B,UAA6B,OAAiB,EAAE,iBAAsE;YAAtH,iBAIC;YAHG,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC;YACrB,OAAO,CAAC,qBAAqB,GAAG,iBAAiB,CAAC;YAClD,OAAO,CAAC,eAAe,GAAG,UAAC,CAAW,EAAE,MAAW,EAAE,MAAW,EAAE,EAAgB,IAAK,OAAA,KAAI,CAAC,yBAAyB,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC,EAArD,CAAqD,CAAC;QACjJ,CAAC;QAM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IAAiC,EAAE,QAAyB;YAC9G,oCAAoC;YACpC,IAAI,IAAI,GAAG,6BAAgB,CAAC,qBAAqB,CAAC,IAAI,CAAC,CAAC;YACxD,EAAE,CAAC,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC;gBACpB,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;gBACrB,MAAM,CAAC;YACX,CAAC;YAED,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QACzB,CAAC;QArLc,6BAAa,GAAG,IAAI,eAAe,EAAE,CAAC;QAsLzD,sBAAC;IAAD,CAvLA,AAuLC,CAvLoC,2BAAc,GAuLlD;IAvLY,4BAAe,kBAuL3B,CAAA;AACL,CAAC,EA9LM,YAAY,KAAZ,YAAY,QA8LlB","file":"AsyncAutoMapper.js","sourcesContent":["/// \r\n/// \r\n/// \r\n/// \r\n/// \r\n\r\nmodule AutoMapperJs {\r\n 'use strict';\r\n\r\n /**\r\n * AsyncAutoMapper implementation, for asynchronous mapping support when using AutoMapper.\r\n */\r\n export class AsyncAutoMapper extends AutoMapperBase {\r\n private static asyncInstance = new AsyncAutoMapper();\r\n\r\n constructor() {\r\n super();\r\n AsyncAutoMapper.asyncInstance = this;\r\n }\r\n\r\n public createMapForMember(property: IProperty,\r\n func: ((opts: IMemberConfigurationOptions, cb: IMemberCallback) => void),\r\n metadata: IMemberMappingMetaData): void {\r\n var { mapping } = property.metadata;\r\n\r\n mapping.async = true;\r\n mapping.mapItemFunction = (m: IMapping, srcObj: any, dstObj: any, cb: IMapCallback) => this.mapItem(m, srcObj, dstObj, cb);\r\n property.async = true;\r\n property.conversionValuesAndFunctions.push(func);\r\n }\r\n\r\n public createMapConvertUsing(mapping: IMapping, converterFunction: (ctx: IResolutionContext, cb: IMapCallback) => void): void {\r\n mapping.async = true;\r\n mapping.typeConverterFunction = converterFunction;\r\n mapping.mapItemFunction = (m: IMapping, srcObj: any, dstObj: any, cb: IMapCallback) => this.mapItemUsingTypeConverter(m, srcObj, dstObj, cb);\r\n }\r\n\r\n public map(m: { [key: string]: IMapping }, srcKey: string | (new () => any)): (dstKey: string | (new () => any), srcObj: any, cb: IMapCallback) => void;\r\n public map(m: { [key: string]: IMapping }, srcKey: string | (new () => any), dstKey: string | (new () => any)): (srcObj: any, cb: IMapCallback) => void;\r\n public map(m: { [key: string]: IMapping }, srcKey: string | (new () => any), dstKey?: string | (new () => any), sourceObject?: any): (cb: IMapCallback) => void;\r\n public map(m: { [key: string]: IMapping }, srcKey: string | (new () => any), dstKey?: string | (new () => any), sourceObject?: any, cb?: IMapCallback): void;\r\n public map(\r\n mappings: { [key: string]: IMapping }, sourceKey: string | (new () => any), destinationKey?: string | (new () => any), sourceObject?: any, callback?: IMapCallback\r\n ): any /* actually, void (impossible with overloads) */ {\r\n\r\n switch (arguments.length) {\r\n case 5:\r\n this.mapWithMapping(super.getMapping(mappings, sourceKey, destinationKey), sourceObject, callback);\r\n return;\r\n // provide performance optimized (preloading) currying support.\r\n case 4:\r\n return (cb: IMapCallback) => this.mapWithMapping(super.getMapping(mappings, sourceKey, destinationKey), sourceObject, cb);\r\n case 3:\r\n return (srcObj: any, cb: IMapCallback) => this.mapWithMapping(super.getMapping(mappings, sourceKey, destinationKey), srcObj, cb);\r\n case 2:\r\n return (dstKey: string | (new () => any), srcObj: any, cb: IMapCallback) => this.map(mappings, sourceKey, dstKey, srcObj, cb);\r\n default:\r\n throw new Error('The AsyncAutoMapper.map function expects between 2 and 5 parameters, you provided ' + arguments.length + '.');\r\n }\r\n }\r\n\r\n public mapWithMapping(mapping: IMapping, sourceObject: any, callback: IMapCallback): void {\r\n if (super.isArray(sourceObject)) {\r\n this.mapArray(mapping, sourceObject, callback);\r\n return;\r\n }\r\n\r\n return (mapping.mapItemFunction)(mapping, sourceObject, super.createDestinationObject(mapping.destinationTypeClass), callback);\r\n }\r\n\r\n /**\r\n * Execute a mapping from the source array to a new destination array with explicit mapping configuration and supplied mapping options (using createMap).\r\n * @param mapping The mapping configuration for the current mapping keys/types.\r\n * @param sourceArray The source array to map.\r\n * @returns {Array} Destination array.\r\n */\r\n private mapArray(mapping: IMapping, sourceArray: Array, callback: IMapCallback): void {\r\n var callbacksToGo = 0;\r\n\r\n var destinationArray = super.handleArray(mapping, sourceArray, (sourceObject: any, destinationObject: any) => {\r\n callbacksToGo++;\r\n (mapping.mapItemFunction)(mapping, sourceObject, destinationObject, (result: any): void => {\r\n callbacksToGo--;\r\n });\r\n });\r\n\r\n var waitForCallbackToSend = (): void => {\r\n if (callbacksToGo === 0) {\r\n callback(destinationArray);\r\n } else {\r\n setTimeout((): void => {\r\n waitForCallbackToSend();\r\n }, 10 * callbacksToGo);\r\n }\r\n };\r\n\r\n waitForCallbackToSend();\r\n }\r\n\r\n private mapItemUsingTypeConverter(mapping: IMapping, sourceObject: any, destinationObject: any, callback: IMapCallback): void {\r\n var resolutionContext: IResolutionContext = {\r\n sourceValue: sourceObject,\r\n destinationValue: destinationObject\r\n };\r\n (<(ctx: IResolutionContext, cb: IMapCallback) => any>mapping.typeConverterFunction)(resolutionContext, callback);\r\n }\r\n\r\n /**\r\n * Execute a mapping from the source object to a new destination object with explicit mapping configuration and supplied mapping options (using createMap).\r\n * @param mapping The mapping configuration for the current mapping keys/types.\r\n * @param sourceObject The source object to map.\r\n * @param destinationObject The destination object to map to.\r\n * @param callback The callback to call after async mapping has been executed.\r\n */\r\n private mapItem(mapping: IMapping, sourceObject: any, destinationObject: any, callback: IMapCallback): void {\r\n var callbacksToGo = 0;\r\n\r\n super.handleItem(mapping, sourceObject, destinationObject, (sourceProperty: string) => {\r\n callbacksToGo++;\r\n this.mapProperty(mapping, sourceObject, sourceProperty, destinationObject, (result: any): void => {\r\n callbacksToGo--;\r\n });\r\n });\r\n\r\n var waitForCallbackToSend = (): void => {\r\n if (callbacksToGo === 0) {\r\n callback(destinationObject);\r\n } else {\r\n setTimeout((): void => {\r\n waitForCallbackToSend();\r\n }, 10 * callbacksToGo);\r\n }\r\n };\r\n\r\n waitForCallbackToSend();\r\n }\r\n\r\n /**\r\n * Execute a mapping from the source object property to the destination object property with explicit mapping configuration and supplied mapping options.\r\n * @param mapping The mapping configuration for the current mapping keys/types.\r\n * @param sourceObject The source object to map.\r\n * @param sourcePropertyName The source property to map.\r\n * @param destinationObject The destination object to map to.\r\n * @param callback The callback to call after async property mapping has been executed.\r\n */\r\n private mapProperty(mapping: IMapping, sourceObject: any, sourceProperty: string, destinationObject: any, callback: IMemberCallback): void {\r\n super.handleProperty(mapping, sourceObject, sourceProperty, destinationObject,\r\n (destinations: IProperty[], valuesAndFunctions: Array, opts: IMemberConfigurationOptions) => {\r\n this.handlePropertyMappings(valuesAndFunctions, opts, (destinationPropertyValue: any) => {\r\n for (let destination of destinations) {\r\n super.setPropertyValue(mapping, destinationObject, destination, destinationPropertyValue);\r\n }\r\n callback(destinationPropertyValue);\r\n });\r\n }, (destinationPropertyValue: any) => {\r\n callback(destinationPropertyValue);\r\n });\r\n }\r\n\r\n private handlePropertyMappings(valuesAndFunctions: Array, opts: IMemberConfigurationOptions, callback: IMemberCallback): void {\r\n if (!valuesAndFunctions || valuesAndFunctions.length === 0) {\r\n callback(opts.intermediatePropertyValue);\r\n return;\r\n }\r\n\r\n var valueOrFunction = valuesAndFunctions[0];\r\n\r\n if (typeof valueOrFunction === 'function') {\r\n this.handlePropertyMappingFunction(valueOrFunction, opts, (result: any) => {\r\n if (typeof result !== 'undefined') {\r\n opts.intermediatePropertyValue = result;\r\n\r\n // recursively walk values/functions\r\n this.handlePropertyMappings(valuesAndFunctions.slice(1), opts, callback);\r\n }\r\n });\r\n } else {\r\n // valueOrFunction is a value\r\n opts.intermediatePropertyValue = valueOrFunction;\r\n\r\n // recursively walk values/functions\r\n this.handlePropertyMappings(valuesAndFunctions.slice(1), opts, callback);\r\n }\r\n }\r\n\r\n private handlePropertyMappingFunction(func: Function, opts: IMemberConfigurationOptions, callback: IMemberCallback): void {\r\n // check if function is asynchronous\r\n var args = AutoMapperHelper.getFunctionParameters(func);\r\n if (args.length === 2) { // asynchronous: opts, callback\r\n func(opts, callback);\r\n return;\r\n }\r\n\r\n callback(func(opts));\r\n }\r\n }\r\n}"],"sourceRoot":"/source/"} \ No newline at end of file +{"version":3,"sources":["AsyncAutoMapper.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAC9D,sCAAsC;AACtC,yCAAyC;AACzC,4CAA4C;AAC5C,+CAA+C;;;;;;AAE/C,IAAO,YAAY,CAuMlB;AAvMD,WAAO,YAAY,EAAC,CAAC;IACjB,YAAY,CAAC;IAEb;;OAEG;IACH;QAAqC,mCAAc;QAG/C;YACI,iBAAO,CAAC;YACR,eAAe,CAAC,aAAa,GAAG,IAAI,CAAC;QACzC,CAAC;QAEM,mCAAS,GAAhB,UAAiB,eAAwC,EAAE,oBAA6C;YACpG,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;QAC9C,CAAC;QAEM,4CAAkB,GAAzB,UAA0B,QAAmB,EACnB,IAAwE,EACxE,QAAgC;YAF1D,iBAUC;YAPQ,uCAAO,CAAsB;YAElC,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC;YACrB,sCAAsC;YACtC,OAAO,CAAC,eAAe,GAAG,UAAC,CAAW,EAAE,MAAW,EAAE,MAAW,EAAE,EAAgB,IAAK,OAAA,KAAI,CAAC,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC,EAAnC,CAAmC,CAAC;YAC3H,QAAQ,CAAC,KAAK,GAAG,IAAI,CAAC;YACtB,QAAQ,CAAC,4BAA4B,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACrD,CAAC;QAEM,+CAAqB,GAA5B,UAA6B,OAAiB,EAAE,iBAAsE;YAAtH,iBAIC;YAHG,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC;YACrB,OAAO,CAAC,qBAAqB,GAAG,iBAAiB,CAAC;YAClD,OAAO,CAAC,eAAe,GAAG,UAAC,CAAW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AI,CAAC,sBAAsB,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;YAC7E,CAAC;QACL,CAAC;QAEO,uDAA6B,GAArC,UAAsC,IAAc,EAAE,IAAiC,EAAE,QAAyB;YAC9G,oCAAoC;YACpC,IAAI,IAAI,GAAG,6BAAgB,CAAC,qBAAqB,CAAC,IAAI,CAAC,CAAC;YACxD,EAAE,CAAC,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC;gBACpB,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;gBACrB,MAAM,CAAC;YACX,CAAC;YAED,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QACzB,CAAC;QA5Lc,6BAAa,GAAG,IAAI,eAAe,EAAE,CAAC;QA+LzD,sBAAC;IAAD,CAhMA,AAgMC,CAhMoC,2BAAc,GAgMlD;IAhMY,4BAAe,kBAgM3B,CAAA;AACL,CAAC,EAvMM,YAAY,KAAZ,YAAY,QAuMlB","file":"AsyncAutoMapper.js","sourcesContent":["/// \r\n/// \r\n/// \r\n/// \r\n/// \r\n\r\nmodule AutoMapperJs {\r\n 'use strict';\r\n\r\n /**\r\n * AsyncAutoMapper implementation, for asynchronous mapping support when using AutoMapper.\r\n */\r\n export class AsyncAutoMapper extends AutoMapperBase {\r\n private static asyncInstance = new AsyncAutoMapper();\r\n\r\n constructor() {\r\n super();\r\n AsyncAutoMapper.asyncInstance = this;\r\n }\r\n\r\n public createMap(sourceKeyOrType: string | (new() => any), destinationKeyOrType: string | (new() => any)): any {\r\n throw new Error('Not implemented method');\r\n }\r\n\r\n public createMapForMember(property: IProperty,\r\n func: ((opts: IMemberConfigurationOptions, cb: IMemberCallback) => void),\r\n metadata: IMemberMappingMetaData): void {\r\n var {mapping} = property.metadata;\r\n\r\n mapping.async = true;\r\n //noinspection TypeScriptValidateTypes\r\n mapping.mapItemFunction = (m: IMapping, srcObj: any, dstObj: any, cb: IMapCallback) => this.mapItem(m, srcObj, dstObj, cb);\r\n property.async = true;\r\n property.conversionValuesAndFunctions.push(func);\r\n }\r\n\r\n public createMapConvertUsing(mapping: IMapping, converterFunction: (ctx: IResolutionContext, cb: IMapCallback) => void): void {\r\n mapping.async = true;\r\n mapping.typeConverterFunction = converterFunction;\r\n mapping.mapItemFunction = (m: IMapping, srcObj: any, dstObj: any, cb: IMapCallback) => this.mapItemUsingTypeConverter(m, srcObj, dstObj, cb);\r\n }\r\n\r\n public map(m: { [key: string]: IMapping }, srcKey: string | (new () => any)): (dstKey: string | (new () => any), srcObj: any, cb: IMapCallback) => void;\r\n public map(m: { [key: string]: IMapping }, srcKey: string | (new () => any), dstKey: string | (new () => any)): (srcObj: any, cb: IMapCallback) => void;\r\n public map(m: { [key: string]: IMapping }, srcKey: string | (new () => any), dstKey?: string | (new () => any), sourceObject?: any): (cb: IMapCallback) => void;\r\n public map(m: { [key: string]: IMapping }, srcKey: string | (new () => any), dstKey?: string | (new () => any), sourceObject?: any, cb?: IMapCallback): void;\r\n public map(mappings: { [key: string]: IMapping },\r\n sourceKey: string | (new () => any),\r\n destinationKey?: string | (new () => any),\r\n sourceObject?: any,\r\n callback?: IMapCallback): any /* actually, void (impossible with overloads) */ {\r\n\r\n switch (arguments.length) {\r\n case 5:\r\n this.mapWithMapping(super.getMapping(mappings, sourceKey, destinationKey), sourceObject, callback);\r\n return;\r\n // provide performance optimized (preloading) currying support.\r\n case 4:\r\n return (cb: IMapCallback) => this.mapWithMapping(super.getMapping(mappings, sourceKey, destinationKey), sourceObject, cb);\r\n case 3:\r\n return (srcObj: any, cb: IMapCallback) => this.mapWithMapping(super.getMapping(mappings, sourceKey, destinationKey), srcObj, cb);\r\n case 2:\r\n return (dstKey: string | (new () => any), srcObj: any, cb: IMapCallback) => this.map(mappings, sourceKey, dstKey, srcObj, cb);\r\n default:\r\n throw new Error('The AsyncAutoMapper.map function expects between 2 and 5 parameters, you provided ' + arguments.length + '.');\r\n }\r\n }\r\n\r\n public mapWithMapping(mapping: IMapping, sourceObject: any, callback: IMapCallback): void {\r\n if (super.isArray(sourceObject)) {\r\n this.mapArray(mapping, sourceObject, callback);\r\n return;\r\n }\r\n\r\n return (mapping.mapItemFunction)(mapping, sourceObject, super.createDestinationObject(mapping.destinationTypeClass), callback);\r\n }\r\n\r\n /**\r\n * Execute a mapping from the source array to a new destination array with explicit mapping configuration and supplied mapping options (using createMap).\r\n * @param mapping The mapping configuration for the current mapping keys/types.\r\n * @param sourceArray The source array to map.\r\n * @returns {Array} Destination array.\r\n */\r\n private mapArray(mapping: IMapping, sourceArray: Array, callback: IMapCallback): void {\r\n var callbacksToGo = 0;\r\n\r\n var destinationArray = super.handleArray(mapping, sourceArray, (sourceObject: any, destinationObject: any) => {\r\n callbacksToGo++;\r\n (mapping.mapItemFunction)(mapping, sourceObject, destinationObject, (result: any): void => {\r\n callbacksToGo--;\r\n });\r\n });\r\n\r\n var waitForCallbackToSend = (): void => {\r\n if (callbacksToGo === 0) {\r\n callback(destinationArray);\r\n } else {\r\n setTimeout((): void => {\r\n waitForCallbackToSend();\r\n }, 10 * callbacksToGo);\r\n }\r\n };\r\n\r\n waitForCallbackToSend();\r\n }\r\n\r\n private mapItemUsingTypeConverter(mapping: IMapping, sourceObject: any, destinationObject: any, callback: IMapCallback): void {\r\n var resolutionContext: IResolutionContext = {\r\n sourceValue: sourceObject,\r\n destinationValue: destinationObject\r\n };\r\n (<(ctx: IResolutionContext, cb: IMapCallback) => any>mapping.typeConverterFunction)(resolutionContext, callback);\r\n }\r\n\r\n /**\r\n * Execute a mapping from the source object to a new destination object with explicit mapping configuration and supplied mapping options (using createMap).\r\n * @param mapping The mapping configuration for the current mapping keys/types.\r\n * @param sourceObject The source object to map.\r\n * @param destinationObject The destination object to map to.\r\n * @param callback The callback to call after async mapping has been executed.\r\n */\r\n private mapItem(mapping: IMapping, sourceObject: any, destinationObject: any, callback: IMapCallback): void {\r\n var callbacksToGo = 0;\r\n\r\n super.handleItem(mapping, sourceObject, destinationObject, (sourceProperty: string) => {\r\n callbacksToGo++;\r\n this.mapProperty(mapping, sourceObject, sourceProperty, destinationObject, (result: any): void => {\r\n callbacksToGo--;\r\n });\r\n });\r\n\r\n var waitForCallbackToSend = (): void => {\r\n if (callbacksToGo === 0) {\r\n callback(destinationObject);\r\n } else {\r\n setTimeout((): void => {\r\n waitForCallbackToSend();\r\n }, 10 * callbacksToGo);\r\n }\r\n };\r\n\r\n waitForCallbackToSend();\r\n }\r\n\r\n /**\r\n * Execute a mapping from the source object property to the destination object property with explicit mapping configuration and supplied mapping options.\r\n * @param mapping The mapping configuration for the current mapping keys/types.\r\n * @param sourceObject The source object to map.\r\n * @param sourcePropertyName The source property to map.\r\n * @param destinationObject The destination object to map to.\r\n * @param callback The callback to call after async property mapping has been executed.\r\n */\r\n private mapProperty(mapping: IMapping, sourceObject: any, sourceProperty: string, destinationObject: any, callback: IMemberCallback): void {\r\n super.handleProperty(mapping, sourceObject, sourceProperty, destinationObject,\r\n (destinations: IProperty[], valuesAndFunctions: Array, opts: IMemberConfigurationOptions) => {\r\n this.handlePropertyMappings(valuesAndFunctions, opts, (destinationPropertyValue: any) => {\r\n for (let destination of destinations) {\r\n super.setPropertyValue(mapping, destinationObject, destination, destinationPropertyValue);\r\n }\r\n callback(destinationPropertyValue);\r\n });\r\n }, (destinationPropertyValue: any) => {\r\n callback(destinationPropertyValue);\r\n });\r\n }\r\n\r\n private handlePropertyMappings(valuesAndFunctions: Array, opts: IMemberConfigurationOptions, callback: IMemberCallback): void {\r\n if (!valuesAndFunctions || valuesAndFunctions.length === 0) {\r\n callback(opts.intermediatePropertyValue);\r\n return;\r\n }\r\n\r\n var valueOrFunction = valuesAndFunctions[0];\r\n\r\n if (typeof valueOrFunction === 'function') {\r\n this.handlePropertyMappingFunction(valueOrFunction, opts, (result: any) => {\r\n if (typeof result !== 'undefined') {\r\n opts.intermediatePropertyValue = result;\r\n\r\n // recursively walk values/functions\r\n this.handlePropertyMappings(valuesAndFunctions.slice(1), opts, callback);\r\n }\r\n });\r\n } else {\r\n // valueOrFunction is a value\r\n opts.intermediatePropertyValue = valueOrFunction;\r\n\r\n // recursively walk values/functions\r\n this.handlePropertyMappings(valuesAndFunctions.slice(1), opts, callback);\r\n }\r\n }\r\n\r\n private handlePropertyMappingFunction(func: Function, opts: IMemberConfigurationOptions, callback: IMemberCallback): void {\r\n // check if function is asynchronous\r\n var args = AutoMapperHelper.getFunctionParameters(func);\r\n if (args.length === 2) { // asynchronous: opts, callback\r\n func(opts, callback);\r\n return;\r\n }\r\n\r\n callback(func(opts));\r\n }\r\n\r\n\r\n }\r\n}\r\n"]} \ No newline at end of file diff --git a/src/js/AutoMapper.js.map b/src/js/AutoMapper.js.map index 03f4569..a470c6b 100644 --- a/src/js/AutoMapper.js.map +++ b/src/js/AutoMapper.js.map @@ -1 +1 @@ -{"version":3,"sources":["AutoMapper.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAC9D,0CAA0C;AAC1C,2CAA2C;AAC3C,yCAAyC;AACzC,4CAA4C;AAC5C,+CAA+C;;;;;;AAE/C,IAAO,YAAY,CAimBlB;AAjmBD,WAAO,YAAY,EAAC,CAAC;IACjB,YAAY,CAAC;IAeb;QAAgC,8BAAc;QAY1C;;;WAGG;QACH;YACI,iBAAO,CAAC;YAER,EAAE,CAAC,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC;gBACvB,MAAM,CAAC,UAAU,CAAC,SAAS,CAAC;YAChC,CAAC;YAAC,IAAI,CAAC,CAAC;gBACJ,UAAU,CAAC,SAAS,GAAG,IAAI,CAAC;gBAE5B,IAAI,CAAC,SAAS,GAAG,EAAE,CAAC;gBACpB,IAAI,CAAC,SAAS,GAAG,EAAE,CAAC;gBAEpB,IAAI,CAAC,YAAY,GAAG,IAAI,4BAAe,EAAE,CAAC;YAC9C,CAAC;QACL,CAAC;QArBa,sBAAW,GAAzB;YACI,MAAM,CAAC,UAAU,CAA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tD,CAAsD;gBAC1D,oBAAoB,EAAE,cAAoB,OAAA,KAAI,CAAC,6BAA6B,CAAC,OAAO,EAAE,UAAU,CAAC,EAAvD,CAAuD;gBACjG,aAAa,EAAE,UAAC,IAAmB,IAAmB,OAAA,KAAI,CAAC,sBAAsB,CAAC,OAAO,EAAE,UAAU,EAAE,IAAI,CAAC,EAAtD,CAAsD;gBAC5G,YAAY,EAAE,UAAC,aAAoD;oBAC/D,OAAA,KAAI,CAAC,qBAAqB,CAAC,OAAO,EAAE,aAAa,CAAC;gBAAlD,CAAkD;gBACtD,WAAW,EAAE,UAAC,OAAe,IAAY,OAAA,KAAI,CAAC,oBAAoB,CAAC,OAAO,EAAE,OAAO,CAAC,EAA3C,CAA2C;aACvF,CAAC;YAEF,MAAM,CAAC,UAAU,CAAC;QACtB,CAAC;QA9kBc,oBAAS,GAAG,IAAI,UAAU,EAAE,CAAC;QA+kBhD,iBAAC;IAAD,CAhlBA,AAglBC,CAhlB+B,2BAAc,GAglB7C;IAhlBY,uBAAU,aAglBtB,CAAA;AACL,CAAC,EAjmBM,YAAY,KAAZ,YAAY,QAimBlB;AAED,0HAA0H;AAC1H,IAAI,UAAU,GAA4B,CAAC,UAAC,GAAQ;IAChD,GAAG,CAAC,UAAU,GAAG,YAAY,CAAC,UAAU,CAAC,WAAW,EAAE,CAAC;IACvD,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC;AAC1B,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC","file":"AutoMapper.js","sourcesContent":["/// \r\n/// \r\n/// \r\n/// \r\n/// \r\n/// \r\n\r\nmodule AutoMapperJs {\r\n 'use strict';\r\n\r\n // interface shorthands\r\n type IFluentFunc = ICreateMapFluentFunctions;\r\n type IDMCO = IMemberConfigurationOptions;\r\n type ISMCO = ISourceMemberConfigurationOptions;\r\n type IMC = IMemberCallback;\r\n type IRC = IResolutionContext;\r\n type TC = TypeConverter;\r\n\r\n // method overload shorthands\r\n type stringOrClass = string | (new() => any);\r\n type forMemberValueOrFunction = any | ((opts: IDMCO) => any) | ((opts: IDMCO, cb: IMC) => void);\r\n type convertUsingClassOrInstanceOrFunction = ((ctx: IRC) => any) | ((ctx: IRC, callback: IMapCallback) => void) | TC | (new() => TC);\r\n\r\n export class AutoMapper extends AutoMapperBase {\r\n private static _instance = new AutoMapper();\r\n\r\n private _profiles: { [name: string]: IProfile };\r\n private _mappings: { [key: string]: IMapping };\r\n\r\n private _asyncMapper: AsyncAutoMapper;\r\n\r\n public static getInstance(): AutoMapper {\r\n return AutoMapper._instance;\r\n }\r\n\r\n /**\r\n * This class is intended to be a Singleton. Preferrably use getInstance() \r\n * function instead of using the constructor directly from code.\r\n */\r\n constructor() {\r\n super();\r\n\r\n if (AutoMapper._instance) {\r\n return AutoMapper._instance;\r\n } else {\r\n AutoMapper._instance = this;\r\n\r\n this._profiles = {};\r\n this._mappings = {};\r\n\r\n this._asyncMapper = new AsyncAutoMapper();\r\n }\r\n }\r\n\r\n /**\r\n * Initializes the mapper with the supplied configuration.\r\n * @param {(config: IConfiguration) => void} configFunction Configuration function to call.\r\n */\r\n public initialize(configFunction: (config: IConfiguration) => void): void {\r\n var that = this;\r\n\r\n var configuration: IConfiguration = {\r\n addProfile: (profile: IProfile) : void => {\r\n profile.configure();\r\n that._profiles[profile.profileName] = profile;\r\n },\r\n createMap: function (sourceKey: string, destinationKey: string): IFluentFunc {\r\n // pass through using arguments to keep createMap's currying support fully functional.\r\n return that.createMap.apply(that, arguments);\r\n }\r\n };\r\n\r\n configFunction(configuration);\r\n }\r\n\r\n /**\r\n * Create a mapping profile.\r\n * @param {string} sourceKey The map source key.\r\n * @param {string} destinationKey The map destination key.\r\n * @returns {Core.ICreateMapFluentFunctions}\r\n */\r\n public createMap(sourceKeyOrType: string | (new() => any), destinationKeyOrType: string | (new() => any)): IFluentFunc {\r\n // provide currying support.\r\n if (arguments.length < 2) {\r\n return AutoMapperHelper.handleCurrying(this.createMap, arguments, this);\r\n }\r\n\r\n var mapping = this.createMappingObjectForGivenKeys(sourceKeyOrType, destinationKeyOrType);\r\n\r\n return this.createMapGetFluentApiFunctions(mapping);\r\n }\r\n\r\n /**\r\n * Execute a mapping from the source object to a new destination object with explicit mapping configuration and supplied mapping options (using createMap).\r\n * @param sourceKey Source key, for instance the source type name.\r\n * @param destinationKey Destination key, for instance the destination type name.\r\n * @param sourceObject The source object to map.\r\n * @returns {any} Destination object.\r\n */\r\n public map(sourceKeyOrType: stringOrClass, destinationKeyOrType: stringOrClass, sourceObject: any): any {\r\n if (arguments.length === 3) {\r\n return this.mapInternal(super.getMapping(this._mappings, sourceKeyOrType, destinationKeyOrType), sourceObject);\r\n }\r\n\r\n // provide performance optimized (preloading) currying support.\r\n if (arguments.length === 2) {\r\n return (srcObj: any) => this.mapInternal(super.getMapping(this._mappings, sourceKeyOrType, destinationKeyOrType), srcObj);\r\n }\r\n\r\n if (arguments.length === 1) {\r\n return (dstKey: string | (new() => any), srcObj: any) => this.map(sourceKeyOrType, dstKey, srcObj);\r\n }\r\n\r\n return (srcKey: string | (new() => any), dstKey: string | (new() => any), srcObj: any) => this.map(srcKey, dstKey, srcObj);\r\n }\r\n\r\n /**\r\n * Execute an asynchronous mapping from the source object to a new destination object with explicit mapping configuration and supplied mapping options (using createMap).\r\n * @param sourceKey Source key, for instance the source type name.\r\n * @param destinationKey Destination key, for instance the destination type name.\r\n * @param sourceObject The source object to map.\r\n * @param {IMapCallback} callback The callback to call when asynchronous mapping is complete.\r\n */\r\n public mapAsync(sourceKeyOrType: string | (new() => any), destinationKeyOrType: string | (new() => any), sourceObject: any, callback: IMapCallback): any {\r\n switch (arguments.length) {\r\n case 4:\r\n return this._asyncMapper.map(this._mappings, sourceKeyOrType, destinationKeyOrType, sourceObject, callback);\r\n case 3:\r\n return this._asyncMapper.map(this._mappings, sourceKeyOrType, destinationKeyOrType, sourceObject);\r\n case 2:\r\n return this._asyncMapper.map(this._mappings, sourceKeyOrType, destinationKeyOrType);\r\n case 1:\r\n return this._asyncMapper.map(this._mappings, sourceKeyOrType);\r\n default:\r\n throw new Error('The mapAsync function expects between 1 and 4 parameters, you provided ' + arguments.length + '.');\r\n }\r\n }\r\n\r\n /**\r\n * Validates mapping configuration by dry-running. Since JS does not fully support typing, it only checks if properties match on both\r\n * sides. The function needs IMapping.sourceTypeClass and IMapping.destinationTypeClass to function.\r\n * @param {boolean} strictMode Whether or not to fail when properties sourceTypeClass or destinationTypeClass are unavailable. \r\n */\r\n public assertConfigurationIsValid(strictMode: boolean = true): void {\r\n AutoMapperValidator.assertConfigurationIsValid(this._mappings, strictMode);\r\n }\r\n\r\n private createMapForMember(parameters: ICreateMapParameters): IFluentFunc {\r\n var { mapping, destinationProperty, conversionValueOrFunction, sourceMapping, fluentFunctions } = parameters;\r\n\r\n var metadata = AutoMapperHelper.getMappingMetadataFromConfigFunction(destinationProperty, conversionValueOrFunction, sourceMapping);\r\n\r\n var property: IProperty;\r\n if (!sourceMapping) {\r\n property = this.getPropertyByDestinationProperty(mapping.properties, destinationProperty);\r\n }\r\n\r\n if (!property) {\r\n property = this.getOrCreateProperty({\r\n propertyNameParts: metadata.source.split('.'),\r\n mapping: mapping,\r\n propertyArray: mapping.properties,\r\n parent: null,\r\n destination: destinationProperty,\r\n sourceMapping: sourceMapping\r\n });\r\n }\r\n\r\n if (this.createMapForMemberHandleIgnore(property, metadata)) {\r\n return fluentFunctions;\r\n }\r\n\r\n if (metadata.async) {\r\n this._asyncMapper.createMapForMember(property, <(opts: IDMCO, cb: IMemberCallback) => void>conversionValueOrFunction, metadata);\r\n return fluentFunctions;\r\n }\r\n\r\n this.createMapForMemberHandleMapFrom(property, metadata);\r\n property.conditionFunction = metadata.condition;\r\n property.conversionValuesAndFunctions.push(conversionValueOrFunction);\r\n\r\n return fluentFunctions;\r\n }\r\n\r\n private createMapForMemberHandleMapFrom(property: IProperty, metadata: IMemberMappingMetaData): void {\r\n if (metadata.source === metadata.destination) {\r\n return;\r\n }\r\n\r\n var { mapping, root } = property.metadata;\r\n\r\n var sourceNameParts = metadata.source.split('.');\r\n if (sourceNameParts.length === property.level) {\r\n this.updatePropertyName(sourceNameParts, property);\r\n return;\r\n }\r\n\r\n // check if only one destination on property root. in that case, rebase property and overwrite root.\r\n if (root.metadata.destinationCount !== 1) {\r\n throw new Error('Rebasing properties with multiple destinations is not yet implemented.');\r\n }\r\n\r\n var propertyRootIndex = mapping.properties.indexOf(root);\r\n mapping.properties[propertyRootIndex] = undefined;\r\n var propArray: IProperty[] = [];\r\n var newProperty = this.getOrCreateProperty({\r\n propertyNameParts: metadata.source.split('.'),\r\n mapping: mapping,\r\n propertyArray: propArray,\r\n destination: metadata.destination,\r\n sourceMapping: metadata.sourceMapping\r\n });\r\n\r\n newProperty.conditionFunction = property.conditionFunction;\r\n newProperty.conversionValuesAndFunctions = property.conversionValuesAndFunctions;\r\n mapping.properties[propertyRootIndex] = propArray[0];\r\n }\r\n\r\n private updatePropertyName(sourceNameParts: string[], property: IProperty): void {\r\n property.name = sourceNameParts[sourceNameParts.length - 1];\r\n\r\n if (sourceNameParts.length === 1) {\r\n return;\r\n }\r\n\r\n this.updatePropertyName(sourceNameParts.splice(0, 1), property.metadata.parent);\r\n }\r\n\r\n private createMapForMemberHandleIgnore(property: IProperty, metadata: IMemberMappingMetaData): boolean {\r\n if (property.ignore || metadata.ignore) {\r\n // source name will always be destination name when ignoring.\r\n property.name = metadata.destination;\r\n property.ignore = true;\r\n property.async = false;\r\n property.destinations = null;\r\n property.conversionValuesAndFunctions = [];\r\n return true;\r\n }\r\n return false;\r\n }\r\n\r\n private getPropertyByDestinationProperty(properties: IProperty[], destinationPropertyName: string): IProperty {\r\n if (properties === null || properties === undefined) {\r\n return null;\r\n }\r\n\r\n for (let srcProp of properties) {\r\n if (srcProp.metadata.destinations !== null && srcProp.metadata.destinations !== undefined) {\r\n for (let destination in srcProp.metadata.destinations) {\r\n if (destination === destinationPropertyName) {\r\n return srcProp.metadata.destinations[destination].source;\r\n }\r\n }\r\n }\r\n\r\n let childProp = this.getPropertyByDestinationProperty(srcProp.children, destinationPropertyName);\r\n if (childProp != null) {\r\n return childProp;\r\n }\r\n }\r\n\r\n return null;\r\n }\r\n\r\n private getOrCreateProperty(parameters: IGetOrCreatePropertyParameters): IProperty {\r\n var { propertyNameParts, mapping, parent, propertyArray, destination, sourceMapping } = parameters;\r\n\r\n var name = propertyNameParts[0];\r\n\r\n var property = this.getPropertyFromArray(name, propertyArray);\r\n if (!property) {\r\n property = this.createProperty({\r\n name: name,\r\n parent: parent,\r\n propertyArray: propertyArray,\r\n sourceMapping: sourceMapping,\r\n mapping: mapping\r\n });\r\n }\r\n\r\n if (propertyNameParts.length === 1) {\r\n this.addPropertyDestination(property, destination, mapping, sourceMapping);\r\n return property;\r\n }\r\n\r\n if (!property.children) {\r\n property.children = [];\r\n }\r\n\r\n // nested call\r\n return this.getOrCreateProperty({\r\n propertyNameParts: propertyNameParts.slice(1),\r\n mapping: mapping,\r\n propertyArray: property.children,\r\n parent: property,\r\n destination: destination,\r\n sourceMapping: sourceMapping\r\n });\r\n }\r\n\r\n private getPropertyFromArray(name: string, properties: IProperty[]): IProperty {\r\n if (properties) {\r\n for (var child of properties) {\r\n if (child.name === name) {\r\n return child;\r\n }\r\n }\r\n }\r\n\r\n return null;\r\n }\r\n\r\n private addPropertyDestination(property: IProperty, destination: string, mapping: IMapping, sourceMapping: boolean): void {\r\n if (!destination) {\r\n return;\r\n }\r\n\r\n let destinationTargetArray: IProperty[] = property.destinations ? property.destinations : [];\r\n var dstProp = this.getOrCreateProperty({\r\n propertyNameParts: destination.split('.'),\r\n mapping: mapping,\r\n propertyArray: destinationTargetArray,\r\n sourceMapping: sourceMapping\r\n });\r\n\r\n if (destinationTargetArray.length > 0) {\r\n property.metadata.root.metadata.destinations[destination] = { source: property, destination: dstProp };\r\n property.metadata.root.metadata.destinationCount++;\r\n property.destinations = destinationTargetArray;\r\n }\r\n }\r\n\r\n private createProperty(parameters: ICreatePropertyParameters): IProperty {\r\n var { name, parent, propertyArray, sourceMapping, mapping } = parameters;\r\n\r\n var property: IProperty = {\r\n name: name,\r\n metadata: {\r\n mapping: mapping,\r\n root: parent ? parent.metadata.root : null,\r\n parent: parent,\r\n destinations: {},\r\n destinationCount: 0\r\n },\r\n sourceMapping: sourceMapping,\r\n level: !parent ? 1 : parent.level + 1,\r\n ignore: false,\r\n async: false,\r\n conversionValuesAndFunctions: []\r\n };\r\n\r\n if (property.metadata.root === null) {\r\n property.metadata.root = property;\r\n }\r\n\r\n if (propertyArray) {\r\n propertyArray.push(property);\r\n }\r\n\r\n return property;\r\n }\r\n\r\n private createMapForSourceMember(mapping: IMapping, fluentFunc: IFluentFunc, srcProp: string, cnf: ((opts: ISMCO) => any) | ((opts: ISMCO, cb: IMC) => void)): IFluentFunc {\r\n if (typeof cnf !== 'function') {\r\n throw new Error('Configuration of forSourceMember has to be a function with one (sync) or two (async) options parameters.');\r\n }\r\n\r\n return this.createMapForMember({\r\n mapping: mapping,\r\n fluentFunctions: fluentFunc,\r\n destinationProperty: srcProp,\r\n conversionValueOrFunction: cnf,\r\n sourceMapping: true\r\n });\r\n }\r\n\r\n private createMapForAllMembers(mapping: IMapping, fluentFunc: IFluentFunc, func: (dstObj: any, dstProp: string, val: any) => void): IFluentFunc {\r\n mapping.forAllMemberMappings.push(func);\r\n return fluentFunc;\r\n }\r\n\r\n private createMapIgnoreAllNonExisting(mapping: IMapping, fluentFunc: IFluentFunc): IFluentFunc {\r\n mapping.ignoreAllNonExisting = true;\r\n return fluentFunc;\r\n }\r\n\r\n private createMapConvertToType(mapping: IMapping, fluentFunc: IFluentFunc, typeClass: new () => any): IFluentFunc {\r\n if (mapping.destinationTypeClass) {\r\n throw new Error('Destination type class can only be set once.');\r\n }\r\n\r\n mapping.destinationTypeClass = typeClass;\r\n return fluentFunc;\r\n }\r\n\r\n private createMapConvertUsing(mapping: IMapping, tcClassOrFunc: convertUsingClassOrInstanceOrFunction): void {\r\n try {\r\n // check if sync: TypeConverter instance\r\n if (tcClassOrFunc instanceof TypeConverter) {\r\n this.configureSynchronousConverterFunction(mapping, tcClassOrFunc.convert);\r\n return;\r\n }\r\n\r\n var functionParameters = AutoMapperHelper.getFunctionParameters(tcClassOrFunc);\r\n switch (functionParameters.length) {\r\n case 0:\r\n // check if sync: TypeConverter class definition\r\n var typeConverter: TypeConverter;\r\n try {\r\n typeConverter = (new ( TypeConverter>tcClassOrFunc)());\r\n } catch (e) {\r\n // Obviously, typeConverterClassOrFunction is not a TypeConverter class definition\r\n }\r\n if (typeConverter instanceof TypeConverter) {\r\n this.configureSynchronousConverterFunction(mapping, typeConverter.convert);\r\n return;\r\n }\r\n break;\r\n case 1:\r\n // sync: function with resolutionContext parameter\r\n this.configureSynchronousConverterFunction(mapping, <(resolutionContext: IResolutionContext) => any>tcClassOrFunc);\r\n return;\r\n case 2:\r\n // check if async: function with resolutionContext and callback parameters\r\n this._asyncMapper.createMapConvertUsing(mapping, <(ctx: IResolutionContext, cb: IMapCallback) => void>tcClassOrFunc);\r\n return;\r\n }\r\n\r\n // okay, just try feeding the function to the configure function anyway...\r\n this.configureSynchronousConverterFunction(mapping, tcClassOrFunc);\r\n } catch (e) {\r\n throw new Error(`The value provided for typeConverterClassOrFunction is invalid. ${e}`);\r\n }\r\n\r\n throw new Error(`The value provided for typeConverterClassOrFunction is invalid.`);\r\n }\r\n\r\n private configureSynchronousConverterFunction(mapping: IMapping, converterFunc: Function): void {\r\n if (!converterFunc || AutoMapperHelper.getFunctionParameters(converterFunc).length !== 1) {\r\n throw new Error('The function provided does not provide exactly one (resolutionContext) parameter.');\r\n }\r\n\r\n mapping.typeConverterFunction = <(resolutionContext: IResolutionContext) => any>converterFunc;\r\n mapping.mapItemFunction = (m: IMapping, srcObj: any, dstObj: any): any => this.mapItemUsingTypeConverter(m, srcObj, dstObj);\r\n }\r\n\r\n\r\n private createMapWithProfile(mapping: IMapping, profileName: string): void {\r\n // check if given profile exists\r\n var profile = this._profiles[profileName];\r\n if (typeof profile === 'undefined' || profile.profileName !== profileName) {\r\n throw new Error(`Could not find profile with profile name '${profileName}'.`);\r\n }\r\n\r\n mapping.profile = profile;\r\n // merge mappings\r\n this.createMapWithProfileMergeMappings(mapping, profileName);\r\n }\r\n\r\n private createMapWithProfileMergeMappings(mapping: IMapping, profileName: string): void {\r\n var profileMappingKey = `${profileName}=>${mapping.sourceKey}${profileName}=>${mapping.destinationKey}`;\r\n var profileMapping: IMapping = this._mappings[profileMappingKey];\r\n if (!profileMapping) {\r\n return;\r\n }\r\n\r\n // append forAllMemberMappings calls to the original array.\r\n if (profileMapping.forAllMemberMappings.length > 0) {\r\n mapping.forAllMemberMappings.push(...profileMapping.forAllMemberMappings);\r\n }\r\n\r\n // overwrite original type converter function\r\n if (profileMapping.typeConverterFunction) {\r\n mapping.typeConverterFunction = profileMapping.typeConverterFunction;\r\n }\r\n\r\n // overwrite original type converter function\r\n if (profileMapping.destinationTypeClass) {\r\n mapping.destinationTypeClass = profileMapping.destinationTypeClass;\r\n }\r\n\r\n // walk through all the profile's property mappings\r\n for (let property of profileMapping.properties) {\r\n this.mergeProperty(mapping, mapping.properties, property);\r\n }\r\n }\r\n\r\n private mergeProperty(mapping: IMapping, properties: IProperty[], property: IProperty): void {\r\n var overwritten = false;\r\n for (let index = 0; index < mapping.properties.length; index++) {\r\n let existing = mapping.properties[index];\r\n\r\n if (existing.name === property.name) {\r\n // in which case, we overwrite that one with the profile's property mapping.\r\n // okay, maybe a bit rude, but real merging is pretty complex and you should\r\n // probably not want to combine normal and profile createMap.forMember calls.\r\n mapping.properties[index] = property;\r\n overwritten = true;\r\n }\r\n }\r\n\r\n if (overwritten === false) {\r\n mapping.properties.push(property);\r\n }\r\n }\r\n\r\n private mapInternal(mapping: IMapping, sourceObject: any): any {\r\n if (mapping.async) {\r\n throw new Error('Impossible to use asynchronous mapping using automapper.map(); use automapper.mapAsync() instead.');\r\n }\r\n\r\n if (super.isArray(sourceObject)) {\r\n return this.mapArray(mapping, sourceObject);\r\n }\r\n\r\n return (mapping.mapItemFunction)(mapping, sourceObject, super.createDestinationObject(mapping.destinationTypeClass));\r\n }\r\n\r\n private mapArray(mapping: IMapping, sourceArray: Array): Array {\r\n var destinationArray = super.handleArray(mapping, sourceArray, (sourceObject: any, destinationObject: any) => {\r\n (mapping.mapItemFunction)(mapping, sourceObject, destinationObject);\r\n });\r\n return destinationArray;\r\n }\r\n\r\n private mapItem(mapping: IMapping, sourceObject: any, destinationObject: any): void {\r\n destinationObject = super.handleItem(mapping, sourceObject, destinationObject, (propertyName: string) => {\r\n this.mapProperty(mapping, sourceObject, destinationObject, propertyName);\r\n });\r\n return destinationObject;\r\n }\r\n\r\n private mapItemUsingTypeConverter(mapping: IMapping, sourceObject: any, destinationObject: any, arrayIndex?: number): void {\r\n var resolutionContext: IResolutionContext = {\r\n sourceValue: sourceObject,\r\n destinationValue: destinationObject\r\n };\r\n return (<(ctx: IResolutionContext) => any>mapping.typeConverterFunction)(resolutionContext);\r\n }\r\n\r\n private mapProperty(mapping: IMapping, sourceObject: any, destinationObject: any, sourceProperty: string): void {\r\n super.handleProperty(mapping, sourceObject, sourceProperty, destinationObject,\r\n (destinations: IProperty[], valuesAndFunctions: Array, opts: IDMCO) => {\r\n var destinationPropertyValue = this.handlePropertyMappings(valuesAndFunctions, opts);\r\n for (let destination of destinations) {\r\n super.setPropertyValue(mapping, destinationObject, destination, destinationPropertyValue);\r\n }\r\n });\r\n }\r\n\r\n private handlePropertyMappings(valuesAndFunctions: Array, opts: IMemberConfigurationOptions): any {\r\n if (!valuesAndFunctions || valuesAndFunctions.length === 0) {\r\n return opts.intermediatePropertyValue;\r\n }\r\n\r\n var valueOrFunction = valuesAndFunctions[0];\r\n if (typeof valueOrFunction === 'function') {\r\n var result = valueOrFunction(opts);\r\n\r\n if (typeof result !== 'undefined') {\r\n opts.intermediatePropertyValue = result;\r\n }\r\n\r\n // recursively walk values/functions\r\n return this.handlePropertyMappings(valuesAndFunctions.slice(1), opts);\r\n } else {\r\n // valueOrFunction is a value\r\n opts.intermediatePropertyValue = valueOrFunction;\r\n\r\n // recursively walk values/functions\r\n return this.handlePropertyMappings(valuesAndFunctions.slice(1), opts);\r\n }\r\n }\r\n\r\n private createMappingObjectForGivenKeys(srcKeyOrType: string | (new() => any), dstKeyOrType: string | (new() => any)): IMapping {\r\n var mapping: IMapping = {\r\n sourceKey: super.getKey(srcKeyOrType),\r\n destinationKey: super.getKey(dstKeyOrType),\r\n forAllMemberMappings: new Array<(destinationObject: any, destinationPropertyName: string, value: any) => void>(),\r\n properties: [],\r\n typeConverterFunction: undefined,\r\n mapItemFunction: (m: IMapping, srcObj: any, dstObj: any): any => this.mapItem(m, srcObj, dstObj),\r\n sourceTypeClass: (typeof srcKeyOrType === 'string' ? undefined : srcKeyOrType),\r\n destinationTypeClass: (typeof dstKeyOrType === 'string' ? undefined : dstKeyOrType),\r\n profile: undefined,\r\n async: false\r\n };\r\n this._mappings[mapping.sourceKey + mapping.destinationKey] = mapping;\r\n return mapping;\r\n }\r\n\r\n private createMapGetFluentApiFunctions(mapping: IMapping): IFluentFunc {\r\n // create a fluent interface / method chaining (e.g. automapper.createMap().forMember().forMember() ...)\r\n var fluentFunc: IFluentFunc = {\r\n forMember: (prop: string, valFunc: forMemberValueOrFunction) : IFluentFunc =>\r\n this.createMapForMember({\r\n mapping: mapping,\r\n fluentFunctions: fluentFunc,\r\n destinationProperty: prop,\r\n conversionValueOrFunction: valFunc,\r\n sourceMapping: false\r\n }),\r\n forSourceMember: (prop: string, cfgFunc: ((opts: ISMCO) => any) | ((opts: ISMCO, cb: IMC) => void)) : IFluentFunc =>\r\n this.createMapForSourceMember(mapping, fluentFunc, prop, cfgFunc),\r\n forAllMembers: (func: (dstObj: any, dstProp: string, value: any) => void) : IFluentFunc =>\r\n this.createMapForAllMembers(mapping, fluentFunc, func),\r\n ignoreAllNonExisting: () : IFluentFunc => this.createMapIgnoreAllNonExisting(mapping, fluentFunc),\r\n convertToType: (type: new () => any) : IFluentFunc => this.createMapConvertToType(mapping, fluentFunc, type),\r\n convertUsing: (tcClassOrFunc: convertUsingClassOrInstanceOrFunction) : void =>\r\n this.createMapConvertUsing(mapping, tcClassOrFunc),\r\n withProfile: (profile: string) : void => this.createMapWithProfile(mapping, profile)\r\n };\r\n\r\n return fluentFunc;\r\n }\r\n }\r\n}\r\n\r\n// Add AutoMapper to the application's global scope. Of course, you could still use Core.AutoMapper.getInstance() as well.\r\nvar automapper: AutoMapperJs.AutoMapper = ((app: any) => {\r\n app.automapper = AutoMapperJs.AutoMapper.getInstance();\r\n return app.automapper;\r\n})(this);\r\n"],"sourceRoot":"/source/"} \ No newline at end of file +{"version":3,"sources":["AutoMapper.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAC9D,0CAA0C;AAC1C,2CAA2C;AAC3C,yCAAyC;AACzC,4CAA4C;AAC5C,+CAA+C;;;;;;AAE/C,IAAO,YAAY,CAimBlB;AAjmBD,WAAO,YAAY,EAAC,CAAC;IACjB,YAAY,CAAC;IAeb;QAAgC,8BAAc;QAY1C;;;WAGG;QACH;YACI,iBAAO,CAAC;YAER,EAAE,CAAC,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC;gBACvB,MAAM,CAAC,UAAU,CAAC,SAAS,CAAC;YAChC,CAAC;YAAC,IAAI,CAAC,CAAC;gBACJ,UAAU,CAAC,SAAS,GAAG,IAAI,CAAC;gBAE5B,IAAI,CAAC,SAAS,GAAG,EAAE,CAAC;gBACpB,IAAI,CAAC,SAAS,GAAG,EAAE,CAAC;gBAEpB,IAAI,CAAC,YAAY,GAAG,IAAI,4BAAe,EAAE,CAAC;YAC9C,CAAC;QACL,CAAC;QArBa,sBAAW,GAAzB;YACI,MAAM,CAAC,UAAU,CAAC,SAAS,CAAC;QAChC,CAAC;QAqBD;;;WAGG;QACI,+BAAU,GAAjB,UAAkB,cAAgD;YAC9D,IAAI,IAAI,GAAG,IAAI,CAAC;YAEhB,IAAI,aAAa,GAAwB;gBACrC,UAAU,EAAE,UAAC,OAAiB;oBAC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C,OAAO,EAAE,UAAU,EAAE,IAAI,CAAC,EAAtD,CAAsD;gBAC3G,YAAY,EAAE,UAAC,aAAoD;oBAC/D,OAAA,KAAI,CAAC,qBAAqB,CAAC,OAAO,EAAE,aAAa,CAAC;gBAAlD,CAAkD;gBACtD,WAAW,EAAE,UAAC,OAAe,IAAW,OAAA,KAAI,CAAC,oBAAoB,CAAC,OAAO,EAAE,OAAO,CAAC,EAA3C,CAA2C;aACtF,CAAC;YAEF,MAAM,CAAC,UAAU,CAAC;QACtB,CAAC;QA9kBc,oBAAS,GAAG,IAAI,UAAU,EAAE,CAAC;QA+kBhD,iBAAC;IAAD,CAhlBA,AAglBC,CAhlB+B,2BAAc,GAglB7C;IAhlBY,uBAAU,aAglBtB,CAAA;AACL,CAAC,EAjmBM,YAAY,KAAZ,YAAY,QAimBlB;AAED,0HAA0H;AAC1H,IAAI,UAAU,GAA4B,CAAC,UAAC,GAAQ;IAChD,GAAG,CAAC,UAAU,GAAG,YAAY,CAAC,UAAU,CAAC,WAAW,EAAE,CAAC;IACvD,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC;AAC1B,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC","file":"AutoMapper.js","sourcesContent":["/// \r\n/// \r\n/// \r\n/// \r\n/// \r\n/// \r\n\r\nmodule AutoMapperJs {\r\n 'use strict';\r\n\r\n // interface shorthands\r\n type IFluentFunc = ICreateMapFluentFunctions;\r\n type IDMCO = IMemberConfigurationOptions;\r\n type ISMCO = ISourceMemberConfigurationOptions;\r\n type IMC = IMemberCallback;\r\n type IRC = IResolutionContext;\r\n type TC = TypeConverter;\r\n\r\n // method overload shorthands\r\n type stringOrClass = string | (new() => any);\r\n type forMemberValueOrFunction = any | ((opts: IDMCO) => any) | ((opts: IDMCO, cb: IMC) => void);\r\n type convertUsingClassOrInstanceOrFunction = ((ctx: IRC) => any) | ((ctx: IRC, callback: IMapCallback) => void) | TC | (new() => TC);\r\n\r\n export class AutoMapper extends AutoMapperBase {\r\n private static _instance = new AutoMapper();\r\n\r\n private _profiles: { [name: string]: IProfile };\r\n private _mappings: { [key: string]: IMapping };\r\n\r\n private _asyncMapper: AsyncAutoMapper;\r\n\r\n public static getInstance(): AutoMapper {\r\n return AutoMapper._instance;\r\n }\r\n\r\n /**\r\n * This class is intended to be a Singleton. Preferrably use getInstance()\r\n * function instead of using the constructor directly from code.\r\n */\r\n constructor() {\r\n super();\r\n\r\n if (AutoMapper._instance) {\r\n return AutoMapper._instance;\r\n } else {\r\n AutoMapper._instance = this;\r\n\r\n this._profiles = {};\r\n this._mappings = {};\r\n\r\n this._asyncMapper = new AsyncAutoMapper();\r\n }\r\n }\r\n\r\n /**\r\n * Initializes the mapper with the supplied configuration.\r\n * @param {(config: IConfiguration) => void} configFunction Configuration function to call.\r\n */\r\n public initialize(configFunction: (config: IConfiguration) => void): void {\r\n var that = this;\r\n\r\n var configuration: IConfiguration = {\r\n addProfile: (profile: IProfile): void => {\r\n profile.configure();\r\n that._profiles[profile.profileName] = profile;\r\n },\r\n createMap: function (sourceKey: string, destinationKey: string): IFluentFunc {\r\n // pass through using arguments to keep createMap's currying support fully functional.\r\n return that.createMap.apply(that, arguments);\r\n }\r\n };\r\n\r\n configFunction(configuration);\r\n }\r\n\r\n /**\r\n * Create a mapping profile.\r\n * @param {string} sourceKey The map source key.\r\n * @param {string} destinationKey The map destination key.\r\n * @returns {Core.ICreateMapFluentFunctions}\r\n */\r\n public createMap(sourceKeyOrType: string | (new() => any), destinationKeyOrType: string | (new() => any)): IFluentFunc {\r\n // provide currying support.\r\n if (arguments.length < 2) {\r\n return AutoMapperHelper.handleCurrying(this.createMap, arguments, this);\r\n }\r\n\r\n var mapping = this.createMappingObjectForGivenKeys(sourceKeyOrType, destinationKeyOrType);\r\n\r\n return this.createMapGetFluentApiFunctions(mapping);\r\n }\r\n\r\n /**\r\n * Execute a mapping from the source object to a new destination object with explicit mapping configuration and supplied mapping options (using createMap).\r\n * @param sourceKey Source key, for instance the source type name.\r\n * @param destinationKey Destination key, for instance the destination type name.\r\n * @param sourceObject The source object to map.\r\n * @returns {any} Destination object.\r\n */\r\n public map(sourceKeyOrType: stringOrClass, destinationKeyOrType: stringOrClass, sourceObject: any): any {\r\n if (arguments.length === 3) {\r\n return this.mapInternal(super.getMapping(this._mappings, sourceKeyOrType, destinationKeyOrType), sourceObject);\r\n }\r\n\r\n // provide performance optimized (preloading) currying support.\r\n if (arguments.length === 2) {\r\n return (srcObj: any) => this.mapInternal(super.getMapping(this._mappings, sourceKeyOrType, destinationKeyOrType), srcObj);\r\n }\r\n\r\n if (arguments.length === 1) {\r\n return (dstKey: string | (new() => any), srcObj: any) => this.map(sourceKeyOrType, dstKey, srcObj);\r\n }\r\n\r\n return (srcKey: string | (new() => any), dstKey: string | (new() => any), srcObj: any) => this.map(srcKey, dstKey, srcObj);\r\n }\r\n\r\n /**\r\n * Execute an asynchronous mapping from the source object to a new destination object with explicit mapping configuration and supplied mapping options (using createMap).\r\n * @param sourceKey Source key, for instance the source type name.\r\n * @param destinationKey Destination key, for instance the destination type name.\r\n * @param sourceObject The source object to map.\r\n * @param {IMapCallback} callback The callback to call when asynchronous mapping is complete.\r\n */\r\n public mapAsync(sourceKeyOrType: string | (new() => any), destinationKeyOrType: string | (new() => any), sourceObject: any, callback: IMapCallback): any {\r\n switch (arguments.length) {\r\n case 4:\r\n return this._asyncMapper.map(this._mappings, sourceKeyOrType, destinationKeyOrType, sourceObject, callback);\r\n case 3:\r\n return this._asyncMapper.map(this._mappings, sourceKeyOrType, destinationKeyOrType, sourceObject);\r\n case 2:\r\n return this._asyncMapper.map(this._mappings, sourceKeyOrType, destinationKeyOrType);\r\n case 1:\r\n return this._asyncMapper.map(this._mappings, sourceKeyOrType);\r\n default:\r\n throw new Error('The mapAsync function expects between 1 and 4 parameters, you provided ' + arguments.length + '.');\r\n }\r\n }\r\n\r\n /**\r\n * Validates mapping configuration by dry-running. Since JS does not fully support typing, it only checks if properties match on both\r\n * sides. The function needs IMapping.sourceTypeClass and IMapping.destinationTypeClass to function.\r\n * @param {boolean} strictMode Whether or not to fail when properties sourceTypeClass or destinationTypeClass are unavailable.\r\n */\r\n public assertConfigurationIsValid(strictMode: boolean = true): void {\r\n AutoMapperValidator.assertConfigurationIsValid(this._mappings, strictMode);\r\n }\r\n\r\n private createMapForMember(parameters: ICreateMapParameters): IFluentFunc {\r\n var {mapping, destinationProperty, conversionValueOrFunction, sourceMapping, fluentFunctions} = parameters;\r\n\r\n var metadata = AutoMapperHelper.getMappingMetadataFromConfigFunction(destinationProperty, conversionValueOrFunction, sourceMapping);\r\n\r\n var property: IProperty;\r\n if (!sourceMapping) {\r\n property = this.getPropertyByDestinationProperty(mapping.properties, destinationProperty);\r\n }\r\n\r\n if (!property) {\r\n property = this.getOrCreateProperty({\r\n propertyNameParts: metadata.source.split('.'),\r\n mapping: mapping,\r\n propertyArray: mapping.properties,\r\n parent: null,\r\n destination: destinationProperty,\r\n sourceMapping: sourceMapping\r\n });\r\n }\r\n\r\n if (this.createMapForMemberHandleIgnore(property, metadata)) {\r\n return fluentFunctions;\r\n }\r\n\r\n if (metadata.async) {\r\n this._asyncMapper.createMapForMember(property, <(opts: IDMCO, cb: IMemberCallback) => void>conversionValueOrFunction, metadata);\r\n return fluentFunctions;\r\n }\r\n\r\n this.createMapForMemberHandleMapFrom(property, metadata);\r\n property.conditionFunction = metadata.condition;\r\n property.conversionValuesAndFunctions.push(conversionValueOrFunction);\r\n\r\n return fluentFunctions;\r\n }\r\n\r\n private createMapForMemberHandleMapFrom(property: IProperty, metadata: IMemberMappingMetaData): void {\r\n if (metadata.source === metadata.destination) {\r\n return;\r\n }\r\n\r\n var {mapping, root} = property.metadata;\r\n\r\n var sourceNameParts = metadata.source.split('.');\r\n if (sourceNameParts.length === property.level) {\r\n this.updatePropertyName(sourceNameParts, property);\r\n return;\r\n }\r\n\r\n // check if only one destination on property root. in that case, rebase property and overwrite root.\r\n if (root.metadata.destinationCount !== 1) {\r\n throw new Error('Rebasing properties with multiple destinations is not yet implemented.');\r\n }\r\n\r\n var propertyRootIndex = mapping.properties.indexOf(root);\r\n mapping.properties[propertyRootIndex] = undefined;\r\n var propArray: IProperty[] = [];\r\n var newProperty = this.getOrCreateProperty({\r\n propertyNameParts: metadata.source.split('.'),\r\n mapping: mapping,\r\n propertyArray: propArray,\r\n destination: metadata.destination,\r\n sourceMapping: metadata.sourceMapping\r\n });\r\n\r\n newProperty.conditionFunction = property.conditionFunction;\r\n newProperty.conversionValuesAndFunctions = property.conversionValuesAndFunctions;\r\n mapping.properties[propertyRootIndex] = propArray[0];\r\n }\r\n\r\n private updatePropertyName(sourceNameParts: string[], property: IProperty): void {\r\n property.name = sourceNameParts[sourceNameParts.length - 1];\r\n\r\n if (sourceNameParts.length === 1) {\r\n return;\r\n }\r\n\r\n this.updatePropertyName(sourceNameParts.splice(0, 1), property.metadata.parent);\r\n }\r\n\r\n private createMapForMemberHandleIgnore(property: IProperty, metadata: IMemberMappingMetaData): boolean {\r\n if (property.ignore || metadata.ignore) {\r\n // source name will always be destination name when ignoring.\r\n property.name = metadata.destination;\r\n property.ignore = true;\r\n property.async = false;\r\n property.destinations = null;\r\n property.conversionValuesAndFunctions = [];\r\n return true;\r\n }\r\n return false;\r\n }\r\n\r\n private getPropertyByDestinationProperty(properties: IProperty[], destinationPropertyName: string): IProperty {\r\n if (properties === null || properties === undefined) {\r\n return null;\r\n }\r\n\r\n for (let srcProp of properties) {\r\n if (srcProp.metadata.destinations !== null && srcProp.metadata.destinations !== undefined) {\r\n for (let destination in srcProp.metadata.destinations) {\r\n if (destination === destinationPropertyName) {\r\n return srcProp.metadata.destinations[destination].source;\r\n }\r\n }\r\n }\r\n\r\n let childProp = this.getPropertyByDestinationProperty(srcProp.children, destinationPropertyName);\r\n if (childProp != null) {\r\n return childProp;\r\n }\r\n }\r\n\r\n return null;\r\n }\r\n\r\n private getOrCreateProperty(parameters: IGetOrCreatePropertyParameters): IProperty {\r\n var {propertyNameParts, mapping, parent, propertyArray, destination, sourceMapping} = parameters;\r\n\r\n var name = propertyNameParts[0];\r\n\r\n var property = this.getPropertyFromArray(name, propertyArray);\r\n if (!property) {\r\n property = this.createProperty({\r\n name: name,\r\n parent: parent,\r\n propertyArray: propertyArray,\r\n sourceMapping: sourceMapping,\r\n mapping: mapping\r\n });\r\n }\r\n\r\n if (propertyNameParts.length === 1) {\r\n this.addPropertyDestination(property, destination, mapping, sourceMapping);\r\n return property;\r\n }\r\n\r\n if (!property.children) {\r\n property.children = [];\r\n }\r\n\r\n // nested call\r\n return this.getOrCreateProperty({\r\n propertyNameParts: propertyNameParts.slice(1),\r\n mapping: mapping,\r\n propertyArray: property.children,\r\n parent: property,\r\n destination: destination,\r\n sourceMapping: sourceMapping\r\n });\r\n }\r\n\r\n private getPropertyFromArray(name: string, properties: IProperty[]): IProperty {\r\n if (properties) {\r\n for (var child of properties) {\r\n if (child.name === name) {\r\n return child;\r\n }\r\n }\r\n }\r\n\r\n return null;\r\n }\r\n\r\n private addPropertyDestination(property: IProperty, destination: string, mapping: IMapping, sourceMapping: boolean): void {\r\n if (!destination) {\r\n return;\r\n }\r\n\r\n let destinationTargetArray: IProperty[] = property.destinations ? property.destinations : [];\r\n var dstProp = this.getOrCreateProperty({\r\n propertyNameParts: destination.split('.'),\r\n mapping: mapping,\r\n propertyArray: destinationTargetArray,\r\n sourceMapping: sourceMapping\r\n });\r\n\r\n if (destinationTargetArray.length > 0) {\r\n property.metadata.root.metadata.destinations[destination] = {source: property, destination: dstProp};\r\n property.metadata.root.metadata.destinationCount++;\r\n property.destinations = destinationTargetArray;\r\n }\r\n }\r\n\r\n private createProperty(parameters: ICreatePropertyParameters): IProperty {\r\n var {name, parent, propertyArray, sourceMapping, mapping} = parameters;\r\n\r\n var property: IProperty = {\r\n name: name,\r\n metadata: {\r\n mapping: mapping,\r\n root: parent ? parent.metadata.root : null,\r\n parent: parent,\r\n destinations: {},\r\n destinationCount: 0\r\n },\r\n sourceMapping: sourceMapping,\r\n level: !parent ? 1 : parent.level + 1,\r\n ignore: false,\r\n async: false,\r\n conversionValuesAndFunctions: []\r\n };\r\n\r\n if (property.metadata.root === null) {\r\n property.metadata.root = property;\r\n }\r\n\r\n if (propertyArray) {\r\n propertyArray.push(property);\r\n }\r\n\r\n return property;\r\n }\r\n\r\n private createMapForSourceMember(mapping: IMapping, fluentFunc: IFluentFunc, srcProp: string, cnf: ((opts: ISMCO) => any) | ((opts: ISMCO, cb: IMC) => void)): IFluentFunc {\r\n if (typeof cnf !== 'function') {\r\n throw new Error('Configuration of forSourceMember has to be a function with one (sync) or two (async) options parameters.');\r\n }\r\n\r\n return this.createMapForMember({\r\n mapping: mapping,\r\n fluentFunctions: fluentFunc,\r\n destinationProperty: srcProp,\r\n conversionValueOrFunction: cnf,\r\n sourceMapping: true\r\n });\r\n }\r\n\r\n private createMapForAllMembers(mapping: IMapping, fluentFunc: IFluentFunc, func: (dstObj: any, dstProp: string, val: any) => void): IFluentFunc {\r\n mapping.forAllMemberMappings.push(func);\r\n return fluentFunc;\r\n }\r\n\r\n private createMapIgnoreAllNonExisting(mapping: IMapping, fluentFunc: IFluentFunc): IFluentFunc {\r\n mapping.ignoreAllNonExisting = true;\r\n return fluentFunc;\r\n }\r\n\r\n private createMapConvertToType(mapping: IMapping, fluentFunc: IFluentFunc, typeClass: new () => any): IFluentFunc {\r\n if (mapping.destinationTypeClass) {\r\n throw new Error('Destination type class can only be set once.');\r\n }\r\n\r\n mapping.destinationTypeClass = typeClass;\r\n return fluentFunc;\r\n }\r\n\r\n private createMapConvertUsing(mapping: IMapping, tcClassOrFunc: convertUsingClassOrInstanceOrFunction): void {\r\n try {\r\n // check if sync: TypeConverter instance\r\n if (tcClassOrFunc instanceof TypeConverter) {\r\n this.configureSynchronousConverterFunction(mapping, tcClassOrFunc.convert);\r\n return;\r\n }\r\n\r\n var functionParameters = AutoMapperHelper.getFunctionParameters(tcClassOrFunc);\r\n switch (functionParameters.length) {\r\n case 0:\r\n // check if sync: TypeConverter class definition\r\n var typeConverter: TypeConverter;\r\n try {\r\n typeConverter = (new ( TypeConverter>tcClassOrFunc)());\r\n } catch (e) {\r\n // Obviously, typeConverterClassOrFunction is not a TypeConverter class definition\r\n }\r\n if (typeConverter instanceof TypeConverter) {\r\n this.configureSynchronousConverterFunction(mapping, typeConverter.convert);\r\n return;\r\n }\r\n break;\r\n case 1:\r\n // sync: function with resolutionContext parameter\r\n this.configureSynchronousConverterFunction(mapping, <(resolutionContext: IResolutionContext) => any>tcClassOrFunc);\r\n return;\r\n case 2:\r\n // check if async: function with resolutionContext and callback parameters\r\n this._asyncMapper.createMapConvertUsing(mapping, <(ctx: IResolutionContext, cb: IMapCallback) => void>tcClassOrFunc);\r\n return;\r\n }\r\n\r\n // okay, just try feeding the function to the configure function anyway...\r\n this.configureSynchronousConverterFunction(mapping, tcClassOrFunc);\r\n } catch (e) {\r\n throw new Error(`The value provided for typeConverterClassOrFunction is invalid. ${e}`);\r\n }\r\n\r\n throw new Error(`The value provided for typeConverterClassOrFunction is invalid.`);\r\n }\r\n\r\n private configureSynchronousConverterFunction(mapping: IMapping, converterFunc: Function): void {\r\n if (!converterFunc || AutoMapperHelper.getFunctionParameters(converterFunc).length !== 1) {\r\n throw new Error('The function provided does not provide exactly one (resolutionContext) parameter.');\r\n }\r\n\r\n mapping.typeConverterFunction = <(resolutionContext: IResolutionContext) => any>converterFunc;\r\n mapping.mapItemFunction = (m: IMapping, srcObj: any, dstObj: any): any => this.mapItemUsingTypeConverter(m, srcObj, dstObj);\r\n }\r\n\r\n\r\n private createMapWithProfile(mapping: IMapping, profileName: string): void {\r\n // check if given profile exists\r\n var profile = this._profiles[profileName];\r\n if (typeof profile === 'undefined' || profile.profileName !== profileName) {\r\n throw new Error(`Could not find profile with profile name '${profileName}'.`);\r\n }\r\n\r\n mapping.profile = profile;\r\n // merge mappings\r\n this.createMapWithProfileMergeMappings(mapping, profileName);\r\n }\r\n\r\n private createMapWithProfileMergeMappings(mapping: IMapping, profileName: string): void {\r\n var profileMappingKey = `${profileName}=>${mapping.sourceKey}${profileName}=>${mapping.destinationKey}`;\r\n var profileMapping: IMapping = this._mappings[profileMappingKey];\r\n if (!profileMapping) {\r\n return;\r\n }\r\n\r\n // append forAllMemberMappings calls to the original array.\r\n if (profileMapping.forAllMemberMappings.length > 0) {\r\n mapping.forAllMemberMappings.push(...profileMapping.forAllMemberMappings);\r\n }\r\n\r\n // overwrite original type converter function\r\n if (profileMapping.typeConverterFunction) {\r\n mapping.typeConverterFunction = profileMapping.typeConverterFunction;\r\n }\r\n\r\n // overwrite original type converter function\r\n if (profileMapping.destinationTypeClass) {\r\n mapping.destinationTypeClass = profileMapping.destinationTypeClass;\r\n }\r\n\r\n // walk through all the profile's property mappings\r\n for (let property of profileMapping.properties) {\r\n this.mergeProperty(mapping, mapping.properties, property);\r\n }\r\n }\r\n\r\n private mergeProperty(mapping: IMapping, properties: IProperty[], property: IProperty): void {\r\n var overwritten = false;\r\n for (let index = 0; index < mapping.properties.length; index++) {\r\n let existing = mapping.properties[index];\r\n\r\n if (existing.name === property.name) {\r\n // in which case, we overwrite that one with the profile's property mapping.\r\n // okay, maybe a bit rude, but real merging is pretty complex and you should\r\n // probably not want to combine normal and profile createMap.forMember calls.\r\n mapping.properties[index] = property;\r\n overwritten = true;\r\n }\r\n }\r\n\r\n if (overwritten === false) {\r\n mapping.properties.push(property);\r\n }\r\n }\r\n\r\n private mapInternal(mapping: IMapping, sourceObject: any): any {\r\n if (mapping.async) {\r\n throw new Error('Impossible to use asynchronous mapping using automapper.map(); use automapper.mapAsync() instead.');\r\n }\r\n\r\n if (super.isArray(sourceObject)) {\r\n return this.mapArray(mapping, sourceObject);\r\n }\r\n\r\n return (mapping.mapItemFunction)(mapping, sourceObject, super.createDestinationObject(mapping.destinationTypeClass));\r\n }\r\n\r\n private mapArray(mapping: IMapping, sourceArray: Array): Array {\r\n var destinationArray = super.handleArray(mapping, sourceArray, (sourceObject: any, destinationObject: any) => {\r\n (mapping.mapItemFunction)(mapping, sourceObject, destinationObject);\r\n });\r\n return destinationArray;\r\n }\r\n\r\n private mapItem(mapping: IMapping, sourceObject: any, destinationObject: any): void {\r\n destinationObject = super.handleItem(mapping, sourceObject, destinationObject, (propertyName: string) => {\r\n this.mapProperty(mapping, sourceObject, destinationObject, propertyName);\r\n });\r\n return destinationObject;\r\n }\r\n\r\n private mapItemUsingTypeConverter(mapping: IMapping, sourceObject: any, destinationObject: any, arrayIndex?: number): void {\r\n var resolutionContext: IResolutionContext = {\r\n sourceValue: sourceObject,\r\n destinationValue: destinationObject\r\n };\r\n return (<(ctx: IResolutionContext) => any>mapping.typeConverterFunction)(resolutionContext);\r\n }\r\n\r\n private mapProperty(mapping: IMapping, sourceObject: any, destinationObject: any, sourceProperty: string): void {\r\n super.handleProperty(mapping, sourceObject, sourceProperty, destinationObject,\r\n (destinations: IProperty[], valuesAndFunctions: Array, opts: IDMCO) => {\r\n var destinationPropertyValue = this.handlePropertyMappings(valuesAndFunctions, opts);\r\n for (let destination of destinations) {\r\n super.setPropertyValue(mapping, destinationObject, destination, destinationPropertyValue);\r\n }\r\n });\r\n }\r\n\r\n private handlePropertyMappings(valuesAndFunctions: Array, opts: IMemberConfigurationOptions): any {\r\n if (!valuesAndFunctions || valuesAndFunctions.length === 0) {\r\n return opts.intermediatePropertyValue;\r\n }\r\n\r\n var valueOrFunction = valuesAndFunctions[0];\r\n if (typeof valueOrFunction === 'function') {\r\n var result = valueOrFunction(opts);\r\n\r\n if (typeof result !== 'undefined') {\r\n opts.intermediatePropertyValue = result;\r\n }\r\n\r\n // recursively walk values/functions\r\n return this.handlePropertyMappings(valuesAndFunctions.slice(1), opts);\r\n } else {\r\n // valueOrFunction is a value\r\n opts.intermediatePropertyValue = valueOrFunction;\r\n\r\n // recursively walk values/functions\r\n return this.handlePropertyMappings(valuesAndFunctions.slice(1), opts);\r\n }\r\n }\r\n\r\n private createMappingObjectForGivenKeys(srcKeyOrType: string | (new() => any), dstKeyOrType: string | (new() => any)): IMapping {\r\n var mapping: IMapping = {\r\n sourceKey: super.getKey(srcKeyOrType),\r\n destinationKey: super.getKey(dstKeyOrType),\r\n forAllMemberMappings: new Array<(destinationObject: any, destinationPropertyName: string, value: any) => void>(),\r\n properties: [],\r\n typeConverterFunction: undefined,\r\n mapItemFunction: (m: IMapping, srcObj: any, dstObj: any): any => this.mapItem(m, srcObj, dstObj),\r\n sourceTypeClass: (typeof srcKeyOrType === 'string' ? undefined : srcKeyOrType),\r\n destinationTypeClass: (typeof dstKeyOrType === 'string' ? undefined : dstKeyOrType),\r\n profile: undefined,\r\n async: false\r\n };\r\n this._mappings[mapping.sourceKey + mapping.destinationKey] = mapping;\r\n return mapping;\r\n }\r\n\r\n private createMapGetFluentApiFunctions(mapping: IMapping): IFluentFunc {\r\n // create a fluent interface / method chaining (e.g. automapper.createMap().forMember().forMember() ...)\r\n var fluentFunc: IFluentFunc = {\r\n forMember: (prop: string, valFunc: forMemberValueOrFunction): IFluentFunc =>\r\n this.createMapForMember({\r\n mapping: mapping,\r\n fluentFunctions: fluentFunc,\r\n destinationProperty: prop,\r\n conversionValueOrFunction: valFunc,\r\n sourceMapping: false\r\n }),\r\n forSourceMember: (prop: string, cfgFunc: ((opts: ISMCO) => any) | ((opts: ISMCO, cb: IMC) => void)): IFluentFunc =>\r\n this.createMapForSourceMember(mapping, fluentFunc, prop, cfgFunc),\r\n forAllMembers: (func: (dstObj: any, dstProp: string, value: any) => void): IFluentFunc =>\r\n this.createMapForAllMembers(mapping, fluentFunc, func),\r\n ignoreAllNonExisting: (): IFluentFunc => this.createMapIgnoreAllNonExisting(mapping, fluentFunc),\r\n convertToType: (type: new () => any): IFluentFunc => this.createMapConvertToType(mapping, fluentFunc, type),\r\n convertUsing: (tcClassOrFunc: convertUsingClassOrInstanceOrFunction): void =>\r\n this.createMapConvertUsing(mapping, tcClassOrFunc),\r\n withProfile: (profile: string): void => this.createMapWithProfile(mapping, profile)\r\n };\r\n\r\n return fluentFunc;\r\n }\r\n }\r\n}\r\n\r\n// Add AutoMapper to the application's global scope. Of course, you could still use Core.AutoMapper.getInstance() as well.\r\nvar automapper: AutoMapperJs.AutoMapper = ((app: any) => {\r\n app.automapper = AutoMapperJs.AutoMapper.getInstance();\r\n return app.automapper;\r\n})(this);\r\n"]} \ No newline at end of file diff --git a/src/js/AutoMapperBase.js b/src/js/AutoMapperBase.js index 44a6bfc..64a9edf 100644 --- a/src/js/AutoMapperBase.js +++ b/src/js/AutoMapperBase.js @@ -175,14 +175,34 @@ var AutoMapperJs; if (mapping.ignoreAllNonExisting) { return; } + if (mapping.destinationTypeClass && Object.keys(destinationObject).indexOf(sourcePropertyName) < 0) { + return; + } + var objectValue = null; + var isNestedObject = false; + if (typeof destinationObject[sourcePropertyName] === 'object' && destinationObject[sourcePropertyName]) { + isNestedObject = (destinationObject[sourcePropertyName].constructor.name !== 'Object'); + if (isNestedObject) { + this + .createMap(sourceObject[sourcePropertyName].constructor.name, destinationObject[sourcePropertyName].constructor.name) + .convertToType(destinationObject[sourcePropertyName].constructor); + objectValue = this.map(sourceObject[sourcePropertyName].constructor.name, destinationObject[sourcePropertyName].constructor.name, sourceObject[sourcePropertyName]); + } + } // use profile mapping when specified; otherwise, specify source property name as destination property name. var destinationPropertyName = this.getDestinationPropertyName(mapping.profile, sourcePropertyName); - var destinationPropertyValue = sourceObject ? sourceObject[sourcePropertyName] : null; + var destinationPropertyValue = this.getDestinationPropertyValue(sourceObject, sourcePropertyName, objectValue, isNestedObject); this.setPropertyValueByName(mapping, destinationObject, destinationPropertyName, destinationPropertyValue); if (autoMappingCallbackFunction) { autoMappingCallbackFunction(destinationPropertyValue); } }; + AutoMapperBase.prototype.getDestinationPropertyValue = function (sourceObject, sourcePropertyName, objectValue, isNestedObject) { + if (isNestedObject) { + return objectValue; + } + return sourceObject ? sourceObject[sourcePropertyName] : null; + }; AutoMapperBase.prototype.handlePropertyWithPropertyMapping = function (mapping, propertyMapping, sourceObject, sourcePropertyName, loopMemberValuesAndFunctions) { // a forMember mapping exists var ignore = propertyMapping.ignore, conditionFunction = propertyMapping.conditionFunction, children = propertyMapping.children, destinations = propertyMapping.destinations, conversionValuesAndFunctions = propertyMapping.conversionValuesAndFunctions; diff --git a/src/js/AutoMapperBase.js.map b/src/js/AutoMapperBase.js.map index 6e65b81..4bcd302 100644 --- a/src/js/AutoMapperBase.js.map +++ b/src/js/AutoMapperBase.js.map @@ -1 +1 @@ -{"version":3,"sources":["AutoMapperBase.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAC9D,yCAAyC;AACzC,4CAA4C;AAC5C,+CAA+C;AAE/C,IAAO,YAAY,CA4SlB;AA5SD,WAAO,YAAY,EAAC,CAAC;IACjB,YAAY,CAAC;IAMb;;;OAGG;IACH;QAAA;QAgSA,CAAC;QA/Ra,mCAAU,GAApB,UAAqB,QAAqC,EAAE,SAAwB,EAAE,cAA6B;YAC/G,IAAI,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;YACpC,IAAI,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;YACzC,IAAI,OAAO,GAAa,QAAQ,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC;YAElD,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;gBACX,MAAM,IAAI,KAAK,CAAC,gDAA8C,MAAM,8BAAyB,MAAQ,CAAC,CAAC;YAC3G,CAAC;YACD,MAAM,CAAC,OAAO,CAAC;QACnB,CAAC;QAES,+BAAM,GAAhB,UAAiB,eAAyC;YACtD,EAAE,CAAC,CAAC,OAAO,eAAe,KAAK,QAAQ,CAAC,CAAC,CAAC;gBACtC,MAAM,CAAC,eAAe,CAAC;YAC3B,CAAC;YAAC,IAAI,CAAC,CAAC;gBACJ,MAAM,CAAC,6BAAgB,CAAC,YAAY,CAAC,eAAe,CAAC,CAAC;YAC1D,CAAC;QACL,CAAC;QAES,gCAAO,GAAjB,UAAkB,YAAiB;YAC/B,MAAM,CAAC,YAAY,YAA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AK,CAAC,OAAO,CAAC,4BAA4B,CAAC,mBAAmB,CAAC,CAAC;gBAEjH,2GAA2G;gBAC3G,GAAG,CAAC,CAAC,IAAI,KAAK,GAAG,uBAAuB,CAAC,MAAM,GAAG,CAAC,EAAE,KAAK,IAAI,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC;oBACvE,EAAE,CAAC,CAAC,uBAAuB,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;wBACxC,uBAAuB,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;oBAC7C,CAAC;gBACL,CAAC;gBAED,MAAM,CAAC,OAAO,CAAC,iCAAiC,CAAC,qBAAqB,CAAC,uBAAuB,CAAC,CAAC;YACpG,CAAE;YAAA,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;gBACb,MAAM,CAAC,kBAAkB,CAAC;YAC9B,CAAC;QACL,CAAC;QACL,qBAAC;IAAD,CAhSA,AAgSC,IAAA;IAhSY,2BAAc,iBAgS1B,CAAA;AACL,CAAC,EA5SM,YAAY,KAAZ,YAAY,QA4SlB","file":"AutoMapperBase.js","sourcesContent":["/// \r\n/// \r\n/// \r\n/// \r\n\r\nmodule AutoMapperJs {\r\n 'use strict';\r\n\r\n type IFluentFunc = ICreateMapFluentFunctions;\r\n\r\n type stringOrClass = string | (new() => any);\r\n\r\n /**\r\n * AutoMapper implementation, for both creating maps and performing maps. Comparable usage and functionality to the original\r\n * .NET AutoMapper library is the pursuit of this implementation.\r\n */\r\n export class AutoMapperBase {\r\n protected getMapping(mappings: { [key: string]: IMapping }, sourceKey: stringOrClass, destinationKey: stringOrClass): IMapping {\r\n let srcKey = this.getKey(sourceKey);\r\n let dstKey = this.getKey(destinationKey);\r\n let mapping: IMapping = mappings[srcKey + dstKey];\r\n\r\n if (!mapping) {\r\n throw new Error(`Could not find map object with a source of ${srcKey} and a destination of ${dstKey}`);\r\n }\r\n return mapping;\r\n }\r\n\r\n protected getKey(keyStringOrType: string | (new () => any)): string {\r\n if (typeof keyStringOrType === 'string') {\r\n return keyStringOrType;\r\n } else {\r\n return AutoMapperHelper.getClassName(keyStringOrType);\r\n }\r\n }\r\n\r\n protected isArray(sourceObject: any): boolean {\r\n return sourceObject instanceof Array;\r\n }\r\n\r\n protected handleArray(mapping: IMapping, sourceArray: Array, itemFunc: (sourceObject: any, destinationObject: any) => void): Array {\r\n var arrayLength = sourceArray.length;\r\n var destinationArray = new Array(sourceArray.length);\r\n\r\n for (let index = 0; index < arrayLength; index++) {\r\n let sourceObject = sourceArray[index];\r\n let destinationObject: any;\r\n\r\n if (sourceObject === null || sourceObject === undefined) {\r\n destinationObject = sourceObject;\r\n } else {\r\n destinationObject = this.createDestinationObject(mapping.destinationTypeClass);\r\n itemFunc(sourceObject, destinationObject);\r\n }\r\n\r\n destinationArray[index] = destinationObject;\r\n }\r\n\r\n return destinationArray;\r\n }\r\n\r\n protected handleItem(mapping: IMapping, sourceObject: any, destinationObject: any, propertyFunction: (propertyName: string) => void): any {\r\n var sourceProperties: string[] = [];\r\n var atLeastOnePropertyMapped = false;\r\n\r\n for (let sourcePropertyName in sourceObject) {\r\n if (!sourceObject.hasOwnProperty(sourcePropertyName)) {\r\n continue;\r\n }\r\n\r\n atLeastOnePropertyMapped = true;\r\n sourceProperties.push(sourcePropertyName);\r\n propertyFunction(sourcePropertyName);\r\n }\r\n\r\n // unsourced properties\r\n for (let property of mapping.properties) {\r\n if (sourceProperties.indexOf(property.name) >= 0) {\r\n continue;\r\n }\r\n\r\n atLeastOnePropertyMapped = true;\r\n propertyFunction(property.name);\r\n }\r\n\r\n // return null/undefined sourceObject if no properties added\r\n if (!atLeastOnePropertyMapped && sourceObject === null || sourceObject === undefined) {\r\n return sourceObject;\r\n }\r\n\r\n return destinationObject;\r\n }\r\n\r\n protected handleProperty(mapping: IMapping,\r\n sourceObject: any,\r\n sourcePropertyName: string,\r\n destinationObject: any,\r\n loopMemberValuesAndFunctions: (\r\n destinations: IProperty[],\r\n conversionValuesAndFunctions: Array,\r\n opts: IMemberConfigurationOptions\r\n ) => void,\r\n autoMappingCallbackFunction?: (dstPropVal: any) => void): void {\r\n var propertyMapping: IProperty = this.getMappingProperty(mapping.properties, sourcePropertyName);\r\n if (propertyMapping) {\r\n this.handlePropertyWithPropertyMapping(mapping, propertyMapping, sourceObject, sourcePropertyName, loopMemberValuesAndFunctions);\r\n } else {\r\n this.handlePropertyWithAutoMapping(mapping, sourceObject, sourcePropertyName, destinationObject, autoMappingCallbackFunction);\r\n }\r\n }\r\n\r\n protected setPropertyValue(mapping: IMapping, destinationObject: any, destinationProperty: IProperty, destinationPropertyValue: any): void {\r\n if (mapping.forAllMemberMappings.length > 0) {\r\n for (let forAllMemberMapping of mapping.forAllMemberMappings) {\r\n this.handleNestedForAllMemberMappings(destinationObject, destinationProperty, destinationPropertyValue, forAllMemberMapping);\r\n }\r\n } else {\r\n this.setNestedPropertyValue(destinationObject, destinationProperty, destinationPropertyValue);\r\n }\r\n }\r\n\r\n protected setPropertyValueByName(mapping: IMapping, destinationObject: any, destinationProperty: string, destinationPropertyValue: any): void {\r\n if (mapping.forAllMemberMappings.length > 0) {\r\n for (let forAllMemberMapping of mapping.forAllMemberMappings) {\r\n forAllMemberMapping(destinationObject, destinationProperty, destinationPropertyValue);\r\n }\r\n } else {\r\n destinationObject[destinationProperty] = destinationPropertyValue;\r\n }\r\n }\r\n protected createDestinationObject(destinationType: new () => any): any {\r\n // create empty destination object.\r\n return destinationType\r\n ? new destinationType()\r\n : {};\r\n }\r\n\r\n private handleNestedForAllMemberMappings(destinationObject: any,\r\n destinationProperty: IProperty,\r\n destinationPropertyValue: any,\r\n forAllMemberMapping: (destinationObject: any, destinationPropertyName: string, value: any) => void): void {\r\n if (destinationProperty.children && destinationProperty.children.length > 0) {\r\n this.setChildPropertyValues(destinationObject, destinationProperty, destinationPropertyValue);\r\n } else {\r\n forAllMemberMapping(destinationObject, destinationProperty.name, destinationPropertyValue);\r\n }\r\n }\r\n\r\n private setNestedPropertyValue(destinationObject: any, destinationProperty: IProperty, destinationPropertyValue: any): boolean {\r\n if (destinationProperty.children && destinationProperty.children.length > 0) {\r\n var isSuccess = this.setChildPropertyValues(destinationObject, destinationProperty, destinationPropertyValue);\r\n if (!isSuccess) {\r\n destinationObject[destinationProperty.name] = destinationPropertyValue;\r\n }\r\n return isSuccess;\r\n } else {\r\n destinationObject[destinationProperty.name] = destinationPropertyValue;\r\n return destinationPropertyValue !== undefined && destinationPropertyValue !== null;\r\n }\r\n }\r\n\r\n private setChildPropertyValues(destinationObject: any, destinationProperty: IProperty, destinationPropertyValue: any): boolean {\r\n var dstObj: any = {};\r\n var destinationAlreadyExists = destinationObject.hasOwnProperty(destinationProperty.name) && destinationObject[destinationProperty.name];\r\n\r\n var isSuccess: boolean;\r\n for (var index = 0, count = destinationProperty.children.length; index < count; index++) {\r\n var tmpObj: any = {};\r\n var child = destinationProperty.children[index];\r\n\r\n var isChildSucces = this.setNestedPropertyValue(tmpObj, child, destinationPropertyValue);\r\n if (isChildSucces) {\r\n dstObj[child.name] = tmpObj[child.name];\r\n }\r\n isSuccess = isSuccess || isChildSucces;\r\n }\r\n\r\n if (isSuccess) {\r\n if (destinationAlreadyExists) {\r\n for (let child in dstObj) {\r\n if (!dstObj.hasOwnProperty(child)) {\r\n continue;\r\n }\r\n\r\n destinationObject[destinationProperty.name][child] = dstObj[child];\r\n }\r\n } else {\r\n destinationObject[destinationProperty.name] = dstObj;\r\n }\r\n }\r\n\r\n return destinationAlreadyExists || isSuccess;\r\n }\r\n\r\n private getMappingProperty(properties: IProperty[], sourcePropertyName: string): IProperty {\r\n for (let property of properties) {\r\n if (property.name === sourcePropertyName) {\r\n return property;\r\n }\r\n }\r\n\r\n return null;\r\n }\r\n\r\n private handlePropertyWithAutoMapping(mapping: IMapping,\r\n sourceObject: any,\r\n sourcePropertyName: string,\r\n destinationObject: any,\r\n autoMappingCallbackFunction?: (dstPropVal: any) => void): void {\r\n // no forMember mapping exists, auto map properties, except for the situation where ignoreAllNonExisting is specified.\r\n if (mapping.ignoreAllNonExisting) {\r\n return;\r\n }\r\n\r\n // use profile mapping when specified; otherwise, specify source property name as destination property name.\r\n let destinationPropertyName = this.getDestinationPropertyName(mapping.profile, sourcePropertyName);\r\n var destinationPropertyValue = sourceObject ? sourceObject[sourcePropertyName] : null;\r\n this.setPropertyValueByName(mapping, destinationObject, destinationPropertyName, destinationPropertyValue);\r\n if (autoMappingCallbackFunction) {\r\n autoMappingCallbackFunction(destinationPropertyValue);\r\n }\r\n }\r\n\r\n private handlePropertyWithPropertyMapping(\r\n mapping: IMapping,\r\n propertyMapping: IProperty,\r\n sourceObject: any,\r\n sourcePropertyName: string,\r\n loopMemberValuesAndFunctions: (destinations: IProperty[], conversionValuesAndFunctions: Array, opts: IMemberConfigurationOptions) => void): void {\r\n // a forMember mapping exists\r\n\r\n var {\r\n ignore,\r\n conditionFunction,\r\n children,\r\n destinations,\r\n conversionValuesAndFunctions\r\n } = propertyMapping;\r\n\r\n if (children) {\r\n var childSourceObject = sourceObject[propertyMapping.name];\r\n for (let index = 0; index < children.length; index++) {\r\n let child = children[index];\r\n this.handlePropertyWithPropertyMapping(mapping, child, childSourceObject, child.name, loopMemberValuesAndFunctions);\r\n }\r\n }\r\n\r\n // ignore ignored properties\r\n if (ignore) {\r\n return;\r\n }\r\n\r\n // check for condition function\r\n if (conditionFunction) {\r\n // and, if there, return when the condition is not met.\r\n if (conditionFunction(sourceObject) === false) {\r\n return;\r\n }\r\n }\r\n\r\n // it makes no sense to handle a property without destination(s).\r\n if (!destinations) {\r\n return;\r\n }\r\n\r\n var memberConfigurationOptions: IMemberConfigurationOptions = {\r\n mapFrom: (): void => {//sourceMemberKey: string) {\r\n // no action required, just here as a stub to prevent calling a non-existing 'opts.mapFrom()' function.\r\n },\r\n condition: (predicate: ((sourceObject: any) => boolean)): void => {\r\n // no action required, just here as a stub to prevent calling a non-existing 'opts.mapFrom()' function.\r\n },\r\n sourceObject: sourceObject,\r\n sourcePropertyName: sourcePropertyName,\r\n intermediatePropertyValue: sourceObject ? sourceObject[sourcePropertyName] : sourceObject\r\n };\r\n\r\n loopMemberValuesAndFunctions(destinations, conversionValuesAndFunctions, memberConfigurationOptions);\r\n }\r\n\r\n private getDestinationPropertyName(profile: IProfile, sourcePropertyName: string): string {\r\n if (!profile) {\r\n return sourcePropertyName;\r\n }\r\n\r\n // TODO BL no support yet for INamingConvention.splittingCharacter\r\n\r\n try {\r\n // First, split the source property name based on the splitting expression.\r\n // TODO BL Caching of RegExp splitting!\r\n var sourcePropertyNameParts = sourcePropertyName.split(profile.sourceMemberNamingConvention.splittingExpression);\r\n\r\n // NOTE BL For some reason, splitting by (my ;)) RegExp results in empty strings in the array; remove them.\r\n for (let index = sourcePropertyNameParts.length - 1; index >= 0; index--) {\r\n if (sourcePropertyNameParts[index] === '') {\r\n sourcePropertyNameParts.splice(index, 1);\r\n }\r\n }\r\n\r\n return profile.destinationMemberNamingConvention.transformPropertyName(sourcePropertyNameParts);\r\n } catch (error) {\r\n return sourcePropertyName;\r\n }\r\n }\r\n }\r\n}"],"sourceRoot":"/source/"} \ No newline at end of file +{"version":3,"sources":["AutoMapperBase.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAC9D,yCAAyC;AACzC,4CAA4C;AAC5C,+CAA+C;AAE/C,IAAO,YAAY,CAoVlB;AApVD,WAAO,YAAY,EAAC,CAAC;IACjB,YAAY,CAAC;IAMb;;;OAGG;IACH;QAAA;QAwUA,CAAC;QAlUa,mCAAU,GAApB,UAAqB,QAAqC,EAAE,SAAwB,EAAE,cAA6B;YAC/G,IAAI,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;YACpC,IAAI,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;YACzC,IAAI,OAAO,GAAa,QAAQ,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC;YAElD,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAA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AutoMapperJs {\r\n 'use strict';\r\n\r\n type IFluentFunc = ICreateMapFluentFunctions;\r\n\r\n type stringOrClass = string | (new() => any);\r\n\r\n /**\r\n * AutoMapper implementation, for both creating maps and performing maps. Comparable usage and functionality to the original\r\n * .NET AutoMapper library is the pursuit of this implementation.\r\n */\r\n export abstract class AutoMapperBase {\r\n\r\n public abstract map(sourceKeyOrType: any, destinationKeyOrType: any, sourceObject: any): any\r\n\r\n public abstract createMap(sourceKeyOrType: string | (new() => any), destinationKeyOrType: string | (new() => any)): any;\r\n\r\n protected getMapping(mappings: { [key: string]: IMapping }, sourceKey: stringOrClass, destinationKey: stringOrClass): IMapping {\r\n let srcKey = this.getKey(sourceKey);\r\n let dstKey = this.getKey(destinationKey);\r\n let mapping: IMapping = mappings[srcKey + dstKey];\r\n\r\n if (!mapping) {\r\n throw new Error(`Could not find map object with a source of ${srcKey} and a destination of ${dstKey}`);\r\n }\r\n return mapping;\r\n }\r\n\r\n protected getKey(keyStringOrType: string | (new () => any)): string {\r\n if (typeof keyStringOrType === 'string') {\r\n return keyStringOrType;\r\n } else {\r\n return AutoMapperHelper.getClassName(keyStringOrType);\r\n }\r\n }\r\n\r\n protected isArray(sourceObject: any): boolean {\r\n return sourceObject instanceof Array;\r\n }\r\n\r\n protected handleArray(mapping: IMapping, sourceArray: Array, itemFunc: (sourceObject: any, destinationObject: any) => void): Array {\r\n var arrayLength = sourceArray.length;\r\n var destinationArray = new Array(sourceArray.length);\r\n\r\n for (let index = 0; index < arrayLength; index++) {\r\n let sourceObject = sourceArray[index];\r\n let destinationObject: any;\r\n\r\n if (sourceObject === null || sourceObject === undefined) {\r\n destinationObject = sourceObject;\r\n } else {\r\n destinationObject = this.createDestinationObject(mapping.destinationTypeClass);\r\n itemFunc(sourceObject, destinationObject);\r\n }\r\n\r\n destinationArray[index] = destinationObject;\r\n }\r\n\r\n return destinationArray;\r\n }\r\n\r\n protected handleItem(mapping: IMapping, sourceObject: any, destinationObject: any, propertyFunction: (propertyName: string) => void): any {\r\n var sourceProperties: string[] = [];\r\n var atLeastOnePropertyMapped = false;\r\n\r\n for (let sourcePropertyName in sourceObject) {\r\n if (!sourceObject.hasOwnProperty(sourcePropertyName)) {\r\n continue;\r\n }\r\n\r\n atLeastOnePropertyMapped = true;\r\n sourceProperties.push(sourcePropertyName);\r\n propertyFunction(sourcePropertyName);\r\n }\r\n\r\n // unsourced properties\r\n for (let property of mapping.properties) {\r\n if (sourceProperties.indexOf(property.name) >= 0) {\r\n continue;\r\n }\r\n\r\n atLeastOnePropertyMapped = true;\r\n propertyFunction(property.name);\r\n }\r\n\r\n // return null/undefined sourceObject if no properties added\r\n if (!atLeastOnePropertyMapped && sourceObject === null || sourceObject === undefined) {\r\n return sourceObject;\r\n }\r\n\r\n return destinationObject;\r\n }\r\n\r\n protected handleProperty(mapping: IMapping,\r\n sourceObject: any,\r\n sourcePropertyName: string,\r\n destinationObject: any,\r\n loopMemberValuesAndFunctions: (destinations: IProperty[],\r\n conversionValuesAndFunctions: Array,\r\n opts: IMemberConfigurationOptions) => void,\r\n autoMappingCallbackFunction?: (dstPropVal: any) => void): void {\r\n var propertyMapping: IProperty = this.getMappingProperty(mapping.properties, sourcePropertyName);\r\n if (propertyMapping) {\r\n this.handlePropertyWithPropertyMapping(mapping, propertyMapping, sourceObject, sourcePropertyName, loopMemberValuesAndFunctions);\r\n } else {\r\n this.handlePropertyWithAutoMapping(mapping, sourceObject, sourcePropertyName, destinationObject, autoMappingCallbackFunction);\r\n }\r\n }\r\n\r\n protected setPropertyValue(mapping: IMapping, destinationObject: any, destinationProperty: IProperty, destinationPropertyValue: any): void {\r\n if (mapping.forAllMemberMappings.length > 0) {\r\n for (let forAllMemberMapping of mapping.forAllMemberMappings) {\r\n this.handleNestedForAllMemberMappings(destinationObject, destinationProperty, destinationPropertyValue, forAllMemberMapping);\r\n }\r\n } else {\r\n this.setNestedPropertyValue(destinationObject, destinationProperty, destinationPropertyValue);\r\n }\r\n }\r\n\r\n protected setPropertyValueByName(mapping: IMapping, destinationObject: any, destinationProperty: string, destinationPropertyValue: any): void {\r\n if (mapping.forAllMemberMappings.length > 0) {\r\n for (let forAllMemberMapping of mapping.forAllMemberMappings) {\r\n forAllMemberMapping(destinationObject, destinationProperty, destinationPropertyValue);\r\n }\r\n } else {\r\n destinationObject[destinationProperty] = destinationPropertyValue;\r\n }\r\n }\r\n\r\n protected createDestinationObject(destinationType: new () => any): any {\r\n // create empty destination object.\r\n return destinationType\r\n ? new destinationType()\r\n : {};\r\n }\r\n\r\n private handleNestedForAllMemberMappings(destinationObject: any,\r\n destinationProperty: IProperty,\r\n destinationPropertyValue: any,\r\n forAllMemberMapping: (destinationObject: any, destinationPropertyName: string, value: any) => void): void {\r\n if (destinationProperty.children && destinationProperty.children.length > 0) {\r\n this.setChildPropertyValues(destinationObject, destinationProperty, destinationPropertyValue);\r\n } else {\r\n forAllMemberMapping(destinationObject, destinationProperty.name, destinationPropertyValue);\r\n }\r\n }\r\n\r\n private setNestedPropertyValue(destinationObject: any, destinationProperty: IProperty, destinationPropertyValue: any): boolean {\r\n if (destinationProperty.children && destinationProperty.children.length > 0) {\r\n var isSuccess = this.setChildPropertyValues(destinationObject, destinationProperty, destinationPropertyValue);\r\n if (!isSuccess) {\r\n destinationObject[destinationProperty.name] = destinationPropertyValue;\r\n }\r\n return isSuccess;\r\n } else {\r\n destinationObject[destinationProperty.name] = destinationPropertyValue;\r\n return destinationPropertyValue !== undefined && destinationPropertyValue !== null;\r\n }\r\n }\r\n\r\n private setChildPropertyValues(destinationObject: any, destinationProperty: IProperty, destinationPropertyValue: any): boolean {\r\n var dstObj: any = {};\r\n var destinationAlreadyExists = destinationObject.hasOwnProperty(destinationProperty.name) && destinationObject[destinationProperty.name];\r\n\r\n var isSuccess: boolean;\r\n for (var index = 0, count = destinationProperty.children.length; index < count; index++) {\r\n var tmpObj: any = {};\r\n var child = destinationProperty.children[index];\r\n\r\n var isChildSucces = this.setNestedPropertyValue(tmpObj, child, destinationPropertyValue);\r\n if (isChildSucces) {\r\n dstObj[child.name] = tmpObj[child.name];\r\n }\r\n isSuccess = isSuccess || isChildSucces;\r\n }\r\n\r\n if (isSuccess) {\r\n if (destinationAlreadyExists) {\r\n for (let child in dstObj) {\r\n if (!dstObj.hasOwnProperty(child)) {\r\n continue;\r\n }\r\n\r\n destinationObject[destinationProperty.name][child] = dstObj[child];\r\n }\r\n } else {\r\n destinationObject[destinationProperty.name] = dstObj;\r\n }\r\n }\r\n\r\n return destinationAlreadyExists || isSuccess;\r\n }\r\n\r\n private getMappingProperty(properties: IProperty[], sourcePropertyName: string): IProperty {\r\n for (let property of properties) {\r\n if (property.name === sourcePropertyName) {\r\n return property;\r\n }\r\n }\r\n\r\n return null;\r\n }\r\n\r\n private handlePropertyWithAutoMapping(mapping: IMapping,\r\n sourceObject: any,\r\n sourcePropertyName: string,\r\n destinationObject: any,\r\n autoMappingCallbackFunction?: (dstPropVal: any) => void): void {\r\n // no forMember mapping exists, auto map properties, except for the situation where ignoreAllNonExisting is specified.\r\n if (mapping.ignoreAllNonExisting) {\r\n return;\r\n }\r\n\r\n if (mapping.destinationTypeClass && Object.keys(destinationObject).indexOf(sourcePropertyName) < 0) {\r\n return;\r\n }\r\n\r\n let objectValue: any = null;\r\n let isNestedObject = false;\r\n\r\n if (typeof destinationObject[sourcePropertyName] === 'object' && destinationObject[sourcePropertyName]) {\r\n isNestedObject = (destinationObject[sourcePropertyName].constructor.name !== 'Object');\r\n\r\n if (isNestedObject) {\r\n this\r\n .createMap(sourceObject[sourcePropertyName].constructor.name, destinationObject[sourcePropertyName].constructor.name)\r\n .convertToType(destinationObject[sourcePropertyName].constructor);\r\n\r\n objectValue = this.map(\r\n sourceObject[sourcePropertyName].constructor.name,\r\n destinationObject[sourcePropertyName].constructor.name,\r\n sourceObject[sourcePropertyName]\r\n );\r\n }\r\n }\r\n\r\n // use profile mapping when specified; otherwise, specify source property name as destination property name.\r\n let destinationPropertyName = this.getDestinationPropertyName(mapping.profile, sourcePropertyName);\r\n var destinationPropertyValue = this.getDestinationPropertyValue(sourceObject, sourcePropertyName, objectValue, isNestedObject);\r\n this.setPropertyValueByName(mapping, destinationObject, destinationPropertyName, destinationPropertyValue);\r\n if (autoMappingCallbackFunction) {\r\n autoMappingCallbackFunction(destinationPropertyValue);\r\n }\r\n }\r\n\r\n private getDestinationPropertyValue(sourceObject: any,\r\n sourcePropertyName: string,\r\n objectValue: any,\r\n isNestedObject: boolean): any {\r\n if (isNestedObject) {\r\n return objectValue;\r\n }\r\n\r\n return sourceObject ? sourceObject[sourcePropertyName] : null;\r\n\r\n }\r\n\r\n private handlePropertyWithPropertyMapping(mapping: IMapping,\r\n propertyMapping: IProperty,\r\n sourceObject: any,\r\n sourcePropertyName: string,\r\n loopMemberValuesAndFunctions: (destinations: IProperty[],\r\n conversionValuesAndFunctions: Array,\r\n opts: IMemberConfigurationOptions) => void): void {\r\n // a forMember mapping exists\r\n\r\n var {\r\n ignore,\r\n conditionFunction,\r\n children,\r\n destinations,\r\n conversionValuesAndFunctions\r\n } = propertyMapping;\r\n\r\n if (children) {\r\n var childSourceObject = sourceObject[propertyMapping.name];\r\n for (let index = 0; index < children.length; index++) {\r\n let child = children[index];\r\n this.handlePropertyWithPropertyMapping(mapping, child, childSourceObject, child.name, loopMemberValuesAndFunctions);\r\n }\r\n }\r\n\r\n // ignore ignored properties\r\n if (ignore) {\r\n return;\r\n }\r\n\r\n // check for condition function\r\n if (conditionFunction) {\r\n // and, if there, return when the condition is not met.\r\n if (conditionFunction(sourceObject) === false) {\r\n return;\r\n }\r\n }\r\n\r\n // it makes no sense to handle a property without destination(s).\r\n if (!destinations) {\r\n return;\r\n }\r\n\r\n var memberConfigurationOptions: IMemberConfigurationOptions = {\r\n mapFrom: (): void => {//sourceMemberKey: string) {\r\n // no action required, just here as a stub to prevent calling a non-existing 'opts.mapFrom()' function.\r\n },\r\n condition: (predicate: ((sourceObject: any) => boolean)): void => {\r\n // no action required, just here as a stub to prevent calling a non-existing 'opts.mapFrom()' function.\r\n },\r\n sourceObject: sourceObject,\r\n sourcePropertyName: sourcePropertyName,\r\n intermediatePropertyValue: sourceObject ? sourceObject[sourcePropertyName] : sourceObject\r\n };\r\n\r\n loopMemberValuesAndFunctions(destinations, conversionValuesAndFunctions, memberConfigurationOptions);\r\n }\r\n\r\n private getDestinationPropertyName(profile: IProfile, sourcePropertyName: string): string {\r\n if (!profile) {\r\n return sourcePropertyName;\r\n }\r\n\r\n // TODO BL no support yet for INamingConvention.splittingCharacter\r\n\r\n try {\r\n // First, split the source property name based on the splitting expression.\r\n // TODO BL Caching of RegExp splitting!\r\n var sourcePropertyNameParts = sourcePropertyName.split(profile.sourceMemberNamingConvention.splittingExpression);\r\n\r\n // NOTE BL For some reason, splitting by (my ;)) RegExp results in empty strings in the array; remove them.\r\n for (let index = sourcePropertyNameParts.length - 1; index >= 0; index--) {\r\n if (sourcePropertyNameParts[index] === '') {\r\n sourcePropertyNameParts.splice(index, 1);\r\n }\r\n }\r\n\r\n return profile.destinationMemberNamingConvention.transformPropertyName(sourcePropertyNameParts);\r\n } catch (error) {\r\n return sourcePropertyName;\r\n }\r\n }\r\n }\r\n}\r\n"]} \ No newline at end of file diff --git a/src/js/AutoMapperHelper.js.map b/src/js/AutoMapperHelper.js.map index 5b99f05..e7c785b 100644 --- a/src/js/AutoMapperHelper.js.map +++ b/src/js/AutoMapperHelper.js.map @@ -1 +1 @@ -{"version":3,"sources":["AutoMapperHelper.ts"],"names":[],"mappings":"AAAA,IAAO,YAAY,CAuNlB;AAvND,WAAO,YAAY,EAAC,CAAC;IACjB,YAAY,CAAC;IAEb;;OAEG;IACH;QAAA;QAgNH,CAAC;QA/MoB,6BAAY,GAA1B,UAA2B,SAAuB;YAC9C,EAAE,CAAC,CAAC,SAAS,IAAU,SAAU,CAAC,IAAI,CAAC,CAAC,CAAC;gBACrC,MAAM,CAAO,SAAU,CAAC,IAAI,CAAC;YACjC,CAAC;YACD,qDAAqD;YACrD,EAAE,CAAC,CAA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r\n */\r\n export class AutoMapperHelper {\r\n public static getClassName(classType: new() => any): string {\r\n if (classType && (classType).name) {\r\n return (classType).name;\r\n }\r\n // source: http://stackoverflow.com/a/13914278/702357\r\n if (classType && classType.constructor) {\r\n let className = classType.toString();\r\n if (className) {\r\n // classType.toString() is \"function classType (...) { ... }\"\r\n let matchParts = className.match(/function\\s*(\\w+)/);\r\n if (matchParts && matchParts.length === 2) {\r\n return matchParts[1];\r\n }\r\n }\r\n\r\n // for browsers which have name property in the constructor\r\n // of the object, such as chrome\r\n if ((classType.constructor).name) {\r\n return (classType.constructor).name;\r\n }\r\n\r\n if (classType.constructor.toString()) {\r\n var str = classType.constructor.toString();\r\n\r\n if (str.charAt(0) === '[') {\r\n // executed if the return of object.constructor.toString() is \"[object objectClass]\"\r\n var arr = str.match(/\\[\\w+\\s*(\\w+)\\]/);\r\n } else {\r\n // executed if the return of object.constructor.toString() is \"function objectClass () {}\"\r\n // (IE and Firefox)\r\n var arr = str.match(/function\\s*(\\w+)/);\r\n }\r\n\r\n if (arr && arr.length === 2) {\r\n return arr[1];\r\n }\r\n }\r\n }\r\n\r\n throw new Error(`Unable to extract class name from type '${classType}'`);\r\n }\r\n\r\n public static getFunctionParameters(func: Function): Array {\r\n const stripComments = /((\\/\\/.*$)|(\\/\\*[\\s\\S]*?\\*\\/))/mg;\r\n const argumentNames = /([^\\s,]+)/g;\r\n\r\n var functionString = func.toString().replace(stripComments, '');\r\n var functionParameterNames = functionString.slice(functionString.indexOf('(') + 1, functionString.indexOf(')')).match(argumentNames);\r\n if (functionParameterNames === null) {\r\n functionParameterNames = new Array();\r\n }\r\n return functionParameterNames;\r\n }\r\n\r\n public static handleCurrying(func: Function, args: IArguments, closure: any): any {\r\n const argumentsStillToCome = func.length - args.length;\r\n\r\n // saved accumulator array\r\n // NOTE BL this does not deep copy array objects, only the array itself; should side effects occur, please report (or refactor).\r\n var argumentsCopy = Array.prototype.slice.apply(args);\r\n\r\n function accumulator(moreArgs: IArguments, alreadyProvidedArgs: Array, stillToCome: number): Function {\r\n var previousAlreadyProvidedArgs = alreadyProvidedArgs.slice(0); // to reset\r\n var previousStillToCome = stillToCome; // to reset\r\n\r\n for (let i = 0; i < moreArgs.length; i++, stillToCome--) {\r\n alreadyProvidedArgs[alreadyProvidedArgs.length] = moreArgs[i];\r\n }\r\n\r\n if (stillToCome - moreArgs.length <= 0) {\r\n var functionCallResult = func.apply(closure, alreadyProvidedArgs);\r\n\r\n // reset vars, so curried function can be applied to new params.\r\n alreadyProvidedArgs = previousAlreadyProvidedArgs;\r\n stillToCome = previousStillToCome;\r\n\r\n return functionCallResult;\r\n } else {\r\n return function(): Function {\r\n // arguments are params, so closure bussiness is avoided.\r\n return accumulator(arguments, alreadyProvidedArgs.slice(0), stillToCome);\r\n };\r\n }\r\n }\r\n\r\n return accumulator(([]), argumentsCopy, argumentsStillToCome);\r\n }\r\n\r\n public static getMappingMetadataFromConfigFunction(destination: string, func: any, sourceMapping: boolean): IMemberMappingMetaData {\r\n if (typeof func !== 'function') {\r\n return {\r\n destination: destination,\r\n source: destination,\r\n sourceMapping: sourceMapping,\r\n condition: null,\r\n ignore: false,\r\n async: false\r\n };\r\n }\r\n\r\n var funcStr = func.toString();\r\n\r\n var parameterNames = AutoMapperHelper.getFunctionParameters(func);\r\n var optsParamName = parameterNames.length >= 1 ? parameterNames[0] : '';\r\n\r\n var source = sourceMapping\r\n ? destination\r\n : AutoMapperHelper.getMapFromString(funcStr, destination, optsParamName);\r\n\r\n var metadata: IMemberMappingMetaData = {\r\n destination: destination,\r\n source: source,\r\n sourceMapping: sourceMapping,\r\n condition: null,\r\n ignore: AutoMapperHelper.getIgnoreFromString(funcStr, destination),\r\n async: parameterNames.length === 2\r\n };\r\n\r\n // calling the member options function when used asynchronous would be too 'dangerous'.\r\n if (!metadata.async && AutoMapperHelper.getFunctionCallIndex(funcStr, 'condition', optsParamName) >= 0) {\r\n metadata.condition = AutoMapperHelper.getConditionFromFunction(func, source);\r\n }\r\n\r\n return metadata;\r\n }\r\n\r\n private static getIgnoreFromString(functionString: string, optionsParameterName: string): boolean {\r\n var indexOfIgnore = AutoMapperHelper.getFunctionCallIndex(functionString, 'ignore', optionsParameterName);\r\n if (indexOfIgnore < 0) {\r\n return false;\r\n }\r\n\r\n var indexOfMapFromStart = functionString.indexOf('(', indexOfIgnore) + 1;\r\n var indexOfMapFromEnd = functionString.indexOf(')', indexOfMapFromStart);\r\n\r\n if (indexOfMapFromStart < 0 || indexOfMapFromEnd < 0) {\r\n return false;\r\n }\r\n\r\n var ignoreString = functionString.substring(indexOfMapFromStart, indexOfMapFromEnd).replace(/\\r/g, '').replace(/\\n/g, '').trim();\r\n return ignoreString === null || ignoreString === ''\r\n ? true // .ignore()\r\n : false; // .ignore( -> unexpected content)\r\n }\r\n\r\n private static getMapFromString(functionString: string, defaultValue: string, optionsParameterName: string): string {\r\n var indexOfMapFrom = AutoMapperHelper.getFunctionCallIndex(functionString, 'mapFrom', optionsParameterName);\r\n if (indexOfMapFrom < 0) {\r\n return defaultValue;\r\n }\r\n\r\n var indexOfMapFromStart = functionString.indexOf('(', indexOfMapFrom) + 1;\r\n var indexOfMapFromEnd = functionString.indexOf(')', indexOfMapFromStart);\r\n\r\n if (indexOfMapFromStart < 0 || indexOfMapFromEnd < 0) {\r\n return defaultValue;\r\n }\r\n\r\n var mapFromString = functionString.substring(indexOfMapFromStart, indexOfMapFromEnd).replace(/'/g, '').replace(/\"/g, '').trim();\r\n return mapFromString === null || mapFromString === ''\r\n ? defaultValue\r\n : mapFromString;\r\n }\r\n\r\n private static getFunctionCallIndex(functionString: string, functionToLookFor: string, optionsParameterName: string): number {\r\n var indexOfFunctionCall = functionString.indexOf(optionsParameterName + '.' + functionToLookFor);\r\n if (indexOfFunctionCall < 0) {\r\n indexOfFunctionCall = functionString.indexOf('.' + functionToLookFor);\r\n }\r\n\r\n return indexOfFunctionCall;\r\n }\r\n\r\n private static getConditionFromFunction(func: Function, sourceProperty: string): ((sourceObject: any) => boolean) {\r\n // Since we are calling the valueOrFunction function to determine whether to ignore or map from another property, we\r\n // want to prevent the call to be error prone when the end user uses the '(opts)=> opts.sourceObject.sourcePropertyName'\r\n // syntax. We don't actually have a source object when creating a mapping; therefore, we 'stub' a source object for the\r\n // function call.\r\n var sourceObject: any = {};\r\n sourceObject[sourceProperty] = {};\r\n\r\n var condition: (sourceObject: any) => boolean;\r\n\r\n // calling the function will result in calling our stubbed ignore() and mapFrom() functions if used inside the function.\r\n const configFuncOptions: IMemberConfigurationOptions = {\r\n ignore: (): void => {\r\n // do nothing\r\n },\r\n condition: (predicate: ((sourceObject: any) => boolean)): void => {\r\n condition = predicate;\r\n },\r\n mapFrom: (sourcePropertyName: string): void => {\r\n // do nothing\r\n },\r\n sourceObject: sourceObject,\r\n sourcePropertyName: sourceProperty,\r\n intermediatePropertyValue: {}\r\n };\r\n\r\n try {\r\n func(configFuncOptions);\r\n } catch (exc) {\r\n // do not handle by default.\r\n }\r\n\r\n return condition;\r\n }\r\n\t}\r\n}"],"sourceRoot":"/source/"} \ No newline at end of file +{"version":3,"sources":["AutoMapperHelper.ts"],"names":[],"mappings":"AAAA,IAAO,YAAY,CAuNlB;AAvND,WAAO,YAAY,EAAC,CAAC;IACjB,YAAY,CAAC;IAEb;;OAEG;IACH;QAAA;QAgNH,CAAC;QA/MoB,6BAAY,GAA1B,UAA2B,SAAuB;YAC9C,EAAE,CAAC,CAAC,SAAS,IAAU,SAAU,CAAC,IAAI,CAAC,CAAC,CAAC;gBACrC,MAAM,CAAO,SAAU,CAAC,IAAI,CAAC;YACjC,CAAC;YACD,qDAAqD;YACrD,EAAE,CAAC,CAAC,SAAS,IAAI,SAAS,CAAC,WAAW,CAAC,CAAC,CAAC;gBACrC,IAAI,SAAS,GAAG,SAAS,CAAC,QAAQ,EAAE,CAAC;gBACrC,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;oBACZ,6DAA6D;oBAC7D,IAAI,UAAU,GAAG,SAAS,CAAC,KAAK,CAA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AC,OAAO,CAAC,GAAG,GAAG,iBAAiB,CAAC,CAAC;YAC1E,CAAC;YAED,MAAM,CAAC,mBAAmB,CAAC;QAC/B,CAAC;QAEc,yCAAwB,GAAvC,UAAwC,IAAc,EAAE,cAAsB;YAC1E,oHAAoH;YACpH,wHAAwH;YACxH,uHAAuH;YACvH,iBAAiB;YACjB,IAAI,YAAY,GAAQ,EAAE,CAAC;YAC3B,YAAY,CAAC,cAAc,CAAC,GAAG,EAAE,CAAC;YAElC,IAAI,SAAyC,CAAC;YAE9C,wHAAwH;YACxH,IAAM,iBAAiB,GAAgC;gBACnD,MAAM,EAAE;oBACJ,aAAa;gBACjB,CAAC;gBACD,SAAS,EAAE,UAAC,SAA2C;oBACnD,SAAS,GAAG,SAAS,CAAC;gBAC1B,CAAC;gBACD,OAAO,EAAE,UAAC,kBAA0B;oBAChC,aAAa;gBACjB,CAAC;gBACD,YAAY,EAAE,YAAY;gBAC1B,kBAAkB,EAAE,cAAc;gBAClC,yBAAyB,EAAE,EAAE;aAChC,CAAC;YAEF,IAAI,CAAC;gBACD,IAAI,CAAC,iBAAiB,CAAC,CAAC;YAC5B,CAAE;YAAA,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;YAEf,CAAC;YAED,MAAM,CAAC,SAAS,CAAC;QACrB,CAAC;QACR,uBAAC;IAAD,CAhNG,AAgNF,IAAA;IAhNe,6BAAgB,mBAgN/B,CAAA;AACF,CAAC,EAvNM,YAAY,KAAZ,YAAY,QAuNlB","file":"AutoMapperHelper.js","sourcesContent":["module AutoMapperJs {\r\n 'use strict';\r\n\r\n /**\r\n * AutoMapper helper functions\r\n */\r\n export class AutoMapperHelper {\r\n public static getClassName(classType: new() => any): string {\r\n if (classType && (classType).name) {\r\n return (classType).name;\r\n }\r\n // source: http://stackoverflow.com/a/13914278/702357\r\n if (classType && classType.constructor) {\r\n let className = classType.toString();\r\n if (className) {\r\n // classType.toString() is \"function classType (...) { ... }\"\r\n let matchParts = className.match(/function\\s*(\\w+)/);\r\n if (matchParts && matchParts.length === 2) {\r\n return matchParts[1];\r\n }\r\n }\r\n\r\n // for browsers which have name property in the constructor\r\n // of the object, such as chrome\r\n if ((classType.constructor).name) {\r\n return (classType.constructor).name;\r\n }\r\n\r\n if (classType.constructor.toString()) {\r\n var str = classType.constructor.toString();\r\n\r\n if (str.charAt(0) === '[') {\r\n // executed if the return of object.constructor.toString() is \"[object objectClass]\"\r\n var arr = str.match(/\\[\\w+\\s*(\\w+)\\]/);\r\n } else {\r\n // executed if the return of object.constructor.toString() is \"function objectClass () {}\"\r\n // (IE and Firefox)\r\n var arr = str.match(/function\\s*(\\w+)/);\r\n }\r\n\r\n if (arr && arr.length === 2) {\r\n return arr[1];\r\n }\r\n }\r\n }\r\n\r\n throw new Error(`Unable to extract class name from type '${classType}'`);\r\n }\r\n\r\n public static getFunctionParameters(func: Function): Array {\r\n const stripComments = /((\\/\\/.*$)|(\\/\\*[\\s\\S]*?\\*\\/))/mg;\r\n const argumentNames = /([^\\s,]+)/g;\r\n\r\n var functionString = func.toString().replace(stripComments, '');\r\n var functionParameterNames = functionString.slice(functionString.indexOf('(') + 1, functionString.indexOf(')')).match(argumentNames);\r\n if (functionParameterNames === null) {\r\n functionParameterNames = new Array();\r\n }\r\n return functionParameterNames;\r\n }\r\n\r\n public static handleCurrying(func: Function, args: IArguments, closure: any): any {\r\n const argumentsStillToCome = func.length - args.length;\r\n\r\n // saved accumulator array\r\n // NOTE BL this does not deep copy array objects, only the array itself; should side effects occur, please report (or refactor).\r\n var argumentsCopy = Array.prototype.slice.apply(args);\r\n\r\n function accumulator(moreArgs: IArguments, alreadyProvidedArgs: Array, stillToCome: number): Function {\r\n var previousAlreadyProvidedArgs = alreadyProvidedArgs.slice(0); // to reset\r\n var previousStillToCome = stillToCome; // to reset\r\n\r\n for (let i = 0; i < moreArgs.length; i++, stillToCome--) {\r\n alreadyProvidedArgs[alreadyProvidedArgs.length] = moreArgs[i];\r\n }\r\n\r\n if (stillToCome - moreArgs.length <= 0) {\r\n var functionCallResult = func.apply(closure, alreadyProvidedArgs);\r\n\r\n // reset vars, so curried function can be applied to new params.\r\n alreadyProvidedArgs = previousAlreadyProvidedArgs;\r\n stillToCome = previousStillToCome;\r\n\r\n return functionCallResult;\r\n } else {\r\n return function(): Function {\r\n // arguments are params, so closure bussiness is avoided.\r\n return accumulator(arguments, alreadyProvidedArgs.slice(0), stillToCome);\r\n };\r\n }\r\n }\r\n\r\n return accumulator(([]), argumentsCopy, argumentsStillToCome);\r\n }\r\n\r\n public static getMappingMetadataFromConfigFunction(destination: string, func: any, sourceMapping: boolean): IMemberMappingMetaData {\r\n if (typeof func !== 'function') {\r\n return {\r\n destination: destination,\r\n source: destination,\r\n sourceMapping: sourceMapping,\r\n condition: null,\r\n ignore: false,\r\n async: false\r\n };\r\n }\r\n\r\n var funcStr = func.toString();\r\n\r\n var parameterNames = AutoMapperHelper.getFunctionParameters(func);\r\n var optsParamName = parameterNames.length >= 1 ? parameterNames[0] : '';\r\n\r\n var source = sourceMapping\r\n ? destination\r\n : AutoMapperHelper.getMapFromString(funcStr, destination, optsParamName);\r\n\r\n var metadata: IMemberMappingMetaData = {\r\n destination: destination,\r\n source: source,\r\n sourceMapping: sourceMapping,\r\n condition: null,\r\n ignore: AutoMapperHelper.getIgnoreFromString(funcStr, destination),\r\n async: parameterNames.length === 2\r\n };\r\n\r\n // calling the member options function when used asynchronous would be too 'dangerous'.\r\n if (!metadata.async && AutoMapperHelper.getFunctionCallIndex(funcStr, 'condition', optsParamName) >= 0) {\r\n metadata.condition = AutoMapperHelper.getConditionFromFunction(func, source);\r\n }\r\n\r\n return metadata;\r\n }\r\n\r\n private static getIgnoreFromString(functionString: string, optionsParameterName: string): boolean {\r\n var indexOfIgnore = AutoMapperHelper.getFunctionCallIndex(functionString, 'ignore', optionsParameterName);\r\n if (indexOfIgnore < 0) {\r\n return false;\r\n }\r\n\r\n var indexOfMapFromStart = functionString.indexOf('(', indexOfIgnore) + 1;\r\n var indexOfMapFromEnd = functionString.indexOf(')', indexOfMapFromStart);\r\n\r\n if (indexOfMapFromStart < 0 || indexOfMapFromEnd < 0) {\r\n return false;\r\n }\r\n\r\n var ignoreString = functionString.substring(indexOfMapFromStart, indexOfMapFromEnd).replace(/\\r/g, '').replace(/\\n/g, '').trim();\r\n return ignoreString === null || ignoreString === ''\r\n ? true // .ignore()\r\n : false; // .ignore( -> unexpected content)\r\n }\r\n\r\n private static getMapFromString(functionString: string, defaultValue: string, optionsParameterName: string): string {\r\n var indexOfMapFrom = AutoMapperHelper.getFunctionCallIndex(functionString, 'mapFrom', optionsParameterName);\r\n if (indexOfMapFrom < 0) {\r\n return defaultValue;\r\n }\r\n\r\n var indexOfMapFromStart = functionString.indexOf('(', indexOfMapFrom) + 1;\r\n var indexOfMapFromEnd = functionString.indexOf(')', indexOfMapFromStart);\r\n\r\n if (indexOfMapFromStart < 0 || indexOfMapFromEnd < 0) {\r\n return defaultValue;\r\n }\r\n\r\n var mapFromString = functionString.substring(indexOfMapFromStart, indexOfMapFromEnd).replace(/'/g, '').replace(/\"/g, '').trim();\r\n return mapFromString === null || mapFromString === ''\r\n ? defaultValue\r\n : mapFromString;\r\n }\r\n\r\n private static getFunctionCallIndex(functionString: string, functionToLookFor: string, optionsParameterName: string): number {\r\n var indexOfFunctionCall = functionString.indexOf(optionsParameterName + '.' + functionToLookFor);\r\n if (indexOfFunctionCall < 0) {\r\n indexOfFunctionCall = functionString.indexOf('.' + functionToLookFor);\r\n }\r\n\r\n return indexOfFunctionCall;\r\n }\r\n\r\n private static getConditionFromFunction(func: Function, sourceProperty: string): ((sourceObject: any) => boolean) {\r\n // Since we are calling the valueOrFunction function to determine whether to ignore or map from another property, we\r\n // want to prevent the call to be error prone when the end user uses the '(opts)=> opts.sourceObject.sourcePropertyName'\r\n // syntax. We don't actually have a source object when creating a mapping; therefore, we 'stub' a source object for the\r\n // function call.\r\n var sourceObject: any = {};\r\n sourceObject[sourceProperty] = {};\r\n\r\n var condition: (sourceObject: any) => boolean;\r\n\r\n // calling the function will result in calling our stubbed ignore() and mapFrom() functions if used inside the function.\r\n const configFuncOptions: IMemberConfigurationOptions = {\r\n ignore: (): void => {\r\n // do nothing\r\n },\r\n condition: (predicate: ((sourceObject: any) => boolean)): void => {\r\n condition = predicate;\r\n },\r\n mapFrom: (sourcePropertyName: string): void => {\r\n // do nothing\r\n },\r\n sourceObject: sourceObject,\r\n sourcePropertyName: sourceProperty,\r\n intermediatePropertyValue: {}\r\n };\r\n\r\n try {\r\n func(configFuncOptions);\r\n } catch (exc) {\r\n // do not handle by default.\r\n }\r\n\r\n return condition;\r\n }\r\n\t}\r\n}"]} \ No newline at end of file diff --git a/src/js/AutoMapperValidator.js.map b/src/js/AutoMapperValidator.js.map index 08bc683..1577436 100644 --- a/src/js/AutoMapperValidator.js.map +++ b/src/js/AutoMapperValidator.js.map @@ -1 +1 @@ -{"version":3,"sources":["AutoMapperValidator.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAC9D,4CAA4C;AAC5C,IAAO,YAAY,CA8JlB;AA9JD,WAAO,YAAY,EAAC,CAAC;IACjB,YAAY,CAAC;IAEb;;OAEG;IACH;QAAA;QAuJA,CAAC;QAtJG;;;;;;;;WAQG;QACW,8CAA0B,GAAxC,UAAyC,QAAa,EAAE,UAAmB;YACvE,GAAG,CAAC,CAAC,IAAI,GAAG,IAAI,QAAQ,CAAC,CAAC,CAAC;gBACvB,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;oBAChC,QAAQ,CAAC;gBACb,CAAC;gBAED,mBAAmB,CAAC,0BAA0B,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,UAAU,CAAC,CAAC;YAC9E,CAAC;QACL,CAAC;QAEc,8CAA0B,GAAzC,UAA0C,OAAiB,EAAE,UAAmB;YAC5E,IAAI,UAAU,GAAM,OAAO,CAAC,SAAS,UAAK,OAAO,CAAC,cAAgB,CAAC;YAE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AM,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;gBACjC,MAAM,CAAC,yBAAuB,MAAM,oEAAiE,CAAC;YAC1G,CAAC;YAED,sDAAsD;YAEtD,MAAM,CAAC,SAAS,CAAC;QACrB,CAAC;QAEc,oCAAgB,GAA/B,UAAgC,SAAc,EAAE,MAAW;YACvD,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;gBACpC,MAAM,CAAC,oBAAkB,SAAS,yEAAsE,CAAC;YAC7G,CAAC;YAED,MAAM,CAAC,SAAS,CAAC;QACrB,CAAC;QACL,0BAAC;IAAD,CAvJA,AAuJC,IAAA;IAvJY,gCAAmB,sBAuJ/B,CAAA;AACL,CAAC,EA9JM,YAAY,KAAZ,YAAY,QA8JlB","file":"AutoMapperValidator.js","sourcesContent":["/// \r\n/// \r\nmodule AutoMapperJs {\r\n 'use strict';\r\n\r\n /**\r\n * AutoMapper configuration validator.\r\n */\r\n export class AutoMapperValidator {\r\n /**\r\n * Validates mapping configuration by dry-running. Since JS does not\r\n * fully support typing, it only checks if properties match on both\r\n * sides. The function needs IMapping.sourceTypeClass and \r\n * IMapping.destinationTypeClass to function.\r\n * @param {boolean} strictMode Whether or not to fail when properties\r\n * sourceTypeClass or destinationTypeClass\r\n * are unavailable. \r\n */\r\n public static assertConfigurationIsValid(mappings: any, strictMode: boolean): void {\r\n for (var key in mappings) {\r\n if (!mappings.hasOwnProperty(key)) {\r\n continue;\r\n }\r\n\r\n AutoMapperValidator.assertMappingConfiguration(mappings[key], strictMode);\r\n }\r\n }\r\n\r\n private static assertMappingConfiguration(mapping: IMapping, strictMode: boolean): void {\r\n var mappingKey = `${mapping.sourceKey}=>${mapping.destinationKey}`;\r\n\r\n var sourceType = mapping.sourceTypeClass;\r\n var destinationType = mapping.destinationTypeClass;\r\n\r\n var sourceClassName = sourceType ? AutoMapperHelper.getClassName(sourceType) : undefined;\r\n var destinationClassName = destinationType ? AutoMapperHelper.getClassName(destinationType) : undefined;\r\n\r\n if (!sourceType || !destinationType) {\r\n if (strictMode === false) {\r\n return;\r\n }\r\n\r\n throw new Error(`Mapping '${mappingKey}' cannot be validated, since mapping.sourceType or mapping.destinationType are unspecified.`);\r\n }\r\n\r\n var tryHandle = (errorMessage: string) => {\r\n if (errorMessage) {\r\n throw new Error(`Mapping '${mappingKey}' is invalid: ${errorMessage} (source: '${sourceClassName}', destination: '${destinationClassName}').`);\r\n }\r\n };\r\n\r\n var validatedMembers = new Array();\r\n\r\n var srcObj = new sourceType();\r\n var dstObj = new destinationType();\r\n\r\n // walk member mappings\r\n for (let property of mapping.properties) {\r\n\r\n\r\n tryHandle(AutoMapperValidator.validatePropertyMapping(property, property.name, srcObj, dstObj));\r\n validatedMembers.push(property.name);\r\n }\r\n\r\n // walk source members\r\n for (let srcMember in srcObj) {\r\n if (!srcObj.hasOwnProperty(srcMember)) {\r\n continue;\r\n }\r\n\r\n if (validatedMembers.indexOf(srcMember) >= 0) {\r\n // already validated\r\n continue;\r\n }\r\n\r\n tryHandle(AutoMapperValidator.validateProperty(srcMember, dstObj));\r\n validatedMembers.push(srcMember);\r\n }\r\n\r\n // walk destination members\r\n for (let dstMember in dstObj) {\r\n if (!dstObj.hasOwnProperty(dstMember)) {\r\n continue;\r\n }\r\n\r\n if (validatedMembers.indexOf(dstMember) >= 0) {\r\n // already validated\r\n continue;\r\n }\r\n\r\n tryHandle(`Destination member '${dstMember}' does not exist on source type`);\r\n }\r\n // /* tslint:disable */\r\n // console.error(key);\r\n // /* tslint:enable */ \r\n }\r\n\r\n private static validatePropertyMapping(propertyMapping: IProperty, member: any, srcObj: any, dstObj: any): string {\r\n return propertyMapping.sourceMapping\r\n ? AutoMapperValidator.validateSourcePropertyMapping(propertyMapping, member, srcObj, dstObj)\r\n : AutoMapperValidator.validateDestinationPropertyMapping(propertyMapping, member, srcObj, dstObj);\r\n\r\n }\r\n\r\n private static validateSourcePropertyMapping(propertyMapping: IProperty, member: any, srcObj: any, dstObj: any): string {\r\n // a member for which configuration is provided, should exist.\r\n if (!srcObj.hasOwnProperty(member)) {\r\n return `Source member '${member}' is configured, but does not exist on source type`;\r\n }\r\n\r\n // an ignored source member should not exist on the destination type. \r\n if (propertyMapping.ignore) {\r\n if (dstObj.hasOwnProperty(member)) {\r\n return `Source member '${member}' is ignored, but does exist on destination type`;\r\n }\r\n return;\r\n }\r\n\r\n // a mapped source member should exist on the destination type.\r\n if (!dstObj.hasOwnProperty(member)) {\r\n return `Source member '${member}' is configured to be mapped, but does not exist on destination type`;\r\n }\r\n\r\n //var dstMember = propertyMapping.destinationProperty;\r\n\r\n return undefined;\r\n }\r\n\r\n private static validateDestinationPropertyMapping(propertyMapping: IProperty, member: any, srcObj: any, dstObj: any): string {\r\n // a member for which configuration is provided, should exist.\r\n if (!dstObj.hasOwnProperty(member)) {\r\n return `Destination member '${member}' is configured, but does not exist on destination type`;\r\n }\r\n\r\n // an ignored destination member should not exist on the source type. \r\n if (propertyMapping.ignore) {\r\n if (srcObj.hasOwnProperty(member)) {\r\n return `Destination member '${member}' is ignored, but does exist on source type`;\r\n }\r\n return;\r\n }\r\n\r\n // a mapped destination member should exist on the source type.\r\n if (!srcObj.hasOwnProperty(member)) {\r\n return `Destination member '${member}' is configured to be mapped, but does not exist on source type`;\r\n }\r\n\r\n //var dstMember = propertyMapping.destinationProperty;\r\n\r\n return undefined;\r\n }\r\n\r\n private static validateProperty(srcMember: any, dstObj: any): string {\r\n if (!dstObj.hasOwnProperty(srcMember)) {\r\n return `Source member '${srcMember}' is configured to be mapped, but does not exist on destination type`;\r\n }\r\n\r\n return undefined;\r\n }\r\n }\r\n}"],"sourceRoot":"/source/"} \ No newline at end of file +{"version":3,"sources":["AutoMapperValidator.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAC9D,4CAA4C;AAC5C,IAAO,YAAY,CA8JlB;AA9JD,WAAO,YAAY,EAAC,CAAC;IACjB,YAAY,CAAC;IAEb;;O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c,sDAAkC,GAAjD,UAAkD,eAA0B,EAAE,MAAW,EAAE,MAAW,EAAE,MAAW;YAC/G,8DAA8D;YAC9D,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;gBACjC,MAAM,CAAC,yBAAuB,MAAM,4DAAyD,CAAC;YAClG,CAAC;YAED,sEAAsE;YACtE,EAAE,CAAC,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC,CAAC;gBACzB,EAAE,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;oBAChC,MAAM,CAAC,yBAAuB,MAAM,gDAA6C,CAAC;gBACtF,CAAC;gBACD,MAAM,CAAC;YACX,CAAC;YAED,+DAA+D;YAC/D,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;gBACjC,MAAM,CAAC,yBAAuB,MAAM,oEAAiE,CAAC;YAC1G,CAAC;YAED,sDAAsD;YAEtD,MAAM,CAAC,SAAS,CAAC;QACrB,CAAC;QAEc,oCAAgB,GAA/B,UAAgC,SAAc,EAAE,MAAW;YACvD,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;gBACpC,MAAM,CAAC,oBAAkB,SAAS,yEAAsE,CAAC;YAC7G,CAAC;YAED,MAAM,CAAC,SAAS,CAAC;QACrB,CAAC;QACL,0BAAC;IAAD,CAvJA,AAuJC,IAAA;IAvJY,gCAAmB,sBAuJ/B,CAAA;AACL,CAAC,EA9JM,YAAY,KAAZ,YAAY,QA8JlB","file":"AutoMapperValidator.js","sourcesContent":["/// \r\n/// \r\nmodule AutoMapperJs {\r\n 'use strict';\r\n\r\n /**\r\n * AutoMapper configuration validator.\r\n */\r\n export class AutoMapperValidator {\r\n /**\r\n * Validates mapping configuration by dry-running. Since JS does not\r\n * fully support typing, it only checks if properties match on both\r\n * sides. The function needs IMapping.sourceTypeClass and \r\n * IMapping.destinationTypeClass to function.\r\n * @param {boolean} strictMode Whether or not to fail when properties\r\n * sourceTypeClass or destinationTypeClass\r\n * are unavailable. \r\n */\r\n public static assertConfigurationIsValid(mappings: any, strictMode: boolean): void {\r\n for (var key in mappings) {\r\n if (!mappings.hasOwnProperty(key)) {\r\n continue;\r\n }\r\n\r\n AutoMapperValidator.assertMappingConfiguration(mappings[key], strictMode);\r\n }\r\n }\r\n\r\n private static assertMappingConfiguration(mapping: IMapping, strictMode: boolean): void {\r\n var mappingKey = `${mapping.sourceKey}=>${mapping.destinationKey}`;\r\n\r\n var sourceType = mapping.sourceTypeClass;\r\n var destinationType = mapping.destinationTypeClass;\r\n\r\n var sourceClassName = sourceType ? AutoMapperHelper.getClassName(sourceType) : undefined;\r\n var destinationClassName = destinationType ? AutoMapperHelper.getClassName(destinationType) : undefined;\r\n\r\n if (!sourceType || !destinationType) {\r\n if (strictMode === false) {\r\n return;\r\n }\r\n\r\n throw new Error(`Mapping '${mappingKey}' cannot be validated, since mapping.sourceType or mapping.destinationType are unspecified.`);\r\n }\r\n\r\n var tryHandle = (errorMessage: string) => {\r\n if (errorMessage) {\r\n throw new Error(`Mapping '${mappingKey}' is invalid: ${errorMessage} (source: '${sourceClassName}', destination: '${destinationClassName}').`);\r\n }\r\n };\r\n\r\n var validatedMembers = new Array();\r\n\r\n var srcObj = new sourceType();\r\n var dstObj = new destinationType();\r\n\r\n // walk member mappings\r\n for (let property of mapping.properties) {\r\n\r\n\r\n tryHandle(AutoMapperValidator.validatePropertyMapping(property, property.name, srcObj, dstObj));\r\n validatedMembers.push(property.name);\r\n }\r\n\r\n // walk source members\r\n for (let srcMember in srcObj) {\r\n if (!srcObj.hasOwnProperty(srcMember)) {\r\n continue;\r\n }\r\n\r\n if (validatedMembers.indexOf(srcMember) >= 0) {\r\n // already validated\r\n continue;\r\n }\r\n\r\n tryHandle(AutoMapperValidator.validateProperty(srcMember, dstObj));\r\n validatedMembers.push(srcMember);\r\n }\r\n\r\n // walk destination members\r\n for (let dstMember in dstObj) {\r\n if (!dstObj.hasOwnProperty(dstMember)) {\r\n continue;\r\n }\r\n\r\n if (validatedMembers.indexOf(dstMember) >= 0) {\r\n // already validated\r\n continue;\r\n }\r\n\r\n tryHandle(`Destination member '${dstMember}' does not exist on source type`);\r\n }\r\n // /* tslint:disable */\r\n // console.error(key);\r\n // /* tslint:enable */ \r\n }\r\n\r\n private static validatePropertyMapping(propertyMapping: IProperty, member: any, srcObj: any, dstObj: any): string {\r\n return propertyMapping.sourceMapping\r\n ? AutoMapperValidator.validateSourcePropertyMapping(propertyMapping, member, srcObj, dstObj)\r\n : AutoMapperValidator.validateDestinationPropertyMapping(propertyMapping, member, srcObj, dstObj);\r\n\r\n }\r\n\r\n private static validateSourcePropertyMapping(propertyMapping: IProperty, member: any, srcObj: any, dstObj: any): string {\r\n // a member for which configuration is provided, should exist.\r\n if (!srcObj.hasOwnProperty(member)) {\r\n return `Source member '${member}' is configured, but does not exist on source type`;\r\n }\r\n\r\n // an ignored source member should not exist on the destination type. \r\n if (propertyMapping.ignore) {\r\n if (dstObj.hasOwnProperty(member)) {\r\n return `Source member '${member}' is ignored, but does exist on destination type`;\r\n }\r\n return;\r\n }\r\n\r\n // a mapped source member should exist on the destination type.\r\n if (!dstObj.hasOwnProperty(member)) {\r\n return `Source member '${member}' is configured to be mapped, but does not exist on destination type`;\r\n }\r\n\r\n //var dstMember = propertyMapping.destinationProperty;\r\n\r\n return undefined;\r\n }\r\n\r\n private static validateDestinationPropertyMapping(propertyMapping: IProperty, member: any, srcObj: any, dstObj: any): string {\r\n // a member for which configuration is provided, should exist.\r\n if (!dstObj.hasOwnProperty(member)) {\r\n return `Destination member '${member}' is configured, but does not exist on destination type`;\r\n }\r\n\r\n // an ignored destination member should not exist on the source type. \r\n if (propertyMapping.ignore) {\r\n if (srcObj.hasOwnProperty(member)) {\r\n return `Destination member '${member}' is ignored, but does exist on source type`;\r\n }\r\n return;\r\n }\r\n\r\n // a mapped destination member should exist on the source type.\r\n if (!srcObj.hasOwnProperty(member)) {\r\n return `Destination member '${member}' is configured to be mapped, but does not exist on source type`;\r\n }\r\n\r\n //var dstMember = propertyMapping.destinationProperty;\r\n\r\n return undefined;\r\n }\r\n\r\n private static validateProperty(srcMember: any, dstObj: any): string {\r\n if (!dstObj.hasOwnProperty(srcMember)) {\r\n return `Source member '${srcMember}' is configured to be mapped, but does not exist on destination type`;\r\n }\r\n\r\n return undefined;\r\n }\r\n }\r\n}"]} \ No newline at end of file diff --git a/src/js/Profile.js.map b/src/js/Profile.js.map index e1cf263..500fa23 100644 --- a/src/js/Profile.js.map +++ b/src/js/Profile.js.map @@ -1 +1 @@ -{"version":3,"sources":["Profile.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAC9D,mDAAmD;AAEnD,IAAO,YAAY,CA8ClB;AA9CD,WAAO,YAAY,EAAC,CAAC;IACjB,YAAY,CAAC;IAEb;;OAEG;IACH;QAAA;QAuCA,CAAC;QA7BG;;;WAGG;QACI,2BAAS,GAAhB;YACI,aAAa;QACjB,CAAC;QAED;;;;;WAKG;QACO,2BAAS,GAAnB,UAAoB,SAAiB,EAAE,cAAsB;YACzD,IAAI,QAAQ,GAAG,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;YAEtD,GAAG,CAAC,CAAC,IAAI,KAAK,GAAG,CAAC,EAAE,MAAM,GAAG,QAAQ,CAAC,MAAM,EAAE,KAAK,GAAG,MAAM,EAAE,KAAK,EAAG,EAAE,CAAC;gBACrE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;oBACnB,QAAQ,CAAC;gBACb,CAAC;gBAED,2DAA2D;gBAC3D,QAAQ,CAAC,KAAK,CAAC,GAAM,IAAI,CAAC,WAAW,UAAK,QAAQ,CAAC,KAAK,CAAG,CAAC;YAChE,CAAC;YAED,sFAAsF;YACtF,MAAM,CAAC,UAAU,CAAC,SAAS,CAAC,KAAK,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;QAC5D,CAAC;QACL,cAAC;IAAD,CAvCA,AAuCC,IAAA;IAvCY,oBAAO,UAuCnB,CAAA;AACL,CAAC,EA9CM,YAAY,KAAZ,YAAY,QA8ClB","file":"Profile.js","sourcesContent":["/// \r\n/// \r\n\r\nmodule AutoMapperJs {\r\n 'use strict';\r\n\r\n /**\r\n * Converts source type to destination type instead of normal member mapping\r\n */\r\n export class Profile implements IProfile {\r\n /** Profile name */\r\n public profileName: string;\r\n\r\n /** Naming convention for source members */\r\n public sourceMemberNamingConvention: INamingConvention;\r\n\r\n /** Naming convention for destination members */\r\n public destinationMemberNamingConvention: INamingConvention;\r\n\r\n /**\r\n * Implement this method in a derived class and call the CreateMap method to associate that map with this profile.\r\n * Avoid calling the AutoMapper class / automapper instance from this method. \r\n */\r\n public configure(): void {\r\n // do nothing\r\n }\r\n\r\n /**\r\n * Create a mapping profile.\r\n * @param {string} sourceKey The map source key.\r\n * @param {string} destinationKey The map destination key.\r\n * @returns {Core.ICreateMapFluentFunctions}\r\n */\r\n protected createMap(sourceKey: string, destinationKey: string): ICreateMapFluentFunctions {\r\n var argsCopy = Array.prototype.slice.apply(arguments);\r\n\r\n for (var index = 0, length = argsCopy.length; index < length; index ++) {\r\n if (!argsCopy[index]) {\r\n continue;\r\n }\r\n\r\n // prefix sourceKey and destinationKey with 'profileName=>'\r\n argsCopy[index] = `${this.profileName}=>${argsCopy[index]}`;\r\n }\r\n\r\n // pass through using arguments to keep createMap's currying support fully functional.\r\n return automapper.createMap.apply(automapper, argsCopy);\r\n }\r\n }\r\n}"],"sourceRoot":"/source/"} \ No newline at end of file +{"version":3,"sources":["Profile.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAC9D,mDAAmD;AAEnD,IAAO,YAAY,CA8ClB;AA9CD,WAAO,YAAY,EAAC,CAAC;IACjB,YAAY,CAAC;IAEb;;OAEG;IACH;QAAA;QAuCA,CAAC;QA7BG;;;WAGG;QACI,2BAAS,GAAhB;YACI,aAAa;QACjB,CAAC;QAED;;;;;WAKG;QACO,2BAAS,GAAnB,UAAoB,SAAiB,EAAE,cAAsB;YACzD,IAAI,QAAQ,GAAG,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;YAEtD,GAAG,CAAC,CAAC,IAAI,KAAK,GAAG,CAAC,EAAE,MAAM,GAAG,QAAQ,CAAC,MAAM,EAAE,KAAK,GAAG,MAAM,EAAE,KAAK,EAAG,EAAE,CAAC;gBACrE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;oBACnB,QAAQ,CAAC;gBACb,CAAC;gBAED,2DAA2D;gBAC3D,QAAQ,CAAC,KAAK,CAAC,GAAM,IAAI,CAAC,WAAW,UAAK,QAAQ,CAAC,KAAK,CAAG,CAAC;YAChE,CAAC;YAED,sFAAsF;YACtF,MAAM,CAAC,UAAU,CAAC,SAAS,CAAC,KAAK,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;QAC5D,CAAC;QACL,cAAC;IAAD,CAvCA,AAuCC,IAAA;IAvCY,oBAAO,UAuCnB,CAAA;AACL,CAAC,EA9CM,YAAY,KAAZ,YAAY,QA8ClB","file":"Profile.js","sourcesContent":["/// \r\n/// \r\n\r\nmodule AutoMapperJs {\r\n 'use strict';\r\n\r\n /**\r\n * Converts source type to destination type instead of normal member mapping\r\n */\r\n export class Profile implements IProfile {\r\n /** Profile name */\r\n public profileName: string;\r\n\r\n /** Naming convention for source members */\r\n public sourceMemberNamingConvention: INamingConvention;\r\n\r\n /** Naming convention for destination members */\r\n public destinationMemberNamingConvention: INamingConvention;\r\n\r\n /**\r\n * Implement this method in a derived class and call the CreateMap method to associate that map with this profile.\r\n * Avoid calling the AutoMapper class / automapper instance from this method. \r\n */\r\n public configure(): void {\r\n // do nothing\r\n }\r\n\r\n /**\r\n * Create a mapping profile.\r\n * @param {string} sourceKey The map source key.\r\n * @param {string} destinationKey The map destination key.\r\n * @returns {Core.ICreateMapFluentFunctions}\r\n */\r\n protected createMap(sourceKey: string, destinationKey: string): ICreateMapFluentFunctions {\r\n var argsCopy = Array.prototype.slice.apply(arguments);\r\n\r\n for (var index = 0, length = argsCopy.length; index < length; index ++) {\r\n if (!argsCopy[index]) {\r\n continue;\r\n }\r\n\r\n // prefix sourceKey and destinationKey with 'profileName=>'\r\n argsCopy[index] = `${this.profileName}=>${argsCopy[index]}`;\r\n }\r\n\r\n // pass through using arguments to keep createMap's currying support fully functional.\r\n return automapper.createMap.apply(automapper, argsCopy);\r\n }\r\n }\r\n}"]} \ No newline at end of file diff --git a/src/js/TypeConverter.js.map b/src/js/TypeConverter.js.map index f2fabe8..00c5425 100644 --- a/src/js/TypeConverter.js.map +++ b/src/js/TypeConverter.js.map @@ -1 +1 @@ -{"version":3,"sources":["TypeConverter.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAE9D,IAAO,YAAY,CAkBlB;AAlBD,WAAO,YAAY,EAAC,CAAC;IACjB,YAAY,CAAC;IAEb;;OAEG;IACH;QAAA;QAWA,CAAC;QAVG;;;;WAIG;QACI,+BAAO,GAAd,UAAe,iBAAqC;YAChD,qFAAqF;YACrF,mFAAmF;YACnF,MAAM,IAAI,KAAK,CAAC,4FAA4F,CAAC,CAAC;QAClH,CAAC;QACL,oBAAC;IAAD,CAXA,AAWC,IAAA;IAXY,0BAAa,gBAWzB,CAAA;AACL,CAAC,EAlBM,YAAY,KAAZ,YAAY,QAkBlB","file":"TypeConverter.js","sourcesContent":["/// \r\n\r\nmodule AutoMapperJs {\r\n 'use strict';\r\n\r\n /**\r\n * Converts source type to destination type instead of normal member mapping\r\n */\r\n export class TypeConverter implements ITypeConverter {\r\n /**\r\n * Performs conversion from source to destination type.\r\n * @param {IResolutionContext} resolutionContext Resolution context.\r\n * @returns {any} Destination object.\r\n */\r\n public convert(resolutionContext: IResolutionContext): any {\r\n // NOTE BL Unfortunately, TypeScript/JavaScript do not support abstract base classes.\r\n // This is just one way around, please convince me about a better solution.\r\n throw new Error('The TypeConverter.convert method is abstract. Use a TypeConverter extension class instead.');\r\n }\r\n }\r\n}"],"sourceRoot":"/source/"} \ No newline at end of file +{"version":3,"sources":["TypeConverter.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAE9D,IAAO,YAAY,CAkBlB;AAlBD,WAAO,YAAY,EAAC,CAAC;IACjB,YAAY,CAAC;IAEb;;OAEG;IACH;QAAA;QAWA,CAAC;QAVG;;;;WAIG;QACI,+BAAO,GAAd,UAAe,iBAAqC;YAChD,qFAAqF;YACrF,mFAAmF;YACnF,MAAM,IAAI,KAAK,CAAC,4FAA4F,CAAC,CAAC;QAClH,CAAC;QACL,oBAAC;IAAD,CAXA,AAWC,IAAA;IAXY,0BAAa,gBAWzB,CAAA;AACL,CAAC,EAlBM,YAAY,KAAZ,YAAY,QAkBlB","file":"TypeConverter.js","sourcesContent":["/// \r\n\r\nmodule AutoMapperJs {\r\n 'use strict';\r\n\r\n /**\r\n * Converts source type to destination type instead of normal member mapping\r\n */\r\n export class TypeConverter implements ITypeConverter {\r\n /**\r\n * Performs conversion from source to destination type.\r\n * @param {IResolutionContext} resolutionContext Resolution context.\r\n * @returns {any} Destination object.\r\n */\r\n public convert(resolutionContext: IResolutionContext): any {\r\n // NOTE BL Unfortunately, TypeScript/JavaScript do not support abstract base classes.\r\n // This is just one way around, please convince me about a better solution.\r\n throw new Error('The TypeConverter.convert method is abstract. Use a TypeConverter extension class instead.');\r\n }\r\n }\r\n}"]} \ No newline at end of file diff --git a/src/js/naming-conventions/CamelCaseNamingConvention.js.map b/src/js/naming-conventions/CamelCaseNamingConvention.js.map index 98593f2..e22dac8 100644 --- a/src/js/naming-conventions/CamelCaseNamingConvention.js.map +++ b/src/js/naming-conventions/CamelCaseNamingConvention.js.map @@ -1 +1 @@ -{"version":3,"sources":["naming-conventions/CamelCaseNamingConvention.ts"],"names":[],"mappings":"AAAA,iEAAiE;AAEjE,IAAO,YAAY,CAwBlB;AAxBD,WAAO,YAAY,EAAC,CAAC;IACjB,YAAY,CAAC;IAEhB;QAAA;YACc,wBAAmB,GAAG,kDAAkD,CAAC;YACzE,uBAAkB,GAAG,EAAE,CAAC;QAkBtC,CAAC;QAhBO,yDAAqB,GAA5B,UAA6B,uBAAiC;YACpD,gCAAgC;YAChC,IAAI,MAAM,GAAW,EAAE,CAAC;YAExB,GAAG,CAAC,CAAC,IAAI,KAAK,GAAG,CAAC,EAAE,MAAM,GAAG,uBAAuB,CAAC,MAAM,EAAE,KAAK,GAAG,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;gBAC9F,EAAE,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC;oBACH,MAAM,IAAI,uBAAuB,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE;wBACxD,uBAAuB,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;gBACjE,CAAC;gBAAC,IAAI,CAAC,CAAC;oBACI,MAAM,IAAI,uBAAuB,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE;wBACtD,uBAAuB,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;gBACnD,CAAC;YACL,CAAC;YAED,MAAM,CAAC,MAAM,CAAC;QAClB,CAAC;QACR,gCAAC;IAAD,CApBA,AAoBC,IAAA;IApBY,sCAAyB,4BAoBrC,CAAA;AACF,CAAC,EAxBM,YAAY,KAAZ,YAAY,QAwBlB","file":"naming-conventions/CamelCaseNamingConvention.js","sourcesContent":["/// \r\n\r\nmodule AutoMapperJs {\r\n 'use strict';\r\n\r\n\texport class CamelCaseNamingConvention implements INamingConvention {\r\n public splittingExpression = /(^[a-z]+(?=$|[A-Z]{1}[a-z0-9]+)|[A-Z]?[a-z0-9]+)/;\r\n public separatorCharacter = '';\r\n\r\n\t\tpublic transformPropertyName(sourcePropertyNameParts: string[]): string {\r\n // Transform the splitted parts.\r\n var result: string = '';\r\n\r\n for (var index = 0, length = sourcePropertyNameParts.length; index < length; index++) {\r\n \t\t\t\tif (index === 0) {\r\n result += sourcePropertyNameParts[index].charAt(0).toLowerCase() +\r\n sourcePropertyNameParts[index].substr(1);\r\n\t\t\t\t} else {\r\n result += sourcePropertyNameParts[index].charAt(0).toUpperCase() +\r\n sourcePropertyNameParts[index].substr(1);\r\n }\r\n }\r\n\r\n return result;\r\n }\r\n\t}\r\n}"],"sourceRoot":"/source/"} \ No newline at end of file +{"version":3,"sources":["naming-conventions/CamelCaseNamingConvention.ts"],"names":[],"mappings":"AAAA,iEAAiE;AAEjE,IAAO,YAAY,CAwBlB;AAxBD,WAAO,YAAY,EAAC,CAAC;IACjB,YAAY,CAAC;IAEhB;QAAA;YACc,wBAAmB,GAAG,kDAAkD,CAAC;YACzE,uBAAkB,GAAG,EAAE,CAAC;QAkBtC,CAAC;QAhBO,yDAAqB,GAA5B,UAA6B,uBAAiC;YACpD,gCAAgC;YAChC,IAAI,MAAM,GAAW,EAAE,CAAC;YAExB,GAAG,CAAC,CAAC,IAAI,KAAK,GAAG,CAAC,EAAE,MAAM,GAAG,uBAAuB,CAAC,MAAM,EAAE,KAAK,GAAG,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;gBAC9F,EAAE,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC;oBACH,MAAM,IAAI,uBAAuB,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE;wBACxD,uBAAuB,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;gBACjE,CAAC;gBAAC,IAAI,CAAC,CAAC;oBACI,MAAM,IAAI,uBAAuB,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE;wBACtD,uBAAuB,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;gBACnD,CAAC;YACL,CAAC;YAED,MAAM,CAAC,MAAM,CAAC;QAClB,CAAC;QACR,gCAAC;IAAD,CApBA,AAoBC,IAAA;IApBY,sCAAyB,4BAoBrC,CAAA;AACF,CAAC,EAxBM,YAAY,KAAZ,YAAY,QAwBlB","file":"CamelCaseNamingConvention.js","sourcesContent":["/// \r\n\r\nmodule AutoMapperJs {\r\n 'use strict';\r\n\r\n\texport class CamelCaseNamingConvention implements INamingConvention {\r\n public splittingExpression = /(^[a-z]+(?=$|[A-Z]{1}[a-z0-9]+)|[A-Z]?[a-z0-9]+)/;\r\n public separatorCharacter = '';\r\n\r\n\t\tpublic transformPropertyName(sourcePropertyNameParts: string[]): string {\r\n // Transform the splitted parts.\r\n var result: string = '';\r\n\r\n for (var index = 0, length = sourcePropertyNameParts.length; index < length; index++) {\r\n \t\t\t\tif (index === 0) {\r\n result += sourcePropertyNameParts[index].charAt(0).toLowerCase() +\r\n sourcePropertyNameParts[index].substr(1);\r\n\t\t\t\t} else {\r\n result += sourcePropertyNameParts[index].charAt(0).toUpperCase() +\r\n sourcePropertyNameParts[index].substr(1);\r\n }\r\n }\r\n\r\n return result;\r\n }\r\n\t}\r\n}"]} \ No newline at end of file diff --git a/src/js/naming-conventions/PascalCaseNamingConvention.js.map b/src/js/naming-conventions/PascalCaseNamingConvention.js.map index a03b4a7..d5bf9fc 100644 --- a/src/js/naming-conventions/PascalCaseNamingConvention.js.map +++ b/src/js/naming-conventions/PascalCaseNamingConvention.js.map @@ -1 +1 @@ -{"version":3,"sources":["naming-conventions/PascalCaseNamingConvention.ts"],"names":[],"mappings":"AAAA,iEAAiE;AAEjE,IAAO,YAAY,CAuBlB;AAvBD,WAAO,YAAY,EAAC,CAAC;IACjB,YAAY,CAAC;IAEhB;QAAA;YACc,wBAAmB,GAAG,kDAAkD,CAAC;YACzE,uBAAkB,GAAG,EAAE,CAAC;QAiBtC,CAAC;QAfO,0DAAqB,GAA5B,UAA6B,uBAAiC;YACpD,gCAAgC;YAChC,IAAI,MAAM,GAAW,EAAE,CAAC;YAExB,GAAG,CAAC,CAAC,IAAI,KAAK,GAAG,CAAC,EAAE,MAAM,GAAG,uBAAuB,CAAC,MAAM,EAAE,KAAK,GAAG,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;gBACnF,MAAM,IAAI,uBAAuB,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE;oBACtD,uBAAuB,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;YAKvD,CAAC;YAED,MAAM,CAAC,MAAM,CAAC;QAClB,CAAC;QACR,iCAAC;IAAD,CAnBA,AAmBC,IAAA;IAnBY,uCAA0B,6BAmBtC,CAAA;AACF,CAAC,EAvBM,YAAY,KAAZ,YAAY,QAuBlB","file":"naming-conventions/PascalCaseNamingConvention.js","sourcesContent":["/// \r\n\r\nmodule AutoMapperJs {\r\n 'use strict';\r\n\r\n\texport class PascalCaseNamingConvention implements INamingConvention {\r\n public splittingExpression = /(^[A-Z]+(?=$|[A-Z]{1}[a-z0-9]+)|[A-Z]?[a-z0-9]+)/;\r\n public separatorCharacter = '';\r\n\r\n\t\tpublic transformPropertyName(sourcePropertyNameParts: string[]): string {\r\n // Transform the splitted parts.\r\n var result: string = '';\r\n\r\n for (var index = 0, length = sourcePropertyNameParts.length; index < length; index++) {\r\n result += sourcePropertyNameParts[index].charAt(0).toUpperCase() +\r\n sourcePropertyNameParts[index].substr(1);\r\n\r\n\t\t\t\t//if (index < (length - 1)) {\r\n\t\t\t\t// this.separatorCharacter;\r\n\t\t\t\t//}\r\n }\r\n\r\n return result;\r\n }\r\n\t}\r\n}"],"sourceRoot":"/source/"} \ No newline at end of file +{"version":3,"sources":["naming-conventions/PascalCaseNamingConvention.ts"],"names":[],"mappings":"AAAA,iEAAiE;AAEjE,IAAO,YAAY,CAuBlB;AAvBD,WAAO,YAAY,EAAC,CAAC;IACjB,YAAY,CAAC;IAEhB;QAAA;YACc,wBAAmB,GAAG,kDAAkD,CAAC;YACzE,uBAAkB,GAAG,EAAE,CAAC;QAiBtC,CAAC;QAfO,0DAAqB,GAA5B,UAA6B,uBAAiC;YACpD,gCAAgC;YAChC,IAAI,MAAM,GAAW,EAAE,CAAC;YAExB,GAAG,CAAC,CAAC,IAAI,KAAK,GAAG,CAAC,EAAE,MAAM,GAAG,uBAAuB,CAAC,MAAM,EAAE,KAAK,GAAG,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;gBACnF,MAAM,IAAI,uBAAuB,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE;oBACtD,uBAAuB,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;YAKvD,CAAC;YAED,MAAM,CAAC,MAAM,CAAC;QAClB,CAAC;QACR,iCAAC;IAAD,CAnBA,AAmBC,IAAA;IAnBY,uCAA0B,6BAmBtC,CAAA;AACF,CAAC,EAvBM,YAAY,KAAZ,YAAY,QAuBlB","file":"PascalCaseNamingConvention.js","sourcesContent":["/// \r\n\r\nmodule AutoMapperJs {\r\n 'use strict';\r\n\r\n\texport class PascalCaseNamingConvention implements INamingConvention {\r\n public splittingExpression = /(^[A-Z]+(?=$|[A-Z]{1}[a-z0-9]+)|[A-Z]?[a-z0-9]+)/;\r\n public separatorCharacter = '';\r\n\r\n\t\tpublic transformPropertyName(sourcePropertyNameParts: string[]): string {\r\n // Transform the splitted parts.\r\n var result: string = '';\r\n\r\n for (var index = 0, length = sourcePropertyNameParts.length; index < length; index++) {\r\n result += sourcePropertyNameParts[index].charAt(0).toUpperCase() +\r\n sourcePropertyNameParts[index].substr(1);\r\n\r\n\t\t\t\t//if (index < (length - 1)) {\r\n\t\t\t\t// this.separatorCharacter;\r\n\t\t\t\t//}\r\n }\r\n\r\n return result;\r\n }\r\n\t}\r\n}"]} \ No newline at end of file diff --git a/src/ts/AsyncAutoMapper.ts b/src/ts/AsyncAutoMapper.ts index 385af45..c0a3bde 100644 --- a/src/ts/AsyncAutoMapper.ts +++ b/src/ts/AsyncAutoMapper.ts @@ -18,12 +18,17 @@ module AutoMapperJs { AsyncAutoMapper.asyncInstance = this; } + public createMap(sourceKeyOrType: string | (new() => any), destinationKeyOrType: string | (new() => any)): any { + throw new Error('Not implemented method'); + } + public createMapForMember(property: IProperty, func: ((opts: IMemberConfigurationOptions, cb: IMemberCallback) => void), metadata: IMemberMappingMetaData): void { - var { mapping } = property.metadata; + var {mapping} = property.metadata; mapping.async = true; + //noinspection TypeScriptValidateTypes mapping.mapItemFunction = (m: IMapping, srcObj: any, dstObj: any, cb: IMapCallback) => this.mapItem(m, srcObj, dstObj, cb); property.async = true; property.conversionValuesAndFunctions.push(func); @@ -39,9 +44,11 @@ module AutoMapperJs { public map(m: { [key: string]: IMapping }, srcKey: string | (new () => any), dstKey: string | (new () => any)): (srcObj: any, cb: IMapCallback) => void; public map(m: { [key: string]: IMapping }, srcKey: string | (new () => any), dstKey?: string | (new () => any), sourceObject?: any): (cb: IMapCallback) => void; public map(m: { [key: string]: IMapping }, srcKey: string | (new () => any), dstKey?: string | (new () => any), sourceObject?: any, cb?: IMapCallback): void; - public map( - mappings: { [key: string]: IMapping }, sourceKey: string | (new () => any), destinationKey?: string | (new () => any), sourceObject?: any, callback?: IMapCallback - ): any /* actually, void (impossible with overloads) */ { + public map(mappings: { [key: string]: IMapping }, + sourceKey: string | (new () => any), + destinationKey?: string | (new () => any), + sourceObject?: any, + callback?: IMapCallback): any /* actually, void (impossible with overloads) */ { switch (arguments.length) { case 5: @@ -193,5 +200,7 @@ module AutoMapperJs { callback(func(opts)); } + + } -} \ No newline at end of file +} diff --git a/src/ts/AutoMapper.ts b/src/ts/AutoMapper.ts index 82d7cdd..c672191 100644 --- a/src/ts/AutoMapper.ts +++ b/src/ts/AutoMapper.ts @@ -34,7 +34,7 @@ module AutoMapperJs { } /** - * This class is intended to be a Singleton. Preferrably use getInstance() + * This class is intended to be a Singleton. Preferrably use getInstance() * function instead of using the constructor directly from code. */ constructor() { @@ -60,7 +60,7 @@ module AutoMapperJs { var that = this; var configuration: IConfiguration = { - addProfile: (profile: IProfile) : void => { + addProfile: (profile: IProfile): void => { profile.configure(); that._profiles[profile.profileName] = profile; }, @@ -139,14 +139,14 @@ module AutoMapperJs { /** * Validates mapping configuration by dry-running. Since JS does not fully support typing, it only checks if properties match on both * sides. The function needs IMapping.sourceTypeClass and IMapping.destinationTypeClass to function. - * @param {boolean} strictMode Whether or not to fail when properties sourceTypeClass or destinationTypeClass are unavailable. + * @param {boolean} strictMode Whether or not to fail when properties sourceTypeClass or destinationTypeClass are unavailable. */ public assertConfigurationIsValid(strictMode: boolean = true): void { AutoMapperValidator.assertConfigurationIsValid(this._mappings, strictMode); } private createMapForMember(parameters: ICreateMapParameters): IFluentFunc { - var { mapping, destinationProperty, conversionValueOrFunction, sourceMapping, fluentFunctions } = parameters; + var {mapping, destinationProperty, conversionValueOrFunction, sourceMapping, fluentFunctions} = parameters; var metadata = AutoMapperHelper.getMappingMetadataFromConfigFunction(destinationProperty, conversionValueOrFunction, sourceMapping); @@ -187,7 +187,7 @@ module AutoMapperJs { return; } - var { mapping, root } = property.metadata; + var {mapping, root} = property.metadata; var sourceNameParts = metadata.source.split('.'); if (sourceNameParts.length === property.level) { @@ -263,7 +263,7 @@ module AutoMapperJs { } private getOrCreateProperty(parameters: IGetOrCreatePropertyParameters): IProperty { - var { propertyNameParts, mapping, parent, propertyArray, destination, sourceMapping } = parameters; + var {propertyNameParts, mapping, parent, propertyArray, destination, sourceMapping} = parameters; var name = propertyNameParts[0]; @@ -284,7 +284,7 @@ module AutoMapperJs { } if (!property.children) { - property.children = []; + property.children = []; } // nested call @@ -324,14 +324,14 @@ module AutoMapperJs { }); if (destinationTargetArray.length > 0) { - property.metadata.root.metadata.destinations[destination] = { source: property, destination: dstProp }; + property.metadata.root.metadata.destinations[destination] = {source: property, destination: dstProp}; property.metadata.root.metadata.destinationCount++; property.destinations = destinationTargetArray; } } private createProperty(parameters: ICreatePropertyParameters): IProperty { - var { name, parent, propertyArray, sourceMapping, mapping } = parameters; + var {name, parent, propertyArray, sourceMapping, mapping} = parameters; var property: IProperty = { name: name, @@ -592,7 +592,7 @@ module AutoMapperJs { private createMapGetFluentApiFunctions(mapping: IMapping): IFluentFunc { // create a fluent interface / method chaining (e.g. automapper.createMap().forMember().forMember() ...) var fluentFunc: IFluentFunc = { - forMember: (prop: string, valFunc: forMemberValueOrFunction) : IFluentFunc => + forMember: (prop: string, valFunc: forMemberValueOrFunction): IFluentFunc => this.createMapForMember({ mapping: mapping, fluentFunctions: fluentFunc, @@ -600,15 +600,15 @@ module AutoMapperJs { conversionValueOrFunction: valFunc, sourceMapping: false }), - forSourceMember: (prop: string, cfgFunc: ((opts: ISMCO) => any) | ((opts: ISMCO, cb: IMC) => void)) : IFluentFunc => + forSourceMember: (prop: string, cfgFunc: ((opts: ISMCO) => any) | ((opts: ISMCO, cb: IMC) => void)): IFluentFunc => this.createMapForSourceMember(mapping, fluentFunc, prop, cfgFunc), - forAllMembers: (func: (dstObj: any, dstProp: string, value: any) => void) : IFluentFunc => + forAllMembers: (func: (dstObj: any, dstProp: string, value: any) => void): IFluentFunc => this.createMapForAllMembers(mapping, fluentFunc, func), - ignoreAllNonExisting: () : IFluentFunc => this.createMapIgnoreAllNonExisting(mapping, fluentFunc), - convertToType: (type: new () => any) : IFluentFunc => this.createMapConvertToType(mapping, fluentFunc, type), - convertUsing: (tcClassOrFunc: convertUsingClassOrInstanceOrFunction) : void => + ignoreAllNonExisting: (): IFluentFunc => this.createMapIgnoreAllNonExisting(mapping, fluentFunc), + convertToType: (type: new () => any): IFluentFunc => this.createMapConvertToType(mapping, fluentFunc, type), + convertUsing: (tcClassOrFunc: convertUsingClassOrInstanceOrFunction): void => this.createMapConvertUsing(mapping, tcClassOrFunc), - withProfile: (profile: string) : void => this.createMapWithProfile(mapping, profile) + withProfile: (profile: string): void => this.createMapWithProfile(mapping, profile) }; return fluentFunc; diff --git a/src/ts/AutoMapperBase.ts b/src/ts/AutoMapperBase.ts index 1ecffba..259d917 100644 --- a/src/ts/AutoMapperBase.ts +++ b/src/ts/AutoMapperBase.ts @@ -14,7 +14,12 @@ module AutoMapperJs { * AutoMapper implementation, for both creating maps and performing maps. Comparable usage and functionality to the original * .NET AutoMapper library is the pursuit of this implementation. */ - export class AutoMapperBase { + export abstract class AutoMapperBase { + + public abstract map(sourceKeyOrType: any, destinationKeyOrType: any, sourceObject: any): any + + public abstract createMap(sourceKeyOrType: string | (new() => any), destinationKeyOrType: string | (new() => any)): any; + protected getMapping(mappings: { [key: string]: IMapping }, sourceKey: stringOrClass, destinationKey: stringOrClass): IMapping { let srcKey = this.getKey(sourceKey); let dstKey = this.getKey(destinationKey); @@ -76,7 +81,7 @@ module AutoMapperJs { // unsourced properties for (let property of mapping.properties) { if (sourceProperties.indexOf(property.name) >= 0) { - continue; + continue; } atLeastOnePropertyMapped = true; @@ -95,11 +100,9 @@ module AutoMapperJs { sourceObject: any, sourcePropertyName: string, destinationObject: any, - loopMemberValuesAndFunctions: ( - destinations: IProperty[], + loopMemberValuesAndFunctions: (destinations: IProperty[], conversionValuesAndFunctions: Array, - opts: IMemberConfigurationOptions - ) => void, + opts: IMemberConfigurationOptions) => void, autoMappingCallbackFunction?: (dstPropVal: any) => void): void { var propertyMapping: IProperty = this.getMappingProperty(mapping.properties, sourcePropertyName); if (propertyMapping) { @@ -128,6 +131,7 @@ module AutoMapperJs { destinationObject[destinationProperty] = destinationPropertyValue; } } + protected createDestinationObject(destinationType: new () => any): any { // create empty destination object. return destinationType @@ -135,7 +139,7 @@ module AutoMapperJs { : {}; } - private handleNestedForAllMemberMappings(destinationObject: any, + private handleNestedForAllMemberMappings(destinationObject: any, destinationProperty: IProperty, destinationPropertyValue: any, forAllMemberMapping: (destinationObject: any, destinationPropertyName: string, value: any) => void): void { @@ -212,70 +216,106 @@ module AutoMapperJs { return; } + if (mapping.destinationTypeClass && Object.keys(destinationObject).indexOf(sourcePropertyName) < 0) { + return; + } + + let objectValue: any = null; + let isNestedObject = false; + + if (typeof destinationObject[sourcePropertyName] === 'object' && destinationObject[sourcePropertyName]) { + isNestedObject = (destinationObject[sourcePropertyName].constructor.name !== 'Object'); + + if (isNestedObject) { + this + .createMap(sourceObject[sourcePropertyName].constructor.name, destinationObject[sourcePropertyName].constructor.name) + .convertToType(destinationObject[sourcePropertyName].constructor); + + objectValue = this.map( + sourceObject[sourcePropertyName].constructor.name, + destinationObject[sourcePropertyName].constructor.name, + sourceObject[sourcePropertyName] + ); + } + } + // use profile mapping when specified; otherwise, specify source property name as destination property name. let destinationPropertyName = this.getDestinationPropertyName(mapping.profile, sourcePropertyName); - var destinationPropertyValue = sourceObject ? sourceObject[sourcePropertyName] : null; + var destinationPropertyValue = this.getDestinationPropertyValue(sourceObject, sourcePropertyName, objectValue, isNestedObject); this.setPropertyValueByName(mapping, destinationObject, destinationPropertyName, destinationPropertyValue); if (autoMappingCallbackFunction) { autoMappingCallbackFunction(destinationPropertyValue); } } - private handlePropertyWithPropertyMapping( - mapping: IMapping, - propertyMapping: IProperty, - sourceObject: any, - sourcePropertyName: string, - loopMemberValuesAndFunctions: (destinations: IProperty[], conversionValuesAndFunctions: Array, opts: IMemberConfigurationOptions) => void): void { - // a forMember mapping exists - - var { - ignore, - conditionFunction, - children, - destinations, - conversionValuesAndFunctions - } = propertyMapping; - - if (children) { - var childSourceObject = sourceObject[propertyMapping.name]; - for (let index = 0; index < children.length; index++) { - let child = children[index]; - this.handlePropertyWithPropertyMapping(mapping, child, childSourceObject, child.name, loopMemberValuesAndFunctions); - } - } + private getDestinationPropertyValue(sourceObject: any, + sourcePropertyName: string, + objectValue: any, + isNestedObject: boolean): any { + if (isNestedObject) { + return objectValue; + } - // ignore ignored properties - if (ignore) { - return; - } + return sourceObject ? sourceObject[sourcePropertyName] : null; - // check for condition function - if (conditionFunction) { - // and, if there, return when the condition is not met. - if (conditionFunction(sourceObject) === false) { - return; - } + } + + private handlePropertyWithPropertyMapping(mapping: IMapping, + propertyMapping: IProperty, + sourceObject: any, + sourcePropertyName: string, + loopMemberValuesAndFunctions: (destinations: IProperty[], + conversionValuesAndFunctions: Array, + opts: IMemberConfigurationOptions) => void): void { + // a forMember mapping exists + + var { + ignore, + conditionFunction, + children, + destinations, + conversionValuesAndFunctions + } = propertyMapping; + + if (children) { + var childSourceObject = sourceObject[propertyMapping.name]; + for (let index = 0; index < children.length; index++) { + let child = children[index]; + this.handlePropertyWithPropertyMapping(mapping, child, childSourceObject, child.name, loopMemberValuesAndFunctions); } + } - // it makes no sense to handle a property without destination(s). - if (!destinations) { + // ignore ignored properties + if (ignore) { + return; + } + + // check for condition function + if (conditionFunction) { + // and, if there, return when the condition is not met. + if (conditionFunction(sourceObject) === false) { return; } + } + + // it makes no sense to handle a property without destination(s). + if (!destinations) { + return; + } - var memberConfigurationOptions: IMemberConfigurationOptions = { - mapFrom: (): void => {//sourceMemberKey: string) { - // no action required, just here as a stub to prevent calling a non-existing 'opts.mapFrom()' function. - }, - condition: (predicate: ((sourceObject: any) => boolean)): void => { - // no action required, just here as a stub to prevent calling a non-existing 'opts.mapFrom()' function. - }, - sourceObject: sourceObject, - sourcePropertyName: sourcePropertyName, - intermediatePropertyValue: sourceObject ? sourceObject[sourcePropertyName] : sourceObject - }; - - loopMemberValuesAndFunctions(destinations, conversionValuesAndFunctions, memberConfigurationOptions); + var memberConfigurationOptions: IMemberConfigurationOptions = { + mapFrom: (): void => {//sourceMemberKey: string) { + // no action required, just here as a stub to prevent calling a non-existing 'opts.mapFrom()' function. + }, + condition: (predicate: ((sourceObject: any) => boolean)): void => { + // no action required, just here as a stub to prevent calling a non-existing 'opts.mapFrom()' function. + }, + sourceObject: sourceObject, + sourcePropertyName: sourcePropertyName, + intermediatePropertyValue: sourceObject ? sourceObject[sourcePropertyName] : sourceObject + }; + + loopMemberValuesAndFunctions(destinations, conversionValuesAndFunctions, memberConfigurationOptions); } private getDestinationPropertyName(profile: IProfile, sourcePropertyName: string): string { @@ -303,4 +343,4 @@ module AutoMapperJs { } } } -} \ No newline at end of file +} diff --git a/test/tests/js/automapper-createmap-specs.js b/test/tests/js/automapper-createmap-specs.js index 18d43f8..e6528d8 100644 --- a/test/tests/js/automapper-createmap-specs.js +++ b/test/tests/js/automapper-createmap-specs.js @@ -103,8 +103,12 @@ var AutoMapperJs; var toKey = '{2BDE907C-1CE6-4CC5-A601-9A94CC665837}'; automapper .createMap(fromKey, toKey) - .forMember('prop1', function (opts) { opts.mapFrom('prop2'); }) - .forMember('prop1', function (opts) { opts.ignore(); }); + .forMember('prop1', function (opts) { + opts.mapFrom('prop2'); + }) + .forMember('prop1', function (opts) { + opts.ignore(); + }); // act var objB = automapper.map(fromKey, toKey, objA); // assert @@ -117,7 +121,9 @@ var AutoMapperJs; var toKey = '{2A6714C4-784E-47D3-BBF4-6205834EC8D5}'; automapper .createMap(fromKey, toKey) - .forSourceMember('prop1', function (opts) { opts.ignore(); }); + .forSourceMember('prop1', function (opts) { + opts.ignore(); + }); // act var objB = automapper.map(fromKey, toKey, objA); // assert @@ -130,7 +136,9 @@ var AutoMapperJs; var toKey = '{2A6714C4-784E-47D3-BBF4-6205834EC8D5}'; automapper .createMap(fromKey, toKey) - .forSourceMember('prop1', function (opts) { return 'Yeah!'; }); + .forSourceMember('prop1', function (opts) { + return 'Yeah!'; + }); // act var objB = automapper.map(fromKey, toKey, objA); // assert @@ -144,7 +152,9 @@ var AutoMapperJs; automapper .createMap(fromKey, toKey) .forMember('prop1', 12) - .forSourceMember('prop1', function (opts) { opts.ignore(); }); + .forSourceMember('prop1', function (opts) { + opts.ignore(); + }); // act var objB = automapper.map(fromKey, toKey, objA); // assert @@ -178,7 +188,9 @@ var AutoMapperJs; var toKey = '{2BDE907C-1CE6-4CC5-A601-9A94CC665837}'; automapper .createMap(fromKey, toKey) - .forMember('prop', function (opts) { opts.mapFrom('prop2'); }); + .forMember('prop', function (opts) { + opts.mapFrom('prop2'); + }); // act var objB = automapper.map(fromKey, toKey, objA); // assert @@ -223,7 +235,9 @@ var AutoMapperJs; var constantResult = 3; automapper .createMap(fromKey, toKey) - .forMember('prop', function () { return constantResult; }); + .forMember('prop', function () { + return constantResult; + }); // act var objB = automapper.map(fromKey, toKey, objA); // assert @@ -236,7 +250,9 @@ var AutoMapperJs; var toKey = '{2D7FDB88-97E9-45EF-A111-C9CC9C188227}'; automapper .createMap(fromKey, toKey) - .forMember('prop', function (opts) { return opts.sourceObject[opts.sourcePropertyName].subProp.value * 2; }); + .forMember('prop', function (opts) { + return opts.sourceObject[opts.sourcePropertyName].subProp.value * 2; + }); // act var objB = automapper.map(fromKey, toKey, objA); // assert @@ -249,7 +265,9 @@ var AutoMapperJs; var toKey = '{18192391-85FF-4729-9A08-5954FCFE3954}'; automapper .createMap(fromKey, toKey) - .forMember('prop', function (opts) { opts.ignore(); }); + .forMember('prop', function (opts) { + opts.ignore(); + }); // act var objB = automapper.map(fromKey, toKey, objA); // assert @@ -262,7 +280,9 @@ var AutoMapperJs; var toKey = '{03B05E43-3028-44FD-909F-652E2DA5E607}'; automapper .createMap(fromKey, toKey) - .forMember('prop', function (opts) { opts.mapFrom('propDiff'); }); + .forMember('prop', function (opts) { + opts.mapFrom('propDiff'); + }); // act var objB = automapper.map(fromKey, toKey, objA); // assert @@ -276,8 +296,12 @@ var AutoMapperJs; var toKey = '{F9F45923-2D13-4EF1-9685-4883AD1D2F98}'; automapper .createMap(fromKey, toKey) - .forMember('birthday', function (opts) { opts.mapFrom('birthdayString'); }) - .forMember('birthday', function (opts) { return new Date(opts.intermediatePropertyValue); }); + .forMember('birthday', function (opts) { + opts.mapFrom('birthdayString'); + }) + .forMember('birthday', function (opts) { + return new Date(opts.intermediatePropertyValue); + }); // act var objB = automapper.map(fromKey, toKey, objA); // assert @@ -292,8 +316,12 @@ var AutoMapperJs; var toKey = '{47AF7D2D-A848-4C5B-904F-39402E2DCDD5}'; automapper .createMap(fromKey, toKey) - .forMember('birthday', function (opts) { return new Date(opts.intermediatePropertyValue); }) - .forMember('birthday', function (opts) { opts.mapFrom('birthdayString'); }); + .forMember('birthday', function (opts) { + return new Date(opts.intermediatePropertyValue); + }) + .forMember('birthday', function (opts) { + opts.mapFrom('birthdayString'); + }); // act var objB = automapper.map(fromKey, toKey, objA); // assert @@ -408,7 +436,9 @@ var AutoMapperJs; var toKey = '{2BDE907C-1CE6-4CC5-A601-9A94CA6C4737}'; automapper .createMap(fromKey, toKey) - .forMember('property', function (opts) { opts.mapFrom('ApiProperty'); }) + .forMember('property', function (opts) { + opts.mapFrom('ApiProperty'); + }) .convertToType(DemoToBusinessType); // act var objB = automapper.map(fromKey, toKey, objA); @@ -423,8 +453,12 @@ var AutoMapperJs; var toKey = '{18192191-85FE-4729-A980-5954FCFE3954}'; automapper .createMap(fromKey, toKey) - .forMember('prop', function (opts) { opts.condition(function (sourceObject) { return sourceObject.prop === 0; }); }) - .forMember('prop2', function (opts) { opts.condition(function (sourceObject) { return sourceObject.prop2 === 2; }); }); + .forMember('prop', function (opts) { + opts.condition(function (sourceObject) { return sourceObject.prop === 0; }); + }) + .forMember('prop2', function (opts) { + opts.condition(function (sourceObject) { return sourceObject.prop2 === 2; }); + }); // act var objB = automapper.map(fromKey, toKey, objA); // assert @@ -454,7 +488,7 @@ var AutoMapperJs; // arrange var objA = new ClassA(); objA.propA = 'Value'; - // act + // act automapper.createMap(ClassA, ClassB); var objB = automapper.map(ClassA, ClassB, objA); // assert @@ -487,7 +521,9 @@ var AutoMapperJs; var toKey = '{2BDE907C-1CE6-4CC5-A601-9A94CC665837}'; automapper .createMap(fromKey, toKey) - .forMember('propFromNestedSource', function (opts) { opts.mapFrom('prop1.propProp1'); }); + .forMember('propFromNestedSource', function (opts) { + opts.mapFrom('prop1.propProp1'); + }); // act var objB = automapper.map(fromKey, toKey, objA); // assert @@ -501,8 +537,12 @@ var AutoMapperJs; var toKey = '{2BDE907C-1CE6-4CC5-56A1-9A94CC6658C7}'; automapper .createMap(fromKey, toKey) - .forMember('propFromNestedSource', function (opts) { opts.mapFrom('prop1.propProp1'); }) - .forMember('propFromNestedSource', function (opts) { return opts.intermediatePropertyValue + addition; }); + .forMember('propFromNestedSource', function (opts) { + opts.mapFrom('prop1.propProp1'); + }) + .forMember('propFromNestedSource', function (opts) { + return opts.intermediatePropertyValue + addition; + }); // act var objB = automapper.map(fromKey, toKey, objA); // assert @@ -516,8 +556,12 @@ var AutoMapperJs; var toKey = '{BBD6907C-ACE6-4FC8-A60D-1A943C66D83F}'; automapper .createMap(fromKey, toKey) - .forMember('propFromNestedSource', function (opts) { return opts.intermediatePropertyValue + addition; }) - .forMember('propFromNestedSource', function (opts) { opts.mapFrom('prop1.propProp1'); }); + .forMember('propFromNestedSource', function (opts) { + return opts.intermediatePropertyValue + addition; + }) + .forMember('propFromNestedSource', function (opts) { + opts.mapFrom('prop1.propProp1'); + }); // act var objB = automapper.map(fromKey, toKey, objA); // assert @@ -531,9 +575,15 @@ var AutoMapperJs; var toKey = '{BBD6907C-ACE6-4FC8-A60D-1A943C66D83F}'; automapper .createMap(fromKey, toKey) - .forMember('propFromNestedSource', function (opts) { return opts.intermediatePropertyValue + addition; }) - .forMember('propFromNestedSource', function (opts) { opts.mapFrom('prop1.propProp2.propProp2Prop'); }) - .forMember('propFromNestedSource', function (opts) { opts.mapFrom('prop1.propProp1'); }); + .forMember('propFromNestedSource', function (opts) { + return opts.intermediatePropertyValue + addition; + }) + .forMember('propFromNestedSource', function (opts) { + opts.mapFrom('prop1.propProp2.propProp2Prop'); + }) + .forMember('propFromNestedSource', function (opts) { + opts.mapFrom('prop1.propProp1'); + }); // act var objB = automapper.map(fromKey, toKey, objA); // assert @@ -547,9 +597,15 @@ var AutoMapperJs; var toKey = '{BBD6907C-ACE6-4FC8-A60D-1A943C66D83F}'; automapper .createMap(fromKey, toKey) - .forMember('nested.property', function (opts) { return opts.intermediatePropertyValue + addition; }) - .forMember('nested.property', function (opts) { opts.mapFrom('prop1.propProp2.propProp2Prop'); }) - .forMember('nested.property', function (opts) { opts.mapFrom('prop1.propProp1'); }); + .forMember('nested.property', function (opts) { + return opts.intermediatePropertyValue + addition; + }) + .forMember('nested.property', function (opts) { + opts.mapFrom('prop1.propProp2.propProp2Prop'); + }) + .forMember('nested.property', function (opts) { + opts.mapFrom('prop1.propProp1'); + }); // act var objB = automapper.map(fromKey, toKey, objA); // assert @@ -563,9 +619,15 @@ var AutoMapperJs; // act automapper .createMap(fromKey, toKey) - .forMember('prop1', function (opts) { opts.mapFrom('prop2'); }) - .forMember('prop2', function (opts) { opts.mapFrom('prop1'); }) - .forSourceMember('prop3', function (opts) { opts.ignore(); }); + .forMember('prop1', function (opts) { + opts.mapFrom('prop2'); + }) + .forMember('prop2', function (opts) { + opts.mapFrom('prop1'); + }) + .forSourceMember('prop3', function (opts) { + opts.ignore(); + }); var objB = automapper.map(fromKey, toKey, objA); // assert expect(objB).toEqualData({ prop1: objA.prop2, prop2: objA.prop1 }); @@ -578,7 +640,9 @@ var AutoMapperJs; // act automapper .createMap(fromKey, toKey) - .forMember('prop4', function (opts) { return 12; }); + .forMember('prop4', function (opts) { + return 12; + }); var objB = automapper.map(fromKey, toKey, objA); // assert expect(objB).toEqualData({ prop4: 12 }); @@ -603,7 +667,9 @@ var AutoMapperJs; // act automapper .createMap(fromKey, toKey) - .forMember('prop4', function (opts) { return 12; }); + .forMember('prop4', function (opts) { + return 12; + }); var objB = automapper.map(fromKey, toKey, objA); // assert expect(objB).toEqualData({ prop4: 12 }); @@ -613,15 +679,15 @@ var AutoMapperJs; // arrange var src = { homeAddress: null /*{ - address1: '200 Main St', - address2: '200 Main St', - city: 'Los Angeles', - state: 'CA', - zip: '90000' - }*/, + address1: '200 Main St', + address2: '200 Main St', + city: 'Los Angeles', + state: 'CA', + zip: '90000' + }*/, businessAddress: { address1: '200 Main St', - // address2: '200 Main St', + // address2: '200 Main St', city: 'Los Angeles', state: 'CA', zip: '90000' @@ -631,12 +697,22 @@ var AutoMapperJs; var toKey = '{AC6D5A97-9AEF-42C7-BD60-A5F3D17E541A}'; automapper .createMap(fromKey, toKey) - .forMember('homeAddress.address2', function (opts) { opts.mapFrom('homeAddress.address2'); }) - .forMember('businessAddress.address1', function (opts) { opts.mapFrom('businessAddress.address1'); }) + .forMember('homeAddress.address2', function (opts) { + opts.mapFrom('homeAddress.address2'); + }) + .forMember('businessAddress.address1', function (opts) { + opts.mapFrom('businessAddress.address1'); + }) .forMember('businessAddress.address2', function (opts) { return null; }) - .forMember('businessAddress.city', function (opts) { opts.mapFrom('businessAddress.city'); }) - .forMember('businessAddress.state', function (opts) { opts.mapFrom('businessAddress.state'); }) - .forMember('businessAddress.zip', function (opts) { opts.mapFrom('businessAddress.zip'); }); + .forMember('businessAddress.city', function (opts) { + opts.mapFrom('businessAddress.city'); + }) + .forMember('businessAddress.state', function (opts) { + opts.mapFrom('businessAddress.state'); + }) + .forMember('businessAddress.zip', function (opts) { + opts.mapFrom('businessAddress.zip'); + }); // act var dst = automapper.map(fromKey, toKey, src); // assert @@ -652,7 +728,7 @@ var AutoMapperJs; // // arrange // var src: any = { // businessAddress: { - // address1: '200 Main St', + // address1: '200 Main St', // city: 'Los Angeles', // state: 'CA', // zip: '90000' @@ -662,8 +738,8 @@ var AutoMapperJs; // var toKey = '{AC6D5A97-9AEF-42C7-BD60-A5F3D17E541A}'; // automapper // .createMap(fromKey, toKey) - // .forMember('businessAddress.address2', (opts: IMemberConfigurationOptions) => null); - // // the forMember call currently fails the test. Automapping on nested properties is currently + // .forMember('businessAddress.address2', (opts: IMemberConfigurationOptions) => null); + // // the forMember call currently fails the test. Automapping on nested properties is currently // // not implemented when a forMember call is present! Should work somewhat like the handleItem // // function at 'root level'. // // act @@ -679,16 +755,20 @@ var AutoMapperJs; // }); var ClassA = (function () { function ClassA() { + this.propA = null; } return ClassA; }()); var ClassB = (function () { function ClassB() { + this.propA = null; } return ClassB; }()); + //Initialization of property necessary to force Javascript create this property on class var ClassC = (function () { function ClassC() { + this.propA = null; } return ClassC; }()); diff --git a/test/tests/js/automapper-initialize-specs.js b/test/tests/js/automapper-initialize-specs.js index a0d113d..98427cf 100644 --- a/test/tests/js/automapper-initialize-specs.js +++ b/test/tests/js/automapper-initialize-specs.js @@ -36,6 +36,14 @@ var AutoMapperJs; }; return CamelCaseToPascalCaseMappingProfile; }(AutoMapperJs.Profile)); + // class ComplexObjectToSimpleObject extends Profile { + // public profileName = 'ComplexObjectToSimpleObject'; + // + // public configure() { + // alert('Complex configuration'); + // super.createMap('complex', 'simple'); + // } + // } var ValidatedAgeMappingProfile = (function (_super) { __extends(ValidatedAgeMappingProfile, _super); function ValidatedAgeMappingProfile() { @@ -70,6 +78,8 @@ var AutoMapperJs; }(AutoMapperJs.Profile)); var Person = (function () { function Person() { + this.fullName = null; + this.age = null; } return Person; }()); @@ -204,7 +214,9 @@ var AutoMapperJs; automapper.initialize(function (config) { mapFromKeyCurry = config.createMap(fromKey); mapFromKeyCurry(toKey1) - .forSourceMember('prop', function (opts) { opts.ignore(); }); + .forSourceMember('prop', function (opts) { + opts.ignore(); + }); mapFromKeyCurry(toKey2); }); var result1 = automapper.map(fromKey, toKey1, source); @@ -214,5 +226,20 @@ var AutoMapperJs; expect(result1.prop).toBeUndefined(); expect(result2.prop).toEqual(source.prop); }); + // it('should be able to convert Complex Objects to Simple Objects', ()=> { + // automapper.initialize((config: IConfiguration) => { + // config.addProfile(new ComplexObjectToSimpleObject()); + // }); + // + // const sourceKey = '{74d523ee-8dbb-4e72-bdf1-db8fa3b27d07}'; + // const destinationKey = '{cf7bbaa0-14f9-400d-a59a-65313651db6b}'; + // + // automapper + // .createMap(sourceKey, destinationKey) + // .withProfile('ValidatedAgeMappingProfile'); + // + // + // + // }); }); })(AutoMapperJs || (AutoMapperJs = {})); diff --git a/test/tests/js/automapper-map-specs.js b/test/tests/js/automapper-map-specs.js index 178c906..6258d2c 100644 --- a/test/tests/js/automapper-map-specs.js +++ b/test/tests/js/automapper-map-specs.js @@ -44,5 +44,60 @@ var AutoMapperJs; // assert expect(arrB).toEqualData(arrA); }); + it('should ignore properties on source object missing on destination object type Definition', function () { + // arrange + var DestinationType = (function () { + function DestinationType() { + this.keep = null; + } + return DestinationType; + }()); + var fromObject = { + keep: true, + remove: true + }; + var fromKey = '{60D9DB56-D6E1-48FF-9BAC-0805FCAF91B7}'; + var toKey = '{AC6D5B97-9AE3-4267-BD60-A5FED17E541A}'; + automapper.createMap(fromKey, toKey).convertToType(DestinationType); + // act + var toObject = automapper.map(fromKey, toKey, fromObject); + // assert + expect(toObject).toBeDefined(); + expect(toObject.remove).not.toBeDefined(); + }); + it('should ignore properties on source object missing on destination object type Definition for nested objects too', function () { + // arrange + var DestinationType = (function () { + function DestinationType() { + this.keep = null; + this.nested = new NestedDestinationType; + } + return DestinationType; + }()); + var NestedDestinationType = (function () { + function NestedDestinationType() { + this.keep = null; + } + return NestedDestinationType; + }()); + var fromObject = { + keep: true, + remove: true, + nested: { + keep: true, + remove: false + } + }; + var fromKey = '{2dc59bc0-40d2-4d68-87ae-d1f2953dcb4c}'; + var toKey = '{0bf8ffd0-c003-4b76-bbcf-83a40b0d1cad}'; + automapper.createMap(fromKey, toKey).convertToType(DestinationType); + // act + var toObject = automapper.map(fromKey, toKey, fromObject); + // assert + expect(toObject).toBeDefined(); + expect(toObject.remove).not.toBeDefined(); + expect(toObject.nested.keep).toBeDefined(); + expect(toObject.nested.remove).not.toBeDefined(); + }); }); })(AutoMapperJs || (AutoMapperJs = {})); diff --git a/test/tests/ts/automapper-createmap-specs.ts b/test/tests/ts/automapper-createmap-specs.ts index efd0938..9761310 100644 --- a/test/tests/ts/automapper-createmap-specs.ts +++ b/test/tests/ts/automapper-createmap-specs.ts @@ -79,17 +79,17 @@ module AutoMapperJs { var fromKey = '{5700E351-8D88-4327-A216-3CCBHJ808EDF}'; var toKey = '{BB33A261-3CA9-48FC-85E6-2C269FDFT28D}'; - var source = { prop1: 'prop1', prop2: 'prop2' }; + var source = {prop1: 'prop1', prop2: 'prop2'}; var suffix = ' [forAllMembers]'; automapper.createMap(fromKey, toKey) - .forMember('prop1', (opts: IMemberConfigurationOptions): any => opts.intermediatePropertyValue) - .forMember('prop2', (opts: IMemberConfigurationOptions): any => opts.intermediatePropertyValue) - .forAllMembers((destinationObject: any, - destinationPropertyName: string, - value: any): void => { - destinationObject[destinationPropertyName] = value + suffix; - }); + .forMember('prop1', (opts: IMemberConfigurationOptions): any => opts.intermediatePropertyValue) + .forMember('prop2', (opts: IMemberConfigurationOptions): any => opts.intermediatePropertyValue) + .forAllMembers((destinationObject: any, + destinationPropertyName: string, + value: any): void => { + destinationObject[destinationPropertyName] = value + suffix; + }); // act var destination = automapper.map(fromKey, toKey, source); @@ -104,15 +104,15 @@ module AutoMapperJs { var fromKey = '{5700E351-8D88-4327-A216-3CCBHJ808EDF}'; var toKey = '{BB33A261-3CA9-48FC-85E6-2C269FDFT28D}'; - var source = { prop1: 'prop1', prop2: 'prop2' }; + var source = {prop1: 'prop1', prop2: 'prop2'}; var suffix = ' [forAllMembers]'; automapper.createMap(fromKey, toKey) - .forAllMembers((destinationObject: any, - destinationPropertyName: string, - value: any): void => { - destinationObject[destinationPropertyName] = value + suffix; - }); + .forAllMembers((destinationObject: any, + destinationPropertyName: string, + value: any): void => { + destinationObject[destinationPropertyName] = value + suffix; + }); // act var destination = automapper.map(fromKey, toKey, source); @@ -124,62 +124,70 @@ module AutoMapperJs { it('should accept multiple forMember calls for the same destination property and overwrite with the last one specified', () => { //arrange - var objA = { prop1: 'From A', prop2: 'From A too' }; + var objA = {prop1: 'From A', prop2: 'From A too'}; var fromKey = '{7AC4134B-ECC1-464B-B144-5B9D8F5B568E}'; var toKey = '{2BDE907C-1CE6-4CC5-A601-9A94CC665837}'; automapper .createMap(fromKey, toKey) - .forMember('prop1', (opts: IMemberConfigurationOptions) => { opts.mapFrom('prop2'); }) - .forMember('prop1', (opts: IMemberConfigurationOptions) => { opts.ignore(); }); + .forMember('prop1', (opts: IMemberConfigurationOptions) => { + opts.mapFrom('prop2'); + }) + .forMember('prop1', (opts: IMemberConfigurationOptions) => { + opts.ignore(); + }); // act var objB = automapper.map(fromKey, toKey, objA); // assert - expect(objB).toEqualData({ prop2: objA.prop2 }); + expect(objB).toEqualData({prop2: objA.prop2}); }); it('should be able to ignore a source property using the forSourceMember function', () => { // arrange - var objA = { prop1: 'From A', prop2: 'From A too' }; + var objA = {prop1: 'From A', prop2: 'From A too'}; var fromKey = '{AD88481E-597B-4C1B-967B-3D700B8BAB0F}'; var toKey = '{2A6714C4-784E-47D3-BBF4-6205834EC8D5}'; automapper .createMap(fromKey, toKey) - .forSourceMember('prop1', (opts: ISourceMemberConfigurationOptions) => { opts.ignore(); }); + .forSourceMember('prop1', (opts: ISourceMemberConfigurationOptions) => { + opts.ignore(); + }); // act var objB = automapper.map(fromKey, toKey, objA); // assert - expect(objB).toEqualData({ prop2: 'From A too' }); + expect(objB).toEqualData({prop2: 'From A too'}); }); it('should be able to custom map a source property using the forSourceMember function', () => { // arrange - var objA = { prop1: 'From A', prop2: 'From A too' }; + var objA = {prop1: 'From A', prop2: 'From A too'}; var fromKey = '{AD88481E-597B-4C1B-967B-3D700B8BAB0F}'; var toKey = '{2A6714C4-784E-47D3-BBF4-6205834EC8D5}'; automapper .createMap(fromKey, toKey) - .forSourceMember('prop1', (opts: ISourceMemberConfigurationOptions) => { return 'Yeah!'; }); + .forSourceMember('prop1', (opts: ISourceMemberConfigurationOptions) => { + return 'Yeah!'; + }); // act var objB = automapper.map(fromKey, toKey, objA); // assert - expect(objB).toEqualData({ prop1: 'Yeah!', prop2: 'From A too' }); + expect(objB).toEqualData({prop1: 'Yeah!', prop2: 'From A too'}); }); it('should be able to ignore a source property already specified (by forMember) using the forSourceMember function', () => { // arrange - var objA = { prop1: 'From A', prop2: 'From A too' }; + var objA = {prop1: 'From A', prop2: 'From A too'}; var fromKey = '{AD88481E-597B-4C1B-967B-3D701B8CAB0A}'; var toKey = '{2A6714C4-784E-47D3-BBF4-620583DEC86A}'; @@ -187,13 +195,15 @@ module AutoMapperJs { automapper .createMap(fromKey, toKey) .forMember('prop1', 12) - .forSourceMember('prop1', (opts: ISourceMemberConfigurationOptions) => { opts.ignore(); }); + .forSourceMember('prop1', (opts: ISourceMemberConfigurationOptions) => { + opts.ignore(); + }); // act var objB = automapper.map(fromKey, toKey, objA); // assert - expect(objB).toEqualData({ prop2: 'From A too' }); + expect(objB).toEqualData({prop2: 'From A too'}); }); it('should fail when forSourceMember is used with anything else than a function', () => { @@ -222,25 +232,27 @@ module AutoMapperJs { it('should be able to use forMember to map a source property to a destination property with a different name', () => { //arrange - var objA = { prop1: 'From A', prop2: 'From A too' }; + var objA = {prop1: 'From A', prop2: 'From A too'}; var fromKey = '{7AC4134B-ECC1-464B-B144-5B9D8F5B568E}'; var toKey = '{2BDE907C-1CE6-4CC5-A601-9A94CC665837}'; automapper .createMap(fromKey, toKey) - .forMember('prop', (opts: IMemberConfigurationOptions) => { opts.mapFrom('prop2'); }); + .forMember('prop', (opts: IMemberConfigurationOptions) => { + opts.mapFrom('prop2'); + }); // act var objB = automapper.map(fromKey, toKey, objA); // assert - expect(objB).toEqualData({ prop1: objA.prop1, prop: objA.prop2 }); + expect(objB).toEqualData({prop1: objA.prop1, prop: objA.prop2}); }); it('should use forAllMembers function for each mapped destination property when specified', () => { // arrange - var objA = { prop1: 'From A', prop2: 'From A too' }; + var objA = {prop1: 'From A', prop2: 'From A too'}; var fromKey = '{C4056539-FA86-4398-A10B-C41D3A791F26}'; var toKey = '{01C64E8D-CDB5-4307-9011-0C7F1E70D115}'; @@ -263,7 +275,7 @@ module AutoMapperJs { it('should be able to use forMember with a constant value', () => { // arrange - var objA = { prop: 1 }; + var objA = {prop: 1}; var fromKey = '{54E67626-B877-4824-82E6-01E9F411B78F}'; var toKey = '{2D7FDB88-97E9-45EF-A111-C9CC9C188227}'; @@ -283,7 +295,7 @@ module AutoMapperJs { it('should be able to use forMember with a function returning a constant value', () => { // arrange - var objA = { prop: 1 }; + var objA = {prop: 1}; var fromKey = '{74C12B56-1DD1-4EA0-A640-D1F814971124}'; var toKey = '{BBC617B8-26C8-42A0-A204-45CC77073355}'; @@ -292,7 +304,9 @@ module AutoMapperJs { automapper .createMap(fromKey, toKey) - .forMember('prop', () => { return constantResult; }); + .forMember('prop', () => { + return constantResult; + }); // act var objB = automapper.map(fromKey, toKey, objA); @@ -303,14 +317,16 @@ module AutoMapperJs { it('should be able to use forMember with a function using the source object', () => { // arrange - var objA = { prop: { subProp: { value: 1 } } }; + var objA = {prop: {subProp: {value: 1}}}; var fromKey = '{54E67626-B877-4824-82E6-01E9F411B78F}'; var toKey = '{2D7FDB88-97E9-45EF-A111-C9CC9C188227}'; automapper .createMap(fromKey, toKey) - .forMember('prop', (opts: IMemberConfigurationOptions) => { return opts.sourceObject[opts.sourcePropertyName].subProp.value * 2; }); + .forMember('prop', (opts: IMemberConfigurationOptions) => { + return opts.sourceObject[opts.sourcePropertyName].subProp.value * 2; + }); // act var objB = automapper.map(fromKey, toKey, objA); @@ -321,14 +337,16 @@ module AutoMapperJs { it('should be able to use forMember to ignore a property', () => { // arrange - var objA = { prop: 1 }; + var objA = {prop: 1}; var fromKey = '{76D26B33-888A-4DF7-ABDA-E5B99E944272}'; var toKey = '{18192391-85FF-4729-9A08-5954FCFE3954}'; automapper .createMap(fromKey, toKey) - .forMember('prop', (opts: IMemberConfigurationOptions) => { opts.ignore(); }); + .forMember('prop', (opts: IMemberConfigurationOptions) => { + opts.ignore(); + }); // act var objB = automapper.map(fromKey, toKey, objA); @@ -339,14 +357,16 @@ module AutoMapperJs { it('should be able to use forMember to map a source property to a destination property with a different name', () => { // arrange - var objA = { propDiff: 1 }; + var objA = {propDiff: 1}; var fromKey = '{A317A36A-AD92-4346-A015-AE06FC862DB4}'; var toKey = '{03B05E43-3028-44FD-909F-652E2DA5E607}'; automapper .createMap(fromKey, toKey) - .forMember('prop', (opts: IMemberConfigurationOptions) => { opts.mapFrom('propDiff'); }); + .forMember('prop', (opts: IMemberConfigurationOptions) => { + opts.mapFrom('propDiff'); + }); // act var objB = automapper.map(fromKey, toKey, objA); @@ -358,15 +378,19 @@ module AutoMapperJs { it('should be able to use stack forMember calls to map a source property to a destination property using multiple mapping steps', () => { // arrange var birthdayString = '2000-01-01T00:00:00.000Z'; - var objA = { birthdayString: birthdayString }; + var objA = {birthdayString: birthdayString}; var fromKey = '{564F1F57-FD4F-413C-A9D3-4B1C1333A20B}'; var toKey = '{F9F45923-2D13-4EF1-9685-4883AD1D2F98}'; automapper .createMap(fromKey, toKey) - .forMember('birthday', (opts: IMemberConfigurationOptions) => { opts.mapFrom('birthdayString'); }) - .forMember('birthday', (opts: IMemberConfigurationOptions) => { return new Date(opts.intermediatePropertyValue); }); + .forMember('birthday', (opts: IMemberConfigurationOptions) => { + opts.mapFrom('birthdayString'); + }) + .forMember('birthday', (opts: IMemberConfigurationOptions) => { + return new Date(opts.intermediatePropertyValue); + }); // act var objB = automapper.map(fromKey, toKey, objA); @@ -379,15 +403,19 @@ module AutoMapperJs { it('should be able to use stack forMember calls to map a source property to a destination property using multiple mapping steps in any order', () => { // arrange var birthdayString = '2000-01-01T00:00:00.000Z'; - var objA = { birthdayString: birthdayString }; + var objA = {birthdayString: birthdayString}; var fromKey = '{1609A9B5-6083-448B-8FD6-51DAD106B63D}'; var toKey = '{47AF7D2D-A848-4C5B-904F-39402E2DCDD5}'; automapper .createMap(fromKey, toKey) - .forMember('birthday', (opts: IMemberConfigurationOptions) => { return new Date(opts.intermediatePropertyValue); }) - .forMember('birthday', (opts: IMemberConfigurationOptions) => { opts.mapFrom('birthdayString'); }); + .forMember('birthday', (opts: IMemberConfigurationOptions) => { + return new Date(opts.intermediatePropertyValue); + }) + .forMember('birthday', (opts: IMemberConfigurationOptions) => { + opts.mapFrom('birthdayString'); + }); // act var objB = automapper.map(fromKey, toKey, objA); @@ -415,15 +443,15 @@ module AutoMapperJs { }); it('should be able to use convertUsing to map an object with a custom type resolver function', () => { - var objA = { propA: 'propA' }; + var objA = {propA: 'propA'}; var fromKey = '{D1534A0F-6120-475E-B7E2-BF2489C58571}'; var toKey = '{1896FF99-1A28-4FE6-800B-072D5616B02D}'; automapper .createMap(fromKey, toKey) - .convertUsing(function(resolutionContext: IResolutionContext): any { - return { propA: resolutionContext.sourceValue.propA + ' (custom mapped with resolution context)' }; + .convertUsing(function (resolutionContext: IResolutionContext): any { + return {propA: resolutionContext.sourceValue.propA + ' (custom mapped with resolution context)'}; }); // act @@ -435,7 +463,7 @@ module AutoMapperJs { it('should be able to use convertUsing to map an object with a custom type resolver class', () => { // arrange - var objA = { propA: 'propA' }; + var objA = {propA: 'propA'}; var fromKey = '{6E7F5757-1E55-4B55-BB86-44FF5B33DE2F}'; var toKey = '{8521AE41-C3AF-4FCD-B7C7-A915C037D69E}'; @@ -456,7 +484,7 @@ module AutoMapperJs { // NOTE BL The CustomTypeConverter class definition is defined at the bottom, since TypeScript // does not allow classes to be defined inline. - var objA = { propA: 'propA' }; + var objA = {propA: 'propA'}; var fromKey = '{BDF3758C-B38E-4343-95B6-AE0F80C8B9C4}'; var toKey = '{13DD7AE1-4177-4A80-933B-B60A55859E50}'; @@ -475,7 +503,7 @@ module AutoMapperJs { it('should fail when directly using the type converter base class', () => { // arrange var caught = false; - var objA = { propA: 'propA' }; + var objA = {propA: 'propA'}; var fromKey = 'should fail when directly using '; var toKey = 'the type converter base class'; @@ -519,7 +547,7 @@ module AutoMapperJs { // assert caught = true; expect(e.message).toEqual('The value provided for typeConverterClassOrFunction is invalid. ' + - 'Error: The function provided does not provide exactly one (resolutionContext) parameter.'); + 'Error: The function provided does not provide exactly one (resolutionContext) parameter.'); } if (!caught) { @@ -530,7 +558,7 @@ module AutoMapperJs { it('should be able to use convertToType to map a source object to a destination object which is an instance of a given class', () => { //arrange - var objA = { ApiProperty: 'From A' }; + var objA = {ApiProperty: 'From A'}; var fromKey = '{7AC4134B-ECC1-464B-B144-5C9D8F5B5A7E}'; @@ -538,7 +566,9 @@ module AutoMapperJs { automapper .createMap(fromKey, toKey) - .forMember('property', (opts: IMemberConfigurationOptions) => { opts.mapFrom('ApiProperty'); }) + .forMember('property', (opts: IMemberConfigurationOptions) => { + opts.mapFrom('ApiProperty'); + }) .convertToType(DemoToBusinessType); // act @@ -551,15 +581,19 @@ module AutoMapperJs { it('should be able to use a condition to map or ignore a property', () => { // arrange - var objA = { prop: 1, prop2: 2 }; + var objA = {prop: 1, prop2: 2}; var fromKey = '{76D23B33-888A-4DF7-BEBE-E5B99E944272}'; var toKey = '{18192191-85FE-4729-A980-5954FCFE3954}'; automapper .createMap(fromKey, toKey) - .forMember('prop', (opts: IMemberConfigurationOptions) => { opts.condition((sourceObject: any) => sourceObject.prop === 0); }) - .forMember('prop2', (opts: IMemberConfigurationOptions) => { opts.condition((sourceObject: any) => sourceObject.prop2 === 2); }); + .forMember('prop', (opts: IMemberConfigurationOptions) => { + opts.condition((sourceObject: any) => sourceObject.prop === 0); + }) + .forMember('prop2', (opts: IMemberConfigurationOptions) => { + opts.condition((sourceObject: any) => sourceObject.prop2 === 2); + }); // act var objB = automapper.map(fromKey, toKey, objA); @@ -590,21 +624,21 @@ module AutoMapperJs { var objB = automapper.map(fromKey, toKey, objA); // assert - expect(objB).toEqualData({ propA: 'Prop A' }); + expect(objB).toEqualData({propA: 'Prop A'}); }); it('should be able to create a map and use it using class types', () => { - // arrange - var objA = new ClassA(); - objA.propA = 'Value'; + // arrange + var objA = new ClassA(); + objA.propA = 'Value'; - // act - automapper.createMap(ClassA, ClassB); - var objB = automapper.map(ClassA, ClassB, objA); + // act + automapper.createMap(ClassA, ClassB); + var objB = automapper.map(ClassA, ClassB, objA); // assert expect(objB instanceof ClassB).toBeTruthy(); - expect(objB).toEqualData({ propA: 'Value' }); + expect(objB).toEqualData({propA: 'Value'}); }); it('should throw an error when creating a map using class types and specifying a conflicting destination type', () => { @@ -630,25 +664,27 @@ module AutoMapperJs { it('should be able to use forMember to map a nested source property to a destination property', () => { //arrange - var objA = { prop1: { propProp1: 'From A' }, prop2: 'From A too' }; + var objA = {prop1: {propProp1: 'From A'}, prop2: 'From A too'}; var fromKey = '{7AC4134B-ECC1-464B-B144-5B9D8F5B568E}'; var toKey = '{2BDE907C-1CE6-4CC5-A601-9A94CC665837}'; automapper .createMap(fromKey, toKey) - .forMember('propFromNestedSource', (opts: IMemberConfigurationOptions) => { opts.mapFrom('prop1.propProp1'); }); + .forMember('propFromNestedSource', (opts: IMemberConfigurationOptions) => { + opts.mapFrom('prop1.propProp1'); + }); // act var objB = automapper.map(fromKey, toKey, objA); // assert - expect(objB).toEqualData({ prop2: objA.prop2, propFromNestedSource: objA.prop1.propProp1 }); + expect(objB).toEqualData({prop2: objA.prop2, propFromNestedSource: objA.prop1.propProp1}); }); it('should be able to stack forMember calls when mapping a nested source property to a destination property', () => { //arrange - var objA = { prop1: { propProp1: 'From A' }, prop2: 'From A too' }; + var objA = {prop1: {propProp1: 'From A'}, prop2: 'From A too'}; var addition = ' - sure works!'; var fromKey = '{7AC4134B-ECC1-464B-B144-5B99CF5B558E}'; @@ -656,19 +692,23 @@ module AutoMapperJs { automapper .createMap(fromKey, toKey) - .forMember('propFromNestedSource', (opts: IMemberConfigurationOptions) => { opts.mapFrom('prop1.propProp1'); }) - .forMember('propFromNestedSource', (opts: IMemberConfigurationOptions) => { return opts.intermediatePropertyValue + addition; }); + .forMember('propFromNestedSource', (opts: IMemberConfigurationOptions) => { + opts.mapFrom('prop1.propProp1'); + }) + .forMember('propFromNestedSource', (opts: IMemberConfigurationOptions) => { + return opts.intermediatePropertyValue + addition; + }); // act var objB = automapper.map(fromKey, toKey, objA); // assert - expect(objB).toEqualData({ prop2: objA.prop2, propFromNestedSource: objA.prop1.propProp1 + addition }); + expect(objB).toEqualData({prop2: objA.prop2, propFromNestedSource: objA.prop1.propProp1 + addition}); }); it('should be able to stack forMember calls when mapping a nested source property to a destination property in any order', () => { //arrange - var objA = { prop1: { propProp1: 'From A' }, prop2: 'From A too' }; + var objA = {prop1: {propProp1: 'From A'}, prop2: 'From A too'}; var addition = ' - sure works!'; var fromKey = '{7AC4134B-ECD1-46EB-B14A-5B9D8F5B5F8E}'; @@ -676,19 +716,23 @@ module AutoMapperJs { automapper .createMap(fromKey, toKey) - .forMember('propFromNestedSource', (opts: IMemberConfigurationOptions) => { return opts.intermediatePropertyValue + addition; }) - .forMember('propFromNestedSource', (opts: IMemberConfigurationOptions) => { opts.mapFrom('prop1.propProp1'); }); + .forMember('propFromNestedSource', (opts: IMemberConfigurationOptions) => { + return opts.intermediatePropertyValue + addition; + }) + .forMember('propFromNestedSource', (opts: IMemberConfigurationOptions) => { + opts.mapFrom('prop1.propProp1'); + }); // act var objB = automapper.map(fromKey, toKey, objA); // assert - expect(objB).toEqualData({ prop2: objA.prop2, propFromNestedSource: objA.prop1.propProp1 + addition }); + expect(objB).toEqualData({prop2: objA.prop2, propFromNestedSource: objA.prop1.propProp1 + addition}); }); it('should be able to stack forMember mapFrom calls when mapping a nested source property to a destination property', () => { //arrange - var objA = { prop1: { propProp1: 'From A', propProp2: { propProp2Prop: 'From A' } }, prop2: 'From A too' }; + var objA = {prop1: {propProp1: 'From A', propProp2: {propProp2Prop: 'From A'}}, prop2: 'From A too'}; var addition = ' - sure works!'; var fromKey = '{7AC4134B-ECD1-46EB-B14A-5B9D8F5B5F8E}'; @@ -696,20 +740,26 @@ module AutoMapperJs { automapper .createMap(fromKey, toKey) - .forMember('propFromNestedSource', (opts: IMemberConfigurationOptions) => { return opts.intermediatePropertyValue + addition; }) - .forMember('propFromNestedSource', (opts: IMemberConfigurationOptions) => { opts.mapFrom('prop1.propProp2.propProp2Prop'); }) - .forMember('propFromNestedSource', (opts: IMemberConfigurationOptions) => { opts.mapFrom('prop1.propProp1'); }); + .forMember('propFromNestedSource', (opts: IMemberConfigurationOptions) => { + return opts.intermediatePropertyValue + addition; + }) + .forMember('propFromNestedSource', (opts: IMemberConfigurationOptions) => { + opts.mapFrom('prop1.propProp2.propProp2Prop'); + }) + .forMember('propFromNestedSource', (opts: IMemberConfigurationOptions) => { + opts.mapFrom('prop1.propProp1'); + }); // act var objB = automapper.map(fromKey, toKey, objA); // assert - expect(objB).toEqualData({ prop2: objA.prop2, propFromNestedSource: objA.prop1.propProp1 + addition }); + expect(objB).toEqualData({prop2: objA.prop2, propFromNestedSource: objA.prop1.propProp1 + addition}); }); it('should be able to use forMember to map to a nested destination', () => { //arrange - var objA = { prop1: { propProp1: 'From A', propProp2: { propProp2Prop: 'From A' } }, prop2: 'From A too' }; + var objA = {prop1: {propProp1: 'From A', propProp2: {propProp2Prop: 'From A'}}, prop2: 'From A too'}; var addition = ' - sure works!'; var fromKey = '{7AC4134B-ECD1-46EB-B14A-5B9D8F5B5F8E}'; @@ -717,20 +767,26 @@ module AutoMapperJs { automapper .createMap(fromKey, toKey) - .forMember('nested.property', (opts: IMemberConfigurationOptions) => { return opts.intermediatePropertyValue + addition; }) - .forMember('nested.property', (opts: IMemberConfigurationOptions) => { opts.mapFrom('prop1.propProp2.propProp2Prop'); }) - .forMember('nested.property', (opts: IMemberConfigurationOptions) => { opts.mapFrom('prop1.propProp1'); }); + .forMember('nested.property', (opts: IMemberConfigurationOptions) => { + return opts.intermediatePropertyValue + addition; + }) + .forMember('nested.property', (opts: IMemberConfigurationOptions) => { + opts.mapFrom('prop1.propProp2.propProp2Prop'); + }) + .forMember('nested.property', (opts: IMemberConfigurationOptions) => { + opts.mapFrom('prop1.propProp1'); + }); // act var objB = automapper.map(fromKey, toKey, objA); // assert - expect(objB).toEqualData({ prop2: objA.prop2, nested: { property: objA.prop1.propProp1 + addition }}); + expect(objB).toEqualData({prop2: objA.prop2, nested: {property: objA.prop1.propProp1 + addition}}); }); it('should be able to use mapFrom to switch properties and ignore a property as well', () => { // arrange - var objA = { prop1: 'From A', prop2: 'From A too', prop3: 'Also from A (really)' }; + var objA = {prop1: 'From A', prop2: 'From A too', prop3: 'Also from A (really)'}; var fromKey = 'should be able to use mapFrom to switch '; var toKey = 'properties and ignore a property as well'; @@ -738,19 +794,25 @@ module AutoMapperJs { // act automapper .createMap(fromKey, toKey) - .forMember('prop1', (opts: IMemberConfigurationOptions) => { opts.mapFrom('prop2'); }) - .forMember('prop2', (opts: IMemberConfigurationOptions) => { opts.mapFrom('prop1'); }) - .forSourceMember('prop3', (opts: ISourceMemberConfigurationOptions) => { opts.ignore(); }); + .forMember('prop1', (opts: IMemberConfigurationOptions) => { + opts.mapFrom('prop2'); + }) + .forMember('prop2', (opts: IMemberConfigurationOptions) => { + opts.mapFrom('prop1'); + }) + .forSourceMember('prop3', (opts: ISourceMemberConfigurationOptions) => { + opts.ignore(); + }); var objB = automapper.map(fromKey, toKey, objA); // assert - expect(objB).toEqualData({ prop1: objA.prop2, prop2: objA.prop1 }); + expect(objB).toEqualData({prop1: objA.prop2, prop2: objA.prop1}); }); it('should be able to create a new property using a constant value', () => { // arrange - var objA = { }; + var objA = {}; var fromKey = 'should be able to create a new property '; var toKey = 'using a constant value'; @@ -758,12 +820,14 @@ module AutoMapperJs { // act automapper .createMap(fromKey, toKey) - .forMember('prop4', (opts: IMemberConfigurationOptions) => { return 12; }); + .forMember('prop4', (opts: IMemberConfigurationOptions) => { + return 12; + }); var objB = automapper.map(fromKey, toKey, objA); // assert - expect(objB).toEqualData({ prop4: 12 }); + expect(objB).toEqualData({prop4: 12}); }); it('should just return source object when no properties are created using null source object', () => { @@ -793,12 +857,14 @@ module AutoMapperJs { // act automapper .createMap(fromKey, toKey) - .forMember('prop4', (opts: IMemberConfigurationOptions) => { return 12; }); + .forMember('prop4', (opts: IMemberConfigurationOptions) => { + return 12; + }); var objB = automapper.map(fromKey, toKey, objA); // assert - expect(objB).toEqualData({ prop4: 12 }); + expect(objB).toEqualData({prop4: 12}); }); }); @@ -806,15 +872,15 @@ module AutoMapperJs { // arrange var src: any = { homeAddress: null /*{ - address1: '200 Main St', - address2: '200 Main St', - city: 'Los Angeles', - state: 'CA', - zip: '90000' - }*/, + address1: '200 Main St', + address2: '200 Main St', + city: 'Los Angeles', + state: 'CA', + zip: '90000' + }*/, businessAddress: { - address1: '200 Main St', - // address2: '200 Main St', + address1: '200 Main St', + // address2: '200 Main St', city: 'Los Angeles', state: 'CA', zip: '90000' @@ -827,17 +893,27 @@ module AutoMapperJs { automapper .createMap(fromKey, toKey) // .forMember('homeAddress.address1', (opts: IMemberConfigurationOptions) => { opts.mapFrom('homeAddress.address1'); }) - .forMember('homeAddress.address2', (opts: IMemberConfigurationOptions) => { opts.mapFrom('homeAddress.address2'); }) + .forMember('homeAddress.address2', (opts: IMemberConfigurationOptions) => { + opts.mapFrom('homeAddress.address2'); + }) // .forMember('homeAddress.city', (opts: IMemberConfigurationOptions) => { opts.mapFrom('homeAddress.city'); }) // .forMember('homeAddress.state', (opts: IMemberConfigurationOptions) => { opts.mapFrom('homeAddress.state'); }) // .forMember('homeAddress.zip', (opts: IMemberConfigurationOptions) => { opts.mapFrom('homeAddress.zip'); }) - .forMember('businessAddress.address1', (opts: IMemberConfigurationOptions) => { opts.mapFrom('businessAddress.address1'); }) + .forMember('businessAddress.address1', (opts: IMemberConfigurationOptions) => { + opts.mapFrom('businessAddress.address1'); + }) .forMember('businessAddress.address2', (opts: IMemberConfigurationOptions) => null) - .forMember('businessAddress.city', (opts: IMemberConfigurationOptions) => { opts.mapFrom('businessAddress.city'); }) - .forMember('businessAddress.state', (opts: IMemberConfigurationOptions) => { opts.mapFrom('businessAddress.state'); }) - .forMember('businessAddress.zip', (opts: IMemberConfigurationOptions) => { opts.mapFrom('businessAddress.zip'); }) - ; + .forMember('businessAddress.city', (opts: IMemberConfigurationOptions) => { + opts.mapFrom('businessAddress.city'); + }) + .forMember('businessAddress.state', (opts: IMemberConfigurationOptions) => { + opts.mapFrom('businessAddress.state'); + }) + .forMember('businessAddress.zip', (opts: IMemberConfigurationOptions) => { + opts.mapFrom('businessAddress.zip'); + }) + ; // act var dst = automapper.map(fromKey, toKey, src); @@ -846,7 +922,7 @@ module AutoMapperJs { expect(dst).not.toBeNull(); expect(dst.homeAddress).toBeNull(); - + expect(dst.businessAddress.address1).toBe(src.businessAddress.address1); expect(dst.businessAddress.address2).toBeUndefined(); expect(dst.businessAddress.city).toBe(src.businessAddress.city); @@ -858,7 +934,7 @@ module AutoMapperJs { // // arrange // var src: any = { // businessAddress: { - // address1: '200 Main St', + // address1: '200 Main St', // city: 'Los Angeles', // state: 'CA', // zip: '90000' @@ -870,8 +946,8 @@ module AutoMapperJs { // automapper // .createMap(fromKey, toKey) - // .forMember('businessAddress.address2', (opts: IMemberConfigurationOptions) => null); - // // the forMember call currently fails the test. Automapping on nested properties is currently + // .forMember('businessAddress.address2', (opts: IMemberConfigurationOptions) => null); + // // the forMember call currently fails the test. Automapping on nested properties is currently // // not implemented when a forMember call is present! Should work somewhat like the handleItem // // function at 'root level'. @@ -882,7 +958,7 @@ module AutoMapperJs { // expect(dst).not.toBeNull(); // expect(dst.homeAddress).toBeNull(); - + // expect(dst.businessAddress.address1).toBe(src.businessAddress.address1); // expect(dst.businessAddress.address2).toBeUndefined(); // expect(dst.businessAddress.city).toBe(src.businessAddress.city); @@ -891,15 +967,16 @@ module AutoMapperJs { // }); class ClassA { - public propA: string; + public propA: string = null; } class ClassB { - public propA: string; + public propA: string = null; } + //Initialization of property necessary to force Javascript create this property on class class ClassC { - public propA: string; + public propA: string = null; } class DemoToBusinessType { @@ -907,13 +984,13 @@ module AutoMapperJs { class CustomTypeConverterInstance extends TypeConverter { public convert(resolutionContext: IResolutionContext): any { - return { propA: resolutionContext.sourceValue.propA + ' (convertUsing with a class instance)' }; + return {propA: resolutionContext.sourceValue.propA + ' (convertUsing with a class instance)'}; } } class CustomTypeConverterDefinition extends TypeConverter { public convert(resolutionContext: IResolutionContext): any { - return { propA: resolutionContext.sourceValue.propA + ' (convertUsing with a class definition)' }; + return {propA: resolutionContext.sourceValue.propA + ' (convertUsing with a class definition)'}; } } -} \ No newline at end of file +} diff --git a/test/tests/ts/automapper-initialize-specs.ts b/test/tests/ts/automapper-initialize-specs.ts index c295947..b4cd855 100644 --- a/test/tests/ts/automapper-initialize-specs.ts +++ b/test/tests/ts/automapper-initialize-specs.ts @@ -34,6 +34,15 @@ module AutoMapperJs { } } + // class ComplexObjectToSimpleObject extends Profile { + // public profileName = 'ComplexObjectToSimpleObject'; + // + // public configure() { + // alert('Complex configuration'); + // super.createMap('complex', 'simple'); + // } + // } + class ValidatedAgeMappingProfile extends Profile { public profileName = 'ValidatedAgeMappingProfile'; @@ -63,8 +72,8 @@ module AutoMapperJs { } class Person { - fullName: string; - age: number; + fullName: string = null; + age: number = null; } class BeerBuyingYoungster extends Person { @@ -99,7 +108,7 @@ module AutoMapperJs { const sourceKey = 'PascalCase'; const destinationKey = 'CamelCase'; - const sourceObject = { FullName: 'John Doe' }; + const sourceObject = {FullName: 'John Doe'}; automapper .createMap(sourceKey, destinationKey) @@ -107,7 +116,7 @@ module AutoMapperJs { var result = automapper.map(sourceKey, destinationKey, sourceObject); - expect(result).toEqualData({ fullName: 'John Doe' }); + expect(result).toEqualData({fullName: 'John Doe'}); }); it('should be able to use a naming convention to convert camelCase to PascalCase', () => { @@ -118,7 +127,7 @@ module AutoMapperJs { const sourceKey = 'CamelCase2'; const destinationKey = 'PascalCase2'; - const sourceObject = { fullName: 'John Doe' }; + const sourceObject = {fullName: 'John Doe'}; automapper .createMap(sourceKey, destinationKey) @@ -126,7 +135,7 @@ module AutoMapperJs { var result = automapper.map(sourceKey, destinationKey, sourceObject); - expect(result).toEqualData({ FullName: 'John Doe' }); + expect(result).toEqualData({FullName: 'John Doe'}); }); it('should be able to use forMember besides using a profile', () => { @@ -137,7 +146,7 @@ module AutoMapperJs { const sourceKey = 'CamelCase'; const destinationKey = 'PascalCase'; - const sourceObject = { fullName: 'John Doe', age: 20 }; + const sourceObject = {fullName: 'John Doe', age: 20}; automapper .createMap(sourceKey, destinationKey) @@ -146,7 +155,7 @@ module AutoMapperJs { var result = automapper.map(sourceKey, destinationKey, sourceObject); - expect(result).toEqualData({ FullName: 'John Doe', theAge: sourceObject.age }); + expect(result).toEqualData({FullName: 'John Doe', theAge: sourceObject.age}); }); it('should use profile when only profile properties are specified', () => { @@ -157,7 +166,7 @@ module AutoMapperJs { const sourceKey = '{918D9D7F-AA89-4D07-917E-A528F07EEF42}'; const destinationKey = '{908D9D6F-BA89-4D17-915E-A528E988EE64}'; - const sourceObject = { fullName: 'John Doe', proclaimedAge: 21, ageOnId: 15 }; + const sourceObject = {fullName: 'John Doe', proclaimedAge: 21, ageOnId: 15}; automapper .createMap(sourceKey, destinationKey) @@ -165,7 +174,7 @@ module AutoMapperJs { var result = automapper.map(sourceKey, destinationKey, sourceObject); - expect(result).toEqualData({ fullName: 'John Doe', age: sourceObject.ageOnId }); + expect(result).toEqualData({fullName: 'John Doe', age: sourceObject.ageOnId}); expect(result instanceof Person).toBeTruthy(); expect(result instanceof BeerBuyingYoungster).not.toBeTruthy(); }); @@ -176,7 +185,7 @@ module AutoMapperJs { var profileName = 'Non-existing profile'; const sourceKey = 'should fail when using '; const destinationKey = 'a non-existimg profile'; - const sourceObject = { }; + const sourceObject = {}; // act try { @@ -205,7 +214,7 @@ module AutoMapperJs { const sourceKey = '{808D9D7F-AA89-4D07-917E-A528F078E642}'; const destinationKey = '{808D9D6F-BA89-4D17-915E-A528E178EE64}'; - const sourceObject = { fullName: 'John Doe', proclaimedAge: 21, ageOnId: 15 }; + const sourceObject = {fullName: 'John Doe', proclaimedAge: 21, ageOnId: 15}; automapper .createMap(sourceKey, destinationKey) @@ -216,7 +225,7 @@ module AutoMapperJs { var result = automapper.map(sourceKey, destinationKey, sourceObject); - expect(result).toEqualData({ fullName: 'John Doe', age: sourceObject.ageOnId }); + expect(result).toEqualData({fullName: 'John Doe', age: sourceObject.ageOnId}); expect(result instanceof Person).toBeTruthy(); expect(result instanceof BeerBuyingYoungster).not.toBeTruthy(); }); @@ -227,7 +236,7 @@ module AutoMapperJs { var toKey1 = '{B364C0A0-9E24-4424-A569-A4C14102147C}'; var toKey2 = '{1055CA5A-4FC4-44CA-B4D8-B004F43D4440}'; - var source = { prop: 'Value' }; + var source = {prop: 'Value'}; // act var mapFromKeyCurry: (destinationKey: string) => ICreateMapFluentFunctions; @@ -236,7 +245,9 @@ module AutoMapperJs { mapFromKeyCurry = config.createMap(fromKey); mapFromKeyCurry(toKey1) - .forSourceMember('prop', (opts: ISourceMemberConfigurationOptions) => { opts.ignore(); }); + .forSourceMember('prop', (opts: ISourceMemberConfigurationOptions) => { + opts.ignore(); + }); mapFromKeyCurry(toKey2); }); @@ -250,5 +261,20 @@ module AutoMapperJs { expect(result2.prop).toEqual(source.prop); }); + // it('should be able to convert Complex Objects to Simple Objects', ()=> { + // automapper.initialize((config: IConfiguration) => { + // config.addProfile(new ComplexObjectToSimpleObject()); + // }); + // + // const sourceKey = '{74d523ee-8dbb-4e72-bdf1-db8fa3b27d07}'; + // const destinationKey = '{cf7bbaa0-14f9-400d-a59a-65313651db6b}'; + // + // automapper + // .createMap(sourceKey, destinationKey) + // .withProfile('ValidatedAgeMappingProfile'); + // + // + // + // }); }); -} \ No newline at end of file +} diff --git a/test/tests/ts/automapper-map-specs.ts b/test/tests/ts/automapper-map-specs.ts index 348a90a..4cdf32e 100644 --- a/test/tests/ts/automapper-map-specs.ts +++ b/test/tests/ts/automapper-map-specs.ts @@ -16,7 +16,7 @@ module AutoMapperJs { it('should auto map matching properties', () => { // arrange - var objA = { prop1: 'From A', prop2: 'From A too' }; + var objA = {prop1: 'From A', prop2: 'From A too'}; var fromKey = '{7F5AF9AC-2E9E-4676-8BE1-3E72866B11E8}'; var toKey = '{8089EBDC-3BBB-4988-95F2-683CC1AD23A3}'; @@ -32,7 +32,7 @@ module AutoMapperJs { it('should map an array', () => { // arrange - var arrA = [{ prop1: 'From A', prop2: 'From A too' }]; + var arrA = [{prop1: 'From A', prop2: 'From A too'}]; var fromKey = '{60D9DB56-D6E1-48FF-9BAC-0805FCAF91B7}'; var toKey = '{AC6D5B97-9AE3-4267-BD60-A5FED17E541A}'; @@ -48,7 +48,7 @@ module AutoMapperJs { it('should map an array and handle empty items', () => { // arrange - var arrA = [{ prop1: 'From A', prop2: 'From A too' }, undefined]; + var arrA = [{prop1: 'From A', prop2: 'From A too'}, undefined]; var fromKey = '{60D9DB56-D6E1-48FF-9BAC-0805FCAF91B7}'; var toKey = '{AC6D5B97-9AE3-4267-BD60-A5FED17E541A}'; @@ -61,5 +61,60 @@ module AutoMapperJs { // assert expect(arrB).toEqualData(arrA); }); + it('should ignore properties on source object missing on destination object type Definition', () => { + // arrange + class DestinationType { + public keep: string = null; + } + + var fromObject = { + keep: true, + remove: true + }; + + var fromKey = '{60D9DB56-D6E1-48FF-9BAC-0805FCAF91B7}'; + var toKey = '{AC6D5B97-9AE3-4267-BD60-A5FED17E541A}'; + + automapper.createMap(fromKey, toKey).convertToType(DestinationType); + + // act + var toObject = automapper.map(fromKey, toKey, fromObject); + // assert + expect(toObject).toBeDefined(); + expect(toObject.remove).not.toBeDefined(); + }); + it('should ignore properties on source object missing on destination object type Definition for nested objects too', () => { + // arrange + class DestinationType { + public keep: string = null; + public nested: NestedDestinationType = new NestedDestinationType; + } + + class NestedDestinationType { + public keep: string = null; + } + + var fromObject = { + keep: true, + remove: true, + nested: { + keep: true, + remove: false + } + }; + + var fromKey = '{2dc59bc0-40d2-4d68-87ae-d1f2953dcb4c}'; + var toKey = '{0bf8ffd0-c003-4b76-bbcf-83a40b0d1cad}'; + + automapper.createMap(fromKey, toKey).convertToType(DestinationType); + + // act + var toObject = automapper.map(fromKey, toKey, fromObject); + // assert + expect(toObject).toBeDefined(); + expect(toObject.remove).not.toBeDefined(); + expect(toObject.nested.keep).toBeDefined(); + expect(toObject.nested.remove).not.toBeDefined(); + }); }); -} \ No newline at end of file +}