backend v4 half
This commit is contained in:
+62
@@ -0,0 +1,62 @@
|
||||
var __assign = (this && this.__assign) || function () {
|
||||
__assign = Object.assign || function(t) {
|
||||
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
||||
s = arguments[i];
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
||||
t[p] = s[p];
|
||||
}
|
||||
return t;
|
||||
};
|
||||
return __assign.apply(this, arguments);
|
||||
};
|
||||
import { TransformOperationExecutor } from './TransformOperationExecutor';
|
||||
import { TransformationType } from './enums';
|
||||
import { defaultOptions } from './constants/default-options.constant';
|
||||
var ClassTransformer = /** @class */ (function () {
|
||||
function ClassTransformer() {
|
||||
}
|
||||
ClassTransformer.prototype.instanceToPlain = function (object, options) {
|
||||
var executor = new TransformOperationExecutor(TransformationType.CLASS_TO_PLAIN, __assign(__assign({}, defaultOptions), options));
|
||||
return executor.transform(undefined, object, undefined, undefined, undefined, undefined);
|
||||
};
|
||||
ClassTransformer.prototype.classToPlainFromExist = function (object, plainObject, options) {
|
||||
var executor = new TransformOperationExecutor(TransformationType.CLASS_TO_PLAIN, __assign(__assign({}, defaultOptions), options));
|
||||
return executor.transform(plainObject, object, undefined, undefined, undefined, undefined);
|
||||
};
|
||||
ClassTransformer.prototype.plainToInstance = function (cls, plain, options) {
|
||||
var executor = new TransformOperationExecutor(TransformationType.PLAIN_TO_CLASS, __assign(__assign({}, defaultOptions), options));
|
||||
return executor.transform(undefined, plain, cls, undefined, undefined, undefined);
|
||||
};
|
||||
ClassTransformer.prototype.plainToClassFromExist = function (clsObject, plain, options) {
|
||||
var executor = new TransformOperationExecutor(TransformationType.PLAIN_TO_CLASS, __assign(__assign({}, defaultOptions), options));
|
||||
return executor.transform(clsObject, plain, undefined, undefined, undefined, undefined);
|
||||
};
|
||||
ClassTransformer.prototype.instanceToInstance = function (object, options) {
|
||||
var executor = new TransformOperationExecutor(TransformationType.CLASS_TO_CLASS, __assign(__assign({}, defaultOptions), options));
|
||||
return executor.transform(undefined, object, undefined, undefined, undefined, undefined);
|
||||
};
|
||||
ClassTransformer.prototype.classToClassFromExist = function (object, fromObject, options) {
|
||||
var executor = new TransformOperationExecutor(TransformationType.CLASS_TO_CLASS, __assign(__assign({}, defaultOptions), options));
|
||||
return executor.transform(fromObject, object, undefined, undefined, undefined, undefined);
|
||||
};
|
||||
ClassTransformer.prototype.serialize = function (object, options) {
|
||||
return JSON.stringify(this.instanceToPlain(object, options));
|
||||
};
|
||||
/**
|
||||
* Deserializes given JSON string to a object of the given class.
|
||||
*/
|
||||
ClassTransformer.prototype.deserialize = function (cls, json, options) {
|
||||
var jsonObject = JSON.parse(json);
|
||||
return this.plainToInstance(cls, jsonObject, options);
|
||||
};
|
||||
/**
|
||||
* Deserializes given JSON string to an array of objects of the given class.
|
||||
*/
|
||||
ClassTransformer.prototype.deserializeArray = function (cls, json, options) {
|
||||
var jsonObject = JSON.parse(json);
|
||||
return this.plainToInstance(cls, jsonObject, options);
|
||||
};
|
||||
return ClassTransformer;
|
||||
}());
|
||||
export { ClassTransformer };
|
||||
//# sourceMappingURL=ClassTransformer.js.map
|
||||
+1
File diff suppressed because one or more lines are too long
+212
@@ -0,0 +1,212 @@
|
||||
import { TransformationType } from './enums';
|
||||
/**
|
||||
* Storage all library metadata.
|
||||
*/
|
||||
var MetadataStorage = /** @class */ (function () {
|
||||
function MetadataStorage() {
|
||||
// -------------------------------------------------------------------------
|
||||
// Properties
|
||||
// -------------------------------------------------------------------------
|
||||
this._typeMetadatas = new Map();
|
||||
this._transformMetadatas = new Map();
|
||||
this._exposeMetadatas = new Map();
|
||||
this._excludeMetadatas = new Map();
|
||||
this._ancestorsMap = new Map();
|
||||
}
|
||||
// -------------------------------------------------------------------------
|
||||
// Adder Methods
|
||||
// -------------------------------------------------------------------------
|
||||
MetadataStorage.prototype.addTypeMetadata = function (metadata) {
|
||||
if (!this._typeMetadatas.has(metadata.target)) {
|
||||
this._typeMetadatas.set(metadata.target, new Map());
|
||||
}
|
||||
this._typeMetadatas.get(metadata.target).set(metadata.propertyName, metadata);
|
||||
};
|
||||
MetadataStorage.prototype.addTransformMetadata = function (metadata) {
|
||||
if (!this._transformMetadatas.has(metadata.target)) {
|
||||
this._transformMetadatas.set(metadata.target, new Map());
|
||||
}
|
||||
if (!this._transformMetadatas.get(metadata.target).has(metadata.propertyName)) {
|
||||
this._transformMetadatas.get(metadata.target).set(metadata.propertyName, []);
|
||||
}
|
||||
this._transformMetadatas.get(metadata.target).get(metadata.propertyName).push(metadata);
|
||||
};
|
||||
MetadataStorage.prototype.addExposeMetadata = function (metadata) {
|
||||
if (!this._exposeMetadatas.has(metadata.target)) {
|
||||
this._exposeMetadatas.set(metadata.target, new Map());
|
||||
}
|
||||
this._exposeMetadatas.get(metadata.target).set(metadata.propertyName, metadata);
|
||||
};
|
||||
MetadataStorage.prototype.addExcludeMetadata = function (metadata) {
|
||||
if (!this._excludeMetadatas.has(metadata.target)) {
|
||||
this._excludeMetadatas.set(metadata.target, new Map());
|
||||
}
|
||||
this._excludeMetadatas.get(metadata.target).set(metadata.propertyName, metadata);
|
||||
};
|
||||
// -------------------------------------------------------------------------
|
||||
// Public Methods
|
||||
// -------------------------------------------------------------------------
|
||||
MetadataStorage.prototype.findTransformMetadatas = function (target, propertyName, transformationType) {
|
||||
return this.findMetadatas(this._transformMetadatas, target, propertyName).filter(function (metadata) {
|
||||
if (!metadata.options)
|
||||
return true;
|
||||
if (metadata.options.toClassOnly === true && metadata.options.toPlainOnly === true)
|
||||
return true;
|
||||
if (metadata.options.toClassOnly === true) {
|
||||
return (transformationType === TransformationType.CLASS_TO_CLASS ||
|
||||
transformationType === TransformationType.PLAIN_TO_CLASS);
|
||||
}
|
||||
if (metadata.options.toPlainOnly === true) {
|
||||
return transformationType === TransformationType.CLASS_TO_PLAIN;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
};
|
||||
MetadataStorage.prototype.findExcludeMetadata = function (target, propertyName) {
|
||||
return this.findMetadata(this._excludeMetadatas, target, propertyName);
|
||||
};
|
||||
MetadataStorage.prototype.findExposeMetadata = function (target, propertyName) {
|
||||
return this.findMetadata(this._exposeMetadatas, target, propertyName);
|
||||
};
|
||||
MetadataStorage.prototype.findExposeMetadataByCustomName = function (target, name) {
|
||||
return this.getExposedMetadatas(target).find(function (metadata) {
|
||||
return metadata.options && metadata.options.name === name;
|
||||
});
|
||||
};
|
||||
MetadataStorage.prototype.findTypeMetadata = function (target, propertyName) {
|
||||
return this.findMetadata(this._typeMetadatas, target, propertyName);
|
||||
};
|
||||
MetadataStorage.prototype.getStrategy = function (target) {
|
||||
var excludeMap = this._excludeMetadatas.get(target);
|
||||
var exclude = excludeMap && excludeMap.get(undefined);
|
||||
var exposeMap = this._exposeMetadatas.get(target);
|
||||
var expose = exposeMap && exposeMap.get(undefined);
|
||||
if ((exclude && expose) || (!exclude && !expose))
|
||||
return 'none';
|
||||
return exclude ? 'excludeAll' : 'exposeAll';
|
||||
};
|
||||
MetadataStorage.prototype.getExposedMetadatas = function (target) {
|
||||
return this.getMetadata(this._exposeMetadatas, target);
|
||||
};
|
||||
MetadataStorage.prototype.getExcludedMetadatas = function (target) {
|
||||
return this.getMetadata(this._excludeMetadatas, target);
|
||||
};
|
||||
MetadataStorage.prototype.getExposedProperties = function (target, transformationType) {
|
||||
return this.getExposedMetadatas(target)
|
||||
.filter(function (metadata) {
|
||||
if (!metadata.options)
|
||||
return true;
|
||||
if (metadata.options.toClassOnly === true && metadata.options.toPlainOnly === true)
|
||||
return true;
|
||||
if (metadata.options.toClassOnly === true) {
|
||||
return (transformationType === TransformationType.CLASS_TO_CLASS ||
|
||||
transformationType === TransformationType.PLAIN_TO_CLASS);
|
||||
}
|
||||
if (metadata.options.toPlainOnly === true) {
|
||||
return transformationType === TransformationType.CLASS_TO_PLAIN;
|
||||
}
|
||||
return true;
|
||||
})
|
||||
.map(function (metadata) { return metadata.propertyName; });
|
||||
};
|
||||
MetadataStorage.prototype.getExcludedProperties = function (target, transformationType) {
|
||||
return this.getExcludedMetadatas(target)
|
||||
.filter(function (metadata) {
|
||||
if (!metadata.options)
|
||||
return true;
|
||||
if (metadata.options.toClassOnly === true && metadata.options.toPlainOnly === true)
|
||||
return true;
|
||||
if (metadata.options.toClassOnly === true) {
|
||||
return (transformationType === TransformationType.CLASS_TO_CLASS ||
|
||||
transformationType === TransformationType.PLAIN_TO_CLASS);
|
||||
}
|
||||
if (metadata.options.toPlainOnly === true) {
|
||||
return transformationType === TransformationType.CLASS_TO_PLAIN;
|
||||
}
|
||||
return true;
|
||||
})
|
||||
.map(function (metadata) { return metadata.propertyName; });
|
||||
};
|
||||
MetadataStorage.prototype.clear = function () {
|
||||
this._typeMetadatas.clear();
|
||||
this._exposeMetadatas.clear();
|
||||
this._excludeMetadatas.clear();
|
||||
this._ancestorsMap.clear();
|
||||
};
|
||||
// -------------------------------------------------------------------------
|
||||
// Private Methods
|
||||
// -------------------------------------------------------------------------
|
||||
MetadataStorage.prototype.getMetadata = function (metadatas, target) {
|
||||
var metadataFromTargetMap = metadatas.get(target);
|
||||
var metadataFromTarget;
|
||||
if (metadataFromTargetMap) {
|
||||
metadataFromTarget = Array.from(metadataFromTargetMap.values()).filter(function (meta) { return meta.propertyName !== undefined; });
|
||||
}
|
||||
var metadataFromAncestors = [];
|
||||
for (var _i = 0, _a = this.getAncestors(target); _i < _a.length; _i++) {
|
||||
var ancestor = _a[_i];
|
||||
var ancestorMetadataMap = metadatas.get(ancestor);
|
||||
if (ancestorMetadataMap) {
|
||||
var metadataFromAncestor = Array.from(ancestorMetadataMap.values()).filter(function (meta) { return meta.propertyName !== undefined; });
|
||||
metadataFromAncestors.push.apply(metadataFromAncestors, metadataFromAncestor);
|
||||
}
|
||||
}
|
||||
return metadataFromAncestors.concat(metadataFromTarget || []);
|
||||
};
|
||||
MetadataStorage.prototype.findMetadata = function (metadatas, target, propertyName) {
|
||||
var metadataFromTargetMap = metadatas.get(target);
|
||||
if (metadataFromTargetMap) {
|
||||
var metadataFromTarget = metadataFromTargetMap.get(propertyName);
|
||||
if (metadataFromTarget) {
|
||||
return metadataFromTarget;
|
||||
}
|
||||
}
|
||||
for (var _i = 0, _a = this.getAncestors(target); _i < _a.length; _i++) {
|
||||
var ancestor = _a[_i];
|
||||
var ancestorMetadataMap = metadatas.get(ancestor);
|
||||
if (ancestorMetadataMap) {
|
||||
var ancestorResult = ancestorMetadataMap.get(propertyName);
|
||||
if (ancestorResult) {
|
||||
return ancestorResult;
|
||||
}
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
MetadataStorage.prototype.findMetadatas = function (metadatas, target, propertyName) {
|
||||
var metadataFromTargetMap = metadatas.get(target);
|
||||
var metadataFromTarget;
|
||||
if (metadataFromTargetMap) {
|
||||
metadataFromTarget = metadataFromTargetMap.get(propertyName);
|
||||
}
|
||||
var metadataFromAncestorsTarget = [];
|
||||
for (var _i = 0, _a = this.getAncestors(target); _i < _a.length; _i++) {
|
||||
var ancestor = _a[_i];
|
||||
var ancestorMetadataMap = metadatas.get(ancestor);
|
||||
if (ancestorMetadataMap) {
|
||||
if (ancestorMetadataMap.has(propertyName)) {
|
||||
metadataFromAncestorsTarget.push.apply(metadataFromAncestorsTarget, ancestorMetadataMap.get(propertyName));
|
||||
}
|
||||
}
|
||||
}
|
||||
return metadataFromAncestorsTarget
|
||||
.slice()
|
||||
.reverse()
|
||||
.concat((metadataFromTarget || []).slice().reverse());
|
||||
};
|
||||
MetadataStorage.prototype.getAncestors = function (target) {
|
||||
if (!target)
|
||||
return [];
|
||||
if (!this._ancestorsMap.has(target)) {
|
||||
var ancestors = [];
|
||||
for (var baseClass = Object.getPrototypeOf(target.prototype.constructor); typeof baseClass.prototype !== 'undefined'; baseClass = Object.getPrototypeOf(baseClass.prototype.constructor)) {
|
||||
ancestors.push(baseClass);
|
||||
}
|
||||
this._ancestorsMap.set(target, ancestors);
|
||||
}
|
||||
return this._ancestorsMap.get(target);
|
||||
};
|
||||
return MetadataStorage;
|
||||
}());
|
||||
export { MetadataStorage };
|
||||
//# sourceMappingURL=MetadataStorage.js.map
|
||||
+1
File diff suppressed because one or more lines are too long
Generated
Vendored
+499
@@ -0,0 +1,499 @@
|
||||
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
||||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
||||
if (ar || !(i in from)) {
|
||||
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
||||
ar[i] = from[i];
|
||||
}
|
||||
}
|
||||
return to.concat(ar || Array.prototype.slice.call(from));
|
||||
};
|
||||
import { defaultMetadataStorage } from './storage';
|
||||
import { TransformationType } from './enums';
|
||||
import { getGlobal, isPromise } from './utils';
|
||||
function instantiateArrayType(arrayType) {
|
||||
var array = new arrayType();
|
||||
if (!(array instanceof Set) && !('push' in array)) {
|
||||
return [];
|
||||
}
|
||||
return array;
|
||||
}
|
||||
var TransformOperationExecutor = /** @class */ (function () {
|
||||
// -------------------------------------------------------------------------
|
||||
// Constructor
|
||||
// -------------------------------------------------------------------------
|
||||
function TransformOperationExecutor(transformationType, options) {
|
||||
this.transformationType = transformationType;
|
||||
this.options = options;
|
||||
// -------------------------------------------------------------------------
|
||||
// Private Properties
|
||||
// -------------------------------------------------------------------------
|
||||
this.recursionStack = new Set();
|
||||
}
|
||||
// -------------------------------------------------------------------------
|
||||
// Public Methods
|
||||
// -------------------------------------------------------------------------
|
||||
TransformOperationExecutor.prototype.transform = function (source, value, targetType, arrayType, isMap, level) {
|
||||
var _this = this;
|
||||
if (level === void 0) { level = 0; }
|
||||
if (Array.isArray(value) || value instanceof Set) {
|
||||
var newValue_1 = arrayType && this.transformationType === TransformationType.PLAIN_TO_CLASS
|
||||
? instantiateArrayType(arrayType)
|
||||
: [];
|
||||
value.forEach(function (subValue, index) {
|
||||
var subSource = source ? source[index] : undefined;
|
||||
if (!_this.options.enableCircularCheck || !_this.isCircular(subValue)) {
|
||||
var realTargetType = void 0;
|
||||
if (typeof targetType !== 'function' &&
|
||||
targetType &&
|
||||
targetType.options &&
|
||||
targetType.options.discriminator &&
|
||||
targetType.options.discriminator.property &&
|
||||
targetType.options.discriminator.subTypes) {
|
||||
if (_this.transformationType === TransformationType.PLAIN_TO_CLASS) {
|
||||
realTargetType = targetType.options.discriminator.subTypes.find(function (subType) {
|
||||
return subType.name === subValue[targetType.options.discriminator.property];
|
||||
});
|
||||
var options = { newObject: newValue_1, object: subValue, property: undefined };
|
||||
var newType = targetType.typeFunction(options);
|
||||
realTargetType === undefined ? (realTargetType = newType) : (realTargetType = realTargetType.value);
|
||||
if (!targetType.options.keepDiscriminatorProperty)
|
||||
delete subValue[targetType.options.discriminator.property];
|
||||
}
|
||||
if (_this.transformationType === TransformationType.CLASS_TO_CLASS) {
|
||||
realTargetType = subValue.constructor;
|
||||
}
|
||||
if (_this.transformationType === TransformationType.CLASS_TO_PLAIN) {
|
||||
subValue[targetType.options.discriminator.property] = targetType.options.discriminator.subTypes.find(function (subType) { return subType.value === subValue.constructor; }).name;
|
||||
}
|
||||
}
|
||||
else {
|
||||
realTargetType = targetType;
|
||||
}
|
||||
var value_1 = _this.transform(subSource, subValue, realTargetType, undefined, subValue instanceof Map, level + 1);
|
||||
if (newValue_1 instanceof Set) {
|
||||
newValue_1.add(value_1);
|
||||
}
|
||||
else {
|
||||
newValue_1.push(value_1);
|
||||
}
|
||||
}
|
||||
else if (_this.transformationType === TransformationType.CLASS_TO_CLASS) {
|
||||
if (newValue_1 instanceof Set) {
|
||||
newValue_1.add(subValue);
|
||||
}
|
||||
else {
|
||||
newValue_1.push(subValue);
|
||||
}
|
||||
}
|
||||
});
|
||||
return newValue_1;
|
||||
}
|
||||
else if (targetType === String && !isMap) {
|
||||
if (value === null || value === undefined)
|
||||
return value;
|
||||
return String(value);
|
||||
}
|
||||
else if (targetType === Number && !isMap) {
|
||||
if (value === null || value === undefined)
|
||||
return value;
|
||||
return Number(value);
|
||||
}
|
||||
else if (targetType === Boolean && !isMap) {
|
||||
if (value === null || value === undefined)
|
||||
return value;
|
||||
return Boolean(value);
|
||||
}
|
||||
else if ((targetType === Date || value instanceof Date) && !isMap) {
|
||||
if (value instanceof Date) {
|
||||
return new Date(value.valueOf());
|
||||
}
|
||||
if (value === null || value === undefined)
|
||||
return value;
|
||||
return new Date(value);
|
||||
}
|
||||
else if (!!getGlobal().Buffer && (targetType === Buffer || value instanceof Buffer) && !isMap) {
|
||||
if (value === null || value === undefined)
|
||||
return value;
|
||||
return Buffer.from(value);
|
||||
}
|
||||
else if (isPromise(value) && !isMap) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
value.then(function (data) { return resolve(_this.transform(undefined, data, targetType, undefined, undefined, level + 1)); }, reject);
|
||||
});
|
||||
}
|
||||
else if (!isMap && value !== null && typeof value === 'object' && typeof value.then === 'function') {
|
||||
// Note: We should not enter this, as promise has been handled above
|
||||
// This option simply returns the Promise preventing a JS error from happening and should be an inaccessible path.
|
||||
return value; // skip promise transformation
|
||||
}
|
||||
else if (typeof value === 'object' && value !== null) {
|
||||
// try to guess the type
|
||||
if (!targetType && value.constructor !== Object /* && TransformationType === TransformationType.CLASS_TO_PLAIN*/)
|
||||
if (!Array.isArray(value) && value.constructor === Array) {
|
||||
// Somebody attempts to convert special Array like object to Array, eg:
|
||||
// const evilObject = { '100000000': '100000000', __proto__: [] };
|
||||
// This could be used to cause Denial-of-service attack so we don't allow it.
|
||||
// See prevent-array-bomb.spec.ts for more details.
|
||||
}
|
||||
else {
|
||||
// We are good we can use the built-in constructor
|
||||
targetType = value.constructor;
|
||||
}
|
||||
if (!targetType && source)
|
||||
targetType = source.constructor;
|
||||
if (this.options.enableCircularCheck) {
|
||||
// add transformed type to prevent circular references
|
||||
this.recursionStack.add(value);
|
||||
}
|
||||
var keys = this.getKeys(targetType, value, isMap);
|
||||
var newValue = source ? source : {};
|
||||
if (!source &&
|
||||
(this.transformationType === TransformationType.PLAIN_TO_CLASS ||
|
||||
this.transformationType === TransformationType.CLASS_TO_CLASS)) {
|
||||
if (isMap) {
|
||||
newValue = new Map();
|
||||
}
|
||||
else if (targetType) {
|
||||
newValue = new targetType();
|
||||
}
|
||||
else {
|
||||
newValue = {};
|
||||
}
|
||||
}
|
||||
var _loop_1 = function (key) {
|
||||
if (key === '__proto__' || key === 'constructor') {
|
||||
return "continue";
|
||||
}
|
||||
var valueKey = key;
|
||||
var newValueKey = key, propertyName = key;
|
||||
if (!this_1.options.ignoreDecorators && targetType) {
|
||||
if (this_1.transformationType === TransformationType.PLAIN_TO_CLASS) {
|
||||
var exposeMetadata = defaultMetadataStorage.findExposeMetadataByCustomName(targetType, key);
|
||||
if (exposeMetadata) {
|
||||
propertyName = exposeMetadata.propertyName;
|
||||
newValueKey = exposeMetadata.propertyName;
|
||||
}
|
||||
}
|
||||
else if (this_1.transformationType === TransformationType.CLASS_TO_PLAIN ||
|
||||
this_1.transformationType === TransformationType.CLASS_TO_CLASS) {
|
||||
var exposeMetadata = defaultMetadataStorage.findExposeMetadata(targetType, key);
|
||||
if (exposeMetadata && exposeMetadata.options && exposeMetadata.options.name) {
|
||||
newValueKey = exposeMetadata.options.name;
|
||||
}
|
||||
}
|
||||
}
|
||||
// get a subvalue
|
||||
var subValue = undefined;
|
||||
if (this_1.transformationType === TransformationType.PLAIN_TO_CLASS) {
|
||||
/**
|
||||
* This section is added for the following report:
|
||||
* https://github.com/typestack/class-transformer/issues/596
|
||||
*
|
||||
* We should not call functions or constructors when transforming to class.
|
||||
*/
|
||||
subValue = value[valueKey];
|
||||
}
|
||||
else {
|
||||
if (value instanceof Map) {
|
||||
subValue = value.get(valueKey);
|
||||
}
|
||||
else if (value[valueKey] instanceof Function) {
|
||||
subValue = value[valueKey]();
|
||||
}
|
||||
else {
|
||||
subValue = value[valueKey];
|
||||
}
|
||||
}
|
||||
// determine a type
|
||||
var type = undefined, isSubValueMap = subValue instanceof Map;
|
||||
if (targetType && isMap) {
|
||||
type = targetType;
|
||||
}
|
||||
else if (targetType) {
|
||||
var metadata_1 = defaultMetadataStorage.findTypeMetadata(targetType, propertyName);
|
||||
if (metadata_1) {
|
||||
var options = { newObject: newValue, object: value, property: propertyName };
|
||||
var newType = metadata_1.typeFunction ? metadata_1.typeFunction(options) : metadata_1.reflectedType;
|
||||
if (metadata_1.options &&
|
||||
metadata_1.options.discriminator &&
|
||||
metadata_1.options.discriminator.property &&
|
||||
metadata_1.options.discriminator.subTypes) {
|
||||
if (!(value[valueKey] instanceof Array)) {
|
||||
if (this_1.transformationType === TransformationType.PLAIN_TO_CLASS) {
|
||||
type = metadata_1.options.discriminator.subTypes.find(function (subType) {
|
||||
if (subValue && subValue instanceof Object && metadata_1.options.discriminator.property in subValue) {
|
||||
return subType.name === subValue[metadata_1.options.discriminator.property];
|
||||
}
|
||||
});
|
||||
type === undefined ? (type = newType) : (type = type.value);
|
||||
if (!metadata_1.options.keepDiscriminatorProperty) {
|
||||
if (subValue && subValue instanceof Object && metadata_1.options.discriminator.property in subValue) {
|
||||
delete subValue[metadata_1.options.discriminator.property];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this_1.transformationType === TransformationType.CLASS_TO_CLASS) {
|
||||
type = subValue.constructor;
|
||||
}
|
||||
if (this_1.transformationType === TransformationType.CLASS_TO_PLAIN) {
|
||||
if (subValue) {
|
||||
subValue[metadata_1.options.discriminator.property] = metadata_1.options.discriminator.subTypes.find(function (subType) { return subType.value === subValue.constructor; }).name;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
type = metadata_1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
type = newType;
|
||||
}
|
||||
isSubValueMap = isSubValueMap || metadata_1.reflectedType === Map;
|
||||
}
|
||||
else if (this_1.options.targetMaps) {
|
||||
// try to find a type in target maps
|
||||
this_1.options.targetMaps
|
||||
.filter(function (map) { return map.target === targetType && !!map.properties[propertyName]; })
|
||||
.forEach(function (map) { return (type = map.properties[propertyName]); });
|
||||
}
|
||||
else if (this_1.options.enableImplicitConversion &&
|
||||
this_1.transformationType === TransformationType.PLAIN_TO_CLASS) {
|
||||
// if we have no registererd type via the @Type() decorator then we check if we have any
|
||||
// type declarations in reflect-metadata (type declaration is emited only if some decorator is added to the property.)
|
||||
var reflectedType = Reflect.getMetadata('design:type', targetType.prototype, propertyName);
|
||||
if (reflectedType) {
|
||||
type = reflectedType;
|
||||
}
|
||||
}
|
||||
}
|
||||
// if value is an array try to get its custom array type
|
||||
var arrayType_1 = Array.isArray(value[valueKey])
|
||||
? this_1.getReflectedType(targetType, propertyName)
|
||||
: undefined;
|
||||
// const subValueKey = TransformationType === TransformationType.PLAIN_TO_CLASS && newKeyName ? newKeyName : key;
|
||||
var subSource = source ? source[valueKey] : undefined;
|
||||
// if its deserialization then type if required
|
||||
// if we uncomment this types like string[] will not work
|
||||
// if (this.transformationType === TransformationType.PLAIN_TO_CLASS && !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
|
||||
if (newValue.constructor.prototype) {
|
||||
var descriptor = Object.getOwnPropertyDescriptor(newValue.constructor.prototype, newValueKey);
|
||||
if ((this_1.transformationType === TransformationType.PLAIN_TO_CLASS ||
|
||||
this_1.transformationType === TransformationType.CLASS_TO_CLASS) &&
|
||||
// eslint-disable-next-line @typescript-eslint/unbound-method
|
||||
((descriptor && !descriptor.set) || newValue[newValueKey] instanceof Function))
|
||||
return "continue";
|
||||
}
|
||||
if (!this_1.options.enableCircularCheck || !this_1.isCircular(subValue)) {
|
||||
var transformKey = this_1.transformationType === TransformationType.PLAIN_TO_CLASS ? newValueKey : key;
|
||||
var finalValue = void 0;
|
||||
if (this_1.transformationType === TransformationType.CLASS_TO_PLAIN) {
|
||||
// Get original value
|
||||
finalValue = value[transformKey];
|
||||
// Apply custom transformation
|
||||
finalValue = this_1.applyCustomTransformations(finalValue, targetType, transformKey, value, this_1.transformationType);
|
||||
// If nothing change, it means no custom transformation was applied, so use the subValue.
|
||||
finalValue = value[transformKey] === finalValue ? subValue : finalValue;
|
||||
// Apply the default transformation
|
||||
finalValue = this_1.transform(subSource, finalValue, type, arrayType_1, isSubValueMap, level + 1);
|
||||
}
|
||||
else {
|
||||
if (subValue === undefined && this_1.options.exposeDefaultValues) {
|
||||
// Set default value if nothing provided
|
||||
finalValue = newValue[newValueKey];
|
||||
}
|
||||
else {
|
||||
finalValue = this_1.transform(subSource, subValue, type, arrayType_1, isSubValueMap, level + 1);
|
||||
finalValue = this_1.applyCustomTransformations(finalValue, targetType, transformKey, value, this_1.transformationType);
|
||||
}
|
||||
}
|
||||
if (finalValue !== undefined || this_1.options.exposeUnsetFields) {
|
||||
if (newValue instanceof Map) {
|
||||
newValue.set(newValueKey, finalValue);
|
||||
}
|
||||
else {
|
||||
newValue[newValueKey] = finalValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (this_1.transformationType === TransformationType.CLASS_TO_CLASS) {
|
||||
var finalValue = subValue;
|
||||
finalValue = this_1.applyCustomTransformations(finalValue, targetType, key, value, this_1.transformationType);
|
||||
if (finalValue !== undefined || this_1.options.exposeUnsetFields) {
|
||||
if (newValue instanceof Map) {
|
||||
newValue.set(newValueKey, finalValue);
|
||||
}
|
||||
else {
|
||||
newValue[newValueKey] = finalValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
var this_1 = this;
|
||||
// traverse over keys
|
||||
for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) {
|
||||
var key = keys_1[_i];
|
||||
_loop_1(key);
|
||||
}
|
||||
if (this.options.enableCircularCheck) {
|
||||
this.recursionStack.delete(value);
|
||||
}
|
||||
return newValue;
|
||||
}
|
||||
else {
|
||||
return value;
|
||||
}
|
||||
};
|
||||
TransformOperationExecutor.prototype.applyCustomTransformations = function (value, target, key, obj, transformationType) {
|
||||
var _this = this;
|
||||
var metadatas = defaultMetadataStorage.findTransformMetadatas(target, key, this.transformationType);
|
||||
// apply versioning options
|
||||
if (this.options.version !== undefined) {
|
||||
metadatas = metadatas.filter(function (metadata) {
|
||||
if (!metadata.options)
|
||||
return true;
|
||||
return _this.checkVersion(metadata.options.since, metadata.options.until);
|
||||
});
|
||||
}
|
||||
// apply grouping options
|
||||
if (this.options.groups && this.options.groups.length) {
|
||||
metadatas = metadatas.filter(function (metadata) {
|
||||
if (!metadata.options)
|
||||
return true;
|
||||
return _this.checkGroups(metadata.options.groups);
|
||||
});
|
||||
}
|
||||
else {
|
||||
metadatas = metadatas.filter(function (metadata) {
|
||||
return !metadata.options || !metadata.options.groups || !metadata.options.groups.length;
|
||||
});
|
||||
}
|
||||
metadatas.forEach(function (metadata) {
|
||||
value = metadata.transformFn({ value: value, key: key, obj: obj, type: transformationType, options: _this.options });
|
||||
});
|
||||
return value;
|
||||
};
|
||||
// preventing circular references
|
||||
TransformOperationExecutor.prototype.isCircular = function (object) {
|
||||
return this.recursionStack.has(object);
|
||||
};
|
||||
TransformOperationExecutor.prototype.getReflectedType = function (target, propertyName) {
|
||||
if (!target)
|
||||
return undefined;
|
||||
var meta = defaultMetadataStorage.findTypeMetadata(target, propertyName);
|
||||
return meta ? meta.reflectedType : undefined;
|
||||
};
|
||||
TransformOperationExecutor.prototype.getKeys = function (target, object, isMap) {
|
||||
var _this = this;
|
||||
// determine exclusion strategy
|
||||
var strategy = defaultMetadataStorage.getStrategy(target);
|
||||
if (strategy === 'none')
|
||||
strategy = this.options.strategy || 'exposeAll'; // exposeAll is default strategy
|
||||
// get all keys that need to expose
|
||||
var keys = [];
|
||||
if (strategy === 'exposeAll' || isMap) {
|
||||
if (object instanceof Map) {
|
||||
keys = Array.from(object.keys());
|
||||
}
|
||||
else {
|
||||
keys = Object.keys(object);
|
||||
}
|
||||
}
|
||||
if (isMap) {
|
||||
// expose & exclude do not apply for map keys only to fields
|
||||
return keys;
|
||||
}
|
||||
/**
|
||||
* If decorators are ignored but we don't want the extraneous values, then we use the
|
||||
* metadata to decide which property is needed, but doesn't apply the decorator effect.
|
||||
*/
|
||||
if (this.options.ignoreDecorators && this.options.excludeExtraneousValues && target) {
|
||||
var exposedProperties = defaultMetadataStorage.getExposedProperties(target, this.transformationType);
|
||||
var excludedProperties = defaultMetadataStorage.getExcludedProperties(target, this.transformationType);
|
||||
keys = __spreadArray(__spreadArray([], exposedProperties, true), excludedProperties, true);
|
||||
}
|
||||
if (!this.options.ignoreDecorators && target) {
|
||||
// add all exposed to list of keys
|
||||
var exposedProperties = defaultMetadataStorage.getExposedProperties(target, this.transformationType);
|
||||
if (this.transformationType === TransformationType.PLAIN_TO_CLASS) {
|
||||
exposedProperties = exposedProperties.map(function (key) {
|
||||
var exposeMetadata = defaultMetadataStorage.findExposeMetadata(target, key);
|
||||
if (exposeMetadata && exposeMetadata.options && exposeMetadata.options.name) {
|
||||
return exposeMetadata.options.name;
|
||||
}
|
||||
return key;
|
||||
});
|
||||
}
|
||||
if (this.options.excludeExtraneousValues) {
|
||||
keys = exposedProperties;
|
||||
}
|
||||
else {
|
||||
keys = keys.concat(exposedProperties);
|
||||
}
|
||||
// exclude excluded properties
|
||||
var excludedProperties_1 = defaultMetadataStorage.getExcludedProperties(target, this.transformationType);
|
||||
if (excludedProperties_1.length > 0) {
|
||||
keys = keys.filter(function (key) {
|
||||
return !excludedProperties_1.includes(key);
|
||||
});
|
||||
}
|
||||
// apply versioning options
|
||||
if (this.options.version !== undefined) {
|
||||
keys = keys.filter(function (key) {
|
||||
var exposeMetadata = defaultMetadataStorage.findExposeMetadata(target, key);
|
||||
if (!exposeMetadata || !exposeMetadata.options)
|
||||
return true;
|
||||
return _this.checkVersion(exposeMetadata.options.since, exposeMetadata.options.until);
|
||||
});
|
||||
}
|
||||
// apply grouping options
|
||||
if (this.options.groups && this.options.groups.length) {
|
||||
keys = keys.filter(function (key) {
|
||||
var exposeMetadata = defaultMetadataStorage.findExposeMetadata(target, key);
|
||||
if (!exposeMetadata || !exposeMetadata.options)
|
||||
return true;
|
||||
return _this.checkGroups(exposeMetadata.options.groups);
|
||||
});
|
||||
}
|
||||
else {
|
||||
keys = keys.filter(function (key) {
|
||||
var exposeMetadata = defaultMetadataStorage.findExposeMetadata(target, key);
|
||||
return (!exposeMetadata ||
|
||||
!exposeMetadata.options ||
|
||||
!exposeMetadata.options.groups ||
|
||||
!exposeMetadata.options.groups.length);
|
||||
});
|
||||
}
|
||||
}
|
||||
// exclude prefixed properties
|
||||
if (this.options.excludePrefixes && this.options.excludePrefixes.length) {
|
||||
keys = keys.filter(function (key) {
|
||||
return _this.options.excludePrefixes.every(function (prefix) {
|
||||
return key.substr(0, prefix.length) !== prefix;
|
||||
});
|
||||
});
|
||||
}
|
||||
// make sure we have unique keys
|
||||
keys = keys.filter(function (key, index, self) {
|
||||
return self.indexOf(key) === index;
|
||||
});
|
||||
return keys;
|
||||
};
|
||||
TransformOperationExecutor.prototype.checkVersion = function (since, until) {
|
||||
var decision = true;
|
||||
if (decision && since)
|
||||
decision = this.options.version >= since;
|
||||
if (decision && until)
|
||||
decision = this.options.version < until;
|
||||
return decision;
|
||||
};
|
||||
TransformOperationExecutor.prototype.checkGroups = function (groups) {
|
||||
if (!groups)
|
||||
return true;
|
||||
return this.options.groups.some(function (optionGroup) { return groups.includes(optionGroup); });
|
||||
};
|
||||
return TransformOperationExecutor;
|
||||
}());
|
||||
export { TransformOperationExecutor };
|
||||
//# sourceMappingURL=TransformOperationExecutor.js.map
|
||||
Generated
Vendored
+1
File diff suppressed because one or more lines are too long
Generated
Vendored
+17
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* These are the default options used by any transformation operation.
|
||||
*/
|
||||
export var defaultOptions = {
|
||||
enableCircularCheck: false,
|
||||
enableImplicitConversion: false,
|
||||
excludeExtraneousValues: false,
|
||||
excludePrefixes: undefined,
|
||||
exposeDefaultValues: false,
|
||||
exposeUnsetFields: true,
|
||||
groups: undefined,
|
||||
ignoreDecorators: false,
|
||||
strategy: undefined,
|
||||
targetMaps: undefined,
|
||||
version: undefined,
|
||||
};
|
||||
//# sourceMappingURL=default-options.constant.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"default-options.constant.js","sourceRoot":"","sources":["../../../src/constants/default-options.constant.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,CAAC,IAAM,cAAc,GAAmC;IAC5D,mBAAmB,EAAE,KAAK;IAC1B,wBAAwB,EAAE,KAAK;IAC/B,uBAAuB,EAAE,KAAK;IAC9B,eAAe,EAAE,SAAS;IAC1B,mBAAmB,EAAE,KAAK;IAC1B,iBAAiB,EAAE,IAAI;IACvB,MAAM,EAAE,SAAS;IACjB,gBAAgB,EAAE,KAAK;IACvB,QAAQ,EAAE,SAAS;IACnB,UAAU,EAAE,SAAS;IACrB,OAAO,EAAE,SAAS;CACnB,CAAC","sourcesContent":["import { ClassTransformOptions } from '../interfaces/class-transformer-options.interface';\n\n/**\n * These are the default options used by any transformation operation.\n */\nexport const defaultOptions: Partial<ClassTransformOptions> = {\n enableCircularCheck: false,\n enableImplicitConversion: false,\n excludeExtraneousValues: false,\n excludePrefixes: undefined,\n exposeDefaultValues: false,\n exposeUnsetFields: true,\n groups: undefined,\n ignoreDecorators: false,\n strategy: undefined,\n targetMaps: undefined,\n version: undefined,\n};\n"]}
|
||||
Generated
Vendored
+25
@@ -0,0 +1,25 @@
|
||||
import { defaultMetadataStorage } from '../storage';
|
||||
/**
|
||||
* Marks the given class or property as excluded. By default the property is excluded in both
|
||||
* constructorToPlain and plainToConstructor transformations. It can be limited to only one direction
|
||||
* via using the `toPlainOnly` or `toClassOnly` option.
|
||||
*
|
||||
* Can be applied to class definitions and properties.
|
||||
*/
|
||||
export function Exclude(options) {
|
||||
if (options === void 0) { options = {}; }
|
||||
/**
|
||||
* NOTE: The `propertyName` property must be marked as optional because
|
||||
* this decorator used both as a class and a property decorator and the
|
||||
* Typescript compiler will freak out if we make it mandatory as a class
|
||||
* decorator only receives one parameter.
|
||||
*/
|
||||
return function (object, propertyName) {
|
||||
defaultMetadataStorage.addExcludeMetadata({
|
||||
target: object instanceof Function ? object : object.constructor,
|
||||
propertyName: propertyName,
|
||||
options: options,
|
||||
});
|
||||
};
|
||||
}
|
||||
//# sourceMappingURL=exclude.decorator.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"exclude.decorator.js","sourceRoot":"","sources":["../../../src/decorators/exclude.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAGpD;;;;;;GAMG;AACH,MAAM,UAAU,OAAO,CAAC,OAA4B;IAA5B,wBAAA,EAAA,YAA4B;IAClD;;;;;OAKG;IACH,OAAO,UAAU,MAAW,EAAE,YAA8B;QAC1D,sBAAsB,CAAC,kBAAkB,CAAC;YACxC,MAAM,EAAE,MAAM,YAAY,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,WAAW;YAChE,YAAY,EAAE,YAAsB;YACpC,OAAO,SAAA;SACR,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { defaultMetadataStorage } from '../storage';\nimport { ExcludeOptions } from '../interfaces';\n\n/**\n * Marks the given class or property as excluded. By default the property is excluded in both\n * constructorToPlain and plainToConstructor transformations. It can be limited to only one direction\n * via using the `toPlainOnly` or `toClassOnly` option.\n *\n * Can be applied to class definitions and properties.\n */\nexport function Exclude(options: ExcludeOptions = {}): PropertyDecorator & ClassDecorator {\n /**\n * NOTE: The `propertyName` property must be marked as optional because\n * this decorator used both as a class and a property decorator and the\n * Typescript compiler will freak out if we make it mandatory as a class\n * decorator only receives one parameter.\n */\n return function (object: any, propertyName?: string | Symbol): void {\n defaultMetadataStorage.addExcludeMetadata({\n target: object instanceof Function ? object : object.constructor,\n propertyName: propertyName as string,\n options,\n });\n };\n}\n"]}
|
||||
Generated
Vendored
+25
@@ -0,0 +1,25 @@
|
||||
import { defaultMetadataStorage } from '../storage';
|
||||
/**
|
||||
* Marks the given class or property as included. By default the property is included in both
|
||||
* constructorToPlain and plainToConstructor transformations. It can be limited to only one direction
|
||||
* via using the `toPlainOnly` or `toClassOnly` option.
|
||||
*
|
||||
* Can be applied to class definitions and properties.
|
||||
*/
|
||||
export function Expose(options) {
|
||||
if (options === void 0) { options = {}; }
|
||||
/**
|
||||
* NOTE: The `propertyName` property must be marked as optional because
|
||||
* this decorator used both as a class and a property decorator and the
|
||||
* Typescript compiler will freak out if we make it mandatory as a class
|
||||
* decorator only receives one parameter.
|
||||
*/
|
||||
return function (object, propertyName) {
|
||||
defaultMetadataStorage.addExposeMetadata({
|
||||
target: object instanceof Function ? object : object.constructor,
|
||||
propertyName: propertyName,
|
||||
options: options,
|
||||
});
|
||||
};
|
||||
}
|
||||
//# sourceMappingURL=expose.decorator.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"expose.decorator.js","sourceRoot":"","sources":["../../../src/decorators/expose.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAGpD;;;;;;GAMG;AACH,MAAM,UAAU,MAAM,CAAC,OAA2B;IAA3B,wBAAA,EAAA,YAA2B;IAChD;;;;;OAKG;IACH,OAAO,UAAU,MAAW,EAAE,YAA8B;QAC1D,sBAAsB,CAAC,iBAAiB,CAAC;YACvC,MAAM,EAAE,MAAM,YAAY,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,WAAW;YAChE,YAAY,EAAE,YAAsB;YACpC,OAAO,SAAA;SACR,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { defaultMetadataStorage } from '../storage';\nimport { ExposeOptions } from '../interfaces';\n\n/**\n * Marks the given class or property as included. By default the property is included in both\n * constructorToPlain and plainToConstructor transformations. It can be limited to only one direction\n * via using the `toPlainOnly` or `toClassOnly` option.\n *\n * Can be applied to class definitions and properties.\n */\nexport function Expose(options: ExposeOptions = {}): PropertyDecorator & ClassDecorator {\n /**\n * NOTE: The `propertyName` property must be marked as optional because\n * this decorator used both as a class and a property decorator and the\n * Typescript compiler will freak out if we make it mandatory as a class\n * decorator only receives one parameter.\n */\n return function (object: any, propertyName?: string | Symbol): void {\n defaultMetadataStorage.addExposeMetadata({\n target: object instanceof Function ? object : object.constructor,\n propertyName: propertyName as string,\n options,\n });\n };\n}\n"]}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
export * from './exclude.decorator';
|
||||
export * from './expose.decorator';
|
||||
export * from './transform-instance-to-instance.decorator';
|
||||
export * from './transform-instance-to-plain.decorator';
|
||||
export * from './transform-plain-to-instance.decorator';
|
||||
export * from './transform.decorator';
|
||||
export * from './type.decorator';
|
||||
//# sourceMappingURL=index.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/decorators/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,4CAA4C,CAAC;AAC3D,cAAc,yCAAyC,CAAC;AACxD,cAAc,yCAAyC,CAAC;AACxD,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC","sourcesContent":["export * from './exclude.decorator';\nexport * from './expose.decorator';\nexport * from './transform-instance-to-instance.decorator';\nexport * from './transform-instance-to-plain.decorator';\nexport * from './transform-plain-to-instance.decorator';\nexport * from './transform.decorator';\nexport * from './type.decorator';\n"]}
|
||||
Generated
Vendored
+24
@@ -0,0 +1,24 @@
|
||||
import { ClassTransformer } from '../ClassTransformer';
|
||||
/**
|
||||
* Return the class instance only with the exposed properties.
|
||||
*
|
||||
* Can be applied to functions and getters/setters only.
|
||||
*/
|
||||
export function TransformInstanceToInstance(params) {
|
||||
return function (target, propertyKey, descriptor) {
|
||||
var classTransformer = new ClassTransformer();
|
||||
var originalMethod = descriptor.value;
|
||||
descriptor.value = function () {
|
||||
var args = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
args[_i] = arguments[_i];
|
||||
}
|
||||
var result = originalMethod.apply(this, args);
|
||||
var isPromise = !!result && (typeof result === 'object' || typeof result === 'function') && typeof result.then === 'function';
|
||||
return isPromise
|
||||
? result.then(function (data) { return classTransformer.instanceToInstance(data, params); })
|
||||
: classTransformer.instanceToInstance(result, params);
|
||||
};
|
||||
};
|
||||
}
|
||||
//# sourceMappingURL=transform-instance-to-instance.decorator.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"transform-instance-to-instance.decorator.js","sourceRoot":"","sources":["../../../src/decorators/transform-instance-to-instance.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAGvD;;;;GAIG;AACH,MAAM,UAAU,2BAA2B,CAAC,MAA8B;IACxE,OAAO,UAAU,MAA2B,EAAE,WAA4B,EAAE,UAA8B;QACxG,IAAM,gBAAgB,GAAqB,IAAI,gBAAgB,EAAE,CAAC;QAClE,IAAM,cAAc,GAAG,UAAU,CAAC,KAAK,CAAC;QAExC,UAAU,CAAC,KAAK,GAAG;YAAU,cAAc;iBAAd,UAAc,EAAd,qBAAc,EAAd,IAAc;gBAAd,yBAAc;;YACzC,IAAM,MAAM,GAAQ,cAAc,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;YACrD,IAAM,SAAS,GACb,CAAC,CAAC,MAAM,IAAI,CAAC,OAAO,MAAM,KAAK,QAAQ,IAAI,OAAO,MAAM,KAAK,UAAU,CAAC,IAAI,OAAO,MAAM,CAAC,IAAI,KAAK,UAAU,CAAC;YAChH,OAAO,SAAS;gBACd,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,UAAC,IAAS,IAAK,OAAA,gBAAgB,CAAC,kBAAkB,CAAC,IAAI,EAAE,MAAM,CAAC,EAAjD,CAAiD,CAAC;gBAC/E,CAAC,CAAC,gBAAgB,CAAC,kBAAkB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC1D,CAAC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { ClassTransformer } from '../ClassTransformer';\nimport { ClassTransformOptions } from '../interfaces';\n\n/**\n * Return the class instance only with the exposed properties.\n *\n * Can be applied to functions and getters/setters only.\n */\nexport function TransformInstanceToInstance(params?: ClassTransformOptions): MethodDecorator {\n return function (target: Record<string, any>, propertyKey: string | Symbol, descriptor: PropertyDescriptor): void {\n const classTransformer: ClassTransformer = new ClassTransformer();\n const originalMethod = descriptor.value;\n\n descriptor.value = function (...args: any[]): Record<string, any> {\n const result: any = originalMethod.apply(this, args);\n const isPromise =\n !!result && (typeof result === 'object' || typeof result === 'function') && typeof result.then === 'function';\n return isPromise\n ? result.then((data: any) => classTransformer.instanceToInstance(data, params))\n : classTransformer.instanceToInstance(result, params);\n };\n };\n}\n"]}
|
||||
Generated
Vendored
+24
@@ -0,0 +1,24 @@
|
||||
import { ClassTransformer } from '../ClassTransformer';
|
||||
/**
|
||||
* Transform the object from class to plain object and return only with the exposed properties.
|
||||
*
|
||||
* Can be applied to functions and getters/setters only.
|
||||
*/
|
||||
export function TransformInstanceToPlain(params) {
|
||||
return function (target, propertyKey, descriptor) {
|
||||
var classTransformer = new ClassTransformer();
|
||||
var originalMethod = descriptor.value;
|
||||
descriptor.value = function () {
|
||||
var args = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
args[_i] = arguments[_i];
|
||||
}
|
||||
var result = originalMethod.apply(this, args);
|
||||
var isPromise = !!result && (typeof result === 'object' || typeof result === 'function') && typeof result.then === 'function';
|
||||
return isPromise
|
||||
? result.then(function (data) { return classTransformer.instanceToPlain(data, params); })
|
||||
: classTransformer.instanceToPlain(result, params);
|
||||
};
|
||||
};
|
||||
}
|
||||
//# sourceMappingURL=transform-instance-to-plain.decorator.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"transform-instance-to-plain.decorator.js","sourceRoot":"","sources":["../../../src/decorators/transform-instance-to-plain.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAGvD;;;;GAIG;AACH,MAAM,UAAU,wBAAwB,CAAC,MAA8B;IACrE,OAAO,UAAU,MAA2B,EAAE,WAA4B,EAAE,UAA8B;QACxG,IAAM,gBAAgB,GAAqB,IAAI,gBAAgB,EAAE,CAAC;QAClE,IAAM,cAAc,GAAG,UAAU,CAAC,KAAK,CAAC;QAExC,UAAU,CAAC,KAAK,GAAG;YAAU,cAAc;iBAAd,UAAc,EAAd,qBAAc,EAAd,IAAc;gBAAd,yBAAc;;YACzC,IAAM,MAAM,GAAQ,cAAc,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;YACrD,IAAM,SAAS,GACb,CAAC,CAAC,MAAM,IAAI,CAAC,OAAO,MAAM,KAAK,QAAQ,IAAI,OAAO,MAAM,KAAK,UAAU,CAAC,IAAI,OAAO,MAAM,CAAC,IAAI,KAAK,UAAU,CAAC;YAChH,OAAO,SAAS;gBACd,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,UAAC,IAAS,IAAK,OAAA,gBAAgB,CAAC,eAAe,CAAC,IAAI,EAAE,MAAM,CAAC,EAA9C,CAA8C,CAAC;gBAC5E,CAAC,CAAC,gBAAgB,CAAC,eAAe,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACvD,CAAC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { ClassTransformer } from '../ClassTransformer';\nimport { ClassTransformOptions } from '../interfaces';\n\n/**\n * Transform the object from class to plain object and return only with the exposed properties.\n *\n * Can be applied to functions and getters/setters only.\n */\nexport function TransformInstanceToPlain(params?: ClassTransformOptions): MethodDecorator {\n return function (target: Record<string, any>, propertyKey: string | Symbol, descriptor: PropertyDescriptor): void {\n const classTransformer: ClassTransformer = new ClassTransformer();\n const originalMethod = descriptor.value;\n\n descriptor.value = function (...args: any[]): Record<string, any> {\n const result: any = originalMethod.apply(this, args);\n const isPromise =\n !!result && (typeof result === 'object' || typeof result === 'function') && typeof result.then === 'function';\n return isPromise\n ? result.then((data: any) => classTransformer.instanceToPlain(data, params))\n : classTransformer.instanceToPlain(result, params);\n };\n };\n}\n"]}
|
||||
Generated
Vendored
+24
@@ -0,0 +1,24 @@
|
||||
import { ClassTransformer } from '../ClassTransformer';
|
||||
/**
|
||||
* Return the class instance only with the exposed properties.
|
||||
*
|
||||
* Can be applied to functions and getters/setters only.
|
||||
*/
|
||||
export function TransformPlainToInstance(classType, params) {
|
||||
return function (target, propertyKey, descriptor) {
|
||||
var classTransformer = new ClassTransformer();
|
||||
var originalMethod = descriptor.value;
|
||||
descriptor.value = function () {
|
||||
var args = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
args[_i] = arguments[_i];
|
||||
}
|
||||
var result = originalMethod.apply(this, args);
|
||||
var isPromise = !!result && (typeof result === 'object' || typeof result === 'function') && typeof result.then === 'function';
|
||||
return isPromise
|
||||
? result.then(function (data) { return classTransformer.plainToInstance(classType, data, params); })
|
||||
: classTransformer.plainToInstance(classType, result, params);
|
||||
};
|
||||
};
|
||||
}
|
||||
//# sourceMappingURL=transform-plain-to-instance.decorator.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"transform-plain-to-instance.decorator.js","sourceRoot":"","sources":["../../../src/decorators/transform-plain-to-instance.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAGvD;;;;GAIG;AACH,MAAM,UAAU,wBAAwB,CACtC,SAAgC,EAChC,MAA8B;IAE9B,OAAO,UAAU,MAA2B,EAAE,WAA4B,EAAE,UAA8B;QACxG,IAAM,gBAAgB,GAAqB,IAAI,gBAAgB,EAAE,CAAC;QAClE,IAAM,cAAc,GAAG,UAAU,CAAC,KAAK,CAAC;QAExC,UAAU,CAAC,KAAK,GAAG;YAAU,cAAc;iBAAd,UAAc,EAAd,qBAAc,EAAd,IAAc;gBAAd,yBAAc;;YACzC,IAAM,MAAM,GAAQ,cAAc,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;YACrD,IAAM,SAAS,GACb,CAAC,CAAC,MAAM,IAAI,CAAC,OAAO,MAAM,KAAK,QAAQ,IAAI,OAAO,MAAM,KAAK,UAAU,CAAC,IAAI,OAAO,MAAM,CAAC,IAAI,KAAK,UAAU,CAAC;YAChH,OAAO,SAAS;gBACd,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,UAAC,IAAS,IAAK,OAAA,gBAAgB,CAAC,eAAe,CAAC,SAAS,EAAE,IAAI,EAAE,MAAM,CAAC,EAAzD,CAAyD,CAAC;gBACvF,CAAC,CAAC,gBAAgB,CAAC,eAAe,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;QAClE,CAAC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { ClassTransformer } from '../ClassTransformer';\nimport { ClassTransformOptions, ClassConstructor } from '../interfaces';\n\n/**\n * Return the class instance only with the exposed properties.\n *\n * Can be applied to functions and getters/setters only.\n */\nexport function TransformPlainToInstance(\n classType: ClassConstructor<any>,\n params?: ClassTransformOptions\n): MethodDecorator {\n return function (target: Record<string, any>, propertyKey: string | Symbol, descriptor: PropertyDescriptor): void {\n const classTransformer: ClassTransformer = new ClassTransformer();\n const originalMethod = descriptor.value;\n\n descriptor.value = function (...args: any[]): Record<string, any> {\n const result: any = originalMethod.apply(this, args);\n const isPromise =\n !!result && (typeof result === 'object' || typeof result === 'function') && typeof result.then === 'function';\n return isPromise\n ? result.then((data: any) => classTransformer.plainToInstance(classType, data, params))\n : classTransformer.plainToInstance(classType, result, params);\n };\n };\n}\n"]}
|
||||
Generated
Vendored
+18
@@ -0,0 +1,18 @@
|
||||
import { defaultMetadataStorage } from '../storage';
|
||||
/**
|
||||
* Defines a custom logic for value transformation.
|
||||
*
|
||||
* Can be applied to properties only.
|
||||
*/
|
||||
export function Transform(transformFn, options) {
|
||||
if (options === void 0) { options = {}; }
|
||||
return function (target, propertyName) {
|
||||
defaultMetadataStorage.addTransformMetadata({
|
||||
target: target.constructor,
|
||||
propertyName: propertyName,
|
||||
transformFn: transformFn,
|
||||
options: options,
|
||||
});
|
||||
};
|
||||
}
|
||||
//# sourceMappingURL=transform.decorator.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"transform.decorator.js","sourceRoot":"","sources":["../../../src/decorators/transform.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAGpD;;;;GAIG;AACH,MAAM,UAAU,SAAS,CACvB,WAA+C,EAC/C,OAA8B;IAA9B,wBAAA,EAAA,YAA8B;IAE9B,OAAO,UAAU,MAAW,EAAE,YAA6B;QACzD,sBAAsB,CAAC,oBAAoB,CAAC;YAC1C,MAAM,EAAE,MAAM,CAAC,WAAW;YAC1B,YAAY,EAAE,YAAsB;YACpC,WAAW,aAAA;YACX,OAAO,SAAA;SACR,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { defaultMetadataStorage } from '../storage';\nimport { TransformFnParams, TransformOptions } from '../interfaces';\n\n/**\n * Defines a custom logic for value transformation.\n *\n * Can be applied to properties only.\n */\nexport function Transform(\n transformFn: (params: TransformFnParams) => any,\n options: TransformOptions = {}\n): PropertyDecorator {\n return function (target: any, propertyName: string | Symbol): void {\n defaultMetadataStorage.addTransformMetadata({\n target: target.constructor,\n propertyName: propertyName as string,\n transformFn,\n options,\n });\n };\n}\n"]}
|
||||
Generated
Vendored
+21
@@ -0,0 +1,21 @@
|
||||
import { defaultMetadataStorage } from '../storage';
|
||||
/**
|
||||
* Specifies a type of the property.
|
||||
* The given TypeFunction can return a constructor. A discriminator can be given in the options.
|
||||
*
|
||||
* Can be applied to properties only.
|
||||
*/
|
||||
export function Type(typeFunction, options) {
|
||||
if (options === void 0) { options = {}; }
|
||||
return function (target, propertyName) {
|
||||
var reflectedType = Reflect.getMetadata('design:type', target, propertyName);
|
||||
defaultMetadataStorage.addTypeMetadata({
|
||||
target: target.constructor,
|
||||
propertyName: propertyName,
|
||||
reflectedType: reflectedType,
|
||||
typeFunction: typeFunction,
|
||||
options: options,
|
||||
});
|
||||
};
|
||||
}
|
||||
//# sourceMappingURL=type.decorator.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"type.decorator.js","sourceRoot":"","sources":["../../../src/decorators/type.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAGpD;;;;;GAKG;AACH,MAAM,UAAU,IAAI,CAClB,YAAmD,EACnD,OAAyB;IAAzB,wBAAA,EAAA,YAAyB;IAEzB,OAAO,UAAU,MAAW,EAAE,YAA6B;QACzD,IAAM,aAAa,GAAI,OAAe,CAAC,WAAW,CAAC,aAAa,EAAE,MAAM,EAAE,YAAY,CAAC,CAAC;QACxF,sBAAsB,CAAC,eAAe,CAAC;YACrC,MAAM,EAAE,MAAM,CAAC,WAAW;YAC1B,YAAY,EAAE,YAAsB;YACpC,aAAa,eAAA;YACb,YAAY,cAAA;YACZ,OAAO,SAAA;SACR,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { defaultMetadataStorage } from '../storage';\nimport { TypeHelpOptions, TypeOptions } from '../interfaces';\n\n/**\n * Specifies a type of the property.\n * The given TypeFunction can return a constructor. A discriminator can be given in the options.\n *\n * Can be applied to properties only.\n */\nexport function Type(\n typeFunction?: (type?: TypeHelpOptions) => Function,\n options: TypeOptions = {}\n): PropertyDecorator {\n return function (target: any, propertyName: string | Symbol): void {\n const reflectedType = (Reflect as any).getMetadata('design:type', target, propertyName);\n defaultMetadataStorage.addTypeMetadata({\n target: target.constructor,\n propertyName: propertyName as string,\n reflectedType,\n typeFunction,\n options,\n });\n };\n}\n"]}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
export * from './transformation-type.enum';
|
||||
//# sourceMappingURL=index.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/enums/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC","sourcesContent":["export * from './transformation-type.enum';\n"]}
|
||||
Generated
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
export var TransformationType;
|
||||
(function (TransformationType) {
|
||||
TransformationType[TransformationType["PLAIN_TO_CLASS"] = 0] = "PLAIN_TO_CLASS";
|
||||
TransformationType[TransformationType["CLASS_TO_PLAIN"] = 1] = "CLASS_TO_PLAIN";
|
||||
TransformationType[TransformationType["CLASS_TO_CLASS"] = 2] = "CLASS_TO_CLASS";
|
||||
})(TransformationType || (TransformationType = {}));
|
||||
//# sourceMappingURL=transformation-type.enum.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"transformation-type.enum.js","sourceRoot":"","sources":["../../../src/enums/transformation-type.enum.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,kBAIX;AAJD,WAAY,kBAAkB;IAC5B,+EAAc,CAAA;IACd,+EAAc,CAAA;IACd,+EAAc,CAAA;AAChB,CAAC,EAJW,kBAAkB,KAAlB,kBAAkB,QAI7B","sourcesContent":["export enum TransformationType {\n PLAIN_TO_CLASS,\n CLASS_TO_PLAIN,\n CLASS_TO_CLASS,\n}\n"]}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
import { ClassTransformer } from './ClassTransformer';
|
||||
export { ClassTransformer } from './ClassTransformer';
|
||||
export * from './decorators';
|
||||
export * from './interfaces';
|
||||
export * from './enums';
|
||||
var classTransformer = new ClassTransformer();
|
||||
export function classToPlain(object, options) {
|
||||
return classTransformer.instanceToPlain(object, options);
|
||||
}
|
||||
export function instanceToPlain(object, options) {
|
||||
return classTransformer.instanceToPlain(object, options);
|
||||
}
|
||||
export function classToPlainFromExist(object, plainObject, options) {
|
||||
return classTransformer.classToPlainFromExist(object, plainObject, options);
|
||||
}
|
||||
export function plainToClass(cls, plain, options) {
|
||||
return classTransformer.plainToInstance(cls, plain, options);
|
||||
}
|
||||
export function plainToInstance(cls, plain, options) {
|
||||
return classTransformer.plainToInstance(cls, plain, options);
|
||||
}
|
||||
export function plainToClassFromExist(clsObject, plain, options) {
|
||||
return classTransformer.plainToClassFromExist(clsObject, plain, options);
|
||||
}
|
||||
export function instanceToInstance(object, options) {
|
||||
return classTransformer.instanceToInstance(object, options);
|
||||
}
|
||||
export function classToClassFromExist(object, fromObject, options) {
|
||||
return classTransformer.classToClassFromExist(object, fromObject, options);
|
||||
}
|
||||
export function serialize(object, options) {
|
||||
return classTransformer.serialize(object, options);
|
||||
}
|
||||
/**
|
||||
* Deserializes given JSON string to a object of the given class.
|
||||
*
|
||||
* @deprecated This function is being removed. Please use the following instead:
|
||||
* ```
|
||||
* instanceToClass(cls, JSON.parse(json), options)
|
||||
* ```
|
||||
*/
|
||||
export function deserialize(cls, json, options) {
|
||||
return classTransformer.deserialize(cls, json, options);
|
||||
}
|
||||
/**
|
||||
* Deserializes given JSON string to an array of objects of the given class.
|
||||
*
|
||||
* @deprecated This function is being removed. Please use the following instead:
|
||||
* ```
|
||||
* JSON.parse(json).map(value => instanceToClass(cls, value, options))
|
||||
* ```
|
||||
*
|
||||
*/
|
||||
export function deserializeArray(cls, json, options) {
|
||||
return classTransformer.deserializeArray(cls, json, options);
|
||||
}
|
||||
//# sourceMappingURL=index.js.map
|
||||
+1
File diff suppressed because one or more lines are too long
Generated
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
export {};
|
||||
//# sourceMappingURL=class-constructor.type.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"class-constructor.type.js","sourceRoot":"","sources":["../../../src/interfaces/class-constructor.type.ts"],"names":[],"mappings":"","sourcesContent":["export type ClassConstructor<T> = {\n new (...args: any[]): T;\n};\n"]}
|
||||
Generated
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
export {};
|
||||
//# sourceMappingURL=class-transformer-options.interface.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"class-transformer-options.interface.js","sourceRoot":"","sources":["../../../src/interfaces/class-transformer-options.interface.ts"],"names":[],"mappings":"","sourcesContent":["import { TargetMap } from './target-map.interface';\n\n/**\n * Options to be passed during transformation.\n */\nexport interface ClassTransformOptions {\n /**\n * Exclusion strategy. By default exposeAll is used, which means that it will expose all properties are transformed\n * by default.\n */\n strategy?: 'excludeAll' | 'exposeAll';\n\n /**\n * Indicates if extraneous properties should be excluded from the value when converting a plain value to a class.\n *\n * This option requires that each property on the target class has at least one `@Expose` or `@Exclude` decorator\n * assigned from this library.\n */\n excludeExtraneousValues?: boolean;\n\n /**\n * Only properties with given groups gonna be transformed.\n */\n groups?: string[];\n\n /**\n * Only properties with \"since\" > version < \"until\" gonna be transformed.\n */\n version?: number;\n\n /**\n * Excludes properties with the given prefixes. For example, if you mark your private properties with \"_\" and \"__\"\n * you can set this option's value to [\"_\", \"__\"] and all private properties will be skipped.\n * This works only for \"exposeAll\" strategy.\n */\n excludePrefixes?: string[];\n\n /**\n * If set to true then class transformer will ignore the effect of all @Expose and @Exclude decorators.\n * This option is useful if you want to kinda clone your object but do not apply decorators affects.\n *\n * __NOTE:__ You may still have to add the decorators to make other options work.\n */\n ignoreDecorators?: boolean;\n\n /**\n * Target maps allows to set a Types of the transforming object without using @Type decorator.\n * This is useful when you are transforming external classes, or if you already have type metadata for\n * objects and you don't want to set it up again.\n */\n targetMaps?: TargetMap[];\n\n /**\n * If set to true then class transformer will perform a circular check. (circular check is turned off by default)\n * This option is useful when you know for sure that your types might have a circular dependency.\n */\n enableCircularCheck?: boolean;\n\n /**\n * If set to true then class transformer will try to convert properties implicitly to their target type based on their typing information.\n *\n * DEFAULT: `false`\n */\n enableImplicitConversion?: boolean;\n\n /**\n * If set to true then class transformer will take default values for unprovided fields.\n * This is useful when you convert a plain object to a class and have an optional field with a default value.\n */\n exposeDefaultValues?: boolean;\n\n /**\n * When set to true, fields with `undefined` as value will be included in class to plain transformation. Otherwise\n * those fields will be omitted from the result.\n *\n * DEFAULT: `true`\n */\n exposeUnsetFields?: boolean;\n}\n"]}
|
||||
Generated
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
export {};
|
||||
//# sourceMappingURL=exclude-options.interface.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"exclude-options.interface.js","sourceRoot":"","sources":["../../../../src/interfaces/decorator-options/exclude-options.interface.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Possible transformation options for the @Exclude decorator.\n */\nexport interface ExcludeOptions {\n /**\n * Expose this property only when transforming from plain to class instance.\n */\n toClassOnly?: boolean;\n\n /**\n * Expose this property only when transforming from class instance to plain object.\n */\n toPlainOnly?: boolean;\n}\n"]}
|
||||
Generated
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
export {};
|
||||
//# sourceMappingURL=expose-options.interface.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"expose-options.interface.js","sourceRoot":"","sources":["../../../../src/interfaces/decorator-options/expose-options.interface.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Possible transformation options for the @Expose decorator.\n */\nexport interface ExposeOptions {\n /**\n * Name of property on the target object to expose the value of this property.\n */\n name?: string;\n\n /**\n * First version where this property should be exposed.\n *\n * Example:\n * ```ts\n * instanceToPlain(payload, { version: 1.0 });\n * ```\n */\n since?: number;\n\n /**\n * Last version where this property should be exposed.\n *\n * Example:\n * ```ts\n * instanceToPlain(payload, { version: 1.0 });\n * ```\n */\n until?: number;\n\n /**\n * List of transformation groups this property belongs to. When set,\n * the property will be exposed only when transform is called with\n * one of the groups specified.\n *\n * Example:\n * ```ts\n * instanceToPlain(payload, { groups: ['user'] });\n * ```\n */\n groups?: string[];\n\n /**\n * Expose this property only when transforming from plain to class instance.\n */\n toClassOnly?: boolean;\n\n /**\n * Expose this property only when transforming from class instance to plain object.\n */\n toPlainOnly?: boolean;\n}\n"]}
|
||||
Generated
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
export {};
|
||||
//# sourceMappingURL=transform-options.interface.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"transform-options.interface.js","sourceRoot":"","sources":["../../../../src/interfaces/decorator-options/transform-options.interface.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Possible transformation options for the @Transform decorator.\n */\nexport interface TransformOptions {\n /**\n * First version where this property should be exposed.\n *\n * Example:\n * ```ts\n * instanceToPlain(payload, { version: 1.0 });\n * ```\n */\n since?: number;\n\n /**\n * Last version where this property should be exposed.\n *\n * Example:\n * ```ts\n * instanceToPlain(payload, { version: 1.0 });\n * ```\n */\n until?: number;\n\n /**\n * List of transformation groups this property belongs to. When set,\n * the property will be exposed only when transform is called with\n * one of the groups specified.\n *\n * Example:\n * ```ts\n * instanceToPlain(payload, { groups: ['user'] });\n * ```\n */\n groups?: string[];\n\n /**\n * Expose this property only when transforming from plain to class instance.\n */\n toClassOnly?: boolean;\n\n /**\n * Expose this property only when transforming from class instance to plain object.\n */\n toPlainOnly?: boolean;\n}\n"]}
|
||||
Generated
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
export {};
|
||||
//# sourceMappingURL=type-discriminator-descriptor.interface.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"type-discriminator-descriptor.interface.js","sourceRoot":"","sources":["../../../../src/interfaces/decorator-options/type-discriminator-descriptor.interface.ts"],"names":[],"mappings":"","sourcesContent":["import { ClassConstructor } from '..';\n\n/**\n * Discriminator object containing the type information to select a proper type\n * during transformation when a discriminator property is provided.\n */\nexport interface DiscriminatorDescriptor {\n /**\n * The name of the property which holds the type information in the received object.\n */\n property: string;\n /**\n * List of the available types. The transformer will try to lookup the object\n * with the same key as the value received in the defined discriminator property\n * and create an instance of the defined class.\n */\n subTypes: {\n /**\n * Name of the type.\n */\n name: string;\n\n /**\n * A class constructor which can be used to create the object.\n */\n value: ClassConstructor<any>;\n }[];\n}\n"]}
|
||||
Generated
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
export {};
|
||||
//# sourceMappingURL=type-options.interface.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"type-options.interface.js","sourceRoot":"","sources":["../../../../src/interfaces/decorator-options/type-options.interface.ts"],"names":[],"mappings":"","sourcesContent":["import { DiscriminatorDescriptor } from './type-discriminator-descriptor.interface';\n\n/**\n * Possible transformation options for the @Type decorator.\n */\nexport interface TypeOptions {\n /**\n * Optional discriminator object, when provided the property value will be\n * initialized according to the specified object.\n */\n discriminator?: DiscriminatorDescriptor;\n\n /**\n * Indicates whether to keep the discriminator property on the\n * transformed object or not. Disabled by default.\n *\n * @default false\n */\n keepDiscriminatorProperty?: boolean;\n}\n"]}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
export * from './decorator-options/expose-options.interface';
|
||||
export * from './decorator-options/exclude-options.interface';
|
||||
export * from './decorator-options/transform-options.interface';
|
||||
export * from './decorator-options/type-discriminator-descriptor.interface';
|
||||
export * from './decorator-options/type-options.interface';
|
||||
export * from './metadata/exclude-metadata.interface';
|
||||
export * from './metadata/expose-metadata.interface';
|
||||
export * from './metadata/transform-metadata.interface';
|
||||
export * from './metadata/transform-fn-params.interface';
|
||||
export * from './metadata/type-metadata.interface';
|
||||
export * from './class-constructor.type';
|
||||
export * from './class-transformer-options.interface';
|
||||
export * from './target-map.interface';
|
||||
export * from './type-help-options.interface';
|
||||
//# sourceMappingURL=index.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/interfaces/index.ts"],"names":[],"mappings":"AAAA,cAAc,8CAA8C,CAAC;AAC7D,cAAc,+CAA+C,CAAC;AAC9D,cAAc,iDAAiD,CAAC;AAChE,cAAc,6DAA6D,CAAC;AAC5E,cAAc,4CAA4C,CAAC;AAC3D,cAAc,uCAAuC,CAAC;AACtD,cAAc,sCAAsC,CAAC;AACrD,cAAc,yCAAyC,CAAC;AACxD,cAAc,0CAA0C,CAAC;AACzD,cAAc,oCAAoC,CAAC;AACnD,cAAc,0BAA0B,CAAC;AACzC,cAAc,uCAAuC,CAAC;AACtD,cAAc,wBAAwB,CAAC;AACvC,cAAc,+BAA+B,CAAC","sourcesContent":["export * from './decorator-options/expose-options.interface';\nexport * from './decorator-options/exclude-options.interface';\nexport * from './decorator-options/transform-options.interface';\nexport * from './decorator-options/type-discriminator-descriptor.interface';\nexport * from './decorator-options/type-options.interface';\nexport * from './metadata/exclude-metadata.interface';\nexport * from './metadata/expose-metadata.interface';\nexport * from './metadata/transform-metadata.interface';\nexport * from './metadata/transform-fn-params.interface';\nexport * from './metadata/type-metadata.interface';\nexport * from './class-constructor.type';\nexport * from './class-transformer-options.interface';\nexport * from './target-map.interface';\nexport * from './type-help-options.interface';\n"]}
|
||||
Generated
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
export {};
|
||||
//# sourceMappingURL=exclude-metadata.interface.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"exclude-metadata.interface.js","sourceRoot":"","sources":["../../../../src/interfaces/metadata/exclude-metadata.interface.ts"],"names":[],"mappings":"","sourcesContent":["import { ExcludeOptions } from '..';\n\n/**\n * This object represents metadata assigned to a property via the @Exclude decorator.\n */\nexport interface ExcludeMetadata {\n target: Function;\n\n /**\n * The property name this metadata belongs to on the target (class or property).\n *\n * Note: If the decorator is applied to a class the propertyName will be undefined.\n */\n propertyName: string | undefined;\n\n /**\n * Options passed to the @Exclude operator for this property.\n */\n options: ExcludeOptions;\n}\n"]}
|
||||
Generated
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
export {};
|
||||
//# sourceMappingURL=expose-metadata.interface.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"expose-metadata.interface.js","sourceRoot":"","sources":["../../../../src/interfaces/metadata/expose-metadata.interface.ts"],"names":[],"mappings":"","sourcesContent":["import { ExposeOptions } from '..';\n\n/**\n * This object represents metadata assigned to a property via the @Expose decorator.\n */\nexport interface ExposeMetadata {\n target: Function;\n\n /**\n * The property name this metadata belongs to on the target (class or property).\n *\n * Note: If the decorator is applied to a class the propertyName will be undefined.\n */\n propertyName: string | undefined;\n\n /**\n * Options passed to the @Expose operator for this property.\n */\n options: ExposeOptions;\n}\n"]}
|
||||
Generated
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
export {};
|
||||
//# sourceMappingURL=transform-fn-params.interface.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"transform-fn-params.interface.js","sourceRoot":"","sources":["../../../../src/interfaces/metadata/transform-fn-params.interface.ts"],"names":[],"mappings":"","sourcesContent":["import { TransformationType } from '../../enums';\nimport { ClassTransformOptions } from '../class-transformer-options.interface';\n\nexport interface TransformFnParams {\n value: any;\n key: string;\n obj: any;\n type: TransformationType;\n options: ClassTransformOptions;\n}\n"]}
|
||||
Generated
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
export {};
|
||||
//# sourceMappingURL=transform-metadata.interface.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"transform-metadata.interface.js","sourceRoot":"","sources":["../../../../src/interfaces/metadata/transform-metadata.interface.ts"],"names":[],"mappings":"","sourcesContent":["import { TransformOptions } from '..';\nimport { TransformFnParams } from './transform-fn-params.interface';\n\n/**\n * This object represents metadata assigned to a property via the @Transform decorator.\n */\nexport interface TransformMetadata {\n target: Function;\n\n /**\n * The property name this metadata belongs to on the target (property only).\n */\n propertyName: string;\n\n /**\n * The custom transformation function provided by the user in the @Transform decorator.\n */\n transformFn: (params: TransformFnParams) => any;\n\n /**\n * Options passed to the @Transform operator for this property.\n */\n options: TransformOptions;\n}\n"]}
|
||||
Generated
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
export {};
|
||||
//# sourceMappingURL=type-metadata.interface.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"type-metadata.interface.js","sourceRoot":"","sources":["../../../../src/interfaces/metadata/type-metadata.interface.ts"],"names":[],"mappings":"","sourcesContent":["import { TypeHelpOptions, TypeOptions } from '..';\n\n/**\n * This object represents metadata assigned to a property via the @Type decorator.\n */\nexport interface TypeMetadata {\n target: Function;\n\n /**\n * The property name this metadata belongs to on the target (property only).\n */\n propertyName: string;\n\n /**\n * The type guessed from assigned Reflect metadata ('design:type')\n */\n reflectedType: any;\n\n /**\n * The custom function provided by the user in the @Type decorator which\n * returns the target type for the transformation.\n */\n typeFunction: (options?: TypeHelpOptions) => Function;\n\n /**\n * Options passed to the @Type operator for this property.\n */\n options: TypeOptions;\n}\n"]}
|
||||
Generated
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
export {};
|
||||
//# sourceMappingURL=target-map.interface.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"target-map.interface.js","sourceRoot":"","sources":["../../../src/interfaces/target-map.interface.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Allows to specify a map of Types in the object without using @Type decorator.\n * This is useful when you have external classes.\n */\nexport interface TargetMap {\n /**\n * Target which Types are being specified.\n */\n target: Function;\n\n /**\n * List of properties and their Types.\n */\n properties: { [key: string]: Function };\n}\n"]}
|
||||
Generated
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
export {};
|
||||
//# sourceMappingURL=type-help-options.interface.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"type-help-options.interface.js","sourceRoot":"","sources":["../../../src/interfaces/type-help-options.interface.ts"],"names":[],"mappings":"","sourcesContent":["// TODO: Document this interface. What does each property means?\nexport interface TypeHelpOptions {\n newObject: any;\n object: Record<string, any>;\n property: string;\n}\n"]}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
import { MetadataStorage } from './MetadataStorage';
|
||||
/**
|
||||
* Default metadata storage is used as singleton and can be used to storage all metadatas.
|
||||
*/
|
||||
export var defaultMetadataStorage = new MetadataStorage();
|
||||
//# sourceMappingURL=storage.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"storage.js","sourceRoot":"","sources":["../../src/storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD;;GAEG;AACH,MAAM,CAAC,IAAM,sBAAsB,GAAG,IAAI,eAAe,EAAE,CAAC","sourcesContent":["import { MetadataStorage } from './MetadataStorage';\n\n/**\n * Default metadata storage is used as singleton and can be used to storage all metadatas.\n */\nexport const defaultMetadataStorage = new MetadataStorage();\n"]}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
* This function returns the global object across Node and browsers.
|
||||
*
|
||||
* Note: `globalThis` is the standardized approach however it has been added to
|
||||
* Node.js in version 12. We need to include this snippet until Node 12 EOL.
|
||||
*/
|
||||
export function getGlobal() {
|
||||
if (typeof globalThis !== 'undefined') {
|
||||
return globalThis;
|
||||
}
|
||||
if (typeof global !== 'undefined') {
|
||||
return global;
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore: Cannot find name 'window'.
|
||||
if (typeof window !== 'undefined') {
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore: Cannot find name 'window'.
|
||||
return window;
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore: Cannot find name 'self'.
|
||||
if (typeof self !== 'undefined') {
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore: Cannot find name 'self'.
|
||||
return self;
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=get-global.util.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"get-global.util.js","sourceRoot":"","sources":["../../../src/utils/get-global.util.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,UAAU,SAAS;IACvB,IAAI,OAAO,UAAU,KAAK,WAAW,EAAE;QACrC,OAAO,UAAU,CAAC;KACnB;IAED,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;QACjC,OAAO,MAAM,CAAC;KACf;IAED,6DAA6D;IAC7D,yCAAyC;IACzC,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;QACjC,6DAA6D;QAC7D,yCAAyC;QACzC,OAAO,MAAM,CAAC;KACf;IAED,6DAA6D;IAC7D,uCAAuC;IACvC,IAAI,OAAO,IAAI,KAAK,WAAW,EAAE;QAC/B,6DAA6D;QAC7D,uCAAuC;QACvC,OAAO,IAAI,CAAC;KACb;AACH,CAAC","sourcesContent":["/**\n * This function returns the global object across Node and browsers.\n *\n * Note: `globalThis` is the standardized approach however it has been added to\n * Node.js in version 12. We need to include this snippet until Node 12 EOL.\n */\nexport function getGlobal() {\n if (typeof globalThis !== 'undefined') {\n return globalThis;\n }\n\n if (typeof global !== 'undefined') {\n return global;\n }\n\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore: Cannot find name 'window'.\n if (typeof window !== 'undefined') {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore: Cannot find name 'window'.\n return window;\n }\n\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore: Cannot find name 'self'.\n if (typeof self !== 'undefined') {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore: Cannot find name 'self'.\n return self;\n }\n}\n"]}
|
||||
Generated
Vendored
+13
@@ -0,0 +1,13 @@
|
||||
import { getGlobal } from '.';
|
||||
describe('getGlobal()', function () {
|
||||
it('should return true if Buffer is present in globalThis', function () {
|
||||
expect(getGlobal().Buffer).toBe(true);
|
||||
});
|
||||
it('should return false if Buffer is not present in globalThis', function () {
|
||||
var bufferImp = global.Buffer;
|
||||
delete global.Buffer;
|
||||
expect(getGlobal().Buffer).toBe(false);
|
||||
global.Buffer = bufferImp;
|
||||
});
|
||||
});
|
||||
//# sourceMappingURL=get-global.util.spect.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"get-global.util.spect.js","sourceRoot":"","sources":["../../../src/utils/get-global.util.spect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,GAAG,CAAC;AAE9B,QAAQ,CAAC,aAAa,EAAE;IACtB,EAAE,CAAC,uDAAuD,EAAE;QAC1D,MAAM,CAAC,SAAS,EAAE,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACxC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,4DAA4D,EAAE;QAC/D,IAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC;QAChC,OAAO,MAAM,CAAC,MAAM,CAAC;QAErB,MAAM,CAAC,SAAS,EAAE,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAEvC,MAAM,CAAC,MAAM,GAAG,SAAS,CAAC;IAC5B,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { getGlobal } from '.';\n\ndescribe('getGlobal()', () => {\n it('should return true if Buffer is present in globalThis', () => {\n expect(getGlobal().Buffer).toBe(true);\n });\n\n it('should return false if Buffer is not present in globalThis', () => {\n const bufferImp = global.Buffer;\n delete global.Buffer;\n\n expect(getGlobal().Buffer).toBe(false);\n\n global.Buffer = bufferImp;\n });\n});\n"]}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
export * from './get-global.util';
|
||||
export * from './is-promise.util';
|
||||
//# sourceMappingURL=index.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC","sourcesContent":["export * from './get-global.util';\nexport * from './is-promise.util';\n"]}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
export function isPromise(p) {
|
||||
return p !== null && typeof p === 'object' && typeof p.then === 'function';
|
||||
}
|
||||
//# sourceMappingURL=is-promise.util.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"is-promise.util.js","sourceRoot":"","sources":["../../../src/utils/is-promise.util.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,SAAS,CAAI,CAAM;IACjC,OAAO,CAAC,KAAK,IAAI,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,OAAO,CAAC,CAAC,IAAI,KAAK,UAAU,CAAC;AAC7E,CAAC","sourcesContent":["export function isPromise<T>(p: any): p is Promise<T> {\n return p !== null && typeof p === 'object' && typeof p.then === 'function';\n}\n"]}
|
||||
Reference in New Issue
Block a user