mapper-factory 2.0.1 → 2.0.3
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/class.decorator.js +1 -1
- package/dist/example.js +30 -0
- package/dist/functions.d.ts +1 -1
- package/dist/functions.js +5 -5
- package/dist/mapper.js +1 -1
- package/package.json +1 -1
package/dist/class.decorator.js
CHANGED
|
@@ -4,7 +4,7 @@ exports.MapClass = void 0;
|
|
|
4
4
|
const functions_1 = require("./functions");
|
|
5
5
|
function MapClass() {
|
|
6
6
|
return function (constructor) {
|
|
7
|
-
constructor.prototype.from = functions_1.
|
|
7
|
+
constructor.prototype.from = functions_1.from;
|
|
8
8
|
constructor.prototype.toMap = functions_1.toMap;
|
|
9
9
|
constructor.prototype.toModel = functions_1.objToModel;
|
|
10
10
|
constructor.prototype.empty = functions_1.empty;
|
package/dist/example.js
CHANGED
|
@@ -193,4 +193,34 @@ console.log("EMPTY: ", test.empty());
|
|
|
193
193
|
console.log("FILLED: ", test.filled());
|
|
194
194
|
console.log("TO MODEL: ", test.toModel({ a: 'test to model' }));
|
|
195
195
|
console.log("TO MAP: ", test.toMap());
|
|
196
|
+
console.log("COPY: ", test.copy());
|
|
197
|
+
console.log("\n\n");
|
|
198
|
+
//TEST TestFlag with initialize
|
|
199
|
+
console.log("\nTEST TestFlag with initialize");
|
|
200
|
+
let TestFlag = class TestFlag {
|
|
201
|
+
flTest;
|
|
202
|
+
};
|
|
203
|
+
__decorate([
|
|
204
|
+
(0, field_decorator_1.MapField)({
|
|
205
|
+
transformer: (num) => {
|
|
206
|
+
console.log("sto trasformando da num a bool");
|
|
207
|
+
return num == '1';
|
|
208
|
+
},
|
|
209
|
+
reverser: bool => {
|
|
210
|
+
console.log("sto trasformando da bool a num");
|
|
211
|
+
return bool ? '1' : '0';
|
|
212
|
+
},
|
|
213
|
+
initialize: true,
|
|
214
|
+
}),
|
|
215
|
+
__metadata("design:type", String)
|
|
216
|
+
], TestFlag.prototype, "flTest", void 0);
|
|
217
|
+
TestFlag = __decorate([
|
|
218
|
+
(0, class_decorator_1.MapClass)()
|
|
219
|
+
], TestFlag);
|
|
220
|
+
const testFlag0 = new TestFlag().from({ flTest: '0' });
|
|
221
|
+
console.log("TEST FLAG0", testFlag0);
|
|
222
|
+
console.log("TO MAP: ", testFlag0.toMap());
|
|
223
|
+
const testFlag1 = new TestFlag().from({ flTest: '1' });
|
|
224
|
+
console.log("TEST FLAG1", testFlag1);
|
|
225
|
+
console.log("TO MAP: ", testFlag1.toMap());
|
|
196
226
|
console.log("\n\n");
|
package/dist/functions.d.ts
CHANGED
package/dist/functions.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.from = exports.copy = exports.set = exports.get = exports.filled = exports.empty = exports.objToModel = exports.toMap = void 0;
|
|
4
4
|
const field_decorator_1 = require("./field.decorator");
|
|
5
5
|
/**
|
|
6
6
|
* Convert the instance of this class to JSON Object.
|
|
@@ -200,7 +200,7 @@ exports.set = set;
|
|
|
200
200
|
* Deep copy of the object caller
|
|
201
201
|
*/
|
|
202
202
|
function copy() {
|
|
203
|
-
return this.
|
|
203
|
+
return this.from(this.toMap());
|
|
204
204
|
}
|
|
205
205
|
exports.copy = copy;
|
|
206
206
|
/**
|
|
@@ -208,7 +208,7 @@ exports.copy = copy;
|
|
|
208
208
|
*
|
|
209
209
|
* @param object object to be mapped considering metadata "src", "transformer" and "reverser"
|
|
210
210
|
*/
|
|
211
|
-
function
|
|
211
|
+
function from(object) {
|
|
212
212
|
const metadataList = (0, field_decorator_1.getMapFieldMetadataList)(this);
|
|
213
213
|
object && Object.keys(object).forEach(propertyName => {
|
|
214
214
|
let metaKeys = metadataList && Object.keys(metadataList).filter(metadata => metadataList[metadata]?.src?.split('.')?.includes(propertyName));
|
|
@@ -291,10 +291,10 @@ function constructorMap(object) {
|
|
|
291
291
|
});
|
|
292
292
|
//MAP CASE initialize = true
|
|
293
293
|
metadataList && Object.keys(metadataList).forEach(metaName => {
|
|
294
|
-
if (metadataList[metaName]?.initialize && metadataList[metaName]?.transformer) {
|
|
294
|
+
if (metadataList[metaName]?.initialize && metadataList[metaName]?.transformer && this[metaName] == undefined) {
|
|
295
295
|
this[metaName] = metadataList[metaName]?.transformer(null, object);
|
|
296
296
|
}
|
|
297
297
|
});
|
|
298
298
|
return this;
|
|
299
299
|
}
|
|
300
|
-
exports.
|
|
300
|
+
exports.from = from;
|
package/dist/mapper.js
CHANGED
|
@@ -91,7 +91,7 @@ class MapperFactory {
|
|
|
91
91
|
});
|
|
92
92
|
//MAP CASE initialize = true
|
|
93
93
|
metadataList && Object.keys(metadataList).forEach(metaName => {
|
|
94
|
-
if (metadataList[metaName]?.initialize && metadataList[metaName]?.transformer) {
|
|
94
|
+
if (metadataList[metaName]?.initialize && metadataList[metaName]?.transformer && this[metaName] == undefined) {
|
|
95
95
|
this[metaName] = metadataList[metaName]?.transformer(null, object);
|
|
96
96
|
}
|
|
97
97
|
});
|