@tsed/json-mapper 6.133.0 → 6.133.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.
- package/lib/cjs/components/PrimitiveMapper.js +11 -4
- package/lib/cjs/components/PrimitiveMapper.js.map +1 -1
- package/lib/esm/components/PrimitiveMapper.js +11 -4
- package/lib/esm/components/PrimitiveMapper.js.map +1 -1
- package/lib/types/components/PrimitiveMapper.d.ts +3 -3
- package/package.json +8 -8
- package/readme.md +5 -5
|
@@ -4,8 +4,11 @@ exports.PrimitiveMapper = void 0;
|
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const exceptions_1 = require("@tsed/exceptions");
|
|
6
6
|
const jsonMapper_1 = require("../decorators/jsonMapper");
|
|
7
|
+
function isNullish(data) {
|
|
8
|
+
return [null, "null"].includes(data);
|
|
9
|
+
}
|
|
7
10
|
/**
|
|
8
|
-
* Mapper for the `String`, `Number` and `Boolean` types.
|
|
11
|
+
* Mapper for the `String`, `Number`, `BigInt` and `Boolean` types.
|
|
9
12
|
* @jsonmapper
|
|
10
13
|
* @component
|
|
11
14
|
*/
|
|
@@ -14,8 +17,12 @@ let PrimitiveMapper = class PrimitiveMapper {
|
|
|
14
17
|
switch (ctx.type) {
|
|
15
18
|
case String:
|
|
16
19
|
return data === null ? null : "" + data;
|
|
20
|
+
case BigInt:
|
|
21
|
+
if (isNullish(data))
|
|
22
|
+
return null;
|
|
23
|
+
return BigInt(data);
|
|
17
24
|
case Number:
|
|
18
|
-
if (
|
|
25
|
+
if (isNullish(data))
|
|
19
26
|
return null;
|
|
20
27
|
const n = +data;
|
|
21
28
|
if (isNaN(n)) {
|
|
@@ -27,7 +34,7 @@ let PrimitiveMapper = class PrimitiveMapper {
|
|
|
27
34
|
return true;
|
|
28
35
|
if (["false", "0", false].includes(data))
|
|
29
36
|
return false;
|
|
30
|
-
if (
|
|
37
|
+
if (isNullish(data))
|
|
31
38
|
return null;
|
|
32
39
|
if (data === undefined)
|
|
33
40
|
return undefined;
|
|
@@ -39,7 +46,7 @@ let PrimitiveMapper = class PrimitiveMapper {
|
|
|
39
46
|
}
|
|
40
47
|
};
|
|
41
48
|
PrimitiveMapper = tslib_1.__decorate([
|
|
42
|
-
(0, jsonMapper_1.JsonMapper)(String, Number, Boolean)
|
|
49
|
+
(0, jsonMapper_1.JsonMapper)(String, Number, Boolean, BigInt)
|
|
43
50
|
], PrimitiveMapper);
|
|
44
51
|
exports.PrimitiveMapper = PrimitiveMapper;
|
|
45
52
|
//# sourceMappingURL=PrimitiveMapper.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrimitiveMapper.js","sourceRoot":"","sources":["../../../src/components/PrimitiveMapper.ts"],"names":[],"mappings":";;;;AAAA,iDAA4C;AAC5C,yDAAoD;AAGpD;;;;GAIG;AAEH,IAAa,eAAe,GAA5B,MAAa,eAAe;IAC1B,WAAW,CAAI,IAAS,EAAE,GAAkB;QAC1C,QAAQ,GAAG,CAAC,IAAI,EAAE;YAChB,KAAK,MAAM;gBACT,OAAO,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC;YAE1C,KAAK,MAAM;gBACT,IAAI,CAAC,IAAI,
|
|
1
|
+
{"version":3,"file":"PrimitiveMapper.js","sourceRoot":"","sources":["../../../src/components/PrimitiveMapper.ts"],"names":[],"mappings":";;;;AAAA,iDAA4C;AAC5C,yDAAoD;AAGpD,SAAS,SAAS,CAAC,IAAS;IAC1B,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;AACvC,CAAC;AAED;;;;GAIG;AAEH,IAAa,eAAe,GAA5B,MAAa,eAAe;IAC1B,WAAW,CAAI,IAAS,EAAE,GAAkB;QAC1C,QAAQ,GAAG,CAAC,IAAI,EAAE;YAChB,KAAK,MAAM;gBACT,OAAO,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC;YAE1C,KAAK,MAAM;gBACT,IAAI,SAAS,CAAC,IAAI,CAAC;oBAAE,OAAO,IAAI,CAAC;gBAEjC,OAAO,MAAM,CAAC,IAAI,CAAC,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,uBAAU,CAAC,+CAA+C,CAAC,CAAC;iBACvE;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,IAAA,uBAAU,EAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC;GAC/B,eAAe,CAmC3B;AAnCY,0CAAe","sourcesContent":["import {BadRequest} from \"@tsed/exceptions\";\nimport {JsonMapper} from \"../decorators/jsonMapper\";\nimport {JsonMapperCtx, JsonMapperMethods} from \"../interfaces/JsonMapperMethods\";\n\nfunction isNullish(data: any) {\n return [null, \"null\"].includes(data);\n}\n\n/**\n * Mapper for the `String`, `Number`, `BigInt` and `Boolean` types.\n * @jsonmapper\n * @component\n */\n@JsonMapper(String, Number, Boolean, BigInt)\nexport class PrimitiveMapper implements JsonMapperMethods {\n deserialize<T>(data: any, ctx: JsonMapperCtx): string | number | boolean | void | null | BigInt {\n switch (ctx.type) {\n case String:\n return data === null ? null : \"\" + data;\n\n case BigInt:\n if (isNullish(data)) return null;\n\n return BigInt(data);\n\n case Number:\n if (isNullish(data)) return null;\n\n const n = +data;\n\n if (isNaN(n)) {\n throw new BadRequest(\"Cast error. Expression value is not a number.\");\n }\n\n return n;\n\n case Boolean:\n if ([\"true\", \"1\", true].includes(data)) return true;\n if ([\"false\", \"0\", false].includes(data)) return false;\n if (isNullish(data)) return null;\n if (data === undefined) return undefined;\n\n return !!data;\n }\n }\n\n serialize(object: string | number | boolean | BigInt): string | number | boolean | BigInt {\n return object;\n }\n}\n"]}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { __decorate } from "tslib";
|
|
2
2
|
import { BadRequest } from "@tsed/exceptions";
|
|
3
3
|
import { JsonMapper } from "../decorators/jsonMapper.js";
|
|
4
|
+
function isNullish(data) {
|
|
5
|
+
return [null, "null"].includes(data);
|
|
6
|
+
}
|
|
4
7
|
/**
|
|
5
|
-
* Mapper for the `String`, `Number` and `Boolean` types.
|
|
8
|
+
* Mapper for the `String`, `Number`, `BigInt` and `Boolean` types.
|
|
6
9
|
* @jsonmapper
|
|
7
10
|
* @component
|
|
8
11
|
*/
|
|
@@ -11,8 +14,12 @@ let PrimitiveMapper = class PrimitiveMapper {
|
|
|
11
14
|
switch (ctx.type) {
|
|
12
15
|
case String:
|
|
13
16
|
return data === null ? null : "" + data;
|
|
17
|
+
case BigInt:
|
|
18
|
+
if (isNullish(data))
|
|
19
|
+
return null;
|
|
20
|
+
return BigInt(data);
|
|
14
21
|
case Number:
|
|
15
|
-
if (
|
|
22
|
+
if (isNullish(data))
|
|
16
23
|
return null;
|
|
17
24
|
const n = +data;
|
|
18
25
|
if (isNaN(n)) {
|
|
@@ -24,7 +31,7 @@ let PrimitiveMapper = class PrimitiveMapper {
|
|
|
24
31
|
return true;
|
|
25
32
|
if (["false", "0", false].includes(data))
|
|
26
33
|
return false;
|
|
27
|
-
if (
|
|
34
|
+
if (isNullish(data))
|
|
28
35
|
return null;
|
|
29
36
|
if (data === undefined)
|
|
30
37
|
return undefined;
|
|
@@ -36,7 +43,7 @@ let PrimitiveMapper = class PrimitiveMapper {
|
|
|
36
43
|
}
|
|
37
44
|
};
|
|
38
45
|
PrimitiveMapper = __decorate([
|
|
39
|
-
JsonMapper(String, Number, Boolean)
|
|
46
|
+
JsonMapper(String, Number, Boolean, BigInt)
|
|
40
47
|
], PrimitiveMapper);
|
|
41
48
|
export { PrimitiveMapper };
|
|
42
49
|
//# sourceMappingURL=PrimitiveMapper.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrimitiveMapper.js","sourceRoot":"","sources":["../../../src/components/PrimitiveMapper.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAC,UAAU,EAAC,MAAM,0BAA0B,CAAC;AAGpD;;;;GAIG;AAEH,IAAa,eAAe,GAA5B,MAAa,eAAe;IAC1B,WAAW,CAAI,IAAS,EAAE,GAAkB;QAC1C,QAAQ,GAAG,CAAC,IAAI,EAAE;YAChB,KAAK,MAAM;gBACT,OAAO,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC;YAE1C,KAAK,MAAM;gBACT,IAAI,CAAC,IAAI,
|
|
1
|
+
{"version":3,"file":"PrimitiveMapper.js","sourceRoot":"","sources":["../../../src/components/PrimitiveMapper.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAC,UAAU,EAAC,MAAM,0BAA0B,CAAC;AAGpD,SA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e;IAD3B,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC;GAC/B,eAAe,CAmC3B;SAnCY,eAAe","sourcesContent":["import {BadRequest} from \"@tsed/exceptions\";\nimport {JsonMapper} from \"../decorators/jsonMapper\";\nimport {JsonMapperCtx, JsonMapperMethods} from \"../interfaces/JsonMapperMethods\";\n\nfunction isNullish(data: any) {\n return [null, \"null\"].includes(data);\n}\n\n/**\n * Mapper for the `String`, `Number`, `BigInt` and `Boolean` types.\n * @jsonmapper\n * @component\n */\n@JsonMapper(String, Number, Boolean, BigInt)\nexport class PrimitiveMapper implements JsonMapperMethods {\n deserialize<T>(data: any, ctx: JsonMapperCtx): string | number | boolean | void | null | BigInt {\n switch (ctx.type) {\n case String:\n return data === null ? null : \"\" + data;\n\n case BigInt:\n if (isNullish(data)) return null;\n\n return BigInt(data);\n\n case Number:\n if (isNullish(data)) return null;\n\n const n = +data;\n\n if (isNaN(n)) {\n throw new BadRequest(\"Cast error. Expression value is not a number.\");\n }\n\n return n;\n\n case Boolean:\n if ([\"true\", \"1\", true].includes(data)) return true;\n if ([\"false\", \"0\", false].includes(data)) return false;\n if (isNullish(data)) return null;\n if (data === undefined) return undefined;\n\n return !!data;\n }\n }\n\n serialize(object: string | number | boolean | BigInt): string | number | boolean | BigInt {\n return object;\n }\n}\n"]}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { JsonMapperCtx, JsonMapperMethods } from "../interfaces/JsonMapperMethods";
|
|
2
2
|
/**
|
|
3
|
-
* Mapper for the `String`, `Number` and `Boolean` types.
|
|
3
|
+
* Mapper for the `String`, `Number`, `BigInt` and `Boolean` types.
|
|
4
4
|
* @jsonmapper
|
|
5
5
|
* @component
|
|
6
6
|
*/
|
|
7
7
|
export declare class PrimitiveMapper implements JsonMapperMethods {
|
|
8
|
-
deserialize<T>(data: any, ctx: JsonMapperCtx): string | number | boolean | void | null;
|
|
9
|
-
serialize(object: string | number | boolean): string | number | boolean;
|
|
8
|
+
deserialize<T>(data: any, ctx: JsonMapperCtx): string | number | boolean | void | null | BigInt;
|
|
9
|
+
serialize(object: string | number | boolean | BigInt): string | number | boolean | BigInt;
|
|
10
10
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/json-mapper",
|
|
3
|
-
"version": "6.133.
|
|
3
|
+
"version": "6.133.2",
|
|
4
4
|
"description": "Json mapper module for Ts.ED Framework",
|
|
5
5
|
"private": false,
|
|
6
6
|
"source": "./src/index.ts",
|
|
@@ -36,14 +36,14 @@
|
|
|
36
36
|
"tslib": "2.4.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@tsed/core": "6.133.
|
|
40
|
-
"@tsed/exceptions": "6.133.
|
|
41
|
-
"@tsed/schema": "6.133.
|
|
39
|
+
"@tsed/core": "6.133.2",
|
|
40
|
+
"@tsed/exceptions": "6.133.2",
|
|
41
|
+
"@tsed/schema": "6.133.2"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
|
-
"@tsed/core": "^6.133.
|
|
45
|
-
"@tsed/exceptions": "^6.133.
|
|
46
|
-
"@tsed/schema": "^6.133.
|
|
44
|
+
"@tsed/core": "^6.133.2",
|
|
45
|
+
"@tsed/exceptions": "^6.133.2",
|
|
46
|
+
"@tsed/schema": "^6.133.2"
|
|
47
47
|
},
|
|
48
48
|
"peerDependenciesMeta": {
|
|
49
49
|
"@tsed/core": {
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"bugs": {
|
|
61
61
|
"url": "https://github.com/tsedio/tsed/issues"
|
|
62
62
|
},
|
|
63
|
-
"homepage": "https://github.com/tsedio/tsed/tree/
|
|
63
|
+
"homepage": "https://github.com/tsedio/tsed/tree/6.x/packages/specs/json-mapper",
|
|
64
64
|
"author": "Romain Lenzotti",
|
|
65
65
|
"license": "MIT"
|
|
66
66
|
}
|
package/readme.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<p style="text-align: center" align="center">
|
|
2
|
-
<a href="https://tsed.
|
|
2
|
+
<a href="https://tsed.dev" target="_blank"><img src="https://tsed.dev/tsed-og.png" width="200" alt="Ts.ED logo"/></a>
|
|
3
3
|
</p>
|
|
4
4
|
|
|
5
5
|
<div align="center">
|
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
</div>
|
|
18
18
|
|
|
19
19
|
<div align="center">
|
|
20
|
-
<a href="https://tsed.
|
|
20
|
+
<a href="https://tsed.dev/">Website</a>
|
|
21
21
|
<span> • </span>
|
|
22
|
-
<a href="https://tsed.
|
|
22
|
+
<a href="https://tsed.dev/getting-started/">Getting started</a>
|
|
23
23
|
<span> • </span>
|
|
24
24
|
<a href="https://api.tsed.io/rest/slack/tsedio/tsed">Slack</a>
|
|
25
25
|
<span> • </span>
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
</div>
|
|
28
28
|
|
|
29
29
|
<hr />
|
|
30
|
-
A package of Ts.ED framework. See website: https://tsed.
|
|
30
|
+
A package of Ts.ED framework. See website: https://tsed.dev/
|
|
31
31
|
|
|
32
32
|
The `@tsed/json-mapper` package is responsible to map a plain object to a model and a model to a plain object.
|
|
33
33
|
|
|
@@ -51,7 +51,7 @@ npm install --save @tsed/schema @tsed/json-mapper
|
|
|
51
51
|
|
|
52
52
|
## Contributors
|
|
53
53
|
|
|
54
|
-
Please read [contributing guidelines here](https://tsed.
|
|
54
|
+
Please read [contributing guidelines here](https://tsed.dev/CONTRIBUTING.html)
|
|
55
55
|
|
|
56
56
|
<a href="https://github.com/tsedio/ts-express-decorators/graphs/contributors"><img src="https://opencollective.com/tsed/contributors.svg?width=890" /></a>
|
|
57
57
|
|