mapper-factory 2.0.3 → 3.0.0
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.d.ts +1 -1
- package/dist/example.js +104 -120
- package/dist/functions.js +100 -192
- package/dist/index.d.ts +1 -2
- package/dist/index.js +1 -3
- package/dist/mapper-functions.d.ts +1 -1
- package/dist/mapper-functions.js +3 -3
- package/dist/mapper.d.ts +157 -13
- package/dist/mapper.js +281 -199
- package/dist/mapper.to-remove.d.ts +190 -0
- package/dist/mapper.to-remove.js +371 -0
- package/dist/test.d.ts +1 -0
- package/dist/test.js +200 -0
- package/package.json +12 -3
package/dist/example.js
CHANGED
|
@@ -9,127 +9,98 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
const _1 = require(".");
|
|
13
|
-
const class_decorator_1 = require("../src/class.decorator");
|
|
14
12
|
const field_decorator_1 = require("../src/field.decorator");
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
testConcatenation;
|
|
13
|
+
const class_decorator_1 = require("./class.decorator");
|
|
14
|
+
/*import { MapperFactory } from "../src/mapper";
|
|
15
|
+
|
|
16
|
+
class TestClass extends MapperFactory {
|
|
17
|
+
field1: string;
|
|
18
|
+
field2: string;
|
|
22
19
|
}
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
|
|
21
|
+
const testInstance = new TestClass({ field1: 'value1', field2: 'value2' });
|
|
22
|
+
console.log('Test instance:', testInstance);
|
|
23
|
+
|
|
24
|
+
class History extends MapperFactory {
|
|
25
|
+
id: string;
|
|
26
|
+
|
|
27
|
+
@MapField({
|
|
25
28
|
transformer: (arr) => " TEST TRASFORMER",
|
|
26
29
|
reverser: (arr) => " TEST REVERSER",
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
(0, field_decorator_1.MapField)({
|
|
30
|
+
})
|
|
31
|
+
name: string;
|
|
32
|
+
|
|
33
|
+
@MapField({
|
|
32
34
|
src: "control"
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
(0, field_decorator_1.MapField)({
|
|
35
|
+
})
|
|
36
|
+
testControl: string;
|
|
37
|
+
|
|
38
|
+
@MapField({
|
|
38
39
|
initialize: true,
|
|
39
|
-
transformer: (arr, obj) => { return [obj.monday, obj.tuesday]
|
|
40
|
+
transformer: (arr, obj) => { return [obj.monday, obj.tuesday] },
|
|
40
41
|
reverser: (arr) => {
|
|
41
|
-
return { monday: arr && arr[0], tuesday: arr && arr[1] }
|
|
42
|
+
return { monday: arr && arr[0], tuesday: arr && arr[1] }
|
|
42
43
|
},
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
(0, field_decorator_1.MapField)({
|
|
44
|
+
})
|
|
45
|
+
daysActive: string[];
|
|
46
|
+
|
|
47
|
+
@MapField({
|
|
48
48
|
src: "test.concatenation"
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
], History.prototype, "testConcatenation", void 0);
|
|
52
|
-
class User extends mapper_1.MapperFactory {
|
|
53
|
-
id;
|
|
54
|
-
username;
|
|
55
|
-
name;
|
|
56
|
-
surname;
|
|
57
|
-
roles;
|
|
58
|
-
employees;
|
|
59
|
-
boss;
|
|
60
|
-
histories;
|
|
49
|
+
})
|
|
50
|
+
testConcatenation: string;
|
|
61
51
|
}
|
|
62
|
-
|
|
63
|
-
|
|
52
|
+
|
|
53
|
+
class User extends MapperFactory {
|
|
54
|
+
@MapField({
|
|
64
55
|
src: 'firstName'
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
(0, field_decorator_1.MapField)({
|
|
56
|
+
})
|
|
57
|
+
name: string;
|
|
58
|
+
|
|
59
|
+
@MapField({
|
|
70
60
|
src: 'lastName'
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
__metadata("design:type", Array)
|
|
81
|
-
], User.prototype, "roles", void 0);
|
|
82
|
-
__decorate([
|
|
83
|
-
(0, field_decorator_1.MapField)({
|
|
84
|
-
transformer: (arr) => arr?.map(user => new User(user))
|
|
85
|
-
}),
|
|
86
|
-
__metadata("design:type", Array)
|
|
87
|
-
], User.prototype, "employees", void 0);
|
|
88
|
-
__decorate([
|
|
89
|
-
(0, field_decorator_1.MapField)({
|
|
90
|
-
transformer: (user) => new User(user)
|
|
91
|
-
}),
|
|
92
|
-
__metadata("design:type", User)
|
|
93
|
-
], User.prototype, "boss", void 0);
|
|
94
|
-
__decorate([
|
|
95
|
-
(0, field_decorator_1.MapField)({
|
|
96
|
-
transformer: histories => histories?.map(hst => new History(hst)),
|
|
97
|
-
reverser: histories => histories?.map(hst => hst.toMap()),
|
|
98
|
-
}),
|
|
99
|
-
__metadata("design:type", Array)
|
|
100
|
-
], User.prototype, "histories", void 0);
|
|
101
|
-
let emp1 = new User({ firstName: "Summer", lastName: "Smith" });
|
|
102
|
-
let emp2 = new User({ firstName: "Morty", lastName: "Smith" });
|
|
103
|
-
let JSONObject = { firstName: "Rick", lastName: "Sanchez", employees: [emp1.toMap(), emp2.toMap()], rolesToMap: ["CEO", "EMPLOYEE"], boss: { firstName: "Nello", lastName: "Stanco" } };
|
|
61
|
+
})
|
|
62
|
+
surname: string;
|
|
63
|
+
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
//let emp1: User = new User({ firstName: "Summer", lastName: "Smith" });
|
|
67
|
+
//let emp2: User = new User({ firstName: "Morty", lastName: "Smith" });
|
|
68
|
+
//let JSONObject = { firstName: "Rick", lastName: "Sanchez", employees: [emp1.toMap(), emp2.toMap()], rolesToMap: ["CEO", "EMPLOYEE"], boss: { firstName: "Nello", lastName: "Stanco" } };
|
|
69
|
+
|
|
104
70
|
//TEST constructor
|
|
105
|
-
let u = new User(JSONObject);
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
console.log(
|
|
109
|
-
|
|
71
|
+
//let u = new User(JSONObject);
|
|
72
|
+
|
|
73
|
+
//const passedConstructorTest: boolean = u.name == JSONObject.firstName && u.surname == JSONObject.lastName && u.employees?.map(emp => emp.name == emp1.name) && u.roles?.map(role => role == "CEO") && u.boss.name == "Nello" && u.boss.surname == "Stanco";
|
|
74
|
+
//console.log("TEST constructor", passedConstructorTest ? '✅' : '❌');
|
|
75
|
+
|
|
110
76
|
//TEST objToModel method with JS Object
|
|
111
77
|
let u1 = new User();
|
|
112
78
|
console.log("\nTEST objToModel method with JS Object");
|
|
113
79
|
console.log(u1.objToModel(u));
|
|
114
80
|
console.log("\n\n");
|
|
81
|
+
|
|
115
82
|
//TEST objToModel method with JSON Object
|
|
116
83
|
console.log("\nTEST objToModel method with JSON Object");
|
|
117
84
|
console.log(u.objToModel({ name: "Rick TEST-objToModel", roles: ["CEO TEST-objToModel", "EMPLOYEE TEST-objToModel"] }));
|
|
118
85
|
console.log("\n\n");
|
|
86
|
+
|
|
119
87
|
//TEST toMap method
|
|
120
88
|
console.log("\nTEST toMap method");
|
|
121
89
|
console.log(u.toMap());
|
|
122
90
|
console.log("\n\n");
|
|
91
|
+
|
|
123
92
|
//TEST empty method
|
|
124
93
|
console.log("\nTEST empty method");
|
|
125
94
|
console.log(u.empty());
|
|
126
95
|
console.log("\n\n");
|
|
96
|
+
|
|
127
97
|
//TEST get AND set method
|
|
128
98
|
u.set("employees[1].name", "name editato");
|
|
129
99
|
console.log("\nTEST get AND set method");
|
|
130
100
|
console.log(u);
|
|
131
101
|
console.log(u.get("employees[1].name"));
|
|
132
102
|
console.log("\n\n");
|
|
103
|
+
|
|
133
104
|
//TEST deep copy
|
|
134
105
|
console.log("\nTEST deep copy");
|
|
135
106
|
let dpCopy = new User(u.toMap());
|
|
@@ -137,6 +108,7 @@ dpCopy.name = "nome dpCopy";
|
|
|
137
108
|
console.log(u);
|
|
138
109
|
console.log(dpCopy);
|
|
139
110
|
console.log("\n\n");
|
|
111
|
+
|
|
140
112
|
//TEST trasformer/reverser
|
|
141
113
|
console.log("\nTEST reverser");
|
|
142
114
|
let h1 = new History({ name: "h1" });
|
|
@@ -145,29 +117,33 @@ u.histories = [h1, h2];
|
|
|
145
117
|
console.log(u);
|
|
146
118
|
console.log(u.toMap());
|
|
147
119
|
console.log("\n\n");
|
|
120
|
+
|
|
148
121
|
//TEST ref
|
|
149
122
|
console.log("\nTEST REF");
|
|
150
123
|
let hTest = new History({ monday: "0", tuesday: "1", control: "control" });
|
|
151
|
-
console.log(hTest)
|
|
124
|
+
console.log(hTest)
|
|
152
125
|
hTest.daysActive = ['1', '0'];
|
|
153
126
|
console.log(hTest.toMap());
|
|
154
127
|
console.log("\n\n");
|
|
128
|
+
|
|
155
129
|
//TEST concat with point
|
|
156
130
|
console.log("\nTEST CONCAT W POINT");
|
|
157
131
|
let hTest2 = new History({ test: { concatenation: "resolve " }, control: "control" });
|
|
158
|
-
console.log(hTest2)
|
|
132
|
+
console.log(hTest2)
|
|
159
133
|
console.log(hTest2.toMap());
|
|
160
134
|
console.log("\n\n");
|
|
135
|
+
|
|
161
136
|
//TEST FUNC MAPPER
|
|
162
137
|
console.log("\nTEST FUNC MAPPER");
|
|
163
138
|
console.log(emp1);
|
|
164
|
-
console.log(
|
|
165
|
-
const testEmp =
|
|
139
|
+
console.log(toMap(emp1));
|
|
140
|
+
const testEmp = toModel<User>(toMap(emp1));
|
|
166
141
|
console.log("USER MODEL: ", testEmp);
|
|
167
|
-
console.log(
|
|
142
|
+
console.log(objToModel(emp1, { name: "test", surname: "prova" }));
|
|
168
143
|
console.log("\n\n");
|
|
144
|
+
*/
|
|
169
145
|
//TEST NEW MapperFactory
|
|
170
|
-
console.log("\
|
|
146
|
+
console.log("\nNew MapperFactory");
|
|
171
147
|
let Test = class Test {
|
|
172
148
|
a;
|
|
173
149
|
};
|
|
@@ -176,51 +152,59 @@ __decorate([
|
|
|
176
152
|
src: 'b',
|
|
177
153
|
transformer: value => 'test transformer',
|
|
178
154
|
reverser: value => ({ a: 'test reverser' }),
|
|
179
|
-
initialize: true,
|
|
180
155
|
}),
|
|
181
156
|
__metadata("design:type", String)
|
|
182
157
|
], Test.prototype, "a", void 0);
|
|
183
158
|
Test = __decorate([
|
|
184
159
|
(0, class_decorator_1.MapClass)()
|
|
185
160
|
], Test);
|
|
186
|
-
const
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
console.log("
|
|
193
|
-
|
|
194
|
-
console.log("TO
|
|
195
|
-
|
|
196
|
-
console.log("COPY
|
|
197
|
-
console.log("\n
|
|
161
|
+
const testEmpty = new Test().from();
|
|
162
|
+
const testFilled = new Test().from({ b: 'filled' });
|
|
163
|
+
const checkTest1 = (testEmpty && testEmpty.empty() == true && testEmpty.filled() == false);
|
|
164
|
+
const checkTest2 = (testFilled && testFilled.empty() == false && testFilled.filled() == true);
|
|
165
|
+
console.log("TEST EMPTY/FILLED", (checkTest1 && checkTest2) ? '✅' : '❌');
|
|
166
|
+
const model3 = new Test().toModel({ a: 'test to model' });
|
|
167
|
+
console.log("TEST TO MODEL", (model3.a == 'test to model') ? '✅' : '❌');
|
|
168
|
+
const model4 = model3.toMap();
|
|
169
|
+
console.log("TEST TO MAP", (model4.b.a == 'test reverser') ? '✅' : '❌');
|
|
170
|
+
const model5 = model3.copy();
|
|
171
|
+
console.log("TEST COPY", (Object.keys(model5).every(k => model5[k] == model3[k])) ? '✅' : '❌');
|
|
172
|
+
console.log("\n");
|
|
198
173
|
//TEST TestFlag with initialize
|
|
199
|
-
console.log("
|
|
174
|
+
console.log("TestFlag with initialize");
|
|
200
175
|
let TestFlag = class TestFlag {
|
|
201
176
|
flTest;
|
|
177
|
+
a;
|
|
202
178
|
};
|
|
203
179
|
__decorate([
|
|
204
180
|
(0, field_decorator_1.MapField)({
|
|
205
|
-
transformer: (num) =>
|
|
206
|
-
|
|
207
|
-
return num == '1';
|
|
208
|
-
},
|
|
209
|
-
reverser: bool => {
|
|
210
|
-
console.log("sto trasformando da bool a num");
|
|
211
|
-
return bool ? '1' : '0';
|
|
212
|
-
},
|
|
181
|
+
transformer: (num) => num == '1',
|
|
182
|
+
reverser: bool => bool ? '1' : '0',
|
|
213
183
|
initialize: true,
|
|
214
184
|
}),
|
|
215
|
-
__metadata("design:type",
|
|
185
|
+
__metadata("design:type", Boolean)
|
|
216
186
|
], TestFlag.prototype, "flTest", void 0);
|
|
187
|
+
__decorate([
|
|
188
|
+
(0, field_decorator_1.MapField)({
|
|
189
|
+
src: 'b',
|
|
190
|
+
transformer: value => 'test transformer',
|
|
191
|
+
reverser: value => ({ a: 'test reverser' }),
|
|
192
|
+
initialize: true,
|
|
193
|
+
}),
|
|
194
|
+
__metadata("design:type", String)
|
|
195
|
+
], TestFlag.prototype, "a", void 0);
|
|
217
196
|
TestFlag = __decorate([
|
|
218
197
|
(0, class_decorator_1.MapClass)()
|
|
219
198
|
], TestFlag);
|
|
220
|
-
const
|
|
221
|
-
console.log("TEST
|
|
222
|
-
|
|
199
|
+
const testFlagInitialize = new TestFlag().from();
|
|
200
|
+
console.log("TEST INITIALIZE", (testFlagInitialize && testFlagInitialize.a == 'test transformer') ? '✅' : '❌');
|
|
201
|
+
const testFlag0 = new TestFlag().from();
|
|
202
|
+
const testFlag0Map = testFlag0.toMap();
|
|
203
|
+
console.log("TEST FLAG0", ((testFlag0.flTest === false) && testFlag0Map.flTest == '0') ? '✅' : '❌');
|
|
223
204
|
const testFlag1 = new TestFlag().from({ flTest: '1' });
|
|
224
|
-
|
|
225
|
-
console.log("
|
|
226
|
-
|
|
205
|
+
const testFlag1Map = testFlag1.toMap();
|
|
206
|
+
console.log("TEST FLAG1", (testFlag1.flTest && testFlag1Map.flTest == '1') ? '✅' : '❌');
|
|
207
|
+
const testFlag2 = new TestFlag().from({ flTest: '0' });
|
|
208
|
+
const testFlag2Map = testFlag2.toMap();
|
|
209
|
+
console.log("TEST FLAG2", (!testFlag2.flTest && testFlag2Map.flTest == '0') ? '✅' : '❌');
|
|
210
|
+
console.log("\n");
|