@nestia/core 12.0.0-dev.20260521.6 → 12.0.0-dev.20260612.1

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 (116) hide show
  1. package/LICENSE +21 -21
  2. package/MIGRATION.md +169 -169
  3. package/README.md +93 -93
  4. package/lib/adaptors/McpAdaptor.d.ts +75 -0
  5. package/lib/adaptors/McpAdaptor.js +257 -0
  6. package/lib/adaptors/McpAdaptor.js.map +1 -0
  7. package/lib/adaptors/WebSocketAdaptor.js +4 -4
  8. package/lib/adaptors/WebSocketAdaptor.js.map +1 -1
  9. package/lib/decorators/McpRoute.d.ts +69 -0
  10. package/lib/decorators/McpRoute.js +58 -0
  11. package/lib/decorators/McpRoute.js.map +1 -0
  12. package/lib/decorators/TypedParam.js +4 -4
  13. package/lib/decorators/TypedParam.js.map +1 -1
  14. package/lib/decorators/TypedRoute.js +1 -1
  15. package/lib/decorators/TypedRoute.js.map +1 -1
  16. package/lib/decorators/internal/IMcpRouteReflect.d.ts +2 -0
  17. package/lib/decorators/internal/IMcpRouteReflect.js +3 -0
  18. package/lib/decorators/internal/IMcpRouteReflect.js.map +1 -0
  19. package/lib/decorators/internal/get_path_and_querify.js +4 -4
  20. package/lib/decorators/internal/get_path_and_querify.js.map +1 -1
  21. package/lib/decorators/internal/get_path_and_stringify.js +4 -4
  22. package/lib/decorators/internal/get_path_and_stringify.js.map +1 -1
  23. package/lib/decorators/internal/load_controller.js +34 -65
  24. package/lib/decorators/internal/load_controller.js.map +1 -1
  25. package/lib/decorators/internal/validate_request_body.js +4 -4
  26. package/lib/decorators/internal/validate_request_body.js.map +1 -1
  27. package/lib/decorators/internal/validate_request_form_data.js +4 -4
  28. package/lib/decorators/internal/validate_request_form_data.js.map +1 -1
  29. package/lib/decorators/internal/validate_request_headers.js +4 -4
  30. package/lib/decorators/internal/validate_request_headers.js.map +1 -1
  31. package/lib/decorators/internal/validate_request_query.js +4 -4
  32. package/lib/decorators/internal/validate_request_query.js.map +1 -1
  33. package/lib/module.d.ts +2 -0
  34. package/lib/module.js +2 -0
  35. package/lib/module.js.map +1 -1
  36. package/native/cmd/ttsc-nestia/main.go +11 -11
  37. package/native/go.mod +32 -32
  38. package/native/go.sum +54 -54
  39. package/native/plugin/plan.go +102 -102
  40. package/native/transform/ast.go +32 -32
  41. package/native/transform/build.go +380 -437
  42. package/native/transform/cleanup.go +408 -408
  43. package/native/transform/contributor.go +97 -68
  44. package/native/transform/core_querify.go +231 -227
  45. package/native/transform/core_transform.go +1996 -1713
  46. package/native/transform/core_websocket.go +115 -115
  47. package/native/transform/exports.go +13 -13
  48. package/native/transform/mcp_transform.go +414 -0
  49. package/native/transform/node_transform.go +357 -0
  50. package/native/transform/path_rewrite.go +285 -285
  51. package/native/transform/printer.go +244 -244
  52. package/native/transform/rewrite.go +668 -662
  53. package/native/transform/run.go +73 -73
  54. package/native/transform/transform.go +336 -387
  55. package/native/transform/typia_fast.go +352 -326
  56. package/native/transform/typia_replacement.go +24 -24
  57. package/native/transform.cjs +43 -43
  58. package/package.json +15 -8
  59. package/src/adaptors/McpAdaptor.ts +276 -0
  60. package/src/adaptors/WebSocketAdaptor.ts +429 -429
  61. package/src/decorators/DynamicModule.ts +44 -44
  62. package/src/decorators/EncryptedBody.ts +97 -97
  63. package/src/decorators/EncryptedController.ts +40 -40
  64. package/src/decorators/EncryptedModule.ts +98 -98
  65. package/src/decorators/EncryptedRoute.ts +213 -213
  66. package/src/decorators/HumanRoute.ts +21 -21
  67. package/src/decorators/McpRoute.ts +154 -0
  68. package/src/decorators/NoTransformConfigurationError.ts +40 -40
  69. package/src/decorators/PlainBody.ts +76 -76
  70. package/src/decorators/SwaggerCustomizer.ts +97 -97
  71. package/src/decorators/SwaggerExample.ts +180 -180
  72. package/src/decorators/TypedBody.ts +57 -57
  73. package/src/decorators/TypedException.ts +147 -147
  74. package/src/decorators/TypedFormData.ts +187 -187
  75. package/src/decorators/TypedHeaders.ts +66 -66
  76. package/src/decorators/TypedParam.ts +77 -77
  77. package/src/decorators/TypedQuery.ts +234 -234
  78. package/src/decorators/TypedRoute.ts +198 -196
  79. package/src/decorators/WebSocketRoute.ts +242 -242
  80. package/src/decorators/doNotThrowTransformError.ts +5 -5
  81. package/src/decorators/internal/EncryptedConstant.ts +2 -2
  82. package/src/decorators/internal/IMcpRouteReflect.ts +40 -0
  83. package/src/decorators/internal/IWebSocketRouteReflect.ts +23 -23
  84. package/src/decorators/internal/get_path_and_querify.ts +94 -94
  85. package/src/decorators/internal/get_path_and_stringify.ts +110 -110
  86. package/src/decorators/internal/get_text_body.ts +16 -16
  87. package/src/decorators/internal/headers_to_object.ts +11 -11
  88. package/src/decorators/internal/is_request_body_undefined.ts +12 -12
  89. package/src/decorators/internal/load_controller.ts +91 -76
  90. package/src/decorators/internal/route_error.ts +43 -43
  91. package/src/decorators/internal/validate_request_body.ts +64 -64
  92. package/src/decorators/internal/validate_request_form_data.ts +67 -67
  93. package/src/decorators/internal/validate_request_headers.ts +76 -76
  94. package/src/decorators/internal/validate_request_query.ts +83 -83
  95. package/src/index.ts +5 -5
  96. package/src/module.ts +25 -23
  97. package/src/options/IRequestBodyValidator.ts +20 -20
  98. package/src/options/IRequestFormDataProps.ts +27 -27
  99. package/src/options/IRequestHeadersValidator.ts +22 -22
  100. package/src/options/IRequestQueryValidator.ts +20 -20
  101. package/src/options/IResponseBodyQuerifier.ts +25 -25
  102. package/src/options/IResponseBodyStringifier.ts +30 -30
  103. package/src/transform.ts +101 -101
  104. package/src/typings/Creator.ts +3 -3
  105. package/src/typings/get-function-location.d.ts +7 -7
  106. package/src/utils/ArrayUtil.ts +7 -7
  107. package/src/utils/ExceptionManager.ts +115 -115
  108. package/src/utils/Singleton.ts +16 -16
  109. package/src/utils/SourceFinder.ts +54 -54
  110. package/src/utils/VersioningStrategy.ts +27 -27
  111. package/native/transform/cleanup_test.go +0 -76
  112. package/native/transform/commonjs_import_alias_test.go +0 -49
  113. package/native/transform/core_dispatch_test.go +0 -127
  114. package/native/transform/path_rewrite_test.go +0 -243
  115. package/native/transform/rewrite_test.go +0 -118
  116. package/native/transform/rewrite_unique_base_test.go +0 -48
