@tsed/json-mapper 7.35.0-rc.1 → 7.35.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.
Files changed (97) hide show
  1. package/jest.config.js +3 -3
  2. package/lib/browser/json-mapper.umd.min.js +1 -1
  3. package/lib/browser/json-mapper.umd.min.js.map +1 -1
  4. package/lib/cjs/components/ArrayMapper.js +23 -0
  5. package/lib/cjs/components/ArrayMapper.js.map +1 -0
  6. package/lib/cjs/components/DateMapper.js +1 -1
  7. package/lib/cjs/components/DateMapper.js.map +1 -1
  8. package/lib/cjs/components/MapMapper.js +30 -0
  9. package/lib/cjs/components/MapMapper.js.map +1 -0
  10. package/lib/cjs/components/PrimitiveMapper.js +26 -30
  11. package/lib/cjs/components/PrimitiveMapper.js.map +1 -1
  12. package/lib/cjs/components/SetMapper.js +30 -0
  13. package/lib/cjs/components/SetMapper.js.map +1 -0
  14. package/lib/cjs/components/SymbolMapper.js.map +1 -1
  15. package/lib/cjs/domain/JsonMapperContext.js +27 -0
  16. package/lib/cjs/domain/JsonMapperContext.js.map +1 -0
  17. package/lib/cjs/index.js +4 -9
  18. package/lib/cjs/index.js.map +1 -1
  19. package/lib/cjs/utils/deserialize.js +202 -5
  20. package/lib/cjs/utils/deserialize.js.map +1 -1
  21. package/lib/cjs/utils/serialize.js +143 -5
  22. package/lib/cjs/utils/serialize.js.map +1 -1
  23. package/lib/esm/components/ArrayMapper.js +20 -0
  24. package/lib/esm/components/ArrayMapper.js.map +1 -0
  25. package/lib/esm/components/DateMapper.js +1 -1
  26. package/lib/esm/components/DateMapper.js.map +1 -1
  27. package/lib/esm/components/MapMapper.js +27 -0
  28. package/lib/esm/components/MapMapper.js.map +1 -0
  29. package/lib/esm/components/PrimitiveMapper.js +26 -30
  30. package/lib/esm/components/PrimitiveMapper.js.map +1 -1
  31. package/lib/esm/components/SetMapper.js +27 -0
  32. package/lib/esm/components/SetMapper.js.map +1 -0
  33. package/lib/esm/components/SymbolMapper.js.map +1 -1
  34. package/lib/esm/domain/JsonMapperContext.js +23 -0
  35. package/lib/esm/domain/JsonMapperContext.js.map +1 -0
  36. package/lib/esm/index.js +4 -9
  37. package/lib/esm/index.js.map +1 -1
  38. package/lib/esm/utils/deserialize.js +200 -4
  39. package/lib/esm/utils/deserialize.js.map +1 -1
  40. package/lib/esm/utils/serialize.js +141 -4
  41. package/lib/esm/utils/serialize.js.map +1 -1
  42. package/lib/tsconfig.esm.tsbuildinfo +1 -1
  43. package/lib/tsconfig.tsbuildinfo +1 -1
  44. package/lib/types/components/ArrayMapper.d.ts +10 -0
  45. package/lib/types/components/MapMapper.d.ts +12 -0
  46. package/lib/types/components/PrimitiveMapper.d.ts +0 -4
  47. package/lib/types/components/SetMapper.d.ts +10 -0
  48. package/lib/types/domain/JsonMapperContext.d.ts +20 -0
  49. package/lib/types/index.d.ts +4 -9
  50. package/lib/types/utils/deserialize.d.ts +47 -2
  51. package/lib/types/utils/serialize.d.ts +18 -2
  52. package/package.json +8 -11
  53. package/lib/cjs/domain/JsonDeserializer.js +0 -275
  54. package/lib/cjs/domain/JsonDeserializer.js.map +0 -1
  55. package/lib/cjs/domain/JsonDeserializerOptions.js +0 -3
  56. package/lib/cjs/domain/JsonDeserializerOptions.js.map +0 -1
  57. package/lib/cjs/domain/JsonMapperCompiler.js +0 -167
  58. package/lib/cjs/domain/JsonMapperCompiler.js.map +0 -1
  59. package/lib/cjs/domain/JsonSerializer.js +0 -219
  60. package/lib/cjs/domain/JsonSerializer.js.map +0 -1
  61. package/lib/cjs/domain/JsonSerializerOptions.js +0 -3
  62. package/lib/cjs/domain/JsonSerializerOptions.js.map +0 -1
  63. package/lib/cjs/domain/Writer.js +0 -141
  64. package/lib/cjs/domain/Writer.js.map +0 -1
  65. package/lib/cjs/hooks/alterOnDeserialize.js +0 -8
  66. package/lib/cjs/hooks/alterOnDeserialize.js.map +0 -1
  67. package/lib/cjs/hooks/alterOnSerialize.js +0 -8
  68. package/lib/cjs/hooks/alterOnSerialize.js.map +0 -1
  69. package/lib/cjs/utils/getObjectProperties.js +0 -9
  70. package/lib/cjs/utils/getObjectProperties.js.map +0 -1
  71. package/lib/esm/domain/JsonDeserializer.js +0 -271
  72. package/lib/esm/domain/JsonDeserializer.js.map +0 -1
  73. package/lib/esm/domain/JsonDeserializerOptions.js +0 -2
  74. package/lib/esm/domain/JsonDeserializerOptions.js.map +0 -1
  75. package/lib/esm/domain/JsonMapperCompiler.js +0 -163
  76. package/lib/esm/domain/JsonMapperCompiler.js.map +0 -1
  77. package/lib/esm/domain/JsonSerializer.js +0 -215
  78. package/lib/esm/domain/JsonSerializer.js.map +0 -1
  79. package/lib/esm/domain/JsonSerializerOptions.js +0 -2
  80. package/lib/esm/domain/JsonSerializerOptions.js.map +0 -1
  81. package/lib/esm/domain/Writer.js +0 -137
  82. package/lib/esm/domain/Writer.js.map +0 -1
  83. package/lib/esm/hooks/alterOnDeserialize.js +0 -4
  84. package/lib/esm/hooks/alterOnDeserialize.js.map +0 -1
  85. package/lib/esm/hooks/alterOnSerialize.js +0 -4
  86. package/lib/esm/hooks/alterOnSerialize.js.map +0 -1
  87. package/lib/esm/utils/getObjectProperties.js +0 -5
  88. package/lib/esm/utils/getObjectProperties.js.map +0 -1
  89. package/lib/types/domain/JsonDeserializer.d.ts +0 -33
  90. package/lib/types/domain/JsonDeserializerOptions.d.ts +0 -31
  91. package/lib/types/domain/JsonMapperCompiler.d.ts +0 -58
  92. package/lib/types/domain/JsonSerializer.d.ts +0 -21
  93. package/lib/types/domain/JsonSerializerOptions.d.ts +0 -13
  94. package/lib/types/domain/Writer.d.ts +0 -43
  95. package/lib/types/hooks/alterOnDeserialize.d.ts +0 -2
  96. package/lib/types/hooks/alterOnSerialize.d.ts +0 -2
  97. package/lib/types/utils/getObjectProperties.d.ts +0 -1
