@pristine-ts/data-mapping 0.0.282 → 0.0.284

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.
Files changed (205) hide show
  1. package/dist/lib/cjs/data-mapping.module.js +31 -10
  2. package/dist/lib/cjs/data-mapping.module.js.map +1 -1
  3. package/dist/lib/cjs/decorators/type.decorator.js +2 -2
  4. package/dist/lib/cjs/decorators/type.decorator.js.map +1 -1
  5. package/dist/lib/cjs/interceptors/default-data-mapping.interceptor.js +1 -1
  6. package/dist/lib/cjs/interceptors/default-data-mapping.interceptor.js.map +1 -1
  7. package/dist/lib/esm/data-mapping.module.js +31 -10
  8. package/dist/lib/esm/data-mapping.module.js.map +1 -1
  9. package/dist/lib/esm/decorators/type.decorator.js +1 -1
  10. package/dist/lib/esm/decorators/type.decorator.js.map +1 -1
  11. package/dist/lib/esm/interceptors/default-data-mapping.interceptor.js +1 -1
  12. package/dist/lib/esm/interceptors/default-data-mapping.interceptor.js.map +1 -1
  13. package/dist/types/data-mapping.module.d.ts +1 -9
  14. package/dist/types/interceptors/default-data-mapping.interceptor.d.ts +1 -2
  15. package/package.json +6 -4
  16. package/dist/lib/cjs/builders/auto-data-mapping.builder.js +0 -147
  17. package/dist/lib/cjs/builders/auto-data-mapping.builder.js.map +0 -1
  18. package/dist/lib/cjs/builders/builders.js +0 -19
  19. package/dist/lib/cjs/builders/builders.js.map +0 -1
  20. package/dist/lib/cjs/builders/data-mapping.builder.js +0 -178
  21. package/dist/lib/cjs/builders/data-mapping.builder.js.map +0 -1
  22. package/dist/lib/cjs/enums/data-mapping-node-type.enum.js +0 -11
  23. package/dist/lib/cjs/enums/data-mapping-node-type.enum.js.map +0 -1
  24. package/dist/lib/cjs/enums/enums.js +0 -18
  25. package/dist/lib/cjs/enums/enums.js.map +0 -1
  26. package/dist/lib/cjs/errors/array-data-mapping-node-invalid-source-property-type.error.js +0 -20
  27. package/dist/lib/cjs/errors/array-data-mapping-node-invalid-source-property-type.error.js.map +0 -1
  28. package/dist/lib/cjs/errors/data-after-mapping-interceptor-already-added.error.js +0 -21
  29. package/dist/lib/cjs/errors/data-after-mapping-interceptor-already-added.error.js.map +0 -1
  30. package/dist/lib/cjs/errors/data-before-mapping-interceptor-already-added.error.js +0 -21
  31. package/dist/lib/cjs/errors/data-before-mapping-interceptor-already-added.error.js.map +0 -1
  32. package/dist/lib/cjs/errors/data-mapping-interceptor-not-found.error.js +0 -21
  33. package/dist/lib/cjs/errors/data-mapping-interceptor-not-found.error.js.map +0 -1
  34. package/dist/lib/cjs/errors/data-mapping-source-property-not-found.error.js +0 -20
  35. package/dist/lib/cjs/errors/data-mapping-source-property-not-found.error.js.map +0 -1
  36. package/dist/lib/cjs/errors/data-normalizer-already-added.error.js +0 -21
  37. package/dist/lib/cjs/errors/data-normalizer-already-added.error.js.map +0 -1
  38. package/dist/lib/cjs/errors/errors.js +0 -25
  39. package/dist/lib/cjs/errors/errors.js.map +0 -1
  40. package/dist/lib/cjs/errors/normalizer-invalid-source-type.error.js +0 -23
  41. package/dist/lib/cjs/errors/normalizer-invalid-source-type.error.js.map +0 -1
  42. package/dist/lib/cjs/errors/undefined-source-property.error.js +0 -20
  43. package/dist/lib/cjs/errors/undefined-source-property.error.js.map +0 -1
  44. package/dist/lib/cjs/interfaces/data-mapping-interceptor.interface.js +0 -3
  45. package/dist/lib/cjs/interfaces/data-mapping-interceptor.interface.js.map +0 -1
  46. package/dist/lib/cjs/interfaces/data-normalizer.interface.js +0 -3
  47. package/dist/lib/cjs/interfaces/data-normalizer.interface.js.map +0 -1
  48. package/dist/lib/cjs/interfaces/interfaces.js +0 -19
  49. package/dist/lib/cjs/interfaces/interfaces.js.map +0 -1
  50. package/dist/lib/cjs/mappers/data.mapper.js +0 -126
  51. package/dist/lib/cjs/mappers/data.mapper.js.map +0 -1
  52. package/dist/lib/cjs/mappers/mappers.js +0 -18
  53. package/dist/lib/cjs/mappers/mappers.js.map +0 -1
  54. package/dist/lib/cjs/nodes/base-data-mapping.node.js +0 -24
  55. package/dist/lib/cjs/nodes/base-data-mapping.node.js.map +0 -1
  56. package/dist/lib/cjs/nodes/data-mapping.leaf.js +0 -184
  57. package/dist/lib/cjs/nodes/data-mapping.leaf.js.map +0 -1
  58. package/dist/lib/cjs/nodes/data-mapping.node.js +0 -217
  59. package/dist/lib/cjs/nodes/data-mapping.node.js.map +0 -1
  60. package/dist/lib/cjs/nodes/nodes.js +0 -20
  61. package/dist/lib/cjs/nodes/nodes.js.map +0 -1
  62. package/dist/lib/cjs/normalizer-options/base-normalizer.options.js +0 -12
  63. package/dist/lib/cjs/normalizer-options/base-normalizer.options.js.map +0 -1
  64. package/dist/lib/cjs/normalizer-options/date-normalizer.options.js +0 -21
  65. package/dist/lib/cjs/normalizer-options/date-normalizer.options.js.map +0 -1
  66. package/dist/lib/cjs/normalizer-options/lowercase-normalizer.options.js +0 -11
  67. package/dist/lib/cjs/normalizer-options/lowercase-normalizer.options.js.map +0 -1
  68. package/dist/lib/cjs/normalizer-options/normalizer-options.js +0 -22
  69. package/dist/lib/cjs/normalizer-options/normalizer-options.js.map +0 -1
  70. package/dist/lib/cjs/normalizer-options/number-normalizer.options.js +0 -16
  71. package/dist/lib/cjs/normalizer-options/number-normalizer.options.js.map +0 -1
  72. package/dist/lib/cjs/normalizer-options/string-normalizer.options.js +0 -17
  73. package/dist/lib/cjs/normalizer-options/string-normalizer.options.js.map +0 -1
  74. package/dist/lib/cjs/normalizers/date.normalizer.js +0 -73
  75. package/dist/lib/cjs/normalizers/date.normalizer.js.map +0 -1
  76. package/dist/lib/cjs/normalizers/lowercase.normalizer.js +0 -33
  77. package/dist/lib/cjs/normalizers/lowercase.normalizer.js.map +0 -1
  78. package/dist/lib/cjs/normalizers/normalizers.js +0 -21
  79. package/dist/lib/cjs/normalizers/normalizers.js.map +0 -1
  80. package/dist/lib/cjs/normalizers/number.normalizer.js +0 -41
  81. package/dist/lib/cjs/normalizers/number.normalizer.js.map +0 -1
  82. package/dist/lib/cjs/normalizers/string.normalizer.js +0 -63
  83. package/dist/lib/cjs/normalizers/string.normalizer.js.map +0 -1
  84. package/dist/lib/cjs/options/auto-data-mapping-builder.options.js +0 -11
  85. package/dist/lib/cjs/options/auto-data-mapping-builder.options.js.map +0 -1
  86. package/dist/lib/cjs/types/data-mapping-interceptor-unique-key.type.js +0 -3
  87. package/dist/lib/cjs/types/data-mapping-interceptor-unique-key.type.js.map +0 -1
  88. package/dist/lib/cjs/types/data-normalizer-unique-key.type.js +0 -3
  89. package/dist/lib/cjs/types/data-normalizer-unique-key.type.js.map +0 -1
  90. package/dist/lib/cjs/types/types.js +0 -19
  91. package/dist/lib/cjs/types/types.js.map +0 -1
  92. package/dist/lib/esm/builders/auto-data-mapping.builder.js +0 -144
  93. package/dist/lib/esm/builders/auto-data-mapping.builder.js.map +0 -1
  94. package/dist/lib/esm/builders/builders.js +0 -3
  95. package/dist/lib/esm/builders/builders.js.map +0 -1
  96. package/dist/lib/esm/builders/data-mapping.builder.js +0 -174
  97. package/dist/lib/esm/builders/data-mapping.builder.js.map +0 -1
  98. package/dist/lib/esm/enums/data-mapping-node-type.enum.js +0 -8
  99. package/dist/lib/esm/enums/data-mapping-node-type.enum.js.map +0 -1
  100. package/dist/lib/esm/enums/enums.js +0 -2
  101. package/dist/lib/esm/enums/enums.js.map +0 -1
  102. package/dist/lib/esm/errors/array-data-mapping-node-invalid-source-property-type.error.js +0 -16
  103. package/dist/lib/esm/errors/array-data-mapping-node-invalid-source-property-type.error.js.map +0 -1
  104. package/dist/lib/esm/errors/data-after-mapping-interceptor-already-added.error.js +0 -17
  105. package/dist/lib/esm/errors/data-after-mapping-interceptor-already-added.error.js.map +0 -1
  106. package/dist/lib/esm/errors/data-before-mapping-interceptor-already-added.error.js +0 -17
  107. package/dist/lib/esm/errors/data-before-mapping-interceptor-already-added.error.js.map +0 -1
  108. package/dist/lib/esm/errors/data-mapping-interceptor-not-found.error.js +0 -17
  109. package/dist/lib/esm/errors/data-mapping-interceptor-not-found.error.js.map +0 -1
  110. package/dist/lib/esm/errors/data-mapping-source-property-not-found.error.js +0 -16
  111. package/dist/lib/esm/errors/data-mapping-source-property-not-found.error.js.map +0 -1
  112. package/dist/lib/esm/errors/data-normalizer-already-added.error.js +0 -17
  113. package/dist/lib/esm/errors/data-normalizer-already-added.error.js.map +0 -1
  114. package/dist/lib/esm/errors/errors.js +0 -9
  115. package/dist/lib/esm/errors/errors.js.map +0 -1
  116. package/dist/lib/esm/errors/normalizer-invalid-source-type.error.js +0 -19
  117. package/dist/lib/esm/errors/normalizer-invalid-source-type.error.js.map +0 -1
  118. package/dist/lib/esm/errors/undefined-source-property.error.js +0 -16
  119. package/dist/lib/esm/errors/undefined-source-property.error.js.map +0 -1
  120. package/dist/lib/esm/interfaces/data-mapping-interceptor.interface.js +0 -2
  121. package/dist/lib/esm/interfaces/data-mapping-interceptor.interface.js.map +0 -1
  122. package/dist/lib/esm/interfaces/data-normalizer.interface.js +0 -2
  123. package/dist/lib/esm/interfaces/data-normalizer.interface.js.map +0 -1
  124. package/dist/lib/esm/interfaces/interfaces.js +0 -3
  125. package/dist/lib/esm/interfaces/interfaces.js.map +0 -1
  126. package/dist/lib/esm/mappers/data.mapper.js +0 -123
  127. package/dist/lib/esm/mappers/data.mapper.js.map +0 -1
  128. package/dist/lib/esm/mappers/mappers.js +0 -2
  129. package/dist/lib/esm/mappers/mappers.js.map +0 -1
  130. package/dist/lib/esm/nodes/base-data-mapping.node.js +0 -20
  131. package/dist/lib/esm/nodes/base-data-mapping.node.js.map +0 -1
  132. package/dist/lib/esm/nodes/data-mapping.leaf.js +0 -180
  133. package/dist/lib/esm/nodes/data-mapping.leaf.js.map +0 -1
  134. package/dist/lib/esm/nodes/data-mapping.node.js +0 -213
  135. package/dist/lib/esm/nodes/data-mapping.node.js.map +0 -1
  136. package/dist/lib/esm/nodes/nodes.js +0 -4
  137. package/dist/lib/esm/nodes/nodes.js.map +0 -1
  138. package/dist/lib/esm/normalizer-options/base-normalizer.options.js +0 -8
  139. package/dist/lib/esm/normalizer-options/base-normalizer.options.js.map +0 -1
  140. package/dist/lib/esm/normalizer-options/date-normalizer.options.js +0 -17
  141. package/dist/lib/esm/normalizer-options/date-normalizer.options.js.map +0 -1
  142. package/dist/lib/esm/normalizer-options/lowercase-normalizer.options.js +0 -7
  143. package/dist/lib/esm/normalizer-options/lowercase-normalizer.options.js.map +0 -1
  144. package/dist/lib/esm/normalizer-options/normalizer-options.js +0 -6
  145. package/dist/lib/esm/normalizer-options/normalizer-options.js.map +0 -1
  146. package/dist/lib/esm/normalizer-options/number-normalizer.options.js +0 -12
  147. package/dist/lib/esm/normalizer-options/number-normalizer.options.js.map +0 -1
  148. package/dist/lib/esm/normalizer-options/string-normalizer.options.js +0 -13
  149. package/dist/lib/esm/normalizer-options/string-normalizer.options.js.map +0 -1
  150. package/dist/lib/esm/normalizers/date.normalizer.js +0 -70
  151. package/dist/lib/esm/normalizers/date.normalizer.js.map +0 -1
  152. package/dist/lib/esm/normalizers/lowercase.normalizer.js +0 -30
  153. package/dist/lib/esm/normalizers/lowercase.normalizer.js.map +0 -1
  154. package/dist/lib/esm/normalizers/normalizers.js +0 -5
  155. package/dist/lib/esm/normalizers/normalizers.js.map +0 -1
  156. package/dist/lib/esm/normalizers/number.normalizer.js +0 -38
  157. package/dist/lib/esm/normalizers/number.normalizer.js.map +0 -1
  158. package/dist/lib/esm/normalizers/string.normalizer.js +0 -60
  159. package/dist/lib/esm/normalizers/string.normalizer.js.map +0 -1
  160. package/dist/lib/esm/options/auto-data-mapping-builder.options.js +0 -7
  161. package/dist/lib/esm/options/auto-data-mapping-builder.options.js.map +0 -1
  162. package/dist/lib/esm/types/data-mapping-interceptor-unique-key.type.js +0 -2
  163. package/dist/lib/esm/types/data-mapping-interceptor-unique-key.type.js.map +0 -1
  164. package/dist/lib/esm/types/data-normalizer-unique-key.type.js +0 -2
  165. package/dist/lib/esm/types/data-normalizer-unique-key.type.js.map +0 -1
  166. package/dist/lib/esm/types/types.js +0 -3
  167. package/dist/lib/esm/types/types.js.map +0 -1
  168. package/dist/types/builders/auto-data-mapping.builder.d.ts +0 -25
  169. package/dist/types/builders/builders.d.ts +0 -2
  170. package/dist/types/builders/data-mapping.builder.d.ts +0 -110
  171. package/dist/types/enums/data-mapping-node-type.enum.d.ts +0 -6
  172. package/dist/types/enums/enums.d.ts +0 -1
  173. package/dist/types/errors/array-data-mapping-node-invalid-source-property-type.error.d.ts +0 -7
  174. package/dist/types/errors/data-after-mapping-interceptor-already-added.error.d.ts +0 -8
  175. package/dist/types/errors/data-before-mapping-interceptor-already-added.error.d.ts +0 -8
  176. package/dist/types/errors/data-mapping-interceptor-not-found.error.d.ts +0 -8
  177. package/dist/types/errors/data-mapping-source-property-not-found.error.d.ts +0 -7
  178. package/dist/types/errors/data-normalizer-already-added.error.d.ts +0 -7
  179. package/dist/types/errors/errors.d.ts +0 -8
  180. package/dist/types/errors/normalizer-invalid-source-type.error.d.ts +0 -7
  181. package/dist/types/errors/undefined-source-property.error.d.ts +0 -9
  182. package/dist/types/interfaces/data-mapping-interceptor.interface.d.ts +0 -19
  183. package/dist/types/interfaces/data-normalizer.interface.d.ts +0 -15
  184. package/dist/types/interfaces/interfaces.d.ts +0 -2
  185. package/dist/types/mappers/data.mapper.d.ts +0 -38
  186. package/dist/types/mappers/mappers.d.ts +0 -1
  187. package/dist/types/nodes/base-data-mapping.node.d.ts +0 -15
  188. package/dist/types/nodes/data-mapping.leaf.d.ts +0 -92
  189. package/dist/types/nodes/data-mapping.node.d.ts +0 -104
  190. package/dist/types/nodes/nodes.d.ts +0 -3
  191. package/dist/types/normalizer-options/base-normalizer.options.d.ts +0 -4
  192. package/dist/types/normalizer-options/date-normalizer.options.d.ts +0 -12
  193. package/dist/types/normalizer-options/lowercase-normalizer.options.d.ts +0 -4
  194. package/dist/types/normalizer-options/normalizer-options.d.ts +0 -5
  195. package/dist/types/normalizer-options/number-normalizer.options.d.ts +0 -8
  196. package/dist/types/normalizer-options/string-normalizer.options.d.ts +0 -12
  197. package/dist/types/normalizers/date.normalizer.d.ts +0 -6
  198. package/dist/types/normalizers/lowercase.normalizer.d.ts +0 -7
  199. package/dist/types/normalizers/normalizers.d.ts +0 -4
  200. package/dist/types/normalizers/number.normalizer.d.ts +0 -6
  201. package/dist/types/normalizers/string.normalizer.d.ts +0 -6
  202. package/dist/types/options/auto-data-mapping-builder.options.d.ts +0 -11
  203. package/dist/types/types/data-mapping-interceptor-unique-key.type.d.ts +0 -1
  204. package/dist/types/types/data-normalizer-unique-key.type.d.ts +0 -1
  205. package/dist/types/types/types.d.ts +0 -2
