@tsed/json-mapper 6.87.1 → 6.89.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/lib/{components → cjs/components}/ArrayMapper.d.ts +0 -0
- package/lib/cjs/components/ArrayMapper.js +23 -0
- package/lib/cjs/components/ArrayMapper.js.map +1 -0
- package/lib/{components → cjs/components}/DateMapper.d.ts +0 -0
- package/lib/cjs/components/DateMapper.js +30 -0
- package/lib/cjs/components/DateMapper.js.map +1 -0
- package/lib/{components → cjs/components}/MapMapper.d.ts +0 -0
- package/lib/cjs/components/MapMapper.js +30 -0
- package/lib/cjs/components/MapMapper.js.map +1 -0
- package/lib/{components → cjs/components}/PrimitiveMapper.d.ts +0 -0
- package/lib/cjs/components/PrimitiveMapper.js +45 -0
- package/lib/cjs/components/PrimitiveMapper.js.map +1 -0
- package/lib/{components → cjs/components}/SetMapper.d.ts +0 -0
- package/lib/cjs/components/SetMapper.js +30 -0
- package/lib/cjs/components/SetMapper.js.map +1 -0
- package/lib/{components → cjs/components}/SymbolMapper.d.ts +0 -0
- package/lib/cjs/components/SymbolMapper.js +24 -0
- package/lib/cjs/components/SymbolMapper.js.map +1 -0
- package/lib/{components → cjs/components}/index.d.ts +0 -0
- package/lib/cjs/components/index.js +10 -0
- package/lib/cjs/components/index.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/afterDeserialize.d.ts +0 -0
- package/lib/cjs/decorators/afterDeserialize.js +39 -0
- package/lib/cjs/decorators/afterDeserialize.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/beforeDeserialize.d.ts +0 -0
- package/lib/cjs/decorators/beforeDeserialize.js +39 -0
- package/lib/cjs/decorators/beforeDeserialize.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/jsonMapper.d.ts +0 -0
- package/lib/cjs/decorators/jsonMapper.js +18 -0
- package/lib/cjs/decorators/jsonMapper.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/onDeserialize.d.ts +0 -0
- package/lib/cjs/decorators/onDeserialize.js +29 -0
- package/lib/cjs/decorators/onDeserialize.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/onSerialize.d.ts +0 -0
- package/lib/cjs/decorators/onSerialize.js +29 -0
- package/lib/cjs/decorators/onSerialize.js.map +1 -0
- package/lib/{domain → cjs/domain}/JsonMapperContext.d.ts +0 -0
- package/lib/cjs/domain/JsonMapperContext.js +23 -0
- package/lib/cjs/domain/JsonMapperContext.js.map +1 -0
- package/lib/{domain → cjs/domain}/JsonMapperTypesContainer.d.ts +0 -0
- package/lib/cjs/domain/JsonMapperTypesContainer.js +23 -0
- package/lib/cjs/domain/JsonMapperTypesContainer.js.map +1 -0
- package/lib/{hooks → cjs/hooks}/alterAfterDeserialize.d.ts +0 -0
- package/lib/cjs/hooks/alterAfterDeserialize.js +9 -0
- package/lib/cjs/hooks/alterAfterDeserialize.js.map +1 -0
- package/lib/{hooks → cjs/hooks}/alterBeforeDeserialize.d.ts +0 -0
- package/lib/cjs/hooks/alterBeforeDeserialize.js +9 -0
- package/lib/cjs/hooks/alterBeforeDeserialize.js.map +1 -0
- package/lib/{index.d.ts → cjs/index.d.ts} +0 -0
- package/lib/cjs/index.js +15 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/{interfaces → cjs/interfaces}/JsonMapperMethods.d.ts +0 -0
- package/lib/cjs/interfaces/JsonMapperMethods.js +3 -0
- package/lib/cjs/interfaces/JsonMapperMethods.js.map +1 -0
- package/lib/{utils → cjs/utils}/deserialize.d.ts +0 -0
- package/lib/cjs/utils/deserialize.js +140 -0
- package/lib/cjs/utils/deserialize.js.map +1 -0
- package/lib/{utils → cjs/utils}/serialize.d.ts +0 -0
- package/lib/cjs/utils/serialize.js +112 -0
- package/lib/cjs/utils/serialize.js.map +1 -0
- package/lib/esm/components/ArrayMapper.js +20 -0
- package/lib/esm/components/ArrayMapper.js.map +1 -0
- package/lib/esm/components/DateMapper.js +27 -0
- package/lib/esm/components/DateMapper.js.map +1 -0
- package/lib/esm/components/MapMapper.js +27 -0
- package/lib/esm/components/MapMapper.js.map +1 -0
- package/lib/esm/components/PrimitiveMapper.js +42 -0
- package/lib/esm/components/PrimitiveMapper.js.map +1 -0
- package/lib/esm/components/SetMapper.js +27 -0
- package/lib/esm/components/SetMapper.js.map +1 -0
- package/lib/esm/components/SymbolMapper.js +21 -0
- package/lib/esm/components/SymbolMapper.js.map +1 -0
- package/lib/esm/components/index.js +7 -0
- package/lib/esm/components/index.js.map +1 -0
- package/lib/esm/decorators/afterDeserialize.js +35 -0
- package/lib/esm/decorators/afterDeserialize.js.map +1 -0
- package/lib/esm/decorators/beforeDeserialize.js +35 -0
- package/lib/esm/decorators/beforeDeserialize.js.map +1 -0
- package/lib/esm/decorators/jsonMapper.js +14 -0
- package/lib/esm/decorators/jsonMapper.js.map +1 -0
- package/lib/esm/decorators/onDeserialize.js +25 -0
- package/lib/esm/decorators/onDeserialize.js.map +1 -0
- package/lib/esm/decorators/onSerialize.js +25 -0
- package/lib/esm/decorators/onSerialize.js.map +1 -0
- package/lib/esm/domain/JsonMapperContext.js +19 -0
- package/lib/esm/domain/JsonMapperContext.js.map +1 -0
- package/lib/esm/domain/JsonMapperTypesContainer.js +18 -0
- package/lib/esm/domain/JsonMapperTypesContainer.js.map +1 -0
- package/lib/esm/hooks/alterAfterDeserialize.js +5 -0
- package/lib/esm/hooks/alterAfterDeserialize.js.map +1 -0
- package/lib/esm/hooks/alterBeforeDeserialize.js +5 -0
- package/lib/esm/hooks/alterBeforeDeserialize.js.map +1 -0
- package/lib/esm/index.js +12 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/interfaces/JsonMapperMethods.js +2 -0
- package/lib/esm/interfaces/JsonMapperMethods.js.map +1 -0
- package/lib/esm/utils/deserialize.js +135 -0
- package/lib/esm/utils/deserialize.js.map +1 -0
- package/lib/esm/utils/serialize.js +107 -0
- package/lib/esm/utils/serialize.js.map +1 -0
- package/lib/types/components/ArrayMapper.d.ts +10 -0
- package/lib/types/components/DateMapper.d.ts +11 -0
- package/lib/types/components/MapMapper.d.ts +12 -0
- package/lib/types/components/PrimitiveMapper.d.ts +10 -0
- package/lib/types/components/SetMapper.d.ts +10 -0
- package/lib/types/components/SymbolMapper.d.ts +11 -0
- package/lib/types/components/index.d.ts +6 -0
- package/lib/types/decorators/afterDeserialize.d.ts +33 -0
- package/lib/types/decorators/beforeDeserialize.d.ts +33 -0
- package/lib/types/decorators/jsonMapper.d.ts +7 -0
- package/lib/types/decorators/onDeserialize.d.ts +23 -0
- package/lib/types/decorators/onSerialize.d.ts +23 -0
- package/lib/types/domain/JsonMapperContext.d.ts +20 -0
- package/lib/types/domain/JsonMapperTypesContainer.d.ts +10 -0
- package/lib/types/hooks/alterAfterDeserialize.d.ts +4 -0
- package/lib/types/hooks/alterBeforeDeserialize.d.ts +4 -0
- package/lib/types/index.d.ts +11 -0
- package/lib/types/interfaces/JsonMapperMethods.d.ts +25 -0
- package/lib/types/utils/deserialize.d.ts +41 -0
- package/lib/types/utils/serialize.d.ts +16 -0
- package/package.json +18 -14
- package/tsconfig.compile.esm.json +23 -0
- package/lib/index.js +0 -719
- package/lib/index.js.map +0 -1
- package/lib/index.modern.js +0 -708
- package/lib/index.modern.js.map +0 -1
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { JsonHookContext } from "@tsed/schema";
|
|
2
|
+
export interface OnSerializeCallback {
|
|
3
|
+
(value: any, ctx: JsonHookContext): any;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Call the function before property serialization.
|
|
7
|
+
*
|
|
8
|
+
* ## Example
|
|
9
|
+
*
|
|
10
|
+
* ```typescript
|
|
11
|
+
* class Model {
|
|
12
|
+
* @OnSerialize(v => v + 1)
|
|
13
|
+
* property: string;
|
|
14
|
+
* }
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @returns {Function}
|
|
18
|
+
* @decorator
|
|
19
|
+
* @schema
|
|
20
|
+
* @property
|
|
21
|
+
* @param cb
|
|
22
|
+
*/
|
|
23
|
+
export declare function OnSerialize(cb: OnSerializeCallback): PropertyDecorator;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Type } from "@tsed/core";
|
|
2
|
+
import { JsonMapperCtx } from "../interfaces/JsonMapperMethods";
|
|
3
|
+
/**
|
|
4
|
+
* @ignore
|
|
5
|
+
*/
|
|
6
|
+
export interface JsonMapperContextProps extends Partial<Omit<JsonMapperCtx, "next">> {
|
|
7
|
+
next: (data: any, options: any) => void;
|
|
8
|
+
options: any;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* @ignore
|
|
12
|
+
*/
|
|
13
|
+
export declare class JsonMapperContext implements JsonMapperCtx {
|
|
14
|
+
readonly collectionType: Type<any> | undefined;
|
|
15
|
+
readonly type: Type<any> | any;
|
|
16
|
+
readonly options: any;
|
|
17
|
+
private _next;
|
|
18
|
+
constructor({ type, collectionType, next, options }: JsonMapperContextProps);
|
|
19
|
+
next(data: any): void;
|
|
20
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Type } from "@tsed/core";
|
|
2
|
+
import { JsonMapperMethods } from "../interfaces/JsonMapperMethods";
|
|
3
|
+
/**
|
|
4
|
+
* @ignore
|
|
5
|
+
*/
|
|
6
|
+
export declare function registerJsonTypeMapper(type: Type<any>, token: Type<JsonMapperMethods>): void;
|
|
7
|
+
/**
|
|
8
|
+
* @ignore
|
|
9
|
+
*/
|
|
10
|
+
export declare function getJsonMapperTypes(): WeakMap<Type<any> | Symbol, JsonMapperMethods>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from "./components";
|
|
2
|
+
export * from "./decorators/jsonMapper";
|
|
3
|
+
export * from "./decorators/onDeserialize";
|
|
4
|
+
export * from "./decorators/onSerialize";
|
|
5
|
+
export * from "./decorators/afterDeserialize";
|
|
6
|
+
export * from "./decorators/beforeDeserialize";
|
|
7
|
+
export * from "./domain/JsonMapperContext";
|
|
8
|
+
export * from "./domain/JsonMapperTypesContainer";
|
|
9
|
+
export * from "./interfaces/JsonMapperMethods";
|
|
10
|
+
export * from "./utils/deserialize";
|
|
11
|
+
export * from "./utils/serialize";
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Type } from "@tsed/core";
|
|
2
|
+
export interface JsonMapperCtx<T = any, C = any> {
|
|
3
|
+
collectionType: Type<C> | undefined;
|
|
4
|
+
type: Type<T> | T;
|
|
5
|
+
next: JsonMapperNext;
|
|
6
|
+
}
|
|
7
|
+
export interface JsonMapperNext {
|
|
8
|
+
(obj: any): any;
|
|
9
|
+
}
|
|
10
|
+
export interface JsonMapperMethods {
|
|
11
|
+
/**
|
|
12
|
+
*
|
|
13
|
+
* @param obj
|
|
14
|
+
* @param {JsonMapperNext} ctx
|
|
15
|
+
* @returns {any}
|
|
16
|
+
*/
|
|
17
|
+
deserialize<T = any, C = any>(obj: any, ctx: JsonMapperCtx<T, C>): any;
|
|
18
|
+
/**
|
|
19
|
+
*
|
|
20
|
+
* @param obj
|
|
21
|
+
* @param ctx
|
|
22
|
+
* @returns {any}
|
|
23
|
+
*/
|
|
24
|
+
serialize(obj: any, ctx: JsonMapperCtx<any>): any;
|
|
25
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { MetadataTypes, Type } from "@tsed/core";
|
|
2
|
+
import { JsonEntityStore } from "@tsed/schema";
|
|
3
|
+
import "../components";
|
|
4
|
+
import { JsonMapperMethods } from "../interfaces/JsonMapperMethods";
|
|
5
|
+
export interface JsonDeserializerOptions<T = any, C = any> extends MetadataTypes<T, C> {
|
|
6
|
+
/**
|
|
7
|
+
* Types used to map complex types (Symbol, Array, Set, Map)
|
|
8
|
+
*/
|
|
9
|
+
types?: WeakMap<Type<any>, JsonMapperMethods>;
|
|
10
|
+
/**
|
|
11
|
+
* useAlias mapping
|
|
12
|
+
*/
|
|
13
|
+
useAlias?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Accept additionalProperties or ignore it
|
|
16
|
+
*/
|
|
17
|
+
additionalProperties?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Use the store which have all metadata to deserialize correctly the model. This
|
|
20
|
+
* property is useful when you deal with metadata parameters.
|
|
21
|
+
*/
|
|
22
|
+
store?: JsonEntityStore;
|
|
23
|
+
/**
|
|
24
|
+
*
|
|
25
|
+
*/
|
|
26
|
+
groups?: string[] | false;
|
|
27
|
+
[key: string]: any;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Transform given plain object to class.
|
|
31
|
+
* @param src
|
|
32
|
+
* @param options
|
|
33
|
+
*/
|
|
34
|
+
export declare function plainObjectToClass<T = any>(src: any, options: JsonDeserializerOptions): T;
|
|
35
|
+
/**
|
|
36
|
+
* Transform given source to class base on the given `options.type`.
|
|
37
|
+
*
|
|
38
|
+
* @param src
|
|
39
|
+
* @param options
|
|
40
|
+
*/
|
|
41
|
+
export declare function deserialize<T = any>(src: any, options?: JsonDeserializerOptions): T;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { MetadataTypes, Type } from "@tsed/core";
|
|
2
|
+
import "../components";
|
|
3
|
+
import { JsonMapperMethods } from "../interfaces/JsonMapperMethods";
|
|
4
|
+
export interface JsonSerializerOptions<T = any, C = any> extends MetadataTypes<T, C> {
|
|
5
|
+
/**
|
|
6
|
+
* Types used to map complex types (Symbol, Array, Set, Map)
|
|
7
|
+
*/
|
|
8
|
+
types?: Map<Type<any>, JsonMapperMethods>;
|
|
9
|
+
/**
|
|
10
|
+
* useAlias mapping
|
|
11
|
+
*/
|
|
12
|
+
useAlias?: boolean;
|
|
13
|
+
[key: string]: any;
|
|
14
|
+
}
|
|
15
|
+
export declare function classToPlainObject(obj: any, options: JsonSerializerOptions<any, any>): {};
|
|
16
|
+
export declare function serialize(obj: any, { type, collectionType, groups, ...options }?: JsonSerializerOptions): any;
|
package/package.json
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/json-mapper",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.89.0",
|
|
4
4
|
"description": "Json mapper module for Ts.ED Framework",
|
|
5
5
|
"private": false,
|
|
6
6
|
"source": "./src/index.ts",
|
|
7
|
-
"main": "./lib/index.js",
|
|
8
|
-
"typings": "./lib/index.d.ts",
|
|
7
|
+
"main": "./lib/cjs/index.js",
|
|
8
|
+
"typings": "./lib/types/index.d.ts",
|
|
9
9
|
"exports": {
|
|
10
|
-
"
|
|
11
|
-
"
|
|
10
|
+
"types": "./lib/types/index.d.ts",
|
|
11
|
+
"import": "./lib/esm/index.js",
|
|
12
|
+
"require": "./lib/cjs/index.js",
|
|
13
|
+
"default": "./lib/esm/index.js"
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "yarn run build:esm && yarn run build:cjs",
|
|
17
|
+
"build:cjs": "tsc --build tsconfig.compile.json",
|
|
18
|
+
"build:esm": "tsc --build tsconfig.compile.esm.json"
|
|
12
19
|
},
|
|
13
20
|
"keywords": [
|
|
14
21
|
"TypeScript",
|
|
@@ -22,21 +29,18 @@
|
|
|
22
29
|
"classes",
|
|
23
30
|
"tsed"
|
|
24
31
|
],
|
|
25
|
-
"scripts": {
|
|
26
|
-
"build": "microbundle --target node --no-compress --format modern,cjs --tsconfig ./tsconfig.compile.json"
|
|
27
|
-
},
|
|
28
32
|
"dependencies": {
|
|
29
33
|
"tslib": "2.2.0"
|
|
30
34
|
},
|
|
31
35
|
"devDependencies": {
|
|
32
|
-
"@tsed/core": "6.
|
|
33
|
-
"@tsed/exceptions": "6.
|
|
34
|
-
"@tsed/schema": "6.
|
|
36
|
+
"@tsed/core": "6.89.0",
|
|
37
|
+
"@tsed/exceptions": "6.89.0",
|
|
38
|
+
"@tsed/schema": "6.89.0"
|
|
35
39
|
},
|
|
36
40
|
"peerDependencies": {
|
|
37
|
-
"@tsed/core": "^6.
|
|
38
|
-
"@tsed/exceptions": "^6.
|
|
39
|
-
"@tsed/schema": "^6.
|
|
41
|
+
"@tsed/core": "^6.89.0",
|
|
42
|
+
"@tsed/exceptions": "^6.89.0",
|
|
43
|
+
"@tsed/schema": "^6.89.0"
|
|
40
44
|
},
|
|
41
45
|
"repository": "https://github.com/tsedio/tsed",
|
|
42
46
|
"bugs": {
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./tsconfig.compile.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"baseUrl": ".",
|
|
5
|
+
"module": "ES2020",
|
|
6
|
+
"rootDir": "src",
|
|
7
|
+
"outDir": "./lib/esm",
|
|
8
|
+
"declaration": true,
|
|
9
|
+
"declarationDir": "./lib/types"
|
|
10
|
+
},
|
|
11
|
+
"exclude": [
|
|
12
|
+
"node_modules",
|
|
13
|
+
"test",
|
|
14
|
+
"lib",
|
|
15
|
+
"benchmark",
|
|
16
|
+
"coverage",
|
|
17
|
+
"spec",
|
|
18
|
+
"**/*.benchmark.ts",
|
|
19
|
+
"**/*.spec.ts",
|
|
20
|
+
"keys",
|
|
21
|
+
"jest.config.js"
|
|
22
|
+
]
|
|
23
|
+
}
|