@@ -1,5 +1,4 @@
1
1
  import { __decorate } from "tslib";
2
- import { nameOf } from "@tsed/core";
3
2
  import { JsonMapper } from "../decorators/jsonMapper.js";
4
3
  function isNullish(data) {
5
4
  return [null, "null"].includes(data);
@@ -17,39 +16,36 @@ export class CastError extends Error {
17
16
  */
18
17
  let PrimitiveMapper = class PrimitiveMapper {
19
18
  deserialize(data, ctx) {
20
- return this[nameOf(ctx.type)] ? this[nameOf(ctx.type)](data, ctx) : undefined;
19
+ switch (ctx.type) {
20
+ case String:
21
+ return data === null ? null : "" + data;
22
+ case BigInt:
23
+ if (isNullish(data))
24
+ return null;
25
+ return BigInt(data);
26
+ case Number:
27
+ if (isNullish(data))
28
+ return null;
29
+ const n = +data;
30
+ if (isNaN(n)) {
31
+ throw new CastError("Expression value is not a number.");
32
+ }
33
+ return n;
34
+ case Boolean:
35
+ if (["true", "1", true].includes(data))
36
+ return true;
37
+ if (["false", "0", false].includes(data))
38
+ return false;
39
+ if (isNullish(data))
40
+ return null;
41
+ if (data === undefined)
42
+ return undefined;
43
+ return !!data;
44
+ }
21
45
  }
22
46
  serialize(object) {
23
47
  return object;
24
48
  }
25
- String(data) {
26
- return data === null ? null : "" + data;
27
- }
28
- Boolean(data) {
29
- if (["true", "1", true].includes(data))
30
- return true;
31
- if (["false", "0", false].includes(data))
32
- return false;
33
- if (isNullish(data))
34
- return null;
35
- if (data === undefined)
36
- return undefined;
37
- return !!data;
38
- }
39
- Number(data) {
40
- if (isNullish(data))
41
- return null;
42
- const n = +data;
43
- if (isNaN(n)) {
44
- throw new CastError("Expression value is not a number.");
45
- }
46
- return n;
47
- }
48
- BigInt(data) {
49
- if (isNullish(data))
50
- return null;
51
- return BigInt(data);
52
- }
53
49
  };
54
50
  PrimitiveMapper = __decorate([
55
51
  JsonMapper(String, Number, Boolean, BigInt)
@@ -1 +1 @@
1
- {"version":3,"file":"PrimitiveMapper.js","sourceRoot":"","sources":["../../../src/components/PrimitiveMapper.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,YAAY,CAAC;AAClC,OAAO,EAAC,UAAU,EAAC,MAAM,0BAA0B,CAAC;AAGpD,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AC,CAAC;YAEtB,KAAK,MAAM;gBACT,IAAI,SAAS,CAAC,IAAI,CAAC;oBAAE,OAAO,IAAI,CAAC;gBAEjC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC;gBAEhB,IAAI,KAAK,CAAC,CAAC,CAAC,EAAE;oBACZ,MAAM,IAAI,SAAS,CAAC,mCAAmC,CAAC,CAAC;iBAC1D;gBAED,OAAO,CAAC,CAAC;YAEX,KAAK,OAAO;gBACV,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC;oBAAE,OAAO,IAAI,CAAC;gBACpD,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC;oBAAE,OAAO,KAAK,CAAC;gBACvD,IAAI,SAAS,CAAC,IAAI,CAAC;oBAAE,OAAO,IAAI,CAAC;gBACjC,IAAI,IAAI,KAAK,SAAS;oBAAE,OAAO,SAAS,CAAC;gBAEzC,OAAO,CAAC,CAAC,IAAI,CAAC;SACjB;IACH,CAAC;IAED,SAAS,CAAC,MAA0C;QAClD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF,CAAA;AAnCY,eAAe;IAD3B,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC;GAC/B,eAAe,CAmC3B;SAnCY,eAAe"}
@@ -0,0 +1,27 @@
1
+ import { __decorate } from "tslib";
2
+ import { objectKeys } from "@tsed/core";
3
+ import { JsonMapper } from "../decorators/jsonMapper.js";
4
+ /**
5
+ * Mapper for the `Set` Type.
6
+ * @jsonmapper
7
+ * @component
8
+ */
9
+ let SetMapper = class SetMapper {
10
+ deserialize(data, ctx) {
11
+ const obj = new Set();
12
+ objectKeys(data).forEach((key) => {
13
+ obj.add(ctx.next(data[key]));
14
+ });
15
+ return obj;
16
+ }
17
+ serialize(data, ctx) {
18
+ const array = [];
19
+ data.forEach((value) => array.push(ctx.next(value)));
20
+ return array;
21
+ }
22
+ };
23
+ SetMapper = __decorate([
24
+ JsonMapper(Set)
25
+ ], SetMapper);
26
+ export { SetMapper };
27
+ //# sourceMappingURL=SetMapper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SetMapper.js","sourceRoot":"","sources":["../../../src/components/SetMapper.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,YAAY,CAAC;AACtC,OAAO,EAAC,UAAU,EAAC,MAAM,0BAA0B,CAAC;AAGpD;;;;GAIG;AAEH,IAAa,SAAS,GAAtB,MAAa,SAAS;IACpB,WAAW,CAAI,IAAS,EAAE,GAAkB;QAC1C,MAAM,GAAG,GAAG,IAAI,GAAG,EAAK,CAAC;QAEzB,UAAU,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;YAC/B,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAC/B,CAAC,CAAC,CAAC;QAEH,OAAO,GAAG,CAAC;IACb,CAAC;IAED,SAAS,CAAI,IAAY,EAAE,GAAkB;QAC3C,MAAM,KAAK,GAAU,EAAE,CAAC;QAExB,IAAI,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAErD,OAAO,KAAK,CAAC;IACf,CAAC;CACF,CAAA;AAlBY,SAAS;IADrB,UAAU,CAAC,GAAG,CAAC;GACH,SAAS,CAkBrB;SAlBY,SAAS"}
@@ -1 +1 @@
1
- {"version":3,"file":"SymbolMapper.js","sourceRoot":"","sources":["../../../src/components/SymbolMapper.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,0BAA0B,CAAC;AAGpD;;;;;GAKG;AAEI,IAAM,YAAY,GAAlB,MAAM,YAAY;IACvB,WAAW,CAAC,IAAY;QACtB,OAAO,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;IAED,SAAS,CAAC,MAAc;QACtB,OAAO,MAAM,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;IACnE,CAAC;CACF,CAAA;AARY,YAAY;IADxB,UAAU,CAAC,MAAM,CAAC;GACN,YAAY,CAQxB;SARY,YAAY"}
1
+ {"version":3,"file":"SymbolMapper.js","sourceRoot":"","sources":["../../../src/components/SymbolMapper.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,0BAA0B,CAAC;AAGpD;;;;;GAKG;AAEH,IAAa,YAAY,GAAzB,MAAa,YAAY;IACvB,WAAW,CAAC,IAAY;QACtB,OAAO,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;IAED,SAAS,CAAC,MAAc;QACtB,OAAO,MAAM,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;IACnE,CAAC;CACF,CAAA;AARY,YAAY;IADxB,UAAU,CAAC,MAAM,CAAC;GACN,YAAY,CAQxB;SARY,YAAY"}
@@ -0,0 +1,23 @@
1
+ import { isCollection } from "@tsed/core";
2
+ /**
3
+ * @ignore
4
+ */
5
+ export class JsonMapperContext {
6
+ collectionType;
7
+ type;
8
+ options;
9
+ _next;
10
+ constructor({ type, collectionType, next, options }) {
11
+ this.type = type;
12
+ this.collectionType = isCollection(collectionType) ? collectionType : undefined;
13
+ this._next = next;
14
+ this.options = options;
15
+ }
16
+ next(data) {
17
+ return this._next(data, {
18
+ ...this.options,
19
+ type: this.type
20
+ });
21
+ }
22
+ }
23
+ //# sourceMappingURL=JsonMapperContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"JsonMapperContext.js","sourceRoot":"","sources":["../../../src/domain/JsonMapperContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAO,MAAM,YAAY,CAAC;AAS9C;;GAEG;AACH,MAAM,OAAO,iBAAiB;IACnB,cAAc,CAAwB;IACtC,IAAI,CAAkB;IACtB,OAAO,CAAM;IACd,KAAK,CAAoC;IAEjD,YAAY,EAAC,IAAI,EAAE,cAAc,EAAE,IAAI,EAAE,OAAO,EAAyB;QACvE,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,cAAc,GAAG,YAAY,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,SAAS,CAAC;QAChF,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED,IAAI,CAAC,IAAS;QACZ,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE;YACtB,GAAG,IAAI,CAAC,OAAO;YACf,IAAI,EAAE,IAAI,CAAC,IAAI;SAChB,CAAC,CAAC;IACL,CAAC;CACF"}
package/lib/esm/index.js CHANGED
@@ -1,28 +1,23 @@
1
1
  /**
2
2
  * @file Automatically generated by barrelsby.
3
3
  */
4
+ export * from "./components/ArrayMapper.js";
4
5
  export * from "./components/DateMapper.js";
6
+ export * from "./components/MapMapper.js";
5
7
  export * from "./components/PrimitiveMapper.js";
8
+ export * from "./components/SetMapper.js";
6
9
  export * from "./components/SymbolMapper.js";
7
10
  export * from "./decorators/afterDeserialize.js";
8
11
  export * from "./decorators/beforeDeserialize.js";
9
12
  export * from "./decorators/jsonMapper.js";
10
13
  export * from "./decorators/onDeserialize.js";
11
14
  export * from "./decorators/onSerialize.js";
12
- export * from "./domain/JsonDeserializer.js";
13
- export * from "./domain/JsonDeserializerOptions.js";
14
- export * from "./domain/JsonMapperCompiler.js";
15
+ export * from "./domain/JsonMapperContext.js";
15
16
  export * from "./domain/JsonMapperSettings.js";
16
17
  export * from "./domain/JsonMapperTypesContainer.js";
17
- export * from "./domain/JsonSerializer.js";
18
- export * from "./domain/JsonSerializerOptions.js";
19
- export * from "./domain/Writer.js";
20
18
  export * from "./hooks/alterAfterDeserialize.js";
21
19
  export * from "./hooks/alterBeforeDeserialize.js";
22
- export * from "./hooks/alterOnDeserialize.js";
23
- export * from "./hooks/alterOnSerialize.js";
24
20
  export * from "./interfaces/JsonMapperMethods.js";
25
21
  export * from "./utils/deserialize.js";
26
- export * from "./utils/getObjectProperties.js";
27
22
  export * from "./utils/serialize.js";
28
23
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,yBAAyB,CAAC;AACxC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,yBAAyB,CAAC;AACxC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,0BAA0B,CAAC;AACzC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,kCAAkC,CAAC;AACjD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,mCAAmC,CAAC;AAClD,cAAc,yBAAyB,CAAC;AACxC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,iBAAiB,CAAC;AAChC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,0BAA0B,CAAC;AACzC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,qBAAqB,CAAC;AACpC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,mBAAmB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,yBAAyB,CAAC;AACxC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,0BAA0B,CAAC;AACzC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,mCAAmC,CAAC;AAClD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC"}
@@ -1,9 +1,205 @@
1
+ import { getValue, isArray, isBoolean, isClass, isEmpty, isNil, nameOf, objectKeys } from "@tsed/core";
2
+ import { alterIgnore, Discriminator, getProperties, JsonEntityStore, JsonParameterStore, JsonPropertyStore, JsonSchema } from "@tsed/schema";
3
+ import "../components/ArrayMapper.js";
1
4
  import "../components/DateMapper.js";
5
+ import "../components/MapMapper.js";
2
6
  import "../components/PrimitiveMapper.js";
7
+ import "../components/SetMapper.js";
3
8
  import "../components/SymbolMapper.js";
4
- import { JsonDeserializer } from "../domain/JsonDeserializer.js";
5
- const deserializer = new JsonDeserializer();
6
- export function deserialize(input, options) {
7
- return deserializer.map(input, options);
9
+ import { JsonMapperContext } from "../domain/JsonMapperContext.js";
10
+ import { JsonMapperSettings } from "../domain/JsonMapperSettings.js";
11
+ import { getJsonMapperTypes } from "../domain/JsonMapperTypesContainer.js";
12
+ import { alterAfterDeserialize } from "../hooks/alterAfterDeserialize.js";
13
+ import { alterBeforeDeserialize } from "../hooks/alterBeforeDeserialize.js";
14
+ function isDeserializable(obj, options) {
15
+ if ((!!options.collectionType && isNil(obj)) || obj === undefined) {
16
+ return false;
17
+ }
18
+ return !(isEmpty(options.type) || (options.type === Object && !options.collectionType));
19
+ }
20
+ function alterValue(schema, value, options) {
21
+ return schema.$hooks.alter("onDeserialize", value, [options]);
22
+ }
23
+ function transformCollection(src, options) {
24
+ const { types, type = Object, collectionType } = options;
25
+ const context = new JsonMapperContext({
26
+ type,
27
+ collectionType,
28
+ options,
29
+ next: (data, { collectionType, ...options }) => deserialize(data, options)
30
+ });
31
+ return types?.get(options.collectionType)?.deserialize(src, context);
32
+ }
33
+ function transformType(src, options) {
34
+ const { types, type = Object } = options;
35
+ const context = new JsonMapperContext({
36
+ type,
37
+ options,
38
+ next: (data, { type, ...options }) => deserialize(data, options)
39
+ });
40
+ return types?.get(type)?.deserialize(src, context);
41
+ }
42
+ function getAdditionalProperties(nbProps, store, options) {
43
+ const additionalProperties = store.schema.get("additionalProperties");
44
+ if (isBoolean(additionalProperties) || isClass(additionalProperties)) {
45
+ return additionalProperties;
46
+ }
47
+ return nbProps === 0 || !!options.additionalProperties;
48
+ }
49
+ /**
50
+ * Transform given plain object to class.
51
+ * @param src
52
+ * @param options
53
+ */
54
+ export function plainObjectToClass(src, options) {
55
+ if (isEmpty(src)) {
56
+ return src;
57
+ }
58
+ const { type, store = JsonEntityStore.from(type) } = options;
59
+ const propertiesMap = getProperties(store, { ...options, withIgnoredProps: true });
60
+ let keys = new Set(objectKeys(src));
61
+ const additionalProperties = getAdditionalProperties(propertiesMap.size, store, options);
62
+ src = alterBeforeDeserialize(src, store.schema, options);
63
+ const out = new type(options.disableUnsecureConstructor ? {} : src);
64
+ propertiesMap.forEach((propStore) => {
65
+ const key = options.useAlias
66
+ ? propStore.parent.schema.getAliasOf(propStore.propertyName) || propStore.propertyName
67
+ : propStore.propertyName;
68
+ keys.delete(key);
69
+ if (alterIgnore(propStore.schema, options)) {
70
+ return;
71
+ }
72
+ let value = alterValue(propStore.schema, src[key], { ...options, self: src });
73
+ value =
74
+ value === src[key]
75
+ ? deserialize(value, {
76
+ ...options,
77
+ store: propStore,
78
+ format: propStore.itemSchema.get("format"),
79
+ self: src,
80
+ collectionType: propStore.collectionType
81
+ })
82
+ : value;
83
+ if (!propStore.isGetterOnly()) {
84
+ if (value !== undefined) {
85
+ out[propStore.propertyName] = value;
86
+ }
87
+ else if (options.partial) {
88
+ delete out[propStore.propertyName];
89
+ }
90
+ }
91
+ });
92
+ if (additionalProperties) {
93
+ if (isBoolean(additionalProperties)) {
94
+ keys.forEach((key) => {
95
+ out[key] = src[key];
96
+ });
97
+ }
98
+ else {
99
+ const type = additionalProperties.getComputedType();
100
+ keys.forEach((key) => {
101
+ out[key] = deserialize(src[key], {
102
+ ...options,
103
+ type
104
+ });
105
+ });
106
+ }
107
+ }
108
+ return alterAfterDeserialize(out, store.schema, options);
109
+ }
110
+ function mapPropStoreOptions(store, options) {
111
+ const itemOpts = {
112
+ ...options,
113
+ store: undefined,
114
+ type: store.computedType
115
+ };
116
+ if (store.itemSchema.isDiscriminator) {
117
+ itemOpts.type = store.itemSchema.discriminator();
118
+ }
119
+ if (store.schema.hasGenerics) {
120
+ itemOpts.nestedGenerics = store.schema.nestedGenerics;
121
+ }
122
+ else if (store.schema.isGeneric && options.nestedGenerics) {
123
+ const [genericTypes = [], ...nestedGenerics] = options.nestedGenerics;
124
+ const genericLabels = store.parent.schema.genericLabels || [];
125
+ itemOpts.type = genericTypes[genericLabels.indexOf(store.schema.genericType)] || Object;
126
+ if (itemOpts.type instanceof JsonSchema) {
127
+ itemOpts.type = itemOpts.type.getTarget();
128
+ }
129
+ itemOpts.nestedGenerics = nestedGenerics;
130
+ }
131
+ return itemOpts;
132
+ }
133
+ function mapParamStoreOptions(store, options) {
134
+ return {
135
+ ...options,
136
+ store: undefined,
137
+ type: store.getBestType(),
138
+ collectionType: store.collectionType,
139
+ groups: store.parameter.groups,
140
+ genericTypes: store.nestedGenerics[0],
141
+ nestedGenerics: store.nestedGenerics
142
+ };
143
+ }
144
+ function buildOptions(options) {
145
+ if (options.store instanceof JsonPropertyStore) {
146
+ return buildOptions(mapPropStoreOptions(options.store, options));
147
+ }
148
+ if (options.store instanceof JsonParameterStore) {
149
+ return buildOptions(mapParamStoreOptions(options.store, options));
150
+ }
151
+ if (options.store instanceof JsonEntityStore) {
152
+ options.type = options.store.computedType;
153
+ options.collectionType = options.store.collectionType;
154
+ options.store = undefined;
155
+ }
156
+ else if (isClass(options.type)) {
157
+ const store = JsonEntityStore.from(options.type);
158
+ if (store.schema.isDiscriminator) {
159
+ options.type = JsonEntityStore.from(options.type).schema.discriminator();
160
+ }
161
+ }
162
+ return {
163
+ groups: false,
164
+ useAlias: true,
165
+ ...options,
166
+ additionalProperties: getValue(options, "additionalProperties", JsonMapperSettings.additionalProperties),
167
+ disableUnsecureConstructor: getValue(options, "disableUnsecureConstructor", JsonMapperSettings.disableUnsecureConstructor),
168
+ partial: options.groups ? options.groups.includes("partial") : false,
169
+ type: options.type ? options.type : undefined,
170
+ types: options.types ? options.types : getJsonMapperTypes()
171
+ };
172
+ }
173
+ /**
174
+ * Transform given source to class base on the given `options.type`.
175
+ *
176
+ * @param src
177
+ * @param options
178
+ */
179
+ export function deserialize(src, options = {}) {
180
+ options = buildOptions(options);
181
+ if (!isDeserializable(src, options)) {
182
+ return src;
183
+ }
184
+ if (!options.collectionType && isArray(src)) {
185
+ options.collectionType = Array;
186
+ }
187
+ if (options.collectionType) {
188
+ if (!options.types?.has(options.collectionType)) {
189
+ throw new Error(`${nameOf(options.collectionType)} is not supported by JsonMapper.`);
190
+ }
191
+ return transformCollection(src, options);
192
+ }
193
+ if (options.types?.has(options.type)) {
194
+ return transformType(src, options);
195
+ }
196
+ if (options.type instanceof Discriminator) {
197
+ const discriminator = options.type;
198
+ const discriminatorValue = src[discriminator.propertyName];
199
+ const type = discriminator.getType(discriminatorValue);
200
+ return plainObjectToClass(src, { ...options, type });
201
+ }
202
+ // class converter
203
+ return plainObjectToClass(src, options);
8
204
  }
9
205
  //# sourceMappingURL=deserialize.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"deserialize.js","sourceRoot":"","sources":["../../../src/utils/deserialize.ts"],"names":[],"mappings":"AAAA,OAAO,0BAA0B,CAAC;AAClC,OAAO,+BAA+B,CAAC;AACvC,OAAO,4BAA4B,CAAC;AAEpC,OAAO,EAAC,gBAAgB,EAAC,MAAM,4BAA4B,CAAC;AAG5D,MAAM,YAAY,GAAG,IAAI,gBAAgB,EAAE,CAAC;AAE5C,MAAM,UAAU,WAAW,CAAc,KAAU,EAAE,OAAiC;IACpF,OAAO,YAAY,CAAC,GAAG,CAAQ,KAAK,EAAE,OAAO,CAAC,CAAC;AACjD,CAAC"}
1
+ {"version":3,"file":"deserialize.js","sourceRoot":"","sources":["../../../src/utils/deserialize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAiB,MAAM,EAAE,UAAU,EAAO,MAAM,YAAY,CAAC;AAC1H,OAAO,EACL,WAAW,EACX,aAAa,EACb,aAAa,EACb,eAAe,EAEf,kBAAkB,EAClB,iBAAiB,EACjB,UAAU,EACX,MAAM,cAAc,CAAC;AACtB,OAAO,2BAA2B,CAAC;AACnC,OAAO,0BAA0B,CAAC;AAClC,OAAO,yBAAyB,CAAC;AACjC,OAAO,+BAA+B,CAAC;AACvC,OAAO,yBAAyB,CAAC;AACjC,OAAO,4BAA4B,CAAC;AACpC,OAAO,EAAC,iBAAiB,EAAC,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAC,kBAAkB,EAAC,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAC,kBAAkB,EAAC,MAAM,oCAAoC,CAAC;AACtE,OAAO,EAAC,qBAAqB,EAAC,MAAM,gCAAgC,CAAC;AACrE,OAAO,EAAC,sBAAsB,EAAC,MAAM,iCAAiC,CAAC;AAiCvE,SAAS,gBAAgB,CAAC,GAAQ,EAAE,OAAgC;IAClE,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,cAAc,IAAI,KAAK,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AC,EAAE;YAC/C,MAAM,IAAI,KAAK,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,kCAAkC,CAAC,CAAC;SACtF;QAED,OAAO,mBAAmB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;KAC1C;IAED,IAAI,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;QACpC,OAAO,aAAa,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;KACpC;IAED,IAAI,OAAO,CAAC,IAAI,YAAY,aAAa,EAAE;QACzC,MAAM,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;QACnC,MAAM,kBAAkB,GAAG,GAAG,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC;QAC3D,MAAM,IAAI,GAAG,aAAa,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC;QAEvD,OAAO,kBAAkB,CAAC,GAAG,EAAE,EAAC,GAAG,OAAO,EAAE,IAAI,EAAC,CAAC,CAAC;KACpD;IAED,kBAAkB;IAClB,OAAO,kBAAkB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;AAC1C,CAAC"}
@@ -1,9 +1,146 @@
1
+ import { classOf, isArray, isClassObject, isCollection, isDate, isEmpty, isFunction, isNil, nameOf, objectKeys } from "@tsed/core";
2
+ import { alterIgnore, getPropertiesStores, JsonEntityStore } from "@tsed/schema";
3
+ import "../components/ArrayMapper.js";
1
4
  import "../components/DateMapper.js";
5
+ import "../components/MapMapper.js";
2
6
  import "../components/PrimitiveMapper.js";
7
+ import "../components/SetMapper.js";
3
8
  import "../components/SymbolMapper.js";
4
- import { JsonSerializer } from "../domain/JsonSerializer.js";
5
- const serializer = new JsonSerializer();
6
- export function serialize(input, options) {
7
- return serializer.map(input, options);
9
+ import { JsonMapperContext } from "../domain/JsonMapperContext.js";
10
+ import { getJsonMapperTypes } from "../domain/JsonMapperTypesContainer.js";
11
+ function alterValue(schema, value, options) {
12
+ return schema.$hooks.alter("onSerialize", value, [options]);
13
+ }
14
+ function getSchemaProperties(storedJson, obj) {
15
+ const stores = Array.from(getPropertiesStores(storedJson).entries());
16
+ if (!stores.length) {
17
+ // fallback to auto discovering field from obj
18
+ objectKeys(obj).forEach((key) => {
19
+ const propStore = JsonEntityStore.from(storedJson.target, key);
20
+ stores.push([key, propStore]);
21
+ });
22
+ }
23
+ return stores;
24
+ }
25
+ function getObjectProperties(obj) {
26
+ return Object.entries(obj).filter(([, value]) => !isFunction(value));
27
+ }
28
+ function getType(propStore, value) {
29
+ if (isNil(value) || propStore.type === Object || isCollection(propStore.type)) {
30
+ return undefined;
31
+ }
32
+ return propStore.type;
33
+ }
34
+ export function classToPlainObject(obj, options) {
35
+ const { useAlias = true, type, ...props } = options;
36
+ const entity = JsonEntityStore.from(type || obj);
37
+ const additionalProperties = !!entity.schema.get("additionalProperties");
38
+ const schemaProperties = getSchemaProperties(entity, obj);
39
+ const properties = new Set();
40
+ const out = schemaProperties.reduce((newObj, [key, propStore]) => {
41
+ properties.add(key);
42
+ const schema = propStore.schema;
43
+ if (alterIgnore(schema, { useAlias, ...props, self: obj })) {
44
+ return newObj;
45
+ }
46
+ let value = alterValue(schema, obj[key], { useAlias, ...props, self: obj });
47
+ value = serialize(value, {
48
+ useAlias,
49
+ self: obj,
50
+ type: value === obj[key] ? getType(propStore, value) : undefined,
51
+ collectionType: propStore.collectionType,
52
+ format: propStore.itemSchema.get("format"),
53
+ ...props
54
+ });
55
+ if (value === undefined) {
56
+ return newObj;
57
+ }
58
+ key = useAlias ? propStore.parent.schema.getAliasOf(key) || key : key;
59
+ return {
60
+ ...newObj,
61
+ [key]: value
62
+ };
63
+ }, {});
64
+ if (entity.discriminatorAncestor) {
65
+ const discriminator = entity.discriminatorAncestor.schema.discriminator();
66
+ if (!out[discriminator.propertyName]) {
67
+ out[discriminator.propertyName] = discriminator.getDefaultValue(entity.target);
68
+ }
69
+ }
70
+ if (additionalProperties) {
71
+ objectKeys(obj).forEach((key) => {
72
+ if (!properties.has(key)) {
73
+ out[key] = obj[key];
74
+ }
75
+ });
76
+ }
77
+ return out;
78
+ }
79
+ function toObject(obj, options) {
80
+ return getObjectProperties(obj).reduce((newObj, [key, value]) => ({
81
+ ...newObj,
82
+ [key]: serialize(value, options)
83
+ }), {});
84
+ }
85
+ function getBestType(type, obj) {
86
+ const dataType = classOf(obj);
87
+ if (dataType && !isClassObject(dataType)) {
88
+ return dataType;
89
+ }
90
+ return type || Object;
91
+ }
92
+ function hasJsonMethod(obj) {
93
+ return typeof obj.toJSON === "function";
94
+ }
95
+ function isMongooseObject(obj) {
96
+ return (hasJsonMethod(obj) && obj.$isMongooseModelPrototype) || obj._bsontype;
97
+ }
98
+ function isMomentObject(obj) {
99
+ return obj && obj?._isAMomentObject;
100
+ }
101
+ export function serialize(obj, { type, collectionType, groups = false, ...options } = {}) {
102
+ if (isEmpty(obj)) {
103
+ return obj;
104
+ }
105
+ let currentType = type;
106
+ const types = options.types ? options.types : getJsonMapperTypes();
107
+ options.groups = groups;
108
+ // FIX custom serialization function from @tsed/mongoose and bson
109
+ if (isMongooseObject(obj)) {
110
+ return obj.toJSON(options);
111
+ }
112
+ if (hasJsonMethod(obj) && !isMomentObject(obj) && !isDate(obj)) {
113
+ return serialize(obj.toJSON(), { ...options, type: classOf(obj) });
114
+ }
115
+ if (!isCollection(obj)) {
116
+ options.type = currentType = getBestType(currentType, obj);
117
+ }
118
+ else if (!options.collectionType) {
119
+ currentType = classOf(obj);
120
+ options.type = type;
121
+ options.collectionType = currentType;
122
+ }
123
+ const context = new JsonMapperContext({
124
+ type: currentType,
125
+ options,
126
+ next: (data) => serialize(data, {
127
+ ...options,
128
+ collectionType: undefined,
129
+ type: options.type
130
+ })
131
+ });
132
+ const mapper = types.get(currentType) || types.get(nameOf(currentType));
133
+ if (mapper) {
134
+ const jsonMapper = mapper;
135
+ return jsonMapper.serialize(obj, context);
136
+ }
137
+ else if (obj?._isAMomentObject) {
138
+ return obj.toJSON();
139
+ }
140
+ if (isArray(obj)) {
141
+ // Serialize Array class like
142
+ return types.get(Array)?.serialize(obj, context);
143
+ }
144
+ return !isClassObject(currentType) ? classToPlainObject(obj, options) : toObject(obj, options);
8
145
  }
9
146
  //# sourceMappingURL=serialize.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"serialize.js","sourceRoot":"","sources":["../../../src/utils/serialize.ts"],"names":[],"mappings":"AAAA,OAAO,0BAA0B,CAAC;AAClC,OAAO,+BAA+B,CAAC;AACvC,OAAO,4BAA4B,CAAC;AAEpC,OAAO,EAAC,cAAc,EAAC,MAAM,0BAA0B,CAAC;AAGxD,MAAM,UAAU,GAAG,IAAI,cAAc,EAAE,CAAC;AAExC,MAAM,UAAU,SAAS,CAAC,KAAU,EAAE,OAA+B;IACnE,OAAO,UAAU,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;AACxC,CAAC"}
1
+ {"version":3,"file":"serialize.js","sourceRoot":"","sources":["../../../src/utils/serialize.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,OAAO,EACP,aAAa,EACb,YAAY,EACZ,MAAM,EACN,OAAO,EACP,UAAU,EACV,KAAK,EAEL,MAAM,EACN,UAAU,EAEX,MAAM,YAAY,CAAC;AACpB,OAAO,EAAC,WAAW,EAAE,mBAAmB,EAAE,eAAe,EAA8B,MAAM,cAAc,CAAC;AAC5G,OAAO,2BAA2B,CAAC;AACnC,OAAO,0BAA0B,CAAC;AAClC,OAAO,yBAAyB,CAAC;AACjC,OAAO,+BAA+B,CAAC;AACvC,OAAO,yBAAyB,CAAC;AACjC,OAAO,4BAA4B,CAAC;AACpC,OAAO,EAAC,iBAAiB,EAAC,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAC,kBAAkB,EAAC,MAAM,oCAAoC,CAAC;AAgBtE,SAAS,UAAU,CAAC,MAAkB,EAAE,KAAU,EAAE,OAAwB;IAC1E,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,aAAa,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