@@ -1,184 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.DataMappingLeaf = void 0;
13
- const data_mapping_node_type_enum_1 = require("../enums/data-mapping-node-type.enum");
14
- const data_normalizer_already_added_error_1 = require("../errors/data-normalizer-already-added.error");
15
- const data_mapping_source_property_not_found_error_1 = require("../errors/data-mapping-source-property-not-found.error");
16
- const array_data_mapping_node_invalid_source_property_type_error_1 = require("../errors/array-data-mapping-node-invalid-source-property-type.error");
17
- class DataMappingLeaf {
18
- constructor(root, parent, type = data_mapping_node_type_enum_1.DataMappingNodeTypeEnum.Leaf) {
19
- this.root = root;
20
- this.parent = parent;
21
- this.type = type;
22
- /**
23
- * This property contains an array of Normalizers to apply sequentially when mapping this property.
24
- */
25
- this.normalizers = [];
26
- /**
27
- * This property contains an array of Normalizers that must be excluded from normalizers defined by parents.
28
- */
29
- this.excludedNormalizers = new Set();
30
- /**
31
- * This method specified whether it's possible that this element not be present in the `source` object.
32
- */
33
- this.isOptional = false;
34
- }
35
- /**
36
- * This is a setter for `sourceProperty`.
37
- * @param sourceProperty
38
- */
39
- setSourceProperty(sourceProperty) {
40
- this.sourceProperty = sourceProperty;
41
- return this;
42
- }
43
- /**
44
- * This is a setter for `destinationProperty`.
45
- * @param destinationProperty
46
- */
47
- setDestinationProperty(destinationProperty) {
48
- this.destinationProperty = destinationProperty;
49
- return this;
50
- }
51
- /**
52
- * This is a setter for `isOptional`.
53
- * @param isOptional
54
- */
55
- setIsOptional(isOptional) {
56
- this.isOptional = isOptional;
57
- return this;
58
- }
59
- /**
60
- * This methods adds a normalizer but checks that this normalizer hasn't been added already (either at the root) or
61
- * directly on this leaf.
62
- *
63
- * @param normalizerUniqueKey
64
- * @param options
65
- */
66
- addNormalizer(normalizerUniqueKey, options) {
67
- if (this.hasNormalizer(normalizerUniqueKey)) {
68
- throw new data_normalizer_already_added_error_1.DataNormalizerAlreadyAdded("The data normalizer '" + normalizerUniqueKey + "' has already been added to the leaf with destination property: '" + this.destinationProperty + "'.", normalizerUniqueKey, options);
69
- }
70
- if (this.root.hasNormalizer(normalizerUniqueKey)) {
71
- throw new data_normalizer_already_added_error_1.DataNormalizerAlreadyAdded("The data normalizer '" + normalizerUniqueKey + "' has already been added to the root and cannot be also added to the leaf with destination property: '" + this.destinationProperty + "'.", normalizerUniqueKey, options);
72
- }
73
- this.normalizers.push({
74
- key: normalizerUniqueKey,
75
- options,
76
- });
77
- return this;
78
- }
79
- /**
80
- * This method simply returns whether the normalizer was already added to this node.
81
- * @param normalizerUniqueKey
82
- */
83
- hasNormalizer(normalizerUniqueKey) {
84
- return this.normalizers.find(element => element.key === normalizerUniqueKey) !== undefined;
85
- }
86
- /**
87
- * This method adds a normalizer that must be excluded from the normalizers applied at a higher level.à
88
- * @param normalizerUniqueKey
89
- */
90
- excludeNormalizer(normalizerUniqueKey) {
91
- if (this.excludedNormalizers.has(normalizerUniqueKey)) {
92
- throw new data_normalizer_already_added_error_1.DataNormalizerAlreadyAdded("The EXCLUDED data normalizer '" + normalizerUniqueKey + "' has already been added to this source property: '" + this.sourceProperty + "'.", normalizerUniqueKey);
93
- }
94
- this.excludedNormalizers.add(normalizerUniqueKey);
95
- return this;
96
- }
97
- /**
98
- * This method adds this node to its parent and returns the parent.
99
- */
100
- end() {
101
- // todo: Validate that we actually have all the properties needed (sourceProperty and destinationProperty) for example.
102
- this.parent.addNode(this);
103
- return this.parent;
104
- }
105
- /**
106
- * This method maps the `sourceProperty` from the `source` object and maps it to the `destinationProperty` of the
107
- * `destination` object while applying the normalizers.
108
- *
109
- * @param source
110
- * @param destination
111
- * @param normalizersMap
112
- */
113
- map(source, destination, normalizersMap) {
114
- return __awaiter(this, void 0, void 0, function* () {
115
- if (source.hasOwnProperty(this.sourceProperty) === false) {
116
- if (this.isOptional) {
117
- return;
118
- }
119
- throw new data_mapping_source_property_not_found_error_1.DataMappingSourcePropertyNotFoundError("The property '" + this.sourceProperty + "' isn't found in the Source object and isn't marked as Optional. If you want to ignore this property, use the 'setIsOptional(true)' method in the builder.", this.sourceProperty);
120
- }
121
- const normalizers = this.root.normalizers.filter(element => this.excludedNormalizers.has(element.key) === false);
122
- normalizers.push(...this.normalizers);
123
- if (this.type === data_mapping_node_type_enum_1.DataMappingNodeTypeEnum.ScalarArray) {
124
- // This means that the source[propertyKey] contains an array of objects and each object should be mapped
125
- const array = source[this.sourceProperty];
126
- if (Array.isArray(array) === false) {
127
- throw new array_data_mapping_node_invalid_source_property_type_error_1.ArrayDataMappingNodeInvalidSourcePropertyTypeError(`According to your schema, the property '${this.sourceProperty}' in the source object must contain an Array of Scalar. Instead, it contains: '${typeof array}'.`, this.sourceProperty);
128
- }
129
- destination[this.destinationProperty] = [];
130
- for (let value of array) {
131
- normalizers.forEach(element => {
132
- const normalizer = normalizersMap[element.key];
133
- value = normalizer.normalize(value, element.options);
134
- });
135
- destination[this.destinationProperty].push(value);
136
- }
137
- return;
138
- }
139
- let value = source[this.sourceProperty];
140
- normalizers.forEach(element => {
141
- const normalizer = normalizersMap[element.key];
142
- value = normalizer.normalize(value, element.options);
143
- });
144
- destination[this.destinationProperty] = value;
145
- return;
146
- });
147
- }
148
- /**
149
- * This method imports a schema.
150
- *
151
- * @param schema
152
- */
153
- import(schema) {
154
- this.normalizers = schema.normalizers;
155
- this.excludedNormalizers = new Set();
156
- if (schema.hasOwnProperty("excludedNormalizers")) {
157
- for (const item in schema.excludedNormalizers) {
158
- this.excludeNormalizer(item);
159
- }
160
- }
161
- this.isOptional = schema.isOptional;
162
- this.sourceProperty = schema.sourceProperty;
163
- this.destinationProperty = schema.destinationProperty;
164
- }
165
- /**
166
- * This method exports this node.
167
- */
168
- export() {
169
- const excludedNormalizers = {};
170
- for (const element of this.excludedNormalizers.values()) {
171
- excludedNormalizers[element] = true;
172
- }
173
- return {
174
- "_type": this.type,
175
- "sourceProperty": this.sourceProperty,
176
- "destinationProperty": this.destinationProperty,
177
- "isOptional": this.isOptional,
178
- "normalizers": this.normalizers,
179
- "excludedNormalizers": excludedNormalizers,
180
- };
181
- }
182
- }
183
- exports.DataMappingLeaf = DataMappingLeaf;
184
- //# sourceMappingURL=data-mapping.leaf.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"data-mapping.leaf.js","sourceRoot":"","sources":["../../../../src/nodes/data-mapping.leaf.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,sFAA6E;AAE7E,uGAAyF;AAGzF,yHAA8G;AAE9G,qJAE8E;AAE9E,MAAa,eAAe;IA0BxB,YACqB,IAAwB,EACzB,MAA4C,EAC5C,OAAgC,qDAAuB,CAAC,IAAI;QAF3D,SAAI,GAAJ,IAAI,CAAoB;QACzB,WAAM,GAAN,MAAM,CAAsC;QAC5C,SAAI,GAAJ,IAAI,CAAwD;QAlBhF;;WAEG;QACI,gBAAW,GAAoD,EAAE,CAAC;QAE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,cAAc,CAAC,qBAAqB,CAAC,EAAE;YAC7C,KAAI,MAAM,IAAI,IAAI,MAAM,CAAC,mBAAmB,EAAE;gBAC1C,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;aAChC;SACJ;QAED,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC;QACpC,IAAI,CAAC,cAAc,GAAG,MAAM,CAAC,cAAc,CAAC;QAC5C,IAAI,CAAC,mBAAmB,GAAG,MAAM,CAAC,mBAAmB,CAAC;IAC1D,CAAC;IAED;;OAEG;IACI,MAAM;QACT,MAAM,mBAAmB,GAAQ,EAAE,CAAA;QAEnC,KAAI,MAAM,OAAO,IAAI,IAAI,CAAC,mBAAmB,CAAC,MAAM,EAAE,EAAE;YACpD,mBAAmB,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;SACvC;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,aAAa,EAAE,IAAI,CAAC,WAAW;YAC/B,qBAAqB,EAAE,mBAAmB;SAC7C,CAAA;IACL,CAAC;CACJ;AAjND,0CAiNC"}
@@ -1,217 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.DataMappingNode = void 0;
13
- const data_mapping_node_type_enum_1 = require("../enums/data-mapping-node-type.enum");
14
- const data_mapping_leaf_1 = require("./data-mapping.leaf");
15
- const base_data_mapping_node_1 = require("./base-data-mapping.node");
16
- const data_mapping_source_property_not_found_error_1 = require("../errors/data-mapping-source-property-not-found.error");
17
- const array_data_mapping_node_invalid_source_property_type_error_1 = require("../errors/array-data-mapping-node-invalid-source-property-type.error");
18
- const class_transformer_1 = require("class-transformer");
19
- class DataMappingNode extends base_data_mapping_node_1.BaseDataMappingNode {
20
- constructor(root, parent, type = data_mapping_node_type_enum_1.DataMappingNodeTypeEnum.Node) {
21
- super();
22
- this.root = root;
23
- this.parent = parent;
24
- this.type = type;
25
- /**
26
- * This method specified whether it's possible that this element not be present in the `source` object.
27
- */
28
- this.isOptional = false;
29
- }
30
- /**
31
- * This is a setter for `sourceProperty`.
32
- * @param sourceProperty
33
- */
34
- setSourceProperty(sourceProperty) {
35
- this.sourceProperty = sourceProperty;
36
- return this;
37
- }
38
- /**
39
- * This is a setter for `destinationProperty`.
40
- * @param destinationProperty
41
- */
42
- setDestinationProperty(destinationProperty) {
43
- this.destinationProperty = destinationProperty;
44
- return this;
45
- }
46
- /**
47
- * This is a setter for `destinationType`.
48
- * @param destinationType
49
- */
50
- setDestinationType(destinationType) {
51
- this.destinationType = destinationType;
52
- return this;
53
- }
54
- /**
55
- * This is a setter for `isOptional`.
56
- * @param isOptional
57
- */
58
- setIsOptional(isOptional) {
59
- this.isOptional = isOptional;
60
- return this;
61
- }
62
- /**
63
- * This property creates a new DataMappingLeaf and returns it. It doesn't add it yet. To do so, the `end()` method
64
- * must be called.
65
- */
66
- add() {
67
- return new data_mapping_leaf_1.DataMappingLeaf(this.root, this);
68
- }
69
- /**
70
- * This method adds a nesting level. This should be used when the property contains an object and you want to map
71
- * this object into another object.
72
- */
73
- addNestingLevel() {
74
- return new DataMappingNode(this.root, this);
75
- }
76
- /**
77
- * This method adds an array of Scalar allowing you to apply the normalizer on each scalar in the array. The
78
- * `sourceProperty` and `destinationProperty` correspond to the name of the property that is an array. But, the
79
- * values in the array will be normalized using the normalizer.
80
- *
81
- */
82
- addArrayOfScalar() {
83
- return new data_mapping_leaf_1.DataMappingLeaf(this.root, this, data_mapping_node_type_enum_1.DataMappingNodeTypeEnum.ScalarArray);
84
- }
85
- /**
86
- * This method adds an array of objects allowing to define a node for each property in the object. Each object in
87
- * the array will be treated as being the same.
88
- */
89
- addArrayOfObjects() {
90
- return new DataMappingNode(this.root, this, data_mapping_node_type_enum_1.DataMappingNodeTypeEnum.ObjectArray);
91
- }
92
- /**
93
- * This method adds this node to its parent and returns the parent.
94
- */
95
- end() {
96
- // todo: Validate that we actually have all the properties needed (sourceProperty and destinationProperty) for example.
97
- this.parent.addNode(this);
98
- return this.parent;
99
- }
100
- /**
101
- * This method maps the `sourceProperty` from the `source` object and maps it to the `destinationProperty` of the
102
- * `destination` object while applying the normalizers.
103
- *
104
- * @param source
105
- * @param destination
106
- * @param normalizersMap
107
- */
108
- map(source, destination, normalizersMap) {
109
- return __awaiter(this, void 0, void 0, function* () {
110
- if (source.hasOwnProperty(this.sourceProperty) === false) {
111
- if (this.isOptional) {
112
- return;
113
- }
114
- throw new data_mapping_source_property_not_found_error_1.DataMappingSourcePropertyNotFoundError("The property '" + this.sourceProperty + "' isn't found in the Source object and isn't marked as Optional. If you want to ignore this property, use the 'setIsOptional(true)' method in the builder.", this.sourceProperty);
115
- }
116
- const sourceElement = source[this.sourceProperty];
117
- if (destination[this.destinationProperty] === undefined) {
118
- if (this.type === data_mapping_node_type_enum_1.DataMappingNodeTypeEnum.ObjectArray) {
119
- destination[this.destinationProperty] = [];
120
- }
121
- else {
122
- if (this.destinationType) {
123
- destination[this.destinationProperty] = (0, class_transformer_1.plainToInstance)(this.destinationType, {});
124
- }
125
- else {
126
- destination[this.destinationProperty] = {};
127
- }
128
- }
129
- }
130
- const destinationElement = destination[this.destinationProperty];
131
- if (this.type === data_mapping_node_type_enum_1.DataMappingNodeTypeEnum.ObjectArray) {
132
- // This means that the source[propertyKey] contains an array of objects and each object should be mapped
133
- const array = source[this.sourceProperty];
134
- if (Array.isArray(array) === false) {
135
- throw new array_data_mapping_node_invalid_source_property_type_error_1.ArrayDataMappingNodeInvalidSourcePropertyTypeError(`According to your schema, the property '${this.sourceProperty}' in the source object must contain an Array of objects. Instead, it contains: '${typeof array}'.`, this.sourceProperty);
136
- }
137
- for (const element of array) {
138
- let dest = {};
139
- if (this.destinationType) {
140
- dest = (0, class_transformer_1.plainToInstance)(this.destinationType, {});
141
- }
142
- for (const key in this.nodes) {
143
- if (this.nodes.hasOwnProperty(key) === false) {
144
- continue;
145
- }
146
- const node = this.nodes[key];
147
- yield node.map(element, dest, normalizersMap);
148
- }
149
- destinationElement.push(dest);
150
- }
151
- return;
152
- }
153
- // When the current node is not an array, we simply iterate
154
- for (const key in this.nodes) {
155
- if (this.nodes.hasOwnProperty(key) === false) {
156
- continue;
157
- }
158
- const node = this.nodes[key];
159
- yield node.map(sourceElement, destinationElement, normalizersMap);
160
- }
161
- });
162
- }
163
- /**
164
- * This method imports a schema.
165
- *
166
- * @param schema
167
- */
168
- import(schema) {
169
- this.sourceProperty = schema.sourceProperty;
170
- this.destinationProperty = schema.destinationProperty;
171
- this.isOptional = schema.isOptional;
172
- this.nodes = {};
173
- const nodes = schema.nodes;
174
- for (const key in nodes) {
175
- if (nodes.hasOwnProperty(key) === false) {
176
- continue;
177
- }
178
- const nodeInfo = nodes[key];
179
- const type = nodeInfo["_type"];
180
- switch (type) {
181
- case data_mapping_node_type_enum_1.DataMappingNodeTypeEnum.ScalarArray:
182
- case data_mapping_node_type_enum_1.DataMappingNodeTypeEnum.Leaf:
183
- const leaf = new data_mapping_leaf_1.DataMappingLeaf(this.root, this, type);
184
- leaf.import(nodeInfo);
185
- this.nodes[leaf.sourceProperty] = leaf;
186
- continue;
187
- case data_mapping_node_type_enum_1.DataMappingNodeTypeEnum.Node:
188
- case data_mapping_node_type_enum_1.DataMappingNodeTypeEnum.ObjectArray:
189
- const node = new DataMappingNode(this.root, this, type);
190
- node.import(nodeInfo);
191
- this.nodes[node.sourceProperty] = node;
192
- continue;
193
- }
194
- }
195
- }
196
- /**
197
- * This method exports this node.
198
- */
199
- export() {
200
- const nodes = this.nodes;
201
- for (const key in nodes) {
202
- if (nodes.hasOwnProperty(key) === false) {
203
- continue;
204
- }
205
- nodes[key] = nodes[key].export();
206
- }
207
- return {
208
- "_type": this.type,
209
- "sourceProperty": this.sourceProperty,
210
- "destinationProperty": this.destinationProperty,
211
- "isOptional": this.isOptional,
212
- "nodes": nodes,
213
- };
214
- }
215
- }
216
- exports.DataMappingNode = DataMappingNode;
217
- //# sourceMappingURL=data-mapping.node.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"data-mapping.node.js","sourceRoot":"","sources":["../../../../src/nodes/data-mapping.node.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,sFAA6E;AAC7E,2DAAoD;AAEpD,qEAA6D;AAC7D,yHAA8G;AAG9G,qJAE8E;AAC9E,yDAAoE;AAEpE,MAAa,eAAgB,SAAQ,4CAAmB;IAqBpD,YAA4B,IAAwB,EACxB,MAA4C,EAC5C,OAAgC,qDAAuB,CAAC,IAAI;QAEpF,KAAK,EAAE,CAAC;QAJgB,SAAI,GAAJ,IAAI,CAAoB;QACxB,WAAM,GAAN,MAAM,CAAsC;QAC5C,SAAI,GAAJ,IAAI,CAAwD;QAZxF;;WAEG;QACI,eAAU,GAAY,KAAK,CAAC;IAYnC,CAAC;IAED;;;OAGG;IACI,iBAAiB,CAAC,cAAsB;QAC3C,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;QACrC,OAAO,IAAI,CAAC;IAChB,CAAC;IAED;;;OAGG;IACI,sBAAsB,CAAC,mBAA2B;QACrD,IAAI,CAAC,mBAAmB,GAAG,mBAAmB,CAAC;QAC/C,OAAO,IAAI,CAAC;IAChB,CAAC;IAED;;;OAGG;IACI,kBAAkB,CAAC,eAAsC;QAC5D,IAAI,CAAC,eAAe,GA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AC,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;gBAEb,KAAK,qDAAuB,CAAC,IAAI,CAAC;gBAClC,KAAK,qDAAuB,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;AAvPD,0CAuPC"}
@@ -1,20 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./base-data-mapping.node"), exports);
18
- __exportStar(require("./data-mapping.leaf"), exports);
19
- __exportStar(require("./data-mapping.node"), exports);
20
- //# sourceMappingURL=nodes.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"nodes.js","sourceRoot":"","sources":["../../../../src/nodes/nodes.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2DAAyC;AACzC,sDAAoC;AACpC,sDAAoC"}
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BaseNormalizerOptions = void 0;
4
- class BaseNormalizerOptions {
5
- constructor(options) {
6
- var _a;
7
- this.shouldThrowIfTypeIsNotString = false;
8
- this.shouldThrowIfTypeIsNotString = (_a = options === null || options === void 0 ? void 0 : options.shouldThrowIfTypeIsNotString) !== null && _a !== void 0 ? _a : this.shouldThrowIfTypeIsNotString;
9
- }
10
- }
11
- exports.BaseNormalizerOptions = BaseNormalizerOptions;
12
- //# sourceMappingURL=base-normalizer.options.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"base-normalizer.options.js","sourceRoot":"","sources":["../../../../src/normalizer-options/base-normalizer.options.ts"],"names":[],"mappings":";;;AAAA,MAAsB,qBAAqB;IAGvC,YAAmB,OAAwC;;QAFpD,iCAA4B,GAAY,KAAK,CAAC;QAGjD,IAAI,CAAC,4BAA4B,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,4BAA4B,mCAAI,IAAI,CAAC,4BAA4B,CAAC;IACnH,CAAC;CACJ;AAND,sDAMC"}
@@ -1,21 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DateNormalizerOptions = void 0;
4
- class DateNormalizerOptions {
5
- constructor(options) {
6
- var _a, _b;
7
- /**
8
- * This property specifies whether an invalid date should return undefined or a date object.
9
- */
10
- this.returnUndefinedOnInvalidDate = true;
11
- /**
12
- * This property specifies if a number should be treated as being in seconds or not. Since JS Date expects a
13
- * timestamp in milliseconds, if the number is in seconds, it will be multiplied by 1000.
14
- */
15
- this.treatNumbers = "seconds";
16
- this.returnUndefinedOnInvalidDate = (_a = options === null || options === void 0 ? void 0 : options.returnUndefinedOnInvalidDate) !== null && _a !== void 0 ? _a : this.returnUndefinedOnInvalidDate;
17
- this.treatNumbers = (_b = options === null || options === void 0 ? void 0 : options.treatNumbers) !== null && _b !== void 0 ? _b : this.treatNumbers;
18
- }
19
- }
20
- exports.DateNormalizerOptions = DateNormalizerOptions;
21
- //# sourceMappingURL=date-normalizer.options.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"date-normalizer.options.js","sourceRoot":"","sources":["../../../../src/normalizer-options/date-normalizer.options.ts"],"names":[],"mappings":";;;AAAA,MAAa,qBAAqB;IAY9B,YAAmB,OAAwC;;QAX3D;;WAEG;QACI,iCAA4B,GAAY,IAAI,CAAC;QAEpD;;;WAGG;QACI,iBAAY,GAA+B,SAAS,CAAC;QAGxD,IAAI,CAAC,4BAA4B,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,4BAA4B,mCAAI,IAAI,CAAC,4BAA4B,CAAC;QAC/G,IAAI,CAAC,YAAY,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,YAAY,mCAAI,IAAI,CAAC,YAAY,CAAC;IACnE,CAAC;CACJ;AAhBD,sDAgBC"}
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LowercaseNormalizerOptions = void 0;
4
- const base_normalizer_options_1 = require("./base-normalizer.options");
5
- class LowercaseNormalizerOptions extends base_normalizer_options_1.BaseNormalizerOptions {
6
- constructor(options) {
7
- super(options);
8
- }
9
- }
10
- exports.LowercaseNormalizerOptions = LowercaseNormalizerOptions;
11
- //# sourceMappingURL=lowercase-normalizer.options.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"lowercase-normalizer.options.js","sourceRoot":"","sources":["../../../../src/normalizer-options/lowercase-normalizer.options.ts"],"names":[],"mappings":";;;AAAA,uEAAgE;AAEhE,MAAa,0BAA2B,SAAQ,+CAAqB;IACjE,YAAmB,OAA6C;QAC5D,KAAK,CAAC,OAAO,CAAC,CAAC;IACnB,CAAC;CACJ;AAJD,gEAIC"}
@@ -1,22 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./base-normalizer.options"), exports);
18
- __exportStar(require("./date-normalizer.options"), exports);
19
- __exportStar(require("./lowercase-normalizer.options"), exports);
20
- __exportStar(require("./number-normalizer.options"), exports);
21
- __exportStar(require("./string-normalizer.options"), exports);
22
- //# sourceMappingURL=normalizer-options.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"normalizer-options.js","sourceRoot":"","sources":["../../../../src/normalizer-options/normalizer-options.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4DAA0C;AAC1C,4DAA0C;AAC1C,iEAA+C;AAC/C,8DAA4C;AAC5C,8DAA4C"}
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NumberNormalizerOptions = void 0;
4
- class NumberNormalizerOptions {
5
- constructor(options) {
6
- var _a;
7
- /**
8
- * This property specifies whether an undefined value should be ignored and simply returned or treated as a potential string
9
- * and return an empty string `""`.
10
- */
11
- this.ignoreUndefined = true;
12
- this.ignoreUndefined = (_a = options === null || options === void 0 ? void 0 : options.ignoreUndefined) !== null && _a !== void 0 ? _a : this.ignoreUndefined;
13
- }
14
- }
15
- exports.NumberNormalizerOptions = NumberNormalizerOptions;
16
- //# sourceMappingURL=number-normalizer.options.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"number-normalizer.options.js","sourceRoot":"","sources":["../../../../src/normalizer-options/number-normalizer.options.ts"],"names":[],"mappings":";;;AAAA,MAAa,uBAAuB;IAOhC,YAAmB,OAA0C;;QAN7D;;;WAGG;QACI,oBAAe,GAAY,IAAI,CAAC;QAGnC,IAAI,CAAC,eAAe,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,eAAe,mCAAI,IAAI,CAAC,eAAe,CAAC;IAC5E,CAAC;CACJ;AAVD,0DAUC"}
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.StringNormalizerOptions = void 0;
4
- class StringNormalizerOptions {
5
- constructor(options) {
6
- var _a;
7
- /**
8
- * This property specifies whether an undefined value should be ignored and simply returned or treated as a potential string
9
- * and return an empty string `""`.
10
- */
11
- this.ignoreUndefined = true;
12
- this.ignoreUndefined = (_a = options === null || options === void 0 ? void 0 : options.ignoreUndefined) !== null && _a !== void 0 ? _a : this.ignoreUndefined;
13
- this.dateFormat = options === null || options === void 0 ? void 0 : options.dateFormat;
14
- }
15
- }
16
- exports.StringNormalizerOptions = StringNormalizerOptions;
17
- //# sourceMappingURL=string-normalizer.options.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"string-normalizer.options.js","sourceRoot":"","sources":["../../../../src/normalizer-options/string-normalizer.options.ts"],"names":[],"mappings":";;;AAAA,MAAa,uBAAuB;IAYhC,YAAmB,OAA0C;;QAX7D;;;WAGG;QACI,oBAAe,GAAY,IAAI,CAAC;QAQnC,IAAI,CAAC,eAAe,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,eAAe,mCAAI,IAAI,CAAC,eAAe,CAAC;QACxE,IAAI,CAAC,UAAU,GAAG,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,UAAU,CAAC;IAC1C,CAAC;CACJ;AAhBD,0DAgBC"}
@@ -1,73 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- 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;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var DateNormalizer_1;
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.DateNormalizer = void 0;
11
- const tsyringe_1 = require("tsyringe");
12
- const metadata_1 = require("@pristine-ts/metadata");
13
- let DateNormalizer = DateNormalizer_1 = class DateNormalizer {
14
- getUniqueKey() {
15
- return DateNormalizer_1.name;
16
- }
17
- normalize(source, options) {
18
- const typeEnum = metadata_1.TypeUtils.getTypeOfValue(source);
19
- if (typeEnum === undefined) {
20
- if ((options === null || options === void 0 ? void 0 : options.returnUndefinedOnInvalidDate) === false) {
21
- return new Date();
22
- }
23
- return undefined;
24
- }
25
- let date;
26
- switch (typeEnum) {
27
- case metadata_1.TypeEnum.Number:
28
- if ((options === null || options === void 0 ? void 0 : options.treatNumbers) === "seconds") {
29
- source = source * 1000;
30
- }
31
- case metadata_1.TypeEnum.String:
32
- date = new Date(source);
33
- if (!isNaN(date.getTime())) {
34
- return date;
35
- }
36
- break;
37
- case metadata_1.TypeEnum.Object:
38
- date = new Date();
39
- // todo: Allow this property to be customizable in the options eventually
40
- if (source.hasOwnProperty("year")) {
41
- date.setFullYear(source["year"]);
42
- }
43
- if (source.hasOwnProperty("month")) {
44
- date.setMonth(source["month"]);
45
- }
46
- if (source.hasOwnProperty("day")) {
47
- date.setDate(source["day"]);
48
- }
49
- if (source.hasOwnProperty("hours")) {
50
- date.setHours(source["hours"]);
51
- }
52
- if (source.hasOwnProperty("minutes")) {
53
- date.setMinutes(source["minutes"]);
54
- }
55
- if (source.hasOwnProperty("seconds")) {
56
- date.setSeconds(source["seconds"]);
57
- }
58
- if (!isNaN(date.getTime())) {
59
- return date;
60
- }
61
- break;
62
- }
63
- if ((options === null || options === void 0 ? void 0 : options.returnUndefinedOnInvalidDate) === false) {
64
- return new Date();
65
- }
66
- return undefined;
67
- }
68
- };
69
- exports.DateNormalizer = DateNormalizer;
70
- exports.DateNormalizer = DateNormalizer = DateNormalizer_1 = __decorate([
71
- (0, tsyringe_1.injectable)()
72
- ], DateNormalizer);
73
- //# sourceMappingURL=date.normalizer.js.map