@tsed/json-mapper 6.88.1 → 6.92.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.
Files changed (126) hide show
  1. package/lib/{components → cjs/components}/ArrayMapper.d.ts +0 -0
  2. package/lib/cjs/components/ArrayMapper.js +23 -0
  3. package/lib/cjs/components/ArrayMapper.js.map +1 -0
  4. package/lib/{components → cjs/components}/DateMapper.d.ts +0 -0
  5. package/lib/cjs/components/DateMapper.js +30 -0
  6. package/lib/cjs/components/DateMapper.js.map +1 -0
  7. package/lib/{components → cjs/components}/MapMapper.d.ts +0 -0
  8. package/lib/cjs/components/MapMapper.js +30 -0
  9. package/lib/cjs/components/MapMapper.js.map +1 -0
  10. package/lib/{components → cjs/components}/PrimitiveMapper.d.ts +0 -0
  11. package/lib/cjs/components/PrimitiveMapper.js +45 -0
  12. package/lib/cjs/components/PrimitiveMapper.js.map +1 -0
  13. package/lib/{components → cjs/components}/SetMapper.d.ts +0 -0
  14. package/lib/cjs/components/SetMapper.js +30 -0
  15. package/lib/cjs/components/SetMapper.js.map +1 -0
  16. package/lib/{components → cjs/components}/SymbolMapper.d.ts +0 -0
  17. package/lib/cjs/components/SymbolMapper.js +24 -0
  18. package/lib/cjs/components/SymbolMapper.js.map +1 -0
  19. package/lib/{components → cjs/components}/index.d.ts +0 -0
  20. package/lib/cjs/components/index.js +10 -0
  21. package/lib/cjs/components/index.js.map +1 -0
  22. package/lib/{decorators → cjs/decorators}/afterDeserialize.d.ts +0 -0
  23. package/lib/cjs/decorators/afterDeserialize.js +39 -0
  24. package/lib/cjs/decorators/afterDeserialize.js.map +1 -0
  25. package/lib/{decorators → cjs/decorators}/beforeDeserialize.d.ts +0 -0
  26. package/lib/cjs/decorators/beforeDeserialize.js +39 -0
  27. package/lib/cjs/decorators/beforeDeserialize.js.map +1 -0
  28. package/lib/{decorators → cjs/decorators}/jsonMapper.d.ts +0 -0
  29. package/lib/cjs/decorators/jsonMapper.js +18 -0
  30. package/lib/cjs/decorators/jsonMapper.js.map +1 -0
  31. package/lib/{decorators → cjs/decorators}/onDeserialize.d.ts +0 -0
  32. package/lib/cjs/decorators/onDeserialize.js +29 -0
  33. package/lib/cjs/decorators/onDeserialize.js.map +1 -0
  34. package/lib/{decorators → cjs/decorators}/onSerialize.d.ts +0 -0
  35. package/lib/cjs/decorators/onSerialize.js +29 -0
  36. package/lib/cjs/decorators/onSerialize.js.map +1 -0
  37. package/lib/{domain → cjs/domain}/JsonMapperContext.d.ts +0 -0
  38. package/lib/cjs/domain/JsonMapperContext.js +23 -0
  39. package/lib/cjs/domain/JsonMapperContext.js.map +1 -0
  40. package/lib/{domain → cjs/domain}/JsonMapperTypesContainer.d.ts +0 -0
  41. package/lib/cjs/domain/JsonMapperTypesContainer.js +23 -0
  42. package/lib/cjs/domain/JsonMapperTypesContainer.js.map +1 -0
  43. package/lib/{hooks → cjs/hooks}/alterAfterDeserialize.d.ts +0 -0
  44. package/lib/cjs/hooks/alterAfterDeserialize.js +9 -0
  45. package/lib/cjs/hooks/alterAfterDeserialize.js.map +1 -0
  46. package/lib/{hooks → cjs/hooks}/alterBeforeDeserialize.d.ts +0 -0
  47. package/lib/cjs/hooks/alterBeforeDeserialize.js +9 -0
  48. package/lib/cjs/hooks/alterBeforeDeserialize.js.map +1 -0
  49. package/lib/{index.d.ts → cjs/index.d.ts} +0 -0
  50. package/lib/cjs/index.js +15 -0
  51. package/lib/cjs/index.js.map +1 -0
  52. package/lib/{interfaces → cjs/interfaces}/JsonMapperMethods.d.ts +0 -0
  53. package/lib/cjs/interfaces/JsonMapperMethods.js +3 -0
  54. package/lib/cjs/interfaces/JsonMapperMethods.js.map +1 -0
  55. package/lib/{utils → cjs/utils}/deserialize.d.ts +0 -0
  56. package/lib/cjs/utils/deserialize.js +140 -0
  57. package/lib/cjs/utils/deserialize.js.map +1 -0
  58. package/lib/{utils → cjs/utils}/serialize.d.ts +0 -0
  59. package/lib/cjs/utils/serialize.js +112 -0
  60. package/lib/cjs/utils/serialize.js.map +1 -0
  61. package/lib/esm/components/ArrayMapper.js +20 -0
  62. package/lib/esm/components/ArrayMapper.js.map +1 -0
  63. package/lib/esm/components/DateMapper.js +27 -0
  64. package/lib/esm/components/DateMapper.js.map +1 -0
  65. package/lib/esm/components/MapMapper.js +27 -0
  66. package/lib/esm/components/MapMapper.js.map +1 -0
  67. package/lib/esm/components/PrimitiveMapper.js +42 -0
  68. package/lib/esm/components/PrimitiveMapper.js.map +1 -0
  69. package/lib/esm/components/SetMapper.js +27 -0
  70. package/lib/esm/components/SetMapper.js.map +1 -0
  71. package/lib/esm/components/SymbolMapper.js +21 -0
  72. package/lib/esm/components/SymbolMapper.js.map +1 -0
  73. package/lib/esm/components/index.js +7 -0
  74. package/lib/esm/components/index.js.map +1 -0
  75. package/lib/esm/decorators/afterDeserialize.js +35 -0
  76. package/lib/esm/decorators/afterDeserialize.js.map +1 -0
  77. package/lib/esm/decorators/beforeDeserialize.js +35 -0
  78. package/lib/esm/decorators/beforeDeserialize.js.map +1 -0
  79. package/lib/esm/decorators/jsonMapper.js +14 -0
  80. package/lib/esm/decorators/jsonMapper.js.map +1 -0
  81. package/lib/esm/decorators/onDeserialize.js +25 -0
  82. package/lib/esm/decorators/onDeserialize.js.map +1 -0
  83. package/lib/esm/decorators/onSerialize.js +25 -0
  84. package/lib/esm/decorators/onSerialize.js.map +1 -0
  85. package/lib/esm/domain/JsonMapperContext.js +19 -0
  86. package/lib/esm/domain/JsonMapperContext.js.map +1 -0
  87. package/lib/esm/domain/JsonMapperTypesContainer.js +18 -0
  88. package/lib/esm/domain/JsonMapperTypesContainer.js.map +1 -0
  89. package/lib/esm/hooks/alterAfterDeserialize.js +5 -0
  90. package/lib/esm/hooks/alterAfterDeserialize.js.map +1 -0
  91. package/lib/esm/hooks/alterBeforeDeserialize.js +5 -0
  92. package/lib/esm/hooks/alterBeforeDeserialize.js.map +1 -0
  93. package/lib/esm/index.js +12 -0
  94. package/lib/esm/index.js.map +1 -0
  95. package/lib/esm/interfaces/JsonMapperMethods.js +2 -0
  96. package/lib/esm/interfaces/JsonMapperMethods.js.map +1 -0
  97. package/lib/esm/utils/deserialize.js +135 -0
  98. package/lib/esm/utils/deserialize.js.map +1 -0
  99. package/lib/esm/utils/serialize.js +107 -0
  100. package/lib/esm/utils/serialize.js.map +1 -0
  101. package/lib/types/components/ArrayMapper.d.ts +10 -0
  102. package/lib/types/components/DateMapper.d.ts +11 -0
  103. package/lib/types/components/MapMapper.d.ts +12 -0
  104. package/lib/types/components/PrimitiveMapper.d.ts +10 -0
  105. package/lib/types/components/SetMapper.d.ts +10 -0
  106. package/lib/types/components/SymbolMapper.d.ts +11 -0
  107. package/lib/types/components/index.d.ts +6 -0
  108. package/lib/types/decorators/afterDeserialize.d.ts +33 -0
  109. package/lib/types/decorators/beforeDeserialize.d.ts +33 -0
  110. package/lib/types/decorators/jsonMapper.d.ts +7 -0
  111. package/lib/types/decorators/onDeserialize.d.ts +23 -0
  112. package/lib/types/decorators/onSerialize.d.ts +23 -0
  113. package/lib/types/domain/JsonMapperContext.d.ts +20 -0
  114. package/lib/types/domain/JsonMapperTypesContainer.d.ts +10 -0
  115. package/lib/types/hooks/alterAfterDeserialize.d.ts +4 -0
  116. package/lib/types/hooks/alterBeforeDeserialize.d.ts +4 -0
  117. package/lib/types/index.d.ts +11 -0
  118. package/lib/types/interfaces/JsonMapperMethods.d.ts +25 -0
  119. package/lib/types/utils/deserialize.d.ts +41 -0
  120. package/lib/types/utils/serialize.d.ts +16 -0
  121. package/package.json +18 -14
  122. package/tsconfig.compile.esm.json +23 -0
  123. package/lib/index.js +0 -719
  124. package/lib/index.js.map +0 -1
  125. package/lib/index.modern.js +0 -708
  126. 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,4 @@
1
+ import { Hooks } from "@tsed/core";
2
+ export declare function alterAfterDeserialize(data: any, schema: {
3
+ $hooks: Hooks;
4
+ }, options: any): any;
@@ -0,0 +1,4 @@
1
+ import { Hooks } from "@tsed/core";
2
+ export declare function alterBeforeDeserialize(data: any, schema: {
3
+ $hooks: Hooks;
4
+ }, options: any): any;
@@ -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.88.1",
3
+ "version": "6.92.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
- "require": "./lib/index.js",
11
- "default": "./lib/index.modern.js"
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.88.1",
33
- "@tsed/exceptions": "6.88.1",
34
- "@tsed/schema": "6.88.1"
36
+ "@tsed/core": "6.92.0",
37
+ "@tsed/exceptions": "6.92.0",
38
+ "@tsed/schema": "6.92.0"
35
39
  },
36
40
  "peerDependencies": {
37
- "@tsed/core": "^6.88.1",
38
- "@tsed/exceptions": "^6.88.1",
39
- "@tsed/schema": "^6.88.1"
41
+ "@tsed/core": "^6.92.0",
42
+ "@tsed/exceptions": "^6.92.0",
43
+ "@tsed/schema": "^6.92.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
+ }