@nestia/core 12.0.0-rc.2 → 12.0.0-rc.4

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 (80) hide show
  1. package/LICENSE +21 -21
  2. package/MIGRATION.md +138 -169
  3. package/lib/decorators/NoTransformConfigurationError.js +5 -5
  4. package/lib/decorators/NoTransformConfigurationError.js.map +1 -1
  5. package/native/cmd/ttsc-nestia/main.go +11 -11
  6. package/native/go.mod +32 -32
  7. package/native/go.sum +54 -54
  8. package/native/plugin/plan.go +102 -102
  9. package/native/transform/ast.go +32 -32
  10. package/native/transform/build.go +388 -380
  11. package/native/transform/cleanup.go +408 -408
  12. package/native/transform/contributor.go +97 -97
  13. package/native/transform/core_querify.go +231 -231
  14. package/native/transform/core_transform.go +1996 -1996
  15. package/native/transform/core_websocket.go +115 -115
  16. package/native/transform/exports.go +13 -13
  17. package/native/transform/mcp_transform.go +414 -414
  18. package/native/transform/node_transform.go +357 -357
  19. package/native/transform/path_rewrite.go +285 -285
  20. package/native/transform/printer.go +244 -244
  21. package/native/transform/rewrite.go +668 -668
  22. package/native/transform/run.go +73 -73
  23. package/native/transform/transform.go +336 -336
  24. package/native/transform/typia_fast.go +375 -352
  25. package/native/transform/typia_replacement.go +24 -24
  26. package/native/transform.cjs +43 -43
  27. package/package.json +9 -9
  28. package/src/adaptors/McpAdaptor.ts +276 -276
  29. package/src/adaptors/WebSocketAdaptor.ts +429 -429
  30. package/src/decorators/DynamicModule.ts +44 -44
  31. package/src/decorators/EncryptedBody.ts +97 -97
  32. package/src/decorators/EncryptedController.ts +40 -40
  33. package/src/decorators/EncryptedModule.ts +98 -98
  34. package/src/decorators/EncryptedRoute.ts +213 -213
  35. package/src/decorators/HumanRoute.ts +21 -21
  36. package/src/decorators/McpRoute.ts +154 -154
  37. package/src/decorators/NoTransformConfigurationError.ts +40 -40
  38. package/src/decorators/PlainBody.ts +76 -76
  39. package/src/decorators/SwaggerCustomizer.ts +97 -97
  40. package/src/decorators/SwaggerExample.ts +180 -180
  41. package/src/decorators/TypedBody.ts +57 -57
  42. package/src/decorators/TypedException.ts +147 -147
  43. package/src/decorators/TypedFormData.ts +187 -187
  44. package/src/decorators/TypedHeaders.ts +66 -66
  45. package/src/decorators/TypedParam.ts +77 -77
  46. package/src/decorators/TypedQuery.ts +234 -234
  47. package/src/decorators/TypedRoute.ts +198 -198
  48. package/src/decorators/WebSocketRoute.ts +242 -242
  49. package/src/decorators/doNotThrowTransformError.ts +5 -5
  50. package/src/decorators/internal/EncryptedConstant.ts +2 -2
  51. package/src/decorators/internal/IMcpRouteReflect.ts +40 -40
  52. package/src/decorators/internal/IWebSocketRouteReflect.ts +23 -23
  53. package/src/decorators/internal/get_path_and_querify.ts +94 -94
  54. package/src/decorators/internal/get_path_and_stringify.ts +110 -110
  55. package/src/decorators/internal/get_text_body.ts +16 -16
  56. package/src/decorators/internal/headers_to_object.ts +11 -11
  57. package/src/decorators/internal/is_request_body_undefined.ts +12 -12
  58. package/src/decorators/internal/load_controller.ts +94 -94
  59. package/src/decorators/internal/route_error.ts +43 -43
  60. package/src/decorators/internal/validate_request_body.ts +64 -64
  61. package/src/decorators/internal/validate_request_form_data.ts +67 -67
  62. package/src/decorators/internal/validate_request_headers.ts +76 -76
  63. package/src/decorators/internal/validate_request_query.ts +83 -83
  64. package/src/index.ts +5 -5
  65. package/src/module.ts +25 -25
  66. package/src/options/IRequestBodyValidator.ts +20 -20
  67. package/src/options/IRequestFormDataProps.ts +27 -27
  68. package/src/options/IRequestHeadersValidator.ts +22 -22
  69. package/src/options/IRequestQueryValidator.ts +20 -20
  70. package/src/options/IResponseBodyQuerifier.ts +25 -25
  71. package/src/options/IResponseBodyStringifier.ts +30 -30
  72. package/src/transform.ts +26 -26
  73. package/src/typings/Creator.ts +3 -3
  74. package/src/typings/get-function-location.d.ts +7 -7
  75. package/src/utils/ArrayUtil.ts +7 -7
  76. package/src/utils/ExceptionManager.ts +115 -115
  77. package/src/utils/Singleton.ts +16 -16
  78. package/src/utils/SourceFinder.ts +54 -54
  79. package/src/utils/VersioningStrategy.ts +27 -27
  80. package/README.md +0 -93
@@ -1,198 +1,198 @@
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
- };
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
+ };