mapper-factory 1.0.32 → 1.0.33
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/examples/example.d.ts +1 -0
- package/dist/examples/example.js +135 -0
- package/dist/{mapper.js → src/mapper.js} +4 -3
- package/package.json +1 -1
- /package/dist/{field.decorator.d.ts → src/field.decorator.d.ts} +0 -0
- /package/dist/{field.decorator.js → src/field.decorator.js} +0 -0
- /package/dist/{index.d.ts → src/index.d.ts} +0 -0
- /package/dist/{index.js → src/index.js} +0 -0
- /package/dist/{mapper.d.ts → src/mapper.d.ts} +0 -0
- /package/dist/{types.d.ts → src/types.d.ts} +0 -0
- /package/dist/{types.js → src/types.js} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,135 @@
|
|
|
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 __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const field_decorator_1 = require("../src/field.decorator");
|
|
13
|
+
const mapper_1 = require("../src/mapper");
|
|
14
|
+
class History extends mapper_1.MapperFactory {
|
|
15
|
+
}
|
|
16
|
+
__decorate([
|
|
17
|
+
(0, field_decorator_1.MapField)({
|
|
18
|
+
transformer: (arr) => " TEST TRASFORMER",
|
|
19
|
+
reverser: (arr) => " TEST REVERSER",
|
|
20
|
+
}),
|
|
21
|
+
__metadata("design:type", String)
|
|
22
|
+
], History.prototype, "name", void 0);
|
|
23
|
+
__decorate([
|
|
24
|
+
(0, field_decorator_1.MapField)({
|
|
25
|
+
src: "control"
|
|
26
|
+
}),
|
|
27
|
+
__metadata("design:type", String)
|
|
28
|
+
], History.prototype, "testControl", void 0);
|
|
29
|
+
__decorate([
|
|
30
|
+
(0, field_decorator_1.MapField)({
|
|
31
|
+
initialize: true,
|
|
32
|
+
transformer: (arr, obj) => { return [obj.monday, obj.tuesday]; },
|
|
33
|
+
reverser: (arr) => {
|
|
34
|
+
return { monday: arr && arr[0], tuesday: arr && arr[1] };
|
|
35
|
+
},
|
|
36
|
+
}),
|
|
37
|
+
__metadata("design:type", Array)
|
|
38
|
+
], History.prototype, "daysActive", void 0);
|
|
39
|
+
__decorate([
|
|
40
|
+
(0, field_decorator_1.MapField)({
|
|
41
|
+
src: "test.concatenation"
|
|
42
|
+
}),
|
|
43
|
+
__metadata("design:type", String)
|
|
44
|
+
], History.prototype, "testConcatenation", void 0);
|
|
45
|
+
class User extends mapper_1.MapperFactory {
|
|
46
|
+
}
|
|
47
|
+
__decorate([
|
|
48
|
+
(0, field_decorator_1.MapField)({
|
|
49
|
+
src: 'firstName'
|
|
50
|
+
}),
|
|
51
|
+
__metadata("design:type", String)
|
|
52
|
+
], User.prototype, "name", void 0);
|
|
53
|
+
__decorate([
|
|
54
|
+
(0, field_decorator_1.MapField)({
|
|
55
|
+
src: 'lastName'
|
|
56
|
+
}),
|
|
57
|
+
__metadata("design:type", String)
|
|
58
|
+
], User.prototype, "surname", void 0);
|
|
59
|
+
__decorate([
|
|
60
|
+
(0, field_decorator_1.MapField)({
|
|
61
|
+
src: 'rolesToMap',
|
|
62
|
+
transformer: (arr) => arr?.map(role => role + " TEST TRASFORMER"),
|
|
63
|
+
reverser: (arr) => arr?.map(role => role.replace(" TEST TRASFORMER", "")),
|
|
64
|
+
}),
|
|
65
|
+
__metadata("design:type", Array)
|
|
66
|
+
], User.prototype, "roles", void 0);
|
|
67
|
+
__decorate([
|
|
68
|
+
(0, field_decorator_1.MapField)({
|
|
69
|
+
transformer: (arr) => arr?.map(user => new User(user))
|
|
70
|
+
}),
|
|
71
|
+
__metadata("design:type", Array)
|
|
72
|
+
], User.prototype, "employees", void 0);
|
|
73
|
+
__decorate([
|
|
74
|
+
(0, field_decorator_1.MapField)({
|
|
75
|
+
transformer: (user) => new User(user)
|
|
76
|
+
}),
|
|
77
|
+
__metadata("design:type", User)
|
|
78
|
+
], User.prototype, "boss", void 0);
|
|
79
|
+
__decorate([
|
|
80
|
+
(0, field_decorator_1.MapField)({
|
|
81
|
+
transformer: histories => histories?.map(hst => new History(hst)),
|
|
82
|
+
reverser: histories => histories?.map(hst => hst.toMap()),
|
|
83
|
+
}),
|
|
84
|
+
__metadata("design:type", Array)
|
|
85
|
+
], User.prototype, "histories", void 0);
|
|
86
|
+
let emp1 = new User({ firstName: "Summer", lastName: "Smith" });
|
|
87
|
+
let emp2 = new User({ firstName: "Morty", lastName: "Smith" });
|
|
88
|
+
let JSONObject = { firstName: "Rick", lastName: "Sanchez", employees: [emp1.toMap(), emp2.toMap()], rolesToMap: ["CEO", "EMPLOYEE"], boss: { firstName: "Nello", lastName: "Stanco" } };
|
|
89
|
+
//TEST constructor
|
|
90
|
+
let u = new User(JSONObject);
|
|
91
|
+
console.log("\nTEST constructor");
|
|
92
|
+
console.log(JSONObject);
|
|
93
|
+
console.log(u);
|
|
94
|
+
//TEST objToModel method with JS Object
|
|
95
|
+
let u1 = new User();
|
|
96
|
+
console.log("\nTEST objToModel method with JS Object");
|
|
97
|
+
console.log(u1.objToModel(u));
|
|
98
|
+
//TEST objToModel method with JSON Object
|
|
99
|
+
console.log("\nTEST objToModel method with JSON Object");
|
|
100
|
+
console.log(u.objToModel({ name: "Rick TEST-objToModel", roles: ["CEO TEST-objToModel", "EMPLOYEE TEST-objToModel"] }));
|
|
101
|
+
//TEST toMap method
|
|
102
|
+
console.log("\nTEST toMap method");
|
|
103
|
+
console.log(u.toMap());
|
|
104
|
+
//TEST empty method
|
|
105
|
+
console.log("\nTEST empty method");
|
|
106
|
+
console.log(u.empty());
|
|
107
|
+
//TEST get AND set method
|
|
108
|
+
u.set("employees[1].name", "name editato");
|
|
109
|
+
console.log("\nTEST get AND set method");
|
|
110
|
+
console.log(u);
|
|
111
|
+
console.log(u.get("employees[1].name"));
|
|
112
|
+
//TEST deep copy
|
|
113
|
+
console.log("\nTEST deep copy");
|
|
114
|
+
let dpCopy = new User(u.toMap());
|
|
115
|
+
dpCopy.name = "nome dpCopy";
|
|
116
|
+
console.log(u);
|
|
117
|
+
console.log(dpCopy);
|
|
118
|
+
//TEST trasformer/reverser
|
|
119
|
+
console.log("\nTEST reverser");
|
|
120
|
+
let h1 = new History({ name: "h1" });
|
|
121
|
+
let h2 = new History({ name: "h2" });
|
|
122
|
+
u.histories = [h1, h2];
|
|
123
|
+
console.log(u);
|
|
124
|
+
console.log(u.toMap());
|
|
125
|
+
//TEST ref
|
|
126
|
+
console.log("\nTEST REF");
|
|
127
|
+
let hTest = new History({ monday: "0", tuesday: "1", control: "control" });
|
|
128
|
+
console.log(hTest);
|
|
129
|
+
hTest.daysActive = ['1', '0'];
|
|
130
|
+
console.log(hTest.toMap());
|
|
131
|
+
//TEST concat with point
|
|
132
|
+
console.log("\nTEST CONCAT W POINT");
|
|
133
|
+
let hTest2 = new History({ test: { concatenation: "resolve " }, control: "control" });
|
|
134
|
+
console.log(hTest2);
|
|
135
|
+
console.log(hTest2.toMap());
|
|
@@ -259,9 +259,10 @@ class MapperFactory {
|
|
|
259
259
|
let props = path.split('.');
|
|
260
260
|
let obj = this;
|
|
261
261
|
let i;
|
|
262
|
-
for (i = 0; i < props?.length - 1; i++)
|
|
263
|
-
obj = obj[props[i]];
|
|
264
|
-
|
|
262
|
+
for (i = 0; i < props?.length - 1; i++) {
|
|
263
|
+
props?.[i] && (obj = obj?.[props?.[i]]);
|
|
264
|
+
}
|
|
265
|
+
props?.[i] && obj && (obj[props?.[i]] = value);
|
|
265
266
|
}
|
|
266
267
|
}
|
|
267
268
|
exports.MapperFactory = MapperFactory;
|
package/package.json
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|