class-transformer
Advanced tools
Comparing version 0.1.0-beta.3 to 0.1.0-beta.4
import { ExposeOptions, ExcludeOptions } from "./metadata/ExposeExcludeOptions"; | ||
export interface TypeTransformOptions { | ||
newObject: any; | ||
object: Object; | ||
property: string; | ||
} | ||
/** | ||
* Specifies a type of the property. | ||
*/ | ||
export declare function Type(typeFunction?: (type?: any) => Function): (target: any, key: string) => void; | ||
export declare function Type(typeFunction?: (type?: TypeTransformOptions) => Function): (target: any, key: string) => void; | ||
/** | ||
@@ -7,0 +12,0 @@ * Marks property as included in the process of transformation. By default it includes the property for both |
{ | ||
"name": "class-transformer", | ||
"version": "0.1.0-beta.3", | ||
"version": "0.1.0-beta.4", | ||
"description": "Proper decorator-based transformation / serialization / deserialization of plain javascript objects to class constructors", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -10,5 +10,5 @@ import { ClassTransformOptions } from "./ClassTransformOptions"; | ||
private isCircular(object, level); | ||
private getKeyType(object, target, key); | ||
private getKeyType(newObject, object, target, key); | ||
private getReflectedType(target, propertyName); | ||
private getKeys(target, object); | ||
} |
@@ -45,3 +45,3 @@ "use strict"; | ||
if (value instanceof Date) { | ||
return new Date(value.getTime()); | ||
return new Date(value.valueOf()); | ||
} | ||
@@ -81,3 +81,3 @@ return new Date(value); | ||
} | ||
var type = this.getKeyType(value, targetType, propertyName); | ||
var type = this.getKeyType(newValue, value, targetType, propertyName); | ||
// if value is an array try to get its custom array type | ||
@@ -89,4 +89,5 @@ var arrayType_1 = value[valueKey] instanceof Array ? this.getReflectedType(targetType, propertyName) : undefined; | ||
// if its deserialization then type if required | ||
if (this.transformationType === "plainToClass" && !type && subValue instanceof Object && !(subValue instanceof Date)) | ||
throw new Error("Cannot determine type for " + targetType.name + "." + propertyName + ", did you forget to specify a @Type?"); | ||
// if we uncomment this types like string[] will not work | ||
// if (this.transformationType === "plainToClass" && !type && subValue instanceof Object && !(subValue instanceof Date)) | ||
// throw new Error(`Cannot determine type for ${(targetType as any).name }.${propertyName}, did you forget to specify a @Type?`); | ||
// if newValue is a source object that has method that match newKeyName then skip it | ||
@@ -117,7 +118,7 @@ var hasDescriptor = false; | ||
}; | ||
TransformOperationExecutor.prototype.getKeyType = function (object, target, key) { | ||
TransformOperationExecutor.prototype.getKeyType = function (newObject, object, target, key) { | ||
if (!target) | ||
return undefined; | ||
var metadata = index_1.defaultMetadataStorage.findTypeMetadata(target, key); | ||
return metadata ? metadata.typeFunction(object) : undefined; | ||
return metadata ? metadata.typeFunction({ newObject: newObject, transformingObject: object, property: key }) : undefined; | ||
}; | ||
@@ -124,0 +125,0 @@ TransformOperationExecutor.prototype.getReflectedType = function (target, propertyName) { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
103929
753