@nestia/core 4.4.0-dev.20241216 → 4.4.0-dev.20241216-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/decorators/TypedParam.d.ts +1 -1
- package/lib/decorators/TypedParam.js +12 -7
- package/lib/decorators/TypedParam.js.map +1 -1
- package/lib/options/INestiaTransformOptions.d.ts +6 -2
- package/lib/programmers/TypedParamProgrammer.js +8 -0
- package/lib/programmers/TypedParamProgrammer.js.map +1 -1
- package/package.json +4 -4
- package/src/decorators/TypedParam.ts +16 -5
- package/src/options/INestiaTransformOptions.ts +11 -6
- package/src/programmers/TypedParamProgrammer.ts +3 -0
|
@@ -21,4 +21,4 @@
|
|
|
21
21
|
*
|
|
22
22
|
* @author Jeongho Nam - https://github.com/samchon
|
|
23
23
|
*/
|
|
24
|
-
export declare function TypedParam<T extends boolean | bigint | number | string | null>(name: string, assert?: (value: string) => T): ParameterDecorator;
|
|
24
|
+
export declare function TypedParam<T extends boolean | bigint | number | string | null>(name: string, assert?: (value: string) => T, validate?: boolean): ParameterDecorator;
|
|
@@ -30,12 +30,13 @@ const NoTransformConfigurationError_1 = require("./NoTransformConfigurationError
|
|
|
30
30
|
*
|
|
31
31
|
* @author Jeongho Nam - https://github.com/samchon
|
|
32
32
|
*/
|
|
33
|
-
function TypedParam(name, assert) {
|
|
33
|
+
function TypedParam(name, assert, validate) {
|
|
34
34
|
if (assert === undefined) {
|
|
35
35
|
(0, NoTransformConfigurationError_1.NoTransformConfigurationError)("TypedParam");
|
|
36
36
|
assert = (value) => value;
|
|
37
37
|
}
|
|
38
38
|
return (0, common_1.createParamDecorator)(function TypedParam({}, context) {
|
|
39
|
+
var _a;
|
|
39
40
|
const request = context
|
|
40
41
|
.switchToHttp()
|
|
41
42
|
.getRequest();
|
|
@@ -44,14 +45,18 @@ function TypedParam(name, assert) {
|
|
|
44
45
|
return assert(str);
|
|
45
46
|
}
|
|
46
47
|
catch (exp) {
|
|
47
|
-
if ((() => { const _io0 = input => "string" === typeof input.method && (undefined === input.path || "string" === typeof input.path) && "string" === typeof input.expected && true && true && "string" === typeof input.name && "string" === typeof input.message && (undefined === input.stack || "string" === typeof input.stack); return input => "object" === typeof input && null !== input && _io0(input); })()(exp))
|
|
48
|
-
|
|
49
|
-
path: exp.path,
|
|
50
|
-
reason: exp.message,
|
|
48
|
+
if ((() => { const _io0 = input => "string" === typeof input.method && (undefined === input.path || "string" === typeof input.path) && "string" === typeof input.expected && true && true && "string" === typeof input.name && "string" === typeof input.message && (undefined === input.stack || "string" === typeof input.stack); return input => "object" === typeof input && null !== input && _io0(input); })()(exp)) {
|
|
49
|
+
const trace = {
|
|
50
|
+
path: (_a = exp.path) !== null && _a !== void 0 ? _a : "$input",
|
|
51
51
|
expected: exp.expected,
|
|
52
52
|
value: exp.value,
|
|
53
|
-
|
|
54
|
-
}
|
|
53
|
+
};
|
|
54
|
+
throw new common_1.BadRequestException(Object.assign({ message: `Invalid URL parameter value on "${name}".` }, (validate === true
|
|
55
|
+
? {
|
|
56
|
+
errors: [trace],
|
|
57
|
+
}
|
|
58
|
+
: Object.assign(Object.assign({}, trace), { reason: exp.message }))));
|
|
59
|
+
}
|
|
55
60
|
throw exp;
|
|
56
61
|
}
|
|
57
62
|
})(name);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypedParam.js","sourceRoot":"","sources":["../../src/decorators/TypedParam.ts"],"names":[],"mappings":";;;;;AAkCA,
|
|
1
|
+
{"version":3,"file":"TypedParam.js","sourceRoot":"","sources":["../../src/decorators/TypedParam.ts"],"names":[],"mappings":";;;;;AAkCA,gCA0CC;AA5ED,2CAIwB;AAGxB,kDAA2D;AAE3D,mFAAgF;AAEhF;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,SAAgB,UAAU,CACxB,IAAY,EACZ,MAA6B,EAC7B,QAAkB;IAElB,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,IAAA,6DAA6B,EAAC,YAAY,CAAC,CAAC;QAC5C,MAAM,GAAG,CAAC,KAAK,EAAE,EAAE,CAAC,KAAU,CAAC;IACjC,CAAC;IAED,OAAO,IAAA,6BAAoB,EAAC,SAAS,UAAU,CAC7C,EAAO,EACP,OAAyB;;QAEzB,MAAM,OAAO,GAAqC,OAAO;aACtD,YAAY,EAAE;aACd,UAAU,EAAE,CAAC;QAChB,MAAM,GAAG,GAAY,OAAO,CAAC,MAAc,CAAC,IAAI,CAAC,CAAC;QAClD,IAAI,CAAC;YACH,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;QACrB,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,qZAA6B,GAAG,GAAG,CAAC;gBAClC,MAAM,KAAK,GAAuB;oBAChC,IAAI,EAAE,MAAA,GAAG,CAAC,IAAI,mCAAI,QAAQ;oBAC1B,QAAQ,EAAE,GAAG,CAAC,QAAQ;oBACtB,KAAK,EAAE,GAAG,CAAC,KAAK;iBACjB,CAAC;gBACF,MAAM,IAAI,4BAAmB,iBAC3B,OAAO,EAAE,mCAAmC,IAAI,IAAI,IACjD,CAAC,QAAQ,KAAK,IAAI;oBACnB,CAAC,CAAC;wBACE,MAAM,EAAE,CAAC,KAAK,CAAC;qBAChB;oBACH,CAAC,iCACM,KAAK,KACR,MAAM,EAAE,GAAG,CAAC,OAAO,GACpB,CAAC,EACN,CAAC;YACL,CAAC;YACD,MAAM,GAAG,CAAC;QACZ,CAAC;IACH,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;AACX,CAAC"}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
export interface INestiaTransformOptions {
|
|
2
|
-
validate?:
|
|
3
|
-
stringify?:
|
|
2
|
+
validate?: INestiaTransformOptions.Validate;
|
|
3
|
+
stringify?: INestiaTransformOptions.Stringify | null;
|
|
4
4
|
throws?: boolean;
|
|
5
5
|
}
|
|
6
|
+
export declare namespace INestiaTransformOptions {
|
|
7
|
+
type Validate = "assert" | "is" | "validate" | "assertEquals" | "equals" | "validateEquals" | "assertClone" | "validateClone" | "assertPrune" | "validatePrune";
|
|
8
|
+
type Stringify = "stringify" | "assert" | "is" | "validate" | "validate.log";
|
|
9
|
+
}
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.TypedParamProgrammer = void 0;
|
|
7
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
4
8
|
const HttpParameterProgrammer_1 = require("typia/lib/programmers/http/HttpParameterProgrammer");
|
|
5
9
|
var TypedParamProgrammer;
|
|
6
10
|
(function (TypedParamProgrammer) {
|
|
7
11
|
TypedParamProgrammer.generate = (props) => {
|
|
12
|
+
var _a, _b;
|
|
8
13
|
// ALREADY BEING TRANSFORMED
|
|
9
14
|
if (props.arguments.length !== 1)
|
|
10
15
|
return props.arguments;
|
|
@@ -18,6 +23,9 @@ var TypedParamProgrammer;
|
|
|
18
23
|
type: props.type,
|
|
19
24
|
name: undefined,
|
|
20
25
|
}),
|
|
26
|
+
...(((_b = (_a = props.context.options) === null || _a === void 0 ? void 0 : _a.validate) === null || _b === void 0 ? void 0 : _b.startsWith("validate"))
|
|
27
|
+
? [typescript_1.default.factory.createTrue()]
|
|
28
|
+
: []),
|
|
21
29
|
];
|
|
22
30
|
};
|
|
23
31
|
})(TypedParamProgrammer || (exports.TypedParamProgrammer = TypedParamProgrammer = {}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypedParamProgrammer.js","sourceRoot":"","sources":["../../src/programmers/TypedParamProgrammer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"TypedParamProgrammer.js","sourceRoot":"","sources":["../../src/programmers/TypedParamProgrammer.ts"],"names":[],"mappings":";;;;;;AAAA,4DAA4B;AAC5B,gGAA6F;AAI7F,IAAiB,oBAAoB,CA2BpC;AA3BD,WAAiB,oBAAoB;IACtB,6BAAQ,GAAG,CAAC,KAKxB,EAA4B,EAAE;;QAC7B,4BAA4B;QAC5B,IAAI,KAAK,CAAC,SAAS,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,KAAK,CAAC,SAAS,CAAC;QACzD,OAAO;YACL,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC;YAClB,iDAAuB,CAAC,KAAK,CAAC;gBAC5B,OAAO,kCACF,KAAK,CAAC,OAAO,KAChB,OAAO,EAAE;wBACP,OAAO,EAAE,IAAI;qBACd,GACF;gBACD,MAAM,EAAE,KAAK,CAAC,MAAM;gBACpB,IAAI,EAAE,KAAK,CAAC,IAAI;gBAChB,IAAI,EAAE,SAAS;aAChB,CAAC;YACF,GAAG,CAAC,CAAA,MAAA,MAAA,KAAK,CAAC,OAAO,CAAC,OAAO,0CAAE,QAAQ,0CAAE,UAAU,CAAC,UAAU,CAAC;gBACzD,CAAC,CAAC,CAAC,oBAAE,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC;gBAC3B,CAAC,CAAC,EAAE,CAAC;SACR,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC,EA3BgB,oBAAoB,oCAApB,oBAAoB,QA2BpC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nestia/core",
|
|
3
|
-
"version": "4.4.0-dev.20241216",
|
|
3
|
+
"version": "4.4.0-dev.20241216-2",
|
|
4
4
|
"description": "Super-fast validation decorators of NestJS",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
@@ -36,10 +36,10 @@
|
|
|
36
36
|
},
|
|
37
37
|
"homepage": "https://nestia.io",
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@nestia/fetcher": "^4.4.0-dev.20241216",
|
|
39
|
+
"@nestia/fetcher": "^4.4.0-dev.20241216-2",
|
|
40
40
|
"@nestjs/common": ">=7.0.1",
|
|
41
41
|
"@nestjs/core": ">=7.0.1",
|
|
42
|
-
"@samchon/openapi": "^2.
|
|
42
|
+
"@samchon/openapi": "^2.2.0",
|
|
43
43
|
"detect-ts-node": "^1.0.5",
|
|
44
44
|
"get-function-location": "^2.0.0",
|
|
45
45
|
"glob": "^7.2.0",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"ws": "^7.5.3"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
|
-
"@nestia/fetcher": ">=4.4.0-dev.20241216",
|
|
55
|
+
"@nestia/fetcher": ">=4.4.0-dev.20241216-2",
|
|
56
56
|
"@nestjs/common": ">=7.0.1",
|
|
57
57
|
"@nestjs/core": ">=7.0.1",
|
|
58
58
|
"reflect-metadata": ">=0.1.12",
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
} from "@nestjs/common";
|
|
6
6
|
import type express from "express";
|
|
7
7
|
import type { FastifyRequest } from "fastify";
|
|
8
|
-
import typia, { TypeGuardError } from "typia";
|
|
8
|
+
import typia, { IValidation, TypeGuardError } from "typia";
|
|
9
9
|
|
|
10
10
|
import { NoTransformConfigurationError } from "./NoTransformConfigurationError";
|
|
11
11
|
|
|
@@ -35,6 +35,7 @@ import { NoTransformConfigurationError } from "./NoTransformConfigurationError";
|
|
|
35
35
|
export function TypedParam<T extends boolean | bigint | number | string | null>(
|
|
36
36
|
name: string,
|
|
37
37
|
assert?: (value: string) => T,
|
|
38
|
+
validate?: boolean,
|
|
38
39
|
): ParameterDecorator {
|
|
39
40
|
if (assert === undefined) {
|
|
40
41
|
NoTransformConfigurationError("TypedParam");
|
|
@@ -52,14 +53,24 @@ export function TypedParam<T extends boolean | bigint | number | string | null>(
|
|
|
52
53
|
try {
|
|
53
54
|
return assert(str);
|
|
54
55
|
} catch (exp) {
|
|
55
|
-
if (typia.is<TypeGuardError>(exp))
|
|
56
|
-
|
|
57
|
-
path: exp.path,
|
|
58
|
-
reason: exp.message,
|
|
56
|
+
if (typia.is<TypeGuardError>(exp)) {
|
|
57
|
+
const trace: IValidation.IError = {
|
|
58
|
+
path: exp.path ?? "$input",
|
|
59
59
|
expected: exp.expected,
|
|
60
60
|
value: exp.value,
|
|
61
|
+
};
|
|
62
|
+
throw new BadRequestException({
|
|
61
63
|
message: `Invalid URL parameter value on "${name}".`,
|
|
64
|
+
...(validate === true
|
|
65
|
+
? {
|
|
66
|
+
errors: [trace],
|
|
67
|
+
}
|
|
68
|
+
: {
|
|
69
|
+
...trace,
|
|
70
|
+
reason: exp.message,
|
|
71
|
+
}),
|
|
62
72
|
});
|
|
73
|
+
}
|
|
63
74
|
throw exp;
|
|
64
75
|
}
|
|
65
76
|
})(name);
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
export interface INestiaTransformOptions {
|
|
2
|
-
validate?:
|
|
3
|
-
|
|
|
2
|
+
validate?: INestiaTransformOptions.Validate;
|
|
3
|
+
stringify?: INestiaTransformOptions.Stringify | null;
|
|
4
|
+
throws?: boolean;
|
|
5
|
+
}
|
|
6
|
+
export namespace INestiaTransformOptions {
|
|
7
|
+
export type Validate =
|
|
8
|
+
// NORMAL
|
|
9
|
+
| "assert"
|
|
4
10
|
| "is"
|
|
5
11
|
| "validate"
|
|
6
12
|
// STRICT
|
|
@@ -13,12 +19,11 @@ export interface INestiaTransformOptions {
|
|
|
13
19
|
// PRUNE
|
|
14
20
|
| "assertPrune"
|
|
15
21
|
| "validatePrune";
|
|
16
|
-
|
|
22
|
+
|
|
23
|
+
export type Stringify =
|
|
17
24
|
| "stringify"
|
|
18
25
|
| "assert"
|
|
19
26
|
| "is"
|
|
20
27
|
| "validate"
|
|
21
|
-
| "validate.log"
|
|
22
|
-
| null;
|
|
23
|
-
throws?: boolean;
|
|
28
|
+
| "validate.log";
|
|
24
29
|
}
|