mapper-factory 3.0.1 → 3.1.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/dist/class.decorator.d.ts +11 -11
- package/dist/class.decorator.js +16 -17
- package/dist/field.decorator.d.ts +22 -22
- package/dist/field.decorator.js +54 -54
- package/dist/functions.d.ts +49 -49
- package/dist/functions.js +211 -208
- package/dist/index.d.ts +10 -10
- package/dist/index.js +13 -13
- package/dist/test.d.ts +1 -1
- package/dist/test.js +218 -219
- package/dist/types.d.ts +6 -6
- package/dist/types.js +2 -2
- package/package.json +5 -3
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export declare function MapClass(): (constructor: any) => void;
|
|
2
|
-
export interface MapInterface<T> {
|
|
3
|
-
from: (object?: any) => T;
|
|
4
|
-
toMap: () => any;
|
|
5
|
-
toModel: (object: any) => T;
|
|
6
|
-
empty: () => boolean;
|
|
7
|
-
filled: () => boolean;
|
|
8
|
-
get: (path: string) => any;
|
|
9
|
-
set: (path: string, value: any) => void;
|
|
10
|
-
copy: () => T;
|
|
11
|
-
}
|
|
1
|
+
export declare function MapClass(): (constructor: any) => void;
|
|
2
|
+
export interface MapInterface<T> {
|
|
3
|
+
from: (object?: any) => T;
|
|
4
|
+
toMap: () => any;
|
|
5
|
+
toModel: (object: any) => T;
|
|
6
|
+
empty: () => boolean;
|
|
7
|
+
filled: () => boolean;
|
|
8
|
+
get: (path: string) => any;
|
|
9
|
+
set: (path: string, value: any) => void;
|
|
10
|
+
copy: () => T;
|
|
11
|
+
}
|
package/dist/class.decorator.js
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MapClass =
|
|
4
|
-
const functions_1 = require("./functions");
|
|
5
|
-
function MapClass() {
|
|
6
|
-
return function (constructor) {
|
|
7
|
-
constructor.prototype.from = functions_1.from;
|
|
8
|
-
constructor.prototype.toMap = functions_1.toMap;
|
|
9
|
-
constructor.prototype.toModel = functions_1.objToModel;
|
|
10
|
-
constructor.prototype.empty = functions_1.empty;
|
|
11
|
-
constructor.prototype.filled = functions_1.filled;
|
|
12
|
-
constructor.prototype.get = functions_1.get;
|
|
13
|
-
constructor.prototype.set = functions_1.set;
|
|
14
|
-
constructor.prototype.copy = functions_1.copy;
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
exports.MapClass = MapClass;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MapClass = MapClass;
|
|
4
|
+
const functions_1 = require("./functions");
|
|
5
|
+
function MapClass() {
|
|
6
|
+
return function (constructor) {
|
|
7
|
+
constructor.prototype.from = functions_1.from;
|
|
8
|
+
constructor.prototype.toMap = functions_1.toMap;
|
|
9
|
+
constructor.prototype.toModel = functions_1.objToModel;
|
|
10
|
+
constructor.prototype.empty = functions_1.empty;
|
|
11
|
+
constructor.prototype.filled = functions_1.filled;
|
|
12
|
+
constructor.prototype.get = functions_1.get;
|
|
13
|
+
constructor.prototype.set = functions_1.set;
|
|
14
|
+
constructor.prototype.copy = functions_1.copy;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import 'reflect-metadata';
|
|
2
|
-
import { ClassType } from './types';
|
|
3
|
-
export declare const MAP_FIELD: unique symbol;
|
|
4
|
-
export interface MapperMetadata<T = any> {
|
|
5
|
-
src?: keyof T;
|
|
6
|
-
initialize?: boolean;
|
|
7
|
-
transformer?: {
|
|
8
|
-
(input: any, ref: any): any;
|
|
9
|
-
};
|
|
10
|
-
reverser?: {
|
|
11
|
-
(input: any): any;
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
export declare function isClass(func: any): func is ClassType;
|
|
15
|
-
export declare function getPrototype(target: Record<string, unknown> | ClassType): any;
|
|
16
|
-
export declare const MapField: <T = any>({ transformer, reverser, src, initialize, }?: MapperMetadata<T>) => PropertyDecorator;
|
|
17
|
-
export declare const getMapFieldMetadataList: (target: Record<string, unknown> | ClassType | any) => {
|
|
18
|
-
[key: string]: MapperMetadata
|
|
19
|
-
};
|
|
20
|
-
export declare const hasMapFieldMetadataList: (target: Record<string, unknown> | ClassType) => boolean;
|
|
21
|
-
export declare const getMapFieldMetadata: (target: Record<string, unknown> | ClassType, propertyName: string | symbol) => MapperMetadata | undefined;
|
|
22
|
-
export declare const hasMapFieldMetadata: (target: Record<string, unknown> | ClassType, propertyName: string) => boolean;
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
import { ClassType } from './types';
|
|
3
|
+
export declare const MAP_FIELD: unique symbol;
|
|
4
|
+
export interface MapperMetadata<T = any> {
|
|
5
|
+
src?: keyof T;
|
|
6
|
+
initialize?: boolean;
|
|
7
|
+
transformer?: {
|
|
8
|
+
(input: any, ref: any): any;
|
|
9
|
+
};
|
|
10
|
+
reverser?: {
|
|
11
|
+
(input: any): any;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export declare function isClass(func: any): func is ClassType;
|
|
15
|
+
export declare function getPrototype(target: Record<string, unknown> | ClassType): any;
|
|
16
|
+
export declare const MapField: <T = any>({ transformer, reverser, src, initialize, }?: MapperMetadata<T>) => PropertyDecorator;
|
|
17
|
+
export declare const getMapFieldMetadataList: (target: Record<string, unknown> | ClassType | any) => {
|
|
18
|
+
[key: string]: MapperMetadata;
|
|
19
|
+
} | undefined;
|
|
20
|
+
export declare const hasMapFieldMetadataList: (target: Record<string, unknown> | ClassType) => boolean;
|
|
21
|
+
export declare const getMapFieldMetadata: (target: Record<string, unknown> | ClassType, propertyName: string | symbol) => MapperMetadata | undefined;
|
|
22
|
+
export declare const hasMapFieldMetadata: (target: Record<string, unknown> | ClassType, propertyName: string) => boolean;
|
package/dist/field.decorator.js
CHANGED
|
@@ -1,54 +1,54 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.hasMapFieldMetadata = exports.getMapFieldMetadata = exports.hasMapFieldMetadataList = exports.getMapFieldMetadataList = exports.MapField = exports.
|
|
4
|
-
|
|
5
|
-
exports.
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const MapField = ({ transformer, reverser, src, initialize = false, } = {}) => {
|
|
16
|
-
return (target, property) => {
|
|
17
|
-
const classConstructor = target.constructor;
|
|
18
|
-
const propertyName = property.toString();
|
|
19
|
-
const metadata = Reflect.getMetadata(exports.MAP_FIELD, classConstructor) || {};
|
|
20
|
-
// create new object reference to avoid this issue: https://github.com/rbuckton/reflect-metadata/issues/62
|
|
21
|
-
const newMetadata = { ...metadata };
|
|
22
|
-
const previousValues = metadata[propertyName];
|
|
23
|
-
newMetadata[propertyName] = {
|
|
24
|
-
...previousValues,
|
|
25
|
-
src,
|
|
26
|
-
initialize,
|
|
27
|
-
transformer,
|
|
28
|
-
reverser,
|
|
29
|
-
};
|
|
30
|
-
Reflect.defineMetadata(exports.MAP_FIELD, newMetadata, classConstructor);
|
|
31
|
-
};
|
|
32
|
-
};
|
|
33
|
-
exports.MapField = MapField;
|
|
34
|
-
const getMapFieldMetadataList = (target) => {
|
|
35
|
-
return Reflect.getMetadata(exports.MAP_FIELD, getPrototype(target));
|
|
36
|
-
};
|
|
37
|
-
exports.getMapFieldMetadataList = getMapFieldMetadataList;
|
|
38
|
-
const hasMapFieldMetadataList = (target) => {
|
|
39
|
-
return Reflect.hasMetadata(exports.MAP_FIELD, getPrototype(target));
|
|
40
|
-
};
|
|
41
|
-
exports.hasMapFieldMetadataList = hasMapFieldMetadataList;
|
|
42
|
-
const getMapFieldMetadata = (target, propertyName) => {
|
|
43
|
-
const metadata = (0, exports.getMapFieldMetadataList)(target);
|
|
44
|
-
const name = propertyName.toString();
|
|
45
|
-
if (!metadata || !metadata[name])
|
|
46
|
-
return undefined;
|
|
47
|
-
return metadata[name];
|
|
48
|
-
};
|
|
49
|
-
exports.getMapFieldMetadata = getMapFieldMetadata;
|
|
50
|
-
const hasMapFieldMetadata = (target, propertyName) => {
|
|
51
|
-
const metadata = Reflect.getMetadata(exports.MAP_FIELD, getPrototype(target));
|
|
52
|
-
return metadata && !!metadata[propertyName];
|
|
53
|
-
};
|
|
54
|
-
exports.hasMapFieldMetadata = hasMapFieldMetadata;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hasMapFieldMetadata = exports.getMapFieldMetadata = exports.hasMapFieldMetadataList = exports.getMapFieldMetadataList = exports.MapField = exports.MAP_FIELD = void 0;
|
|
4
|
+
exports.isClass = isClass;
|
|
5
|
+
exports.getPrototype = getPrototype;
|
|
6
|
+
require("reflect-metadata");
|
|
7
|
+
exports.MAP_FIELD = Symbol('MAP_FIELD');
|
|
8
|
+
function isClass(func) {
|
|
9
|
+
return (typeof func === 'function' &&
|
|
10
|
+
/^class\s/.test(Function.prototype.toString.call(func)));
|
|
11
|
+
}
|
|
12
|
+
function getPrototype(target) {
|
|
13
|
+
return isClass(target) || !target?.prototype ? !target?.constructor ? target : target?.constructor : target?.prototype;
|
|
14
|
+
}
|
|
15
|
+
const MapField = ({ transformer, reverser, src, initialize = false, } = {}) => {
|
|
16
|
+
return (target, property) => {
|
|
17
|
+
const classConstructor = target.constructor;
|
|
18
|
+
const propertyName = property.toString();
|
|
19
|
+
const metadata = Reflect.getMetadata(exports.MAP_FIELD, classConstructor) || {};
|
|
20
|
+
// create new object reference to avoid this issue: https://github.com/rbuckton/reflect-metadata/issues/62
|
|
21
|
+
const newMetadata = { ...metadata };
|
|
22
|
+
const previousValues = metadata[propertyName];
|
|
23
|
+
newMetadata[propertyName] = {
|
|
24
|
+
...previousValues,
|
|
25
|
+
src,
|
|
26
|
+
initialize,
|
|
27
|
+
transformer,
|
|
28
|
+
reverser,
|
|
29
|
+
};
|
|
30
|
+
Reflect.defineMetadata(exports.MAP_FIELD, newMetadata, classConstructor);
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
exports.MapField = MapField;
|
|
34
|
+
const getMapFieldMetadataList = (target) => {
|
|
35
|
+
return Reflect.getMetadata(exports.MAP_FIELD, getPrototype(target));
|
|
36
|
+
};
|
|
37
|
+
exports.getMapFieldMetadataList = getMapFieldMetadataList;
|
|
38
|
+
const hasMapFieldMetadataList = (target) => {
|
|
39
|
+
return Reflect.hasMetadata(exports.MAP_FIELD, getPrototype(target));
|
|
40
|
+
};
|
|
41
|
+
exports.hasMapFieldMetadataList = hasMapFieldMetadataList;
|
|
42
|
+
const getMapFieldMetadata = (target, propertyName) => {
|
|
43
|
+
const metadata = (0, exports.getMapFieldMetadataList)(target);
|
|
44
|
+
const name = propertyName.toString();
|
|
45
|
+
if (!metadata || !metadata[name])
|
|
46
|
+
return undefined;
|
|
47
|
+
return metadata[name];
|
|
48
|
+
};
|
|
49
|
+
exports.getMapFieldMetadata = getMapFieldMetadata;
|
|
50
|
+
const hasMapFieldMetadata = (target, propertyName) => {
|
|
51
|
+
const metadata = Reflect.getMetadata(exports.MAP_FIELD, getPrototype(target));
|
|
52
|
+
return metadata && !!metadata[propertyName];
|
|
53
|
+
};
|
|
54
|
+
exports.hasMapFieldMetadata = hasMapFieldMetadata;
|
package/dist/functions.d.ts
CHANGED
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Convert the instance of this class to JSON Object.
|
|
3
|
-
*
|
|
4
|
-
* @returns JSON object mapped considering metadata "src" and "reverser"
|
|
5
|
-
*/
|
|
6
|
-
export declare function toMap(): any;
|
|
7
|
-
/**
|
|
8
|
-
* Convert a JSON Object to an instance of this class.
|
|
9
|
-
*
|
|
10
|
-
* @param obj JSON Object
|
|
11
|
-
* @returns Instance of this class
|
|
12
|
-
*/
|
|
13
|
-
export declare function objToModel(obj: Object): any;
|
|
14
|
-
/**
|
|
15
|
-
* Check if this instance is empty.
|
|
16
|
-
*
|
|
17
|
-
* @returns true or false
|
|
18
|
-
*/
|
|
19
|
-
export declare function empty(): boolean;
|
|
20
|
-
/**
|
|
21
|
-
* Check if this instance is filled.
|
|
22
|
-
*
|
|
23
|
-
* @returns true or false
|
|
24
|
-
*/
|
|
25
|
-
export declare function filled(): boolean;
|
|
26
|
-
/**
|
|
27
|
-
* GET property value from a string path.
|
|
28
|
-
*
|
|
29
|
-
* @param path String path
|
|
30
|
-
* @returns Value of the property
|
|
31
|
-
*/
|
|
32
|
-
export declare function get<T>(path: string): T;
|
|
33
|
-
/**
|
|
34
|
-
* SET property value from a string path.
|
|
35
|
-
*
|
|
36
|
-
* @param path String path
|
|
37
|
-
* @param value Value of the property
|
|
38
|
-
*/
|
|
39
|
-
export declare function set(path: string, value: any): void;
|
|
40
|
-
/**
|
|
41
|
-
* Deep copy of the object caller
|
|
42
|
-
*/
|
|
43
|
-
export declare function copy<T>(): T;
|
|
44
|
-
/**
|
|
45
|
-
* Constructor of the mapper.
|
|
46
|
-
*
|
|
47
|
-
* @param object object to be mapped considering metadata "src", "transformer" and "reverser"
|
|
48
|
-
*/
|
|
49
|
-
export declare function from(object: any): any;
|
|
1
|
+
/**
|
|
2
|
+
* Convert the instance of this class to JSON Object.
|
|
3
|
+
*
|
|
4
|
+
* @returns JSON object mapped considering metadata "src" and "reverser"
|
|
5
|
+
*/
|
|
6
|
+
export declare function toMap(): any;
|
|
7
|
+
/**
|
|
8
|
+
* Convert a JSON Object to an instance of this class.
|
|
9
|
+
*
|
|
10
|
+
* @param obj JSON Object
|
|
11
|
+
* @returns Instance of this class
|
|
12
|
+
*/
|
|
13
|
+
export declare function objToModel(obj: Object): any;
|
|
14
|
+
/**
|
|
15
|
+
* Check if this instance is empty.
|
|
16
|
+
*
|
|
17
|
+
* @returns true or false
|
|
18
|
+
*/
|
|
19
|
+
export declare function empty(): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Check if this instance is filled.
|
|
22
|
+
*
|
|
23
|
+
* @returns true or false
|
|
24
|
+
*/
|
|
25
|
+
export declare function filled(): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* GET property value from a string path.
|
|
28
|
+
*
|
|
29
|
+
* @param path String path
|
|
30
|
+
* @returns Value of the property
|
|
31
|
+
*/
|
|
32
|
+
export declare function get<T>(path: string): T;
|
|
33
|
+
/**
|
|
34
|
+
* SET property value from a string path.
|
|
35
|
+
*
|
|
36
|
+
* @param path String path
|
|
37
|
+
* @param value Value of the property
|
|
38
|
+
*/
|
|
39
|
+
export declare function set(path: string, value: any): void;
|
|
40
|
+
/**
|
|
41
|
+
* Deep copy of the object caller
|
|
42
|
+
*/
|
|
43
|
+
export declare function copy<T>(): T;
|
|
44
|
+
/**
|
|
45
|
+
* Constructor of the mapper.
|
|
46
|
+
*
|
|
47
|
+
* @param object object to be mapped considering metadata "src", "transformer" and "reverser"
|
|
48
|
+
*/
|
|
49
|
+
export declare function from(object: any): any;
|