@tsed/json-mapper 7.35.1 → 7.36.0-rc.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.
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/DateMapper.js +1 -1
  5. package/lib/cjs/components/DateMapper.js.map +1 -1
  6. package/lib/cjs/components/PrimitiveMapper.js +30 -26
  7. package/lib/cjs/components/PrimitiveMapper.js.map +1 -1
  8. package/lib/cjs/components/SymbolMapper.js.map +1 -1
  9. package/lib/cjs/domain/JsonDeserializer.js +275 -0
  10. package/lib/cjs/domain/JsonDeserializer.js.map +1 -0
  11. package/lib/cjs/domain/JsonDeserializerOptions.js +3 -0
  12. package/lib/cjs/domain/JsonDeserializerOptions.js.map +1 -0
  13. package/lib/cjs/domain/JsonMapperCompiler.js +167 -0
  14. package/lib/cjs/domain/JsonMapperCompiler.js.map +1 -0
  15. package/lib/cjs/domain/JsonSerializer.js +219 -0
  16. package/lib/cjs/domain/JsonSerializer.js.map +1 -0
  17. package/lib/cjs/domain/JsonSerializerOptions.js +3 -0
  18. package/lib/cjs/domain/JsonSerializerOptions.js.map +1 -0
  19. package/lib/cjs/domain/Writer.js +141 -0
  20. package/lib/cjs/domain/Writer.js.map +1 -0
  21. package/lib/cjs/hooks/alterOnDeserialize.js +8 -0
  22. package/lib/cjs/hooks/alterOnDeserialize.js.map +1 -0
  23. package/lib/cjs/hooks/alterOnSerialize.js +8 -0
  24. package/lib/cjs/hooks/alterOnSerialize.js.map +1 -0
  25. package/lib/cjs/index.js +9 -4
  26. package/lib/cjs/index.js.map +1 -1
  27. package/lib/cjs/utils/deserialize.js +5 -202
  28. package/lib/cjs/utils/deserialize.js.map +1 -1
  29. package/lib/cjs/utils/getObjectProperties.js +9 -0
  30. package/lib/cjs/utils/getObjectProperties.js.map +1 -0
  31. package/lib/cjs/utils/serialize.js +5 -143
  32. package/lib/cjs/utils/serialize.js.map +1 -1
  33. package/lib/esm/components/DateMapper.js +1 -1
  34. package/lib/esm/components/DateMapper.js.map +1 -1
  35. package/lib/esm/components/PrimitiveMapper.js +30 -26
  36. package/lib/esm/components/PrimitiveMapper.js.map +1 -1
  37. package/lib/esm/components/SymbolMapper.js.map +1 -1
  38. package/lib/esm/domain/JsonDeserializer.js +271 -0
  39. package/lib/esm/domain/JsonDeserializer.js.map +1 -0
  40. package/lib/esm/domain/JsonDeserializerOptions.js +2 -0
  41. package/lib/esm/domain/JsonDeserializerOptions.js.map +1 -0
  42. package/lib/esm/domain/JsonMapperCompiler.js +163 -0
  43. package/lib/esm/domain/JsonMapperCompiler.js.map +1 -0
  44. package/lib/esm/domain/JsonSerializer.js +215 -0
  45. package/lib/esm/domain/JsonSerializer.js.map +1 -0
  46. package/lib/esm/domain/JsonSerializerOptions.js +2 -0
  47. package/lib/esm/domain/JsonSerializerOptions.js.map +1 -0
  48. package/lib/esm/domain/Writer.js +137 -0
  49. package/lib/esm/domain/Writer.js.map +1 -0
  50. package/lib/esm/hooks/alterOnDeserialize.js +4 -0
  51. package/lib/esm/hooks/alterOnDeserialize.js.map +1 -0
  52. package/lib/esm/hooks/alterOnSerialize.js +4 -0
  53. package/lib/esm/hooks/alterOnSerialize.js.map +1 -0
  54. package/lib/esm/index.js +9 -4
  55. package/lib/esm/index.js.map +1 -1
  56. package/lib/esm/utils/deserialize.js +4 -200
  57. package/lib/esm/utils/deserialize.js.map +1 -1
  58. package/lib/esm/utils/getObjectProperties.js +5 -0
  59. package/lib/esm/utils/getObjectProperties.js.map +1 -0
  60. package/lib/esm/utils/serialize.js +4 -141
  61. package/lib/esm/utils/serialize.js.map +1 -1
  62. package/lib/tsconfig.esm.tsbuildinfo +1 -1
  63. package/lib/tsconfig.tsbuildinfo +1 -1
  64. package/lib/types/components/PrimitiveMapper.d.ts +4 -0
  65. package/lib/types/domain/JsonDeserializer.d.ts +33 -0
  66. package/lib/types/domain/JsonDeserializerOptions.d.ts +31 -0
  67. package/lib/types/domain/JsonMapperCompiler.d.ts +58 -0
  68. package/lib/types/domain/JsonSerializer.d.ts +21 -0
  69. package/lib/types/domain/JsonSerializerOptions.d.ts +13 -0
  70. package/lib/types/domain/Writer.d.ts +43 -0
  71. package/lib/types/hooks/alterOnDeserialize.d.ts +2 -0
  72. package/lib/types/hooks/alterOnSerialize.d.ts +2 -0
  73. package/lib/types/index.d.ts +9 -4
  74. package/lib/types/utils/deserialize.d.ts +2 -47
  75. package/lib/types/utils/getObjectProperties.d.ts +1 -0
  76. package/lib/types/utils/serialize.d.ts +2 -18
  77. package/package.json +11 -8
  78. package/lib/cjs/components/ArrayMapper.js +0 -23
  79. package/lib/cjs/components/ArrayMapper.js.map +0 -1
  80. package/lib/cjs/components/MapMapper.js +0 -30
  81. package/lib/cjs/components/MapMapper.js.map +0 -1
  82. package/lib/cjs/components/SetMapper.js +0 -30
  83. package/lib/cjs/components/SetMapper.js.map +0 -1
  84. package/lib/cjs/domain/JsonMapperContext.js +0 -27
  85. package/lib/cjs/domain/JsonMapperContext.js.map +0 -1
  86. package/lib/esm/components/ArrayMapper.js +0 -20
  87. package/lib/esm/components/ArrayMapper.js.map +0 -1
  88. package/lib/esm/components/MapMapper.js +0 -27
  89. package/lib/esm/components/MapMapper.js.map +0 -1
  90. package/lib/esm/components/SetMapper.js +0 -27
  91. package/lib/esm/components/SetMapper.js.map +0 -1
  92. package/lib/esm/domain/JsonMapperContext.js +0 -23
  93. package/lib/esm/domain/JsonMapperContext.js.map +0 -1
  94. package/lib/types/components/ArrayMapper.d.ts +0 -10
  95. package/lib/types/components/MapMapper.d.ts +0 -12
  96. package/lib/types/components/SetMapper.d.ts +0 -10
  97. package/lib/types/domain/JsonMapperContext.d.ts +0 -20
