mapper-factory 3.1.3 → 4.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.js +10 -13
- package/dist/field-decorators/array.decorator.d.ts +3 -1
- package/dist/field-decorators/array.decorator.js +4 -6
- package/dist/field-decorators/date.decorator.d.ts +3 -1
- package/dist/field-decorators/date.decorator.js +4 -6
- package/dist/field-decorators/field.decorator.js +15 -25
- package/dist/field-decorators/object.decorator.d.ts +3 -1
- package/dist/field-decorators/object.decorator.js +4 -6
- package/dist/functions.js +11 -21
- package/dist/index.js +6 -13
- package/dist/test.js +34 -34
- package/dist/types.js +1 -2
- package/package.json +9 -2
- package/dist/example.d.ts +0 -1
- package/dist/example.js +0 -210
- package/dist/examples/example.d.ts +0 -1
- package/dist/examples/example.js +0 -135
- package/dist/field.decorator.d.ts +0 -22
- package/dist/field.decorator.js +0 -54
- package/dist/mapper-functions.d.ts +0 -5
- package/dist/mapper-functions.js +0 -20
- package/dist/mapper.d.ts +0 -190
- package/dist/mapper.js +0 -371
- package/dist/mapper.to-remove.d.ts +0 -190
- package/dist/mapper.to-remove.js +0 -371
- package/dist/src/field.decorator.d.ts +0 -22
- package/dist/src/field.decorator.js +0 -54
- package/dist/src/index.d.ts +0 -10
- package/dist/src/index.js +0 -13
- package/dist/src/mapper.d.ts +0 -46
- package/dist/src/mapper.js +0 -286
- package/dist/src/types.d.ts +0 -6
- package/dist/src/types.js +0 -2
package/dist/class.decorator.js
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.MapClass = MapClass;
|
|
4
|
-
const functions_1 = require("./functions");
|
|
5
|
-
function MapClass() {
|
|
1
|
+
import { copy, empty, filled, from, get, objToModel, set, toMap } from "./functions";
|
|
2
|
+
export function MapClass() {
|
|
6
3
|
return function (constructor) {
|
|
7
|
-
constructor.prototype.from =
|
|
8
|
-
constructor.prototype.toMap =
|
|
9
|
-
constructor.prototype.toModel =
|
|
10
|
-
constructor.prototype.empty =
|
|
11
|
-
constructor.prototype.filled =
|
|
12
|
-
constructor.prototype.get =
|
|
13
|
-
constructor.prototype.set =
|
|
14
|
-
constructor.prototype.copy =
|
|
4
|
+
constructor.prototype.from = from;
|
|
5
|
+
constructor.prototype.toMap = toMap;
|
|
6
|
+
constructor.prototype.toModel = objToModel;
|
|
7
|
+
constructor.prototype.empty = empty;
|
|
8
|
+
constructor.prototype.filled = filled;
|
|
9
|
+
constructor.prototype.get = get;
|
|
10
|
+
constructor.prototype.set = set;
|
|
11
|
+
constructor.prototype.copy = copy;
|
|
15
12
|
};
|
|
16
13
|
}
|
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
import { MapInterface } from "../class.decorator";
|
|
2
|
-
export declare function ArrayField<T extends MapInterface<T>>(clsFactory: new () => T
|
|
2
|
+
export declare function ArrayField<T extends MapInterface<T>>(clsFactory: new () => T, opt?: {
|
|
3
|
+
src?: string;
|
|
4
|
+
}): PropertyDecorator;
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.ArrayField = ArrayField;
|
|
4
|
-
const field_decorator_1 = require("./field.decorator");
|
|
5
|
-
function ArrayField(clsFactory) {
|
|
1
|
+
import { MapField } from "./field.decorator";
|
|
2
|
+
export function ArrayField(clsFactory, opt) {
|
|
6
3
|
const Ctor = clsFactory;
|
|
7
|
-
return
|
|
4
|
+
return MapField({
|
|
5
|
+
src: opt?.src,
|
|
8
6
|
transformer: (arr) => Array.isArray(arr)
|
|
9
7
|
? arr.map((item) => new Ctor().from(item))
|
|
10
8
|
: [],
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
function DateField() {
|
|
6
|
-
return (0, field_decorator_1.MapField)({
|
|
1
|
+
import { MapField } from "./field.decorator";
|
|
2
|
+
export function DateField(opt) {
|
|
3
|
+
return MapField({
|
|
4
|
+
src: opt?.src,
|
|
7
5
|
transformer: (dateISO) => dateISO ? new Date(dateISO) : null,
|
|
8
6
|
reverser: (date) => date?.toISOString() ?? null,
|
|
9
7
|
});
|
|
@@ -1,22 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
exports.isClass = isClass;
|
|
5
|
-
exports.getPrototype = getPrototype;
|
|
6
|
-
require("reflect-metadata");
|
|
7
|
-
exports.MAP_FIELD = Symbol('MAP_FIELD');
|
|
8
|
-
function isClass(func) {
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
export const MAP_FIELD = Symbol('MAP_FIELD');
|
|
3
|
+
export function isClass(func) {
|
|
9
4
|
return (typeof func === 'function' &&
|
|
10
5
|
/^class\s/.test(Function.prototype.toString.call(func)));
|
|
11
6
|
}
|
|
12
|
-
function getPrototype(target) {
|
|
7
|
+
export function getPrototype(target) {
|
|
13
8
|
return isClass(target) || !target?.prototype ? !target?.constructor ? target : target?.constructor : target?.prototype;
|
|
14
9
|
}
|
|
15
|
-
const MapField = ({ transformer, reverser, src, initialize = false, } = {}) => {
|
|
10
|
+
export const MapField = ({ transformer, reverser, src, initialize = false, } = {}) => {
|
|
16
11
|
return (target, property) => {
|
|
17
12
|
const classConstructor = target.constructor;
|
|
18
13
|
const propertyName = property.toString();
|
|
19
|
-
const metadata = Reflect.getMetadata(
|
|
14
|
+
const metadata = Reflect.getMetadata(MAP_FIELD, classConstructor) || {};
|
|
20
15
|
// create new object reference to avoid this issue: https://github.com/rbuckton/reflect-metadata/issues/62
|
|
21
16
|
const newMetadata = { ...metadata };
|
|
22
17
|
const previousValues = metadata[propertyName];
|
|
@@ -27,28 +22,23 @@ const MapField = ({ transformer, reverser, src, initialize = false, } = {}) => {
|
|
|
27
22
|
transformer,
|
|
28
23
|
reverser,
|
|
29
24
|
};
|
|
30
|
-
Reflect.defineMetadata(
|
|
25
|
+
Reflect.defineMetadata(MAP_FIELD, newMetadata, classConstructor);
|
|
31
26
|
};
|
|
32
27
|
};
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return Reflect.getMetadata(exports.MAP_FIELD, getPrototype(target));
|
|
28
|
+
export const getMapFieldMetadataList = (target) => {
|
|
29
|
+
return Reflect.getMetadata(MAP_FIELD, getPrototype(target));
|
|
36
30
|
};
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
return Reflect.hasMetadata(exports.MAP_FIELD, getPrototype(target));
|
|
31
|
+
export const hasMapFieldMetadataList = (target) => {
|
|
32
|
+
return Reflect.hasMetadata(MAP_FIELD, getPrototype(target));
|
|
40
33
|
};
|
|
41
|
-
|
|
42
|
-
const
|
|
43
|
-
const metadata = (0, exports.getMapFieldMetadataList)(target);
|
|
34
|
+
export const getMapFieldMetadata = (target, propertyName) => {
|
|
35
|
+
const metadata = getMapFieldMetadataList(target);
|
|
44
36
|
const name = propertyName.toString();
|
|
45
37
|
if (!metadata || !metadata[name])
|
|
46
38
|
return undefined;
|
|
47
39
|
return metadata[name];
|
|
48
40
|
};
|
|
49
|
-
|
|
50
|
-
const
|
|
51
|
-
const metadata = Reflect.getMetadata(exports.MAP_FIELD, getPrototype(target));
|
|
41
|
+
export const hasMapFieldMetadata = (target, propertyName) => {
|
|
42
|
+
const metadata = Reflect.getMetadata(MAP_FIELD, getPrototype(target));
|
|
52
43
|
return metadata && !!metadata[propertyName];
|
|
53
44
|
};
|
|
54
|
-
exports.hasMapFieldMetadata = hasMapFieldMetadata;
|
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
import { MapInterface } from "../class.decorator";
|
|
2
|
-
export declare function ObjectField<T extends MapInterface<T>>(clsFactory: new () => T
|
|
2
|
+
export declare function ObjectField<T extends MapInterface<T>>(clsFactory: new () => T, opt?: {
|
|
3
|
+
src?: string;
|
|
4
|
+
}): PropertyDecorator;
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.ObjectField = ObjectField;
|
|
4
|
-
const field_decorator_1 = require("./field.decorator");
|
|
5
|
-
function ObjectField(clsFactory) {
|
|
1
|
+
import { MapField } from "./field.decorator";
|
|
2
|
+
export function ObjectField(clsFactory, opt) {
|
|
6
3
|
const Ctor = clsFactory;
|
|
7
|
-
return
|
|
4
|
+
return MapField({
|
|
5
|
+
src: opt?.src,
|
|
8
6
|
transformer: (obj) => (obj ? new Ctor().from(obj) : null),
|
|
9
7
|
reverser: (obj) => obj?.toMap?.() ?? null,
|
|
10
8
|
});
|
package/dist/functions.js
CHANGED
|
@@ -1,21 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.toMap = toMap;
|
|
4
|
-
exports.objToModel = objToModel;
|
|
5
|
-
exports.empty = empty;
|
|
6
|
-
exports.filled = filled;
|
|
7
|
-
exports.get = get;
|
|
8
|
-
exports.set = set;
|
|
9
|
-
exports.copy = copy;
|
|
10
|
-
exports.from = from;
|
|
11
|
-
const field_decorator_1 = require("./field-decorators/field.decorator");
|
|
1
|
+
import { getMapFieldMetadataList } from "./field-decorators/field.decorator";
|
|
12
2
|
/**
|
|
13
3
|
* Convert the instance of this class to JSON Object.
|
|
14
4
|
*
|
|
15
5
|
* @returns JSON object mapped considering metadata "src" and "reverser"
|
|
16
6
|
*/
|
|
17
|
-
function toMap() {
|
|
18
|
-
const metadataList =
|
|
7
|
+
export function toMap() {
|
|
8
|
+
const metadataList = getMapFieldMetadataList(this);
|
|
19
9
|
let obj = {};
|
|
20
10
|
const processProperty = (objCopy, propsStereoid, value, reverser) => {
|
|
21
11
|
let lastIndex;
|
|
@@ -86,7 +76,7 @@ function toMap() {
|
|
|
86
76
|
* @param obj JSON Object
|
|
87
77
|
* @returns Instance of this class
|
|
88
78
|
*/
|
|
89
|
-
function objToModel(obj) {
|
|
79
|
+
export function objToModel(obj) {
|
|
90
80
|
if (!obj)
|
|
91
81
|
return this;
|
|
92
82
|
Object.keys(obj).forEach((propertyName) => {
|
|
@@ -102,7 +92,7 @@ function objToModel(obj) {
|
|
|
102
92
|
*
|
|
103
93
|
* @returns true or false
|
|
104
94
|
*/
|
|
105
|
-
function empty() {
|
|
95
|
+
export function empty() {
|
|
106
96
|
return !Object.keys(this).some((propertyName) => this[propertyName] !== undefined && this[propertyName] !== null);
|
|
107
97
|
}
|
|
108
98
|
/**
|
|
@@ -110,7 +100,7 @@ function empty() {
|
|
|
110
100
|
*
|
|
111
101
|
* @returns true or false
|
|
112
102
|
*/
|
|
113
|
-
function filled() {
|
|
103
|
+
export function filled() {
|
|
114
104
|
return (Object.keys(this).length > 0 &&
|
|
115
105
|
Object.keys(this).every((propertyName) => this[propertyName] !== undefined && this[propertyName] !== null));
|
|
116
106
|
}
|
|
@@ -120,7 +110,7 @@ function filled() {
|
|
|
120
110
|
* @param path String path
|
|
121
111
|
* @returns Value of the property
|
|
122
112
|
*/
|
|
123
|
-
function get(path) {
|
|
113
|
+
export function get(path) {
|
|
124
114
|
const props = path.replace(/\[(\w+)\]/g, ".$1").split(".");
|
|
125
115
|
return props.reduce((acc, prop) => acc && acc[prop], this);
|
|
126
116
|
}
|
|
@@ -130,7 +120,7 @@ function get(path) {
|
|
|
130
120
|
* @param path String path
|
|
131
121
|
* @param value Value of the property
|
|
132
122
|
*/
|
|
133
|
-
function set(path, value) {
|
|
123
|
+
export function set(path, value) {
|
|
134
124
|
const props = path.replace(/\[(\w+)\]/g, ".$1").split(".");
|
|
135
125
|
let obj = this;
|
|
136
126
|
props.slice(0, -1).forEach((prop) => {
|
|
@@ -143,7 +133,7 @@ function set(path, value) {
|
|
|
143
133
|
/**
|
|
144
134
|
* Deep copy of the object caller
|
|
145
135
|
*/
|
|
146
|
-
function copy() {
|
|
136
|
+
export function copy() {
|
|
147
137
|
return this.from(this.toMap());
|
|
148
138
|
}
|
|
149
139
|
/**
|
|
@@ -151,8 +141,8 @@ function copy() {
|
|
|
151
141
|
*
|
|
152
142
|
* @param object object to be mapped considering metadata "src", "transformer" and "reverser"
|
|
153
143
|
*/
|
|
154
|
-
function from(object) {
|
|
155
|
-
const metadataList =
|
|
144
|
+
export function from(object) {
|
|
145
|
+
const metadataList = getMapFieldMetadataList(this);
|
|
156
146
|
const processProperty = (objCopy, propsStereoid) => {
|
|
157
147
|
for (let i = 0; i < propsStereoid.length; i++) {
|
|
158
148
|
const prop = propsStereoid[i];
|
package/dist/index.js
CHANGED
|
@@ -1,16 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
Object.defineProperty(exports, "MapField", { enumerable: true, get: function () { return field_decorator_1.MapField; } });
|
|
8
|
-
const array_decorator_1 = require("./field-decorators/array.decorator");
|
|
9
|
-
Object.defineProperty(exports, "ArrayField", { enumerable: true, get: function () { return array_decorator_1.ArrayField; } });
|
|
10
|
-
const date_decorator_1 = require("./field-decorators/date.decorator");
|
|
11
|
-
Object.defineProperty(exports, "DateField", { enumerable: true, get: function () { return date_decorator_1.DateField; } });
|
|
12
|
-
const object_decorator_1 = require("./field-decorators/object.decorator");
|
|
13
|
-
Object.defineProperty(exports, "ObjectField", { enumerable: true, get: function () { return object_decorator_1.ObjectField; } });
|
|
1
|
+
import { MapClass } from "./class.decorator";
|
|
2
|
+
import { MapField } from "./field-decorators/field.decorator";
|
|
3
|
+
import { ArrayField } from "./field-decorators/array.decorator";
|
|
4
|
+
import { DateField } from "./field-decorators/date.decorator";
|
|
5
|
+
import { ObjectField } from "./field-decorators/object.decorator";
|
|
6
|
+
export { MapClass, MapField, DateField, ArrayField, ObjectField, };
|
|
14
7
|
/**
|
|
15
8
|
* npx tsc
|
|
16
9
|
* npx ts-node src/test.ts
|
package/dist/test.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
2
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
3
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -8,12 +7,11 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
9
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const object_decorator_1 = require("./field-decorators/object.decorator");
|
|
10
|
+
import { MapClass } from "./class.decorator";
|
|
11
|
+
import { ArrayField } from "./field-decorators/array.decorator";
|
|
12
|
+
import { DateField } from "./field-decorators/date.decorator";
|
|
13
|
+
import { MapField } from "./field-decorators/field.decorator";
|
|
14
|
+
import { ObjectField } from "./field-decorators/object.decorator";
|
|
17
15
|
//MAPPER FACTORY - TEST
|
|
18
16
|
console.log("\nMAPPER FACTORY - TEST");
|
|
19
17
|
console.log("\n");
|
|
@@ -25,20 +23,20 @@ let History = class History {
|
|
|
25
23
|
testConcatenation;
|
|
26
24
|
};
|
|
27
25
|
__decorate([
|
|
28
|
-
|
|
26
|
+
MapField({
|
|
29
27
|
transformer: (arr) => " TEST TRASFORMER",
|
|
30
28
|
reverser: (arr) => " TEST REVERSER",
|
|
31
29
|
}),
|
|
32
30
|
__metadata("design:type", String)
|
|
33
31
|
], History.prototype, "name", void 0);
|
|
34
32
|
__decorate([
|
|
35
|
-
|
|
33
|
+
MapField({
|
|
36
34
|
src: "control",
|
|
37
35
|
}),
|
|
38
36
|
__metadata("design:type", String)
|
|
39
37
|
], History.prototype, "testControl", void 0);
|
|
40
38
|
__decorate([
|
|
41
|
-
|
|
39
|
+
MapField({
|
|
42
40
|
initialize: true,
|
|
43
41
|
transformer: (arr, obj) => {
|
|
44
42
|
return [obj.monday, obj.tuesday];
|
|
@@ -50,13 +48,13 @@ __decorate([
|
|
|
50
48
|
__metadata("design:type", Array)
|
|
51
49
|
], History.prototype, "daysActive", void 0);
|
|
52
50
|
__decorate([
|
|
53
|
-
|
|
51
|
+
MapField({
|
|
54
52
|
src: "test.concatenation",
|
|
55
53
|
}),
|
|
56
54
|
__metadata("design:type", String)
|
|
57
55
|
], History.prototype, "testConcatenation", void 0);
|
|
58
56
|
History = __decorate([
|
|
59
|
-
|
|
57
|
+
MapClass()
|
|
60
58
|
], History);
|
|
61
59
|
let User = class User {
|
|
62
60
|
id;
|
|
@@ -69,19 +67,19 @@ let User = class User {
|
|
|
69
67
|
histories;
|
|
70
68
|
};
|
|
71
69
|
__decorate([
|
|
72
|
-
|
|
70
|
+
MapField({
|
|
73
71
|
src: "firstName",
|
|
74
72
|
}),
|
|
75
73
|
__metadata("design:type", String)
|
|
76
74
|
], User.prototype, "name", void 0);
|
|
77
75
|
__decorate([
|
|
78
|
-
|
|
76
|
+
MapField({
|
|
79
77
|
src: "lastName",
|
|
80
78
|
}),
|
|
81
79
|
__metadata("design:type", String)
|
|
82
80
|
], User.prototype, "surname", void 0);
|
|
83
81
|
__decorate([
|
|
84
|
-
|
|
82
|
+
MapField({
|
|
85
83
|
src: "rolesToMap",
|
|
86
84
|
transformer: (arr) => arr?.map((role) => role + " TEST TRASFORMER"),
|
|
87
85
|
reverser: (arr) => arr?.map((role) => role.replace(" TEST TRASFORMER", "")),
|
|
@@ -89,26 +87,26 @@ __decorate([
|
|
|
89
87
|
__metadata("design:type", Array)
|
|
90
88
|
], User.prototype, "roles", void 0);
|
|
91
89
|
__decorate([
|
|
92
|
-
|
|
90
|
+
MapField({
|
|
93
91
|
transformer: (arr) => arr?.map((user) => new User().from(user)),
|
|
94
92
|
}),
|
|
95
93
|
__metadata("design:type", Array)
|
|
96
94
|
], User.prototype, "employees", void 0);
|
|
97
95
|
__decorate([
|
|
98
|
-
|
|
96
|
+
MapField({
|
|
99
97
|
transformer: (user) => new User().from(user),
|
|
100
98
|
}),
|
|
101
99
|
__metadata("design:type", User)
|
|
102
100
|
], User.prototype, "boss", void 0);
|
|
103
101
|
__decorate([
|
|
104
|
-
|
|
102
|
+
MapField({
|
|
105
103
|
transformer: (histories) => histories?.map((hst) => new History().from(hst)),
|
|
106
104
|
reverser: (histories) => histories?.map((hst) => hst.toMap()),
|
|
107
105
|
}),
|
|
108
106
|
__metadata("design:type", Array)
|
|
109
107
|
], User.prototype, "histories", void 0);
|
|
110
108
|
User = __decorate([
|
|
111
|
-
|
|
109
|
+
MapClass()
|
|
112
110
|
], User);
|
|
113
111
|
const emp1 = new User().from({ firstName: "Summer", lastName: "Smith" });
|
|
114
112
|
const emp2 = new User().from({ firstName: "Morty", lastName: "Smith" });
|
|
@@ -172,7 +170,7 @@ let Test = class Test {
|
|
|
172
170
|
a;
|
|
173
171
|
};
|
|
174
172
|
__decorate([
|
|
175
|
-
|
|
173
|
+
MapField({
|
|
176
174
|
src: "b",
|
|
177
175
|
transformer: (value) => "test transformer",
|
|
178
176
|
reverser: (value) => ({ a: "test reverser" }),
|
|
@@ -180,7 +178,7 @@ __decorate([
|
|
|
180
178
|
__metadata("design:type", String)
|
|
181
179
|
], Test.prototype, "a", void 0);
|
|
182
180
|
Test = __decorate([
|
|
183
|
-
|
|
181
|
+
MapClass()
|
|
184
182
|
], Test);
|
|
185
183
|
const testEmpty = new Test().from();
|
|
186
184
|
const testFilled = new Test().from({ b: "filled" });
|
|
@@ -198,7 +196,7 @@ let TestFlag = class TestFlag {
|
|
|
198
196
|
a;
|
|
199
197
|
};
|
|
200
198
|
__decorate([
|
|
201
|
-
|
|
199
|
+
MapField({
|
|
202
200
|
transformer: (num) => num == "1",
|
|
203
201
|
reverser: (bool) => (bool ? "1" : "0"),
|
|
204
202
|
initialize: true,
|
|
@@ -206,7 +204,7 @@ __decorate([
|
|
|
206
204
|
__metadata("design:type", Boolean)
|
|
207
205
|
], TestFlag.prototype, "flTest", void 0);
|
|
208
206
|
__decorate([
|
|
209
|
-
|
|
207
|
+
MapField({
|
|
210
208
|
src: "b",
|
|
211
209
|
transformer: (value) => "test transformer",
|
|
212
210
|
reverser: (value) => ({ a: "test reverser" }),
|
|
@@ -215,7 +213,7 @@ __decorate([
|
|
|
215
213
|
__metadata("design:type", String)
|
|
216
214
|
], TestFlag.prototype, "a", void 0);
|
|
217
215
|
TestFlag = __decorate([
|
|
218
|
-
|
|
216
|
+
MapClass()
|
|
219
217
|
], TestFlag);
|
|
220
218
|
const testFlagInitialize = new TestFlag().from();
|
|
221
219
|
console.log("TEST INITIALIZE", testFlagInitialize && testFlagInitialize.a == "test transformer" ? "✅" : "❌");
|
|
@@ -233,7 +231,7 @@ let TestWithoutMapField = class TestWithoutMapField {
|
|
|
233
231
|
name;
|
|
234
232
|
};
|
|
235
233
|
TestWithoutMapField = __decorate([
|
|
236
|
-
|
|
234
|
+
MapClass()
|
|
237
235
|
], TestWithoutMapField);
|
|
238
236
|
const JSONObject2 = {
|
|
239
237
|
id: "1",
|
|
@@ -246,11 +244,11 @@ let ObjDecorator = class ObjDecorator {
|
|
|
246
244
|
testObject;
|
|
247
245
|
};
|
|
248
246
|
__decorate([
|
|
249
|
-
|
|
247
|
+
ObjectField(ObjDecorator),
|
|
250
248
|
__metadata("design:type", ObjDecorator)
|
|
251
249
|
], ObjDecorator.prototype, "testObject", void 0);
|
|
252
250
|
ObjDecorator = __decorate([
|
|
253
|
-
|
|
251
|
+
MapClass()
|
|
254
252
|
], ObjDecorator);
|
|
255
253
|
let TestDecorators = class TestDecorators {
|
|
256
254
|
date;
|
|
@@ -258,22 +256,22 @@ let TestDecorators = class TestDecorators {
|
|
|
258
256
|
obj;
|
|
259
257
|
};
|
|
260
258
|
__decorate([
|
|
261
|
-
(
|
|
259
|
+
DateField({ src: "dateSrc" }),
|
|
262
260
|
__metadata("design:type", Date)
|
|
263
261
|
], TestDecorators.prototype, "date", void 0);
|
|
264
262
|
__decorate([
|
|
265
|
-
|
|
263
|
+
ArrayField(ObjDecorator),
|
|
266
264
|
__metadata("design:type", Array)
|
|
267
265
|
], TestDecorators.prototype, "objList", void 0);
|
|
268
266
|
__decorate([
|
|
269
|
-
|
|
267
|
+
ObjectField(ObjDecorator),
|
|
270
268
|
__metadata("design:type", ObjDecorator)
|
|
271
269
|
], TestDecorators.prototype, "obj", void 0);
|
|
272
270
|
TestDecorators = __decorate([
|
|
273
|
-
|
|
271
|
+
MapClass()
|
|
274
272
|
], TestDecorators);
|
|
275
273
|
const JSONTestDecorators = {
|
|
276
|
-
|
|
274
|
+
dateSrc: "2023-10-01T00:00:00Z",
|
|
277
275
|
objList: [
|
|
278
276
|
{ id: "1", testObject: { id: "2" } },
|
|
279
277
|
{ id: "3", testObject: { id: "4" } },
|
|
@@ -281,9 +279,11 @@ const JSONTestDecorators = {
|
|
|
281
279
|
obj: { id: "5", testObject: { id: "6" } },
|
|
282
280
|
};
|
|
283
281
|
const testDecorators = new TestDecorators().from(JSONTestDecorators);
|
|
284
|
-
console.log("TEST WITH DECORATORS",
|
|
282
|
+
console.log("TEST WITH DECORATORS", testDecorators.date.toISOString() &&
|
|
285
283
|
testDecorators.objList?.length === 2 &&
|
|
286
284
|
testDecorators.obj instanceof ObjDecorator &&
|
|
287
285
|
testDecorators.objList[0] instanceof ObjDecorator &&
|
|
288
|
-
testDecorators.objList[0].testObject instanceof ObjDecorator
|
|
286
|
+
testDecorators.objList[0].testObject instanceof ObjDecorator
|
|
287
|
+
? "✅"
|
|
288
|
+
: "❌");
|
|
289
289
|
console.log("\n");
|
package/dist/types.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mapper-factory",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "mapper for typescript object",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"main": "dist/index.js",
|
|
6
7
|
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
7
14
|
"files": [
|
|
8
15
|
"/dist",
|
|
9
16
|
"/images"
|
|
@@ -11,7 +18,7 @@
|
|
|
11
18
|
"scripts": {
|
|
12
19
|
"build": "npx tsc",
|
|
13
20
|
"dev": "npx tsc --watch",
|
|
14
|
-
"test": "npx
|
|
21
|
+
"test": "npx tsx src/test.ts",
|
|
15
22
|
"patch": "npm version patch",
|
|
16
23
|
"minor": "npm version minor",
|
|
17
24
|
"major": "npm version major",
|
package/dist/example.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|