@tsed/json-mapper 7.35.0-rc.1 → 7.35.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.
- package/jest.config.js +3 -3
- package/lib/browser/json-mapper.umd.min.js +1 -1
- package/lib/browser/json-mapper.umd.min.js.map +1 -1
- package/lib/cjs/components/ArrayMapper.js +23 -0
- package/lib/cjs/components/ArrayMapper.js.map +1 -0
- package/lib/cjs/components/DateMapper.js +1 -1
- package/lib/cjs/components/DateMapper.js.map +1 -1
- package/lib/cjs/components/MapMapper.js +30 -0
- package/lib/cjs/components/MapMapper.js.map +1 -0
- package/lib/cjs/components/PrimitiveMapper.js +26 -30
- package/lib/cjs/components/PrimitiveMapper.js.map +1 -1
- package/lib/cjs/components/SetMapper.js +30 -0
- package/lib/cjs/components/SetMapper.js.map +1 -0
- package/lib/cjs/components/SymbolMapper.js.map +1 -1
- package/lib/cjs/domain/JsonMapperContext.js +27 -0
- package/lib/cjs/domain/JsonMapperContext.js.map +1 -0
- package/lib/cjs/index.js +4 -9
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/utils/deserialize.js +202 -5
- package/lib/cjs/utils/deserialize.js.map +1 -1
- package/lib/cjs/utils/serialize.js +143 -5
- package/lib/cjs/utils/serialize.js.map +1 -1
- package/lib/esm/components/ArrayMapper.js +20 -0
- package/lib/esm/components/ArrayMapper.js.map +1 -0
- package/lib/esm/components/DateMapper.js +1 -1
- package/lib/esm/components/DateMapper.js.map +1 -1
- package/lib/esm/components/MapMapper.js +27 -0
- package/lib/esm/components/MapMapper.js.map +1 -0
- package/lib/esm/components/PrimitiveMapper.js +26 -30
- package/lib/esm/components/PrimitiveMapper.js.map +1 -1
- package/lib/esm/components/SetMapper.js +27 -0
- package/lib/esm/components/SetMapper.js.map +1 -0
- package/lib/esm/components/SymbolMapper.js.map +1 -1
- package/lib/esm/domain/JsonMapperContext.js +23 -0
- package/lib/esm/domain/JsonMapperContext.js.map +1 -0
- package/lib/esm/index.js +4 -9
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/utils/deserialize.js +200 -4
- package/lib/esm/utils/deserialize.js.map +1 -1
- package/lib/esm/utils/serialize.js +141 -4
- package/lib/esm/utils/serialize.js.map +1 -1
- package/lib/tsconfig.esm.tsbuildinfo +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types/components/ArrayMapper.d.ts +10 -0
- package/lib/types/components/MapMapper.d.ts +12 -0
- package/lib/types/components/PrimitiveMapper.d.ts +0 -4
- package/lib/types/components/SetMapper.d.ts +10 -0
- package/lib/types/domain/JsonMapperContext.d.ts +20 -0
- package/lib/types/index.d.ts +4 -9
- package/lib/types/utils/deserialize.d.ts +47 -2
- package/lib/types/utils/serialize.d.ts +18 -2
- package/package.json +8 -11
- package/lib/cjs/domain/JsonDeserializer.js +0 -275
- package/lib/cjs/domain/JsonDeserializer.js.map +0 -1
- package/lib/cjs/domain/JsonDeserializerOptions.js +0 -3
- package/lib/cjs/domain/JsonDeserializerOptions.js.map +0 -1
- package/lib/cjs/domain/JsonMapperCompiler.js +0 -167
- package/lib/cjs/domain/JsonMapperCompiler.js.map +0 -1
- package/lib/cjs/domain/JsonSerializer.js +0 -219
- package/lib/cjs/domain/JsonSerializer.js.map +0 -1
- package/lib/cjs/domain/JsonSerializerOptions.js +0 -3
- package/lib/cjs/domain/JsonSerializerOptions.js.map +0 -1
- package/lib/cjs/domain/Writer.js +0 -141
- package/lib/cjs/domain/Writer.js.map +0 -1
- package/lib/cjs/hooks/alterOnDeserialize.js +0 -8
- package/lib/cjs/hooks/alterOnDeserialize.js.map +0 -1
- package/lib/cjs/hooks/alterOnSerialize.js +0 -8
- package/lib/cjs/hooks/alterOnSerialize.js.map +0 -1
- package/lib/cjs/utils/getObjectProperties.js +0 -9
- package/lib/cjs/utils/getObjectProperties.js.map +0 -1
- package/lib/esm/domain/JsonDeserializer.js +0 -271
- package/lib/esm/domain/JsonDeserializer.js.map +0 -1
- package/lib/esm/domain/JsonDeserializerOptions.js +0 -2
- package/lib/esm/domain/JsonDeserializerOptions.js.map +0 -1
- package/lib/esm/domain/JsonMapperCompiler.js +0 -163
- package/lib/esm/domain/JsonMapperCompiler.js.map +0 -1
- package/lib/esm/domain/JsonSerializer.js +0 -215
- package/lib/esm/domain/JsonSerializer.js.map +0 -1
- package/lib/esm/domain/JsonSerializerOptions.js +0 -2
- package/lib/esm/domain/JsonSerializerOptions.js.map +0 -1
- package/lib/esm/domain/Writer.js +0 -137
- package/lib/esm/domain/Writer.js.map +0 -1
- package/lib/esm/hooks/alterOnDeserialize.js +0 -4
- package/lib/esm/hooks/alterOnDeserialize.js.map +0 -1
- package/lib/esm/hooks/alterOnSerialize.js +0 -4
- package/lib/esm/hooks/alterOnSerialize.js.map +0 -1
- package/lib/esm/utils/getObjectProperties.js +0 -5
- package/lib/esm/utils/getObjectProperties.js.map +0 -1
- package/lib/types/domain/JsonDeserializer.d.ts +0 -33
- package/lib/types/domain/JsonDeserializerOptions.d.ts +0 -31
- package/lib/types/domain/JsonMapperCompiler.d.ts +0 -58
- package/lib/types/domain/JsonSerializer.d.ts +0 -21
- package/lib/types/domain/JsonSerializerOptions.d.ts +0 -13
- package/lib/types/domain/Writer.d.ts +0 -43
- package/lib/types/hooks/alterOnDeserialize.d.ts +0 -2
- package/lib/types/hooks/alterOnSerialize.d.ts +0 -2
- package/lib/types/utils/getObjectProperties.d.ts +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrimitiveMapper.js","sourceRoot":"","sources":["../../../src/components/PrimitiveMapper.ts"],"names":[],"mappings":";;;;AAAA,
|
|
1
|
+
{"version":3,"file":"PrimitiveMapper.js","sourceRoot":"","sources":["../../../src/components/PrimitiveMapper.ts"],"names":[],"mappings":";;;;AAAA,yDAAoD;AAGpD,SAAS,SAAS,CAAC,IAAS;IAC1B,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;AACv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OAAO,MAAM,CAAC;IAChB,CAAC;CACF,CAAA;AAnCY,eAAe;IAD3B,IAAA,uBAAU,EAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC;GAC/B,eAAe,CAmC3B;AAnCY,0CAAe"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SetMapper = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const core_1 = require("@tsed/core");
|
|
6
|
+
const jsonMapper_1 = require("../decorators/jsonMapper");
|
|
7
|
+
/**
|
|
8
|
+
* Mapper for the `Set` Type.
|
|
9
|
+
* @jsonmapper
|
|
10
|
+
* @component
|
|
11
|
+
*/
|
|
12
|
+
let SetMapper = class SetMapper {
|
|
13
|
+
deserialize(data, ctx) {
|
|
14
|
+
const obj = new Set();
|
|
15
|
+
(0, core_1.objectKeys)(data).forEach((key) => {
|
|
16
|
+
obj.add(ctx.next(data[key]));
|
|
17
|
+
});
|
|
18
|
+
return obj;
|
|
19
|
+
}
|
|
20
|
+
serialize(data, ctx) {
|
|
21
|
+
const array = [];
|
|
22
|
+
data.forEach((value) => array.push(ctx.next(value)));
|
|
23
|
+
return array;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
SetMapper = tslib_1.__decorate([
|
|
27
|
+
(0, jsonMapper_1.JsonMapper)(Set)
|
|
28
|
+
], SetMapper);
|
|
29
|
+
exports.SetMapper = SetMapper;
|
|
30
|
+
//# sourceMappingURL=SetMapper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SetMapper.js","sourceRoot":"","sources":["../../../src/components/SetMapper.ts"],"names":[],"mappings":";;;;AAAA,qCAAsC;AACtC,yDAAoD;AAGpD;;;;GAIG;AAEH,IAAa,SAAS,GAAtB,MAAa,SAAS;IACpB,WAAW,CAAI,IAAS,EAAE,GAAkB;QAC1C,MAAM,GAAG,GAAG,IAAI,GAAG,EAAK,CAAC;QAEzB,IAAA,iBAAU,EAAC,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,IAAA,uBAAU,EAAC,GAAG,CAAC;GACH,SAAS,CAkBrB;AAlBY,8BAAS"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SymbolMapper.js","sourceRoot":"","sources":["../../../src/components/SymbolMapper.ts"],"names":[],"mappings":";;;;AAAA,yDAAoD;AAGpD;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"SymbolMapper.js","sourceRoot":"","sources":["../../../src/components/SymbolMapper.ts"],"names":[],"mappings":";;;;AAAA,yDAAoD;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,IAAA,uBAAU,EAAC,MAAM,CAAC;GACN,YAAY,CAQxB;AARY,oCAAY"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.JsonMapperContext = void 0;
|
|
4
|
+
const core_1 = require("@tsed/core");
|
|
5
|
+
/**
|
|
6
|
+
* @ignore
|
|
7
|
+
*/
|
|
8
|
+
class JsonMapperContext {
|
|
9
|
+
collectionType;
|
|
10
|
+
type;
|
|
11
|
+
options;
|
|
12
|
+
_next;
|
|
13
|
+
constructor({ type, collectionType, next, options }) {
|
|
14
|
+
this.type = type;
|
|
15
|
+
this.collectionType = (0, core_1.isCollection)(collectionType) ? collectionType : undefined;
|
|
16
|
+
this._next = next;
|
|
17
|
+
this.options = options;
|
|
18
|
+
}
|
|
19
|
+
next(data) {
|
|
20
|
+
return this._next(data, {
|
|
21
|
+
...this.options,
|
|
22
|
+
type: this.type
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.JsonMapperContext = JsonMapperContext;
|
|
27
|
+
//# sourceMappingURL=JsonMapperContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JsonMapperContext.js","sourceRoot":"","sources":["../../../src/domain/JsonMapperContext.ts"],"names":[],"mappings":";;;AAAA,qCAA8C;AAS9C;;GAEG;AACH,MAAa,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,IAAA,mBAAY,EAAC,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;AAnBD,8CAmBC"}
|
package/lib/cjs/index.js
CHANGED
|
@@ -4,28 +4,23 @@
|
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const tslib_1 = require("tslib");
|
|
7
|
+
tslib_1.__exportStar(require("./components/ArrayMapper"), exports);
|
|
7
8
|
tslib_1.__exportStar(require("./components/DateMapper"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./components/MapMapper"), exports);
|
|
8
10
|
tslib_1.__exportStar(require("./components/PrimitiveMapper"), exports);
|
|
11
|
+
tslib_1.__exportStar(require("./components/SetMapper"), exports);
|
|
9
12
|
tslib_1.__exportStar(require("./components/SymbolMapper"), exports);
|
|
10
13
|
tslib_1.__exportStar(require("./decorators/afterDeserialize"), exports);
|
|
11
14
|
tslib_1.__exportStar(require("./decorators/beforeDeserialize"), exports);
|
|
12
15
|
tslib_1.__exportStar(require("./decorators/jsonMapper"), exports);
|
|
13
16
|
tslib_1.__exportStar(require("./decorators/onDeserialize"), exports);
|
|
14
17
|
tslib_1.__exportStar(require("./decorators/onSerialize"), exports);
|
|
15
|
-
tslib_1.__exportStar(require("./domain/
|
|
16
|
-
tslib_1.__exportStar(require("./domain/JsonDeserializerOptions"), exports);
|
|
17
|
-
tslib_1.__exportStar(require("./domain/JsonMapperCompiler"), exports);
|
|
18
|
+
tslib_1.__exportStar(require("./domain/JsonMapperContext"), exports);
|
|
18
19
|
tslib_1.__exportStar(require("./domain/JsonMapperSettings"), exports);
|
|
19
20
|
tslib_1.__exportStar(require("./domain/JsonMapperTypesContainer"), exports);
|
|
20
|
-
tslib_1.__exportStar(require("./domain/JsonSerializer"), exports);
|
|
21
|
-
tslib_1.__exportStar(require("./domain/JsonSerializerOptions"), exports);
|
|
22
|
-
tslib_1.__exportStar(require("./domain/Writer"), exports);
|
|
23
21
|
tslib_1.__exportStar(require("./hooks/alterAfterDeserialize"), exports);
|
|
24
22
|
tslib_1.__exportStar(require("./hooks/alterBeforeDeserialize"), exports);
|
|
25
|
-
tslib_1.__exportStar(require("./hooks/alterOnDeserialize"), exports);
|
|
26
|
-
tslib_1.__exportStar(require("./hooks/alterOnSerialize"), exports);
|
|
27
23
|
tslib_1.__exportStar(require("./interfaces/JsonMapperMethods"), exports);
|
|
28
24
|
tslib_1.__exportStar(require("./utils/deserialize"), exports);
|
|
29
|
-
tslib_1.__exportStar(require("./utils/getObjectProperties"), exports);
|
|
30
25
|
tslib_1.__exportStar(require("./utils/serialize"), exports);
|
|
31
26
|
//# sourceMappingURL=index.js.map
|
package/lib/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,kEAAwC;AACxC,uEAA6C;AAC7C,oEAA0C;AAC1C,wEAA8C;AAC9C,yEAA+C;AAC/C,kEAAwC;AACxC,qEAA2C;AAC3C,mEAAyC;AACzC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,mEAAyC;AACzC,kEAAwC;AACxC,iEAAuC;AACvC,uEAA6C;AAC7C,iEAAuC;AACvC,oEAA0C;AAC1C,wEAA8C;AAC9C,yEAA+C;AAC/C,kEAAwC;AACxC,qEAA2C;AAC3C,mEAAyC;AACzC,qEAA2C;AAC3C,sEAA4C;AAC5C,4EAAkD;AAClD,wEAA8C;AAC9C,yEAA+C;AAC/C,yEAA+C;AAC/C,8DAAoC;AACpC,4DAAkC"}
|
|
@@ -1,13 +1,210 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.deserialize = void 0;
|
|
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");
|
|
4
7
|
require("../components/DateMapper");
|
|
8
|
+
require("../components/MapMapper");
|
|
5
9
|
require("../components/PrimitiveMapper");
|
|
10
|
+
require("../components/SetMapper");
|
|
6
11
|
require("../components/SymbolMapper");
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
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);
|
|
11
208
|
}
|
|
12
209
|
exports.deserialize = deserialize;
|
|
13
210
|
//# sourceMappingURL=deserialize.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deserialize.js","sourceRoot":"","sources":["../../../src/utils/deserialize.ts"],"names":[],"mappings":";;;AAAA,oCAAkC;AAClC,yCAAuC;AACvC,sCAAoC;
|
|
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,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,KAAK,MAAM,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC;AAC1F,CAAC;AAED,SAAS,UAAU,CAAC,MAAkB,EAAE,KAAU,EAAE,OAAwB;IAC1E,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,eAAe,EAAE,KAAK,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;AAChE,CAAC;AAED,SAAS,mBAAmB,CAAU,GAAQ,EAAE,OAA0C;IACxF,MAAM,EAAC,KAAK,EAAE,IAAI,GAAG,MAAM,EAAE,cAAc,EAAC,GAAG,OAAO,CAAC;IAEvD,MAAM,OAAO,GAAG,IAAI,qCAAiB,CAAC;QACpC,IAAI;QACJ,cAAc;QACd,OAAO;QACP,IAAI,EAAE,CAAC,IAAI,EAAE,EAAC,cAAc,EAAE,GAAG,OAAO,EAAC,EAAE,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AAO,EAAE,IAAI,EAAC,CAAC,CAAC;KACpD;IAED,kBAAkB;IAClB,OAAO,kBAAkB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;AAC1C,CAAC;AAjCD,kCAiCC"}
|
|
@@ -1,13 +1,151 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.serialize = void 0;
|
|
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");
|
|
4
7
|
require("../components/DateMapper");
|
|
8
|
+
require("../components/MapMapper");
|
|
5
9
|
require("../components/PrimitiveMapper");
|
|
10
|
+
require("../components/SetMapper");
|
|
6
11
|
require("../components/SymbolMapper");
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
function
|
|
10
|
-
return
|
|
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);
|
|
11
149
|
}
|
|
12
150
|
exports.serialize = serialize;
|
|
13
151
|
//# sourceMappingURL=serialize.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serialize.js","sourceRoot":"","sources":["../../../src/utils/serialize.ts"],"names":[],"mappings":";;;AAAA,oCAAkC;AAClC,yCAAuC;AACvC,sCAAoC;
|
|
1
|
+
{"version":3,"file":"serialize.js","sourceRoot":"","sources":["../../../src/utils/serialize.ts"],"names":[],"mappings":";;;AAAA,qCAaoB;AACpB,yCAA4G;AAC5G,qCAAmC;AACnC,oCAAkC;AAClC,mCAAiC;AACjC,yCAAuC;AACvC,mCAAi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,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"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
|
+
import { JsonMapper } from "../decorators/jsonMapper.js";
|
|
3
|
+
/**
|
|
4
|
+
* Mapper for `Array` type.
|
|
5
|
+
* @jsonmapper
|
|
6
|
+
* @component
|
|
7
|
+
*/
|
|
8
|
+
let ArrayMapper = class ArrayMapper {
|
|
9
|
+
deserialize(data, options) {
|
|
10
|
+
return [].concat(data).map((item) => options.next(item));
|
|
11
|
+
}
|
|
12
|
+
serialize(data, options) {
|
|
13
|
+
return [].concat(data).map((item) => options.next(item));
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
ArrayMapper = __decorate([
|
|
17
|
+
JsonMapper(Array)
|
|
18
|
+
], ArrayMapper);
|
|
19
|
+
export { ArrayMapper };
|
|
20
|
+
//# sourceMappingURL=ArrayMapper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ArrayMapper.js","sourceRoot":"","sources":["../../../src/components/ArrayMapper.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,0BAA0B,CAAC;AAGpD;;;;GAIG;AAEH,IAAa,WAAW,GAAxB,MAAa,WAAW;IACtB,WAAW,CAAU,IAAS,EAAE,OAAsB;QACpD,OAAO,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAC3D,CAAC;IAED,SAAS,CAAC,IAAW,EAAE,OAAsB;QAC3C,OAAO,EAAE,CAAC,MAAM,CAAC,IAAW,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAClE,CAAC;CACF,CAAA;AARY,WAAW;IADvB,UAAU,CAAC,KAAK,CAAC;GACL,WAAW,CAQvB;SARY,WAAW"}
|
|
@@ -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;
|
|
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"}
|
|
@@ -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 `Map` type.
|
|
6
|
+
* @jsonmapper
|
|
7
|
+
* @component
|
|
8
|
+
*/
|
|
9
|
+
let MapMapper = class MapMapper {
|
|
10
|
+
deserialize(data, ctx) {
|
|
11
|
+
const obj = new Map();
|
|
12
|
+
objectKeys(data).forEach((key) => {
|
|
13
|
+
obj.set(key, ctx.next(data[key]));
|
|
14
|
+
});
|
|
15
|
+
return obj;
|
|
16
|
+
}
|
|
17
|
+
serialize(data, ctx) {
|
|
18
|
+
const obj = {};
|
|
19
|
+
data.forEach((value, key) => (obj[key] = ctx.next(value)));
|
|
20
|
+
return obj;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
MapMapper = __decorate([
|
|
24
|
+
JsonMapper(Map)
|
|
25
|
+
], MapMapper);
|
|
26
|
+
export { MapMapper };
|
|
27
|
+
//# sourceMappingURL=MapMapper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MapMapper.js","sourceRoot":"","sources":["../../../src/components/MapMapper.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,CAA8B,IAA0B,EAAE,GAAwB;QAC3F,MAAM,GAAG,GAAG,IAAI,GAAG,EAAa,CAAC;QAEjC,UAAU,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;YAC/B,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAM,CAAC,CAAC;QACzC,CAAC,CAAC,CAAC;QAEH,OAAO,GAAG,CAAC;IACb,CAAC;IAED,SAAS,CAAI,IAAoB,EAAE,GAAkB;QACnD,MAAM,GAAG,GAAQ,EAAE,CAAC;QAEpB,IAAI,CAAC,OAAO,CAAC,CAAC,KAAQ,EAAE,GAAW,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAEtE,OAAO,GAAG,CAAC;IACb,CAAC;CACF,CAAA;AAlBY,SAAS;IADrB,UAAU,CAAC,GAAG,CAAC;GACH,SAAS,CAkBrB;SAlBY,SAAS"}
|