1 | define("class-transformer/ClassTransformOptions", ["require", "exports"], function (require, exports) {
|
2 | "use strict";
|
3 | Object.defineProperty(exports, "__esModule", { value: true });
|
4 | });
|
5 | define("class-transformer/metadata/ExposeExcludeOptions", ["require", "exports"], function (require, exports) {
|
6 | "use strict";
|
7 | Object.defineProperty(exports, "__esModule", { value: true });
|
8 | });
|
9 | define("class-transformer/metadata/TypeMetadata", ["require", "exports"], function (require, exports) {
|
10 | "use strict";
|
11 | Object.defineProperty(exports, "__esModule", { value: true });
|
12 | var TypeMetadata = (function () {
|
13 | function TypeMetadata(target, propertyName, reflectedType, typeFunction, options) {
|
14 | this.target = target;
|
15 | this.propertyName = propertyName;
|
16 | this.reflectedType = reflectedType;
|
17 | this.typeFunction = typeFunction;
|
18 | this.options = options;
|
19 | }
|
20 | return TypeMetadata;
|
21 | }());
|
22 | exports.TypeMetadata = TypeMetadata;
|
23 | });
|
24 | define("class-transformer/metadata/ExposeMetadata", ["require", "exports"], function (require, exports) {
|
25 | "use strict";
|
26 | Object.defineProperty(exports, "__esModule", { value: true });
|
27 | var ExposeMetadata = (function () {
|
28 | function ExposeMetadata(target, propertyName, options) {
|
29 | this.target = target;
|
30 | this.propertyName = propertyName;
|
31 | this.options = options;
|
32 | }
|
33 | return ExposeMetadata;
|
34 | }());
|
35 | exports.ExposeMetadata = ExposeMetadata;
|
36 | });
|
37 | define("class-transformer/metadata/ExcludeMetadata", ["require", "exports"], function (require, exports) {
|
38 | "use strict";
|
39 | Object.defineProperty(exports, "__esModule", { value: true });
|
40 | var ExcludeMetadata = (function () {
|
41 | function ExcludeMetadata(target, propertyName, options) {
|
42 | this.target = target;
|
43 | this.propertyName = propertyName;
|
44 | this.options = options;
|
45 | }
|
46 | return ExcludeMetadata;
|
47 | }());
|
48 | exports.ExcludeMetadata = ExcludeMetadata;
|
49 | });
|
50 | define("class-transformer/metadata/TransformMetadata", ["require", "exports"], function (require, exports) {
|
51 | "use strict";
|
52 | Object.defineProperty(exports, "__esModule", { value: true });
|
53 | var TransformMetadata = (function () {
|
54 | function TransformMetadata(target, propertyName, transformFn, options) {
|
55 | this.target = target;
|
56 | this.propertyName = propertyName;
|
57 | this.transformFn = transformFn;
|
58 | this.options = options;
|
59 | }
|
60 | return TransformMetadata;
|
61 | }());
|
62 | exports.TransformMetadata = TransformMetadata;
|
63 | });
|
64 | define("class-transformer/metadata/MetadataStorage", ["require", "exports", "class-transformer/TransformOperationExecutor"], function (require, exports, TransformOperationExecutor_1) {
|
65 | "use strict";
|
66 | Object.defineProperty(exports, "__esModule", { value: true });
|
67 | |
68 |
|
69 |
|
70 | var MetadataStorage = (function () {
|
71 | function MetadataStorage() {
|
72 |
|
73 |
|
74 |
|
75 | this._typeMetadatas = new Map();
|
76 | this._transformMetadatas = new Map();
|
77 | this._exposeMetadatas = new Map();
|
78 | this._excludeMetadatas = new Map();
|
79 | this._ancestorsMap = new Map();
|
80 | }
|
81 |
|
82 |
|
83 |
|
84 | MetadataStorage.prototype.addTypeMetadata = function (metadata) {
|
85 | if (!this._typeMetadatas.has(metadata.target)) {
|
86 | this._typeMetadatas.set(metadata.target, new Map());
|
87 | }
|
88 | this._typeMetadatas.get(metadata.target).set(metadata.propertyName, metadata);
|
89 | };
|
90 | MetadataStorage.prototype.addTransformMetadata = function (metadata) {
|
91 | if (!this._transformMetadatas.has(metadata.target)) {
|
92 | this._transformMetadatas.set(metadata.target, new Map());
|
93 | }
|
94 | if (!this._transformMetadatas.get(metadata.target).has(metadata.propertyName)) {
|
95 | this._transformMetadatas.get(metadata.target).set(metadata.propertyName, []);
|
96 | }
|
97 | this._transformMetadatas.get(metadata.target).get(metadata.propertyName).push(metadata);
|
98 | };
|
99 | MetadataStorage.prototype.addExposeMetadata = function (metadata) {
|
100 | if (!this._exposeMetadatas.has(metadata.target)) {
|
101 | this._exposeMetadatas.set(metadata.target, new Map());
|
102 | }
|
103 | this._exposeMetadatas.get(metadata.target).set(metadata.propertyName, metadata);
|
104 | };
|
105 | MetadataStorage.prototype.addExcludeMetadata = function (metadata) {
|
106 | if (!this._excludeMetadatas.has(metadata.target)) {
|
107 | this._excludeMetadatas.set(metadata.target, new Map());
|
108 | }
|
109 | this._excludeMetadatas.get(metadata.target).set(metadata.propertyName, metadata);
|
110 | };
|
111 |
|
112 |
|
113 |
|
114 | MetadataStorage.prototype.findTransformMetadatas = function (target, propertyName, transformationType) {
|
115 | return this.findMetadatas(this._transformMetadatas, target, propertyName)
|
116 | .filter(function (metadata) {
|
117 | if (!metadata.options)
|
118 | return true;
|
119 | if (metadata.options.toClassOnly === true && metadata.options.toPlainOnly === true)
|
120 | return true;
|
121 | if (metadata.options.toClassOnly === true) {
|
122 | return transformationType === TransformOperationExecutor_1.TransformationType.CLASS_TO_CLASS || transformationType === TransformOperationExecutor_1.TransformationType.PLAIN_TO_CLASS;
|
123 | }
|
124 | if (metadata.options.toPlainOnly === true) {
|
125 | return transformationType === TransformOperationExecutor_1.TransformationType.CLASS_TO_PLAIN;
|
126 | }
|
127 | return true;
|
128 | });
|
129 | };
|
130 | MetadataStorage.prototype.findExcludeMetadata = function (target, propertyName) {
|
131 | return this.findMetadata(this._excludeMetadatas, target, propertyName);
|
132 | };
|
133 | MetadataStorage.prototype.findExposeMetadata = function (target, propertyName) {
|
134 | return this.findMetadata(this._exposeMetadatas, target, propertyName);
|
135 | };
|
136 | MetadataStorage.prototype.findExposeMetadataByCustomName = function (target, name) {
|
137 | return this.getExposedMetadatas(target).find(function (metadata) {
|
138 | return metadata.options && metadata.options.name === name;
|
139 | });
|
140 | };
|
141 | MetadataStorage.prototype.findTypeMetadata = function (target, propertyName) {
|
142 | return this.findMetadata(this._typeMetadatas, target, propertyName);
|
143 | };
|
144 | MetadataStorage.prototype.getStrategy = function (target) {
|
145 | var excludeMap = this._excludeMetadatas.get(target);
|
146 | var exclude = excludeMap && excludeMap.get(undefined);
|
147 | var exposeMap = this._exposeMetadatas.get(target);
|
148 | var expose = exposeMap && exposeMap.get(undefined);
|
149 | if ((exclude && expose) || (!exclude && !expose))
|
150 | return "none";
|
151 | return exclude ? "excludeAll" : "exposeAll";
|
152 | };
|
153 | MetadataStorage.prototype.getExposedMetadatas = function (target) {
|
154 | return this.getMetadata(this._exposeMetadatas, target);
|
155 | };
|
156 | MetadataStorage.prototype.getExcludedMetadatas = function (target) {
|
157 | return this.getMetadata(this._excludeMetadatas, target);
|
158 | };
|
159 | MetadataStorage.prototype.getExposedProperties = function (target, transformationType) {
|
160 | return this.getExposedMetadatas(target)
|
161 | .filter(function (metadata) {
|
162 | if (!metadata.options)
|
163 | return true;
|
164 | if (metadata.options.toClassOnly === true && metadata.options.toPlainOnly === true)
|
165 | return true;
|
166 | if (metadata.options.toClassOnly === true) {
|
167 | return transformationType === TransformOperationExecutor_1.TransformationType.CLASS_TO_CLASS || transformationType === TransformOperationExecutor_1.TransformationType.PLAIN_TO_CLASS;
|
168 | }
|
169 | if (metadata.options.toPlainOnly === true) {
|
170 | return transformationType === TransformOperationExecutor_1.TransformationType.CLASS_TO_PLAIN;
|
171 | }
|
172 | return true;
|
173 | })
|
174 | .map(function (metadata) { return metadata.propertyName; });
|
175 | };
|
176 | MetadataStorage.prototype.getExcludedProperties = function (target, transformationType) {
|
177 | return this.getExcludedMetadatas(target)
|
178 | .filter(function (metadata) {
|
179 | if (!metadata.options)
|
180 | return true;
|
181 | if (metadata.options.toClassOnly === true && metadata.options.toPlainOnly === true)
|
182 | return true;
|
183 | if (metadata.options.toClassOnly === true) {
|
184 | return transformationType === TransformOperationExecutor_1.TransformationType.CLASS_TO_CLASS || transformationType === TransformOperationExecutor_1.TransformationType.PLAIN_TO_CLASS;
|
185 | }
|
186 | if (metadata.options.toPlainOnly === true) {
|
187 | return transformationType === TransformOperationExecutor_1.TransformationType.CLASS_TO_PLAIN;
|
188 | }
|
189 | return true;
|
190 | })
|
191 | .map(function (metadata) { return metadata.propertyName; });
|
192 | };
|
193 | MetadataStorage.prototype.clear = function () {
|
194 | this._typeMetadatas.clear();
|
195 | this._exposeMetadatas.clear();
|
196 | this._excludeMetadatas.clear();
|
197 | this._ancestorsMap.clear();
|
198 | };
|
199 |
|
200 |
|
201 |
|
202 | MetadataStorage.prototype.getMetadata = function (metadatas, target) {
|
203 | var metadataFromTargetMap = metadatas.get(target);
|
204 | var metadataFromTarget;
|
205 | if (metadataFromTargetMap) {
|
206 | metadataFromTarget = Array.from(metadataFromTargetMap.values()).filter(function (meta) { return meta.propertyName !== undefined; });
|
207 | }
|
208 | var metadataFromAncestors = [];
|
209 | for (var _i = 0, _a = this.getAncestors(target); _i < _a.length; _i++) {
|
210 | var ancestor = _a[_i];
|
211 | var ancestorMetadataMap = metadatas.get(ancestor);
|
212 | if (ancestorMetadataMap) {
|
213 | var metadataFromAncestor = Array.from(ancestorMetadataMap.values()).filter(function (meta) { return meta.propertyName !== undefined; });
|
214 | metadataFromAncestors.push.apply(metadataFromAncestors, metadataFromAncestor);
|
215 | }
|
216 | }
|
217 | return metadataFromAncestors.concat(metadataFromTarget || []);
|
218 | };
|
219 | MetadataStorage.prototype.findMetadata = function (metadatas, target, propertyName) {
|
220 | var metadataFromTargetMap = metadatas.get(target);
|
221 | if (metadataFromTargetMap) {
|
222 | var metadataFromTarget = metadataFromTargetMap.get(propertyName);
|
223 | if (metadataFromTarget) {
|
224 | return metadataFromTarget;
|
225 | }
|
226 | }
|
227 | for (var _i = 0, _a = this.getAncestors(target); _i < _a.length; _i++) {
|
228 | var ancestor = _a[_i];
|
229 | var ancestorMetadataMap = metadatas.get(ancestor);
|
230 | if (ancestorMetadataMap) {
|
231 | var ancestorResult = ancestorMetadataMap.get(propertyName);
|
232 | if (ancestorResult) {
|
233 | return ancestorResult;
|
234 | }
|
235 | }
|
236 | }
|
237 | return undefined;
|
238 | };
|
239 | MetadataStorage.prototype.findMetadatas = function (metadatas, target, propertyName) {
|
240 | var metadataFromTargetMap = metadatas.get(target);
|
241 | var metadataFromTarget;
|
242 | if (metadataFromTargetMap) {
|
243 | metadataFromTarget = metadataFromTargetMap.get(propertyName);
|
244 | }
|
245 | var metadataFromAncestorsTarget = [];
|
246 | for (var _i = 0, _a = this.getAncestors(target); _i < _a.length; _i++) {
|
247 | var ancestor = _a[_i];
|
248 | var ancestorMetadataMap = metadatas.get(ancestor);
|
249 | if (ancestorMetadataMap) {
|
250 | if (ancestorMetadataMap.has(propertyName)) {
|
251 | metadataFromAncestorsTarget.push.apply(metadataFromAncestorsTarget, ancestorMetadataMap.get(propertyName));
|
252 | }
|
253 | }
|
254 | }
|
255 | return (metadataFromAncestorsTarget).reverse().concat((metadataFromTarget || []).reverse());
|
256 | };
|
257 | MetadataStorage.prototype.getAncestors = function (target) {
|
258 | if (!target)
|
259 | return [];
|
260 | if (!this._ancestorsMap.has(target)) {
|
261 | var ancestors = [];
|
262 | for (var baseClass = Object.getPrototypeOf(target.prototype.constructor); typeof baseClass.prototype !== "undefined"; baseClass = Object.getPrototypeOf(baseClass.prototype.constructor)) {
|
263 | ancestors.push(baseClass);
|
264 | }
|
265 | this._ancestorsMap.set(target, ancestors);
|
266 | }
|
267 | return this._ancestorsMap.get(target);
|
268 | };
|
269 | return MetadataStorage;
|
270 | }());
|
271 | exports.MetadataStorage = MetadataStorage;
|
272 | });
|
273 | define("class-transformer/storage", ["require", "exports", "class-transformer/metadata/MetadataStorage"], function (require, exports, MetadataStorage_1) {
|
274 | "use strict";
|
275 | Object.defineProperty(exports, "__esModule", { value: true });
|
276 | |
277 |
|
278 |
|
279 | exports.defaultMetadataStorage = new MetadataStorage_1.MetadataStorage();
|
280 | });
|
281 | define("class-transformer/TransformOperationExecutor", ["require", "exports", "class-transformer/storage"], function (require, exports, storage_1) {
|
282 | "use strict";
|
283 | Object.defineProperty(exports, "__esModule", { value: true });
|
284 | var TransformationType;
|
285 | (function (TransformationType) {
|
286 | TransformationType[TransformationType["PLAIN_TO_CLASS"] = 0] = "PLAIN_TO_CLASS";
|
287 | TransformationType[TransformationType["CLASS_TO_PLAIN"] = 1] = "CLASS_TO_PLAIN";
|
288 | TransformationType[TransformationType["CLASS_TO_CLASS"] = 2] = "CLASS_TO_CLASS";
|
289 | })(TransformationType = exports.TransformationType || (exports.TransformationType = {}));
|
290 | var TransformOperationExecutor = (function () {
|
291 |
|
292 |
|
293 |
|
294 | function TransformOperationExecutor(transformationType, options) {
|
295 | this.transformationType = transformationType;
|
296 | this.options = options;
|
297 |
|
298 |
|
299 |
|
300 | this.recursionStack = new Set();
|
301 | }
|
302 |
|
303 |
|
304 |
|
305 | TransformOperationExecutor.prototype.transform = function (source, value, targetType, arrayType, isMap, level) {
|
306 | var _this = this;
|
307 | if (level === void 0) { level = 0; }
|
308 | if (Array.isArray(value) || value instanceof Set) {
|
309 | var newValue_1 = arrayType && this.transformationType === TransformationType.PLAIN_TO_CLASS ? instantiateArrayType(arrayType) : [];
|
310 | value.forEach(function (subValue, index) {
|
311 | var subSource = source ? source[index] : undefined;
|
312 | if (!_this.options.enableCircularCheck || !_this.isCircular(subValue)) {
|
313 | var realTargetType = void 0;
|
314 | if (typeof targetType !== "function" && targetType && targetType.options && targetType.options.discriminator && targetType.options.discriminator.property && targetType.options.discriminator.subTypes) {
|
315 | if (_this.transformationType === TransformationType.PLAIN_TO_CLASS) {
|
316 | realTargetType = targetType.options.discriminator.subTypes.find(function (subType) { return subType.name === subValue[targetType.options.discriminator.property]; });
|
317 | var options = { newObject: newValue_1, object: subValue, property: undefined };
|
318 | var newType = targetType.typeFunction(options);
|
319 | realTargetType === undefined ? realTargetType = newType : realTargetType = realTargetType.value;
|
320 | if (!targetType.options.keepDiscriminatorProperty)
|
321 | delete subValue[targetType.options.discriminator.property];
|
322 | }
|
323 | if (_this.transformationType === TransformationType.CLASS_TO_CLASS) {
|
324 | realTargetType = subValue.constructor;
|
325 | }
|
326 | if (_this.transformationType === TransformationType.CLASS_TO_PLAIN) {
|
327 | subValue[targetType.options.discriminator.property] = targetType.options.discriminator.subTypes.find(function (subType) { return subType.value === subValue.constructor; }).name;
|
328 | }
|
329 | }
|
330 | else {
|
331 | realTargetType = targetType;
|
332 | }
|
333 | var value_1 = _this.transform(subSource, subValue, realTargetType, undefined, subValue instanceof Map, level + 1);
|
334 | if (newValue_1 instanceof Set) {
|
335 | newValue_1.add(value_1);
|
336 | }
|
337 | else {
|
338 | newValue_1.push(value_1);
|
339 | }
|
340 | }
|
341 | else if (_this.transformationType === TransformationType.CLASS_TO_CLASS) {
|
342 | if (newValue_1 instanceof Set) {
|
343 | newValue_1.add(subValue);
|
344 | }
|
345 | else {
|
346 | newValue_1.push(subValue);
|
347 | }
|
348 | }
|
349 | });
|
350 | return newValue_1;
|
351 | }
|
352 | else if (targetType === String && !isMap) {
|
353 | if (value === null || value === undefined)
|
354 | return value;
|
355 | return String(value);
|
356 | }
|
357 | else if (targetType === Number && !isMap) {
|
358 | if (value === null || value === undefined)
|
359 | return value;
|
360 | return Number(value);
|
361 | }
|
362 | else if (targetType === Boolean && !isMap) {
|
363 | if (value === null || value === undefined)
|
364 | return value;
|
365 | return Boolean(value);
|
366 | }
|
367 | else if ((targetType === Date || value instanceof Date) && !isMap) {
|
368 | if (value instanceof Date) {
|
369 | return new Date(value.valueOf());
|
370 | }
|
371 | if (value === null || value === undefined)
|
372 | return value;
|
373 | return new Date(value);
|
374 | }
|
375 | else if (testForBuffer() && (targetType === Buffer || value instanceof Buffer) && !isMap) {
|
376 | if (value === null || value === undefined)
|
377 | return value;
|
378 | return Buffer.from(value);
|
379 | }
|
380 | else if (typeof value === "object" && value !== null) {
|
381 |
|
382 | if (!targetType && value.constructor !== Object )
|
383 | targetType = value.constructor;
|
384 | if (!targetType && source)
|
385 | targetType = source.constructor;
|
386 | if (this.options.enableCircularCheck) {
|
387 |
|
388 | this.recursionStack.add(value);
|
389 | }
|
390 | var keys = this.getKeys(targetType, value);
|
391 | var newValue = source ? source : {};
|
392 | if (!source && (this.transformationType === TransformationType.PLAIN_TO_CLASS || this.transformationType === TransformationType.CLASS_TO_CLASS)) {
|
393 | if (isMap) {
|
394 | newValue = new Map();
|
395 | }
|
396 | else if (targetType) {
|
397 | newValue = new targetType();
|
398 | }
|
399 | else {
|
400 | newValue = {};
|
401 | }
|
402 | }
|
403 | var _loop_1 = function (key) {
|
404 | var valueKey = key, newValueKey = key, propertyName = key;
|
405 | if (!this_1.options.ignoreDecorators && targetType) {
|
406 | if (this_1.transformationType === TransformationType.PLAIN_TO_CLASS) {
|
407 | var exposeMetadata = storage_1.defaultMetadataStorage.findExposeMetadataByCustomName(targetType, key);
|
408 | if (exposeMetadata) {
|
409 | propertyName = exposeMetadata.propertyName;
|
410 | newValueKey = exposeMetadata.propertyName;
|
411 | }
|
412 | }
|
413 | else if (this_1.transformationType === TransformationType.CLASS_TO_PLAIN || this_1.transformationType === TransformationType.CLASS_TO_CLASS) {
|
414 | var exposeMetadata = storage_1.defaultMetadataStorage.findExposeMetadata(targetType, key);
|
415 | if (exposeMetadata && exposeMetadata.options && exposeMetadata.options.name) {
|
416 | newValueKey = exposeMetadata.options.name;
|
417 | }
|
418 | }
|
419 | }
|
420 |
|
421 | var subValue = undefined;
|
422 | if (value instanceof Map) {
|
423 | subValue = value.get(valueKey);
|
424 | }
|
425 | else if (value[valueKey] instanceof Function) {
|
426 | subValue = value[valueKey]();
|
427 | }
|
428 | else {
|
429 | subValue = value[valueKey];
|
430 | }
|
431 |
|
432 | var type = undefined, isSubValueMap = subValue instanceof Map;
|
433 | if (targetType && isMap) {
|
434 | type = targetType;
|
435 | }
|
436 | else if (targetType) {
|
437 | var metadata_1 = storage_1.defaultMetadataStorage.findTypeMetadata(targetType, propertyName);
|
438 | if (metadata_1) {
|
439 | var options = { newObject: newValue, object: value, property: propertyName };
|
440 | var newType = metadata_1.typeFunction ? metadata_1.typeFunction(options) : metadata_1.reflectedType;
|
441 | if (metadata_1.options && metadata_1.options.discriminator && metadata_1.options.discriminator.property && metadata_1.options.discriminator.subTypes) {
|
442 | if (!(value[valueKey] instanceof Array)) {
|
443 | if (this_1.transformationType === TransformationType.PLAIN_TO_CLASS) {
|
444 | type = metadata_1.options.discriminator.subTypes.find(function (subType) {
|
445 | if (subValue && metadata_1.options.discriminator.property in subValue) {
|
446 | return subType.name === subValue[metadata_1.options.discriminator.property];
|
447 | }
|
448 | });
|
449 | type === undefined ? type = newType : type = type.value;
|
450 | if (!metadata_1.options.keepDiscriminatorProperty) {
|
451 | if (subValue && metadata_1.options.discriminator.property in subValue) {
|
452 | delete subValue[metadata_1.options.discriminator.property];
|
453 | }
|
454 | }
|
455 | }
|
456 | if (this_1.transformationType === TransformationType.CLASS_TO_CLASS) {
|
457 | type = subValue.constructor;
|
458 | }
|
459 | if (this_1.transformationType === TransformationType.CLASS_TO_PLAIN) {
|
460 | subValue[metadata_1.options.discriminator.property] = metadata_1.options.discriminator.subTypes.find(function (subType) { return subType.value === subValue.constructor; }).name;
|
461 | }
|
462 | }
|
463 | else {
|
464 | type = metadata_1;
|
465 | }
|
466 | }
|
467 | else {
|
468 | type = newType;
|
469 | }
|
470 | isSubValueMap = isSubValueMap || metadata_1.reflectedType === Map;
|
471 | }
|
472 | else if (this_1.options.targetMaps) {
|
473 | this_1.options.targetMaps
|
474 | .filter(function (map) { return map.target === targetType && !!map.properties[propertyName]; })
|
475 | .forEach(function (map) { return type = map.properties[propertyName]; });
|
476 | }
|
477 | else if (this_1.transformationType === TransformationType.PLAIN_TO_CLASS) {
|
478 |
|
479 |
|
480 | var reflectedType = Reflect.getMetadata("design:type", targetType.prototype, propertyName);
|
481 | if (reflectedType) {
|
482 | type = reflectedType;
|
483 | }
|
484 | }
|
485 | }
|
486 |
|
487 | var arrayType_1 = Array.isArray(value[valueKey]) ? this_1.getReflectedType(targetType, propertyName) : undefined;
|
488 |
|
489 | var subSource = source ? source[valueKey] : undefined;
|
490 |
|
491 |
|
492 |
|
493 |
|
494 |
|
495 | if (newValue.constructor.prototype) {
|
496 | var descriptor = Object.getOwnPropertyDescriptor(newValue.constructor.prototype, newValueKey);
|
497 | if ((this_1.transformationType === TransformationType.PLAIN_TO_CLASS || this_1.transformationType === TransformationType.CLASS_TO_CLASS)
|
498 | && ((descriptor && !descriptor.writable) || newValue[newValueKey] instanceof Function))
|
499 | return "continue";
|
500 | }
|
501 | if (!this_1.options.enableCircularCheck || !this_1.isCircular(subValue)) {
|
502 | var transformKey = this_1.transformationType === TransformationType.PLAIN_TO_CLASS ? newValueKey : key;
|
503 | var finalValue = void 0;
|
504 | if (this_1.transformationType === TransformationType.CLASS_TO_PLAIN) {
|
505 |
|
506 | finalValue = value[transformKey];
|
507 |
|
508 | finalValue = this_1.applyCustomTransformations(finalValue, targetType, transformKey, value, this_1.transformationType);
|
509 |
|
510 | finalValue = (value[transformKey] === finalValue) ? subValue : finalValue;
|
511 |
|
512 | finalValue = this_1.transform(subSource, finalValue, type, arrayType_1, isSubValueMap, level + 1);
|
513 | }
|
514 | else {
|
515 | finalValue = this_1.transform(subSource, subValue, type, arrayType_1, isSubValueMap, level + 1);
|
516 | finalValue = this_1.applyCustomTransformations(finalValue, targetType, transformKey, value, this_1.transformationType);
|
517 | }
|
518 | if (newValue instanceof Map) {
|
519 | newValue.set(newValueKey, finalValue);
|
520 | }
|
521 | else {
|
522 | newValue[newValueKey] = finalValue;
|
523 | }
|
524 | }
|
525 | else if (this_1.transformationType === TransformationType.CLASS_TO_CLASS) {
|
526 | var finalValue = subValue;
|
527 | finalValue = this_1.applyCustomTransformations(finalValue, targetType, key, value, this_1.transformationType);
|
528 | if (newValue instanceof Map) {
|
529 | newValue.set(newValueKey, finalValue);
|
530 | }
|
531 | else {
|
532 | newValue[newValueKey] = finalValue;
|
533 | }
|
534 | }
|
535 | };
|
536 | var this_1 = this;
|
537 |
|
538 | for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) {
|
539 | var key = keys_1[_i];
|
540 | _loop_1(key);
|
541 | }
|
542 | if (this.options.enableCircularCheck) {
|
543 | this.recursionStack.delete(value);
|
544 | }
|
545 | return newValue;
|
546 | }
|
547 | else {
|
548 | return value;
|
549 | }
|
550 | };
|
551 | TransformOperationExecutor.prototype.applyCustomTransformations = function (value, target, key, obj, transformationType) {
|
552 | var _this = this;
|
553 | var metadatas = storage_1.defaultMetadataStorage.findTransformMetadatas(target, key, this.transformationType);
|
554 |
|
555 | if (this.options.version !== undefined) {
|
556 | metadatas = metadatas.filter(function (metadata) {
|
557 | if (!metadata.options)
|
558 | return true;
|
559 | return _this.checkVersion(metadata.options.since, metadata.options.until);
|
560 | });
|
561 | }
|
562 |
|
563 | if (this.options.groups && this.options.groups.length) {
|
564 | metadatas = metadatas.filter(function (metadata) {
|
565 | if (!metadata.options)
|
566 | return true;
|
567 | return _this.checkGroups(metadata.options.groups);
|
568 | });
|
569 | }
|
570 | else {
|
571 | metadatas = metadatas.filter(function (metadata) {
|
572 | return !metadata.options || !metadata.options.groups || !metadata.options.groups.length;
|
573 | });
|
574 | }
|
575 | metadatas.forEach(function (metadata) {
|
576 | value = metadata.transformFn(value, obj, transformationType);
|
577 | });
|
578 | return value;
|
579 | };
|
580 |
|
581 | TransformOperationExecutor.prototype.isCircular = function (object) {
|
582 | return this.recursionStack.has(object);
|
583 | };
|
584 | TransformOperationExecutor.prototype.getReflectedType = function (target, propertyName) {
|
585 | if (!target)
|
586 | return undefined;
|
587 | var meta = storage_1.defaultMetadataStorage.findTypeMetadata(target, propertyName);
|
588 | return meta ? meta.reflectedType : undefined;
|
589 | };
|
590 | TransformOperationExecutor.prototype.getKeys = function (target, object) {
|
591 | var _this = this;
|
592 |
|
593 | var strategy = storage_1.defaultMetadataStorage.getStrategy(target);
|
594 | if (strategy === "none")
|
595 | strategy = this.options.strategy || "exposeAll";
|
596 |
|
597 | var keys = [];
|
598 | if (strategy === "exposeAll") {
|
599 | if (object instanceof Map) {
|
600 | keys = Array.from(object.keys());
|
601 | }
|
602 | else {
|
603 | keys = Object.keys(object);
|
604 | }
|
605 | }
|
606 | if (!this.options.ignoreDecorators && target) {
|
607 |
|
608 | var exposedProperties = storage_1.defaultMetadataStorage.getExposedProperties(target, this.transformationType);
|
609 | if (this.transformationType === TransformationType.PLAIN_TO_CLASS) {
|
610 | exposedProperties = exposedProperties.map(function (key) {
|
611 | var exposeMetadata = storage_1.defaultMetadataStorage.findExposeMetadata(target, key);
|
612 | if (exposeMetadata && exposeMetadata.options && exposeMetadata.options.name) {
|
613 | return exposeMetadata.options.name;
|
614 | }
|
615 | return key;
|
616 | });
|
617 | }
|
618 | if (this.options.excludeExtraneousValues) {
|
619 | keys = exposedProperties;
|
620 | }
|
621 | else {
|
622 | keys = keys.concat(exposedProperties);
|
623 | }
|
624 |
|
625 | var excludedProperties_1 = storage_1.defaultMetadataStorage.getExcludedProperties(target, this.transformationType);
|
626 | if (excludedProperties_1.length > 0) {
|
627 | keys = keys.filter(function (key) {
|
628 | return excludedProperties_1.indexOf(key) === -1;
|
629 | });
|
630 | }
|
631 |
|
632 | if (this.options.version !== undefined) {
|
633 | keys = keys.filter(function (key) {
|
634 | var exposeMetadata = storage_1.defaultMetadataStorage.findExposeMetadata(target, key);
|
635 | if (!exposeMetadata || !exposeMetadata.options)
|
636 | return true;
|
637 | return _this.checkVersion(exposeMetadata.options.since, exposeMetadata.options.until);
|
638 | });
|
639 | }
|
640 |
|
641 | if (this.options.groups && this.options.groups.length) {
|
642 | keys = keys.filter(function (key) {
|
643 | var exposeMetadata = storage_1.defaultMetadataStorage.findExposeMetadata(target, key);
|
644 | if (!exposeMetadata || !exposeMetadata.options)
|
645 | return true;
|
646 | return _this.checkGroups(exposeMetadata.options.groups);
|
647 | });
|
648 | }
|
649 | else {
|
650 | keys = keys.filter(function (key) {
|
651 | var exposeMetadata = storage_1.defaultMetadataStorage.findExposeMetadata(target, key);
|
652 | return !exposeMetadata || !exposeMetadata.options || !exposeMetadata.options.groups || !exposeMetadata.options.groups.length;
|
653 | });
|
654 | }
|
655 | }
|
656 |
|
657 | if (this.options.excludePrefixes && this.options.excludePrefixes.length) {
|
658 | keys = keys.filter(function (key) { return _this.options.excludePrefixes.every(function (prefix) {
|
659 | return key.substr(0, prefix.length) !== prefix;
|
660 | }); });
|
661 | }
|
662 |
|
663 | keys = keys.filter(function (key, index, self) {
|
664 | return self.indexOf(key) === index;
|
665 | });
|
666 | return keys;
|
667 | };
|
668 | TransformOperationExecutor.prototype.checkVersion = function (since, until) {
|
669 | var decision = true;
|
670 | if (decision && since)
|
671 | decision = this.options.version >= since;
|
672 | if (decision && until)
|
673 | decision = this.options.version < until;
|
674 | return decision;
|
675 | };
|
676 | TransformOperationExecutor.prototype.checkGroups = function (groups) {
|
677 | if (!groups)
|
678 | return true;
|
679 | return this.options.groups.some(function (optionGroup) { return groups.indexOf(optionGroup) !== -1; });
|
680 | };
|
681 | return TransformOperationExecutor;
|
682 | }());
|
683 | exports.TransformOperationExecutor = TransformOperationExecutor;
|
684 | function instantiateArrayType(arrayType) {
|
685 | var array = new arrayType();
|
686 | if (!(array instanceof Set) && !("push" in array)) {
|
687 | return [];
|
688 | }
|
689 | return array;
|
690 | }
|
691 | function testForBuffer() {
|
692 | try {
|
693 | Buffer;
|
694 | return true;
|
695 | }
|
696 | catch (_a) { }
|
697 | return false;
|
698 | }
|
699 | exports.testForBuffer = testForBuffer;
|
700 | });
|
701 | define("class-transformer/ClassTransformer", ["require", "exports", "class-transformer/TransformOperationExecutor"], function (require, exports, TransformOperationExecutor_2) {
|
702 | "use strict";
|
703 | Object.defineProperty(exports, "__esModule", { value: true });
|
704 | var ClassTransformer = (function () {
|
705 | function ClassTransformer() {
|
706 | }
|
707 | ClassTransformer.prototype.classToPlain = function (object, options) {
|
708 | var executor = new TransformOperationExecutor_2.TransformOperationExecutor(TransformOperationExecutor_2.TransformationType.CLASS_TO_PLAIN, options || {});
|
709 | return executor.transform(undefined, object, undefined, undefined, undefined, undefined);
|
710 | };
|
711 | ClassTransformer.prototype.classToPlainFromExist = function (object, plainObject, options) {
|
712 | var executor = new TransformOperationExecutor_2.TransformOperationExecutor(TransformOperationExecutor_2.TransformationType.CLASS_TO_PLAIN, options || {});
|
713 | return executor.transform(plainObject, object, undefined, undefined, undefined, undefined);
|
714 | };
|
715 | ClassTransformer.prototype.plainToClass = function (cls, plain, options) {
|
716 | var executor = new TransformOperationExecutor_2.TransformOperationExecutor(TransformOperationExecutor_2.TransformationType.PLAIN_TO_CLASS, options || {});
|
717 | return executor.transform(undefined, plain, cls, undefined, undefined, undefined);
|
718 | };
|
719 | ClassTransformer.prototype.plainToClassFromExist = function (clsObject, plain, options) {
|
720 | var executor = new TransformOperationExecutor_2.TransformOperationExecutor(TransformOperationExecutor_2.TransformationType.PLAIN_TO_CLASS, options || {});
|
721 | return executor.transform(clsObject, plain, undefined, undefined, undefined, undefined);
|
722 | };
|
723 | ClassTransformer.prototype.classToClass = function (object, options) {
|
724 | var executor = new TransformOperationExecutor_2.TransformOperationExecutor(TransformOperationExecutor_2.TransformationType.CLASS_TO_CLASS, options || {});
|
725 | return executor.transform(undefined, object, undefined, undefined, undefined, undefined);
|
726 | };
|
727 | ClassTransformer.prototype.classToClassFromExist = function (object, fromObject, options) {
|
728 | var executor = new TransformOperationExecutor_2.TransformOperationExecutor(TransformOperationExecutor_2.TransformationType.CLASS_TO_CLASS, options || {});
|
729 | return executor.transform(fromObject, object, undefined, undefined, undefined, undefined);
|
730 | };
|
731 | ClassTransformer.prototype.serialize = function (object, options) {
|
732 | return JSON.stringify(this.classToPlain(object, options));
|
733 | };
|
734 | |
735 |
|
736 |
|
737 | ClassTransformer.prototype.deserialize = function (cls, json, options) {
|
738 | var jsonObject = JSON.parse(json);
|
739 | return this.plainToClass(cls, jsonObject, options);
|
740 | };
|
741 | |
742 |
|
743 |
|
744 | ClassTransformer.prototype.deserializeArray = function (cls, json, options) {
|
745 | var jsonObject = JSON.parse(json);
|
746 | return this.plainToClass(cls, jsonObject, options);
|
747 | };
|
748 | return ClassTransformer;
|
749 | }());
|
750 | exports.ClassTransformer = ClassTransformer;
|
751 | });
|
752 | define("class-transformer/decorators", ["require", "exports", "class-transformer/ClassTransformer", "class-transformer/storage", "class-transformer/metadata/TypeMetadata", "class-transformer/metadata/ExposeMetadata", "class-transformer/metadata/ExcludeMetadata", "class-transformer/metadata/TransformMetadata"], function (require, exports, ClassTransformer_1, storage_2, TypeMetadata_1, ExposeMetadata_1, ExcludeMetadata_1, TransformMetadata_1) {
|
753 | "use strict";
|
754 | Object.defineProperty(exports, "__esModule", { value: true });
|
755 | |
756 |
|
757 |
|
758 | function Transform(transformFn, options) {
|
759 | return function (target, key) {
|
760 | var metadata = new TransformMetadata_1.TransformMetadata(target.constructor, key, transformFn, options);
|
761 | storage_2.defaultMetadataStorage.addTransformMetadata(metadata);
|
762 | };
|
763 | }
|
764 | exports.Transform = Transform;
|
765 | |
766 |
|
767 |
|
768 |
|
769 | function Type(typeFunction, options) {
|
770 | return function (target, key) {
|
771 | var type = Reflect.getMetadata("design:type", target, key);
|
772 | var metadata = new TypeMetadata_1.TypeMetadata(target.constructor, key, type, typeFunction, options);
|
773 | storage_2.defaultMetadataStorage.addTypeMetadata(metadata);
|
774 | };
|
775 | }
|
776 | exports.Type = Type;
|
777 | |
778 |
|
779 |
|
780 |
|
781 |
|
782 | function Expose(options) {
|
783 | return function (object, propertyName) {
|
784 | var metadata = new ExposeMetadata_1.ExposeMetadata(object instanceof Function ? object : object.constructor, propertyName, options || {});
|
785 | storage_2.defaultMetadataStorage.addExposeMetadata(metadata);
|
786 | };
|
787 | }
|
788 | exports.Expose = Expose;
|
789 | |
790 |
|
791 |
|
792 |
|
793 |
|
794 | function Exclude(options) {
|
795 | return function (object, propertyName) {
|
796 | var metadata = new ExcludeMetadata_1.ExcludeMetadata(object instanceof Function ? object : object.constructor, propertyName, options || {});
|
797 | storage_2.defaultMetadataStorage.addExcludeMetadata(metadata);
|
798 | };
|
799 | }
|
800 | exports.Exclude = Exclude;
|
801 | |
802 |
|
803 |
|
804 | function TransformClassToPlain(params) {
|
805 | return function (target, propertyKey, descriptor) {
|
806 | var classTransformer = new ClassTransformer_1.ClassTransformer();
|
807 | var originalMethod = descriptor.value;
|
808 | descriptor.value = function () {
|
809 | var args = [];
|
810 | for (var _i = 0; _i < arguments.length; _i++) {
|
811 | args[_i] = arguments[_i];
|
812 | }
|
813 | var result = originalMethod.apply(this, args);
|
814 | var isPromise = !!result && (typeof result === "object" || typeof result === "function") && typeof result.then === "function";
|
815 | return isPromise ? result.then(function (data) { return classTransformer.classToPlain(data, params); }) : classTransformer.classToPlain(result, params);
|
816 | };
|
817 | };
|
818 | }
|
819 | exports.TransformClassToPlain = TransformClassToPlain;
|
820 | |
821 |
|
822 |
|
823 | function TransformClassToClass(params) {
|
824 | return function (target, propertyKey, descriptor) {
|
825 | var classTransformer = new ClassTransformer_1.ClassTransformer();
|
826 | var originalMethod = descriptor.value;
|
827 | descriptor.value = function () {
|
828 | var args = [];
|
829 | for (var _i = 0; _i < arguments.length; _i++) {
|
830 | args[_i] = arguments[_i];
|
831 | }
|
832 | var result = originalMethod.apply(this, args);
|
833 | var isPromise = !!result && (typeof result === "object" || typeof result === "function") && typeof result.then === "function";
|
834 | return isPromise ? result.then(function (data) { return classTransformer.classToClass(data, params); }) : classTransformer.classToClass(result, params);
|
835 | };
|
836 | };
|
837 | }
|
838 | exports.TransformClassToClass = TransformClassToClass;
|
839 | |
840 |
|
841 |
|
842 | function TransformPlainToClass(classType, params) {
|
843 | return function (target, propertyKey, descriptor) {
|
844 | var classTransformer = new ClassTransformer_1.ClassTransformer();
|
845 | var originalMethod = descriptor.value;
|
846 | descriptor.value = function () {
|
847 | var args = [];
|
848 | for (var _i = 0; _i < arguments.length; _i++) {
|
849 | args[_i] = arguments[_i];
|
850 | }
|
851 | var result = originalMethod.apply(this, args);
|
852 | var isPromise = !!result && (typeof result === "object" || typeof result === "function") && typeof result.then === "function";
|
853 | return isPromise ? result.then(function (data) { return classTransformer.plainToClass(classType, data, params); }) : classTransformer.plainToClass(classType, result, params);
|
854 | };
|
855 | };
|
856 | }
|
857 | exports.TransformPlainToClass = TransformPlainToClass;
|
858 | });
|
859 | define("class-transformer/index", ["require", "exports", "class-transformer/ClassTransformer", "class-transformer/ClassTransformer", "class-transformer/decorators"], function (require, exports, ClassTransformer_2, ClassTransformer_3, decorators_1) {
|
860 | "use strict";
|
861 | function __export(m) {
|
862 | for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
|
863 | }
|
864 | Object.defineProperty(exports, "__esModule", { value: true });
|
865 | exports.ClassTransformer = ClassTransformer_3.ClassTransformer;
|
866 | __export(decorators_1);
|
867 | var classTransformer = new ClassTransformer_2.ClassTransformer();
|
868 | function classToPlain(object, options) {
|
869 | return classTransformer.classToPlain(object, options);
|
870 | }
|
871 | exports.classToPlain = classToPlain;
|
872 | function classToPlainFromExist(object, plainObject, options) {
|
873 | return classTransformer.classToPlainFromExist(object, plainObject, options);
|
874 | }
|
875 | exports.classToPlainFromExist = classToPlainFromExist;
|
876 | function plainToClass(cls, plain, options) {
|
877 | return classTransformer.plainToClass(cls, plain, options);
|
878 | }
|
879 | exports.plainToClass = plainToClass;
|
880 | function plainToClassFromExist(clsObject, plain, options) {
|
881 | return classTransformer.plainToClassFromExist(clsObject, plain, options);
|
882 | }
|
883 | exports.plainToClassFromExist = plainToClassFromExist;
|
884 | function classToClass(object, options) {
|
885 | return classTransformer.classToClass(object, options);
|
886 | }
|
887 | exports.classToClass = classToClass;
|
888 | function classToClassFromExist(object, fromObject, options) {
|
889 | return classTransformer.classToClassFromExist(object, fromObject, options);
|
890 | }
|
891 | exports.classToClassFromExist = classToClassFromExist;
|
892 | function serialize(object, options) {
|
893 | return classTransformer.serialize(object, options);
|
894 | }
|
895 | exports.serialize = serialize;
|
896 | |
897 |
|
898 |
|
899 | function deserialize(cls, json, options) {
|
900 | return classTransformer.deserialize(cls, json, options);
|
901 | }
|
902 | exports.deserialize = deserialize;
|
903 | |
904 |
|
905 |
|
906 | function deserializeArray(cls, json, options) {
|
907 | return classTransformer.deserializeArray(cls, json, options);
|
908 | }
|
909 | exports.deserializeArray = deserializeArray;
|
910 | |
911 |
|
912 |
|
913 | var TransformationType;
|
914 | (function (TransformationType) {
|
915 | TransformationType[TransformationType["PLAIN_TO_CLASS"] = 0] = "PLAIN_TO_CLASS";
|
916 | TransformationType[TransformationType["CLASS_TO_PLAIN"] = 1] = "CLASS_TO_PLAIN";
|
917 | TransformationType[TransformationType["CLASS_TO_CLASS"] = 2] = "CLASS_TO_CLASS";
|
918 | })(TransformationType = exports.TransformationType || (exports.TransformationType = {}));
|
919 | });
|
920 | define("class-transformer", ["require", "exports", "class-transformer/index"], function (require, exports, index_1) {
|
921 | "use strict";
|
922 | function __export(m) {
|
923 | for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
|
924 | }
|
925 | Object.defineProperty(exports, "__esModule", { value: true });
|
926 | __export(index_1);
|
927 | });
|