@pristine-ts/data-mapping-common 0.0.287 → 0.0.288
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.
|
@@ -39,98 +39,103 @@ class AutoDataMappingBuilder {
|
|
|
39
39
|
if (!source) {
|
|
40
40
|
return;
|
|
41
41
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
// If the property references an object, this means that we need to recursively call this method to build the schema.
|
|
56
|
-
if (propertyInformation.typeEnum === metadata_1.TypeEnum.Object) {
|
|
57
|
-
const dataMappingNode = new data_mapping_node_1.DataMappingNode(root, parent);
|
|
58
|
-
dataMappingNode
|
|
59
|
-
.setSourceProperty(propertyKey)
|
|
60
|
-
.setDestinationProperty(propertyKey)
|
|
61
|
-
.setDestinationType(typeObject)
|
|
62
|
-
.setIsOptional((_a = propertyInformation.isNullable) !== null && _a !== void 0 ? _a : options.isOptionalDefaultValue)
|
|
63
|
-
.end();
|
|
64
|
-
return this.internalBuild(source[propertyKey], typeObject, root, dataMappingNode, options);
|
|
65
|
-
}
|
|
66
|
-
else if (propertyInformation.typeEnum === metadata_1.TypeEnum.Array) { // If the property references an array, we need to iterate over each element and recursively call this method to build the schema.
|
|
67
|
-
let nestedType = data_mapping_node_type_enum_1.DataMappingNodeTypeEnum.ScalarArray;
|
|
68
|
-
if (!source.hasOwnProperty(propertyKey) || Array.isArray(source[propertyKey]) === false || source[propertyKey].length === 0) {
|
|
69
|
-
return;
|
|
42
|
+
try {
|
|
43
|
+
// Get the metadata of destinationType and iterate over its properties.
|
|
44
|
+
const classInformation = metadata_1.ClassMetadata.getInformation(destinationType);
|
|
45
|
+
classInformation.properties.forEach(propertyKey => {
|
|
46
|
+
var _a, _b, _c, _d;
|
|
47
|
+
// Retrieve the metadata for the property
|
|
48
|
+
const propertyInformation = metadata_1.PropertyMetadata.getInformation(destinationType.prototype, propertyKey);
|
|
49
|
+
let typeObject = propertyInformation.typeObject;
|
|
50
|
+
// Check if we have a `@typeFactory` decorator, it means that there's a callback that must be executed
|
|
51
|
+
// for this property to retrieve the actual DestinationType object. If there's one, execute it.
|
|
52
|
+
const typeFactoryCallback = metadata_1.PropertyMetadata.getMetadata(destinationType.prototype, propertyKey, metadata_enum_1.MetadataEnum.TypeFactory);
|
|
53
|
+
if (typeFactoryCallback) {
|
|
54
|
+
typeObject = typeFactoryCallback(source, propertyKey).constructor;
|
|
70
55
|
}
|
|
71
|
-
//
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
56
|
+
// If the property references an object, this means that we need to recursively call this method to build the schema.
|
|
57
|
+
if (propertyInformation.typeEnum === metadata_1.TypeEnum.Object) {
|
|
58
|
+
const dataMappingNode = new data_mapping_node_1.DataMappingNode(root, parent);
|
|
59
|
+
dataMappingNode
|
|
60
|
+
.setSourceProperty(propertyKey)
|
|
61
|
+
.setDestinationProperty(propertyKey)
|
|
62
|
+
.setDestinationType(typeObject)
|
|
63
|
+
.setIsOptional((_a = propertyInformation.isNullable) !== null && _a !== void 0 ? _a : options.isOptionalDefaultValue)
|
|
64
|
+
.end();
|
|
65
|
+
return this.internalBuild(source[propertyKey], typeObject, root, dataMappingNode, options);
|
|
77
66
|
}
|
|
78
|
-
// If the
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
67
|
+
else if (propertyInformation.typeEnum === metadata_1.TypeEnum.Array) { // If the property references an array, we need to iterate over each element and recursively call this method to build the schema.
|
|
68
|
+
let nestedType = data_mapping_node_type_enum_1.DataMappingNodeTypeEnum.ScalarArray;
|
|
69
|
+
if (!source.hasOwnProperty(propertyKey) || Array.isArray(source[propertyKey]) === false || source[propertyKey].length === 0) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
// Use the first element in the array to determine the type of content stored in the array. Here, we assume that all the elements in the array are of the same type.
|
|
73
|
+
const nestedElementType = metadata_1.TypeUtils.getTypeOfValue(source[propertyKey][0]);
|
|
83
74
|
switch (nestedElementType) {
|
|
84
|
-
case metadata_1.TypeEnum.
|
|
85
|
-
|
|
86
|
-
break;
|
|
87
|
-
case metadata_1.TypeEnum.String:
|
|
88
|
-
normalizers.push(string_normalizer_1.StringNormalizer.name);
|
|
89
|
-
break;
|
|
90
|
-
case metadata_1.TypeEnum.Date:
|
|
91
|
-
normalizers.push(date_normalizer_1.DateNormalizer.name);
|
|
75
|
+
case metadata_1.TypeEnum.Object:
|
|
76
|
+
nestedType = data_mapping_node_type_enum_1.DataMappingNodeTypeEnum.ObjectArray;
|
|
92
77
|
break;
|
|
93
78
|
}
|
|
94
|
-
|
|
95
|
-
|
|
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.
|
|
84
|
+
switch (nestedElementType) {
|
|
85
|
+
case metadata_1.TypeEnum.Number:
|
|
86
|
+
normalizers.push(number_normalizer_1.NumberNormalizer.name);
|
|
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);
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
normalizers.forEach(normalizer => dataMappingLeaf.addNormalizer(normalizer));
|
|
96
|
+
dataMappingLeaf.setSourceProperty(propertyKey)
|
|
97
|
+
.setDestinationProperty(propertyKey)
|
|
98
|
+
.setIsOptional((_b = propertyInformation.isNullable) !== null && _b !== void 0 ? _b : options.isOptionalDefaultValue)
|
|
99
|
+
.end();
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
// Else, it's an array of objects and we must iterate over the first element to get all the properties and
|
|
103
|
+
// build the tree.
|
|
104
|
+
const dataMappingNode = parent.addArrayOfObjects();
|
|
105
|
+
dataMappingNode
|
|
106
|
+
.setSourceProperty(propertyKey)
|
|
96
107
|
.setDestinationProperty(propertyKey)
|
|
97
|
-
.
|
|
108
|
+
.setDestinationType(propertyInformation.arrayMemberObject)
|
|
109
|
+
.setIsOptional((_c = propertyInformation.isNullable) !== null && _c !== void 0 ? _c : options.isOptionalDefaultValue)
|
|
98
110
|
.end();
|
|
99
|
-
|
|
111
|
+
// We assume all the objects are similar so we use only the first one to build the schema
|
|
112
|
+
return this.internalBuild(source[propertyKey][0], propertyInformation.arrayMemberObject, root, dataMappingNode, options);
|
|
113
|
+
}
|
|
114
|
+
const normalizers = [];
|
|
115
|
+
// todo: Allow for options to be specified per attribute. We should probably add a decorator to can customize the normalizer.
|
|
116
|
+
switch (propertyInformation.typeEnum) {
|
|
117
|
+
case metadata_1.TypeEnum.Number:
|
|
118
|
+
normalizers.push(number_normalizer_1.NumberNormalizer.name);
|
|
119
|
+
break;
|
|
120
|
+
case metadata_1.TypeEnum.String:
|
|
121
|
+
normalizers.push(string_normalizer_1.StringNormalizer.name);
|
|
122
|
+
break;
|
|
123
|
+
case metadata_1.TypeEnum.Date:
|
|
124
|
+
normalizers.push(date_normalizer_1.DateNormalizer.name);
|
|
125
|
+
break;
|
|
100
126
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
dataMappingNode
|
|
127
|
+
const dataMappingLeaf = new data_mapping_leaf_1.DataMappingLeaf(root, parent);
|
|
128
|
+
normalizers.forEach(normalizer => dataMappingLeaf.addNormalizer(normalizer));
|
|
129
|
+
dataMappingLeaf
|
|
105
130
|
.setSourceProperty(propertyKey)
|
|
106
131
|
.setDestinationProperty(propertyKey)
|
|
107
|
-
.
|
|
108
|
-
.setIsOptional((_c = propertyInformation.isNullable) !== null && _c !== void 0 ? _c : options.isOptionalDefaultValue)
|
|
132
|
+
.setIsOptional((_d = propertyInformation.isNullable) !== null && _d !== void 0 ? _d : options.isOptionalDefaultValue)
|
|
109
133
|
.end();
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
switch (propertyInformation.typeEnum) {
|
|
116
|
-
case metadata_1.TypeEnum.Number:
|
|
117
|
-
normalizers.push(number_normalizer_1.NumberNormalizer.name);
|
|
118
|
-
break;
|
|
119
|
-
case metadata_1.TypeEnum.String:
|
|
120
|
-
normalizers.push(string_normalizer_1.StringNormalizer.name);
|
|
121
|
-
break;
|
|
122
|
-
case metadata_1.TypeEnum.Date:
|
|
123
|
-
normalizers.push(date_normalizer_1.DateNormalizer.name);
|
|
124
|
-
break;
|
|
125
|
-
}
|
|
126
|
-
const dataMappingLeaf = new data_mapping_leaf_1.DataMappingLeaf(root, parent);
|
|
127
|
-
normalizers.forEach(normalizer => dataMappingLeaf.addNormalizer(normalizer));
|
|
128
|
-
dataMappingLeaf
|
|
129
|
-
.setSourceProperty(propertyKey)
|
|
130
|
-
.setDestinationProperty(propertyKey)
|
|
131
|
-
.setIsOptional((_d = propertyInformation.isNullable) !== null && _d !== void 0 ? _d : options.isOptionalDefaultValue)
|
|
132
|
-
.end();
|
|
133
|
-
});
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
catch (e) {
|
|
137
|
+
console.error(e);
|
|
138
|
+
}
|
|
134
139
|
}
|
|
135
140
|
}
|
|
136
141
|
exports.AutoDataMappingBuilder = AutoDataMappingBuilder;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auto-data-mapping.builder.js","sourceRoot":"","sources":["../../../../src/builders/auto-data-mapping.builder.ts"],"names":[],"mappings":";;;AACA,iEAA0D;AAC1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,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;AAxJD,wDAwJC"}
|
|
@@ -36,98 +36,103 @@ export class AutoDataMappingBuilder {
|
|
|
36
36
|
if (!source) {
|
|
37
37
|
return;
|
|
38
38
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
// If the property references an object, this means that we need to recursively call this method to build the schema.
|
|
53
|
-
if (propertyInformation.typeEnum === TypeEnum.Object) {
|
|
54
|
-
const dataMappingNode = new DataMappingNode(root, parent);
|
|
55
|
-
dataMappingNode
|
|
56
|
-
.setSourceProperty(propertyKey)
|
|
57
|
-
.setDestinationProperty(propertyKey)
|
|
58
|
-
.setDestinationType(typeObject)
|
|
59
|
-
.setIsOptional((_a = propertyInformation.isNullable) !== null && _a !== void 0 ? _a : options.isOptionalDefaultValue)
|
|
60
|
-
.end();
|
|
61
|
-
return this.internalBuild(source[propertyKey], typeObject, root, dataMappingNode, options);
|
|
62
|
-
}
|
|
63
|
-
else if (propertyInformation.typeEnum === TypeEnum.Array) { // If the property references an array, we need to iterate over each element and recursively call this method to build the schema.
|
|
64
|
-
let nestedType = DataMappingNodeTypeEnum.ScalarArray;
|
|
65
|
-
if (!source.hasOwnProperty(propertyKey) || Array.isArray(source[propertyKey]) === false || source[propertyKey].length === 0) {
|
|
66
|
-
return;
|
|
39
|
+
try {
|
|
40
|
+
// Get the metadata of destinationType and iterate over its properties.
|
|
41
|
+
const classInformation = ClassMetadata.getInformation(destinationType);
|
|
42
|
+
classInformation.properties.forEach(propertyKey => {
|
|
43
|
+
var _a, _b, _c, _d;
|
|
44
|
+
// Retrieve the metadata for the property
|
|
45
|
+
const propertyInformation = PropertyMetadata.getInformation(destinationType.prototype, propertyKey);
|
|
46
|
+
let typeObject = propertyInformation.typeObject;
|
|
47
|
+
// Check if we have a `@typeFactory` decorator, it means that there's a callback that must be executed
|
|
48
|
+
// for this property to retrieve the actual DestinationType object. If there's one, execute it.
|
|
49
|
+
const typeFactoryCallback = PropertyMetadata.getMetadata(destinationType.prototype, propertyKey, MetadataEnum.TypeFactory);
|
|
50
|
+
if (typeFactoryCallback) {
|
|
51
|
+
typeObject = typeFactoryCallback(source, propertyKey).constructor;
|
|
67
52
|
}
|
|
68
|
-
//
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
53
|
+
// If the property references an object, this means that we need to recursively call this method to build the schema.
|
|
54
|
+
if (propertyInformation.typeEnum === TypeEnum.Object) {
|
|
55
|
+
const dataMappingNode = new DataMappingNode(root, parent);
|
|
56
|
+
dataMappingNode
|
|
57
|
+
.setSourceProperty(propertyKey)
|
|
58
|
+
.setDestinationProperty(propertyKey)
|
|
59
|
+
.setDestinationType(typeObject)
|
|
60
|
+
.setIsOptional((_a = propertyInformation.isNullable) !== null && _a !== void 0 ? _a : options.isOptionalDefaultValue)
|
|
61
|
+
.end();
|
|
62
|
+
return this.internalBuild(source[propertyKey], typeObject, root, dataMappingNode, options);
|
|
74
63
|
}
|
|
75
|
-
// If the
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
64
|
+
else if (propertyInformation.typeEnum === TypeEnum.Array) { // If the property references an array, we need to iterate over each element and recursively call this method to build the schema.
|
|
65
|
+
let nestedType = DataMappingNodeTypeEnum.ScalarArray;
|
|
66
|
+
if (!source.hasOwnProperty(propertyKey) || Array.isArray(source[propertyKey]) === false || source[propertyKey].length === 0) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
// Use the first element in the array to determine the type of content stored in the array. Here, we assume that all the elements in the array are of the same type.
|
|
70
|
+
const nestedElementType = TypeUtils.getTypeOfValue(source[propertyKey][0]);
|
|
80
71
|
switch (nestedElementType) {
|
|
81
|
-
case TypeEnum.
|
|
82
|
-
|
|
83
|
-
break;
|
|
84
|
-
case TypeEnum.String:
|
|
85
|
-
normalizers.push(StringNormalizer.name);
|
|
86
|
-
break;
|
|
87
|
-
case TypeEnum.Date:
|
|
88
|
-
normalizers.push(DateNormalizer.name);
|
|
72
|
+
case TypeEnum.Object:
|
|
73
|
+
nestedType = DataMappingNodeTypeEnum.ObjectArray;
|
|
89
74
|
break;
|
|
90
75
|
}
|
|
91
|
-
|
|
92
|
-
|
|
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.
|
|
81
|
+
switch (nestedElementType) {
|
|
82
|
+
case TypeEnum.Number:
|
|
83
|
+
normalizers.push(NumberNormalizer.name);
|
|
84
|
+
break;
|
|
85
|
+
case TypeEnum.String:
|
|
86
|
+
normalizers.push(StringNormalizer.name);
|
|
87
|
+
break;
|
|
88
|
+
case TypeEnum.Date:
|
|
89
|
+
normalizers.push(DateNormalizer.name);
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
normalizers.forEach(normalizer => dataMappingLeaf.addNormalizer(normalizer));
|
|
93
|
+
dataMappingLeaf.setSourceProperty(propertyKey)
|
|
94
|
+
.setDestinationProperty(propertyKey)
|
|
95
|
+
.setIsOptional((_b = propertyInformation.isNullable) !== null && _b !== void 0 ? _b : options.isOptionalDefaultValue)
|
|
96
|
+
.end();
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
// Else, it's an array of objects and we must iterate over the first element to get all the properties and
|
|
100
|
+
// build the tree.
|
|
101
|
+
const dataMappingNode = parent.addArrayOfObjects();
|
|
102
|
+
dataMappingNode
|
|
103
|
+
.setSourceProperty(propertyKey)
|
|
93
104
|
.setDestinationProperty(propertyKey)
|
|
94
|
-
.
|
|
105
|
+
.setDestinationType(propertyInformation.arrayMemberObject)
|
|
106
|
+
.setIsOptional((_c = propertyInformation.isNullable) !== null && _c !== void 0 ? _c : options.isOptionalDefaultValue)
|
|
95
107
|
.end();
|
|
96
|
-
|
|
108
|
+
// We assume all the objects are similar so we use only the first one to build the schema
|
|
109
|
+
return this.internalBuild(source[propertyKey][0], propertyInformation.arrayMemberObject, root, dataMappingNode, options);
|
|
110
|
+
}
|
|
111
|
+
const normalizers = [];
|
|
112
|
+
// todo: Allow for options to be specified per attribute. We should probably add a decorator to can customize the normalizer.
|
|
113
|
+
switch (propertyInformation.typeEnum) {
|
|
114
|
+
case TypeEnum.Number:
|
|
115
|
+
normalizers.push(NumberNormalizer.name);
|
|
116
|
+
break;
|
|
117
|
+
case TypeEnum.String:
|
|
118
|
+
normalizers.push(StringNormalizer.name);
|
|
119
|
+
break;
|
|
120
|
+
case TypeEnum.Date:
|
|
121
|
+
normalizers.push(DateNormalizer.name);
|
|
122
|
+
break;
|
|
97
123
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
dataMappingNode
|
|
124
|
+
const dataMappingLeaf = new DataMappingLeaf(root, parent);
|
|
125
|
+
normalizers.forEach(normalizer => dataMappingLeaf.addNormalizer(normalizer));
|
|
126
|
+
dataMappingLeaf
|
|
102
127
|
.setSourceProperty(propertyKey)
|
|
103
128
|
.setDestinationProperty(propertyKey)
|
|
104
|
-
.
|
|
105
|
-
.setIsOptional((_c = propertyInformation.isNullable) !== null && _c !== void 0 ? _c : options.isOptionalDefaultValue)
|
|
129
|
+
.setIsOptional((_d = propertyInformation.isNullable) !== null && _d !== void 0 ? _d : options.isOptionalDefaultValue)
|
|
106
130
|
.end();
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
switch (propertyInformation.typeEnum) {
|
|
113
|
-
case TypeEnum.Number:
|
|
114
|
-
normalizers.push(NumberNormalizer.name);
|
|
115
|
-
break;
|
|
116
|
-
case TypeEnum.String:
|
|
117
|
-
normalizers.push(StringNormalizer.name);
|
|
118
|
-
break;
|
|
119
|
-
case TypeEnum.Date:
|
|
120
|
-
normalizers.push(DateNormalizer.name);
|
|
121
|
-
break;
|
|
122
|
-
}
|
|
123
|
-
const dataMappingLeaf = new DataMappingLeaf(root, parent);
|
|
124
|
-
normalizers.forEach(normalizer => dataMappingLeaf.addNormalizer(normalizer));
|
|
125
|
-
dataMappingLeaf
|
|
126
|
-
.setSourceProperty(propertyKey)
|
|
127
|
-
.setDestinationProperty(propertyKey)
|
|
128
|
-
.setIsOptional((_d = propertyInformation.isNullable) !== null && _d !== void 0 ? _d : options.isOptionalDefaultValue)
|
|
129
|
-
.end();
|
|
130
|
-
});
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
catch (e) {
|
|
134
|
+
console.error(e);
|
|
135
|
+
}
|
|
131
136
|
}
|
|
132
137
|
}
|
|
133
138
|
//# sourceMappingURL=auto-data-mapping.builder.js.map
|
|
@@ -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,EAAE,QAAQ,EAAE,SAAS,EAAC,MAAM,uBAAuB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AAe,EAAE,OAAO,CAAC,CAAC;gBAC7H,CAAC;gBAED,MAAM,WAAW,GAAa,EAAE,CAAC;gBAEjC,6HAA6H;gBAC7H,QAAQ,mBAAmB,CAAC,QAAQ,EAAE,CAAC;oBACnC,KAAK,QAAQ,CAAC,MAAM;wBAChB,WAAW,CAAC,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;wBACxC,MAAM;oBAEV,KAAK,QAAQ,CAAC,MAAM;wBAChB,WAAW,CAAC,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"}
|
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.288",
|
|
4
4
|
"description": "",
|
|
5
5
|
"module": "dist/lib/esm/data-mapping-common.js",
|
|
6
6
|
"main": "dist/lib/cjs/data-mapping-common.js",
|
|
@@ -62,5 +62,5 @@
|
|
|
62
62
|
"jest-extended/all"
|
|
63
63
|
]
|
|
64
64
|
},
|
|
65
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "6f156979d93bc8936c0d531c9666c1b59c875c6a"
|
|
66
66
|
}
|