@nestia/core 2.4.5 → 2.4.6
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/TypedQuery.js.map +1 -1
- package/lib/decorators/internal/load_controller.js.map +1 -1
- package/lib/transformers/NodeTransformer.js.map +1 -1
- package/package.json +4 -3
- package/src/decorators/DynamicModule.ts +39 -39
- package/src/decorators/EncryptedBody.ts +102 -102
- package/src/decorators/EncryptedController.ts +38 -38
- package/src/decorators/EncryptedModule.ts +93 -93
- package/src/decorators/EncryptedRoute.ts +182 -182
- package/src/decorators/PlainBody.ts +72 -72
- package/src/decorators/TypedBody.ts +59 -59
- package/src/decorators/TypedException.ts +89 -89
- package/src/decorators/TypedHeaders.ts +69 -69
- package/src/decorators/TypedParam.ts +65 -65
- package/src/decorators/TypedQuery.ts +2 -2
- package/src/decorators/TypedRoute.ts +1 -1
- package/src/decorators/internal/EncryptedConstant.ts +4 -4
- package/src/decorators/internal/NoTransformConfigureError.ts +8 -8
- package/src/decorators/internal/get_path_and_querify.ts +103 -103
- package/src/decorators/internal/get_path_and_stringify.ts +91 -91
- package/src/decorators/internal/get_text_body.ts +20 -20
- package/src/decorators/internal/headers_to_object.ts +13 -13
- package/src/decorators/internal/load_controller.ts +2 -2
- package/src/decorators/internal/route_error.ts +45 -45
- package/src/decorators/internal/validate_request_body.ts +57 -57
- package/src/decorators/internal/validate_request_headers.ts +68 -68
- package/src/decorators/internal/validate_request_query.ts +56 -56
- package/src/index.ts +5 -5
- package/src/module.ts +14 -14
- package/src/options/INestiaTransformOptions.ts +17 -17
- package/src/options/INestiaTransformProject.ts +7 -7
- package/src/options/IRequestBodyValidator.ts +20 -20
- package/src/options/IRequestHeadersValidator.ts +22 -22
- package/src/options/IRequestQueryValidator.ts +20 -20
- package/src/options/IResponseBodyQuerifier.ts +25 -25
- package/src/options/IResponseBodyStringifier.ts +25 -25
- package/src/programmers/PlainBodyProgrammer.ts +52 -52
- package/src/programmers/TypedBodyProgrammer.ts +108 -108
- package/src/programmers/TypedExceptionProgrammer.ts +72 -72
- package/src/programmers/TypedHeadersProgrammer.ts +56 -56
- package/src/programmers/TypedParamProgrammer.ts +24 -24
- package/src/programmers/TypedQueryBodyProgrammer.ts +56 -56
- package/src/programmers/TypedQueryProgrammer.ts +56 -56
- package/src/programmers/TypedQueryRouteProgrammer.ts +51 -51
- package/src/programmers/TypedRouteProgrammer.ts +51 -51
- package/src/programmers/http/HttpAssertQuerifyProgrammer.ts +58 -58
- package/src/programmers/http/HttpIsQuerifyProgrammer.ts +62 -62
- package/src/programmers/http/HttpQuerifyProgrammer.ts +96 -96
- package/src/programmers/http/HttpValidateQuerifyProgrammer.ts +63 -63
- package/src/programmers/internal/CoreMetadataUtil.ts +21 -21
- package/src/transform.ts +35 -35
- package/src/transformers/FileTransformer.ts +66 -66
- package/src/transformers/MethodTransformer.ts +94 -94
- package/src/transformers/NodeTransformer.ts +2 -2
- package/src/transformers/ParameterDecoratorTransformer.ts +121 -121
- package/src/transformers/ParameterTransformer.ts +48 -48
- package/src/transformers/TypedExceptionTransformer.ts +49 -49
- package/src/transformers/TypedRouteTransformer.ts +95 -95
- package/src/typings/Creator.ts +3 -3
- package/src/utils/ExceptionManager.ts +112 -112
- package/src/utils/Singleton.ts +20 -20
- package/src/utils/SourceFinder.ts +57 -57
|
@@ -1,103 +1,103 @@
|
|
|
1
|
-
import { InternalServerErrorException } from "@nestjs/common";
|
|
2
|
-
import typia, { IValidation, TypeGuardError } from "typia";
|
|
3
|
-
|
|
4
|
-
import { IResponseBodyQuerifier } from "../../options/IResponseBodyQuerifier";
|
|
5
|
-
import { NoTransformConfigureError } from "./NoTransformConfigureError";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* @internal
|
|
9
|
-
*/
|
|
10
|
-
export const get_path_and_querify =
|
|
11
|
-
(method: string) =>
|
|
12
|
-
(
|
|
13
|
-
...args: any[]
|
|
14
|
-
): [string | string[] | undefined, (input: any) => URLSearchParams] => {
|
|
15
|
-
const path: string | string[] | null | undefined =
|
|
16
|
-
args[0] === undefined ||
|
|
17
|
-
typeof args[0] === "string" ||
|
|
18
|
-
Array.isArray(args[0])
|
|
19
|
-
? args[0]
|
|
20
|
-
: null;
|
|
21
|
-
const functor: IResponseBodyQuerifier<any> | undefined =
|
|
22
|
-
path === null ? args[0] : args[1];
|
|
23
|
-
return [path ?? undefined, take(method)(functor)];
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* @internal
|
|
28
|
-
*/
|
|
29
|
-
const take =
|
|
30
|
-
(method: string) =>
|
|
31
|
-
<T>(functor?: IResponseBodyQuerifier<T> | null) => {
|
|
32
|
-
if (functor === undefined) throw NoTransformConfigureError(method);
|
|
33
|
-
else if (functor === null) return querify;
|
|
34
|
-
else if (functor.type === "stringify") return functor.stringify;
|
|
35
|
-
else if (functor.type === "assert") return assert(functor.assert);
|
|
36
|
-
else if (functor.type === "is") return is(functor.is);
|
|
37
|
-
else if (functor.type === "validate") return validate(functor.validate);
|
|
38
|
-
throw new Error(
|
|
39
|
-
`Error on nestia.core.${method}(): invalid typed stringify function.`,
|
|
40
|
-
);
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
const querify = (input: Record<string, any>): URLSearchParams => {
|
|
44
|
-
const output: URLSearchParams = new URLSearchParams();
|
|
45
|
-
for (const [key, value] of Object.entries(input))
|
|
46
|
-
if (key === undefined) continue;
|
|
47
|
-
else if (Array.isArray(value))
|
|
48
|
-
for (const elem of value) output.append(key, String(elem));
|
|
49
|
-
else output.append(key, String(value));
|
|
50
|
-
return output;
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* @internal
|
|
55
|
-
*/
|
|
56
|
-
const assert =
|
|
57
|
-
<T>(closure: (data: T) => URLSearchParams) =>
|
|
58
|
-
(data: T) => {
|
|
59
|
-
try {
|
|
60
|
-
return closure(data);
|
|
61
|
-
} catch (exp) {
|
|
62
|
-
if (typia.is<TypeGuardError>(exp))
|
|
63
|
-
throw new InternalServerErrorException({
|
|
64
|
-
path: exp.path,
|
|
65
|
-
reason: exp.message,
|
|
66
|
-
expected: exp.expected,
|
|
67
|
-
value: exp.value,
|
|
68
|
-
message: MESSAGE,
|
|
69
|
-
});
|
|
70
|
-
throw exp;
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* @internal
|
|
76
|
-
*/
|
|
77
|
-
const is =
|
|
78
|
-
<T>(closure: (data: T) => URLSearchParams | null) =>
|
|
79
|
-
(data: T) => {
|
|
80
|
-
const result: URLSearchParams | null = closure(data);
|
|
81
|
-
if (result === null) throw new InternalServerErrorException(MESSAGE);
|
|
82
|
-
return result;
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* @internal
|
|
87
|
-
*/
|
|
88
|
-
const validate =
|
|
89
|
-
<T>(closure: (data: T) => IValidation<URLSearchParams>) =>
|
|
90
|
-
(data: T) => {
|
|
91
|
-
const result: IValidation<URLSearchParams> = closure(data);
|
|
92
|
-
if (result.success === false)
|
|
93
|
-
throw new InternalServerErrorException({
|
|
94
|
-
errors: result.errors,
|
|
95
|
-
message: MESSAGE,
|
|
96
|
-
});
|
|
97
|
-
return result.data;
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* @internal
|
|
102
|
-
*/
|
|
103
|
-
const MESSAGE = "Response body data is not following the promised type.";
|
|
1
|
+
import { InternalServerErrorException } from "@nestjs/common";
|
|
2
|
+
import typia, { IValidation, TypeGuardError } from "typia";
|
|
3
|
+
|
|
4
|
+
import { IResponseBodyQuerifier } from "../../options/IResponseBodyQuerifier";
|
|
5
|
+
import { NoTransformConfigureError } from "./NoTransformConfigureError";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export const get_path_and_querify =
|
|
11
|
+
(method: string) =>
|
|
12
|
+
(
|
|
13
|
+
...args: any[]
|
|
14
|
+
): [string | string[] | undefined, (input: any) => URLSearchParams] => {
|
|
15
|
+
const path: string | string[] | null | undefined =
|
|
16
|
+
args[0] === undefined ||
|
|
17
|
+
typeof args[0] === "string" ||
|
|
18
|
+
Array.isArray(args[0])
|
|
19
|
+
? args[0]
|
|
20
|
+
: null;
|
|
21
|
+
const functor: IResponseBodyQuerifier<any> | undefined =
|
|
22
|
+
path === null ? args[0] : args[1];
|
|
23
|
+
return [path ?? undefined, take(method)(functor)];
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @internal
|
|
28
|
+
*/
|
|
29
|
+
const take =
|
|
30
|
+
(method: string) =>
|
|
31
|
+
<T>(functor?: IResponseBodyQuerifier<T> | null) => {
|
|
32
|
+
if (functor === undefined) throw NoTransformConfigureError(method);
|
|
33
|
+
else if (functor === null) return querify;
|
|
34
|
+
else if (functor.type === "stringify") return functor.stringify;
|
|
35
|
+
else if (functor.type === "assert") return assert(functor.assert);
|
|
36
|
+
else if (functor.type === "is") return is(functor.is);
|
|
37
|
+
else if (functor.type === "validate") return validate(functor.validate);
|
|
38
|
+
throw new Error(
|
|
39
|
+
`Error on nestia.core.${method}(): invalid typed stringify function.`,
|
|
40
|
+
);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const querify = (input: Record<string, any>): URLSearchParams => {
|
|
44
|
+
const output: URLSearchParams = new URLSearchParams();
|
|
45
|
+
for (const [key, value] of Object.entries(input))
|
|
46
|
+
if (key === undefined) continue;
|
|
47
|
+
else if (Array.isArray(value))
|
|
48
|
+
for (const elem of value) output.append(key, String(elem));
|
|
49
|
+
else output.append(key, String(value));
|
|
50
|
+
return output;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* @internal
|
|
55
|
+
*/
|
|
56
|
+
const assert =
|
|
57
|
+
<T>(closure: (data: T) => URLSearchParams) =>
|
|
58
|
+
(data: T) => {
|
|
59
|
+
try {
|
|
60
|
+
return closure(data);
|
|
61
|
+
} catch (exp) {
|
|
62
|
+
if (typia.is<TypeGuardError>(exp))
|
|
63
|
+
throw new InternalServerErrorException({
|
|
64
|
+
path: exp.path,
|
|
65
|
+
reason: exp.message,
|
|
66
|
+
expected: exp.expected,
|
|
67
|
+
value: exp.value,
|
|
68
|
+
message: MESSAGE,
|
|
69
|
+
});
|
|
70
|
+
throw exp;
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* @internal
|
|
76
|
+
*/
|
|
77
|
+
const is =
|
|
78
|
+
<T>(closure: (data: T) => URLSearchParams | null) =>
|
|
79
|
+
(data: T) => {
|
|
80
|
+
const result: URLSearchParams | null = closure(data);
|
|
81
|
+
if (result === null) throw new InternalServerErrorException(MESSAGE);
|
|
82
|
+
return result;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* @internal
|
|
87
|
+
*/
|
|
88
|
+
const validate =
|
|
89
|
+
<T>(closure: (data: T) => IValidation<URLSearchParams>) =>
|
|
90
|
+
(data: T) => {
|
|
91
|
+
const result: IValidation<URLSearchParams> = closure(data);
|
|
92
|
+
if (result.success === false)
|
|
93
|
+
throw new InternalServerErrorException({
|
|
94
|
+
errors: result.errors,
|
|
95
|
+
message: MESSAGE,
|
|
96
|
+
});
|
|
97
|
+
return result.data;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* @internal
|
|
102
|
+
*/
|
|
103
|
+
const MESSAGE = "Response body data is not following the promised type.";
|
|
@@ -1,91 +1,91 @@
|
|
|
1
|
-
import { InternalServerErrorException } from "@nestjs/common";
|
|
2
|
-
import typia, { IValidation, TypeGuardError } from "typia";
|
|
3
|
-
|
|
4
|
-
import { IResponseBodyStringifier } from "../../options/IResponseBodyStringifier";
|
|
5
|
-
import { NoTransformConfigureError } from "./NoTransformConfigureError";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* @internal
|
|
9
|
-
*/
|
|
10
|
-
export const get_path_and_stringify =
|
|
11
|
-
(method: string) =>
|
|
12
|
-
(...args: any[]): [string | string[] | undefined, (input: any) => string] => {
|
|
13
|
-
const path: string | string[] | null | undefined =
|
|
14
|
-
args[0] === undefined ||
|
|
15
|
-
typeof args[0] === "string" ||
|
|
16
|
-
Array.isArray(args[0])
|
|
17
|
-
? args[0]
|
|
18
|
-
: null;
|
|
19
|
-
const functor: IResponseBodyStringifier<any> | undefined =
|
|
20
|
-
path === null ? args[0] : args[1];
|
|
21
|
-
return [path ?? undefined, take(method)(functor)];
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* @internal
|
|
26
|
-
*/
|
|
27
|
-
const take =
|
|
28
|
-
(method: string) =>
|
|
29
|
-
<T>(functor?: IResponseBodyStringifier<T> | null) => {
|
|
30
|
-
if (functor === undefined) throw NoTransformConfigureError(method);
|
|
31
|
-
else if (functor === null) return JSON.stringify;
|
|
32
|
-
else if (functor.type === "stringify") return functor.stringify;
|
|
33
|
-
else if (functor.type === "assert") return assert(functor.assert);
|
|
34
|
-
else if (functor.type === "is") return is(functor.is);
|
|
35
|
-
else if (functor.type === "validate") return validate(functor.validate);
|
|
36
|
-
throw new Error(
|
|
37
|
-
`Error on nestia.core.${method}(): invalid typed stringify function.`,
|
|
38
|
-
);
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* @internal
|
|
43
|
-
*/
|
|
44
|
-
const assert =
|
|
45
|
-
<T>(closure: (data: T) => string) =>
|
|
46
|
-
(data: T) => {
|
|
47
|
-
try {
|
|
48
|
-
return closure(data);
|
|
49
|
-
} catch (exp) {
|
|
50
|
-
if (typia.is<TypeGuardError>(exp))
|
|
51
|
-
throw new InternalServerErrorException({
|
|
52
|
-
path: exp.path,
|
|
53
|
-
reason: exp.message,
|
|
54
|
-
expected: exp.expected,
|
|
55
|
-
value: exp.value,
|
|
56
|
-
message: MESSAGE,
|
|
57
|
-
});
|
|
58
|
-
throw exp;
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* @internal
|
|
64
|
-
*/
|
|
65
|
-
const is =
|
|
66
|
-
<T>(closure: (data: T) => string | null) =>
|
|
67
|
-
(data: T) => {
|
|
68
|
-
const result: string | null = closure(data);
|
|
69
|
-
if (result === null) throw new InternalServerErrorException(MESSAGE);
|
|
70
|
-
return result;
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* @internal
|
|
75
|
-
*/
|
|
76
|
-
const validate =
|
|
77
|
-
<T>(closure: (data: T) => IValidation<string>) =>
|
|
78
|
-
(data: T) => {
|
|
79
|
-
const result: IValidation<string> = closure(data);
|
|
80
|
-
if (result.success === false)
|
|
81
|
-
throw new InternalServerErrorException({
|
|
82
|
-
errors: result.errors,
|
|
83
|
-
message: MESSAGE,
|
|
84
|
-
});
|
|
85
|
-
return result.data;
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* @internal
|
|
90
|
-
*/
|
|
91
|
-
const MESSAGE = "Response body data is not following the promised type.";
|
|
1
|
+
import { InternalServerErrorException } from "@nestjs/common";
|
|
2
|
+
import typia, { IValidation, TypeGuardError } from "typia";
|
|
3
|
+
|
|
4
|
+
import { IResponseBodyStringifier } from "../../options/IResponseBodyStringifier";
|
|
5
|
+
import { NoTransformConfigureError } from "./NoTransformConfigureError";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export const get_path_and_stringify =
|
|
11
|
+
(method: string) =>
|
|
12
|
+
(...args: any[]): [string | string[] | undefined, (input: any) => string] => {
|
|
13
|
+
const path: string | string[] | null | undefined =
|
|
14
|
+
args[0] === undefined ||
|
|
15
|
+
typeof args[0] === "string" ||
|
|
16
|
+
Array.isArray(args[0])
|
|
17
|
+
? args[0]
|
|
18
|
+
: null;
|
|
19
|
+
const functor: IResponseBodyStringifier<any> | undefined =
|
|
20
|
+
path === null ? args[0] : args[1];
|
|
21
|
+
return [path ?? undefined, take(method)(functor)];
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
27
|
+
const take =
|
|
28
|
+
(method: string) =>
|
|
29
|
+
<T>(functor?: IResponseBodyStringifier<T> | null) => {
|
|
30
|
+
if (functor === undefined) throw NoTransformConfigureError(method);
|
|
31
|
+
else if (functor === null) return JSON.stringify;
|
|
32
|
+
else if (functor.type === "stringify") return functor.stringify;
|
|
33
|
+
else if (functor.type === "assert") return assert(functor.assert);
|
|
34
|
+
else if (functor.type === "is") return is(functor.is);
|
|
35
|
+
else if (functor.type === "validate") return validate(functor.validate);
|
|
36
|
+
throw new Error(
|
|
37
|
+
`Error on nestia.core.${method}(): invalid typed stringify function.`,
|
|
38
|
+
);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @internal
|
|
43
|
+
*/
|
|
44
|
+
const assert =
|
|
45
|
+
<T>(closure: (data: T) => string) =>
|
|
46
|
+
(data: T) => {
|
|
47
|
+
try {
|
|
48
|
+
return closure(data);
|
|
49
|
+
} catch (exp) {
|
|
50
|
+
if (typia.is<TypeGuardError>(exp))
|
|
51
|
+
throw new InternalServerErrorException({
|
|
52
|
+
path: exp.path,
|
|
53
|
+
reason: exp.message,
|
|
54
|
+
expected: exp.expected,
|
|
55
|
+
value: exp.value,
|
|
56
|
+
message: MESSAGE,
|
|
57
|
+
});
|
|
58
|
+
throw exp;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* @internal
|
|
64
|
+
*/
|
|
65
|
+
const is =
|
|
66
|
+
<T>(closure: (data: T) => string | null) =>
|
|
67
|
+
(data: T) => {
|
|
68
|
+
const result: string | null = closure(data);
|
|
69
|
+
if (result === null) throw new InternalServerErrorException(MESSAGE);
|
|
70
|
+
return result;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* @internal
|
|
75
|
+
*/
|
|
76
|
+
const validate =
|
|
77
|
+
<T>(closure: (data: T) => IValidation<string>) =>
|
|
78
|
+
(data: T) => {
|
|
79
|
+
const result: IValidation<string> = closure(data);
|
|
80
|
+
if (result.success === false)
|
|
81
|
+
throw new InternalServerErrorException({
|
|
82
|
+
errors: result.errors,
|
|
83
|
+
message: MESSAGE,
|
|
84
|
+
});
|
|
85
|
+
return result.data;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* @internal
|
|
90
|
+
*/
|
|
91
|
+
const MESSAGE = "Response body data is not following the promised type.";
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import type express from "express";
|
|
2
|
-
import type { FastifyRequest } from "fastify";
|
|
3
|
-
import raw from "raw-body";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @internal
|
|
7
|
-
*/
|
|
8
|
-
export const get_text_body = async (
|
|
9
|
-
request: express.Request | FastifyRequest,
|
|
10
|
-
): Promise<string> =>
|
|
11
|
-
isExpressRequest(request)
|
|
12
|
-
? (await raw(request)).toString("utf8")
|
|
13
|
-
: (request.body as string);
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* @internal
|
|
17
|
-
*/
|
|
18
|
-
const isExpressRequest = (
|
|
19
|
-
request: express.Request | FastifyRequest,
|
|
20
|
-
): request is express.Request => (request as express.Request).app !== undefined;
|
|
1
|
+
import type express from "express";
|
|
2
|
+
import type { FastifyRequest } from "fastify";
|
|
3
|
+
import raw from "raw-body";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
export const get_text_body = async (
|
|
9
|
+
request: express.Request | FastifyRequest,
|
|
10
|
+
): Promise<string> =>
|
|
11
|
+
isExpressRequest(request)
|
|
12
|
+
? (await raw(request)).toString("utf8")
|
|
13
|
+
: (request.body as string);
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
const isExpressRequest = (
|
|
19
|
+
request: express.Request | FastifyRequest,
|
|
20
|
+
): request is express.Request => (request as express.Request).app !== undefined;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import http from "http";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @internal
|
|
5
|
-
*/
|
|
6
|
-
export function headers_to_object(
|
|
7
|
-
headers: http.IncomingHttpHeaders,
|
|
8
|
-
): Record<string, string> {
|
|
9
|
-
const output: Record<string, string> = {};
|
|
10
|
-
for (const [key, value] of Object.entries(headers))
|
|
11
|
-
output[key] = value instanceof Array ? value[0] : value || "";
|
|
12
|
-
return output;
|
|
13
|
-
}
|
|
1
|
+
import http from "http";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @internal
|
|
5
|
+
*/
|
|
6
|
+
export function headers_to_object(
|
|
7
|
+
headers: http.IncomingHttpHeaders,
|
|
8
|
+
): Record<string, string> {
|
|
9
|
+
const output: Record<string, string> = {};
|
|
10
|
+
for (const [key, value] of Object.entries(headers))
|
|
11
|
+
output[key] = value instanceof Array ? value[0] : value || "";
|
|
12
|
+
return output;
|
|
13
|
+
}
|
|
@@ -13,8 +13,8 @@ export const load_controllers = async (
|
|
|
13
13
|
include: Array.isArray(path)
|
|
14
14
|
? path
|
|
15
15
|
: typeof path === "object"
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
? path.include
|
|
17
|
+
: [path],
|
|
18
18
|
exclude:
|
|
19
19
|
typeof path === "object" && !Array.isArray(path)
|
|
20
20
|
? path.exclude ?? []
|
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
import { HttpException } from "@nestjs/common";
|
|
2
|
-
import express from "express";
|
|
3
|
-
import type { FastifyRequest } from "fastify";
|
|
4
|
-
import { throwError } from "rxjs";
|
|
5
|
-
|
|
6
|
-
import { ExceptionManager } from "../../utils/ExceptionManager";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @internal
|
|
10
|
-
*/
|
|
11
|
-
export function route_error(
|
|
12
|
-
request: express.Request | FastifyRequest,
|
|
13
|
-
error: any,
|
|
14
|
-
) {
|
|
15
|
-
error = (() => {
|
|
16
|
-
// HTTP-ERROR
|
|
17
|
-
if (error instanceof HttpException) return error;
|
|
18
|
-
|
|
19
|
-
// CUSTOM-REGISTERED ERROR
|
|
20
|
-
for (const [creator, closure] of ExceptionManager.tuples)
|
|
21
|
-
if (error instanceof creator) return closure(error);
|
|
22
|
-
|
|
23
|
-
// MAYBE INTERNAL ERROR
|
|
24
|
-
return error;
|
|
25
|
-
})();
|
|
26
|
-
|
|
27
|
-
try {
|
|
28
|
-
error.method = request.method;
|
|
29
|
-
error.path =
|
|
30
|
-
(request as express.Request).path ??
|
|
31
|
-
(request as FastifyRequest).routeOptions?.url ??
|
|
32
|
-
(request as FastifyRequest).routerPath;
|
|
33
|
-
} catch {}
|
|
34
|
-
|
|
35
|
-
setTimeout(() => {
|
|
36
|
-
for (const listener of ExceptionManager.listeners) {
|
|
37
|
-
try {
|
|
38
|
-
const res: any | Promise<any> = listener(error);
|
|
39
|
-
if (typeof res === "object" && typeof res.catch === "function")
|
|
40
|
-
res.catch(() => {});
|
|
41
|
-
} catch {}
|
|
42
|
-
}
|
|
43
|
-
}, 0);
|
|
44
|
-
return throwError(() => error);
|
|
45
|
-
}
|
|
1
|
+
import { HttpException } from "@nestjs/common";
|
|
2
|
+
import express from "express";
|
|
3
|
+
import type { FastifyRequest } from "fastify";
|
|
4
|
+
import { throwError } from "rxjs";
|
|
5
|
+
|
|
6
|
+
import { ExceptionManager } from "../../utils/ExceptionManager";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
export function route_error(
|
|
12
|
+
request: express.Request | FastifyRequest,
|
|
13
|
+
error: any,
|
|
14
|
+
) {
|
|
15
|
+
error = (() => {
|
|
16
|
+
// HTTP-ERROR
|
|
17
|
+
if (error instanceof HttpException) return error;
|
|
18
|
+
|
|
19
|
+
// CUSTOM-REGISTERED ERROR
|
|
20
|
+
for (const [creator, closure] of ExceptionManager.tuples)
|
|
21
|
+
if (error instanceof creator) return closure(error);
|
|
22
|
+
|
|
23
|
+
// MAYBE INTERNAL ERROR
|
|
24
|
+
return error;
|
|
25
|
+
})();
|
|
26
|
+
|
|
27
|
+
try {
|
|
28
|
+
error.method = request.method;
|
|
29
|
+
error.path =
|
|
30
|
+
(request as express.Request).path ??
|
|
31
|
+
(request as FastifyRequest).routeOptions?.url ??
|
|
32
|
+
(request as FastifyRequest).routerPath;
|
|
33
|
+
} catch {}
|
|
34
|
+
|
|
35
|
+
setTimeout(() => {
|
|
36
|
+
for (const listener of ExceptionManager.listeners) {
|
|
37
|
+
try {
|
|
38
|
+
const res: any | Promise<any> = listener(error);
|
|
39
|
+
if (typeof res === "object" && typeof res.catch === "function")
|
|
40
|
+
res.catch(() => {});
|
|
41
|
+
} catch {}
|
|
42
|
+
}
|
|
43
|
+
}, 0);
|
|
44
|
+
return throwError(() => error);
|
|
45
|
+
}
|
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
import { BadRequestException } from "@nestjs/common";
|
|
2
|
-
import typia, { IValidation, TypeGuardError } from "typia";
|
|
3
|
-
|
|
4
|
-
import { IRequestBodyValidator } from "../../options/IRequestBodyValidator";
|
|
5
|
-
import { NoTransformConfigureError } from "./NoTransformConfigureError";
|
|
6
|
-
|
|
7
|
-
export const validate_request_body =
|
|
8
|
-
(method: string) =>
|
|
9
|
-
<T>(validator?: IRequestBodyValidator<T>) => {
|
|
10
|
-
if (!validator) return () => NoTransformConfigureError(method);
|
|
11
|
-
else if (validator.type === "assert") return assert(validator.assert);
|
|
12
|
-
else if (validator.type === "is") return is(validator.is);
|
|
13
|
-
else if (validator.type === "validate") return validate(validator.validate);
|
|
14
|
-
return () =>
|
|
15
|
-
new Error(`Error on nestia.core.${method}(): invalid typed validator.`);
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
const assert =
|
|
19
|
-
<T>(closure: (data: T) => T) =>
|
|
20
|
-
(input: T) => {
|
|
21
|
-
try {
|
|
22
|
-
closure(input);
|
|
23
|
-
return null;
|
|
24
|
-
} catch (exp) {
|
|
25
|
-
if (typia.is<TypeGuardError>(exp)) {
|
|
26
|
-
return new BadRequestException({
|
|
27
|
-
path: exp.path,
|
|
28
|
-
reason: exp.message,
|
|
29
|
-
expected: exp.expected,
|
|
30
|
-
value: exp.value,
|
|
31
|
-
message: MESSAGE,
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
throw exp;
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
const is =
|
|
39
|
-
<T>(closure: (data: T) => boolean) =>
|
|
40
|
-
(input: T) => {
|
|
41
|
-
const success: boolean = closure(input);
|
|
42
|
-
return success ? null : new BadRequestException(MESSAGE);
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
const validate =
|
|
46
|
-
<T>(closure: (data: T) => IValidation<T>) =>
|
|
47
|
-
(input: T) => {
|
|
48
|
-
const result: IValidation<T> = closure(input);
|
|
49
|
-
return result.success
|
|
50
|
-
? null
|
|
51
|
-
: new BadRequestException({
|
|
52
|
-
errors: result.errors,
|
|
53
|
-
message: MESSAGE,
|
|
54
|
-
});
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
const MESSAGE = "Request body data is not following the promised type.";
|
|
1
|
+
import { BadRequestException } from "@nestjs/common";
|
|
2
|
+
import typia, { IValidation, TypeGuardError } from "typia";
|
|
3
|
+
|
|
4
|
+
import { IRequestBodyValidator } from "../../options/IRequestBodyValidator";
|
|
5
|
+
import { NoTransformConfigureError } from "./NoTransformConfigureError";
|
|
6
|
+
|
|
7
|
+
export const validate_request_body =
|
|
8
|
+
(method: string) =>
|
|
9
|
+
<T>(validator?: IRequestBodyValidator<T>) => {
|
|
10
|
+
if (!validator) return () => NoTransformConfigureError(method);
|
|
11
|
+
else if (validator.type === "assert") return assert(validator.assert);
|
|
12
|
+
else if (validator.type === "is") return is(validator.is);
|
|
13
|
+
else if (validator.type === "validate") return validate(validator.validate);
|
|
14
|
+
return () =>
|
|
15
|
+
new Error(`Error on nestia.core.${method}(): invalid typed validator.`);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const assert =
|
|
19
|
+
<T>(closure: (data: T) => T) =>
|
|
20
|
+
(input: T) => {
|
|
21
|
+
try {
|
|
22
|
+
closure(input);
|
|
23
|
+
return null;
|
|
24
|
+
} catch (exp) {
|
|
25
|
+
if (typia.is<TypeGuardError>(exp)) {
|
|
26
|
+
return new BadRequestException({
|
|
27
|
+
path: exp.path,
|
|
28
|
+
reason: exp.message,
|
|
29
|
+
expected: exp.expected,
|
|
30
|
+
value: exp.value,
|
|
31
|
+
message: MESSAGE,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
throw exp;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const is =
|
|
39
|
+
<T>(closure: (data: T) => boolean) =>
|
|
40
|
+
(input: T) => {
|
|
41
|
+
const success: boolean = closure(input);
|
|
42
|
+
return success ? null : new BadRequestException(MESSAGE);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const validate =
|
|
46
|
+
<T>(closure: (data: T) => IValidation<T>) =>
|
|
47
|
+
(input: T) => {
|
|
48
|
+
const result: IValidation<T> = closure(input);
|
|
49
|
+
return result.success
|
|
50
|
+
? null
|
|
51
|
+
: new BadRequestException({
|
|
52
|
+
errors: result.errors,
|
|
53
|
+
message: MESSAGE,
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const MESSAGE = "Request body data is not following the promised type.";
|