@nestia/core 12.0.0-dev.20260601.1 → 12.0.0-dev.20260612.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.
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 -444
  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 -403
  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,196 +1,198 @@
1
- import {
2
- CallHandler,
3
- Delete,
4
- ExecutionContext,
5
- Get,
6
- NestInterceptor,
7
- Patch,
8
- Post,
9
- Put,
10
- UseInterceptors,
11
- applyDecorators,
12
- } from "@nestjs/common";
13
- import { HttpArgumentsHost } from "@nestjs/common/interfaces";
14
- import type express from "express";
15
- import { catchError, map } from "rxjs/operators";
16
- import typia, { IValidation } from "typia";
17
-
18
- import { IResponseBodyStringifier } from "../options/IResponseBodyStringifier";
19
- import { get_path_and_stringify } from "./internal/get_path_and_stringify";
20
- import { route_error } from "./internal/route_error";
21
-
22
- /**
23
- * Type safe router decorator functions.
24
- *
25
- * `TypedRoute` is a module containing router decorator functions which can
26
- * boost up JSON string conversion speed about 200x times faster than
27
- * `class-transformer`. Furthermore, such JSON string conversion is even type
28
- * safe through [typia](https://github.com/samchon/typia).
29
- *
30
- * For reference, if you try to invalid data that is not following the promised
31
- * type `T`, 500 internal server error would be thrown. Also, as `TypedRoute`
32
- * composes JSON string through `typia.assertStringify<T>()` function, it is not
33
- * possible to modify response data through interceptors.
34
- *
35
- * @author Jeongho Nam - https://github.com/samchon
36
- */
37
- export namespace TypedRoute {
38
- /**
39
- * Router decorator function for the GET method.
40
- *
41
- * @param path Path of the HTTP request
42
- * @returns Method decorator
43
- */
44
- export const Get = Generator("Get");
45
-
46
- /**
47
- * Router decorator function for the POST method.
48
- *
49
- * @param path Path of the HTTP request
50
- * @returns Method decorator
51
- */
52
- export const Post = Generator("Post");
53
-
54
- /**
55
- * Router decorator function for the PATH method.
56
- *
57
- * @param path Path of the HTTP request
58
- * @returns Method decorator
59
- */
60
- export const Patch = Generator("Patch");
61
-
62
- /**
63
- * Router decorator function for the PUT method.
64
- *
65
- * @param path Path of the HTTP request
66
- * @returns Method decorator
67
- */
68
- export const Put = Generator("Put");
69
-
70
- /**
71
- * Router decorator function for the DELETE method.
72
- *
73
- * @param path Path of the HTTP request
74
- * @returns Method decorator
75
- */
76
- export const Delete = Generator("Delete");
77
-
78
- /**
79
- * Set the logger function for the response validation failure.
80
- *
81
- * If you've configured the transformation option to `validate.log` in the
82
- * `tsconfig.json` file, then the error log information of the response
83
- * validation failure would be logged through this function instead of
84
- * throwing the 400 bad request error.
85
- *
86
- * By the way, be careful. If you've configured the response transformation
87
- * option to be `validate.log`, client may get wrong response data. Therefore,
88
- * this way is not recommended in the common backend server case.
89
- *
90
- * @default console.log
91
- * @param func Logger function
92
- */
93
- export function setValidateErrorLogger(
94
- func: (log: IValidateErrorLog) => void,
95
- ): void {
96
- __logger = func;
97
- }
98
-
99
- /**
100
- * Error log information of the response validation failure.
101
- *
102
- * `IValidationErrorLog` is a structure representing the error log information
103
- * when the returned value from the `@TypedRoute` or `@EncryptedRoute`
104
- * decorated controller method is not following the promised type `T`.
105
- *
106
- * If you've configured the transformation option to `validate.log` or
107
- * `validateEquals.log` in the `tsconfig.json` file, then this error log
108
- * information `IValidateErrorLog` would be logged through the
109
- * {@link setValidateErrorLogger} function instead of throwing the 400 bad
110
- * request error.
111
- */
112
- export interface IValidateErrorLog {
113
- /** HTTP method of the request. */
114
- method: string;
115
-
116
- /** HTTP path of the request. */
117
- path: string;
118
-
119
- /** Validation error information with detailed reasons. */
120
- errors: IValidation.IError[];
121
-
122
- /** Data that is not following the promised type `T`. */
123
- data: unknown;
124
- }
125
-
126
- /** @internal */
127
- export let __logger: (log: IValidateErrorLog) => void = console.log;
128
-
129
- /** @internal */
130
- function Generator(method: "Get" | "Post" | "Put" | "Patch" | "Delete") {
131
- function route(path?: string | string[]): MethodDecorator;
132
- function route<T>(stringify?: IResponseBodyStringifier<T>): MethodDecorator;
133
- function route<T>(
134
- path: string | string[],
135
- stringify?: IResponseBodyStringifier<T>,
136
- ): MethodDecorator;
137
-
138
- function route(...args: any[]): MethodDecorator {
139
- const [path, stringify] = get_path_and_stringify(() => __logger)(
140
- `TypedRoute.${method}`,
141
- )(...args);
142
- return applyDecorators(
143
- ROUTERS[method](path),
144
- UseInterceptors(new TypedRouteInterceptor(stringify)),
145
- );
146
- }
147
- return route;
148
- }
149
- }
150
- for (const method of [
151
- typia.json.stringify,
152
- typia.json.isStringify,
153
- typia.json.assertStringify,
154
- typia.json.validateStringify,
155
- ])
156
- for (const [key, value] of Object.entries(method))
157
- for (const deco of [
158
- TypedRoute.Get,
159
- TypedRoute.Delete,
160
- TypedRoute.Post,
161
- TypedRoute.Put,
162
- TypedRoute.Patch,
163
- ])
164
- (deco as any)[key] = value;
165
-
166
- /** @internal */
167
- class TypedRouteInterceptor implements NestInterceptor {
168
- public constructor(
169
- private readonly stringify: (
170
- input: any,
171
- method: string,
172
- path: string,
173
- ) => string,
174
- ) {}
175
-
176
- public intercept(context: ExecutionContext, next: CallHandler) {
177
- const http: HttpArgumentsHost = context.switchToHttp();
178
- const request: express.Request = http.getRequest();
179
- const response: express.Response = http.getResponse();
180
- response.header("Content-Type", "application/json");
181
-
182
- return next.handle().pipe(
183
- map((value) => this.stringify(value, request.method, request.url)),
184
- catchError((err) => route_error(http.getRequest(), err)),
185
- );
186
- }
187
- }
188
-
189
- /** @internal */
190
- const ROUTERS = {
191
- Get,
192
- Post,
193
- Patch,
194
- Put,
195
- Delete,
196
- };
1
+ import {
2
+ CallHandler,
3
+ Delete,
4
+ ExecutionContext,
5
+ Get,
6
+ Header,
7
+ NestInterceptor,
8
+ Patch,
9
+ Post,
10
+ Put,
11
+ UseInterceptors,
12
+ applyDecorators,
13
+ } from "@nestjs/common";
14
+ import { HttpArgumentsHost } from "@nestjs/common/interfaces";
15
+ import type express from "express";
16
+ import { catchError, map } from "rxjs/operators";
17
+ import typia, { IValidation } from "typia";
18
+
19
+ import { IResponseBodyStringifier } from "../options/IResponseBodyStringifier";
20
+ import { get_path_and_stringify } from "./internal/get_path_and_stringify";
21
+ import { route_error } from "./internal/route_error";
22
+
23
+ /**
24
+ * Type safe router decorator functions.
25
+ *
26
+ * `TypedRoute` is a module containing router decorator functions which can
27
+ * boost up JSON string conversion speed about 200x times faster than
28
+ * `class-transformer`. Furthermore, such JSON string conversion is even type
29
+ * safe through [typia](https://github.com/samchon/typia).
30
+ *
31
+ * For reference, if you try to invalid data that is not following the promised
32
+ * type `T`, 500 internal server error would be thrown. Also, as `TypedRoute`
33
+ * composes JSON string through `typia.assertStringify<T>()` function, it is not
34
+ * possible to modify response data through interceptors.
35
+ *
36
+ * @author Jeongho Nam - https://github.com/samchon
37
+ */
38
+ export namespace TypedRoute {
39
+ /**
40
+ * Router decorator function for the GET method.
41
+ *
42
+ * @param path Path of the HTTP request
43
+ * @returns Method decorator
44
+ */
45
+ export const Get = Generator("Get");
46
+
47
+ /**
48
+ * Router decorator function for the POST method.
49
+ *
50
+ * @param path Path of the HTTP request
51
+ * @returns Method decorator
52
+ */
53
+ export const Post = Generator("Post");
54
+
55
+ /**
56
+ * Router decorator function for the PATH method.
57
+ *
58
+ * @param path Path of the HTTP request
59
+ * @returns Method decorator
60
+ */
61
+ export const Patch = Generator("Patch");
62
+
63
+ /**
64
+ * Router decorator function for the PUT method.
65
+ *
66
+ * @param path Path of the HTTP request
67
+ * @returns Method decorator
68
+ */
69
+ export const Put = Generator("Put");
70
+
71
+ /**
72
+ * Router decorator function for the DELETE method.
73
+ *
74
+ * @param path Path of the HTTP request
75
+ * @returns Method decorator
76
+ */
77
+ export const Delete = Generator("Delete");
78
+
79
+ /**
80
+ * Set the logger function for the response validation failure.
81
+ *
82
+ * If you've configured the transformation option to `validate.log` in the
83
+ * `tsconfig.json` file, then the error log information of the response
84
+ * validation failure would be logged through this function instead of
85
+ * throwing the 400 bad request error.
86
+ *
87
+ * By the way, be careful. If you've configured the response transformation
88
+ * option to be `validate.log`, client may get wrong response data. Therefore,
89
+ * this way is not recommended in the common backend server case.
90
+ *
91
+ * @default console.log
92
+ * @param func Logger function
93
+ */
94
+ export function setValidateErrorLogger(
95
+ func: (log: IValidateErrorLog) => void,
96
+ ): void {
97
+ __logger = func;
98
+ }
99
+
100
+ /**
101
+ * Error log information of the response validation failure.
102
+ *
103
+ * `IValidationErrorLog` is a structure representing the error log information
104
+ * when the returned value from the `@TypedRoute` or `@EncryptedRoute`
105
+ * decorated controller method is not following the promised type `T`.
106
+ *
107
+ * If you've configured the transformation option to `validate.log` or
108
+ * `validateEquals.log` in the `tsconfig.json` file, then this error log
109
+ * information `IValidateErrorLog` would be logged through the
110
+ * {@link setValidateErrorLogger} function instead of throwing the 400 bad
111
+ * request error.
112
+ */
113
+ export interface IValidateErrorLog {
114
+ /** HTTP method of the request. */
115
+ method: string;
116
+
117
+ /** HTTP path of the request. */
118
+ path: string;
119
+
120
+ /** Validation error information with detailed reasons. */
121
+ errors: IValidation.IError[];
122
+
123
+ /** Data that is not following the promised type `T`. */
124
+ data: unknown;
125
+ }
126
+
127
+ /** @internal */
128
+ export let __logger: (log: IValidateErrorLog) => void = console.log;
129
+
130
+ /** @internal */
131
+ function Generator(method: "Get" | "Post" | "Put" | "Patch" | "Delete") {
132
+ function route(path?: string | string[]): MethodDecorator;
133
+ function route<T>(stringify?: IResponseBodyStringifier<T>): MethodDecorator;
134
+ function route<T>(
135
+ path: string | string[],
136
+ stringify?: IResponseBodyStringifier<T>,
137
+ ): MethodDecorator;
138
+
139
+ function route(...args: any[]): MethodDecorator {
140
+ const [path, stringify] = get_path_and_stringify(() => __logger)(
141
+ `TypedRoute.${method}`,
142
+ )(...args);
143
+ return applyDecorators(
144
+ ROUTERS[method](path),
145
+ Header("Content-Type", "application/json"),
146
+ UseInterceptors(new TypedRouteInterceptor(stringify)),
147
+ );
148
+ }
149
+ return route;
150
+ }
151
+ }
152
+ for (const method of [
153
+ typia.json.stringify,
154
+ typia.json.isStringify,
155
+ typia.json.assertStringify,
156
+ typia.json.validateStringify,
157
+ ])
158
+ for (const [key, value] of Object.entries(method))
159
+ for (const deco of [
160
+ TypedRoute.Get,
161
+ TypedRoute.Delete,
162
+ TypedRoute.Post,
163
+ TypedRoute.Put,
164
+ TypedRoute.Patch,
165
+ ])
166
+ (deco as any)[key] = value;
167
+
168
+ /** @internal */
169
+ class TypedRouteInterceptor implements NestInterceptor {
170
+ public constructor(
171
+ private readonly stringify: (
172
+ input: any,
173
+ method: string,
174
+ path: string,
175
+ ) => string,
176
+ ) {}
177
+
178
+ public intercept(context: ExecutionContext, next: CallHandler) {
179
+ const http: HttpArgumentsHost = context.switchToHttp();
180
+ const request: express.Request = http.getRequest();
181
+ const response: express.Response = http.getResponse();
182
+ response.header("Content-Type", "application/json");
183
+
184
+ return next.handle().pipe(
185
+ map((value) => this.stringify(value, request.method, request.url)),
186
+ catchError((err) => route_error(http.getRequest(), err)),
187
+ );
188
+ }
189
+ }
190
+
191
+ /** @internal */
192
+ const ROUTERS = {
193
+ Get,
194
+ Post,
195
+ Patch,
196
+ Put,
197
+ Delete,
198
+ };