@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,213 +1,213 @@
1
- import { IEncryptionPassword } from "@nestia/fetcher";
2
- import { AesPkcs5 } from "@nestia/fetcher/lib/AesPkcs5";
3
- import {
4
- CallHandler,
5
- Delete,
6
- ExecutionContext,
7
- Get,
8
- NestInterceptor,
9
- Patch,
10
- Post,
11
- Put,
12
- UseInterceptors,
13
- applyDecorators,
14
- } from "@nestjs/common";
15
- import { HttpArgumentsHost } from "@nestjs/common/interfaces";
16
- import express from "express";
17
- import { catchError, map } from "rxjs/operators";
18
- import typia from "typia";
19
-
20
- import { IResponseBodyStringifier } from "../options/IResponseBodyStringifier";
21
- import { Singleton } from "../utils/Singleton";
22
- import { TypedRoute } from "./TypedRoute";
23
- import { ENCRYPTION_METADATA_KEY } from "./internal/EncryptedConstant";
24
- import { get_path_and_stringify } from "./internal/get_path_and_stringify";
25
- import { headers_to_object } from "./internal/headers_to_object";
26
- import { route_error } from "./internal/route_error";
27
-
28
- /**
29
- * Encrypted router decorator functions.
30
- *
31
- * `EncryptedRoute` is a module containing router decorator functions which
32
- * encrypts response body data through AES-128/256 encryption. Furthermore, they
33
- * can boost up JSON string conversion speed about 50x times faster than
34
- * `class-transformer`, even type safe through
35
- * [typia](https://github.com/samchon/typia).
36
- *
37
- * For reference, if you try to invalid data that is not following the promised
38
- * type `T`, 500 internal server error would be thrown. Also, as
39
- * `EncryptedRoute` composes JSON string through `typia.assertStringify<T>()`
40
- * function, it is not possible to modify response data through interceptors.
41
- *
42
- * - AES-128/256
43
- * - CBC mode
44
- * - PKCS #5 Padding
45
- * - Base64 Encoding
46
- *
47
- * @author Jeongho Nam - https://github.com/samchon
48
- */
49
- export namespace EncryptedRoute {
50
- /**
51
- * Encrypted router decorator function for the GET method.
52
- *
53
- * @param paths Path(s) of the HTTP request
54
- * @returns Method decorator
55
- */
56
- export const Get = Generator("Get");
57
-
58
- /**
59
- * Encrypted router decorator function for the GET method.
60
- *
61
- * @param paths Path(s) of the HTTP request
62
- * @returns Method decorator
63
- */
64
- export const Post = Generator("Post");
65
-
66
- /**
67
- * Encrypted router decorator function for the PATCH method.
68
- *
69
- * @param path Path of the HTTP request
70
- * @returns Method decorator
71
- */
72
- export const Patch = Generator("Patch");
73
-
74
- /**
75
- * Encrypted router decorator function for the PUT method.
76
- *
77
- * @param path Path of the HTTP request
78
- * @returns Method decorator
79
- */
80
- export const Put = Generator("Put");
81
-
82
- /**
83
- * Encrypted router decorator function for the DELETE method.
84
- *
85
- * @param path Path of the HTTP request
86
- * @returns Method decorator
87
- */
88
- export const Delete = Generator("Delete");
89
-
90
- /**
91
- * Set the logger function for the response validation failure.
92
- *
93
- * If you've configured the transformation option to `validate.log` in the
94
- * `tsconfig.json` file, then the error log information of the response
95
- * validation failure would be logged through this function instead of
96
- * throwing the 400 bad request error.
97
- *
98
- * By the way, be careful. If you've configured the response transformation
99
- * option to be `validate.log`, client may get wrong response data. Therefore,
100
- * this way is not recommended in the common backend server case.
101
- *
102
- * @default console.log
103
- * @param func Logger function
104
- */
105
- export function setValidateErrorLogger(
106
- func: (log: IValidateErrorLog) => void,
107
- ): void {
108
- TypedRoute.setValidateErrorLogger(func);
109
- }
110
-
111
- export import IValidateErrorLog = TypedRoute.IValidateErrorLog;
112
-
113
- /** @internal */
114
- function Generator(method: "Get" | "Post" | "Put" | "Patch" | "Delete") {
115
- function route(path?: string | string[]): MethodDecorator;
116
- function route<T>(
117
- stringify?: IResponseBodyStringifier<T> | null,
118
- ): MethodDecorator;
119
- function route<T>(
120
- path: string | string[],
121
- stringify?: IResponseBodyStringifier<T> | null,
122
- ): MethodDecorator;
123
-
124
- function route(...args: any[]): MethodDecorator {
125
- const [path, stringify] = get_path_and_stringify(
126
- () => TypedRoute.__logger,
127
- )(`EncryptedRoute.${method}`)(...args);
128
- return applyDecorators(
129
- ROUTERS[method](path),
130
- UseInterceptors(new EncryptedRouteInterceptor(method, stringify)),
131
- );
132
- }
133
- return route;
134
- }
135
- }
136
-
137
- for (const method of [
138
- typia.json.isStringify,
139
- typia.json.assertStringify,
140
- typia.json.validateStringify,
141
- typia.json.stringify,
142
- ])
143
- for (const [key, value] of Object.entries(method))
144
- for (const deco of [
145
- EncryptedRoute.Get,
146
- EncryptedRoute.Delete,
147
- EncryptedRoute.Post,
148
- EncryptedRoute.Put,
149
- EncryptedRoute.Patch,
150
- ])
151
- (deco as any)[key] = value;
152
-
153
- /** @internal */
154
- class EncryptedRouteInterceptor implements NestInterceptor {
155
- public constructor(
156
- private readonly method: string,
157
- private readonly stringify: (
158
- input: any,
159
- method: string,
160
- path: string,
161
- ) => string,
162
- ) {}
163
-
164
- public intercept(context: ExecutionContext, next: CallHandler) {
165
- const http: HttpArgumentsHost = context.switchToHttp();
166
- return next.handle().pipe(
167
- map((value) => {
168
- const param:
169
- | IEncryptionPassword
170
- | IEncryptionPassword.Closure
171
- | undefined = Reflect.getMetadata(
172
- ENCRYPTION_METADATA_KEY,
173
- context.getClass(),
174
- );
175
- if (!param)
176
- return Error(
177
- `Error on EncryptedRoute.${this.method}(): no password found.`,
178
- );
179
-
180
- const request: express.Request = http.getRequest();
181
- const headers: Singleton<Record<string, string>> = new Singleton(() =>
182
- headers_to_object(request.headers),
183
- );
184
- const body: string | undefined = this.stringify(
185
- value,
186
- request.method,
187
- request.url,
188
- );
189
- const password: IEncryptionPassword =
190
- typeof param === "function"
191
- ? param({
192
- headers: headers.get(),
193
- body,
194
- direction: "encode",
195
- })
196
- : param;
197
-
198
- if (body === undefined) return body;
199
- return AesPkcs5.encrypt(body, password.key, password.iv);
200
- }),
201
- catchError((err) => route_error(http.getRequest(), err)),
202
- );
203
- }
204
- }
205
-
206
- /** @internal */
207
- const ROUTERS = {
208
- Get,
209
- Post,
210
- Put,
211
- Patch,
212
- Delete,
213
- };
1
+ import { IEncryptionPassword } from "@nestia/fetcher";
2
+ import { AesPkcs5 } from "@nestia/fetcher/lib/AesPkcs5";
3
+ import {
4
+ CallHandler,
5
+ Delete,
6
+ ExecutionContext,
7
+ Get,
8
+ NestInterceptor,
9
+ Patch,
10
+ Post,
11
+ Put,
12
+ UseInterceptors,
13
+ applyDecorators,
14
+ } from "@nestjs/common";
15
+ import { HttpArgumentsHost } from "@nestjs/common/interfaces";
16
+ import express from "express";
17
+ import { catchError, map } from "rxjs/operators";
18
+ import typia from "typia";
19
+
20
+ import { IResponseBodyStringifier } from "../options/IResponseBodyStringifier";
21
+ import { Singleton } from "../utils/Singleton";
22
+ import { TypedRoute } from "./TypedRoute";
23
+ import { ENCRYPTION_METADATA_KEY } from "./internal/EncryptedConstant";
24
+ import { get_path_and_stringify } from "./internal/get_path_and_stringify";
25
+ import { headers_to_object } from "./internal/headers_to_object";
26
+ import { route_error } from "./internal/route_error";
27
+
28
+ /**
29
+ * Encrypted router decorator functions.
30
+ *
31
+ * `EncryptedRoute` is a module containing router decorator functions which
32
+ * encrypts response body data through AES-128/256 encryption. Furthermore, they
33
+ * can boost up JSON string conversion speed about 50x times faster than
34
+ * `class-transformer`, even type safe through
35
+ * [typia](https://github.com/samchon/typia).
36
+ *
37
+ * For reference, if you try to invalid data that is not following the promised
38
+ * type `T`, 500 internal server error would be thrown. Also, as
39
+ * `EncryptedRoute` composes JSON string through `typia.assertStringify<T>()`
40
+ * function, it is not possible to modify response data through interceptors.
41
+ *
42
+ * - AES-128/256
43
+ * - CBC mode
44
+ * - PKCS #5 Padding
45
+ * - Base64 Encoding
46
+ *
47
+ * @author Jeongho Nam - https://github.com/samchon
48
+ */
49
+ export namespace EncryptedRoute {
50
+ /**
51
+ * Encrypted router decorator function for the GET method.
52
+ *
53
+ * @param paths Path(s) of the HTTP request
54
+ * @returns Method decorator
55
+ */
56
+ export const Get = Generator("Get");
57
+
58
+ /**
59
+ * Encrypted router decorator function for the GET method.
60
+ *
61
+ * @param paths Path(s) of the HTTP request
62
+ * @returns Method decorator
63
+ */
64
+ export const Post = Generator("Post");
65
+
66
+ /**
67
+ * Encrypted router decorator function for the PATCH method.
68
+ *
69
+ * @param path Path of the HTTP request
70
+ * @returns Method decorator
71
+ */
72
+ export const Patch = Generator("Patch");
73
+
74
+ /**
75
+ * Encrypted router decorator function for the PUT method.
76
+ *
77
+ * @param path Path of the HTTP request
78
+ * @returns Method decorator
79
+ */
80
+ export const Put = Generator("Put");
81
+
82
+ /**
83
+ * Encrypted router decorator function for the DELETE method.
84
+ *
85
+ * @param path Path of the HTTP request
86
+ * @returns Method decorator
87
+ */
88
+ export const Delete = Generator("Delete");
89
+
90
+ /**
91
+ * Set the logger function for the response validation failure.
92
+ *
93
+ * If you've configured the transformation option to `validate.log` in the
94
+ * `tsconfig.json` file, then the error log information of the response
95
+ * validation failure would be logged through this function instead of
96
+ * throwing the 400 bad request error.
97
+ *
98
+ * By the way, be careful. If you've configured the response transformation
99
+ * option to be `validate.log`, client may get wrong response data. Therefore,
100
+ * this way is not recommended in the common backend server case.
101
+ *
102
+ * @default console.log
103
+ * @param func Logger function
104
+ */
105
+ export function setValidateErrorLogger(
106
+ func: (log: IValidateErrorLog) => void,
107
+ ): void {
108
+ TypedRoute.setValidateErrorLogger(func);
109
+ }
110
+
111
+ export import IValidateErrorLog = TypedRoute.IValidateErrorLog;
112
+
113
+ /** @internal */
114
+ function Generator(method: "Get" | "Post" | "Put" | "Patch" | "Delete") {
115
+ function route(path?: string | string[]): MethodDecorator;
116
+ function route<T>(
117
+ stringify?: IResponseBodyStringifier<T> | null,
118
+ ): MethodDecorator;
119
+ function route<T>(
120
+ path: string | string[],
121
+ stringify?: IResponseBodyStringifier<T> | null,
122
+ ): MethodDecorator;
123
+
124
+ function route(...args: any[]): MethodDecorator {
125
+ const [path, stringify] = get_path_and_stringify(
126
+ () => TypedRoute.__logger,
127
+ )(`EncryptedRoute.${method}`)(...args);
128
+ return applyDecorators(
129
+ ROUTERS[method](path),
130
+ UseInterceptors(new EncryptedRouteInterceptor(method, stringify)),
131
+ );
132
+ }
133
+ return route;
134
+ }
135
+ }
136
+
137
+ for (const method of [
138
+ typia.json.isStringify,
139
+ typia.json.assertStringify,
140
+ typia.json.validateStringify,
141
+ typia.json.stringify,
142
+ ])
143
+ for (const [key, value] of Object.entries(method))
144
+ for (const deco of [
145
+ EncryptedRoute.Get,
146
+ EncryptedRoute.Delete,
147
+ EncryptedRoute.Post,
148
+ EncryptedRoute.Put,
149
+ EncryptedRoute.Patch,
150
+ ])
151
+ (deco as any)[key] = value;
152
+
153
+ /** @internal */
154
+ class EncryptedRouteInterceptor implements NestInterceptor {
155
+ public constructor(
156
+ private readonly method: string,
157
+ private readonly stringify: (
158
+ input: any,
159
+ method: string,
160
+ path: string,
161
+ ) => string,
162
+ ) {}
163
+
164
+ public intercept(context: ExecutionContext, next: CallHandler) {
165
+ const http: HttpArgumentsHost = context.switchToHttp();
166
+ return next.handle().pipe(
167
+ map((value) => {
168
+ const param:
169
+ | IEncryptionPassword
170
+ | IEncryptionPassword.Closure
171
+ | undefined = Reflect.getMetadata(
172
+ ENCRYPTION_METADATA_KEY,
173
+ context.getClass(),
174
+ );
175
+ if (!param)
176
+ return Error(
177
+ `Error on EncryptedRoute.${this.method}(): no password found.`,
178
+ );
179
+
180
+ const request: express.Request = http.getRequest();
181
+ const headers: Singleton<Record<string, string>> = new Singleton(() =>
182
+ headers_to_object(request.headers),
183
+ );
184
+ const body: string | undefined = this.stringify(
185
+ value,
186
+ request.method,
187
+ request.url,
188
+ );
189
+ const password: IEncryptionPassword =
190
+ typeof param === "function"
191
+ ? param({
192
+ headers: headers.get(),
193
+ body,
194
+ direction: "encode",
195
+ })
196
+ : param;
197
+
198
+ if (body === undefined) return body;
199
+ return AesPkcs5.encrypt(body, password.key, password.iv);
200
+ }),
201
+ catchError((err) => route_error(http.getRequest(), err)),
202
+ );
203
+ }
204
+ }
205
+
206
+ /** @internal */
207
+ const ROUTERS = {
208
+ Get,
209
+ Post,
210
+ Put,
211
+ Patch,
212
+ Delete,
213
+ };
@@ -1,21 +1,21 @@
1
- import { SwaggerCustomizer } from "./SwaggerCustomizer";
2
-
3
- /**
4
- * Human only API marking.
5
- *
6
- * This decorator marks the API for human only, so that LLM function calling
7
- * schema composer excludes the API.
8
- *
9
- * In other words, if you adjust the `@HumanRoute()` decorator to the API, the
10
- * API never participates in the LLM function calling. When calling the
11
- * {@link HttpLlm.application} function, matched {@link IHttpLlmFunction} data
12
- * never be composed.
13
- *
14
- * @author Jeongho Nam - https://github.com/samchon
15
- * @returns Method decorator
16
- */
17
- export function HumanRoute(): MethodDecorator {
18
- return SwaggerCustomizer((props) => {
19
- props.route["x-samchon-human"] = true;
20
- });
21
- }
1
+ import { SwaggerCustomizer } from "./SwaggerCustomizer";
2
+
3
+ /**
4
+ * Human only API marking.
5
+ *
6
+ * This decorator marks the API for human only, so that LLM function calling
7
+ * schema composer excludes the API.
8
+ *
9
+ * In other words, if you adjust the `@HumanRoute()` decorator to the API, the
10
+ * API never participates in the LLM function calling. When calling the
11
+ * {@link HttpLlm.application} function, matched {@link IHttpLlmFunction} data
12
+ * never be composed.
13
+ *
14
+ * @author Jeongho Nam - https://github.com/samchon
15
+ * @returns Method decorator
16
+ */
17
+ export function HumanRoute(): MethodDecorator {
18
+ return SwaggerCustomizer((props) => {
19
+ props.route["x-samchon-human"] = true;
20
+ });
21
+ }