@@ -1,43 +1,43 @@
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
- /** @internal */
9
- export function route_error(
10
- request: express.Request | FastifyRequest,
11
- error: any,
12
- ) {
13
- error = (() => {
14
- // HTTP-ERROR
15
- if (error instanceof HttpException) return error;
16
-
17
- // CUSTOM-REGISTERED ERROR
18
- for (const [creator, closure] of ExceptionManager.tuples)
19
- if (error instanceof creator) return closure(error);
20
-
21
- // MAYBE INTERNAL ERROR
22
- return error;
23
- })();
24
-
25
- try {
26
- error.method = request.method;
27
- error.path =
28
- (request as express.Request).path ??
29
- (request as FastifyRequest).routeOptions?.url ??
30
- (request as any).routerPath;
31
- } catch {}
32
-
33
- setTimeout(() => {
34
- for (const listener of ExceptionManager.listeners) {
35
- try {
36
- const res: any | Promise<any> = listener(error);
37
- if (typeof res === "object" && typeof res.catch === "function")
38
- res.catch(() => {});
39
- } catch {}
40
- }
41
- }, 0);
42
- return throwError(() => error);
43
- }
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
+ /** @internal */
9
+ export function route_error(
10
+ request: express.Request | FastifyRequest,
11
+ error: any,
12
+ ) {
13
+ error = (() => {
14
+ // HTTP-ERROR
15
+ if (error instanceof HttpException) return error;
16
+
17
+ // CUSTOM-REGISTERED ERROR
18
+ for (const [creator, closure] of ExceptionManager.tuples)
19
+ if (error instanceof creator) return closure(error);
20
+
21
+ // MAYBE INTERNAL ERROR
22
+ return error;
23
+ })();
24
+
25
+ try {
26
+ error.method = request.method;
27
+ error.path =
28
+ (request as express.Request).path ??
29
+ (request as FastifyRequest).routeOptions?.url ??
30
+ (request as any).routerPath;
31
+ } catch {}
32
+
33
+ setTimeout(() => {
34
+ for (const listener of ExceptionManager.listeners) {
35
+ try {
36
+ const res: any | Promise<any> = listener(error);
37
+ if (typeof res === "object" && typeof res.catch === "function")
38
+ res.catch(() => {});
39
+ } catch {}
40
+ }
41
+ }, 0);
42
+ return throwError(() => error);
43
+ }
@@ -1,64 +1,64 @@
1
- import { BadRequestException } from "@nestjs/common";
2
- import typia, { IValidation, TypeGuardError } from "typia";
3
-
4
- import { IRequestBodyValidator } from "../../options/IRequestBodyValidator";
5
- import { NoTransformConfigurationError } from "../NoTransformConfigurationError";
6
-
7
- /** @internal */
8
- export const validate_request_body =
9
- (method: string) =>
10
- <T>(validator?: IRequestBodyValidator<T>): ((input: T) => Error | null) => {
11
- if (!validator) {
12
- NoTransformConfigurationError(method);
13
- return () => null;
14
- } else if (validator.type === "assert") return assert(validator.assert);
15
- else if (validator.type === "is") return is(validator.is);
16
- else if (validator.type === "validate") return validate(validator.validate);
17
- return () =>
18
- new Error(`Error on nestia.core.${method}(): invalid typed validator.`);
19
- };
20
-
21
- /** @internal */
22
- const assert =
23
- <T>(closure: (data: T) => T) =>
24
- (input: T) => {
25
- try {
26
- closure(input);
27
- return null;
28
- } catch (exp) {
29
- if (typia.is<TypeGuardError>(exp)) {
30
- return new BadRequestException({
31
- path: exp.path,
32
- reason: exp.message,
33
- expected: exp.expected,
34
- value: exp.value,
35
- message: MESSAGE,
36
- });
37
- }
38
- throw exp;
39
- }
40
- };
41
-
42
- /** @internal */
43
- const is =
44
- <T>(closure: (data: T) => boolean) =>
45
- (input: T) => {
46
- const success: boolean = closure(input);
47
- return success ? null : new BadRequestException(MESSAGE);
48
- };
49
-
50
- /** @internal */
51
- const validate =
52
- <T>(closure: (data: T) => IValidation<T>) =>
53
- (input: T) => {
54
- const result: IValidation<T> = closure(input);
55
- return result.success
56
- ? null
57
- : new BadRequestException({
58
- errors: result.errors,
59
- message: MESSAGE,
60
- });
61
- };
62
-
63
- /** @internal */
64
- 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 { NoTransformConfigurationError } from "../NoTransformConfigurationError";
6
+
7
+ /** @internal */
8
+ export const validate_request_body =
9
+ (method: string) =>
10
+ <T>(validator?: IRequestBodyValidator<T>): ((input: T) => Error | null) => {
11
+ if (!validator) {
12
+ NoTransformConfigurationError(method);
13
+ return () => null;
14
+ } else if (validator.type === "assert") return assert(validator.assert);
15
+ else if (validator.type === "is") return is(validator.is);
16
+ else if (validator.type === "validate") return validate(validator.validate);
17
+ return () =>
18
+ new Error(`Error on nestia.core.${method}(): invalid typed validator.`);
19
+ };
20
+
21
+ /** @internal */
22
+ const assert =
23
+ <T>(closure: (data: T) => T) =>
24
+ (input: T) => {
25
+ try {
26
+ closure(input);
27
+ return null;
28
+ } catch (exp) {
29
+ if (typia.is<TypeGuardError>(exp)) {
30
+ return new BadRequestException({
31
+ path: exp.path,
32
+ reason: exp.message,
33
+ expected: exp.expected,
34
+ value: exp.value,
35
+ message: MESSAGE,
36
+ });
37
+ }
38
+ throw exp;
39
+ }
40
+ };
41
+
42
+ /** @internal */
43
+ const is =
44
+ <T>(closure: (data: T) => boolean) =>
45
+ (input: T) => {
46
+ const success: boolean = closure(input);
47
+ return success ? null : new BadRequestException(MESSAGE);
48
+ };
49
+
50
+ /** @internal */
51
+ const validate =
52
+ <T>(closure: (data: T) => IValidation<T>) =>
53
+ (input: T) => {
54
+ const result: IValidation<T> = closure(input);
55
+ return result.success
56
+ ? null
57
+ : new BadRequestException({
58
+ errors: result.errors,
59
+ message: MESSAGE,
60
+ });
61
+ };
62
+
63
+ /** @internal */
64
+ const MESSAGE = "Request body data is not following the promised type.";
@@ -1,67 +1,67 @@
1
- import { BadRequestException } from "@nestjs/common";
2
- import typia, { IValidation, TypeGuardError } from "typia";
3
-
4
- import { IRequestFormDataProps } from "../../options/IRequestFormDataProps";
5
- import { NoTransformConfigurationError } from "../NoTransformConfigurationError";
6
-
7
- /** @internal */
8
- export const validate_request_form_data = <T>(
9
- props?: IRequestFormDataProps<T>,
10
- ): ((value: FormData) => T | Error) => {
11
- if (!props) {
12
- NoTransformConfigurationError("TypedFormData.Body");
13
- return (input: FormData) => Object.entries(input) as T;
14
- } else if (props.validator.type === "assert")
15
- return assert(props.validator.assert);
16
- else if (props.validator.type === "is") return is(props.validator.is);
17
- else if (props.validator.type === "validate")
18
- return validate(props.validator.validate);
19
- return () =>
20
- new Error(
21
- `Error on nestia.core.TypedFormData.Body(): invalid typed validator.`,
22
- );
23
- };
24
-
25
- /** @internal */
26
- const assert =
27
- <T>(closure: (input: FormData) => T) =>
28
- (input: FormData): T | BadRequestException => {
29
- try {
30
- return closure(input);
31
- } catch (exp) {
32
- if (typia.is<TypeGuardError>(exp)) {
33
- return new BadRequestException({
34
- path: exp.path,
35
- reason: exp.message,
36
- expected: exp.expected,
37
- value: exp.value,
38
- message: MESSAGE,
39
- });
40
- }
41
- throw exp;
42
- }
43
- };
44
-
45
- /** @internal */
46
- const is =
47
- <T>(closure: (input: FormData) => T | null) =>
48
- (input: FormData): T | BadRequestException => {
49
- const result: T | null = closure(input);
50
- return result !== null ? result : new BadRequestException(MESSAGE);
51
- };
52
-
53
- /** @internal */
54
- const validate =
55
- <T>(closure: (input: FormData) => IValidation<T>) =>
56
- (input: FormData): T | BadRequestException => {
57
- const result: IValidation<T> = closure(input);
58
- return result.success
59
- ? result.data
60
- : new BadRequestException({
61
- errors: result.errors,
62
- message: MESSAGE,
63
- });
64
- };
65
-
66
- /** @internal */
67
- const MESSAGE = "Request multipart data is not following the promised type.";
1
+ import { BadRequestException } from "@nestjs/common";
2
+ import typia, { IValidation, TypeGuardError } from "typia";
3
+
4
+ import { IRequestFormDataProps } from "../../options/IRequestFormDataProps";
5
+ import { NoTransformConfigurationError } from "../NoTransformConfigurationError";
6
+
7
+ /** @internal */
8
+ export const validate_request_form_data = <T>(
9
+ props?: IRequestFormDataProps<T>,
10
+ ): ((value: FormData) => T | Error) => {
11
+ if (!props) {
12
+ NoTransformConfigurationError("TypedFormData.Body");
13
+ return (input: FormData) => Object.entries(input) as T;
14
+ } else if (props.validator.type === "assert")
15
+ return assert(props.validator.assert);
16
+ else if (props.validator.type === "is") return is(props.validator.is);
17
+ else if (props.validator.type === "validate")
18
+ return validate(props.validator.validate);
19
+ return () =>
20
+ new Error(
21
+ `Error on nestia.core.TypedFormData.Body(): invalid typed validator.`,
22
+ );
23
+ };
24
+
25
+ /** @internal */
26
+ const assert =
27
+ <T>(closure: (input: FormData) => T) =>
28
+ (input: FormData): T | BadRequestException => {
29
+ try {
30
+ return closure(input);
31
+ } catch (exp) {
32
+ if (typia.is<TypeGuardError>(exp)) {
33
+ return new BadRequestException({
34
+ path: exp.path,
35
+ reason: exp.message,
36
+ expected: exp.expected,
37
+ value: exp.value,
38
+ message: MESSAGE,
39
+ });
40
+ }
41
+ throw exp;
42
+ }
43
+ };
44
+
45
+ /** @internal */
46
+ const is =
47
+ <T>(closure: (input: FormData) => T | null) =>
48
+ (input: FormData): T | BadRequestException => {
49
+ const result: T | null = closure(input);
50
+ return result !== null ? result : new BadRequestException(MESSAGE);
51
+ };
52
+
53
+ /** @internal */
54
+ const validate =
55
+ <T>(closure: (input: FormData) => IValidation<T>) =>
56
+ (input: FormData): T | BadRequestException => {
57
+ const result: IValidation<T> = closure(input);
58
+ return result.success
59
+ ? result.data
60
+ : new BadRequestException({
61
+ errors: result.errors,
62
+ message: MESSAGE,
63
+ });
64
+ };
65
+
66
+ /** @internal */
67
+ const MESSAGE = "Request multipart data is not following the promised type.";
@@ -1,76 +1,76 @@
1
- import { BadRequestException } from "@nestjs/common";
2
- import typia, { IValidation, TypeGuardError } from "typia";
3
-
4
- import { IRequestHeadersValidator } from "../../options/IRequestHeadersValidator";
5
- import { NoTransformConfigurationError } from "../NoTransformConfigurationError";
6
-
7
- /** @internal */
8
- export const validate_request_headers = <T>(
9
- validator?: IRequestHeadersValidator<T>,
10
- ): ((input: Record<string, string | string[] | undefined>) => T | Error) => {
11
- if (!validator) {
12
- NoTransformConfigurationError("TypedHeaders");
13
- return (input: Record<string, string | string[] | undefined>) =>
14
- Object.entries(input) as T;
15
- } else if (validator.type === "assert") return assert(validator.assert);
16
- else if (validator.type === "is") return is(validator.is);
17
- else if (validator.type === "validate") return validate(validator.validate);
18
- return () =>
19
- new Error(`Error on nestia.core.TypedHeaders(): invalid typed validator.`);
20
- };
21
-
22
- /** @internal */
23
- const assert =
24
- <T>(closure: (input: Record<string, string | string[] | undefined>) => T) =>
25
- (
26
- input: Record<string, string | string[] | undefined>,
27
- ): T | BadRequestException => {
28
- try {
29
- return closure(input);
30
- } catch (exp) {
31
- if (typia.is<TypeGuardError>(exp)) {
32
- return new BadRequestException({
33
- path: exp.path,
34
- reason: exp.message,
35
- expected: exp.expected,
36
- value: exp.value,
37
- message: MESSAGE,
38
- });
39
- }
40
- throw exp;
41
- }
42
- };
43
-
44
- /** @internal */
45
- const is =
46
- <T>(
47
- closure: (input: Record<string, string | string[] | undefined>) => T | null,
48
- ) =>
49
- (
50
- input: Record<string, string | string[] | undefined>,
51
- ): T | BadRequestException => {
52
- const result: T | null = closure(input);
53
- return result !== null ? result : new BadRequestException(MESSAGE);
54
- };
55
-
56
- /** @internal */
57
- const validate =
58
- <T>(
59
- closure: (
60
- input: Record<string, string | string[] | undefined>,
61
- ) => IValidation<T>,
62
- ) =>
63
- (
64
- input: Record<string, string | string[] | undefined>,
65
- ): T | BadRequestException => {
66
- const result: IValidation<T> = closure(input);
67
- return result.success
68
- ? result.data
69
- : new BadRequestException({
70
- errors: result.errors,
71
- message: MESSAGE,
72
- });
73
- };
74
-
75
- /** @internal */
76
- const MESSAGE = "Request headers data is not following the promised type.";
1
+ import { BadRequestException } from "@nestjs/common";
2
+ import typia, { IValidation, TypeGuardError } from "typia";
3
+
4
+ import { IRequestHeadersValidator } from "../../options/IRequestHeadersValidator";
5
+ import { NoTransformConfigurationError } from "../NoTransformConfigurationError";
6
+
7
+ /** @internal */
8
+ export const validate_request_headers = <T>(
9
+ validator?: IRequestHeadersValidator<T>,
10
+ ): ((input: Record<string, string | string[] | undefined>) => T | Error) => {
11
+ if (!validator) {
12
+ NoTransformConfigurationError("TypedHeaders");
13
+ return (input: Record<string, string | string[] | undefined>) =>
14
+ Object.entries(input) as T;
15
+ } else if (validator.type === "assert") return assert(validator.assert);
16
+ else if (validator.type === "is") return is(validator.is);
17
+ else if (validator.type === "validate") return validate(validator.validate);
18
+ return () =>
19
+ new Error(`Error on nestia.core.TypedHeaders(): invalid typed validator.`);
20
+ };
21
+
22
+ /** @internal */
23
+ const assert =
24
+ <T>(closure: (input: Record<string, string | string[] | undefined>) => T) =>
25
+ (
26
+ input: Record<string, string | string[] | undefined>,
27
+ ): T | BadRequestException => {
28
+ try {
29
+ return closure(input);
30
+ } catch (exp) {
31
+ if (typia.is<TypeGuardError>(exp)) {
32
+ return new BadRequestException({
33
+ path: exp.path,
34
+ reason: exp.message,
35
+ expected: exp.expected,
36
+ value: exp.value,
37
+ message: MESSAGE,
38
+ });
39
+ }
40
+ throw exp;
41
+ }
42
+ };
43
+
44
+ /** @internal */
45
+ const is =
46
+ <T>(
47
+ closure: (input: Record<string, string | string[] | undefined>) => T | null,
48
+ ) =>
49
+ (
50
+ input: Record<string, string | string[] | undefined>,
51
+ ): T | BadRequestException => {
52
+ const result: T | null = closure(input);
53
+ return result !== null ? result : new BadRequestException(MESSAGE);
54
+ };
55
+
56
+ /** @internal */
57
+ const validate =
58
+ <T>(
59
+ closure: (
60
+ input: Record<string, string | string[] | undefined>,
61
+ ) => IValidation<T>,
62
+ ) =>
63
+ (
64
+ input: Record<string, string | string[] | undefined>,
65
+ ): T | BadRequestException => {
66
+ const result: IValidation<T> = closure(input);
67
+ return result.success
68
+ ? result.data
69
+ : new BadRequestException({
70
+ errors: result.errors,
71
+ message: MESSAGE,
72
+ });
73
+ };
74
+
75
+ /** @internal */
76
+ const MESSAGE = "Request headers data is not following the promised type.";
@@ -1,83 +1,83 @@
1
- import { BadRequestException } from "@nestjs/common";
2
- import typia, { IValidation, TypeGuardError } from "typia";
3
-
4
- import { IRequestQueryValidator } from "../../options/IRequestQueryValidator";
5
- import { NoTransformConfigurationError } from "../NoTransformConfigurationError";
6
-
7
- /** @internal */
8
- export const validate_request_query =
9
- (method: string) =>
10
- <T>(validator?: IRequestQueryValidator<T>) => {
11
- if (!validator) {
12
- NoTransformConfigurationError(method);
13
- return (input: URLSearchParams) =>
14
- Object.fromEntries(input.entries()) as T;
15
- } else if (validator.type === "assert") return assert(validator.assert);
16
- else if (validator.type === "is") return is(validator.is);
17
- else if (validator.type === "validate") return validate(validator.validate);
18
- return () =>
19
- new Error(`Error on nestia.core.${method}(): invalid typed validator.`);
20
- };
21
-
22
- /** @internal */
23
- const assert =
24
- <T>(closure: (input: URLSearchParams) => T) =>
25
- (input: URLSearchParams): T | BadRequestException => {
26
- try {
27
- return closure(input);
28
- } catch (exp) {
29
- if (typia.is<TypeGuardError>(exp)) {
30
- return new BadRequestException({
31
- path: exp.path,
32
- reason: exp.message,
33
- expected: exp.expected,
34
- value: exp.value,
35
- message: MESSAGE,
36
- });
37
- }
38
- if (is_missing_query_property(exp)) return new BadRequestException(MESSAGE);
39
- throw exp;
40
- }
41
- };
42
-
43
- /** @internal */
44
- const is =
45
- <T>(closure: (input: URLSearchParams) => T | null) =>
46
- (input: URLSearchParams): T | BadRequestException => {
47
- const result: T | null = (() => {
48
- try {
49
- return closure(input);
50
- } catch (exp) {
51
- if (is_missing_query_property(exp)) return null;
52
- throw exp;
53
- }
54
- })();
55
- return result !== null ? result : new BadRequestException(MESSAGE);
56
- };
57
-
58
- /** @internal */
59
- const validate =
60
- <T>(closure: (input: URLSearchParams) => IValidation<T>) =>
61
- (input: URLSearchParams): T | BadRequestException => {
62
- const result: IValidation<T> | null = (() => {
63
- try {
64
- return closure(input);
65
- } catch (exp) {
66
- if (is_missing_query_property(exp)) return null;
67
- throw exp;
68
- }
69
- })();
70
- if (result === null) return new BadRequestException(MESSAGE);
71
- return result.success
72
- ? result.data
73
- : new BadRequestException({
74
- errors: result.errors,
75
- message: MESSAGE,
76
- });
77
- };
78
-
79
- /** @internal */
80
- const MESSAGE = "Request query data is not following the promised type.";
81
-
82
- const is_missing_query_property = (exp: unknown): exp is Error =>
83
- exp instanceof Error && /^missing [^.\[\]\s]+$/.test(exp.message);
1
+ import { BadRequestException } from "@nestjs/common";
2
+ import typia, { IValidation, TypeGuardError } from "typia";
3
+
4
+ import { IRequestQueryValidator } from "../../options/IRequestQueryValidator";
5
+ import { NoTransformConfigurationError } from "../NoTransformConfigurationError";
6
+
7
+ /** @internal */
8
+ export const validate_request_query =
9
+ (method: string) =>
10
+ <T>(validator?: IRequestQueryValidator<T>) => {
11
+ if (!validator) {
12
+ NoTransformConfigurationError(method);
13
+ return (input: URLSearchParams) =>
14
+ Object.fromEntries(input.entries()) as T;
15
+ } else if (validator.type === "assert") return assert(validator.assert);
16
+ else if (validator.type === "is") return is(validator.is);
17
+ else if (validator.type === "validate") return validate(validator.validate);
18
+ return () =>
19
+ new Error(`Error on nestia.core.${method}(): invalid typed validator.`);
20
+ };
21
+
22
+ /** @internal */
23
+ const assert =
24
+ <T>(closure: (input: URLSearchParams) => T) =>
25
+ (input: URLSearchParams): T | BadRequestException => {
26
+ try {
27
+ return closure(input);
28
+ } catch (exp) {
29
+ if (typia.is<TypeGuardError>(exp)) {
30
+ return new BadRequestException({
31
+ path: exp.path,
32
+ reason: exp.message,
33
+ expected: exp.expected,
34
+ value: exp.value,
35
+ message: MESSAGE,
36
+ });
37
+ }
38
+ if (is_missing_query_property(exp)) return new BadRequestException(MESSAGE);
39
+ throw exp;
40
+ }
41
+ };
42
+
43
+ /** @internal */
44
+ const is =
45
+ <T>(closure: (input: URLSearchParams) => T | null) =>
46
+ (input: URLSearchParams): T | BadRequestException => {
47
+ const result: T | null = (() => {
48
+ try {
49
+ return closure(input);
50
+ } catch (exp) {
51
+ if (is_missing_query_property(exp)) return null;
52
+ throw exp;
53
+ }
54
+ })();
55
+ return result !== null ? result : new BadRequestException(MESSAGE);
56
+ };
57
+
58
+ /** @internal */
59
+ const validate =
60
+ <T>(closure: (input: URLSearchParams) => IValidation<T>) =>
61
+ (input: URLSearchParams): T | BadRequestException => {
62
+ const result: IValidation<T> | null = (() => {
63
+ try {
64
+ return closure(input);
65
+ } catch (exp) {
66
+ if (is_missing_query_property(exp)) return null;
67
+ throw exp;
68
+ }
69
+ })();
70
+ if (result === null) return new BadRequestException(MESSAGE);
71
+ return result.success
72
+ ? result.data
73
+ : new BadRequestException({
74
+ errors: result.errors,
75
+ message: MESSAGE,
76
+ });
77
+ };
78
+
79
+ /** @internal */
80
+ const MESSAGE = "Request query data is not following the promised type.";
81
+
82
+ const is_missing_query_property = (exp: unknown): exp is Error =>
83
+ exp instanceof Error && /^missing [^.\[\]\s]+$/.test(exp.message);