@@ -1,210 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.deserialize = exports.plainObjectToClass = void 0;
4
- const core_1 = require("@tsed/core");
5
- const schema_1 = require("@tsed/schema");
6
- require("../components/ArrayMapper");
3
+ exports.deserialize = void 0;
7
4
  require("../components/DateMapper");
8
- require("../components/MapMapper");
9
5
  require("../components/PrimitiveMapper");
10
- require("../components/SetMapper");
11
6
  require("../components/SymbolMapper");
12
- const JsonMapperContext_1 = require("../domain/JsonMapperContext");
13
- const JsonMapperSettings_1 = require("../domain/JsonMapperSettings");
14
- const JsonMapperTypesContainer_1 = require("../domain/JsonMapperTypesContainer");
15
- const alterAfterDeserialize_1 = require("../hooks/alterAfterDeserialize");
16
- const alterBeforeDeserialize_1 = require("../hooks/alterBeforeDeserialize");
17
- function isDeserializable(obj, options) {
18
- if ((!!options.collectionType && (0, core_1.isNil)(obj)) || obj === undefined) {
19
- return false;
20
- }
21
- return !((0, core_1.isEmpty)(options.type) || (options.type === Object && !options.collectionType));
22
- }
23
- function alterValue(schema, value, options) {
24
- return schema.$hooks.alter("onDeserialize", value, [options]);
25
- }
26
- function transformCollection(src, options) {
27
- const { types, type = Object, collectionType } = options;
28
- const context = new JsonMapperContext_1.JsonMapperContext({
29
- type,
30
- collectionType,
31
- options,
32
- next: (data, { collectionType, ...options }) => deserialize(data, options)
33
- });
34
- return types?.get(options.collectionType)?.deserialize(src, context);
35
- }
36
- function transformType(src, options) {
37
- const { types, type = Object } = options;
38
- const context = new JsonMapperContext_1.JsonMapperContext({
39
- type,
40
- options,
41
- next: (data, { type, ...options }) => deserialize(data, options)
42
- });
43
- return types?.get(type)?.deserialize(src, context);
44
- }
45
- function getAdditionalProperties(nbProps, store, options) {
46
- const additionalProperties = store.schema.get("additionalProperties");
47
- if ((0, core_1.isBoolean)(additionalProperties) || (0, core_1.isClass)(additionalProperties)) {
48
- return additionalProperties;
49
- }
50
- return nbProps === 0 || !!options.additionalProperties;
51
- }
52
- /**
53
- * Transform given plain object to class.
54
- * @param src
55
- * @param options
56
- */
57
- function plainObjectToClass(src, options) {
58
- if ((0, core_1.isEmpty)(src)) {
59
- return src;
60
- }
61
- const { type, store = schema_1.JsonEntityStore.from(type) } = options;
62
- const propertiesMap = (0, schema_1.getProperties)(store, { ...options, withIgnoredProps: true });
63
- let keys = new Set((0, core_1.objectKeys)(src));
64
- const additionalProperties = getAdditionalProperties(propertiesMap.size, store, options);
65
- src = (0, alterBeforeDeserialize_1.alterBeforeDeserialize)(src, store.schema, options);
66
- const out = new type(options.disableUnsecureConstructor ? {} : src);
67
- propertiesMap.forEach((propStore) => {
68
- const key = options.useAlias
69
- ? propStore.parent.schema.getAliasOf(propStore.propertyName) || propStore.propertyName
70
- : propStore.propertyName;
71
- keys.delete(key);
72
- if ((0, schema_1.alterIgnore)(propStore.schema, options)) {
73
- return;
74
- }
75
- let value = alterValue(propStore.schema, src[key], { ...options, self: src });
76
- value =
77
- value === src[key]
78
- ? deserialize(value, {
79
- ...options,
80
- store: propStore,
81
- format: propStore.itemSchema.get("format"),
82
- self: src,
83
- collectionType: propStore.collectionType
84
- })
85
- : value;
86
- if (!propStore.isGetterOnly()) {
87
- if (value !== undefined) {
88
- out[propStore.propertyName] = value;
89
- }
90
- else if (options.partial) {
91
- delete out[propStore.propertyName];
92
- }
93
- }
94
- });
95
- if (additionalProperties) {
96
- if ((0, core_1.isBoolean)(additionalProperties)) {
97
- keys.forEach((key) => {
98
- out[key] = src[key];
99
- });
100
- }
101
- else {
102
- const type = additionalProperties.getComputedType();
103
- keys.forEach((key) => {
104
- out[key] = deserialize(src[key], {
105
- ...options,
106
- type
107
- });
108
- });
109
- }
110
- }
111
- return (0, alterAfterDeserialize_1.alterAfterDeserialize)(out, store.schema, options);
112
- }
113
- exports.plainObjectToClass = plainObjectToClass;
114
- function mapPropStoreOptions(store, options) {
115
- const itemOpts = {
116
- ...options,
117
- store: undefined,
118
- type: store.computedType
119
- };
120
- if (store.itemSchema.isDiscriminator) {
121
- itemOpts.type = store.itemSchema.discriminator();
122
- }
123
- if (store.schema.hasGenerics) {
124
- itemOpts.nestedGenerics = store.schema.nestedGenerics;
125
- }
126
- else if (store.schema.isGeneric && options.nestedGenerics) {
127
- const [genericTypes = [], ...nestedGenerics] = options.nestedGenerics;
128
- const genericLabels = store.parent.schema.genericLabels || [];
129
- itemOpts.type = genericTypes[genericLabels.indexOf(store.schema.genericType)] || Object;
130
- if (itemOpts.type instanceof schema_1.JsonSchema) {
131
- itemOpts.type = itemOpts.type.getTarget();
132
- }
133
- itemOpts.nestedGenerics = nestedGenerics;
134
- }
135
- return itemOpts;
136
- }
137
- function mapParamStoreOptions(store, options) {
138
- return {
139
- ...options,
140
- store: undefined,
141
- type: store.getBestType(),
142
- collectionType: store.collectionType,
143
- groups: store.parameter.groups,
144
- genericTypes: store.nestedGenerics[0],
145
- nestedGenerics: store.nestedGenerics
146
- };
147
- }
148
- function buildOptions(options) {
149
- if (options.store instanceof schema_1.JsonPropertyStore) {
150
- return buildOptions(mapPropStoreOptions(options.store, options));
151
- }
152
- if (options.store instanceof schema_1.JsonParameterStore) {
153
- return buildOptions(mapParamStoreOptions(options.store, options));
154
- }
155
- if (options.store instanceof schema_1.JsonEntityStore) {
156
- options.type = options.store.computedType;
157
- options.collectionType = options.store.collectionType;
158
- options.store = undefined;
159
- }
160
- else if ((0, core_1.isClass)(options.type)) {
161
- const store = schema_1.JsonEntityStore.from(options.type);
162
- if (store.schema.isDiscriminator) {
163
- options.type = schema_1.JsonEntityStore.from(options.type).schema.discriminator();
164
- }
165
- }
166
- return {
167
- groups: false,
168
- useAlias: true,
169
- ...options,
170
- additionalProperties: (0, core_1.getValue)(options, "additionalProperties", JsonMapperSettings_1.JsonMapperSettings.additionalProperties),
171
- disableUnsecureConstructor: (0, core_1.getValue)(options, "disableUnsecureConstructor", JsonMapperSettings_1.JsonMapperSettings.disableUnsecureConstructor),
172
- partial: options.groups ? options.groups.includes("partial") : false,
173
- type: options.type ? options.type : undefined,
174
- types: options.types ? options.types : (0, JsonMapperTypesContainer_1.getJsonMapperTypes)()
175
- };
176
- }
177
- /**
178
- * Transform given source to class base on the given `options.type`.
179
- *
180
- * @param src
181
- * @param options
182
- */
183
- function deserialize(src, options = {}) {
184
- options = buildOptions(options);
185
- if (!isDeserializable(src, options)) {
186
- return src;
187
- }
188
- if (!options.collectionType && (0, core_1.isArray)(src)) {
189
- options.collectionType = Array;
190
- }
191
- if (options.collectionType) {
192
- if (!options.types?.has(options.collectionType)) {
193
- throw new Error(`${(0, core_1.nameOf)(options.collectionType)} is not supported by JsonMapper.`);
194
- }
195
- return transformCollection(src, options);
196
- }
197
- if (options.types?.has(options.type)) {
198
- return transformType(src, options);
199
- }
200
- if (options.type instanceof schema_1.Discriminator) {
201
- const discriminator = options.type;
202
- const discriminatorValue = src[discriminator.propertyName];
203
- const type = discriminator.getType(discriminatorValue);
204
- return plainObjectToClass(src, { ...options, type });
205
- }
206
- // class converter
207
- return plainObjectToClass(src, options);
7
+ const JsonDeserializer_1 = require("../domain/JsonDeserializer");
8
+ const deserializer = new JsonDeserializer_1.JsonDeserializer();
9
+ function deserialize(input, options) {
10
+ return deserializer.map(input, options);
208
11
  }
209
12
  exports.deserialize = deserialize;
210
13
  //# sourceMappingURL=deserialize.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"deserialize.js","sourceRoot":"","sources":["../../../src/utils/deserialize.ts"],"names":[],"mappings":";;;AAAA,qCAA0H;AAC1H,yCASsB;AACtB,qCAAmC;AACnC,oCAAkC;AAClC,mCAAiC;AACjC,yCAAuC;AACvC,mCAAiC;AACjC,sCAAoC;AACpC,mEAA8D;AAC9D,qEAAgE;AAChE,iFAAsE;AACtE,0EAAqE;AACrE,4EAAuE;AAiCvE,SAAS,gBAAgB,CAAC,GAAQ,EAAE,OAAgC;IAClE,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,cAAc,IAAI,IAAA,YAAK,EAAC,GAAG,CAAC,CAAC,IAAI,GAAG,KAAK,SAAS,EAAE;QACjE,OAAO,KAAK,CAAC;KACd;IAED,OAAO,CAAC,CAAC,IAAA,cAAO,EAAC,OAAO,CAA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I,KAAK,CAAC,GAAG,IAAA,aAAM,EAAC,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,sBAAa,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;AAjCD,kCAiCC"}
1
+ {"version":3,"file":"deserialize.js","sourceRoot":"","sources":["../../../src/utils/deserialize.ts"],"names":[],"mappings":";;;AAAA,oCAAkC;AAClC,yCAAuC;AACvC,sCAAoC;AAEpC,iEAA4D;AAG5D,MAAM,YAAY,GAAG,IAAI,mCAAgB,EAAE,CAAC;AAE5C,SAAgB,WAAW,CAAc,KAAU,EAAE,OAAiC;IACpF,OAAO,YAAY,CAAC,GAAG,CAAQ,KAAK,EAAE,OAAO,CAAC,CAAC;AACjD,CAAC;AAFD,kCAEC"}
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getObjectProperties = void 0;
4
+ const core_1 = require("@tsed/core");
5
+ function getObjectProperties(obj) {
6
+ return Object.entries(obj).filter(([, value]) => !(0, core_1.isFunction)(value));
7
+ }
8
+ exports.getObjectProperties = getObjectProperties;
9
+ //# sourceMappingURL=getObjectProperties.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getObjectProperties.js","sourceRoot":"","sources":["../../../src/utils/getObjectProperties.ts"],"names":[],"mappings":";;;AAAA,qCAAsC;AAEtC,SAAgB,mBAAmB,CAAC,GAAQ;IAC1C,OAAO,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,IAAA,iBAAU,EAAC,KAAK,CAAC,CAAC,CAAC;AACvE,CAAC;AAFD,kDAEC"}
@@ -1,151 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.serialize = exports.classToPlainObject = void 0;
4
- const core_1 = require("@tsed/core");
5
- const schema_1 = require("@tsed/schema");
6
- require("../components/ArrayMapper");
3
+ exports.serialize = void 0;
7
4
  require("../components/DateMapper");
8
- require("../components/MapMapper");
9
5
  require("../components/PrimitiveMapper");
10
- require("../components/SetMapper");
11
6
  require("../components/SymbolMapper");
12
- const JsonMapperContext_1 = require("../domain/JsonMapperContext");
13
- const JsonMapperTypesContainer_1 = require("../domain/JsonMapperTypesContainer");
14
- function alterValue(schema, value, options) {
15
- return schema.$hooks.alter("onSerialize", value, [options]);
16
- }
17
- function getSchemaProperties(storedJson, obj) {
18
- const stores = Array.from((0, schema_1.getPropertiesStores)(storedJson).entries());
19
- if (!stores.length) {
20
- // fallback to auto discovering field from obj
21
- (0, core_1.objectKeys)(obj).forEach((key) => {
22
- const propStore = schema_1.JsonEntityStore.from(storedJson.target, key);
23
- stores.push([key, propStore]);
24
- });
25
- }
26
- return stores;
27
- }
28
- function getObjectProperties(obj) {
29
- return Object.entries(obj).filter(([, value]) => !(0, core_1.isFunction)(value));
30
- }
31
- function getType(propStore, value) {
32
- if ((0, core_1.isNil)(value) || propStore.type === Object || (0, core_1.isCollection)(propStore.type)) {
33
- return undefined;
34
- }
35
- return propStore.type;
36
- }
37
- function classToPlainObject(obj, options) {
38
- const { useAlias = true, type, ...props } = options;
39
- const entity = schema_1.JsonEntityStore.from(type || obj);
40
- const additionalProperties = !!entity.schema.get("additionalProperties");
41
- const schemaProperties = getSchemaProperties(entity, obj);
42
- const properties = new Set();
43
- const out = schemaProperties.reduce((newObj, [key, propStore]) => {
44
- properties.add(key);
45
- const schema = propStore.schema;
46
- if ((0, schema_1.alterIgnore)(schema, { useAlias, ...props, self: obj })) {
47
- return newObj;
48
- }
49
- let value = alterValue(schema, obj[key], { useAlias, ...props, self: obj });
50
- value = serialize(value, {
51
- useAlias,
52
- self: obj,
53
- type: value === obj[key] ? getType(propStore, value) : undefined,
54
- collectionType: propStore.collectionType,
55
- format: propStore.itemSchema.get("format"),
56
- ...props
57
- });
58
- if (value === undefined) {
59
- return newObj;
60
- }
61
- key = useAlias ? propStore.parent.schema.getAliasOf(key) || key : key;
62
- return {
63
- ...newObj,
64
- [key]: value
65
- };
66
- }, {});
67
- if (entity.discriminatorAncestor) {
68
- const discriminator = entity.discriminatorAncestor.schema.discriminator();
69
- if (!out[discriminator.propertyName]) {
70
- out[discriminator.propertyName] = discriminator.getDefaultValue(entity.target);
71
- }
72
- }
73
- if (additionalProperties) {
74
- (0, core_1.objectKeys)(obj).forEach((key) => {
75
- if (!properties.has(key)) {
76
- out[key] = obj[key];
77
- }
78
- });
79
- }
80
- return out;
81
- }
82
- exports.classToPlainObject = classToPlainObject;
83
- function toObject(obj, options) {
84
- return getObjectProperties(obj).reduce((newObj, [key, value]) => ({
85
- ...newObj,
86
- [key]: serialize(value, options)
87
- }), {});
88
- }
89
- function getBestType(type, obj) {
90
- const dataType = (0, core_1.classOf)(obj);
91
- if (dataType && !(0, core_1.isClassObject)(dataType)) {
92
- return dataType;
93
- }
94
- return type || Object;
95
- }
96
- function hasJsonMethod(obj) {
97
- return typeof obj.toJSON === "function";
98
- }
99
- function isMongooseObject(obj) {
100
- return (hasJsonMethod(obj) && obj.$isMongooseModelPrototype) || obj._bsontype;
101
- }
102
- function isMomentObject(obj) {
103
- return obj && obj?._isAMomentObject;
104
- }
105
- function serialize(obj, { type, collectionType, groups = false, ...options } = {}) {
106
- if ((0, core_1.isEmpty)(obj)) {
107
- return obj;
108
- }
109
- let currentType = type;
110
- const types = options.types ? options.types : (0, JsonMapperTypesContainer_1.getJsonMapperTypes)();
111
- options.groups = groups;
112
- // FIX custom serialization function from @tsed/mongoose and bson
113
- if (isMongooseObject(obj)) {
114
- return obj.toJSON(options);
115
- }
116
- if (hasJsonMethod(obj) && !isMomentObject(obj) && !(0, core_1.isDate)(obj)) {
117
- return serialize(obj.toJSON(), { ...options, type: (0, core_1.classOf)(obj) });
118
- }
119
- if (!(0, core_1.isCollection)(obj)) {
120
- options.type = currentType = getBestType(currentType, obj);
121
- }
122
- else if (!options.collectionType) {
123
- currentType = (0, core_1.classOf)(obj);
124
- options.type = type;
125
- options.collectionType = currentType;
126
- }
127
- const context = new JsonMapperContext_1.JsonMapperContext({
128
- type: currentType,
129
- options,
130
- next: (data) => serialize(data, {
131
- ...options,
132
- collectionType: undefined,
133
- type: options.type
134
- })
135
- });
136
- const mapper = types.get(currentType) || types.get((0, core_1.nameOf)(currentType));
137
- if (mapper) {
138
- const jsonMapper = mapper;
139
- return jsonMapper.serialize(obj, context);
140
- }
141
- else if (obj?._isAMomentObject) {
142
- return obj.toJSON();
143
- }
144
- if ((0, core_1.isArray)(obj)) {
145
- // Serialize Array class like
146
- return types.get(Array)?.serialize(obj, context);
147
- }
148
- return !(0, core_1.isClassObject)(currentType) ? classToPlainObject(obj, options) : toObject(obj, options);
7
+ const JsonSerializer_1 = require("../domain/JsonSerializer");
8
+ const serializer = new JsonSerializer_1.JsonSerializer();
9
+ function serialize(input, options) {
10
+ return serializer.map(input, options);
149
11
  }
150
12
  exports.serialize = serialize;
151
13
  //# sourceMappingURL=serialize.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"serialize.js","sour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O,GAAG,CAAC,MAAM,EAAE,CAAC;KACrB;IAED,IAAI,IAAA,cAAO,EAAC,GAAG,CAAC,EAAE;QAChB,6BAA6B;QAC7B,OAAO,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,SAAS,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;KAClD;IAED,OAAO,CAAC,IAAA,oBAAa,EAAC,WAAW,CAAC,CAAC,CAAC,CAAC,kBAAkB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;AACjG,CAAC;AAtDD,8BAsDC"}
1
+ {"version":3,"file":"serialize.js","sourceRoot":"","sources":["../../../src/utils/serialize.ts"],"names":[],"mappings":";;;AAAA,oCAAkC;AAClC,yCAAuC;AACvC,sCAAoC;AAEpC,6DAAwD;AAGxD,MAAM,UAAU,GAAG,IAAI,+BAAc,EAAE,CAAC;AAExC,SAAgB,SAAS,CAAC,KAAU,EAAE,OAA+B;IACnE,OAAO,UAAU,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;AACxC,CAAC;AAFD,8BAEC"}
@@ -17,7 +17,7 @@ let DateMapper = class DateMapper {
17
17
  return new Date(data);
18
18
  }
19
19
  serialize(object) {
20
- return new Date(object).toISOString();
20
+ return object ? new Date(object).toISOString() : object;
21
21
  }
22
22
  };
23
23
  DateMapper = __decorate([
@@ -1 +1 @@
1
- {"version":3,"file":"DateMapper.js","sourceRoot":"","sources":["../../../src/components/DateMapper.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,YAAY,CAAC;AACrC,OAAO,EAAC,UAAU,EAAC,MAAM,0BAA0B,CAAC;AAGpD;;;;GAIG;AAEH,IAAa,UAAU,GAAvB,MAAa,UAAU;IAGrB,WAAW,CAAC,IAAS;QACnB,6EAA6E;QAC7E,6EAA6E;QAC7E,oBAAoB;QACpB,IAAI,SAAS,CAAC,IAAI,CAAC,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,SAAS,EAAE;YAC1D,OAAO,IAAI,CAAC;SACb;QAED,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC;IACxB,CAAC;IAED,SAAS,CAAC,MAAY;QACpB,OAAO,IAAI,IAAI,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,CAAC;IACxC,CAAC;CACF,CAAA;AAjBY,UAAU;IADtB,UAAU,CAAC,IAAI,CAAC;GACJ,UAAU,CAiBtB;SAjBY,UAAU"}
1
+ {"version":3,"file":"DateMapper.js","sourceRoot":"","sources":["../../../src/components/DateMapper.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,YAAY,CAAC;AACrC,OAAO,EAAC,UAAU,EAAC,MAAM,0BAA0B,CAAC;AAGpD;;;;GAIG;AAEI,IAAM,UAAU,GAAhB,MAAM,UAAU;IAGrB,WAAW,CAAC,IAAS;QACnB,6EAA6E;QAC7E,6EAA6E;QAC7E,oBAAoB;QACpB,IAAI,SAAS,CAAC,IAAI,CAAC,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,SAAS,EAAE;YAC1D,OAAO,IAAI,CAAC;SACb;QAED,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC;IACxB,CAAC;IAED,SAAS,CAAC,MAAY;QACpB,OAAO,MAAM,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC;IAC1D,CAAC;CACF,CAAA;AAjBY,UAAU;IADtB,UAAU,CAAC,IAAI,CAAC;GACJ,UAAU,CAiBtB;SAjBY,UAAU"}
@@ -1,4 +1,5 @@
1
1
  import { __decorate } from "tslib";
2
+ import { nameOf } from "@tsed/core";
2
3
  import { JsonMapper } from "../decorators/jsonMapper.js";
3
4
  function isNullish(data) {
4
5
  return [null, "null"].includes(data);
@@ -16,36 +17,39 @@ export class CastError extends Error {
16
17
  */
17
18
  let PrimitiveMapper = class PrimitiveMapper {
18
19
  deserialize(data, ctx) {
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
- }
20
+ return this[nameOf(ctx.type)] ? this[nameOf(ctx.type)](data, ctx) : undefined;
45
21
  }
46
22
  serialize(object) {
47
23
  return object;
48
24
  }
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
+ }
49
53
  };
50
54
  PrimitiveMapper = __decorate([
51
55
  JsonMapper(String, Number, Boolean, BigInt)
@@ -1 +1 @@
1
- {"version":3,"file":"PrimitiveMapper.js","sourceRoot":"","sources":["../../../src/components/PrimitiveMapper.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,0BAA0B,CAAC;AAGpD,SAAS,SAAS,CAAC,IAAS;IAC1B,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;AACvC,CAAC;AA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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;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"}