@pristine-ts/data-mapping 0.0.277
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/LICENSE +201 -0
- package/dist/lib/cjs/builders/builders.js +18 -0
- package/dist/lib/cjs/builders/builders.js.map +1 -0
- package/dist/lib/cjs/builders/data-mapping.builder.js +178 -0
- package/dist/lib/cjs/builders/data-mapping.builder.js.map +1 -0
- package/dist/lib/cjs/data-mapping.module.js +38 -0
- package/dist/lib/cjs/data-mapping.module.js.map +1 -0
- package/dist/lib/cjs/data-mapping.module.keyname.js +5 -0
- package/dist/lib/cjs/data-mapping.module.keyname.js.map +1 -0
- package/dist/lib/cjs/enums/data-mapping-node-type.enum.js +11 -0
- package/dist/lib/cjs/enums/data-mapping-node-type.enum.js.map +1 -0
- package/dist/lib/cjs/enums/enums.js +18 -0
- package/dist/lib/cjs/enums/enums.js.map +1 -0
- package/dist/lib/cjs/errors/array-data-mapping-node-invalid-source-property-type.error.js +20 -0
- package/dist/lib/cjs/errors/array-data-mapping-node-invalid-source-property-type.error.js.map +1 -0
- package/dist/lib/cjs/errors/data-after-mapping-interceptor-already-added.error.js +21 -0
- package/dist/lib/cjs/errors/data-after-mapping-interceptor-already-added.error.js.map +1 -0
- package/dist/lib/cjs/errors/data-before-mapping-interceptor-already-added.error.js +21 -0
- package/dist/lib/cjs/errors/data-before-mapping-interceptor-already-added.error.js.map +1 -0
- package/dist/lib/cjs/errors/data-mapping-interceptor-not-found.error.js +21 -0
- package/dist/lib/cjs/errors/data-mapping-interceptor-not-found.error.js.map +1 -0
- package/dist/lib/cjs/errors/data-mapping-source-property-not-found.error.js +20 -0
- package/dist/lib/cjs/errors/data-mapping-source-property-not-found.error.js.map +1 -0
- package/dist/lib/cjs/errors/data-normalizer-already-added.error.js +21 -0
- package/dist/lib/cjs/errors/data-normalizer-already-added.error.js.map +1 -0
- package/dist/lib/cjs/errors/errors.js +25 -0
- package/dist/lib/cjs/errors/errors.js.map +1 -0
- package/dist/lib/cjs/errors/normalizer-invalid-source-type.error.js +23 -0
- package/dist/lib/cjs/errors/normalizer-invalid-source-type.error.js.map +1 -0
- package/dist/lib/cjs/errors/undefined-source-property.error.js +20 -0
- package/dist/lib/cjs/errors/undefined-source-property.error.js.map +1 -0
- package/dist/lib/cjs/interceptors/default-data-mapping.interceptor.js +44 -0
- package/dist/lib/cjs/interceptors/default-data-mapping.interceptor.js.map +1 -0
- package/dist/lib/cjs/interceptors/interceptors.js +18 -0
- package/dist/lib/cjs/interceptors/interceptors.js.map +1 -0
- package/dist/lib/cjs/interfaces/data-mapping-interceptor.interface.js +3 -0
- package/dist/lib/cjs/interfaces/data-mapping-interceptor.interface.js.map +1 -0
- package/dist/lib/cjs/interfaces/data-normalizer.interface.js +3 -0
- package/dist/lib/cjs/interfaces/data-normalizer.interface.js.map +1 -0
- package/dist/lib/cjs/interfaces/interfaces.js +19 -0
- package/dist/lib/cjs/interfaces/interfaces.js.map +1 -0
- package/dist/lib/cjs/mappers/data.mapper.js +112 -0
- package/dist/lib/cjs/mappers/data.mapper.js.map +1 -0
- package/dist/lib/cjs/mappers/mappers.js +18 -0
- package/dist/lib/cjs/mappers/mappers.js.map +1 -0
- package/dist/lib/cjs/nodes/base-data-mapping.node.js +24 -0
- package/dist/lib/cjs/nodes/base-data-mapping.node.js.map +1 -0
- package/dist/lib/cjs/nodes/data-mapping.leaf.js +184 -0
- package/dist/lib/cjs/nodes/data-mapping.leaf.js.map +1 -0
- package/dist/lib/cjs/nodes/data-mapping.node.js +202 -0
- package/dist/lib/cjs/nodes/data-mapping.node.js.map +1 -0
- package/dist/lib/cjs/nodes/nodes.js +20 -0
- package/dist/lib/cjs/nodes/nodes.js.map +1 -0
- package/dist/lib/cjs/normalizer-options/base-normalizer.options.js +11 -0
- package/dist/lib/cjs/normalizer-options/base-normalizer.options.js.map +1 -0
- package/dist/lib/cjs/normalizer-options/lowercase-normalizer.options.js +11 -0
- package/dist/lib/cjs/normalizer-options/lowercase-normalizer.options.js.map +1 -0
- package/dist/lib/cjs/normalizer-options/normalizer-options.js +19 -0
- package/dist/lib/cjs/normalizer-options/normalizer-options.js.map +1 -0
- package/dist/lib/cjs/normalizers/lowercase.normalizer.js +33 -0
- package/dist/lib/cjs/normalizers/lowercase.normalizer.js.map +1 -0
- package/dist/lib/cjs/normalizers/normalizers.js +18 -0
- package/dist/lib/cjs/normalizers/normalizers.js.map +1 -0
- package/dist/lib/cjs/types/data-mapping-interceptor-unique-key.type.js +3 -0
- package/dist/lib/cjs/types/data-mapping-interceptor-unique-key.type.js.map +1 -0
- package/dist/lib/cjs/types/data-normalizer-unique-key.type.js +3 -0
- package/dist/lib/cjs/types/data-normalizer-unique-key.type.js.map +1 -0
- package/dist/lib/cjs/types/types.js +19 -0
- package/dist/lib/cjs/types/types.js.map +1 -0
- package/dist/lib/esm/builders/builders.js +2 -0
- package/dist/lib/esm/builders/builders.js.map +1 -0
- package/dist/lib/esm/builders/data-mapping.builder.js +174 -0
- package/dist/lib/esm/builders/data-mapping.builder.js.map +1 -0
- package/dist/lib/esm/data-mapping.module.js +21 -0
- package/dist/lib/esm/data-mapping.module.js.map +1 -0
- package/dist/lib/esm/data-mapping.module.keyname.js +2 -0
- package/dist/lib/esm/data-mapping.module.keyname.js.map +1 -0
- package/dist/lib/esm/enums/data-mapping-node-type.enum.js +8 -0
- package/dist/lib/esm/enums/data-mapping-node-type.enum.js.map +1 -0
- package/dist/lib/esm/enums/enums.js +2 -0
- package/dist/lib/esm/enums/enums.js.map +1 -0
- package/dist/lib/esm/errors/array-data-mapping-node-invalid-source-property-type.error.js +16 -0
- package/dist/lib/esm/errors/array-data-mapping-node-invalid-source-property-type.error.js.map +1 -0
- package/dist/lib/esm/errors/data-after-mapping-interceptor-already-added.error.js +17 -0
- package/dist/lib/esm/errors/data-after-mapping-interceptor-already-added.error.js.map +1 -0
- package/dist/lib/esm/errors/data-before-mapping-interceptor-already-added.error.js +17 -0
- package/dist/lib/esm/errors/data-before-mapping-interceptor-already-added.error.js.map +1 -0
- package/dist/lib/esm/errors/data-mapping-interceptor-not-found.error.js +17 -0
- package/dist/lib/esm/errors/data-mapping-interceptor-not-found.error.js.map +1 -0
- package/dist/lib/esm/errors/data-mapping-source-property-not-found.error.js +16 -0
- package/dist/lib/esm/errors/data-mapping-source-property-not-found.error.js.map +1 -0
- package/dist/lib/esm/errors/data-normalizer-already-added.error.js +17 -0
- package/dist/lib/esm/errors/data-normalizer-already-added.error.js.map +1 -0
- package/dist/lib/esm/errors/errors.js +9 -0
- package/dist/lib/esm/errors/errors.js.map +1 -0
- package/dist/lib/esm/errors/normalizer-invalid-source-type.error.js +19 -0
- package/dist/lib/esm/errors/normalizer-invalid-source-type.error.js.map +1 -0
- package/dist/lib/esm/errors/undefined-source-property.error.js +16 -0
- package/dist/lib/esm/errors/undefined-source-property.error.js.map +1 -0
- package/dist/lib/esm/interceptors/default-data-mapping.interceptor.js +41 -0
- package/dist/lib/esm/interceptors/default-data-mapping.interceptor.js.map +1 -0
- package/dist/lib/esm/interceptors/interceptors.js +2 -0
- package/dist/lib/esm/interceptors/interceptors.js.map +1 -0
- package/dist/lib/esm/interfaces/data-mapping-interceptor.interface.js +2 -0
- package/dist/lib/esm/interfaces/data-mapping-interceptor.interface.js.map +1 -0
- package/dist/lib/esm/interfaces/data-normalizer.interface.js +2 -0
- package/dist/lib/esm/interfaces/data-normalizer.interface.js.map +1 -0
- package/dist/lib/esm/interfaces/interfaces.js +3 -0
- package/dist/lib/esm/interfaces/interfaces.js.map +1 -0
- package/dist/lib/esm/mappers/data.mapper.js +109 -0
- package/dist/lib/esm/mappers/data.mapper.js.map +1 -0
- package/dist/lib/esm/mappers/mappers.js +2 -0
- package/dist/lib/esm/mappers/mappers.js.map +1 -0
- package/dist/lib/esm/nodes/base-data-mapping.node.js +20 -0
- package/dist/lib/esm/nodes/base-data-mapping.node.js.map +1 -0
- package/dist/lib/esm/nodes/data-mapping.leaf.js +180 -0
- package/dist/lib/esm/nodes/data-mapping.leaf.js.map +1 -0
- package/dist/lib/esm/nodes/data-mapping.node.js +198 -0
- package/dist/lib/esm/nodes/data-mapping.node.js.map +1 -0
- package/dist/lib/esm/nodes/nodes.js +4 -0
- package/dist/lib/esm/nodes/nodes.js.map +1 -0
- package/dist/lib/esm/normalizer-options/base-normalizer.options.js +7 -0
- package/dist/lib/esm/normalizer-options/base-normalizer.options.js.map +1 -0
- package/dist/lib/esm/normalizer-options/lowercase-normalizer.options.js +7 -0
- package/dist/lib/esm/normalizer-options/lowercase-normalizer.options.js.map +1 -0
- package/dist/lib/esm/normalizer-options/normalizer-options.js +3 -0
- package/dist/lib/esm/normalizer-options/normalizer-options.js.map +1 -0
- package/dist/lib/esm/normalizers/lowercase.normalizer.js +30 -0
- package/dist/lib/esm/normalizers/lowercase.normalizer.js.map +1 -0
- package/dist/lib/esm/normalizers/normalizers.js +2 -0
- package/dist/lib/esm/normalizers/normalizers.js.map +1 -0
- package/dist/lib/esm/types/data-mapping-interceptor-unique-key.type.js +2 -0
- package/dist/lib/esm/types/data-mapping-interceptor-unique-key.type.js.map +1 -0
- package/dist/lib/esm/types/data-normalizer-unique-key.type.js +2 -0
- package/dist/lib/esm/types/data-normalizer-unique-key.type.js.map +1 -0
- package/dist/lib/esm/types/types.js +3 -0
- package/dist/lib/esm/types/types.js.map +1 -0
- package/dist/types/builders/builders.d.ts +1 -0
- package/dist/types/builders/data-mapping.builder.d.ts +110 -0
- package/dist/types/data-mapping.module.d.ts +12 -0
- package/dist/types/data-mapping.module.keyname.d.ts +1 -0
- package/dist/types/enums/data-mapping-node-type.enum.d.ts +6 -0
- package/dist/types/enums/enums.d.ts +1 -0
- package/dist/types/errors/array-data-mapping-node-invalid-source-property-type.error.d.ts +7 -0
- package/dist/types/errors/data-after-mapping-interceptor-already-added.error.d.ts +8 -0
- package/dist/types/errors/data-before-mapping-interceptor-already-added.error.d.ts +8 -0
- package/dist/types/errors/data-mapping-interceptor-not-found.error.d.ts +8 -0
- package/dist/types/errors/data-mapping-source-property-not-found.error.d.ts +7 -0
- package/dist/types/errors/data-normalizer-already-added.error.d.ts +7 -0
- package/dist/types/errors/errors.d.ts +8 -0
- package/dist/types/errors/normalizer-invalid-source-type.error.d.ts +7 -0
- package/dist/types/errors/undefined-source-property.error.d.ts +9 -0
- package/dist/types/interceptors/default-data-mapping.interceptor.d.ts +7 -0
- package/dist/types/interceptors/interceptors.d.ts +1 -0
- package/dist/types/interfaces/data-mapping-interceptor.interface.d.ts +19 -0
- package/dist/types/interfaces/data-normalizer.interface.d.ts +15 -0
- package/dist/types/interfaces/interfaces.d.ts +2 -0
- package/dist/types/mappers/data.mapper.d.ts +28 -0
- package/dist/types/mappers/mappers.d.ts +1 -0
- package/dist/types/nodes/base-data-mapping.node.d.ts +15 -0
- package/dist/types/nodes/data-mapping.leaf.d.ts +92 -0
- package/dist/types/nodes/data-mapping.node.d.ts +94 -0
- package/dist/types/nodes/nodes.d.ts +3 -0
- package/dist/types/normalizer-options/base-normalizer.options.d.ts +4 -0
- package/dist/types/normalizer-options/lowercase-normalizer.options.d.ts +4 -0
- package/dist/types/normalizer-options/normalizer-options.d.ts +2 -0
- package/dist/types/normalizers/lowercase.normalizer.d.ts +7 -0
- package/dist/types/normalizers/normalizers.d.ts +1 -0
- package/dist/types/types/data-mapping-interceptor-unique-key.type.d.ts +1 -0
- package/dist/types/types/data-normalizer-unique-key.type.d.ts +1 -0
- package/dist/types/types/types.d.ts +2 -0
- package/package.json +68 -0
- package/readme.md +1 -0
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { DataMappingNodeTypeEnum } from "../enums/data-mapping-node-type.enum";
|
|
11
|
+
import { DataMappingLeaf } from "./data-mapping.leaf";
|
|
12
|
+
import { BaseDataMappingNode } from "./base-data-mapping.node";
|
|
13
|
+
import { DataMappingSourcePropertyNotFoundError } from "../errors/data-mapping-source-property-not-found.error";
|
|
14
|
+
import { ArrayDataMappingNodeInvalidSourcePropertyTypeError } from "../errors/array-data-mapping-node-invalid-source-property-type.error";
|
|
15
|
+
export class DataMappingNode extends BaseDataMappingNode {
|
|
16
|
+
constructor(root, parent, type = DataMappingNodeTypeEnum.Node) {
|
|
17
|
+
super();
|
|
18
|
+
this.root = root;
|
|
19
|
+
this.parent = parent;
|
|
20
|
+
this.type = type;
|
|
21
|
+
/**
|
|
22
|
+
* This method specified whether it's possible that this element not be present in the `source` object.
|
|
23
|
+
*/
|
|
24
|
+
this.isOptional = false;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* This is a setter for `sourceProperty`.
|
|
28
|
+
* @param sourceProperty
|
|
29
|
+
*/
|
|
30
|
+
setSourceProperty(sourceProperty) {
|
|
31
|
+
this.sourceProperty = sourceProperty;
|
|
32
|
+
return this;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* This is a setter for `destinationProperty`.
|
|
36
|
+
* @param destinationProperty
|
|
37
|
+
*/
|
|
38
|
+
setDestinationProperty(destinationProperty) {
|
|
39
|
+
this.destinationProperty = destinationProperty;
|
|
40
|
+
return this;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* This is a setter for `isOptional`.
|
|
44
|
+
* @param isOptional
|
|
45
|
+
*/
|
|
46
|
+
setIsOptional(isOptional) {
|
|
47
|
+
this.isOptional = isOptional;
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* This property creates a new DataMappingLeaf and returns it. It doesn't add it yet. To do so, the `end()` method
|
|
52
|
+
* must be called.
|
|
53
|
+
*/
|
|
54
|
+
add() {
|
|
55
|
+
return new DataMappingLeaf(this.root, this);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* This method adds a nesting level. This should be used when the property contains an object and you want to map
|
|
59
|
+
* this object into another object.
|
|
60
|
+
*/
|
|
61
|
+
addNestingLevel() {
|
|
62
|
+
return new DataMappingNode(this.root, this);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* This method adds an array of Scalar allowing you to apply the normalizer on each scalar in the array. The
|
|
66
|
+
* `sourceProperty` and `destinationProperty` correspond to the name of the property that is an array. But, the
|
|
67
|
+
* values in the array will be normalized using the normalizer.
|
|
68
|
+
*
|
|
69
|
+
*/
|
|
70
|
+
addArrayOfScalar() {
|
|
71
|
+
return new DataMappingLeaf(this.root, this, DataMappingNodeTypeEnum.ScalarArray);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* This method adds an array of objects allowing to define a node for each property in the object. Each object in
|
|
75
|
+
* the array will be treated as being the same.
|
|
76
|
+
*/
|
|
77
|
+
addArrayOfObjects() {
|
|
78
|
+
return new DataMappingNode(this.root, this, DataMappingNodeTypeEnum.ObjectArray);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* This method adds this node to its parent and returns the parent.
|
|
82
|
+
*/
|
|
83
|
+
end() {
|
|
84
|
+
// todo: Validate that we actually have all the properties needed (sourceProperty and destinationProperty) for example.
|
|
85
|
+
this.parent.addNode(this);
|
|
86
|
+
return this.parent;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* This method maps the `sourceProperty` from the `source` object and maps it to the `destinationProperty` of the
|
|
90
|
+
* `destination` object while applying the normalizers.
|
|
91
|
+
*
|
|
92
|
+
* @param source
|
|
93
|
+
* @param destination
|
|
94
|
+
* @param normalizersMap
|
|
95
|
+
*/
|
|
96
|
+
map(source, destination, normalizersMap) {
|
|
97
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
98
|
+
if (source.hasOwnProperty(this.sourceProperty) === false) {
|
|
99
|
+
if (this.isOptional) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
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);
|
|
103
|
+
}
|
|
104
|
+
const sourceElement = source[this.sourceProperty];
|
|
105
|
+
if (destination[this.destinationProperty] === undefined) {
|
|
106
|
+
if (this.type === DataMappingNodeTypeEnum.ObjectArray) {
|
|
107
|
+
destination[this.destinationProperty] = [];
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
// todo: we need to get the expected Type of the `destination[this.destinationProperty]` and actually instantiate it.
|
|
111
|
+
destination[this.destinationProperty] = {};
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
const destinationElement = destination[this.destinationProperty];
|
|
115
|
+
if (this.type === DataMappingNodeTypeEnum.ObjectArray) {
|
|
116
|
+
// This means that the source[propertyKey] contains an array of objects and each object should be mapped
|
|
117
|
+
const array = source[this.sourceProperty];
|
|
118
|
+
if (Array.isArray(array) === false) {
|
|
119
|
+
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);
|
|
120
|
+
}
|
|
121
|
+
for (const element of array) {
|
|
122
|
+
// todo: we need to get the expected Type of the object in the array in the Destination object
|
|
123
|
+
const dest = {};
|
|
124
|
+
for (const key in this.nodes) {
|
|
125
|
+
if (this.nodes.hasOwnProperty(key) === false) {
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
const node = this.nodes[key];
|
|
129
|
+
yield node.map(element, dest, normalizersMap);
|
|
130
|
+
}
|
|
131
|
+
destinationElement.push(dest);
|
|
132
|
+
}
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
// When the current node is not an array, we simply iterate
|
|
136
|
+
for (const key in this.nodes) {
|
|
137
|
+
if (this.nodes.hasOwnProperty(key) === false) {
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
const node = this.nodes[key];
|
|
141
|
+
yield node.map(sourceElement, destinationElement, normalizersMap);
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* This method imports a schema.
|
|
147
|
+
*
|
|
148
|
+
* @param schema
|
|
149
|
+
*/
|
|
150
|
+
import(schema) {
|
|
151
|
+
this.sourceProperty = schema.sourceProperty;
|
|
152
|
+
this.destinationProperty = schema.destinationProperty;
|
|
153
|
+
this.isOptional = schema.isOptional;
|
|
154
|
+
this.nodes = {};
|
|
155
|
+
const nodes = schema.nodes;
|
|
156
|
+
for (const key in nodes) {
|
|
157
|
+
if (nodes.hasOwnProperty(key) === false) {
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
const nodeInfo = nodes[key];
|
|
161
|
+
const type = nodeInfo["_type"];
|
|
162
|
+
switch (type) {
|
|
163
|
+
case DataMappingNodeTypeEnum.ScalarArray:
|
|
164
|
+
case DataMappingNodeTypeEnum.Leaf:
|
|
165
|
+
const leaf = new DataMappingLeaf(this.root, this, type);
|
|
166
|
+
leaf.import(nodeInfo);
|
|
167
|
+
this.nodes[leaf.sourceProperty] = leaf;
|
|
168
|
+
continue;
|
|
169
|
+
case DataMappingNodeTypeEnum.Node:
|
|
170
|
+
case DataMappingNodeTypeEnum.ObjectArray:
|
|
171
|
+
const node = new DataMappingNode(this.root, this, type);
|
|
172
|
+
node.import(nodeInfo);
|
|
173
|
+
this.nodes[node.sourceProperty] = node;
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* This method exports this node.
|
|
180
|
+
*/
|
|
181
|
+
export() {
|
|
182
|
+
const nodes = this.nodes;
|
|
183
|
+
for (const key in nodes) {
|
|
184
|
+
if (nodes.hasOwnProperty(key) === false) {
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
nodes[key] = nodes[key].export();
|
|
188
|
+
}
|
|
189
|
+
return {
|
|
190
|
+
"_type": this.type,
|
|
191
|
+
"sourceProperty": this.sourceProperty,
|
|
192
|
+
"destinationProperty": this.destinationProperty,
|
|
193
|
+
"isOptional": this.isOptional,
|
|
194
|
+
"nodes": nodes,
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
//# sourceMappingURL=data-mapping.node.js.map
|
|
@@ -0,0 +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;AAC7D,OAAO,EAAC,sCAAsC,EAAC,MAAM,wDAAwD,CAAC;AAG9G,OAAO,EACH,kDAAkD,EACrD,MAAM,sEAAsE,CAAC;AAE9E,MAAM,OAAO,eAAgB,SAAQ,mBAAmB;IAgBpD,YAA4B,IAAwB,EACxB,MAA4C,EAC5C,OAAgC,uBAAuB,CAAC,IAAI;QAEpF,KAAK,EAAE,CAAC;QAJgB,SAAI,GAAJ,IAAI,CAAoB;QACxB,WAAM,GAAN,MAAM,CAAsC;QAC5C,SAAI,GAAJ,IAAI,CAAwD;QAPxF;;WAEG;QACI,eAAU,GAAY,KAAK,CAAC;IAOnC,CAAC;IAED;;;OAGG;IACI,iBAAiB,CAAC,cAAsB;QAC3C,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;QACrC,OAAO,IAAI,C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C,SAAS;gBAEb,KAAK,uBAAuB,CAAC,IAAI,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;aAChB;SACJ;IACL,CAAC;IAED;;OAEG;IACI,MAAM;QACT,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;QAEzB,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE;YACrB,IAAG,KAAK,CAAC,cAAc,CAAC,GAAG,CAAC,KAAK,KAAK,EAAE;gBACpC,SAAS;aACZ;YAED,KAAK,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC;SACpC;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":"nodes.js","sourceRoot":"","sources":["../../../../src/nodes/nodes.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export class BaseNormalizerOptions {
|
|
2
|
+
constructor(options) {
|
|
3
|
+
var _a;
|
|
4
|
+
this.shouldThrowIfTypeIsNotString = (_a = options === null || options === void 0 ? void 0 : options.shouldThrowIfTypeIsNotString) !== null && _a !== void 0 ? _a : false;
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=base-normalizer.options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-normalizer.options.js","sourceRoot":"","sources":["../../../../src/normalizer-options/base-normalizer.options.ts"],"names":[],"mappings":"AAAA,MAAM,OAAgB,qBAAqB;IAGvC,YAAmB,OAA+B;;QAC9C,IAAI,CAAC,4BAA4B,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,4BAA4B,mCAAI,KAAK,CAAC;IACvF,CAAC;CACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lowercase-normalizer.options.js","sourceRoot":"","sources":["../../../../src/normalizer-options/lowercase-normalizer.options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,qBAAqB,EAAC,MAAM,2BAA2B,CAAC;AAEhE,MAAM,OAAO,0BAA2B,SAAQ,qBAAqB;IACjE,YAAmB,OAAoC;QACnD,KAAK,CAAC,OAAO,CAAC,CAAC;IACnB,CAAC;CACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalizer-options.js","sourceRoot":"","sources":["../../../../src/normalizer-options/normalizer-options.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,gCAAgC,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var LowercaseNormalizer_1;
|
|
8
|
+
import { NormalizerInvalidSourceTypeError } from "../errors/normalizer-invalid-source-type.error";
|
|
9
|
+
import { tag } from "@pristine-ts/common";
|
|
10
|
+
import { injectable } from "tsyringe";
|
|
11
|
+
let LowercaseNormalizer = LowercaseNormalizer_1 = class LowercaseNormalizer {
|
|
12
|
+
getUniqueKey() {
|
|
13
|
+
return LowercaseNormalizer_1.name;
|
|
14
|
+
}
|
|
15
|
+
normalize(source, options) {
|
|
16
|
+
if (typeof source !== "string") {
|
|
17
|
+
if (options && options.shouldThrowIfTypeIsNotString) {
|
|
18
|
+
throw new NormalizerInvalidSourceTypeError("The 'LowercaseNormalizer' expects the source value to be of type 'string'. Type '" + typeof source + "' was received.", this.getUniqueKey(), options, source, typeof source);
|
|
19
|
+
}
|
|
20
|
+
return source;
|
|
21
|
+
}
|
|
22
|
+
return source.toLowerCase();
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
LowercaseNormalizer = LowercaseNormalizer_1 = __decorate([
|
|
26
|
+
tag("DataNormalizerInterface"),
|
|
27
|
+
injectable()
|
|
28
|
+
], LowercaseNormalizer);
|
|
29
|
+
export { LowercaseNormalizer };
|
|
30
|
+
//# sourceMappingURL=lowercase.normalizer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lowercase.normalizer.js","sourceRoot":"","sources":["../../../../src/normalizers/lowercase.normalizer.ts"],"names":[],"mappings":";;;;;;;AAEA,OAAO,EAAC,gCAAgC,EAAC,MAAM,gDAAgD,CAAC;AAEhG,OAAO,EAAC,GAAG,EAAC,MAAM,qBAAqB,CAAC;AACxC,OAAO,EAAC,UAAU,EAAC,MAAM,UAAU,CAAC;AAI7B,IAAM,mBAAmB,2BAAzB,MAAM,mBAAmB;IAC5B,YAAY;QACR,OAAO,qBAAmB,CAAC,IAAI,CAAC;IACpC,CAAC;IAED,SAAS,CAAC,MAAW,EAAE,OAAoC;QACvD,IAAG,OAAO,MAAM,KAAK,QAAQ,EAAE;YAC3B,IAAG,OAAO,IAAI,OAAO,CAAC,4BAA4B,EAAE;gBAChD,MAAM,IAAI,gCAAgC,CAAC,mFAAmF,GAAG,OAAO,MAAM,GAAE,iBAAiB,EAAE,IAAI,CAAC,YAAY,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,MAAM,CAAC,CAAA;aAC1N;YAED,OAAO,MAAM,CAAC;SACjB;QAED,OAAO,MAAM,CAAC,WAAW,EAAE,CAAC;IAChC,CAAC;CACJ,CAAA;AAhBY,mBAAmB;IAF/B,GAAG,CAAC,yBAAyB,CAAC;IAC9B,UAAU,EAAE;GACA,mBAAmB,CAgB/B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalizers.js","sourceRoot":"","sources":["../../../../src/normalizers/normalizers.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-mapping-interceptor-unique-key.type.js","sourceRoot":"","sources":["../../../../src/types/data-mapping-interceptor-unique-key.type.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-normalizer-unique-key.type.js","sourceRoot":"","sources":["../../../../src/types/data-normalizer-unique-key.type.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/types/types.ts"],"names":[],"mappings":"AAAA,cAAc,mCAAmC,CAAC;AAClD,cAAc,4CAA4C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./data-mapping.builder";
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { DataMappingNode } from "../nodes/data-mapping.node";
|
|
2
|
+
import { DataNormalizerUniqueKey } from "../types/data-normalizer-unique-key.type";
|
|
3
|
+
import { DataMappingInterceptorUniqueKeyType } from "../types/data-mapping-interceptor-unique-key.type";
|
|
4
|
+
import { DataMappingLeaf } from "../nodes/data-mapping.leaf";
|
|
5
|
+
import { BaseDataMappingNode } from "../nodes/base-data-mapping.node";
|
|
6
|
+
export declare class DataMappingBuilder extends BaseDataMappingNode {
|
|
7
|
+
normalizers: {
|
|
8
|
+
key: DataNormalizerUniqueKey;
|
|
9
|
+
options: any;
|
|
10
|
+
}[];
|
|
11
|
+
beforeMappingInterceptors: {
|
|
12
|
+
key: DataMappingInterceptorUniqueKeyType;
|
|
13
|
+
options: any;
|
|
14
|
+
}[];
|
|
15
|
+
afterMappingInterceptors: {
|
|
16
|
+
key: DataMappingInterceptorUniqueKeyType;
|
|
17
|
+
options: any;
|
|
18
|
+
}[];
|
|
19
|
+
/**
|
|
20
|
+
* This method adds a normalizer to the root that will be applied on each node (unless they explicitly exclude to do
|
|
21
|
+
* so).
|
|
22
|
+
*
|
|
23
|
+
* @param normalizerUniqueKey
|
|
24
|
+
* @param options
|
|
25
|
+
*/
|
|
26
|
+
addNormalizer(normalizerUniqueKey: DataNormalizerUniqueKey, options?: any): DataMappingBuilder;
|
|
27
|
+
/**
|
|
28
|
+
* This method returns whether there's a normalizer for the specified key or not.
|
|
29
|
+
*
|
|
30
|
+
* @param normalizerUniqueKey
|
|
31
|
+
*/
|
|
32
|
+
hasNormalizer(normalizerUniqueKey: DataNormalizerUniqueKey): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* This method adds an interceptor that will be executed **before** the object is mapped.
|
|
35
|
+
*
|
|
36
|
+
* @param key
|
|
37
|
+
* @param options
|
|
38
|
+
*/
|
|
39
|
+
addBeforeMappingInterceptor(key: DataMappingInterceptorUniqueKeyType, options?: any): DataMappingBuilder;
|
|
40
|
+
/**
|
|
41
|
+
* This method returns whether a **before** interceptor already exists.
|
|
42
|
+
* @param key
|
|
43
|
+
*/
|
|
44
|
+
hasBeforeMappingInterceptor(key: DataMappingInterceptorUniqueKeyType): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* This method adds an interceptor that will be executed **after** the object is mapped.
|
|
47
|
+
*
|
|
48
|
+
* @param key
|
|
49
|
+
* @param options
|
|
50
|
+
*/
|
|
51
|
+
addAfterMappingInterceptor(key: DataMappingInterceptorUniqueKeyType, options?: any): DataMappingBuilder;
|
|
52
|
+
/**
|
|
53
|
+
* This method returns whether a **after** interceptor already exists.
|
|
54
|
+
* @param key
|
|
55
|
+
*/
|
|
56
|
+
hasAfterMappingInterceptor(key: DataMappingInterceptorUniqueKeyType): boolean;
|
|
57
|
+
/**
|
|
58
|
+
* This property creates a new DataMappingLeaf and returns it. It doesn't add it yet. To do so, the `end()` method
|
|
59
|
+
* must be called.
|
|
60
|
+
*/
|
|
61
|
+
add(): DataMappingLeaf;
|
|
62
|
+
/**
|
|
63
|
+
* This method adds a nesting level. This should be used when the property contains an object and you want to map
|
|
64
|
+
* this object into another object.
|
|
65
|
+
*/
|
|
66
|
+
addNestingLevel(): DataMappingNode;
|
|
67
|
+
/**
|
|
68
|
+
* This method adds an array of Scalar allowing you to apply the normalizer on each scalar in the array. The
|
|
69
|
+
* `sourceProperty` and `destinationProperty` correspond to the name of the property that is an array. But, the
|
|
70
|
+
* values in the array will be normalized using the normalizer.
|
|
71
|
+
*
|
|
72
|
+
*/
|
|
73
|
+
addArrayOfScalar(): DataMappingLeaf;
|
|
74
|
+
/**
|
|
75
|
+
* This method adds an array of objects allowing to define a node for each property in the object. Each object in
|
|
76
|
+
* the array will be treated as being the same.
|
|
77
|
+
*/
|
|
78
|
+
addArrayOfObjects(): DataMappingNode;
|
|
79
|
+
/**
|
|
80
|
+
* This method is called at the end just to make it nice since all the nodes will have one, it's nice
|
|
81
|
+
* that the builder has one too.
|
|
82
|
+
*/
|
|
83
|
+
end(): DataMappingBuilder;
|
|
84
|
+
/**
|
|
85
|
+
* This method imports a schema.
|
|
86
|
+
*
|
|
87
|
+
* @param schema
|
|
88
|
+
*/
|
|
89
|
+
import(schema: any): void;
|
|
90
|
+
/**
|
|
91
|
+
* This method exports this node.
|
|
92
|
+
*/
|
|
93
|
+
export(): {
|
|
94
|
+
nodes: {
|
|
95
|
+
[x: string]: DataMappingLeaf | DataMappingNode;
|
|
96
|
+
};
|
|
97
|
+
normalizers: {
|
|
98
|
+
key: string;
|
|
99
|
+
options: any;
|
|
100
|
+
}[];
|
|
101
|
+
beforeMappingInterceptors: {
|
|
102
|
+
key: string;
|
|
103
|
+
options: any;
|
|
104
|
+
}[];
|
|
105
|
+
afterMappingInterceptors: {
|
|
106
|
+
key: string;
|
|
107
|
+
options: any;
|
|
108
|
+
}[];
|
|
109
|
+
};
|
|
110
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ModuleInterface } from "@pristine-ts/common";
|
|
2
|
+
export * from "./builders/builders";
|
|
3
|
+
export * from "./enums/enums";
|
|
4
|
+
export * from "./errors/errors";
|
|
5
|
+
export * from "./interceptors/interceptors";
|
|
6
|
+
export * from "./interfaces/interfaces";
|
|
7
|
+
export * from "./mappers/mappers";
|
|
8
|
+
export * from "./nodes/nodes";
|
|
9
|
+
export * from "./normalizer-options/normalizer-options";
|
|
10
|
+
export * from "./normalizers/normalizers";
|
|
11
|
+
export * from "./types/types";
|
|
12
|
+
export declare const DataMappingModule: ModuleInterface;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const DataMappingModuleKeyname: string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./data-mapping-node-type.enum";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { LoggableError } from "@pristine-ts/common";
|
|
2
|
+
/**
|
|
3
|
+
* This Error is thrown when a node is of type array but the `source[sourceProperty]` doesn't actually contain an array.
|
|
4
|
+
*/
|
|
5
|
+
export declare class ArrayDataMappingNodeInvalidSourcePropertyTypeError extends LoggableError {
|
|
6
|
+
constructor(message: string, sourceProperty: string);
|
|
7
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { LoggableError } from "@pristine-ts/common";
|
|
2
|
+
import { DataMappingInterceptorUniqueKeyType } from "../types/data-mapping-interceptor-unique-key.type";
|
|
3
|
+
/**
|
|
4
|
+
* This Error is thrown when the before row interceptor is added more than once to the builder.
|
|
5
|
+
*/
|
|
6
|
+
export declare class DataAfterMappingInterceptorAlreadyAddedError extends LoggableError {
|
|
7
|
+
constructor(message: string, uniqueKey: DataMappingInterceptorUniqueKeyType, options?: any);
|
|
8
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { LoggableError } from "@pristine-ts/common";
|
|
2
|
+
import { DataMappingInterceptorUniqueKeyType } from "../types/data-mapping-interceptor-unique-key.type";
|
|
3
|
+
/**
|
|
4
|
+
* This Error is thrown when the after row interceptor is added more than once to the builder.
|
|
5
|
+
*/
|
|
6
|
+
export declare class DataBeforeMappingInterceptorAlreadyAddedError extends LoggableError {
|
|
7
|
+
constructor(message: string, uniqueKey: DataMappingInterceptorUniqueKeyType, options?: any);
|
|
8
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { LoggableError } from "@pristine-ts/common";
|
|
2
|
+
import { DataMappingInterceptorUniqueKeyType } from "../types/data-mapping-interceptor-unique-key.type";
|
|
3
|
+
/**
|
|
4
|
+
* This Error is thrown if the Data Transformer Class is not found in the list of available interceptors. It might be missing a tag.
|
|
5
|
+
*/
|
|
6
|
+
export declare class DataMappingInterceptorNotFoundError extends LoggableError {
|
|
7
|
+
constructor(message: string, uniqueKey: DataMappingInterceptorUniqueKeyType, options?: any);
|
|
8
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { LoggableError } from "@pristine-ts/common";
|
|
2
|
+
/**
|
|
3
|
+
* This Error is thrown when a property isn't optional and should be found in the source object.
|
|
4
|
+
*/
|
|
5
|
+
export declare class DataMappingSourcePropertyNotFoundError extends LoggableError {
|
|
6
|
+
constructor(message: string, sourceProperty: string);
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { LoggableError } from "@pristine-ts/common";
|
|
2
|
+
/**
|
|
3
|
+
* This Error is thrown when a normalizer is added more than once.
|
|
4
|
+
*/
|
|
5
|
+
export declare class DataNormalizerAlreadyAdded extends LoggableError {
|
|
6
|
+
constructor(message: string, normalizerUniqueKey: string, options?: any);
|
|
7
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./array-data-mapping-node-invalid-source-property-type.error";
|
|
2
|
+
export * from "./data-after-mapping-interceptor-already-added.error";
|
|
3
|
+
export * from "./data-before-mapping-interceptor-already-added.error";
|
|
4
|
+
export * from "./data-normalizer-already-added.error";
|
|
5
|
+
export * from "./data-mapping-interceptor-not-found.error";
|
|
6
|
+
export * from "./data-mapping-source-property-not-found.error";
|
|
7
|
+
export * from "./normalizer-invalid-source-type.error";
|
|
8
|
+
export * from "./undefined-source-property.error";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { LoggableError } from "@pristine-ts/common";
|
|
2
|
+
/**
|
|
3
|
+
* This Error is thrown when an invalid source type is passed to the source type while the normalizer expects another type.
|
|
4
|
+
*/
|
|
5
|
+
export declare class NormalizerInvalidSourceTypeError extends LoggableError {
|
|
6
|
+
constructor(message: string, normalizerUniqueKey: string, options: any, source: any, sourceType: any);
|
|
7
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { LoggableError } from "@pristine-ts/common";
|
|
2
|
+
import { DataMappingLeaf } from "../nodes/data-mapping.leaf";
|
|
3
|
+
import { DataMappingNode } from "../nodes/data-mapping.node";
|
|
4
|
+
/**
|
|
5
|
+
* This Error is thrown when you are trying to add a Node which has an undefined sourceProperty value.
|
|
6
|
+
*/
|
|
7
|
+
export declare class UndefinedSourcePropertyError extends LoggableError {
|
|
8
|
+
constructor(node: DataMappingLeaf | DataMappingNode);
|
|
9
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { DataMappingInterceptorInterface } from "../interfaces/data-mapping-interceptor.interface";
|
|
2
|
+
import { DataMappingInterceptorUniqueKeyType } from "../types/data-mapping-interceptor-unique-key.type";
|
|
3
|
+
export declare class DefaultDataMappingInterceptor implements DataMappingInterceptorInterface {
|
|
4
|
+
afterMapping(row: any): Promise<any>;
|
|
5
|
+
beforeMapping(row: any): Promise<any>;
|
|
6
|
+
getUniqueKey(): DataMappingInterceptorUniqueKeyType;
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./default-data-mapping.interceptor";
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { DataMappingInterceptorUniqueKeyType } from "../types/data-mapping-interceptor-unique-key.type";
|
|
2
|
+
export interface DataMappingInterceptorInterface {
|
|
3
|
+
/**
|
|
4
|
+
* Every data mapping interceptor must define a unique key. Then, during the mapping, the schema can specify which
|
|
5
|
+
* interceptors must be called.
|
|
6
|
+
*/
|
|
7
|
+
getUniqueKey(): DataMappingInterceptorUniqueKeyType;
|
|
8
|
+
/**
|
|
9
|
+
* This method is called before the row is being mapped and normalized. It allows you to combine fields for example if that's what you want.
|
|
10
|
+
* @param row
|
|
11
|
+
*/
|
|
12
|
+
beforeMapping(row: any): Promise<any>;
|
|
13
|
+
/**
|
|
14
|
+
* This method is called after the row is being mapped and normalized. It can allow you to apply operations on each
|
|
15
|
+
* field or combine fields for example.
|
|
16
|
+
* @param row
|
|
17
|
+
*/
|
|
18
|
+
afterMapping(row: any): Promise<any>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { DataNormalizerUniqueKey } from "../types/data-normalizer-unique-key.type";
|
|
2
|
+
export interface DataNormalizerInterface<T, R> {
|
|
3
|
+
/**
|
|
4
|
+
* Every data normalizer must define a unique key. Then, during the transformation, the schema can specify which
|
|
5
|
+
* normalizer it must use. Using the unique key, we can quickly (in O(1)) retrieve the normalizer.
|
|
6
|
+
*/
|
|
7
|
+
getUniqueKey(): DataNormalizerUniqueKey;
|
|
8
|
+
/**
|
|
9
|
+
* This method takes the source property value, can receive options to control the behaviour (example, you might
|
|
10
|
+
* want to specify a number of significant digits or a data format) and returns the normalized value.
|
|
11
|
+
* @param source
|
|
12
|
+
* @param options
|
|
13
|
+
*/
|
|
14
|
+
normalize(source: any, options?: R): T;
|
|
15
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { DataNormalizerInterface } from "../interfaces/data-normalizer.interface";
|
|
2
|
+
import { DataMappingInterceptorInterface } from "../interfaces/data-mapping-interceptor.interface";
|
|
3
|
+
import { DataMappingBuilder } from "../builders/data-mapping.builder";
|
|
4
|
+
import { ClassConstructor } from "class-transformer";
|
|
5
|
+
export declare class DataMapper {
|
|
6
|
+
private readonly dataNormalizers;
|
|
7
|
+
private readonly dataTransformerInterceptors;
|
|
8
|
+
private readonly dataNormalizersMap;
|
|
9
|
+
private readonly dataTransformerInterceptorsMap;
|
|
10
|
+
constructor(dataNormalizers: DataNormalizerInterface<any, any>[], dataTransformerInterceptors: DataMappingInterceptorInterface[]);
|
|
11
|
+
/**
|
|
12
|
+
* This method takes an array of source and maps each item.
|
|
13
|
+
*
|
|
14
|
+
* @param builder
|
|
15
|
+
* @param source
|
|
16
|
+
* @param destinationType
|
|
17
|
+
*/
|
|
18
|
+
mapAll(builder: DataMappingBuilder, source: any[], destinationType?: ClassConstructor<any>): Promise<any[]>;
|
|
19
|
+
/**
|
|
20
|
+
* This method takes a builder, a source and maps it according to the builder. You can pass a `destinationType (optional)`
|
|
21
|
+
* that is an object that will be constructed.
|
|
22
|
+
*
|
|
23
|
+
* @param builder
|
|
24
|
+
* @param source
|
|
25
|
+
* @param destinationType
|
|
26
|
+
*/
|
|
27
|
+
map(builder: DataMappingBuilder, source: any, destinationType?: ClassConstructor<any>): Promise<any>;
|
|
28
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./data.mapper";
|