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