@pristine-ts/data-mapping-common 0.0.293 → 0.0.295
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/cjs/builders/auto-data-mapping.builder.js +34 -31
- package/dist/lib/cjs/builders/auto-data-mapping.builder.js.map +1 -1
- package/dist/lib/cjs/decorators/array.decorator.js +25 -0
- package/dist/lib/cjs/decorators/array.decorator.js.map +1 -0
- package/dist/lib/cjs/decorators/decorators.js +1 -0
- package/dist/lib/cjs/decorators/decorators.js.map +1 -1
- package/dist/lib/cjs/enums/metadata.enum.js +1 -0
- package/dist/lib/cjs/enums/metadata.enum.js.map +1 -1
- package/dist/lib/cjs/mappers/data.mapper.js +13 -2
- package/dist/lib/cjs/mappers/data.mapper.js.map +1 -1
- package/dist/lib/cjs/nodes/data-mapping.node.js +14 -3
- package/dist/lib/cjs/nodes/data-mapping.node.js.map +1 -1
- package/dist/lib/cjs/types/array-member-type-factory-callback.type.js +3 -0
- package/dist/lib/cjs/types/array-member-type-factory-callback.type.js.map +1 -0
- package/dist/lib/cjs/types/type-factory-callback.type.js +3 -0
- package/dist/lib/cjs/types/type-factory-callback.type.js.map +1 -0
- package/dist/lib/cjs/types/types.js +2 -0
- package/dist/lib/cjs/types/types.js.map +1 -1
- package/dist/lib/esm/builders/auto-data-mapping.builder.js +35 -32
- package/dist/lib/esm/builders/auto-data-mapping.builder.js.map +1 -1
- package/dist/lib/esm/decorators/array.decorator.js +21 -0
- package/dist/lib/esm/decorators/array.decorator.js.map +1 -0
- package/dist/lib/esm/decorators/decorators.js +1 -0
- package/dist/lib/esm/decorators/decorators.js.map +1 -1
- package/dist/lib/esm/enums/metadata.enum.js +1 -0
- package/dist/lib/esm/enums/metadata.enum.js.map +1 -1
- package/dist/lib/esm/mappers/data.mapper.js +13 -2
- package/dist/lib/esm/mappers/data.mapper.js.map +1 -1
- package/dist/lib/esm/nodes/data-mapping.node.js +14 -3
- package/dist/lib/esm/nodes/data-mapping.node.js.map +1 -1
- package/dist/lib/esm/types/array-member-type-factory-callback.type.js +2 -0
- package/dist/lib/esm/types/array-member-type-factory-callback.type.js.map +1 -0
- package/dist/lib/esm/types/type-factory-callback.type.js +2 -0
- package/dist/lib/esm/types/type-factory-callback.type.js.map +1 -0
- package/dist/lib/esm/types/types.js +2 -0
- package/dist/lib/esm/types/types.js.map +1 -1
- package/dist/types/decorators/array.decorator.d.ts +6 -0
- package/dist/types/decorators/decorators.d.ts +1 -0
- package/dist/types/decorators/type.decorator.d.ts +1 -1
- package/dist/types/enums/metadata.enum.d.ts +2 -1
- package/dist/types/mappers/data.mapper.d.ts +1 -1
- package/dist/types/nodes/data-mapping.node.d.ts +3 -2
- package/dist/types/types/array-member-type-factory-callback.type.d.ts +1 -0
- package/dist/types/types/type-factory-callback.type.d.ts +1 -0
- package/dist/types/types/types.d.ts +2 -0
- package/package.json +3 -3
|
@@ -36,14 +36,14 @@ class AutoDataMappingBuilder {
|
|
|
36
36
|
* @private
|
|
37
37
|
*/
|
|
38
38
|
internalBuild(source, destinationType, root, parent, options) {
|
|
39
|
-
if (!source) {
|
|
39
|
+
if (!source || !destinationType) {
|
|
40
40
|
return;
|
|
41
41
|
}
|
|
42
42
|
try {
|
|
43
43
|
// Get the metadata of destinationType and iterate over its properties.
|
|
44
44
|
const classInformation = metadata_1.ClassMetadata.getInformation(destinationType);
|
|
45
45
|
classInformation.properties.forEach(propertyKey => {
|
|
46
|
-
var _a, _b, _c, _d;
|
|
46
|
+
var _a, _b, _c, _d, _e;
|
|
47
47
|
// Retrieve the metadata for the property
|
|
48
48
|
const propertyInformation = metadata_1.PropertyMetadata.getInformation(destinationType.prototype, propertyKey);
|
|
49
49
|
let typeObject = propertyInformation.typeObject;
|
|
@@ -69,35 +69,38 @@ class AutoDataMappingBuilder {
|
|
|
69
69
|
if (!source.hasOwnProperty(propertyKey) || Array.isArray(source[propertyKey]) === false || source[propertyKey].length === 0) {
|
|
70
70
|
return;
|
|
71
71
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
nestedType = data_mapping_node_type_enum_1.DataMappingNodeTypeEnum.ObjectArray;
|
|
77
|
-
break;
|
|
78
|
-
}
|
|
79
|
-
// If the array is an array of scalars, then it will be a LeafNode of type ScalarArray with no children.
|
|
80
|
-
if (nestedType === data_mapping_node_type_enum_1.DataMappingNodeTypeEnum.ScalarArray) {
|
|
81
|
-
const dataMappingLeaf = parent.addArrayOfScalar();
|
|
82
|
-
const normalizers = [];
|
|
83
|
-
// todo: Allow for options to be specified per attribute. We should probably add a decorator to can customize the normalizer.
|
|
72
|
+
let arrayMemberType = metadata_1.PropertyMetadata.getMetadata(destinationType.prototype, propertyKey, metadata_enum_1.MetadataEnum.ArrayMemberTypeFactory);
|
|
73
|
+
if (arrayMemberType === undefined) { // If this is undefined, then we it's possible that it's a ScalarArray.
|
|
74
|
+
arrayMemberType = (_b = metadata_1.PropertyMetadata.getMetadata(destinationType.prototype, propertyKey, metadata_1.PropertyInformationEnum.ArrayMemberType)) !== null && _b !== void 0 ? _b : source[propertyKey][0]; // Use the first element in the array to determine the type of content stored in the array if not type have been passed. Here, we assume that all the elements in the array are of the same type.
|
|
75
|
+
const nestedElementType = metadata_1.TypeUtils.getTypeOfValue(arrayMemberType);
|
|
84
76
|
switch (nestedElementType) {
|
|
85
|
-
case metadata_1.TypeEnum.
|
|
86
|
-
|
|
87
|
-
break;
|
|
88
|
-
case metadata_1.TypeEnum.String:
|
|
89
|
-
normalizers.push(string_normalizer_1.StringNormalizer.name);
|
|
90
|
-
break;
|
|
91
|
-
case metadata_1.TypeEnum.Date:
|
|
92
|
-
normalizers.push(date_normalizer_1.DateNormalizer.name);
|
|
77
|
+
case metadata_1.TypeEnum.Object:
|
|
78
|
+
nestedType = data_mapping_node_type_enum_1.DataMappingNodeTypeEnum.ObjectArray;
|
|
93
79
|
break;
|
|
94
80
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
.
|
|
98
|
-
|
|
99
|
-
.
|
|
100
|
-
|
|
81
|
+
// If the array is an array of scalars, then it will be a LeafNode of type ScalarArray with no children.
|
|
82
|
+
if (nestedType === data_mapping_node_type_enum_1.DataMappingNodeTypeEnum.ScalarArray) {
|
|
83
|
+
const dataMappingLeaf = parent.addArrayOfScalar();
|
|
84
|
+
const normalizers = [];
|
|
85
|
+
// todo: Allow for options to be specified per attribute. We should probably add a decorator to can customize the normalizer.
|
|
86
|
+
switch (nestedElementType) {
|
|
87
|
+
case metadata_1.TypeEnum.Number:
|
|
88
|
+
normalizers.push(number_normalizer_1.NumberNormalizer.name);
|
|
89
|
+
break;
|
|
90
|
+
case metadata_1.TypeEnum.String:
|
|
91
|
+
normalizers.push(string_normalizer_1.StringNormalizer.name);
|
|
92
|
+
break;
|
|
93
|
+
case metadata_1.TypeEnum.Date:
|
|
94
|
+
normalizers.push(date_normalizer_1.DateNormalizer.name);
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
normalizers.forEach(normalizer => dataMappingLeaf.addNormalizer(normalizer));
|
|
98
|
+
dataMappingLeaf.setSourceProperty(propertyKey)
|
|
99
|
+
.setDestinationProperty(propertyKey)
|
|
100
|
+
.setIsOptional((_c = propertyInformation.isNullable) !== null && _c !== void 0 ? _c : options.isOptionalDefaultValue)
|
|
101
|
+
.end();
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
101
104
|
}
|
|
102
105
|
// Else, it's an array of objects and we must iterate over the first element to get all the properties and
|
|
103
106
|
// build the tree.
|
|
@@ -105,8 +108,8 @@ class AutoDataMappingBuilder {
|
|
|
105
108
|
dataMappingNode
|
|
106
109
|
.setSourceProperty(propertyKey)
|
|
107
110
|
.setDestinationProperty(propertyKey)
|
|
108
|
-
.setDestinationType(
|
|
109
|
-
.setIsOptional((
|
|
111
|
+
.setDestinationType(arrayMemberType)
|
|
112
|
+
.setIsOptional((_d = propertyInformation.isNullable) !== null && _d !== void 0 ? _d : options.isOptionalDefaultValue)
|
|
110
113
|
.end();
|
|
111
114
|
// We assume all the objects are similar so we use only the first one to build the schema
|
|
112
115
|
return this.internalBuild(source[propertyKey][0], propertyInformation.arrayMemberObject, root, dataMappingNode, options);
|
|
@@ -129,7 +132,7 @@ class AutoDataMappingBuilder {
|
|
|
129
132
|
dataMappingLeaf
|
|
130
133
|
.setSourceProperty(propertyKey)
|
|
131
134
|
.setDestinationProperty(propertyKey)
|
|
132
|
-
.setIsOptional((
|
|
135
|
+
.setIsOptional((_e = propertyInformation.isNullable) !== null && _e !== void 0 ? _e : options.isOptionalDefaultValue)
|
|
133
136
|
.end();
|
|
134
137
|
});
|
|
135
138
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auto-data-mapping.builder.js","sourceRoot":"","sources":["../../../../src/builders/auto-data-mapping.builder.ts"],"names":[],"mappings":";;;AACA,iEAA0D;AAC1D,kEAA2D;AAC3D,
|
|
1
|
+
{"version":3,"file":"auto-data-mapping.builder.js","sourceRoot":"","sources":["../../../../src/builders/auto-data-mapping.builder.ts"],"names":[],"mappings":";;;AACA,iEAA0D;AAC1D,kEAA2D;AAC3D,oDAAoH;AACpH,kEAA2D;AAC3D,wEAAkE;AAClE,wEAAkE;AAClE,oEAA8D;AAC9D,sFAA6E;AAC7E,oGAA2F;AAC3F,0DAAoD;AAGpD,MAAa,sBAAsB;IAC/B;;;;;;;OAOG;IACH,KAAK,CAAC,MAAW,EAAE,eAAsC,EAAE,OAAuC;QAC9F,MAAM,kBAAkB,GAAG,IAAI,yCAAkB,EAAE,CAAC;QAEpD,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,eAAe,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,IAAI,iEAA6B,CAAC,OAAO,CAAC,CAAC,CAAC;QAEhI,OAAO,kBAAkB,CAAC;IAC9B,CAAC;IAED;;;;;;;;;OASG;IACK,aAAa,CAAC,MAAW,EAAE,eAAsC,EAAE,IAAwB,EAC7E,MAA4C,EAAE,OAAsC;QAC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C,oCAAgB,CAAC,IAAI,CAAC,CAAC;wBACxC,MAAM;oBAEV,KAAK,mBAAQ,CAAC,MAAM;wBAChB,WAAW,CAAC,IAAI,CAAC,oCAAgB,CAAC,IAAI,CAAC,CAAC;wBACxC,MAAM;oBAEV,KAAK,mBAAQ,CAAC,IAAI;wBACd,WAAW,CAAC,IAAI,CAAC,gCAAc,CAAC,IAAI,CAAC,CAAC;wBACtC,MAAM;gBACd,CAAC;gBAED,MAAM,eAAe,GAAG,IAAI,mCAAe,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;gBAC1D,WAAW,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC,eAAe,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC,CAAC;gBAE7E,eAAe;qBACV,iBAAiB,CAAC,WAAW,CAAC;qBAC9B,sBAAsB,CAAC,WAAW,CAAC;qBACnC,aAAa,CAAC,MAAA,mBAAmB,CAAC,UAAU,mCAAI,OAAO,CAAC,sBAAsB,CAAC;qBAC/E,GAAG,EAAE,CAAC;YACf,CAAC,CAAC,CAAA;QACN,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACT,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACrB,CAAC;IACL,CAAC;CACJ;AA5JD,wDA4JC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.array = void 0;
|
|
4
|
+
const metadata_enum_1 = require("../enums/metadata.enum");
|
|
5
|
+
const metadata_1 = require("@pristine-ts/metadata");
|
|
6
|
+
/**
|
|
7
|
+
* This decorator can be used to specify that a property is nullable. This data
|
|
8
|
+
* is currently not available out of the box so it needs to be manually specified.
|
|
9
|
+
*/
|
|
10
|
+
const array = (dataType) => {
|
|
11
|
+
return (target, propertyKey) => {
|
|
12
|
+
if (dataType) {
|
|
13
|
+
// if the dataType is a function, then it's a factory callback so we store it with a different key.
|
|
14
|
+
if (typeof dataType === 'function' && !dataType.prototype) {
|
|
15
|
+
metadata_1.PropertyMetadata.defineMetadata(target, propertyKey, metadata_enum_1.MetadataEnum.ArrayMemberTypeFactory, dataType);
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
metadata_1.PropertyMetadata.defineMetadata(target, propertyKey, metadata_1.PropertyInformationEnum.ArrayMemberType, dataType);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
metadata_1.PropertyMetadata.propertySeen(target, propertyKey);
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
exports.array = array;
|
|
25
|
+
//# sourceMappingURL=array.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"array.decorator.js","sourceRoot":"","sources":["../../../../src/decorators/array.decorator.ts"],"names":[],"mappings":";;;AACA,0DAAoD;AACpD,oDAAgF;AAChF;;;GAGG;AACI,MAAM,KAAK,GAAG,CAAC,QAAkD,EAAE,EAAE;IACxE,OAAO,CAAC,MAAW,EAAE,WAA4B,EAAE,EAAE;QACjD,IAAG,QAAQ,EAAE,CAAC;YACV,mGAAmG;YACnG,IAAG,OAAO,QAAQ,KAAK,UAAU,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,CAAC;gBACvD,2BAAgB,CAAC,cAAc,CAAC,MAAM,EAAE,WAAW,EAAE,4BAAY,CAAC,sBAAsB,EAAE,QAAQ,CAAC,CAAC;YACxG,CAAC;iBAAM,CAAC;gBACJ,2BAAgB,CAAC,cAAc,CAAC,MAAM,EAAE,WAAW,EAAE,kCAAuB,CAAC,eAAe,EAAE,QAAQ,CAAC,CAAC;YAC5G,CAAC;QACL,CAAC;QAED,2BAAgB,CAAC,YAAY,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IACvD,CAAC,CAAC;AACN,CAAC,CAAA;AAbY,QAAA,KAAK,SAajB"}
|
|
@@ -14,5 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./array.decorator"), exports);
|
|
17
18
|
__exportStar(require("./type.decorator"), exports);
|
|
18
19
|
//# sourceMappingURL=decorators.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["../../../../src/decorators/decorators.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAAgC"}
|
|
1
|
+
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["../../../../src/decorators/decorators.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAiC;AACjC,mDAAgC"}
|
|
@@ -4,5 +4,6 @@ exports.MetadataEnum = void 0;
|
|
|
4
4
|
var MetadataEnum;
|
|
5
5
|
(function (MetadataEnum) {
|
|
6
6
|
MetadataEnum["TypeFactory"] = "type:factory";
|
|
7
|
+
MetadataEnum["ArrayMemberTypeFactory"] = "type:array-member-type-factory";
|
|
7
8
|
})(MetadataEnum || (exports.MetadataEnum = MetadataEnum = {}));
|
|
8
9
|
//# sourceMappingURL=metadata.enum.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metadata.enum.js","sourceRoot":"","sources":["../../../../src/enums/metadata.enum.ts"],"names":[],"mappings":";;;AAAA,IAAY,
|
|
1
|
+
{"version":3,"file":"metadata.enum.js","sourceRoot":"","sources":["../../../../src/enums/metadata.enum.ts"],"names":[],"mappings":";;;AAAA,IAAY,YAGX;AAHD,WAAY,YAAY;IACpB,4CAA4B,CAAA;IAC5B,yEAAyD,CAAA;AAC7D,CAAC,EAHW,YAAY,4BAAZ,YAAY,QAGvB"}
|
|
@@ -12,7 +12,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.DataMapper = void 0;
|
|
13
13
|
const class_transformer_1 = require("class-transformer");
|
|
14
14
|
const data_mapping_interceptor_not_found_error_1 = require("../errors/data-mapping-interceptor-not-found.error");
|
|
15
|
-
const auto_data_mapping_builder_options_1 = require("../options/auto-data-mapping-builder.options");
|
|
16
15
|
const data_mapper_options_1 = require("../options/data-mapper.options");
|
|
17
16
|
class DataMapper {
|
|
18
17
|
constructor(autoDataMappingBuilder, dataNormalizers, dataTransformerInterceptors) {
|
|
@@ -53,8 +52,20 @@ class DataMapper {
|
|
|
53
52
|
autoMap(source, destinationType, options) {
|
|
54
53
|
return __awaiter(this, void 0, void 0, function* () {
|
|
55
54
|
try {
|
|
55
|
+
if (Array.isArray(source)) {
|
|
56
|
+
if (source.length === 0) {
|
|
57
|
+
return [];
|
|
58
|
+
}
|
|
59
|
+
const dataMappingBuilder = this.autoDataMappingBuilder.build(source[0], destinationType, options);
|
|
60
|
+
const destination = [];
|
|
61
|
+
for (const element of source) {
|
|
62
|
+
destination.push(yield this.map(dataMappingBuilder, element, destinationType, new data_mapper_options_1.DataMapperOptions({
|
|
63
|
+
excludeExtraneousValues: options === null || options === void 0 ? void 0 : options.excludeExtraneousValues,
|
|
64
|
+
})));
|
|
65
|
+
}
|
|
66
|
+
return destination;
|
|
67
|
+
}
|
|
56
68
|
const dataMappingBuilder = this.autoDataMappingBuilder.build(source, destinationType, options);
|
|
57
|
-
options = new auto_data_mapping_builder_options_1.AutoDataMappingBuilderOptions(options);
|
|
58
69
|
return yield this.map(dataMappingBuilder, source, destinationType, new data_mapper_options_1.DataMapperOptions({
|
|
59
70
|
excludeExtraneousValues: options === null || options === void 0 ? void 0 : options.excludeExtraneousValues,
|
|
60
71
|
}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data.mapper.js","sourceRoot":"","sources":["../../../../src/mappers/data.mapper.ts"],"names":[],"mappings":";;;;;;;;;;;;AAKA,yDAAoE;AACpE,iHAAuG;
|
|
1
|
+
{"version":3,"file":"data.mapper.js","sourceRoot":"","sources":["../../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;AAjID,gCAiIC"}
|
|
@@ -114,7 +114,6 @@ class DataMappingNode extends base_data_mapping_node_1.BaseDataMappingNode {
|
|
|
114
114
|
throw new data_mapping_source_property_not_found_error_1.DataMappingSourcePropertyNotFoundError("The property '" + this.sourceProperty + "' isn't found in the Source object and isn't marked as Optional. If you want to ignore this property, use the 'setIsOptional(true)' method in the builder.", this.sourceProperty);
|
|
115
115
|
}
|
|
116
116
|
const sourceElement = source[this.sourceProperty];
|
|
117
|
-
//if(destination[this.destinationProperty] === undefined) {
|
|
118
117
|
if (this.type === data_mapping_node_type_enum_1.DataMappingNodeTypeEnum.ObjectArray) {
|
|
119
118
|
destination[this.destinationProperty] = [];
|
|
120
119
|
}
|
|
@@ -131,7 +130,6 @@ class DataMappingNode extends base_data_mapping_node_1.BaseDataMappingNode {
|
|
|
131
130
|
});
|
|
132
131
|
}
|
|
133
132
|
}
|
|
134
|
-
// }
|
|
135
133
|
const destinationElement = destination[this.destinationProperty];
|
|
136
134
|
if (this.type === data_mapping_node_type_enum_1.DataMappingNodeTypeEnum.ObjectArray) {
|
|
137
135
|
// This means that the source[propertyKey] contains an array of objects and each object should be mapped
|
|
@@ -139,10 +137,22 @@ class DataMappingNode extends base_data_mapping_node_1.BaseDataMappingNode {
|
|
|
139
137
|
if (Array.isArray(array) === false) {
|
|
140
138
|
throw new array_data_mapping_node_invalid_source_property_type_error_1.ArrayDataMappingNodeInvalidSourcePropertyTypeError(`According to your schema, the property '${this.sourceProperty}' in the source object must contain an Array of objects. Instead, it contains: '${typeof array}'.`, this.sourceProperty);
|
|
141
139
|
}
|
|
140
|
+
let index = 0;
|
|
142
141
|
for (const element of array) {
|
|
143
142
|
let dest = {};
|
|
144
143
|
if (this.destinationType) {
|
|
145
|
-
|
|
144
|
+
if (typeof this.destinationType === "function") {
|
|
145
|
+
const destinationType = this.destinationType;
|
|
146
|
+
dest = (0, class_transformer_1.plainToInstance)(destinationType(source, this.sourceProperty, index).constructor, element);
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
dest = (0, class_transformer_1.plainToInstance)(this.destinationType, {});
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
if ((options === null || options === void 0 ? void 0 : options.excludeExtraneousValues) === false) {
|
|
153
|
+
Object.keys(element).forEach(property => {
|
|
154
|
+
dest[property] = element[property];
|
|
155
|
+
});
|
|
146
156
|
}
|
|
147
157
|
for (const key in this.nodes) {
|
|
148
158
|
if (this.nodes.hasOwnProperty(key) === false) {
|
|
@@ -153,6 +163,7 @@ class DataMappingNode extends base_data_mapping_node_1.BaseDataMappingNode {
|
|
|
153
163
|
}
|
|
154
164
|
destinationElement.push(dest);
|
|
155
165
|
}
|
|
166
|
+
index++;
|
|
156
167
|
return;
|
|
157
168
|
}
|
|
158
169
|
// When the current node is not an array, we simply iterate
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data-mapping.node.js","sourceRoot":"","sources":["../../../../src/nodes/data-mapping.node.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,sFAA6E;AAC7E,2DAAoD;AAEpD,qEAA6D;AAC7D,yHAA8G;AAG9G,qJAE8E;AAC9E,yDAAoE;
|
|
1
|
+
{"version":3,"file":"data-mapping.node.js","sourceRoot":"","sources":["../../../../src/nodes/data-mapping.node.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,sFAA6E;AAC7E,2DAAoD;AAEpD,qEAA6D;AAC7D,yHAA8G;AAG9G,qJAE8E;AAC9E,yDAAoE;AAIpE,MAAa,eAAgB,SAAQ,4CAAmB;IAqBpD,YAA4B,IAAwB,EACxB,MAA4C,EAC5C,OAAgC,qDAAuB,CAAC,IAAI;QAEpF,KAAK,EAAE,CAAC;QAJgB,SAAI,GAAJ,IAAI,CAAoB;QACxB,WAAM,GAAN,MAAM,CAAsC;QAC5C,SAAI,GAAJ,IAAI,CAAwD;QAZxF;;WAEG;QACI,eAAU,GAAY,KAAK,CAAC;IAYnC,CAAC;IAED;;;OAGG;IACI,iBAA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0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"array-member-type-factory-callback.type.js","sourceRoot":"","sources":["../../../../src/types/array-member-type-factory-callback.type.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-factory-callback.type.js","sourceRoot":"","sources":["../../../../src/types/type-factory-callback.type.ts"],"names":[],"mappings":""}
|
|
@@ -14,6 +14,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./array-member-type-factory-callback.type"), exports);
|
|
17
18
|
__exportStar(require("./data-normalizer-unique-key.type"), exports);
|
|
18
19
|
__exportStar(require("./data-mapping-interceptor-unique-key.type"), exports);
|
|
20
|
+
__exportStar(require("./type-factory-callback.type"), exports);
|
|
19
21
|
//# sourceMappingURL=types.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/types/types.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oEAAkD;AAClD,6EAA2D"}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/types/types.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4EAA0D;AAC1D,oEAAkD;AAClD,6EAA2D;AAC3D,+DAA6C"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DataMappingBuilder } from "./data-mapping.builder";
|
|
2
2
|
import { DataMappingNode } from "../nodes/data-mapping.node";
|
|
3
|
-
import { ClassMetadata, PropertyMetadata, TypeEnum, TypeUtils } from "@pristine-ts/metadata";
|
|
3
|
+
import { ClassMetadata, PropertyInformationEnum, PropertyMetadata, TypeEnum, TypeUtils } from "@pristine-ts/metadata";
|
|
4
4
|
import { DataMappingLeaf } from "../nodes/data-mapping.leaf";
|
|
5
5
|
import { NumberNormalizer } from "../normalizers/number.normalizer";
|
|
6
6
|
import { StringNormalizer } from "../normalizers/string.normalizer";
|
|
@@ -33,14 +33,14 @@ export class AutoDataMappingBuilder {
|
|
|
33
33
|
* @private
|
|
34
34
|
*/
|
|
35
35
|
internalBuild(source, destinationType, root, parent, options) {
|
|
36
|
-
if (!source) {
|
|
36
|
+
if (!source || !destinationType) {
|
|
37
37
|
return;
|
|
38
38
|
}
|
|
39
39
|
try {
|
|
40
40
|
// Get the metadata of destinationType and iterate over its properties.
|
|
41
41
|
const classInformation = ClassMetadata.getInformation(destinationType);
|
|
42
42
|
classInformation.properties.forEach(propertyKey => {
|
|
43
|
-
var _a, _b, _c, _d;
|
|
43
|
+
var _a, _b, _c, _d, _e;
|
|
44
44
|
// Retrieve the metadata for the property
|
|
45
45
|
const propertyInformation = PropertyMetadata.getInformation(destinationType.prototype, propertyKey);
|
|
46
46
|
let typeObject = propertyInformation.typeObject;
|
|
@@ -66,35 +66,38 @@ export class AutoDataMappingBuilder {
|
|
|
66
66
|
if (!source.hasOwnProperty(propertyKey) || Array.isArray(source[propertyKey]) === false || source[propertyKey].length === 0) {
|
|
67
67
|
return;
|
|
68
68
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
nestedType = DataMappingNodeTypeEnum.ObjectArray;
|
|
74
|
-
break;
|
|
75
|
-
}
|
|
76
|
-
// If the array is an array of scalars, then it will be a LeafNode of type ScalarArray with no children.
|
|
77
|
-
if (nestedType === DataMappingNodeTypeEnum.ScalarArray) {
|
|
78
|
-
const dataMappingLeaf = parent.addArrayOfScalar();
|
|
79
|
-
const normalizers = [];
|
|
80
|
-
// todo: Allow for options to be specified per attribute. We should probably add a decorator to can customize the normalizer.
|
|
69
|
+
let arrayMemberType = PropertyMetadata.getMetadata(destinationType.prototype, propertyKey, MetadataEnum.ArrayMemberTypeFactory);
|
|
70
|
+
if (arrayMemberType === undefined) { // If this is undefined, then we it's possible that it's a ScalarArray.
|
|
71
|
+
arrayMemberType = (_b = PropertyMetadata.getMetadata(destinationType.prototype, propertyKey, PropertyInformationEnum.ArrayMemberType)) !== null && _b !== void 0 ? _b : source[propertyKey][0]; // Use the first element in the array to determine the type of content stored in the array if not type have been passed. Here, we assume that all the elements in the array are of the same type.
|
|
72
|
+
const nestedElementType = TypeUtils.getTypeOfValue(arrayMemberType);
|
|
81
73
|
switch (nestedElementType) {
|
|
82
|
-
case TypeEnum.
|
|
83
|
-
|
|
84
|
-
break;
|
|
85
|
-
case TypeEnum.String:
|
|
86
|
-
normalizers.push(StringNormalizer.name);
|
|
87
|
-
break;
|
|
88
|
-
case TypeEnum.Date:
|
|
89
|
-
normalizers.push(DateNormalizer.name);
|
|
74
|
+
case TypeEnum.Object:
|
|
75
|
+
nestedType = DataMappingNodeTypeEnum.ObjectArray;
|
|
90
76
|
break;
|
|
91
77
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
.
|
|
95
|
-
|
|
96
|
-
.
|
|
97
|
-
|
|
78
|
+
// If the array is an array of scalars, then it will be a LeafNode of type ScalarArray with no children.
|
|
79
|
+
if (nestedType === DataMappingNodeTypeEnum.ScalarArray) {
|
|
80
|
+
const dataMappingLeaf = parent.addArrayOfScalar();
|
|
81
|
+
const normalizers = [];
|
|
82
|
+
// todo: Allow for options to be specified per attribute. We should probably add a decorator to can customize the normalizer.
|
|
83
|
+
switch (nestedElementType) {
|
|
84
|
+
case TypeEnum.Number:
|
|
85
|
+
normalizers.push(NumberNormalizer.name);
|
|
86
|
+
break;
|
|
87
|
+
case TypeEnum.String:
|
|
88
|
+
normalizers.push(StringNormalizer.name);
|
|
89
|
+
break;
|
|
90
|
+
case TypeEnum.Date:
|
|
91
|
+
normalizers.push(DateNormalizer.name);
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
normalizers.forEach(normalizer => dataMappingLeaf.addNormalizer(normalizer));
|
|
95
|
+
dataMappingLeaf.setSourceProperty(propertyKey)
|
|
96
|
+
.setDestinationProperty(propertyKey)
|
|
97
|
+
.setIsOptional((_c = propertyInformation.isNullable) !== null && _c !== void 0 ? _c : options.isOptionalDefaultValue)
|
|
98
|
+
.end();
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
98
101
|
}
|
|
99
102
|
// Else, it's an array of objects and we must iterate over the first element to get all the properties and
|
|
100
103
|
// build the tree.
|
|
@@ -102,8 +105,8 @@ export class AutoDataMappingBuilder {
|
|
|
102
105
|
dataMappingNode
|
|
103
106
|
.setSourceProperty(propertyKey)
|
|
104
107
|
.setDestinationProperty(propertyKey)
|
|
105
|
-
.setDestinationType(
|
|
106
|
-
.setIsOptional((
|
|
108
|
+
.setDestinationType(arrayMemberType)
|
|
109
|
+
.setIsOptional((_d = propertyInformation.isNullable) !== null && _d !== void 0 ? _d : options.isOptionalDefaultValue)
|
|
107
110
|
.end();
|
|
108
111
|
// We assume all the objects are similar so we use only the first one to build the schema
|
|
109
112
|
return this.internalBuild(source[propertyKey][0], propertyInformation.arrayMemberObject, root, dataMappingNode, options);
|
|
@@ -126,7 +129,7 @@ export class AutoDataMappingBuilder {
|
|
|
126
129
|
dataMappingLeaf
|
|
127
130
|
.setSourceProperty(propertyKey)
|
|
128
131
|
.setDestinationProperty(propertyKey)
|
|
129
|
-
.setIsOptional((
|
|
132
|
+
.setIsOptional((_e = propertyInformation.isNullable) !== null && _e !== void 0 ? _e : options.isOptionalDefaultValue)
|
|
130
133
|
.end();
|
|
131
134
|
});
|
|
132
135
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auto-data-mapping.builder.js","sourceRoot":"","sources":["../../../../src/builders/auto-data-mapping.builder.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,kBAAkB,EAAC,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAC,eAAe,EAAC,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAC,aAAa,EAAE,gBAAgB,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C,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;wBACxC,MAAM;oBAEV,KAAK,QAAQ,CAAC,IAAI;wBACd,WAAW,CAAC,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;wBACtC,MAAM;gBACd,CAAC;gBAED,MAAM,eAAe,GAAG,IAAI,eAAe,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;gBAC1D,WAAW,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC,eAAe,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC,CAAC;gBAE7E,eAAe;qBACV,iBAAiB,CAAC,WAAW,CAAC;qBAC9B,sBAAsB,CAAC,WAAW,CAAC;qBACnC,aAAa,CAAC,MAAA,mBAAmB,CAAC,UAAU,mCAAI,OAAO,CAAC,sBAAsB,CAAC;qBAC/E,GAAG,EAAE,CAAC;YACf,CAAC,CAAC,CAAA;QACN,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACT,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACrB,CAAC;IACL,CAAC;CACJ"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { MetadataEnum } from "../enums/metadata.enum";
|
|
2
|
+
import { PropertyMetadata, PropertyInformationEnum } from "@pristine-ts/metadata";
|
|
3
|
+
/**
|
|
4
|
+
* This decorator can be used to specify that a property is nullable. This data
|
|
5
|
+
* is currently not available out of the box so it needs to be manually specified.
|
|
6
|
+
*/
|
|
7
|
+
export const array = (dataType) => {
|
|
8
|
+
return (target, propertyKey) => {
|
|
9
|
+
if (dataType) {
|
|
10
|
+
// if the dataType is a function, then it's a factory callback so we store it with a different key.
|
|
11
|
+
if (typeof dataType === 'function' && !dataType.prototype) {
|
|
12
|
+
PropertyMetadata.defineMetadata(target, propertyKey, MetadataEnum.ArrayMemberTypeFactory, dataType);
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
PropertyMetadata.defineMetadata(target, propertyKey, PropertyInformationEnum.ArrayMemberType, dataType);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
PropertyMetadata.propertySeen(target, propertyKey);
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=array.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"array.decorator.js","sourceRoot":"","sources":["../../../../src/decorators/array.decorator.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,YAAY,EAAC,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAC,gBAAgB,EAAE,uBAAuB,EAAC,MAAO,uBAAuB,CAAA;AAChF;;;GAGG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,QAAkD,EAAE,EAAE;IACxE,OAAO,CAAC,MAAW,EAAE,WAA4B,EAAE,EAAE;QACjD,IAAG,QAAQ,EAAE,CAAC;YACV,mGAAmG;YACnG,IAAG,OAAO,QAAQ,KAAK,UAAU,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,CAAC;gBACvD,gBAAgB,CAAC,cAAc,CAAC,MAAM,EAAE,WAAW,EAAE,YAAY,CAAC,sBAAsB,EAAE,QAAQ,CAAC,CAAC;YACxG,CAAC;iBAAM,CAAC;gBACJ,gBAAgB,CAAC,cAAc,CAAC,MAAM,EAAE,WAAW,EAAE,uBAAuB,CAAC,eAAe,EAAE,QAAQ,CAAC,CAAC;YAC5G,CAAC;QACL,CAAC;QAED,gBAAgB,CAAC,YAAY,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IACvD,CAAC,CAAC;AACN,CAAC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["../../../../src/decorators/decorators.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA"}
|
|
1
|
+
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["../../../../src/decorators/decorators.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA;AACjC,cAAc,kBAAkB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metadata.enum.js","sourceRoot":"","sources":["../../../../src/enums/metadata.enum.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,
|
|
1
|
+
{"version":3,"file":"metadata.enum.js","sourceRoot":"","sources":["../../../../src/enums/metadata.enum.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,YAGX;AAHD,WAAY,YAAY;IACpB,4CAA4B,CAAA;IAC5B,yEAAyD,CAAA;AAC7D,CAAC,EAHW,YAAY,KAAZ,YAAY,QAGvB"}
|
|
@@ -9,7 +9,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { plainToInstance } from "class-transformer";
|
|
11
11
|
import { DataMappingInterceptorNotFoundError } from "../errors/data-mapping-interceptor-not-found.error";
|
|
12
|
-
import { AutoDataMappingBuilderOptions } from "../options/auto-data-mapping-builder.options";
|
|
13
12
|
import { DataMapperOptions } from "../options/data-mapper.options";
|
|
14
13
|
export class DataMapper {
|
|
15
14
|
constructor(autoDataMappingBuilder, dataNormalizers, dataTransformerInterceptors) {
|
|
@@ -50,8 +49,20 @@ export class DataMapper {
|
|
|
50
49
|
autoMap(source, destinationType, options) {
|
|
51
50
|
return __awaiter(this, void 0, void 0, function* () {
|
|
52
51
|
try {
|
|
52
|
+
if (Array.isArray(source)) {
|
|
53
|
+
if (source.length === 0) {
|
|
54
|
+
return [];
|
|
55
|
+
}
|
|
56
|
+
const dataMappingBuilder = this.autoDataMappingBuilder.build(source[0], destinationType, options);
|
|
57
|
+
const destination = [];
|
|
58
|
+
for (const element of source) {
|
|
59
|
+
destination.push(yield this.map(dataMappingBuilder, element, destinationType, new DataMapperOptions({
|
|
60
|
+
excludeExtraneousValues: options === null || options === void 0 ? void 0 : options.excludeExtraneousValues,
|
|
61
|
+
})));
|
|
62
|
+
}
|
|
63
|
+
return destination;
|
|
64
|
+
}
|
|
53
65
|
const dataMappingBuilder = this.autoDataMappingBuilder.build(source, destinationType, options);
|
|
54
|
-
options = new AutoDataMappingBuilderOptions(options);
|
|
55
66
|
return yield this.map(dataMappingBuilder, source, destinationType, new DataMapperOptions({
|
|
56
67
|
excludeExtraneousValues: options === null || options === void 0 ? void 0 : options.excludeExtraneousValues,
|
|
57
68
|
}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data.mapper.js","sourceRoot":"","sources":["../../../../src/mappers/data.mapper.ts"],"names":[],"mappings":";;;;;;;;;AAKA,OAAO,EAAmB,eAAe,EAAC,MAAM,mBAAmB,CAAC;AACpE,OAAO,EAAC,mCAAmC,EAAC,MAAM,oDAAoD,CAAC;
|
|
1
|
+
{"version":3,"file":"data.mapper.js","sourceRoot":"","sources":["../../../../src/mappers/data.mapper.ts"],"names":[],"mappings":";;;;;;;;;AAKA,OAAO,EAAmB,eAAe,EAAC,MAAM,mBAAmB,CAAC;AACpE,OAAO,EAAC,mCAAmC,EAAC,MAAM,oDAAoD,CAAC;AAIvG,OAAO,EAAC,iBAAiB,EAAC,MAAM,gCAAgC,CAAC;AAEjE,MAAM,OAAO,UAAU;IAInB,YACqB,sBAA8C,EAC9C,eAAoD,EACpD,2BAA8D;QAF9D,2BAAsB,GAAtB,sBAAsB,CAAwB;QAC9C,oBAAe,GAAf,eAAe,CAAqC;QACpD,gCAA2B,GAA3B,2BAA2B,CAAmC;QANlE,uBAAkB,GAA4E,EAAE,CAAA;QAChG,mCAA8B,GAAsF,EAAE,CAAA;QAMnI,eAAe,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE;YACrC,IAAI,CAAC,kBAAkB,CAAC,cAAc,CAAC,YAAY,EAAE,CAAC,GAAG,cAAc,CAAC;QAC5E,CAAC,CAAC,CAAA;QAEF,2BAA2B,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE;YAC9C,IAAI,CAAC,8BAA8B,CAAC,WAAW,CAAC,YAAY,EAA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AC,iBAAiB,EAAE,WAAW,EAAE,IAAI,CAAC,kBAAkB,EAAE,OAAO,CAAC,CAAC;YACrF,CAAC;YAED,mCAAmC;YACnC,KAAK,MAAM,OAAO,IAAI,OAAO,CAAC,wBAAwB,EAAE,CAAC;gBACrD,MAAM,WAAW,GAAoC,IAAI,CAAC,8BAA8B,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;gBAEtG,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;oBAC5B,MAAM,IAAI,mCAAmC,CAAC,oDAAoD,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;gBACrH,CAAC;gBAED,gDAAgD;gBAChD,WAAW,GAAG,MAAM,WAAW,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC;YAC9D,CAAC;YAED,IAAG,eAAe,EAAE,CAAC;gBACjB,WAAW,GAAG,eAAe,CAAC,eAAe,EAAE,WAAW,CAAC,CAAC;YAChE,CAAC;YAED,OAAO,WAAW,CAAC;QACvB,CAAC;KAAA;CACJ"}
|
|
@@ -111,7 +111,6 @@ export class DataMappingNode extends BaseDataMappingNode {
|
|
|
111
111
|
throw new DataMappingSourcePropertyNotFoundError("The property '" + this.sourceProperty + "' isn't found in the Source object and isn't marked as Optional. If you want to ignore this property, use the 'setIsOptional(true)' method in the builder.", this.sourceProperty);
|
|
112
112
|
}
|
|
113
113
|
const sourceElement = source[this.sourceProperty];
|
|
114
|
-
//if(destination[this.destinationProperty] === undefined) {
|
|
115
114
|
if (this.type === DataMappingNodeTypeEnum.ObjectArray) {
|
|
116
115
|
destination[this.destinationProperty] = [];
|
|
117
116
|
}
|
|
@@ -128,7 +127,6 @@ export class DataMappingNode extends BaseDataMappingNode {
|
|
|
128
127
|
});
|
|
129
128
|
}
|
|
130
129
|
}
|
|
131
|
-
// }
|
|
132
130
|
const destinationElement = destination[this.destinationProperty];
|
|
133
131
|
if (this.type === DataMappingNodeTypeEnum.ObjectArray) {
|
|
134
132
|
// This means that the source[propertyKey] contains an array of objects and each object should be mapped
|
|
@@ -136,10 +134,22 @@ export class DataMappingNode extends BaseDataMappingNode {
|
|
|
136
134
|
if (Array.isArray(array) === false) {
|
|
137
135
|
throw new ArrayDataMappingNodeInvalidSourcePropertyTypeError(`According to your schema, the property '${this.sourceProperty}' in the source object must contain an Array of objects. Instead, it contains: '${typeof array}'.`, this.sourceProperty);
|
|
138
136
|
}
|
|
137
|
+
let index = 0;
|
|
139
138
|
for (const element of array) {
|
|
140
139
|
let dest = {};
|
|
141
140
|
if (this.destinationType) {
|
|
142
|
-
|
|
141
|
+
if (typeof this.destinationType === "function") {
|
|
142
|
+
const destinationType = this.destinationType;
|
|
143
|
+
dest = plainToInstance(destinationType(source, this.sourceProperty, index).constructor, element);
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
dest = plainToInstance(this.destinationType, {});
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
if ((options === null || options === void 0 ? void 0 : options.excludeExtraneousValues) === false) {
|
|
150
|
+
Object.keys(element).forEach(property => {
|
|
151
|
+
dest[property] = element[property];
|
|
152
|
+
});
|
|
143
153
|
}
|
|
144
154
|
for (const key in this.nodes) {
|
|
145
155
|
if (this.nodes.hasOwnProperty(key) === false) {
|
|
@@ -150,6 +160,7 @@ export class DataMappingNode extends BaseDataMappingNode {
|
|
|
150
160
|
}
|
|
151
161
|
destinationElement.push(dest);
|
|
152
162
|
}
|
|
163
|
+
index++;
|
|
153
164
|
return;
|
|
154
165
|
}
|
|
155
166
|
// When the current node is not an array, we simply iterate
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data-mapping.node.js","sourceRoot":"","sources":["../../../../src/nodes/data-mapping.node.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAC,uBAAuB,EAAC,MAAM,sCAAsC,CAAC;AAC7E,OAAO,EAAC,eAAe,EAAC,MAAM,qBAAqB,CAAC;AAEpD,OAAO,EAAC,mBAAmB,EAAC,MAAM,0BAA0B,CAAC;AAC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AI,CAAC;gBAClC,KAAK,uBAAuB,CAAC,WAAW;oBACpC,MAAM,IAAI,GAAG,IAAI,eAAe,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;oBACxD,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;oBACtB,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,cAAc,CAAC,GAAG,IAAI,CAAC;oBACvC,SAAS;YACjB,CAAC;QACL,CAAC;IACL,CAAC;IAED;;OAEG;IACI,MAAM;QACT,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;QAEzB,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE,CAAC;YACtB,IAAI,KAAK,CAAC,cAAc,CAAC,GAAG,CAAC,KAAK,KAAK,EAAE,CAAC;gBACtC,SAAS;YACb,CAAC;YAED,KAAK,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC;QACrC,CAAC;QAED,OAAO;YACH,OAAO,EAAE,IAAI,CAAC,IAAI;YAClB,gBAAgB,EAAE,IAAI,CAAC,cAAc;YACrC,qBAAqB,EAAE,IAAI,CAAC,mBAAmB;YAC/C,YAAY,EAAE,IAAI,CAAC,UAAU;YAC7B,OAAO,EAAE,KAAK;SACjB,CAAA;IACL,CAAC;CACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"array-member-type-factory-callback.type.js","sourceRoot":"","sources":["../../../../src/types/array-member-type-factory-callback.type.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-factory-callback.type.js","sourceRoot":"","sources":["../../../../src/types/type-factory-callback.type.ts"],"names":[],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/types/types.ts"],"names":[],"mappings":"AAAA,cAAc,mCAAmC,CAAC;AAClD,cAAc,4CAA4C,CAAC"}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/types/types.ts"],"names":[],"mappings":"AAAA,cAAc,2CAA2C,CAAC;AAC1D,cAAc,mCAAmC,CAAC;AAClD,cAAc,4CAA4C,CAAC;AAC3D,cAAc,8BAA8B,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ArrayMemberTypeFactoryCallbackType } from "../types/array-member-type-factory-callback.type";
|
|
2
|
+
/**
|
|
3
|
+
* This decorator can be used to specify that a property is nullable. This data
|
|
4
|
+
* is currently not available out of the box so it needs to be manually specified.
|
|
5
|
+
*/
|
|
6
|
+
export declare const array: (dataType: any | ArrayMemberTypeFactoryCallbackType) => (target: any, propertyKey: string | symbol) => void;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { TypeFactoryCallback } from "../types/type-factory-callback.type";
|
|
2
2
|
export declare const type: (callback: TypeFactoryCallback) => (target: any, propertyKey: string | symbol) => void;
|
|
@@ -26,7 +26,7 @@ export declare class DataMapper {
|
|
|
26
26
|
* @param destinationType
|
|
27
27
|
* @param options
|
|
28
28
|
*/
|
|
29
|
-
autoMap(source: any, destinationType: ClassConstructor<any>, options?: AutoDataMappingBuilderOptions): Promise<any>;
|
|
29
|
+
autoMap(source: any | any[], destinationType: ClassConstructor<any>, options?: AutoDataMappingBuilderOptions): Promise<any>;
|
|
30
30
|
/**
|
|
31
31
|
* This method takes a builder, a source and maps it according to the builder. You can pass a `destinationType (optional)`
|
|
32
32
|
* that is an object that will be constructed.
|
|
@@ -6,6 +6,7 @@ import { DataNormalizerUniqueKey } from "../types/data-normalizer-unique-key.typ
|
|
|
6
6
|
import { DataNormalizerInterface } from "../interfaces/data-normalizer.interface";
|
|
7
7
|
import { ClassConstructor } from "class-transformer";
|
|
8
8
|
import { DataMapperOptions } from "../options/data-mapper.options";
|
|
9
|
+
import { ArrayMemberTypeFactoryCallbackType } from "../types/array-member-type-factory-callback.type";
|
|
9
10
|
export declare class DataMappingNode extends BaseDataMappingNode {
|
|
10
11
|
readonly root: DataMappingBuilder;
|
|
11
12
|
readonly parent: DataMappingNode | DataMappingBuilder;
|
|
@@ -25,7 +26,7 @@ export declare class DataMappingNode extends BaseDataMappingNode {
|
|
|
25
26
|
/**
|
|
26
27
|
* IMPORTANT: This property is not serializable. It will be lost during the export.
|
|
27
28
|
*/
|
|
28
|
-
destinationType?: ClassConstructor<any
|
|
29
|
+
destinationType?: ClassConstructor<any> | ArrayMemberTypeFactoryCallbackType;
|
|
29
30
|
constructor(root: DataMappingBuilder, parent: DataMappingNode | DataMappingBuilder, type?: DataMappingNodeTypeEnum);
|
|
30
31
|
/**
|
|
31
32
|
* This is a setter for `sourceProperty`.
|
|
@@ -41,7 +42,7 @@ export declare class DataMappingNode extends BaseDataMappingNode {
|
|
|
41
42
|
* This is a setter for `destinationType`.
|
|
42
43
|
* @param destinationType
|
|
43
44
|
*/
|
|
44
|
-
setDestinationType(destinationType: ClassConstructor<any>): DataMappingNode;
|
|
45
|
+
setDestinationType(destinationType: ClassConstructor<any> | ArrayMemberTypeFactoryCallbackType): DataMappingNode;
|
|
45
46
|
/**
|
|
46
47
|
* This is a setter for `isOptional`.
|
|
47
48
|
* @param isOptional
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type ArrayMemberTypeFactoryCallbackType = (target: any, propertyKey: string, index: number) => any;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type TypeFactoryCallback = (target: any, propertyKey: string) => any;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pristine-ts/data-mapping-common",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.295",
|
|
4
4
|
"description": "",
|
|
5
5
|
"module": "dist/lib/esm/data-mapping-common.js",
|
|
6
6
|
"main": "dist/lib/cjs/data-mapping-common.js",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@pristine-ts/class-validator": "^1.0.25",
|
|
24
|
-
"@pristine-ts/metadata": "
|
|
24
|
+
"@pristine-ts/metadata": "^1.0.13",
|
|
25
25
|
"class-transformer": "^0.5.1",
|
|
26
26
|
"date-fns": "^3.3.1"
|
|
27
27
|
},
|
|
@@ -62,5 +62,5 @@
|
|
|
62
62
|
"jest-extended/all"
|
|
63
63
|
]
|
|
64
64
|
},
|
|
65
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "cbf98b7e70d2f67440825fceb679b5cdb4442cc9"
|
|
66
66
|
}
|