@pristine-ts/data-mapping-common 2.0.7 → 2.0.9
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 +36 -1
- package/dist/lib/cjs/builders/auto-data-mapping.builder.js.map +1 -1
- package/dist/lib/cjs/builders/data-mapping.builder.js +7 -6
- package/dist/lib/cjs/builders/data-mapping.builder.js.map +1 -1
- package/dist/lib/cjs/errors/data-normalizer-not-found.error.js +15 -0
- package/dist/lib/cjs/errors/data-normalizer-not-found.error.js.map +1 -0
- package/dist/lib/cjs/errors/errors.js +3 -0
- package/dist/lib/cjs/errors/errors.js.map +1 -1
- package/dist/lib/cjs/errors/undefined-destination-property.error.js +14 -0
- package/dist/lib/cjs/errors/undefined-destination-property.error.js.map +1 -0
- package/dist/lib/cjs/mappers/data.mapper.js +3 -5
- package/dist/lib/cjs/mappers/data.mapper.js.map +1 -1
- package/dist/lib/cjs/nodes/base-data-mapping.node.js +4 -0
- package/dist/lib/cjs/nodes/base-data-mapping.node.js.map +1 -1
- package/dist/lib/cjs/nodes/data-mapping.leaf.js +36 -11
- package/dist/lib/cjs/nodes/data-mapping.leaf.js.map +1 -1
- package/dist/lib/cjs/nodes/data-mapping.node.js +119 -49
- package/dist/lib/cjs/nodes/data-mapping.node.js.map +1 -1
- package/dist/lib/cjs/options/auto-data-mapping-builder.options.js +2 -1
- package/dist/lib/cjs/options/auto-data-mapping-builder.options.js.map +1 -1
- package/dist/lib/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/lib/esm/builders/auto-data-mapping.builder.js +36 -1
- package/dist/lib/esm/builders/auto-data-mapping.builder.js.map +1 -1
- package/dist/lib/esm/builders/data-mapping.builder.js +7 -6
- package/dist/lib/esm/builders/data-mapping.builder.js.map +1 -1
- package/dist/lib/esm/errors/data-normalizer-not-found.error.js +11 -0
- package/dist/lib/esm/errors/data-normalizer-not-found.error.js.map +1 -0
- package/dist/lib/esm/errors/errors.js +3 -0
- package/dist/lib/esm/errors/errors.js.map +1 -1
- package/dist/lib/esm/errors/undefined-destination-property.error.js +10 -0
- package/dist/lib/esm/errors/undefined-destination-property.error.js.map +1 -0
- package/dist/lib/esm/mappers/data.mapper.js +3 -5
- package/dist/lib/esm/mappers/data.mapper.js.map +1 -1
- package/dist/lib/esm/nodes/base-data-mapping.node.js +4 -0
- package/dist/lib/esm/nodes/base-data-mapping.node.js.map +1 -1
- package/dist/lib/esm/nodes/data-mapping.leaf.js +36 -11
- package/dist/lib/esm/nodes/data-mapping.leaf.js.map +1 -1
- package/dist/lib/esm/nodes/data-mapping.node.js +119 -49
- package/dist/lib/esm/nodes/data-mapping.node.js.map +1 -1
- package/dist/lib/esm/options/auto-data-mapping-builder.options.js +2 -1
- package/dist/lib/esm/options/auto-data-mapping-builder.options.js.map +1 -1
- package/dist/lib/esm/tsconfig.tsbuildinfo +1 -1
- package/dist/types/builders/auto-data-mapping.builder.d.ts +16 -0
- package/dist/types/builders/data-mapping.builder.d.ts +3 -2
- package/dist/types/errors/data-normalizer-not-found.error.d.ts +8 -0
- package/dist/types/errors/errors.d.ts +3 -0
- package/dist/types/errors/undefined-destination-property.error.d.ts +8 -0
- package/dist/types/interfaces/data-mapping-interceptor.interface.d.ts +6 -2
- package/dist/types/nodes/data-mapping.leaf.d.ts +11 -0
- package/dist/types/nodes/data-mapping.node.d.ts +54 -2
- package/dist/types/options/auto-data-mapping-builder.options.d.ts +12 -0
- package/package.json +3 -3
|
@@ -10,6 +10,19 @@ import { AutoDataMappingBuilderOptions } from "../options/auto-data-mapping-buil
|
|
|
10
10
|
import { MetadataEnum } from "../enums/metadata.enum";
|
|
11
11
|
import { BooleanNormalizerUniqueKey } from "../normalizers/boolean.normalizer";
|
|
12
12
|
export class AutoDataMappingBuilder {
|
|
13
|
+
constructor() {
|
|
14
|
+
/**
|
|
15
|
+
* Schema cache keyed by destination class. The auto-built schema is deterministic in `destinationType`
|
|
16
|
+
* + the *shape* of the source (which decoration metadata describes), so for a stable class definition
|
|
17
|
+
* the same builder can be reused across calls. We key only by destinationType to keep things simple;
|
|
18
|
+
* if the source shape varies and the auto-inference depends on it (e.g. inferring scalar-array member
|
|
19
|
+
* type from `source[propertyKey][0]`), callers needing fresh inference can bypass the cache via the
|
|
20
|
+
* `disableCache` option.
|
|
21
|
+
*
|
|
22
|
+
* Stored under a WeakMap so unused destination classes can be garbage-collected.
|
|
23
|
+
*/
|
|
24
|
+
this.cache = new WeakMap();
|
|
25
|
+
}
|
|
13
26
|
/**
|
|
14
27
|
* This method receives a source object and a destinationType that corresponds to the type of the class
|
|
15
28
|
* that the source should be mapped to. It then creates a DataMappingBuilder object that contains the schema
|
|
@@ -19,10 +32,32 @@ export class AutoDataMappingBuilder {
|
|
|
19
32
|
* @param options
|
|
20
33
|
*/
|
|
21
34
|
build(source, destinationType, options) {
|
|
35
|
+
const resolvedOptions = new AutoDataMappingBuilderOptions(options);
|
|
36
|
+
if (resolvedOptions.disableCache !== true) {
|
|
37
|
+
const cached = this.cache.get(destinationType);
|
|
38
|
+
if (cached !== undefined) {
|
|
39
|
+
return cached;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
22
42
|
const dataMappingBuilder = new DataMappingBuilder();
|
|
23
|
-
this.internalBuild(source, destinationType, dataMappingBuilder, dataMappingBuilder,
|
|
43
|
+
this.internalBuild(source, destinationType, dataMappingBuilder, dataMappingBuilder, resolvedOptions);
|
|
44
|
+
if (resolvedOptions.disableCache !== true) {
|
|
45
|
+
this.cache.set(destinationType, dataMappingBuilder);
|
|
46
|
+
}
|
|
24
47
|
return dataMappingBuilder;
|
|
25
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Clear the cached schema for a destinationType (or the whole cache when no argument is passed).
|
|
51
|
+
* Useful in tests, or when class metadata changes at runtime (rare).
|
|
52
|
+
*/
|
|
53
|
+
clearCache(destinationType) {
|
|
54
|
+
if (destinationType === undefined) {
|
|
55
|
+
// WeakMap has no .clear() — recreate.
|
|
56
|
+
this.cache = new WeakMap();
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
this.cache.delete(destinationType);
|
|
60
|
+
}
|
|
26
61
|
/**
|
|
27
62
|
* This method is the internal method that is called recursively to build the schema.
|
|
28
63
|
*
|
|
@@ -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,uBAAuB,EAAE,gBAAgB,EAAE,QAAQ,EAAE,SAAS,EAAC,MAAM,uBAAuB,CAAC;AACpH,OAAO,EAAC,eAAe,EAAC,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAC,yBAAyB,EAAC,MAAM,kCAAkC,CAAC;AAC3E,OAAO,EAAC,yBAAyB,EAAC,MAAM,kCAAkC,CAAC;AAC3E,OAAO,EAAC,uBAAuB,EAAC,MAAM,gCAAgC,CAAC;AACvE,OAAO,EAAC,uBAAuB,EAAC,MAAM,sCAAsC,CAAC;AAC7E,OAAO,EAAC,6BAA6B,EAAC,MAAM,8CAA8C,CAAC;AAC3F,OAAO,EAAC,YAAY,EAAC,MAAM,wBAAwB,CAAC;AAEpD,OAAO,EAAC,0BAA0B,EAAC,MAAM,mCAAmC,CAAC;AAE7E,MAAM,OAAO,sBAAsB;
|
|
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,uBAAuB,EAAE,gBAAgB,EAAE,QAAQ,E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;YAED,IAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,aAAa,EAAE,CAAC;gBAC3B,MAAM,CAAC,CAAC;YACV,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
|
|
@@ -153,18 +153,19 @@ export class DataMappingBuilder extends BaseDataMappingNode {
|
|
|
153
153
|
}
|
|
154
154
|
}
|
|
155
155
|
/**
|
|
156
|
-
* This method exports
|
|
156
|
+
* This method exports the schema as a plain object. The export does not mutate the live tree —
|
|
157
|
+
* the builder remains usable for mapping after this call returns.
|
|
157
158
|
*/
|
|
158
159
|
export() {
|
|
159
|
-
const
|
|
160
|
-
for (const key in nodes) {
|
|
161
|
-
if (nodes.hasOwnProperty(key) === false) {
|
|
160
|
+
const exportedNodes = {};
|
|
161
|
+
for (const key in this.nodes) {
|
|
162
|
+
if (this.nodes.hasOwnProperty(key) === false) {
|
|
162
163
|
continue;
|
|
163
164
|
}
|
|
164
|
-
|
|
165
|
+
exportedNodes[key] = this.nodes[key].export();
|
|
165
166
|
}
|
|
166
167
|
return {
|
|
167
|
-
"nodes":
|
|
168
|
+
"nodes": exportedNodes,
|
|
168
169
|
"normalizers": this.normalizers,
|
|
169
170
|
"beforeMappingInterceptors": this.beforeMappingInterceptors,
|
|
170
171
|
"afterMappingInterceptors": this.afterMappingInterceptors,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data-mapping.builder.js","sourceRoot":"","sources":["../../../../src/builders/data-mapping.builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAC,MAAM,4BAA4B,CAAC;AAE3D,OAAO,EAAC,0BAA0B,EAAC,MAAM,+CAA+C,CAAC;AAEzF,OAAO,EAAC,6CAA6C,EAAC,MAAM,+DAA+D,CAAC;AAC5H,OAAO,EAAC,4CAA4C,EAAC,MAAM,8DAA8D,CAAC;AAC1H,OAAO,EAAC,eAAe,EAAC,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAC,mBAAmB,EAAC,MAAM,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,aAAa,GAA2B,EAAE,CAAC;QAEjD,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YAC7B,IAAI,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,GAAG,CAAC,KAAK,KAAK,EAAE,CAAC;gBAC7C,SAAS;YACX,CAAC;YAED,aAAa,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC;QAChD,CAAC;QAED,OAAO;YACL,OAAO,EAAE,aAAa;YACtB,aAAa,EAAE,IAAI,CAAC,WAAW;YAC/B,2BAA2B,EAAE,IAAI,CAAC,yBAAyB;YAC3D,0BAA0B,EAAE,IAAI,CAAC,wBAAwB;SAC1D,CAAA;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thrown when a leaf references a normalizer key that hasn't been registered with the DataMapper.
|
|
3
|
+
*/
|
|
4
|
+
export class DataNormalizerNotFoundError extends Error {
|
|
5
|
+
constructor(message, normalizerUniqueKey) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.normalizerUniqueKey = normalizerUniqueKey;
|
|
8
|
+
Object.setPrototypeOf(this, DataNormalizerNotFoundError.prototype);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=data-normalizer-not-found.error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-normalizer-not-found.error.js","sourceRoot":"","sources":["../../../../src/errors/data-normalizer-not-found.error.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,OAAO,2BAA4B,SAAQ,KAAK;IACpD,YAAmB,OAAe,EAAkB,mBAA4C;QAC9F,KAAK,CAAC,OAAO,CAAC,CAAC;QADmC,wBAAmB,GAAnB,mBAAmB,CAAyB;QAG9F,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,2BAA2B,CAAC,SAAS,CAAC,CAAC;IACrE,CAAC;CACF"}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
export * from "./array-data-mapping-node-invalid-source-property-type.error";
|
|
2
|
+
export * from "./auto-map-primitive-type-normalizer-not-found.error";
|
|
2
3
|
export * from "./data-after-mapping-interceptor-already-added.error";
|
|
3
4
|
export * from "./data-before-mapping-interceptor-already-added.error";
|
|
4
5
|
export * from "./data-normalizer-already-added.error";
|
|
6
|
+
export * from "./data-normalizer-not-found.error";
|
|
5
7
|
export * from "./data-mapping-interceptor-not-found.error";
|
|
6
8
|
export * from "./data-mapping-source-property-not-found.error";
|
|
7
9
|
export * from "./normalizer-invalid-source-type.error";
|
|
10
|
+
export * from "./undefined-destination-property.error";
|
|
8
11
|
export * from "./undefined-source-property.error";
|
|
9
12
|
//# sourceMappingURL=errors.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../../src/errors/errors.ts"],"names":[],"mappings":"AAAA,cAAc,8DAA8D,CAAC;AAC7E,cAAc,sDAAsD,CAAC;AACrE,cAAc,uDAAuD,CAAC;AACtE,cAAc,uCAAuC,CAAC;AACtD,cAAc,4CAA4C,CAAC;AAC3D,cAAc,gDAAgD,CAAC;AAC/D,cAAc,wCAAwC,CAAC;AACvD,cAAc,mCAAmC,CAAC"}
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../../src/errors/errors.ts"],"names":[],"mappings":"AAAA,cAAc,8DAA8D,CAAC;AAC7E,cAAc,sDAAsD,CAAC;AACrE,cAAc,sDAAsD,CAAC;AACrE,cAAc,uDAAuD,CAAC;AACtE,cAAc,uCAAuC,CAAC;AACtD,cAAc,mCAAmC,CAAC;AAClD,cAAc,4CAA4C,CAAC;AAC3D,cAAc,gDAAgD,CAAC;AAC/D,cAAc,wCAAwC,CAAC;AACvD,cAAc,wCAAwC,CAAC;AACvD,cAAc,mCAAmC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thrown when a Node is being committed to its parent without a `destinationProperty` set.
|
|
3
|
+
*/
|
|
4
|
+
export class UndefinedDestinationPropertyError extends Error {
|
|
5
|
+
constructor(node) {
|
|
6
|
+
super("The `destinationProperty` property of the Node cannot be undefined to be added as a Node to its parent. Source property: '" + node.sourceProperty + "'.");
|
|
7
|
+
Object.setPrototypeOf(this, UndefinedDestinationPropertyError.prototype);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=undefined-destination-property.error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"undefined-destination-property.error.js","sourceRoot":"","sources":["../../../../src/errors/undefined-destination-property.error.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,MAAM,OAAO,iCAAkC,SAAQ,KAAK;IAE1D,YAAmB,IAAuC;QACxD,KAAK,CAAC,4HAA4H,GAAG,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,CAAC;QAEjK,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,iCAAiC,CAAC,SAAS,CAAC,CAAC;IAC3E,CAAC;CACF"}
|
|
@@ -144,8 +144,7 @@ export class DataMapper {
|
|
|
144
144
|
if (interceptor === undefined) {
|
|
145
145
|
throw new DataMappingInterceptorNotFoundError("The interceptor wasn't found and cannot be loaded.", element.key);
|
|
146
146
|
}
|
|
147
|
-
|
|
148
|
-
interceptedSource = yield interceptor.beforeMapping(interceptedSource);
|
|
147
|
+
interceptedSource = yield interceptor.beforeMapping(interceptedSource, element.options);
|
|
149
148
|
}
|
|
150
149
|
// Loop over the properties defined in the builder
|
|
151
150
|
for (const key in builder.nodes) {
|
|
@@ -155,14 +154,13 @@ export class DataMapper {
|
|
|
155
154
|
const node = builder.nodes[key];
|
|
156
155
|
yield node.map(interceptedSource, destination, this.dataNormalizersMap, options);
|
|
157
156
|
}
|
|
158
|
-
// Execute the
|
|
157
|
+
// Execute the after interceptors.
|
|
159
158
|
for (const element of builder.afterMappingInterceptors) {
|
|
160
159
|
const interceptor = this.dataTransformerInterceptorsMap[element.key];
|
|
161
160
|
if (interceptor === undefined) {
|
|
162
161
|
throw new DataMappingInterceptorNotFoundError("The interceptor wasn't found and cannot be loaded.", element.key);
|
|
163
162
|
}
|
|
164
|
-
|
|
165
|
-
destination = yield interceptor.afterMapping(destination);
|
|
163
|
+
destination = yield interceptor.afterMapping(destination, element.options);
|
|
166
164
|
}
|
|
167
165
|
if (destinationType) {
|
|
168
166
|
destination = plainToInstance(destinationType, destination);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data.mapper.js","sourceRoot":"","sources":["../../../../src/mappers/data.mapper.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAIA,OAAO,EAAC,kBAAkB,EAAC,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAmB,eAAe,EAAC,MAAM,mBAAmB,CAAC;AACpE,OAAO,EAAC,mCAAmC,EAAC,MAAM,oDAAoD,CAAC;AAEvG,OAAO,EAAC,6BAA6B,EAAC,MAAM,8CAA8C,CAAC;AAC3F,OAAO,EAAC,iBAAiB,EAAC,MAAM,gCAAgC,CAAC;AACjE,OAAO,EAAC,aAAa,EAAC,MAAM,8BAA8B,CAAC;AAC3D,OAAO,EAAC,QAAQ,EAAE,MAAM,EAAC,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAC,yBAAyB,EAAC,MAAM,kCAAkC,CAAC;AAC3E,OAAO,EAAC,2CAA2C,EAAC,MAAM,8DAA8D,CAAC;AACzH,OAAO,EAAC,yBAAyB,EAAC,MAAM,kCAAkC,CAAC;AAC3E,OAAO,EAAC,0BAA0B,EAAC,MAAM,mCAAmC,CAAC;AAC7E,OAAO,EAAC,uBAAuB,EAAC,MAAM,gCAAgC,CAAC;AAEvE,MAAM,OAAO,UAAU;IAIrB,YACmB,sBAA8C,EAC9C,eAAoD,EACpD,2BAA8D;QAF9D,2BAAsB,GAAtB,sBAAsB,CAAwB;QAC9C,oBAAe,GAAf,e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AAC,cAAc,CAAC,GAAG,CAAC,KAAK,KAAK,EAAE,CAAC;oBAChD,SAAS;gBACX,CAAC;gBAED,MAAM,IAAI,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;gBAChC,MAAM,IAAI,CAAC,GAAG,CAAC,iBAAiB,EAAE,WAAW,EAAE,IAAI,CAAC,kBAAkB,EAAE,OAAO,CAAC,CAAC;YACnF,CAAC;YAED,kCAAkC;YAClC,KAAK,MAAM,OAAO,IAAI,OAAO,CAAC,wBAAwB,EAAE,CAAC;gBACvD,MAAM,WAAW,GAAoC,IAAI,CAAC,8BAA8B,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;gBAEtG,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;oBAC9B,MAAM,IAAI,mCAAmC,CAAC,oDAAoD,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;gBACnH,CAAC;gBAED,WAAW,GAAG,MAAM,WAAW,CAAC,YAAY,CAAC,WAAW,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;YAC7E,CAAC;YAED,IAAI,eAAe,EAAE,CAAC;gBACpB,WAAW,GAAG,eAAe,CAAC,eAAe,EAAE,WAAW,CAAC,CAAC;YAC9D,CAAC;YAED,OAAO,WAAW,CAAC;QACrB,CAAC;KAAA;CACF;AA/Ic;IADZ,MAAM,EAAE;;qCACoB,kBAAkB;;wCAQ9C;AASY;IADZ,MAAM,EAAE;;qDACmG,6BAA6B;;yCA+DxI;AAYY;IADZ,MAAM,EAAE;;qCACiB,kBAAkB,kBAAkE,iBAAiB;;qCAkD9H"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { UndefinedSourcePropertyError } from "../errors/undefined-source-property.error";
|
|
2
|
+
import { UndefinedDestinationPropertyError } from "../errors/undefined-destination-property.error";
|
|
2
3
|
export class BaseDataMappingNode {
|
|
3
4
|
constructor() {
|
|
4
5
|
this.nodes = {};
|
|
@@ -14,6 +15,9 @@ export class BaseDataMappingNode {
|
|
|
14
15
|
if (node.sourceProperty === undefined) {
|
|
15
16
|
throw new UndefinedSourcePropertyError(node);
|
|
16
17
|
}
|
|
18
|
+
if (node.destinationProperty === undefined) {
|
|
19
|
+
throw new UndefinedDestinationPropertyError(node);
|
|
20
|
+
}
|
|
17
21
|
this.nodes[node.sourceProperty] = node;
|
|
18
22
|
}
|
|
19
23
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-data-mapping.node.js","sourceRoot":"","sources":["../../../../src/nodes/base-data-mapping.node.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,4BAA4B,EAAC,MAAM,2CAA2C,CAAC;
|
|
1
|
+
{"version":3,"file":"base-data-mapping.node.js","sourceRoot":"","sources":["../../../../src/nodes/base-data-mapping.node.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,4BAA4B,EAAC,MAAM,2CAA2C,CAAC;AACvF,OAAO,EAAC,iCAAiC,EAAC,MAAM,gDAAgD,CAAC;AAEjG,MAAM,OAAgB,mBAAmB;IAAzC;QACS,UAAK,GAAsE,EAAE,CAAC;IAsBvF,CAAC;IApBC;;;;;;OAMG;IACI,OAAO,CAAC,IAAuC;QACpD,IAAI,IAAI,CAAC,cAAc,KAAK,SAAS,EAAE,CAAC;YACtC,MAAM,IAAI,4BAA4B,CAAC,IAAI,CAAC,CAAC;QAC/C,CAAC;QAED,IAAI,IAAI,CAAC,mBAAmB,KAAK,SAAS,EAAE,CAAC;YAC3C,MAAM,IAAI,iCAAiC,CAAC,IAAI,CAAC,CAAC;QACpD,CAAC;QAED,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,cAAc,CAAC,GAAG,IAAI,CAAC;IACzC,CAAC;CAGF"}
|
|
@@ -11,6 +11,7 @@ import { DataMappingNodeTypeEnum } from "../enums/data-mapping-node-type.enum";
|
|
|
11
11
|
import { DataNormalizerAlreadyAdded } from "../errors/data-normalizer-already-added.error";
|
|
12
12
|
import { DataMappingSourcePropertyNotFoundError } from "../errors/data-mapping-source-property-not-found.error";
|
|
13
13
|
import { ArrayDataMappingNodeInvalidSourcePropertyTypeError } from "../errors/array-data-mapping-node-invalid-source-property-type.error";
|
|
14
|
+
import { DataNormalizerNotFoundError } from "../errors/data-normalizer-not-found.error";
|
|
14
15
|
export class DataMappingLeaf {
|
|
15
16
|
constructor(root, parent, type = DataMappingNodeTypeEnum.Leaf) {
|
|
16
17
|
this.root = root;
|
|
@@ -71,6 +72,7 @@ export class DataMappingLeaf {
|
|
|
71
72
|
key: normalizerUniqueKey,
|
|
72
73
|
options,
|
|
73
74
|
});
|
|
75
|
+
this.effectiveNormalizersCache = undefined;
|
|
74
76
|
return this;
|
|
75
77
|
}
|
|
76
78
|
/**
|
|
@@ -89,8 +91,23 @@ export class DataMappingLeaf {
|
|
|
89
91
|
throw new DataNormalizerAlreadyAdded("The EXCLUDED data normalizer '" + normalizerUniqueKey + "' has already been added to this source property: '" + this.sourceProperty + "'.", normalizerUniqueKey);
|
|
90
92
|
}
|
|
91
93
|
this.excludedNormalizers.add(normalizerUniqueKey);
|
|
94
|
+
this.effectiveNormalizersCache = undefined;
|
|
92
95
|
return this;
|
|
93
96
|
}
|
|
97
|
+
/**
|
|
98
|
+
* Returns the merged list of normalizers applied to this leaf: inherited root normalizers minus the
|
|
99
|
+
* ones explicitly excluded here, followed by leaf-local normalizers. Memoized — the cache is cleared
|
|
100
|
+
* by `addNormalizer`/`excludeNormalizer`.
|
|
101
|
+
*/
|
|
102
|
+
getEffectiveNormalizers() {
|
|
103
|
+
if (this.effectiveNormalizersCache === undefined) {
|
|
104
|
+
this.effectiveNormalizersCache = [
|
|
105
|
+
...this.root.normalizers.filter(element => this.excludedNormalizers.has(element.key) === false),
|
|
106
|
+
...this.normalizers,
|
|
107
|
+
];
|
|
108
|
+
}
|
|
109
|
+
return this.effectiveNormalizersCache;
|
|
110
|
+
}
|
|
94
111
|
/**
|
|
95
112
|
* This method adds this node to its parent and returns the parent.
|
|
96
113
|
*/
|
|
@@ -115,8 +132,7 @@ export class DataMappingLeaf {
|
|
|
115
132
|
}
|
|
116
133
|
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);
|
|
117
134
|
}
|
|
118
|
-
const normalizers = this.
|
|
119
|
-
normalizers.push(...this.normalizers);
|
|
135
|
+
const normalizers = this.getEffectiveNormalizers();
|
|
120
136
|
if (this.type === DataMappingNodeTypeEnum.ScalarArray) {
|
|
121
137
|
// This means that the source[propertyKey] contains an array of objects and each object should be mapped
|
|
122
138
|
const array = source[this.sourceProperty];
|
|
@@ -125,20 +141,25 @@ export class DataMappingLeaf {
|
|
|
125
141
|
}
|
|
126
142
|
destination[this.destinationProperty] = [];
|
|
127
143
|
for (let value of array) {
|
|
128
|
-
|
|
144
|
+
for (const element of normalizers) {
|
|
129
145
|
const normalizer = normalizersMap[element.key];
|
|
130
|
-
if (normalizer)
|
|
131
|
-
|
|
132
|
-
|
|
146
|
+
if (normalizer === undefined) {
|
|
147
|
+
throw new DataNormalizerNotFoundError("The normalizer '" + element.key + "' wasn't found and cannot be loaded for source property '" + this.sourceProperty + "'.", element.key);
|
|
148
|
+
}
|
|
149
|
+
value = normalizer.normalize(value, element.options);
|
|
150
|
+
}
|
|
133
151
|
destination[this.destinationProperty].push(value);
|
|
134
152
|
}
|
|
135
153
|
return;
|
|
136
154
|
}
|
|
137
155
|
let value = source[this.sourceProperty];
|
|
138
|
-
|
|
156
|
+
for (const element of normalizers) {
|
|
139
157
|
const normalizer = normalizersMap[element.key];
|
|
158
|
+
if (normalizer === undefined) {
|
|
159
|
+
throw new DataNormalizerNotFoundError("The normalizer '" + element.key + "' wasn't found and cannot be loaded for source property '" + this.sourceProperty + "'.", element.key);
|
|
160
|
+
}
|
|
140
161
|
value = normalizer.normalize(value, element.options);
|
|
141
|
-
}
|
|
162
|
+
}
|
|
142
163
|
destination[this.destinationProperty] = value;
|
|
143
164
|
return;
|
|
144
165
|
});
|
|
@@ -149,16 +170,20 @@ export class DataMappingLeaf {
|
|
|
149
170
|
* @param schema
|
|
150
171
|
*/
|
|
151
172
|
import(schema) {
|
|
152
|
-
this.normalizers = schema.normalizers;
|
|
173
|
+
this.normalizers = Array.isArray(schema.normalizers) ? schema.normalizers : [];
|
|
153
174
|
this.excludedNormalizers = new Set();
|
|
154
|
-
if (schema.hasOwnProperty("excludedNormalizers")) {
|
|
175
|
+
if (schema.hasOwnProperty("excludedNormalizers") && schema.excludedNormalizers) {
|
|
155
176
|
for (const item in schema.excludedNormalizers) {
|
|
156
|
-
|
|
177
|
+
if (schema.excludedNormalizers.hasOwnProperty(item) === false) {
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
this.excludedNormalizers.add(item);
|
|
157
181
|
}
|
|
158
182
|
}
|
|
159
183
|
this.isOptional = schema.isOptional;
|
|
160
184
|
this.sourceProperty = schema.sourceProperty;
|
|
161
185
|
this.destinationProperty = schema.destinationProperty;
|
|
186
|
+
this.effectiveNormalizersCache = undefined;
|
|
162
187
|
}
|
|
163
188
|
/**
|
|
164
189
|
* This method exports this node.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data-mapping.leaf.js","sourceRoot":"","sources":["../../../../src/nodes/data-mapping.leaf.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAC,uBAAuB,EAAC,MAAM,sCAAsC,CAAC;AAE7E,OAAO,EAAC,0BAA0B,EAAC,MAAM,+CAA+C,CAAC;AAGzF,OAAO,EAAC,sCAAsC,EAAC,MAAM,wDAAwD,CAAC;AAE9G,OAAO,EAAC,kDAAkD,EAAC,MAAM,sEAAsE,CAAC;
|
|
1
|
+
{"version":3,"file":"data-mapping.leaf.js","sourceRoot":"","sources":["../../../../src/nodes/data-mapping.leaf.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAC,uBAAuB,EAAC,MAAM,sCAAsC,CAAC;AAE7E,OA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
|
+
// Whether source-keyed properties should be carried through to the destination.
|
|
118
|
+
// When `excludeExtraneousValues === true`, only renamed destination keys (written by
|
|
119
|
+
// sub-nodes below) end up on the destination — source keys are dropped.
|
|
120
|
+
const includeSourceKeys = (options === null || options === void 0 ? void 0 : options.excludeExtraneousValues) === false;
|
|
117
121
|
if (this.type === DataMappingNodeTypeEnum.ObjectArray) {
|
|
122
|
+
// Array case: handled below in its own loop. Just pre-allocate the array here.
|
|
118
123
|
destination[this.destinationProperty] = [];
|
|
119
124
|
}
|
|
120
125
|
else {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
else {
|
|
125
|
-
destination[this.destinationProperty] = {};
|
|
126
|
-
}
|
|
127
|
-
if ((options === null || options === void 0 ? void 0 : options.excludeExtraneousValues) === false) {
|
|
128
|
-
if (typeof sourceElement === "object" || Array.isArray(sourceElement)) {
|
|
129
|
-
Object.keys(sourceElement).forEach(property => {
|
|
130
|
-
destination[this.destinationProperty][property] = sourceElement[property];
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
}
|
|
126
|
+
// Single-object case: build the destination value once, then let sub-nodes overlay
|
|
127
|
+
// renamed keys onto it.
|
|
128
|
+
destination[this.destinationProperty] = this.buildDestinationObject(sourceElement, includeSourceKeys);
|
|
134
129
|
}
|
|
135
130
|
const destinationElement = destination[this.destinationProperty];
|
|
136
131
|
if (this.type === DataMappingNodeTypeEnum.ObjectArray) {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
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);
|
|
132
|
+
const sourceArray = source[this.sourceProperty];
|
|
133
|
+
if (Array.isArray(sourceArray) === false) {
|
|
134
|
+
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 sourceArray}'.`, this.sourceProperty);
|
|
141
135
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
}
|
|
150
|
-
else if (this.destinationType.prototype) {
|
|
151
|
-
dest = plainToInstance(this.destinationType, {});
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
if ((options === null || options === void 0 ? void 0 : options.excludeExtraneousValues) === false) {
|
|
155
|
-
Object.keys(element).forEach(property => {
|
|
156
|
-
dest[property] = element[property];
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
for (const key in this.nodes) {
|
|
160
|
-
if (this.nodes.hasOwnProperty(key) === false) {
|
|
161
|
-
continue;
|
|
162
|
-
}
|
|
163
|
-
const node = this.nodes[key];
|
|
164
|
-
yield node.map(element, dest, normalizersMap, options);
|
|
165
|
-
}
|
|
136
|
+
// For each source element: build the destination object (whose concrete class may
|
|
137
|
+
// depend on the element index when `destinationType` is a factory callback), let the
|
|
138
|
+
// sub-nodes overlay their renamed keys, then push.
|
|
139
|
+
for (let index = 0; index < sourceArray.length; index++) {
|
|
140
|
+
const element = sourceArray[index];
|
|
141
|
+
const dest = this.buildArrayMemberDestination(source, element, index, includeSourceKeys);
|
|
142
|
+
yield this.runSubNodes(element, dest, normalizersMap, options);
|
|
166
143
|
destinationElement.push(dest);
|
|
167
144
|
}
|
|
168
|
-
index++;
|
|
169
145
|
return;
|
|
170
146
|
}
|
|
171
|
-
//
|
|
147
|
+
// Single-object case: sub-nodes write into the destination we just built above.
|
|
148
|
+
yield this.runSubNodes(sourceElement, destinationElement, normalizersMap, options);
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Build the destination object for the single-object case.
|
|
153
|
+
*
|
|
154
|
+
* If a `destinationType` (class constructor) is set, instantiate the class. Otherwise return
|
|
155
|
+
* a plain object. When `includeSourceKeys` is true, the source's own enumerable properties are
|
|
156
|
+
* seeded onto the result so they survive the mapping; sub-nodes then overlay renamed keys on top.
|
|
157
|
+
*
|
|
158
|
+
* Note: the single-object case treats `destinationType` strictly as a class constructor.
|
|
159
|
+
* Factory callbacks only make sense for the per-element ObjectArray case below.
|
|
160
|
+
*/
|
|
161
|
+
buildDestinationObject(sourceElement, includeSourceKeys) {
|
|
162
|
+
const seedFromSource = includeSourceKeys
|
|
163
|
+
&& sourceElement !== null
|
|
164
|
+
&& (typeof sourceElement === "object" || Array.isArray(sourceElement));
|
|
165
|
+
if (this.destinationType !== undefined) {
|
|
166
|
+
return plainToInstance(this.destinationType, seedFromSource ? sourceElement : {});
|
|
167
|
+
}
|
|
168
|
+
const result = {};
|
|
169
|
+
if (seedFromSource) {
|
|
170
|
+
Object.keys(sourceElement).forEach(property => {
|
|
171
|
+
result[property] = sourceElement[property];
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
return result;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Build the destination object for a single element of an ObjectArray. Mirrors
|
|
178
|
+
* `buildDestinationObject`, with two extra wrinkles unique to arrays:
|
|
179
|
+
*
|
|
180
|
+
* 1. `destinationType` can be a *factory callback* instead of a fixed class. The callback
|
|
181
|
+
* receives the source array's parent + the element's index and returns an instance of
|
|
182
|
+
* the concrete class to use. This is how polymorphic arrays work (e.g. some elements
|
|
183
|
+
* become `Cat`, others `Dog`).
|
|
184
|
+
* 2. The seed value is the per-element object, not the whole array.
|
|
185
|
+
*/
|
|
186
|
+
buildArrayMemberDestination(source, element, index, includeSourceKeys) {
|
|
187
|
+
const seedFromSource = includeSourceKeys && element !== null && typeof element === "object";
|
|
188
|
+
if (this.destinationType === undefined) {
|
|
189
|
+
// Untyped array — produce a plain object, optionally seeded with the element's own keys.
|
|
190
|
+
const result = {};
|
|
191
|
+
if (seedFromSource) {
|
|
192
|
+
Object.keys(element).forEach(property => {
|
|
193
|
+
result[property] = element[property];
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
return result;
|
|
197
|
+
}
|
|
198
|
+
const memberConstructor = this.resolveArrayMemberConstructor(source, index);
|
|
199
|
+
return plainToInstance(memberConstructor, seedFromSource ? element : {});
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Resolve the concrete class constructor for a single element of an ObjectArray.
|
|
203
|
+
*
|
|
204
|
+
* `destinationType` here is one of two things:
|
|
205
|
+
*
|
|
206
|
+
* - a **class constructor** (uniform array — every element maps to the same class), or
|
|
207
|
+
* - a **factory callback** of shape `(source, sourceProperty, index) => instance`
|
|
208
|
+
* (polymorphic array — class is chosen per element).
|
|
209
|
+
*
|
|
210
|
+
* JavaScript gives us no clean way to distinguish a class constructor from a callback —
|
|
211
|
+
* both are `typeof === "function"`. The conventional discriminant: a class constructor has
|
|
212
|
+
* a `.prototype` object (where its instance methods live); an arrow function does not.
|
|
213
|
+
*
|
|
214
|
+
* Caveat: a regular `function() { ... }` expression used as a callback would also have a
|
|
215
|
+
* `.prototype` and would be mis-classified as a class. The public type only documents the
|
|
216
|
+
* arrow-function form (`ArrayMemberTypeFactoryCallbackType = (...) => any`), and in practice
|
|
217
|
+
* callers use arrow functions, so this is safe for documented usage.
|
|
218
|
+
*/
|
|
219
|
+
resolveArrayMemberConstructor(source, index) {
|
|
220
|
+
const destinationType = this.destinationType;
|
|
221
|
+
const isFactoryCallback = typeof destinationType === "function"
|
|
222
|
+
&& destinationType.prototype === undefined;
|
|
223
|
+
if (isFactoryCallback) {
|
|
224
|
+
const factory = destinationType;
|
|
225
|
+
const sampleInstance = factory(source, this.sourceProperty, index);
|
|
226
|
+
return sampleInstance.constructor;
|
|
227
|
+
}
|
|
228
|
+
return destinationType;
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Run every direct child node against `(sourceElement, destinationElement)`. Each child
|
|
232
|
+
* writes its mapped destination property onto `destinationElement`.
|
|
233
|
+
*/
|
|
234
|
+
runSubNodes(sourceElement, destinationElement, normalizersMap, options) {
|
|
235
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
172
236
|
for (const key in this.nodes) {
|
|
173
237
|
if (this.nodes.hasOwnProperty(key) === false) {
|
|
174
238
|
continue;
|
|
@@ -212,22 +276,28 @@ export class DataMappingNode extends BaseDataMappingNode {
|
|
|
212
276
|
}
|
|
213
277
|
}
|
|
214
278
|
/**
|
|
215
|
-
* This method exports this node.
|
|
279
|
+
* This method exports this node. The exported representation is a plain object — it does not mutate
|
|
280
|
+
* the live tree, so the same builder can continue to be used for mapping after `export()` is called.
|
|
281
|
+
*
|
|
282
|
+
* `destinationType` is intentionally not serialized: class constructors aren't transferable, and
|
|
283
|
+
* factory callbacks (`ArrayMemberTypeFactoryCallbackType`) hold closures. To rehydrate a schema with
|
|
284
|
+
* the same destination instantiation behavior, decorate the destination class with class-transformer's
|
|
285
|
+
* `@Type()` and pass the destination class to `DataMapper.map()`.
|
|
216
286
|
*/
|
|
217
287
|
export() {
|
|
218
|
-
const
|
|
219
|
-
for (const key in nodes) {
|
|
220
|
-
if (nodes.hasOwnProperty(key) === false) {
|
|
288
|
+
const exportedNodes = {};
|
|
289
|
+
for (const key in this.nodes) {
|
|
290
|
+
if (this.nodes.hasOwnProperty(key) === false) {
|
|
221
291
|
continue;
|
|
222
292
|
}
|
|
223
|
-
|
|
293
|
+
exportedNodes[key] = this.nodes[key].export();
|
|
224
294
|
}
|
|
225
295
|
return {
|
|
226
296
|
"_type": this.type,
|
|
227
297
|
"sourceProperty": this.sourceProperty,
|
|
228
298
|
"destinationProperty": this.destinationProperty,
|
|
229
299
|
"isOptional": this.isOptional,
|
|
230
|
-
"nodes":
|
|
300
|
+
"nodes": exportedNodes,
|
|
231
301
|
};
|
|
232
302
|
}
|
|
233
303
|
}
|