@tsed/json-mapper 6.95.9 → 6.96.2
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/package.json +7 -7
- package/lib/cjs/components/ArrayMapper.d.ts +0 -10
- package/lib/cjs/components/DateMapper.d.ts +0 -11
- package/lib/cjs/components/MapMapper.d.ts +0 -12
- package/lib/cjs/components/PrimitiveMapper.d.ts +0 -10
- package/lib/cjs/components/SetMapper.d.ts +0 -10
- package/lib/cjs/components/SymbolMapper.d.ts +0 -11
- package/lib/cjs/components/index.d.ts +0 -6
- package/lib/cjs/decorators/afterDeserialize.d.ts +0 -33
- package/lib/cjs/decorators/beforeDeserialize.d.ts +0 -33
- package/lib/cjs/decorators/jsonMapper.d.ts +0 -7
- package/lib/cjs/decorators/onDeserialize.d.ts +0 -23
- package/lib/cjs/decorators/onSerialize.d.ts +0 -23
- package/lib/cjs/domain/JsonMapperContext.d.ts +0 -20
- package/lib/cjs/domain/JsonMapperTypesContainer.d.ts +0 -10
- package/lib/cjs/hooks/alterAfterDeserialize.d.ts +0 -4
- package/lib/cjs/hooks/alterBeforeDeserialize.d.ts +0 -4
- package/lib/cjs/index.d.ts +0 -11
- package/lib/cjs/interfaces/JsonMapperMethods.d.ts +0 -25
- package/lib/cjs/utils/deserialize.d.ts +0 -41
- package/lib/cjs/utils/serialize.d.ts +0 -16
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/json-mapper",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.96.2",
|
|
4
4
|
"description": "Json mapper module for Ts.ED Framework",
|
|
5
5
|
"private": false,
|
|
6
6
|
"source": "./src/index.ts",
|
|
@@ -33,14 +33,14 @@
|
|
|
33
33
|
"tslib": "2.2.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@tsed/core": "6.
|
|
37
|
-
"@tsed/exceptions": "6.
|
|
38
|
-
"@tsed/schema": "6.
|
|
36
|
+
"@tsed/core": "6.96.2",
|
|
37
|
+
"@tsed/exceptions": "6.96.2",
|
|
38
|
+
"@tsed/schema": "6.96.2"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
|
-
"@tsed/core": "^6.
|
|
42
|
-
"@tsed/exceptions": "^6.
|
|
43
|
-
"@tsed/schema": "^6.
|
|
41
|
+
"@tsed/core": "^6.96.2",
|
|
42
|
+
"@tsed/exceptions": "^6.96.2",
|
|
43
|
+
"@tsed/schema": "^6.96.2"
|
|
44
44
|
},
|
|
45
45
|
"repository": "https://github.com/tsedio/tsed",
|
|
46
46
|
"bugs": {
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { JsonMapperCtx, JsonMapperMethods } from "../interfaces/JsonMapperMethods";
|
|
2
|
-
/**
|
|
3
|
-
* Mapper for `Array` type.
|
|
4
|
-
* @jsonmapper
|
|
5
|
-
* @component
|
|
6
|
-
*/
|
|
7
|
-
export declare class ArrayMapper implements JsonMapperMethods {
|
|
8
|
-
deserialize<T = any>(data: any, options: JsonMapperCtx): T[];
|
|
9
|
-
serialize(data: any[], options: JsonMapperCtx): any;
|
|
10
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { JsonMapperMethods } from "../interfaces/JsonMapperMethods";
|
|
2
|
-
/**
|
|
3
|
-
* Mapper for `Date` type.
|
|
4
|
-
* @jsonmapper
|
|
5
|
-
* @component
|
|
6
|
-
*/
|
|
7
|
-
export declare class DateMapper implements JsonMapperMethods {
|
|
8
|
-
deserialize(data: string | number): Date;
|
|
9
|
-
deserialize(data: boolean | null | undefined): boolean | null | undefined;
|
|
10
|
-
serialize(object: Date): any;
|
|
11
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { JsonMapperCtx, JsonMapperMethods } from "../interfaces/JsonMapperMethods";
|
|
2
|
-
/**
|
|
3
|
-
* Mapper for `Map` type.
|
|
4
|
-
* @jsonmapper
|
|
5
|
-
* @component
|
|
6
|
-
*/
|
|
7
|
-
export declare class MapMapper implements JsonMapperMethods {
|
|
8
|
-
deserialize<T = any, C = Map<string, T>>(data: {
|
|
9
|
-
[key: string]: any;
|
|
10
|
-
}, ctx: JsonMapperCtx<T, C>): Map<string, T>;
|
|
11
|
-
serialize<T>(data: Map<string, T>, ctx: JsonMapperCtx): any;
|
|
12
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { JsonMapperCtx, JsonMapperMethods } from "../interfaces/JsonMapperMethods";
|
|
2
|
-
/**
|
|
3
|
-
* Mapper for the `String`, `Number` and `Boolean` types.
|
|
4
|
-
* @jsonmapper
|
|
5
|
-
* @component
|
|
6
|
-
*/
|
|
7
|
-
export declare class PrimitiveMapper implements JsonMapperMethods {
|
|
8
|
-
deserialize<T>(data: any, ctx: JsonMapperCtx): string | number | boolean | void | null;
|
|
9
|
-
serialize(object: string | number | boolean): string | number | boolean;
|
|
10
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { JsonMapperCtx, JsonMapperMethods } from "../interfaces/JsonMapperMethods";
|
|
2
|
-
/**
|
|
3
|
-
* Mapper for the `Set` Type.
|
|
4
|
-
* @jsonmapper
|
|
5
|
-
* @component
|
|
6
|
-
*/
|
|
7
|
-
export declare class SetMapper implements JsonMapperMethods {
|
|
8
|
-
deserialize<T>(data: any, ctx: JsonMapperCtx): Set<T>;
|
|
9
|
-
serialize<T>(data: Set<T>, ctx: JsonMapperCtx): any[];
|
|
10
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { JsonMapperMethods } from "../interfaces/JsonMapperMethods";
|
|
2
|
-
/**
|
|
3
|
-
* Mapper for the `Symbol` type.
|
|
4
|
-
*
|
|
5
|
-
* @jsonmapper
|
|
6
|
-
* @component
|
|
7
|
-
*/
|
|
8
|
-
export declare class SymbolMapper implements JsonMapperMethods {
|
|
9
|
-
deserialize(data: string): symbol;
|
|
10
|
-
serialize(object: Symbol): any;
|
|
11
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { JsonHookContext } from "@tsed/schema";
|
|
2
|
-
export interface AfterDeserializeCallback {
|
|
3
|
-
(value: any, ctx: JsonHookContext): any;
|
|
4
|
-
}
|
|
5
|
-
/**
|
|
6
|
-
* Call the function after JsonMapper.
|
|
7
|
-
*
|
|
8
|
-
* ## Example
|
|
9
|
-
*
|
|
10
|
-
* ```typescript
|
|
11
|
-
* @AfterDeserialize((data: Model) => { // After deserialize get the instance class
|
|
12
|
-
* if (data.prop1 === 'VALUE' && data.prop2 !== 'VALUE2') {
|
|
13
|
-
* throw BadRequest('MyMessage'); // or throw a ValidationError
|
|
14
|
-
* } else {
|
|
15
|
-
* data.prop2 = 'VALUE2';
|
|
16
|
-
* return data;
|
|
17
|
-
* }
|
|
18
|
-
* })
|
|
19
|
-
* class Model {
|
|
20
|
-
* @Property()
|
|
21
|
-
* prop1: string;
|
|
22
|
-
* @Property()
|
|
23
|
-
* prop2: string;
|
|
24
|
-
* }
|
|
25
|
-
* ```
|
|
26
|
-
*
|
|
27
|
-
* @returns {Function}
|
|
28
|
-
* @decorator
|
|
29
|
-
* @schema
|
|
30
|
-
* @property
|
|
31
|
-
* @param cb
|
|
32
|
-
*/
|
|
33
|
-
export declare function AfterDeserialize(cb: AfterDeserializeCallback): ClassDecorator;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { JsonHookContext } from "@tsed/schema";
|
|
2
|
-
export interface BeforeDeserializeCallback {
|
|
3
|
-
(value: any, ctx: JsonHookContext): any;
|
|
4
|
-
}
|
|
5
|
-
/**
|
|
6
|
-
* Call the function before JsonMapper.
|
|
7
|
-
*
|
|
8
|
-
* ## Example
|
|
9
|
-
*
|
|
10
|
-
* ```typescript
|
|
11
|
-
* @BeforeDeserialize((data: Record<string, unknown>) => { // Before deserialize get the data
|
|
12
|
-
* if (data.prop1 === 'VALUE' && data.prop2 !== 'VALUE2') {
|
|
13
|
-
* throw BadRequest('MyMessage'); // or throw a ValidationError
|
|
14
|
-
* } else {
|
|
15
|
-
* data.prop2 = 'VALUE2';
|
|
16
|
-
* return data;
|
|
17
|
-
* }
|
|
18
|
-
* })
|
|
19
|
-
* class Model {
|
|
20
|
-
* @Property()
|
|
21
|
-
* prop1: string;
|
|
22
|
-
* @Property()
|
|
23
|
-
* prop2: string;
|
|
24
|
-
* }
|
|
25
|
-
* ```
|
|
26
|
-
*
|
|
27
|
-
* @returns {Function}
|
|
28
|
-
* @decorator
|
|
29
|
-
* @schema
|
|
30
|
-
* @property
|
|
31
|
-
* @param cb
|
|
32
|
-
*/
|
|
33
|
-
export declare function BeforeDeserialize(cb: BeforeDeserializeCallback): ClassDecorator;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { JsonHookContext } from "@tsed/schema";
|
|
2
|
-
export interface OnDeserializeCallback {
|
|
3
|
-
(value: any, ctx: JsonHookContext): any;
|
|
4
|
-
}
|
|
5
|
-
/**
|
|
6
|
-
* Call the function before property deserialization.
|
|
7
|
-
*
|
|
8
|
-
* ## Example
|
|
9
|
-
*
|
|
10
|
-
* ```typescript
|
|
11
|
-
* class Model {
|
|
12
|
-
* @OnDeserialize(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 OnDeserialize(cb: OnDeserializeCallback): PropertyDecorator;
|
|
@@ -1,23 +0,0 @@
|
|
|
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;
|
|
@@ -1,20 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
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>;
|
package/lib/cjs/index.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
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";
|
|
@@ -1,25 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
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;
|
|
@@ -1,16 +0,0 @@
|
|
|
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;
|