mapper-factory 2.0.3 → 3.0.1
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/README.md +0 -176
- package/dist/class.decorator.d.ts +1 -1
- package/dist/example.js +104 -120
- package/dist/functions.js +101 -193
- package/dist/index.d.ts +2 -4
- package/dist/index.js +2 -8
- 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 +219 -0
- package/package.json +12 -3
package/README.md
CHANGED
|
@@ -213,179 +213,3 @@ let emp2: User = new User().from({ firstName: "Morty", lastName: "Smith" });
|
|
|
213
213
|
|
|
214
214
|
let u = new User().from({ firstName: "Rick", lastName: "Sanchez", employees: [emp1.toMap(), emp2.toMap()], rolesToMap: ["CEO", "EMPLOYEE"] });
|
|
215
215
|
```
|
|
216
|
-
|
|
217
|
-
## Usage V1
|
|
218
|
-
|
|
219
|
-
### Mapping simple objects
|
|
220
|
-
|
|
221
|
-
Your class must extends _MapperFactory_
|
|
222
|
-
|
|
223
|
-
```
|
|
224
|
-
class User extends MapperFactory {
|
|
225
|
-
...
|
|
226
|
-
}
|
|
227
|
-
```
|
|
228
|
-
|
|
229
|
-
After that, you can use _@MapField_ decorator over single property to specify the mapping:
|
|
230
|
-
|
|
231
|
-
```
|
|
232
|
-
class User extends MapperFactory {
|
|
233
|
-
|
|
234
|
-
@MapField({
|
|
235
|
-
src: 'firstName'
|
|
236
|
-
})
|
|
237
|
-
name: string;
|
|
238
|
-
|
|
239
|
-
@MapField({
|
|
240
|
-
src: 'obj.obj[0][1]',
|
|
241
|
-
transformer: (arr) => arr.map(role => role + " TEST TRASFORMER"),
|
|
242
|
-
reverser: (arr) => arr.map(role => role.replace(" TEST TRASFORMER", "")),
|
|
243
|
-
})
|
|
244
|
-
roles?: string[];
|
|
245
|
-
|
|
246
|
-
@MapField({
|
|
247
|
-
transformer: (user) => new User(user)
|
|
248
|
-
})
|
|
249
|
-
boss: User;
|
|
250
|
-
}
|
|
251
|
-
```
|
|
252
|
-
|
|
253
|
-
Inside _@MapField_ you can use:
|
|
254
|
-
|
|
255
|
-
- **_src_**: define a string of original field name (also using a path like _"obj.obj[0][1]"_)
|
|
256
|
-
- **_transform_**: function to transform data input in _constructor_ of the class
|
|
257
|
-
- **_reverse_**: function to transform data input in _toMap_ method of the class
|
|
258
|
-
|
|
259
|
-
In this example:
|
|
260
|
-
|
|
261
|
-
```
|
|
262
|
-
class User extends MapperFactory {
|
|
263
|
-
|
|
264
|
-
id: string;
|
|
265
|
-
username: string;
|
|
266
|
-
|
|
267
|
-
@MapField({
|
|
268
|
-
src: 'firstName'
|
|
269
|
-
})
|
|
270
|
-
name: string;
|
|
271
|
-
|
|
272
|
-
@MapField({
|
|
273
|
-
src: 'lastName'
|
|
274
|
-
})
|
|
275
|
-
surname: string;
|
|
276
|
-
|
|
277
|
-
@MapField({
|
|
278
|
-
src: 'rolesToMap',
|
|
279
|
-
transformer: (arr) => arr.map(role => role + " TEST TRASFORMER"),
|
|
280
|
-
reverser: (arr) => arr.map(role => role.replace(" TEST TRASFORMER", "")),
|
|
281
|
-
})
|
|
282
|
-
roles?: string[];
|
|
283
|
-
|
|
284
|
-
@MapField({
|
|
285
|
-
transformer: (arr) => arr.map(user => new User(user))
|
|
286
|
-
})
|
|
287
|
-
employees?: User[];
|
|
288
|
-
|
|
289
|
-
@MapField({
|
|
290
|
-
transformer: (user) => new User(user)
|
|
291
|
-
})
|
|
292
|
-
boss: User;
|
|
293
|
-
}
|
|
294
|
-
```
|
|
295
|
-
|
|
296
|
-
You can define a new User **_u_**:
|
|
297
|
-
|
|
298
|
-
```
|
|
299
|
-
let emp1: User = new User({ firstName: "Summer", lastName: "Smith" });
|
|
300
|
-
let emp2: User = new User({ firstName: "Morty", lastName: "Smith" });
|
|
301
|
-
|
|
302
|
-
let u = new User({ firstName: "Rick", lastName: "Sanchez", employees: [emp1, emp2], rolesToMap: ["CEO", "EMPLOYEE"] });
|
|
303
|
-
```
|
|
304
|
-
|
|
305
|
-
In that way you can create a new JS Object User passing a JSON object. Automatically constructor use _src_ and _transformer_ to obtain the correct object you want.
|
|
306
|
-
|
|
307
|
-
In the specific case considered we have trasformed a JSON object:
|
|
308
|
-
|
|
309
|
-
```
|
|
310
|
-
{
|
|
311
|
-
firstName: 'Rick',
|
|
312
|
-
lastName: 'Sanchez',
|
|
313
|
-
employees: [
|
|
314
|
-
{ firstName: 'Summer', lastName: 'Smith' },
|
|
315
|
-
{ firstName: 'Morty', lastName: 'Smith' }
|
|
316
|
-
],
|
|
317
|
-
rolesToMap: [ 'CEO', 'EMPLOYEE' ],
|
|
318
|
-
boss: { firstName: 'Jesus', lastName: 'Christ' }
|
|
319
|
-
}
|
|
320
|
-
```
|
|
321
|
-
|
|
322
|
-
In this JS Object:
|
|
323
|
-
|
|
324
|
-
```
|
|
325
|
-
User {
|
|
326
|
-
name: 'Rick',
|
|
327
|
-
surname: 'Sanchez',
|
|
328
|
-
employees: [
|
|
329
|
-
User { name: 'Summer', surname: 'Smith' },
|
|
330
|
-
User { name: 'Morty', surname: 'Smith' }
|
|
331
|
-
],
|
|
332
|
-
roles: [ 'CEO TEST TRASFORMER', 'EMPLOYEE TEST TRASFORMER' ],
|
|
333
|
-
boss: User { name: 'Jesus', surname: 'Christ' }
|
|
334
|
-
}
|
|
335
|
-
```
|
|
336
|
-
|
|
337
|
-
Just using the constructor of _User_ class.
|
|
338
|
-
|
|
339
|
-
If you want to return to the original JSON Object you can just call **_toMap()_** method, in that way:
|
|
340
|
-
|
|
341
|
-
```
|
|
342
|
-
u.toMap()
|
|
343
|
-
```
|
|
344
|
-
|
|
345
|
-
Obtaining the original JSON Object.
|
|
346
|
-
|
|
347
|
-
You can also fill properties of an object from another (typically with same class) by using **_objToModel()_** method, in that way:
|
|
348
|
-
|
|
349
|
-
```
|
|
350
|
-
let uCopy = new User();
|
|
351
|
-
uCopy.objToModel(u);
|
|
352
|
-
```
|
|
353
|
-
|
|
354
|
-
This method is meant to be used also when you have a JSON object but in the correct format, for example:
|
|
355
|
-
|
|
356
|
-
```
|
|
357
|
-
let uCopy = new User();
|
|
358
|
-
uCopy.objToModel({ name: "Rick", surname: "Sanchez", employees: [emp1, emp2], roles: ["CEO", "EMPLOYEE"] })
|
|
359
|
-
```
|
|
360
|
-
|
|
361
|
-
Another utility method is **_empty()_** method, you can check if your object is empty or not in that way:
|
|
362
|
-
|
|
363
|
-
```
|
|
364
|
-
let user = new User();
|
|
365
|
-
user.empty(); //TRUE
|
|
366
|
-
|
|
367
|
-
user.name = "Rick";
|
|
368
|
-
user.empty(); //FALSE
|
|
369
|
-
```
|
|
370
|
-
|
|
371
|
-
It is implemented also a GET/SET method whitch use the path. Using **_get(path: string)_** and **_set(path: string, value: any)_** you can access to the property you want and then GET or SET the value:
|
|
372
|
-
|
|
373
|
-
```
|
|
374
|
-
u.set("name", "Rick TEST-SET");
|
|
375
|
-
console.log(u.get("name"));
|
|
376
|
-
```
|
|
377
|
-
|
|
378
|
-
With this mapper you can easily obtain a performant **_deep copy_** of your object doing:
|
|
379
|
-
|
|
380
|
-
```
|
|
381
|
-
let userDeepCopy = new User(u.toMap());
|
|
382
|
-
```
|
|
383
|
-
|
|
384
|
-
### Functions
|
|
385
|
-
|
|
386
|
-
You can also use the following functions:
|
|
387
|
-
|
|
388
|
-
- **_toMap(model: MapperFactory): Object_**: function to transform data input in _toMap_ method of the class
|
|
389
|
-
- **_toModel\<T extends MapperFactory>(obj: Object)_**: T: function to transform data input (JSON) in the specified model _T_
|
|
390
|
-
- **_objToModel\<T extends MapperFactory>(model: MapperFactory, obj: Object): T_**: T: function to get an instance of the object from a JSON representation without mapping it
|
|
391
|
-
- **_copy\<T extends MapperFactory>(model: MapperFactory): T_**: T: function to get an instance of the object from a JSON representation without mapping it
|
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");
|