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mBtG,KAAKf,QAAQqH,gBAAgBtB,SAC/DrC,EAAOA,EAAKkB,QAAO,SAAAf,GACjB,OAAAlD,EAAKX,QAAQqH,gBAAgBC,OAAM,SAAAC,GACjC,OAAO1D,EAAI2D,OAAO,EAAGD,EAAOxB,UAAYwB,CAC1C,GAFA,KAOJ7D,EAAOA,EAAKkB,QAAO,SAACf,EAAKxC,EAAOoG,GAC9B,OAAOA,EAAKC,QAAQ7D,KAASxC,CAC/B,GAGF,EAEQvB,EAAAK,UAAAkG,aAAR,SAAqBC,EAAeC,GAClC,IAAIoB,GAAW,EAIf,OAHIA,GAAYrB,IAAOqB,EAAW5G,KAAKf,QAAQmG,SAAWG,GACtDqB,GAAYpB,IAAOoB,EAAW5G,KAAKf,QAAQmG,QAAUI,GAElDoB,CACT,EAEQ7H,EAAAK,UAAAsG,YAAR,SAAoBD,GAClB,OAAKA,GAEEzF,KAAKf,QAAQwG,OAAOoB,MAAK,SAAAC,GAAe,OAAArB,EAAOY,SAASS,EAAhB,GACjD,EACF/H,CAAA,CArhBA,E","sources":["webpack://app/../../src/TransformOperationExecutor.ts"],"sourcesContent":["import { defaultMetadataStorage } from './storage';\nimport { ClassTransformOptions, TypeHelpOptions, TypeMetadata, TypeOptions } from './interfaces';\nimport { TransformationType } from './enums';\nimport { getGlobal, isPromise } from './utils';\n\nfunction instantiateArrayType(arrayType: Function): Array | Set {\n const array = new (arrayType as any)();\n if (!(array instanceof Set) && !('push' in array)) {\n return [];\n }\n return array;\n}\n\nexport class TransformOperationExecutor {\n // -------------------------------------------------------------------------\n // Private Properties\n // -------------------------------------------------------------------------\n\n private recursionStack = new Set>();\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(private transformationType: TransformationType, private options: ClassTransformOptions) {}\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n transform(\n source: Record | Record[] | any,\n value: Record | Record[] | any,\n targetType: Function | TypeMetadata,\n arrayType: Function,\n isMap: boolean,\n level: number = 0\n ): any {\n if (Array.isArray(value) || value instanceof Set) {\n const newValue =\n arrayType && this.transformationType === TransformationType.PLAIN_TO_CLASS\n ? instantiateArrayType(arrayType)\n : [];\n (value as any[]).forEach((subValue, index) => {\n const subSource = source ? source[index] : undefined;\n if (!this.options.enableCircularCheck || !this.isCircular(subValue)) {\n let realTargetType;\n if (\n typeof targetType !== 'function' &&\n targetType &&\n targetType.options &&\n targetType.options.discriminator &&\n targetType.options.discriminator.property &&\n targetType.options.discriminator.subTypes\n ) {\n if (this.transformationType === TransformationType.PLAIN_TO_CLASS) {\n realTargetType = targetType.options.discriminator.subTypes.find(\n subType =>\n subType.name === subValue[(targetType as { options: TypeOptions }).options.discriminator.property]\n );\n const options: TypeHelpOptions = { newObject: newValue, object: subValue, property: undefined };\n const newType = targetType.typeFunction(options);\n realTargetType === undefined ? (realTargetType = newType) : (realTargetType = realTargetType.value);\n if (!targetType.options.keepDiscriminatorProperty)\n delete subValue[targetType.options.discriminator.property];\n }\n\n if (this.transformationType === TransformationType.CLASS_TO_CLASS) {\n realTargetType = subValue.constructor;\n }\n if (this.transformationType === TransformationType.CLASS_TO_PLAIN) {\n subValue[targetType.options.discriminator.property] = targetType.options.discriminator.subTypes.find(\n subType => subType.value === subValue.constructor\n ).name;\n }\n } else {\n realTargetType = targetType;\n }\n const value = this.transform(\n subSource,\n subValue,\n realTargetType,\n undefined,\n subValue instanceof Map,\n level + 1\n );\n\n if (newValue instanceof Set) {\n newValue.add(value);\n } else {\n newValue.push(value);\n }\n } else if (this.transformationType === TransformationType.CLASS_TO_CLASS) {\n if (newValue instanceof Set) {\n newValue.add(subValue);\n } else {\n newValue.push(subValue);\n }\n }\n });\n return newValue;\n } else if (targetType === String && !isMap) {\n if (value === null || value === undefined) return value;\n return String(value);\n } else if (targetType === Number && !isMap) {\n if (value === null || value === undefined) return value;\n return Number(value);\n } else if (targetType === Boolean && !isMap) {\n if (value === null || value === undefined) return value;\n return Boolean(value);\n } else if ((targetType === Date || value instanceof Date) && !isMap) {\n if (value instanceof Date) {\n return new Date(value.valueOf());\n }\n if (value === null || value === undefined) return value;\n return new Date(value);\n } else if (!!getGlobal().Buffer && (targetType === Buffer || value instanceof Buffer) && !isMap) {\n if (value === null || value === undefined) return value;\n return Buffer.from(value);\n } else if (isPromise(value) && !isMap) {\n return new Promise((resolve, reject) => {\n value.then(\n (data: any) => resolve(this.transform(undefined, data, targetType, undefined, undefined, level + 1)),\n reject\n );\n });\n } else if (!isMap && value !== null && typeof value === 'object' && typeof value.then === 'function') {\n // Note: We should not enter this, as promise has been handled above\n // This option simply returns the Promise preventing a JS error from happening and should be an inaccessible path.\n return value; // skip promise transformation\n } else if (typeof value === 'object' && value !== null) {\n // try to guess the type\n if (!targetType && value.constructor !== Object /* && TransformationType === TransformationType.CLASS_TO_PLAIN*/)\n if (!Array.isArray(value) && value.constructor === Array) {\n // Somebody attempts to convert special Array like object to Array, eg:\n // const evilObject = { '100000000': '100000000', __proto__: [] };\n // This could be used to cause Denial-of-service attack so we don't allow it.\n // See prevent-array-bomb.spec.ts for more details.\n } else {\n // We are good we can use the built-in constructor\n targetType = value.constructor;\n }\n if (!targetType && source) targetType = source.constructor;\n\n if (this.options.enableCircularCheck) {\n // add transformed type to prevent circular references\n this.recursionStack.add(value);\n }\n\n const keys = this.getKeys(targetType as Function, value, isMap);\n let newValue: any = source ? source : {};\n if (\n !source &&\n (this.transformationType === TransformationType.PLAIN_TO_CLASS ||\n this.transformationType === TransformationType.CLASS_TO_CLASS)\n ) {\n if (isMap) {\n newValue = new Map();\n } else if (targetType) {\n newValue = new (targetType as any)();\n } else {\n newValue = {};\n }\n }\n\n // traverse over keys\n for (const key of keys) {\n if (key === '__proto__' || key === 'constructor') {\n continue;\n }\n\n const valueKey = key;\n let newValueKey = key,\n propertyName = key;\n if (!this.options.ignoreDecorators && targetType) {\n if (this.transformationType === TransformationType.PLAIN_TO_CLASS) {\n const exposeMetadata = defaultMetadataStorage.findExposeMetadataByCustomName(targetType as Function, key);\n if (exposeMetadata) {\n propertyName = exposeMetadata.propertyName;\n newValueKey = exposeMetadata.propertyName;\n }\n } else if (\n this.transformationType === TransformationType.CLASS_TO_PLAIN ||\n this.transformationType === TransformationType.CLASS_TO_CLASS\n ) {\n const exposeMetadata = defaultMetadataStorage.findExposeMetadata(targetType as Function, key);\n if (exposeMetadata && exposeMetadata.options && exposeMetadata.options.name) {\n newValueKey = exposeMetadata.options.name;\n }\n }\n }\n\n // get a subvalue\n let subValue: any = undefined;\n if (this.transformationType === TransformationType.PLAIN_TO_CLASS) {\n /**\n * This section is added for the following report:\n * https://github.com/typestack/class-transformer/issues/596\n *\n * We should not call functions or constructors when transforming to class.\n */\n subValue = value[valueKey];\n } else {\n if (value instanceof Map) {\n subValue = value.get(valueKey);\n } else if (value[valueKey] instanceof Function) {\n subValue = value[valueKey]();\n } else {\n subValue = value[valueKey];\n }\n }\n\n // determine a type\n let type: any = undefined,\n isSubValueMap = subValue instanceof Map;\n if (targetType && isMap) {\n type = targetType;\n } else if (targetType) {\n const metadata = defaultMetadataStorage.findTypeMetadata(targetType as Function, propertyName);\n if (metadata) {\n const options: TypeHelpOptions = { newObject: newValue, object: value, property: propertyName };\n const newType = metadata.typeFunction ? metadata.typeFunction(options) : metadata.reflectedType;\n if (\n metadata.options &&\n metadata.options.discriminator &&\n metadata.options.discriminator.property &&\n metadata.options.discriminator.subTypes\n ) {\n if (!(value[valueKey] instanceof Array)) {\n if (this.transformationType === TransformationType.PLAIN_TO_CLASS) {\n type = metadata.options.discriminator.subTypes.find(subType => {\n if (subValue && subValue instanceof Object && metadata.options.discriminator.property in subValue) {\n return subType.name === subValue[metadata.options.discriminator.property];\n }\n });\n type === undefined ? (type = newType) : (type = type.value);\n if (!metadata.options.keepDiscriminatorProperty) {\n if (subValue && subValue instanceof Object && metadata.options.discriminator.property in subValue) {\n delete subValue[metadata.options.discriminator.property];\n }\n }\n }\n if (this.transformationType === TransformationType.CLASS_TO_CLASS) {\n type = subValue.constructor;\n }\n if (this.transformationType === TransformationType.CLASS_TO_PLAIN) {\n if (subValue) {\n subValue[metadata.options.discriminator.property] = metadata.options.discriminator.subTypes.find(\n subType => subType.value === subValue.constructor\n ).name;\n }\n }\n } else {\n type = metadata;\n }\n } else {\n type = newType;\n }\n isSubValueMap = isSubValueMap || metadata.reflectedType === Map;\n } else if (this.options.targetMaps) {\n // try to find a type in target maps\n this.options.targetMaps\n .filter(map => map.target === targetType && !!map.properties[propertyName])\n .forEach(map => (type = map.properties[propertyName]));\n } else if (\n this.options.enableImplicitConversion &&\n this.transformationType === TransformationType.PLAIN_TO_CLASS\n ) {\n // if we have no registererd type via the @Type() decorator then we check if we have any\n // type declarations in reflect-metadata (type declaration is emited only if some decorator is added to the property.)\n const reflectedType = (Reflect as any).getMetadata(\n 'design:type',\n (targetType as Function).prototype,\n propertyName\n );\n\n if (reflectedType) {\n type = reflectedType;\n }\n }\n }\n\n // if value is an array try to get its custom array type\n const arrayType = Array.isArray(value[valueKey])\n ? this.getReflectedType(targetType as Function, propertyName)\n : undefined;\n\n // const subValueKey = TransformationType === TransformationType.PLAIN_TO_CLASS && newKeyName ? newKeyName : key;\n const subSource = source ? source[valueKey] : undefined;\n\n // if its deserialization then type if required\n // if we uncomment this types like string[] will not work\n // if (this.transformationType === TransformationType.PLAIN_TO_CLASS && !type && subValue instanceof Object && !(subValue instanceof Date))\n // throw new Error(`Cannot determine type for ${(targetType as any).name }.${propertyName}, did you forget to specify a @Type?`);\n\n // if newValue is a source object that has method that match newKeyName then skip it\n if (newValue.constructor.prototype) {\n const descriptor = Object.getOwnPropertyDescriptor(newValue.constructor.prototype, newValueKey);\n if (\n (this.transformationType === TransformationType.PLAIN_TO_CLASS ||\n this.transformationType === TransformationType.CLASS_TO_CLASS) &&\n // eslint-disable-next-line @typescript-eslint/unbound-method\n ((descriptor && !descriptor.set) || newValue[newValueKey] instanceof Function)\n )\n // || TransformationType === TransformationType.CLASS_TO_CLASS\n continue;\n }\n\n if (!this.options.enableCircularCheck || !this.isCircular(subValue)) {\n const transformKey = this.transformationType === TransformationType.PLAIN_TO_CLASS ? newValueKey : key;\n let finalValue;\n\n if (this.transformationType === TransformationType.CLASS_TO_PLAIN) {\n // Get original value\n finalValue = value[transformKey];\n // Apply custom transformation\n finalValue = this.applyCustomTransformations(\n finalValue,\n targetType as Function,\n transformKey,\n value,\n this.transformationType\n );\n // If nothing change, it means no custom transformation was applied, so use the subValue.\n finalValue = value[transformKey] === finalValue ? subValue : finalValue;\n // Apply the default transformation\n finalValue = this.transform(subSource, finalValue, type, arrayType, isSubValueMap, level + 1);\n } else {\n if (subValue === undefined && this.options.exposeDefaultValues) {\n // Set default value if nothing provided\n finalValue = newValue[newValueKey];\n } else {\n finalValue = this.transform(subSource, subValue, type, arrayType, isSubValueMap, level + 1);\n finalValue = this.applyCustomTransformations(\n finalValue,\n targetType as Function,\n transformKey,\n value,\n this.transformationType\n );\n }\n }\n\n if (finalValue !== undefined || this.options.exposeUnsetFields) {\n if (newValue instanceof Map) {\n newValue.set(newValueKey, finalValue);\n } else {\n newValue[newValueKey] = finalValue;\n }\n }\n } else if (this.transformationType === TransformationType.CLASS_TO_CLASS) {\n let finalValue = subValue;\n finalValue = this.applyCustomTransformations(\n finalValue,\n targetType as Function,\n key,\n value,\n this.transformationType\n );\n if (finalValue !== undefined || this.options.exposeUnsetFields) {\n if (newValue instanceof Map) {\n newValue.set(newValueKey, finalValue);\n } else {\n newValue[newValueKey] = finalValue;\n }\n }\n }\n }\n\n if (this.options.enableCircularCheck) {\n this.recursionStack.delete(value);\n }\n\n return newValue;\n } else {\n return value;\n }\n }\n\n private applyCustomTransformations(\n value: any,\n target: Function,\n key: string,\n obj: any,\n transformationType: TransformationType\n ): boolean {\n let metadatas = defaultMetadataStorage.findTransformMetadatas(target, key, this.transformationType);\n\n // apply versioning options\n if (this.options.version !== undefined) {\n metadatas = metadatas.filter(metadata => {\n if (!metadata.options) return true;\n\n return this.checkVersion(metadata.options.since, metadata.options.until);\n });\n }\n\n // apply grouping options\n if (this.options.groups && this.options.groups.length) {\n metadatas = metadatas.filter(metadata => {\n if (!metadata.options) return true;\n\n return this.checkGroups(metadata.options.groups);\n });\n } else {\n metadatas = metadatas.filter(metadata => {\n return !metadata.options || !metadata.options.groups || !metadata.options.groups.length;\n });\n }\n\n metadatas.forEach(metadata => {\n value = metadata.transformFn({ value, key, obj, type: transformationType, options: this.options });\n });\n\n return value;\n }\n\n // preventing circular references\n private isCircular(object: Record): boolean {\n return this.recursionStack.has(object);\n }\n\n private getReflectedType(target: Function, propertyName: string): Function | undefined {\n if (!target) return undefined;\n const meta = defaultMetadataStorage.findTypeMetadata(target, propertyName);\n return meta ? meta.reflectedType : undefined;\n }\n\n private getKeys(target: Function, object: Record, isMap: boolean): string[] {\n // determine exclusion strategy\n let strategy = defaultMetadataStorage.getStrategy(target);\n if (strategy === 'none') strategy = this.options.strategy || 'exposeAll'; // exposeAll is default strategy\n\n // get all keys that need to expose\n let keys: any[] = [];\n if (strategy === 'exposeAll' || isMap) {\n if (object instanceof Map) {\n keys = Array.from(object.keys());\n } else {\n keys = Object.keys(object);\n }\n }\n\n if (isMap) {\n // expose & exclude do not apply for map keys only to fields\n return keys;\n }\n\n /**\n * If decorators are ignored but we don't want the extraneous values, then we use the\n * metadata to decide which property is needed, but doesn't apply the decorator effect.\n */\n if (this.options.ignoreDecorators && this.options.excludeExtraneousValues && target) {\n const exposedProperties = defaultMetadataStorage.getExposedProperties(target, this.transformationType);\n const excludedProperties = defaultMetadataStorage.getExcludedProperties(target, this.transformationType);\n keys = [...exposedProperties, ...excludedProperties];\n }\n\n if (!this.options.ignoreDecorators && target) {\n // add all exposed to list of keys\n let exposedProperties = defaultMetadataStorage.getExposedProperties(target, this.transformationType);\n if (this.transformationType === TransformationType.PLAIN_TO_CLASS) {\n exposedProperties = exposedProperties.map(key => {\n const exposeMetadata = defaultMetadataStorage.findExposeMetadata(target, key);\n if (exposeMetadata && exposeMetadata.options && exposeMetadata.options.name) {\n return exposeMetadata.options.name;\n }\n\n return key;\n });\n }\n if (this.options.excludeExtraneousValues) {\n keys = exposedProperties;\n } else {\n keys = keys.concat(exposedProperties);\n }\n\n // exclude excluded properties\n const excludedProperties = defaultMetadataStorage.getExcludedProperties(target, this.transformationType);\n if (excludedProperties.length > 0) {\n keys = keys.filter(key => {\n return !excludedProperties.includes(key);\n });\n }\n\n // apply versioning options\n if (this.options.version !== undefined) {\n keys = keys.filter(key => {\n const exposeMetadata = defaultMetadataStorage.findExposeMetadata(target, key);\n if (!exposeMetadata || !exposeMetadata.options) return true;\n\n return this.checkVersion(exposeMetadata.options.since, exposeMetadata.options.until);\n });\n }\n\n // apply grouping options\n if (this.options.groups && this.options.groups.length) {\n keys = keys.filter(key => {\n const exposeMetadata = defaultMetadataStorage.findExposeMetadata(target, key);\n if (!exposeMetadata || !exposeMetadata.options) return true;\n\n return this.checkGroups(exposeMetadata.options.groups);\n });\n } else {\n keys = keys.filter(key => {\n const exposeMetadata = defaultMetadataStorage.findExposeMetadata(target, key);\n return (\n !exposeMetadata ||\n !exposeMetadata.options ||\n !exposeMetadata.options.groups ||\n !exposeMetadata.options.groups.length\n );\n });\n }\n }\n\n // exclude prefixed properties\n if (this.options.excludePrefixes && this.options.excludePrefixes.length) {\n keys = keys.filter(key =>\n this.options.excludePrefixes.every(prefix => {\n return key.substr(0, prefix.length) !== prefix;\n })\n );\n }\n\n // make sure we have unique keys\n keys = keys.filter((key, index, self) => {\n return self.indexOf(key) === index;\n });\n\n return keys;\n }\n\n private checkVersion(since: number, until: number): boolean {\n let decision = true;\n if (decision && since) decision = this.options.version >= since;\n if (decision && until) decision = this.options.version < until;\n\n return decision;\n }\n\n private checkGroups(groups: string[]): boolean {\n if (!groups) return true;\n\n return this.options.groups.some(optionGroup => groups.includes(optionGroup));\n }\n}\n"],"names":["TransformOperationExecutor","transformationType","options","recursionStack","Set","prototype","transform","source","value","targetType","arrayType","isMap","level","_this","Array","isArray","newValue_1","this","TransformationType","array","instantiateArrayType","forEach","subValue","index","subSource","undefined","enableCircularCheck","isCircular","add","push","realTargetType","discriminator","property","subTypes","find","subType","name","newObject","object","newType","typeFunction","keepDiscriminatorProperty","constructor","value_1","Map","String","Number","Boolean","Date","valueOf","getGlobal","Buffer","from","isPromise","Promise","resolve","reject","then","data","Object","keys","getKeys","newValue","key","valueKey","newValueKey","propertyName","this_1","ignoreDecorators","exposeMetadata","defaultMetadataStorage","get","Function","type","isSubValueMap","metadata_1","reflectedType","targetMaps","filter","map","target","properties","enableImplicitConversion","Reflect","getMetadata","arrayType_1","getReflectedType","descriptor","getOwnPropertyDescriptor","set","finalValue","applyCustomTransformations","exposeUnsetFields","transformKey","exposeDefaultValues","_i","keys_1","length","delete","obj","metadatas","version","metadata","checkVersion","since","until","groups","checkGroups","transformFn","has","meta","strategy","excludeExtraneousValues","exposedProperties","excludedProperties","__spreadArray","concat","excludedProperties_1","includes","excludePrefixes","every","prefix","substr","self","indexOf","decision","some","optionGroup"],"sourceRoot":""}