@nestia/core 12.0.0-dev.20260601.1 → 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.
- package/LICENSE +21 -21
- package/MIGRATION.md +169 -169
- package/README.md +93 -93
- package/lib/adaptors/McpAdaptor.d.ts +75 -0
- package/lib/adaptors/McpAdaptor.js +257 -0
- package/lib/adaptors/McpAdaptor.js.map +1 -0
- package/lib/adaptors/WebSocketAdaptor.js +4 -4
- package/lib/adaptors/WebSocketAdaptor.js.map +1 -1
- package/lib/decorators/McpRoute.d.ts +69 -0
- package/lib/decorators/McpRoute.js +58 -0
- package/lib/decorators/McpRoute.js.map +1 -0
- package/lib/decorators/TypedParam.js +4 -4
- package/lib/decorators/TypedParam.js.map +1 -1
- package/lib/decorators/TypedRoute.js +1 -1
- package/lib/decorators/TypedRoute.js.map +1 -1
- package/lib/decorators/internal/IMcpRouteReflect.d.ts +2 -0
- package/lib/decorators/internal/IMcpRouteReflect.js +3 -0
- package/lib/decorators/internal/IMcpRouteReflect.js.map +1 -0
- package/lib/decorators/internal/get_path_and_querify.js +4 -4
- package/lib/decorators/internal/get_path_and_querify.js.map +1 -1
- package/lib/decorators/internal/get_path_and_stringify.js +4 -4
- package/lib/decorators/internal/get_path_and_stringify.js.map +1 -1
- package/lib/decorators/internal/load_controller.js +34 -65
- package/lib/decorators/internal/load_controller.js.map +1 -1
- package/lib/decorators/internal/validate_request_body.js +4 -4
- package/lib/decorators/internal/validate_request_body.js.map +1 -1
- package/lib/decorators/internal/validate_request_form_data.js +4 -4
- package/lib/decorators/internal/validate_request_form_data.js.map +1 -1
- package/lib/decorators/internal/validate_request_headers.js +4 -4
- package/lib/decorators/internal/validate_request_headers.js.map +1 -1
- package/lib/decorators/internal/validate_request_query.js +4 -4
- package/lib/decorators/internal/validate_request_query.js.map +1 -1
- package/lib/module.d.ts +2 -0
- package/lib/module.js +2 -0
- package/lib/module.js.map +1 -1
- package/native/cmd/ttsc-nestia/main.go +11 -11
- package/native/go.mod +32 -32
- package/native/go.sum +54 -54
- package/native/plugin/plan.go +102 -102
- package/native/transform/ast.go +32 -32
- package/native/transform/build.go +380 -444
- package/native/transform/cleanup.go +408 -408
- package/native/transform/contributor.go +97 -68
- package/native/transform/core_querify.go +231 -227
- package/native/transform/core_transform.go +1996 -1713
- package/native/transform/core_websocket.go +115 -115
- package/native/transform/exports.go +13 -13
- package/native/transform/mcp_transform.go +414 -0
- package/native/transform/node_transform.go +357 -0
- package/native/transform/path_rewrite.go +285 -285
- package/native/transform/printer.go +244 -244
- package/native/transform/rewrite.go +668 -662
- package/native/transform/run.go +73 -73
- package/native/transform/transform.go +336 -403
- package/native/transform/typia_fast.go +352 -326
- package/native/transform/typia_replacement.go +24 -24
- package/native/transform.cjs +43 -43
- package/package.json +15 -8
- package/src/adaptors/McpAdaptor.ts +276 -0
- package/src/adaptors/WebSocketAdaptor.ts +429 -429
- package/src/decorators/DynamicModule.ts +44 -44
- package/src/decorators/EncryptedBody.ts +97 -97
- package/src/decorators/EncryptedController.ts +40 -40
- package/src/decorators/EncryptedModule.ts +98 -98
- package/src/decorators/EncryptedRoute.ts +213 -213
- package/src/decorators/HumanRoute.ts +21 -21
- package/src/decorators/McpRoute.ts +154 -0
- package/src/decorators/NoTransformConfigurationError.ts +40 -40
- package/src/decorators/PlainBody.ts +76 -76
- package/src/decorators/SwaggerCustomizer.ts +97 -97
- package/src/decorators/SwaggerExample.ts +180 -180
- package/src/decorators/TypedBody.ts +57 -57
- package/src/decorators/TypedException.ts +147 -147
- package/src/decorators/TypedFormData.ts +187 -187
- package/src/decorators/TypedHeaders.ts +66 -66
- package/src/decorators/TypedParam.ts +77 -77
- package/src/decorators/TypedQuery.ts +234 -234
- package/src/decorators/TypedRoute.ts +198 -196
- package/src/decorators/WebSocketRoute.ts +242 -242
- package/src/decorators/doNotThrowTransformError.ts +5 -5
- package/src/decorators/internal/EncryptedConstant.ts +2 -2
- package/src/decorators/internal/IMcpRouteReflect.ts +40 -0
- package/src/decorators/internal/IWebSocketRouteReflect.ts +23 -23
- package/src/decorators/internal/get_path_and_querify.ts +94 -94
- package/src/decorators/internal/get_path_and_stringify.ts +110 -110
- package/src/decorators/internal/get_text_body.ts +16 -16
- package/src/decorators/internal/headers_to_object.ts +11 -11
- package/src/decorators/internal/is_request_body_undefined.ts +12 -12
- package/src/decorators/internal/load_controller.ts +91 -76
- package/src/decorators/internal/route_error.ts +43 -43
- package/src/decorators/internal/validate_request_body.ts +64 -64
- package/src/decorators/internal/validate_request_form_data.ts +67 -67
- package/src/decorators/internal/validate_request_headers.ts +76 -76
- package/src/decorators/internal/validate_request_query.ts +83 -83
- package/src/index.ts +5 -5
- package/src/module.ts +25 -23
- package/src/options/IRequestBodyValidator.ts +20 -20
- package/src/options/IRequestFormDataProps.ts +27 -27
- 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 +30 -30
- package/src/transform.ts +101 -101
- package/src/typings/Creator.ts +3 -3
- package/src/typings/get-function-location.d.ts +7 -7
- package/src/utils/ArrayUtil.ts +7 -7
- package/src/utils/ExceptionManager.ts +115 -115
- package/src/utils/Singleton.ts +16 -16
- package/src/utils/SourceFinder.ts +54 -54
- package/src/utils/VersioningStrategy.ts +27 -27
- package/native/transform/cleanup_test.go +0 -76
- package/native/transform/commonjs_import_alias_test.go +0 -49
- package/native/transform/core_dispatch_test.go +0 -127
- package/native/transform/path_rewrite_test.go +0 -243
- package/native/transform/rewrite_test.go +0 -118
- package/native/transform/rewrite_unique_base_test.go +0 -48
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { IRequestBodyValidator } from "../options/IRequestBodyValidator";
|
|
2
|
+
import { IMcpRouteReflect } from "./internal/IMcpRouteReflect";
|
|
3
|
+
import { validate_request_body } from "./internal/validate_request_body";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* MCP (Model Context Protocol) route decorator.
|
|
7
|
+
*
|
|
8
|
+
* `@McpRoute()` marks a controller method as a callable MCP tool. When the
|
|
9
|
+
* application bootstraps, every method annotated with this decorator is
|
|
10
|
+
* registered on the MCP server built by {@link McpAdaptor.upgrade}, making it
|
|
11
|
+
* reachable by LLM clients through the standard Streamable HTTP transport.
|
|
12
|
+
*
|
|
13
|
+
* The public form takes only the tool's `name` (string). Human-readable
|
|
14
|
+
* `description` and `title` are read from the method's JSDoc:
|
|
15
|
+
*
|
|
16
|
+
* - `description`: the JSDoc comment body.
|
|
17
|
+
* - `title`: the value of an optional `@title` JSDoc tag.
|
|
18
|
+
*
|
|
19
|
+
* For type-safe tool inputs, decorate exactly one parameter of the method with
|
|
20
|
+
* {@link McpRoute.Params}. The parameter type `T` is analyzed at compile time by
|
|
21
|
+
* the nestia transformer, which generates both a runtime validator and the JSON
|
|
22
|
+
* Schema attached to `inputSchema` in `tools/list` responses.
|
|
23
|
+
*
|
|
24
|
+
* For the MCP endpoint to actually be served, call {@link McpAdaptor.upgrade} on
|
|
25
|
+
* the {@link INestApplication} instance at bootstrap. The decorator alone only
|
|
26
|
+
* stores reflection metadata.
|
|
27
|
+
*
|
|
28
|
+
* @author wildduck - https://github.com/wildduck2
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* import core from "@nestia/core";
|
|
32
|
+
*
|
|
33
|
+
* @Controller()
|
|
34
|
+
* export class WeatherController {
|
|
35
|
+
* /**
|
|
36
|
+
* * Return current weather for a city.
|
|
37
|
+
* *
|
|
38
|
+
* * @title Get weather
|
|
39
|
+
* *\/
|
|
40
|
+
* @core.McpRoute("get_weather")
|
|
41
|
+
* public async get(
|
|
42
|
+
* @core.McpRoute.Params() params: { city: string },
|
|
43
|
+
* ): Promise<{ temp: number }> {
|
|
44
|
+
* return { temp: 22 };
|
|
45
|
+
* }
|
|
46
|
+
* }
|
|
47
|
+
* ```;
|
|
48
|
+
*
|
|
49
|
+
* @param name Unique tool identifier exposed to MCP clients via `tools/list`.
|
|
50
|
+
* @returns Method decorator.
|
|
51
|
+
*/
|
|
52
|
+
export function McpRoute(name: string): MethodDecorator;
|
|
53
|
+
|
|
54
|
+
/** @internal */
|
|
55
|
+
export function McpRoute(config: McpRoute.IConfig): MethodDecorator;
|
|
56
|
+
|
|
57
|
+
export function McpRoute(input: string | McpRoute.IConfig): MethodDecorator {
|
|
58
|
+
const config: McpRoute.IConfig =
|
|
59
|
+
typeof input === "string" ? { name: input } : input;
|
|
60
|
+
return function McpRoute(
|
|
61
|
+
_target: Object,
|
|
62
|
+
_propertyKey: string | symbol,
|
|
63
|
+
descriptor: TypedPropertyDescriptor<any>,
|
|
64
|
+
): TypedPropertyDescriptor<any> {
|
|
65
|
+
Reflect.defineMetadata(
|
|
66
|
+
"nestia/McpRoute",
|
|
67
|
+
{
|
|
68
|
+
name: config.name,
|
|
69
|
+
title: config.title,
|
|
70
|
+
description: config.description,
|
|
71
|
+
inputSchema: config.inputSchema ?? { type: "object", properties: {} },
|
|
72
|
+
outputSchema: config.outputSchema,
|
|
73
|
+
annotations: config.annotations,
|
|
74
|
+
} satisfies IMcpRouteReflect,
|
|
75
|
+
descriptor.value,
|
|
76
|
+
);
|
|
77
|
+
return descriptor;
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export namespace McpRoute {
|
|
82
|
+
/**
|
|
83
|
+
* Configuration object emitted by the nestia transformer at compile time.
|
|
84
|
+
*
|
|
85
|
+
* Users call `@McpRoute("name")`; the transformer rewrites the call to
|
|
86
|
+
* `@McpRoute({ name, description, title, inputSchema, ... })` after parsing
|
|
87
|
+
* method JSDoc and analyzing the `@McpRoute.Params<T>()` parameter type.
|
|
88
|
+
*
|
|
89
|
+
* @internal
|
|
90
|
+
*/
|
|
91
|
+
export interface IConfig {
|
|
92
|
+
name: string;
|
|
93
|
+
title?: string;
|
|
94
|
+
description?: string;
|
|
95
|
+
inputSchema?: object;
|
|
96
|
+
outputSchema?: object;
|
|
97
|
+
annotations?: IMcpRouteReflect["annotations"];
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Parameter decorator for an MCP tool's input arguments.
|
|
102
|
+
*
|
|
103
|
+
* `@McpRoute.Params<T>()` validates the `arguments` object from a
|
|
104
|
+
* `tools/call` request against the TypeScript type `T` using typia. A failed
|
|
105
|
+
* validation surfaces to the client as a JSON-RPC `-32602` (`InvalidParams`)
|
|
106
|
+
* error with structured diagnostics, giving the LLM precise feedback to
|
|
107
|
+
* self-correct.
|
|
108
|
+
*
|
|
109
|
+
* MCP tools accept exactly one arguments object; applying this decorator more
|
|
110
|
+
* than once on a single method is a compile-time error. The decorated type
|
|
111
|
+
* `T` must be an object type without dynamic properties.
|
|
112
|
+
*
|
|
113
|
+
* @author wildduck - https://github.com/wildduck2
|
|
114
|
+
* @param validator Optional custom validator. Default is `typia.assert()`.
|
|
115
|
+
* @returns Parameter decorator.
|
|
116
|
+
*/
|
|
117
|
+
export function Params<T>(
|
|
118
|
+
validator?: IRequestBodyValidator<T>,
|
|
119
|
+
): ParameterDecorator {
|
|
120
|
+
const validate = validate_request_body("McpRoute.Params")(validator);
|
|
121
|
+
return function McpRouteParams(
|
|
122
|
+
target: Object,
|
|
123
|
+
propertyKey: string | symbol | undefined,
|
|
124
|
+
parameterIndex: number,
|
|
125
|
+
) {
|
|
126
|
+
emplace(target, propertyKey ?? "", {
|
|
127
|
+
category: "params",
|
|
128
|
+
index: parameterIndex,
|
|
129
|
+
validate,
|
|
130
|
+
});
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** @internal */
|
|
135
|
+
const emplace = (
|
|
136
|
+
target: Object,
|
|
137
|
+
propertyKey: string | symbol,
|
|
138
|
+
value: IMcpRouteReflect.IArgument,
|
|
139
|
+
) => {
|
|
140
|
+
const array: IMcpRouteReflect.IArgument[] | undefined = Reflect.getMetadata(
|
|
141
|
+
"nestia/McpRoute/Parameters",
|
|
142
|
+
target,
|
|
143
|
+
propertyKey,
|
|
144
|
+
);
|
|
145
|
+
if (array !== undefined) array.push(value);
|
|
146
|
+
else
|
|
147
|
+
Reflect.defineMetadata(
|
|
148
|
+
"nestia/McpRoute/Parameters",
|
|
149
|
+
[value],
|
|
150
|
+
target,
|
|
151
|
+
propertyKey,
|
|
152
|
+
);
|
|
153
|
+
};
|
|
154
|
+
}
|