@tsed/json-mapper 8.11.0 → 8.11.2-rc.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/lib/esm/components/DateMapper.js +0 -1
- package/lib/esm/components/PrimitiveMapper.js +0 -1
- package/lib/esm/components/SymbolMapper.js +0 -1
- package/lib/esm/decorators/afterDeserialize.js +0 -1
- package/lib/esm/decorators/beforeDeserialize.js +0 -1
- package/lib/esm/decorators/jsonMapper.js +0 -1
- package/lib/esm/decorators/onDeserialize.js +0 -1
- package/lib/esm/decorators/onSerialize.js +0 -1
- package/lib/esm/domain/JsonDeserializer.js +0 -1
- package/lib/esm/domain/JsonDeserializerOptions.js +0 -1
- package/lib/esm/domain/JsonMapperCompiler.js +0 -1
- package/lib/esm/domain/JsonMapperGlobalOptions.js +0 -1
- package/lib/esm/domain/JsonMapperSettings.js +0 -1
- package/lib/esm/domain/JsonMapperTypesContainer.js +0 -1
- package/lib/esm/domain/JsonSerializer.js +0 -1
- package/lib/esm/domain/JsonSerializerOptions.js +0 -1
- package/lib/esm/domain/Writer.js +0 -1
- package/lib/esm/hooks/alterAfterDeserialize.js +0 -1
- package/lib/esm/hooks/alterBeforeDeserialize.js +0 -1
- package/lib/esm/hooks/alterOnDeserialize.js +0 -1
- package/lib/esm/hooks/alterOnSerialize.js +0 -1
- package/lib/esm/index.js +0 -1
- package/lib/esm/interfaces/JsonMapperMethods.js +0 -1
- package/lib/esm/utils/deserialize.js +0 -1
- package/lib/esm/utils/getObjectProperties.js +0 -1
- package/lib/esm/utils/serialize.js +0 -1
- package/package.json +12 -11
- package/lib/browser/components/DateMapper.js +0 -22
- package/lib/browser/components/DateMapper.js.map +0 -1
- package/lib/browser/components/PrimitiveMapper.js +0 -52
- package/lib/browser/components/PrimitiveMapper.js.map +0 -1
- package/lib/browser/components/SymbolMapper.js +0 -21
- package/lib/browser/components/SymbolMapper.js.map +0 -1
- package/lib/browser/decorators/afterDeserialize.js +0 -10
- package/lib/browser/decorators/afterDeserialize.js.map +0 -1
- package/lib/browser/decorators/beforeDeserialize.js +0 -10
- package/lib/browser/decorators/beforeDeserialize.js.map +0 -1
- package/lib/browser/decorators/jsonMapper.js +0 -12
- package/lib/browser/decorators/jsonMapper.js.map +0 -1
- package/lib/browser/decorators/onDeserialize.js +0 -10
- package/lib/browser/decorators/onDeserialize.js.map +0 -1
- package/lib/browser/decorators/onSerialize.js +0 -10
- package/lib/browser/decorators/onSerialize.js.map +0 -1
- package/lib/browser/domain/JsonDeserializer.js +0 -179
- package/lib/browser/domain/JsonDeserializer.js.map +0 -1
- package/lib/browser/domain/JsonDeserializerOptions.js +0 -2
- package/lib/browser/domain/JsonDeserializerOptions.js.map +0 -1
- package/lib/browser/domain/JsonMapperCompiler.js +0 -110
- package/lib/browser/domain/JsonMapperCompiler.js.map +0 -1
- package/lib/browser/domain/JsonMapperGlobalOptions.js +0 -2
- package/lib/browser/domain/JsonMapperGlobalOptions.js.map +0 -1
- package/lib/browser/domain/JsonMapperSettings.js +0 -9
- package/lib/browser/domain/JsonMapperSettings.js.map +0 -1
- package/lib/browser/domain/JsonMapperTypesContainer.js +0 -12
- package/lib/browser/domain/JsonMapperTypesContainer.js.map +0 -1
- package/lib/browser/domain/JsonSerializer.js +0 -164
- package/lib/browser/domain/JsonSerializer.js.map +0 -1
- package/lib/browser/domain/JsonSerializerOptions.js +0 -2
- package/lib/browser/domain/JsonSerializerOptions.js.map +0 -1
- package/lib/browser/domain/Writer.js +0 -124
- package/lib/browser/domain/Writer.js.map +0 -1
- package/lib/browser/hooks/alterAfterDeserialize.js +0 -8
- package/lib/browser/hooks/alterAfterDeserialize.js.map +0 -1
- package/lib/browser/hooks/alterBeforeDeserialize.js +0 -8
- package/lib/browser/hooks/alterBeforeDeserialize.js.map +0 -1
- package/lib/browser/hooks/alterOnDeserialize.js +0 -7
- package/lib/browser/hooks/alterOnDeserialize.js.map +0 -1
- package/lib/browser/hooks/alterOnSerialize.js +0 -7
- package/lib/browser/hooks/alterOnSerialize.js.map +0 -1
- package/lib/browser/index.js +0 -47
- package/lib/browser/index.js.map +0 -1
- package/lib/browser/utils/deserialize.js +0 -12
- package/lib/browser/utils/deserialize.js.map +0 -1
- package/lib/browser/utils/getObjectProperties.js +0 -8
- package/lib/browser/utils/getObjectProperties.js.map +0 -1
- package/lib/browser/utils/serialize.js +0 -12
- package/lib/browser/utils/serialize.js.map +0 -1
- package/lib/esm/components/DateMapper.js.map +0 -1
- package/lib/esm/components/PrimitiveMapper.js.map +0 -1
- package/lib/esm/components/SymbolMapper.js.map +0 -1
- package/lib/esm/decorators/afterDeserialize.js.map +0 -1
- package/lib/esm/decorators/beforeDeserialize.js.map +0 -1
- package/lib/esm/decorators/jsonMapper.js.map +0 -1
- package/lib/esm/decorators/onDeserialize.js.map +0 -1
- package/lib/esm/decorators/onSerialize.js.map +0 -1
- package/lib/esm/domain/JsonDeserializer.js.map +0 -1
- package/lib/esm/domain/JsonDeserializerOptions.js.map +0 -1
- package/lib/esm/domain/JsonMapperCompiler.js.map +0 -1
- package/lib/esm/domain/JsonMapperGlobalOptions.js.map +0 -1
- package/lib/esm/domain/JsonMapperSettings.js.map +0 -1
- package/lib/esm/domain/JsonMapperTypesContainer.js.map +0 -1
- package/lib/esm/domain/JsonSerializer.js.map +0 -1
- package/lib/esm/domain/JsonSerializerOptions.js.map +0 -1
- package/lib/esm/domain/Writer.js.map +0 -1
- package/lib/esm/hooks/alterAfterDeserialize.js.map +0 -1
- package/lib/esm/hooks/alterBeforeDeserialize.js.map +0 -1
- package/lib/esm/hooks/alterOnDeserialize.js.map +0 -1
- package/lib/esm/hooks/alterOnSerialize.js.map +0 -1
- package/lib/esm/index.js.map +0 -1
- package/lib/esm/interfaces/JsonMapperMethods.js.map +0 -1
- package/lib/esm/utils/deserialize.js.map +0 -1
- package/lib/esm/utils/getObjectProperties.js.map +0 -1
- package/lib/esm/utils/serialize.js.map +0 -1
- package/src/components/DateMapper.spec.ts +0 -43
- package/src/components/DateMapper.ts +0 -29
- package/src/components/PrimitiveMapper.spec.ts +0 -179
- package/src/components/PrimitiveMapper.ts +0 -64
- package/src/components/SymbolMapper.spec.ts +0 -23
- package/src/components/SymbolMapper.ts +0 -19
- package/src/decorators/afterDeserialize.ts +0 -39
- package/src/decorators/beforeDeserialize.ts +0 -39
- package/src/decorators/jsonMapper.ts +0 -16
- package/src/decorators/onDeserialize.ts +0 -29
- package/src/decorators/onSerialize.ts +0 -29
- package/src/domain/JsonDeserializer.spec.ts +0 -1437
- package/src/domain/JsonDeserializer.ts +0 -402
- package/src/domain/JsonDeserializerOptions.ts +0 -31
- package/src/domain/JsonMapperCompiler.ts +0 -247
- package/src/domain/JsonMapperGlobalOptions.ts +0 -14
- package/src/domain/JsonMapperSettings.ts +0 -7
- package/src/domain/JsonMapperTypesContainer.ts +0 -20
- package/src/domain/JsonSerializer.spec.ts +0 -1506
- package/src/domain/JsonSerializer.ts +0 -371
- package/src/domain/JsonSerializerOptions.ts +0 -17
- package/src/domain/Writer.spec.ts +0 -11
- package/src/domain/Writer.ts +0 -181
- package/src/domain/__snapshots__/Writer.spec.ts.snap +0 -10
- package/src/hooks/alterAfterDeserialize.ts +0 -5
- package/src/hooks/alterBeforeDeserialize.ts +0 -5
- package/src/hooks/alterOnDeserialize.ts +0 -5
- package/src/hooks/alterOnSerialize.ts +0 -5
- package/src/index.ts +0 -28
- package/src/interfaces/JsonMapperMethods.ts +0 -32
- package/src/utils/deserialize.spec.ts +0 -33
- package/src/utils/deserialize.ts +0 -12
- package/src/utils/getObjectProperties.ts +0 -5
- package/src/utils/serialize.spec.ts +0 -37
- package/src/utils/serialize.ts +0 -12
- package/vite.config.mts +0 -45
- package/vitest.config.mts +0 -21
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import {SymbolMapper} from "./SymbolMapper.js";
|
|
2
|
-
|
|
3
|
-
describe("SymbolMapper", () => {
|
|
4
|
-
describe("deserialize()", () => {
|
|
5
|
-
it("should return value", () => {
|
|
6
|
-
const mapper = new SymbolMapper();
|
|
7
|
-
|
|
8
|
-
const value = mapper.deserialize("SYMBOL");
|
|
9
|
-
|
|
10
|
-
expect(typeof value).toEqual("symbol");
|
|
11
|
-
expect(value.toString()).toEqual("Symbol(SYMBOL)");
|
|
12
|
-
});
|
|
13
|
-
});
|
|
14
|
-
describe("serialize()", () => {
|
|
15
|
-
it("should return value", () => {
|
|
16
|
-
const mapper = new SymbolMapper();
|
|
17
|
-
|
|
18
|
-
const value = mapper.serialize(Symbol.for("SYMBOL"));
|
|
19
|
-
|
|
20
|
-
expect(value).toEqual("SYMBOL");
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
});
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import {JsonMapper} from "../decorators/jsonMapper.js";
|
|
2
|
-
import {JsonMapperMethods} from "../interfaces/JsonMapperMethods.js";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Mapper for the `Symbol` type.
|
|
6
|
-
*
|
|
7
|
-
* @jsonmapper
|
|
8
|
-
* @component
|
|
9
|
-
*/
|
|
10
|
-
@JsonMapper(Symbol)
|
|
11
|
-
export class SymbolMapper implements JsonMapperMethods {
|
|
12
|
-
deserialize(data: string): symbol {
|
|
13
|
-
return Symbol.for(data);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
serialize(object: Symbol): any {
|
|
17
|
-
return object.toString().replace("Symbol(", "").replace(")", "");
|
|
18
|
-
}
|
|
19
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import {JsonEntityFn, JsonHookContext} from "@tsed/schema";
|
|
2
|
-
|
|
3
|
-
export interface AfterDeserializeCallback {
|
|
4
|
-
(value: any, ctx: JsonHookContext): any;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Call the function after JsonMapper.
|
|
9
|
-
*
|
|
10
|
-
* ## Example
|
|
11
|
-
*
|
|
12
|
-
* ```typescript
|
|
13
|
-
* @AfterDeserialize((data: Model) => { // After deserialize get the instance class
|
|
14
|
-
* if (data.prop1 === 'VALUE' && data.prop2 !== 'VALUE2') {
|
|
15
|
-
* throw BadRequest('MyMessage'); // or throw a ValidationError
|
|
16
|
-
* } else {
|
|
17
|
-
* data.prop2 = 'VALUE2';
|
|
18
|
-
* return data;
|
|
19
|
-
* }
|
|
20
|
-
* })
|
|
21
|
-
* class Model {
|
|
22
|
-
* @Property()
|
|
23
|
-
* prop1: string;
|
|
24
|
-
* @Property()
|
|
25
|
-
* prop2: string;
|
|
26
|
-
* }
|
|
27
|
-
* ```
|
|
28
|
-
*
|
|
29
|
-
* @returns {Function}
|
|
30
|
-
* @decorator
|
|
31
|
-
* @schema
|
|
32
|
-
* @property
|
|
33
|
-
* @param cb
|
|
34
|
-
*/
|
|
35
|
-
export function AfterDeserialize(cb: AfterDeserializeCallback): ClassDecorator {
|
|
36
|
-
return JsonEntityFn((storedJson) => {
|
|
37
|
-
storedJson.schema.$hooks.on("afterDeserialize", cb);
|
|
38
|
-
});
|
|
39
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import {JsonEntityFn, JsonHookContext} from "@tsed/schema";
|
|
2
|
-
|
|
3
|
-
export interface BeforeDeserializeCallback {
|
|
4
|
-
(value: any, ctx: JsonHookContext): any;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Call the function before JsonMapper.
|
|
9
|
-
*
|
|
10
|
-
* ## Example
|
|
11
|
-
*
|
|
12
|
-
* ```typescript
|
|
13
|
-
* @BeforeDeserialize((data: Record<string, unknown>) => { // Before deserialize get the data
|
|
14
|
-
* if (data.prop1 === 'VALUE' && data.prop2 !== 'VALUE2') {
|
|
15
|
-
* throw BadRequest('MyMessage'); // or throw a ValidationError
|
|
16
|
-
* } else {
|
|
17
|
-
* data.prop2 = 'VALUE2';
|
|
18
|
-
* return data;
|
|
19
|
-
* }
|
|
20
|
-
* })
|
|
21
|
-
* class Model {
|
|
22
|
-
* @Property()
|
|
23
|
-
* prop1: string;
|
|
24
|
-
* @Property()
|
|
25
|
-
* prop2: string;
|
|
26
|
-
* }
|
|
27
|
-
* ```
|
|
28
|
-
*
|
|
29
|
-
* @returns {Function}
|
|
30
|
-
* @decorator
|
|
31
|
-
* @schema
|
|
32
|
-
* @property
|
|
33
|
-
* @param cb
|
|
34
|
-
*/
|
|
35
|
-
export function BeforeDeserialize(cb: BeforeDeserializeCallback): ClassDecorator {
|
|
36
|
-
return JsonEntityFn((storedJson) => {
|
|
37
|
-
storedJson.schema.$hooks.on("beforeDeserialize", cb);
|
|
38
|
-
});
|
|
39
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import {Type} from "@tsed/core";
|
|
2
|
-
|
|
3
|
-
import {registerJsonTypeMapper} from "../domain/JsonMapperTypesContainer.js";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Register a new JsonMapper Type
|
|
7
|
-
* @param types
|
|
8
|
-
* @constructor
|
|
9
|
-
*/
|
|
10
|
-
export function JsonMapper(...types: (any | Type)[]): ClassDecorator {
|
|
11
|
-
return (target) => {
|
|
12
|
-
types.forEach((type) => {
|
|
13
|
-
registerJsonTypeMapper(type, target as any);
|
|
14
|
-
});
|
|
15
|
-
};
|
|
16
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import {JsonEntityFn, JsonHookContext} from "@tsed/schema";
|
|
2
|
-
|
|
3
|
-
export interface OnDeserializeCallback {
|
|
4
|
-
(value: any, ctx: JsonHookContext): any;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Call the function before property deserialization.
|
|
9
|
-
*
|
|
10
|
-
* ## Example
|
|
11
|
-
*
|
|
12
|
-
* ```typescript
|
|
13
|
-
* class Model {
|
|
14
|
-
* @OnDeserialize(v => v + 1)
|
|
15
|
-
* property: string;
|
|
16
|
-
* }
|
|
17
|
-
* ```
|
|
18
|
-
*
|
|
19
|
-
* @returns {Function}
|
|
20
|
-
* @decorator
|
|
21
|
-
* @schema
|
|
22
|
-
* @property
|
|
23
|
-
* @param cb
|
|
24
|
-
*/
|
|
25
|
-
export function OnDeserialize(cb: OnDeserializeCallback): PropertyDecorator {
|
|
26
|
-
return JsonEntityFn((storedJson) => {
|
|
27
|
-
storedJson.schema.$hooks.on("onDeserialize", cb);
|
|
28
|
-
});
|
|
29
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import {JsonEntityFn, JsonHookContext} from "@tsed/schema";
|
|
2
|
-
|
|
3
|
-
export interface OnSerializeCallback {
|
|
4
|
-
(value: any, ctx: JsonHookContext): any;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Call the function before property serialization.
|
|
9
|
-
*
|
|
10
|
-
* ## Example
|
|
11
|
-
*
|
|
12
|
-
* ```typescript
|
|
13
|
-
* class Model {
|
|
14
|
-
* @OnSerialize(v => v + 1)
|
|
15
|
-
* property: string;
|
|
16
|
-
* }
|
|
17
|
-
* ```
|
|
18
|
-
*
|
|
19
|
-
* @returns {Function}
|
|
20
|
-
* @decorator
|
|
21
|
-
* @schema
|
|
22
|
-
* @property
|
|
23
|
-
* @param cb
|
|
24
|
-
*/
|
|
25
|
-
export function OnSerialize(cb: OnSerializeCallback): PropertyDecorator {
|
|
26
|
-
return JsonEntityFn((storedJson) => {
|
|
27
|
-
storedJson.schema.$hooks.on("onSerialize", cb);
|
|
28
|
-
});
|
|
29
|
-
}
|