@nestia/core 7.0.0-dev.20250607 → 7.0.0
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/README.md +92 -92
- package/package.json +3 -3
- package/src/adaptors/WebSocketAdaptor.ts +429 -429
- package/src/decorators/DynamicModule.ts +43 -43
- package/src/decorators/EncryptedBody.ts +101 -101
- package/src/decorators/EncryptedController.ts +38 -38
- package/src/decorators/EncryptedModule.ts +100 -100
- package/src/decorators/EncryptedRoute.ts +219 -219
- package/src/decorators/HumanRoute.ts +22 -22
- package/src/decorators/NoTransformConfigurationError.ts +32 -32
- package/src/decorators/PlainBody.ts +79 -79
- package/src/decorators/SwaggerCustomizer.ts +115 -115
- package/src/decorators/SwaggerExample.ts +100 -100
- package/src/decorators/TypedBody.ts +59 -59
- package/src/decorators/TypedException.ts +166 -166
- package/src/decorators/TypedFormData.ts +195 -195
- package/src/decorators/TypedHeaders.ts +64 -64
- package/src/decorators/TypedParam.ts +77 -77
- package/src/decorators/TypedQuery.ts +245 -245
- package/src/decorators/TypedRoute.ts +214 -214
- package/src/decorators/WebSocketRoute.ts +242 -242
- package/src/decorators/internal/EncryptedConstant.ts +4 -4
- package/src/decorators/internal/IWebSocketRouteReflect.ts +23 -23
- package/src/decorators/internal/NoTransformConfigureError.ts +2 -2
- package/src/decorators/internal/get_path_and_querify.ts +108 -108
- package/src/decorators/internal/get_path_and_stringify.ts +122 -122
- package/src/decorators/internal/get_text_body.ts +20 -20
- package/src/decorators/internal/headers_to_object.ts +13 -13
- package/src/decorators/internal/is_request_body_undefined.ts +14 -14
- package/src/decorators/internal/load_controller.ts +49 -49
- package/src/decorators/internal/route_error.ts +45 -45
- package/src/decorators/internal/validate_request_body.ts +74 -74
- package/src/decorators/internal/validate_request_form_data.ts +77 -77
- package/src/decorators/internal/validate_request_headers.ts +86 -86
- package/src/decorators/internal/validate_request_query.ts +74 -74
- package/src/index.ts +5 -5
- package/src/module.ts +22 -22
- package/src/options/INestiaTransformOptions.ts +38 -38
- package/src/options/INestiaTransformProject.ts +8 -8
- 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/programmers/PlainBodyProgrammer.ts +70 -70
- package/src/programmers/TypedBodyProgrammer.ts +142 -142
- package/src/programmers/TypedFormDataBodyProgrammer.ts +118 -118
- package/src/programmers/TypedHeadersProgrammer.ts +63 -63
- package/src/programmers/TypedParamProgrammer.ts +33 -33
- package/src/programmers/TypedQueryBodyProgrammer.ts +112 -112
- package/src/programmers/TypedQueryProgrammer.ts +114 -114
- package/src/programmers/TypedQueryRouteProgrammer.ts +105 -105
- package/src/programmers/TypedRouteProgrammer.ts +94 -94
- package/src/programmers/http/HttpAssertQuerifyProgrammer.ts +72 -72
- package/src/programmers/http/HttpIsQuerifyProgrammer.ts +75 -75
- package/src/programmers/http/HttpQuerifyProgrammer.ts +108 -108
- package/src/programmers/http/HttpValidateQuerifyProgrammer.ts +76 -76
- package/src/programmers/internal/CoreMetadataUtil.ts +21 -21
- package/src/transform.ts +35 -35
- package/src/transformers/FileTransformer.ts +110 -110
- package/src/transformers/MethodTransformer.ts +103 -103
- package/src/transformers/NodeTransformer.ts +23 -23
- package/src/transformers/ParameterDecoratorTransformer.ts +143 -143
- package/src/transformers/ParameterTransformer.ts +57 -57
- package/src/transformers/TypedRouteTransformer.ts +85 -85
- package/src/transformers/WebSocketRouteTransformer.ts +120 -120
- 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 +112 -112
- package/src/utils/Singleton.ts +20 -20
- package/src/utils/SourceFinder.ts +57 -57
- package/src/utils/VersioningStrategy.ts +27 -27
|
@@ -1,219 +1,219 @@
|
|
|
1
|
-
import { AesPkcs5 } from "@nestia/fetcher/lib/AesPkcs5";
|
|
2
|
-
import { IEncryptionPassword } from "@nestia/fetcher/lib/IEncryptionPassword";
|
|
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 encrypts
|
|
32
|
-
* response body data through AES-128/256 encryption. Furthermore, they can boost
|
|
33
|
-
* up JSON string conversion speed about 50x times faster than `class-transformer`,
|
|
34
|
-
* even type safe through [typia](https://github.com/samchon/typia).
|
|
35
|
-
*
|
|
36
|
-
* For reference, if you try to invalid data that is not following the promised
|
|
37
|
-
* type `T`, 500 internal server error would be thrown. Also, as `EncryptedRoute`
|
|
38
|
-
* composes JSON string through `typia.assertStringify<T>()` function, it is not
|
|
39
|
-
* possible to modify response data through interceptors.
|
|
40
|
-
*
|
|
41
|
-
* - AES-128/256
|
|
42
|
-
* - CBC mode
|
|
43
|
-
* - PKCS #5 Padding
|
|
44
|
-
* - Base64 Encoding
|
|
45
|
-
*
|
|
46
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
47
|
-
*/
|
|
48
|
-
export namespace EncryptedRoute {
|
|
49
|
-
/**
|
|
50
|
-
* Encrypted router decorator function for the GET method.
|
|
51
|
-
*
|
|
52
|
-
* @param paths Path(s) of the HTTP request
|
|
53
|
-
* @returns Method decorator
|
|
54
|
-
*/
|
|
55
|
-
export const Get = Generator("Get");
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Encrypted router decorator function for the GET method.
|
|
59
|
-
*
|
|
60
|
-
* @param paths Path(s) of the HTTP request
|
|
61
|
-
* @returns Method decorator
|
|
62
|
-
*/
|
|
63
|
-
export const Post = Generator("Post");
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Encrypted router decorator function for the PATCH method.
|
|
67
|
-
*
|
|
68
|
-
* @param path Path of the HTTP request
|
|
69
|
-
* @returns Method decorator
|
|
70
|
-
*/
|
|
71
|
-
export const Patch = Generator("Patch");
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Encrypted router decorator function for the PUT method.
|
|
75
|
-
*
|
|
76
|
-
* @param path Path of the HTTP request
|
|
77
|
-
* @returns Method decorator
|
|
78
|
-
*/
|
|
79
|
-
export const Put = Generator("Put");
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Encrypted router decorator function for the DELETE method.
|
|
83
|
-
*
|
|
84
|
-
* @param path Path of the HTTP request
|
|
85
|
-
* @returns Method decorator
|
|
86
|
-
*/
|
|
87
|
-
export const Delete = Generator("Delete");
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Set the logger function for the response validation failure.
|
|
91
|
-
*
|
|
92
|
-
* If you've configured the transformation option to `validate.log`
|
|
93
|
-
* in the `tsconfig.json` file, then the error log information of the
|
|
94
|
-
* response validation failure would be logged through this function
|
|
95
|
-
* instead of throwing the 400 bad request error.
|
|
96
|
-
*
|
|
97
|
-
* By the way, be careful. If you've configured the response
|
|
98
|
-
* transformation option to be `validate.log`, client may get wrong
|
|
99
|
-
* response data. Therefore, this way is not recommended in the common
|
|
100
|
-
* backend server case.
|
|
101
|
-
*
|
|
102
|
-
* @param func Logger function
|
|
103
|
-
* @default console.log
|
|
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
|
-
/**
|
|
114
|
-
* @internal
|
|
115
|
-
*/
|
|
116
|
-
function Generator(method: "Get" | "Post" | "Put" | "Patch" | "Delete") {
|
|
117
|
-
function route(path?: string | string[]): MethodDecorator;
|
|
118
|
-
function route<T>(
|
|
119
|
-
stringify?: IResponseBodyStringifier<T> | null,
|
|
120
|
-
): MethodDecorator;
|
|
121
|
-
function route<T>(
|
|
122
|
-
path: string | string[],
|
|
123
|
-
stringify?: IResponseBodyStringifier<T> | null,
|
|
124
|
-
): MethodDecorator;
|
|
125
|
-
|
|
126
|
-
function route(...args: any[]): MethodDecorator {
|
|
127
|
-
const [path, stringify] = get_path_and_stringify(
|
|
128
|
-
() => TypedRoute.__logger,
|
|
129
|
-
)(`EncryptedRoute.${method}`)(...args);
|
|
130
|
-
return applyDecorators(
|
|
131
|
-
ROUTERS[method](path),
|
|
132
|
-
UseInterceptors(new EncryptedRouteInterceptor(method, stringify)),
|
|
133
|
-
);
|
|
134
|
-
}
|
|
135
|
-
return route;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
for (const method of [
|
|
140
|
-
typia.json.isStringify,
|
|
141
|
-
typia.json.assertStringify,
|
|
142
|
-
typia.json.validateStringify,
|
|
143
|
-
typia.json.stringify,
|
|
144
|
-
])
|
|
145
|
-
for (const [key, value] of Object.entries(method))
|
|
146
|
-
for (const deco of [
|
|
147
|
-
EncryptedRoute.Get,
|
|
148
|
-
EncryptedRoute.Delete,
|
|
149
|
-
EncryptedRoute.Post,
|
|
150
|
-
EncryptedRoute.Put,
|
|
151
|
-
EncryptedRoute.Patch,
|
|
152
|
-
])
|
|
153
|
-
(deco as any)[key] = value;
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* @internal
|
|
157
|
-
*/
|
|
158
|
-
class EncryptedRouteInterceptor implements NestInterceptor {
|
|
159
|
-
public constructor(
|
|
160
|
-
private readonly method: string,
|
|
161
|
-
private readonly stringify: (
|
|
162
|
-
input: any,
|
|
163
|
-
method: string,
|
|
164
|
-
path: string,
|
|
165
|
-
) => string,
|
|
166
|
-
) {}
|
|
167
|
-
|
|
168
|
-
public intercept(context: ExecutionContext, next: CallHandler) {
|
|
169
|
-
const http: HttpArgumentsHost = context.switchToHttp();
|
|
170
|
-
return next.handle().pipe(
|
|
171
|
-
map((value) => {
|
|
172
|
-
const param:
|
|
173
|
-
| IEncryptionPassword
|
|
174
|
-
| IEncryptionPassword.Closure
|
|
175
|
-
| undefined = Reflect.getMetadata(
|
|
176
|
-
ENCRYPTION_METADATA_KEY,
|
|
177
|
-
context.getClass(),
|
|
178
|
-
);
|
|
179
|
-
if (!param)
|
|
180
|
-
return Error(
|
|
181
|
-
`Error on EncryptedRoute.${this.method}(): no password found.`,
|
|
182
|
-
);
|
|
183
|
-
|
|
184
|
-
const request: express.Request = http.getRequest();
|
|
185
|
-
const headers: Singleton<Record<string, string>> = new Singleton(() =>
|
|
186
|
-
headers_to_object(request.headers),
|
|
187
|
-
);
|
|
188
|
-
const body: string | undefined = this.stringify(
|
|
189
|
-
value,
|
|
190
|
-
request.method,
|
|
191
|
-
request.url,
|
|
192
|
-
);
|
|
193
|
-
const password: IEncryptionPassword =
|
|
194
|
-
typeof param === "function"
|
|
195
|
-
? param({
|
|
196
|
-
headers: headers.get(),
|
|
197
|
-
body,
|
|
198
|
-
direction: "encode",
|
|
199
|
-
})
|
|
200
|
-
: param;
|
|
201
|
-
|
|
202
|
-
if (body === undefined) return body;
|
|
203
|
-
return AesPkcs5.encrypt(body, password.key, password.iv);
|
|
204
|
-
}),
|
|
205
|
-
catchError((err) => route_error(http.getRequest(), err)),
|
|
206
|
-
);
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
/**
|
|
211
|
-
* @internal
|
|
212
|
-
*/
|
|
213
|
-
const ROUTERS = {
|
|
214
|
-
Get,
|
|
215
|
-
Post,
|
|
216
|
-
Put,
|
|
217
|
-
Patch,
|
|
218
|
-
Delete,
|
|
219
|
-
};
|
|
1
|
+
import { AesPkcs5 } from "@nestia/fetcher/lib/AesPkcs5";
|
|
2
|
+
import { IEncryptionPassword } from "@nestia/fetcher/lib/IEncryptionPassword";
|
|
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 encrypts
|
|
32
|
+
* response body data through AES-128/256 encryption. Furthermore, they can boost
|
|
33
|
+
* up JSON string conversion speed about 50x times faster than `class-transformer`,
|
|
34
|
+
* even type safe through [typia](https://github.com/samchon/typia).
|
|
35
|
+
*
|
|
36
|
+
* For reference, if you try to invalid data that is not following the promised
|
|
37
|
+
* type `T`, 500 internal server error would be thrown. Also, as `EncryptedRoute`
|
|
38
|
+
* composes JSON string through `typia.assertStringify<T>()` function, it is not
|
|
39
|
+
* possible to modify response data through interceptors.
|
|
40
|
+
*
|
|
41
|
+
* - AES-128/256
|
|
42
|
+
* - CBC mode
|
|
43
|
+
* - PKCS #5 Padding
|
|
44
|
+
* - Base64 Encoding
|
|
45
|
+
*
|
|
46
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
47
|
+
*/
|
|
48
|
+
export namespace EncryptedRoute {
|
|
49
|
+
/**
|
|
50
|
+
* Encrypted router decorator function for the GET method.
|
|
51
|
+
*
|
|
52
|
+
* @param paths Path(s) of the HTTP request
|
|
53
|
+
* @returns Method decorator
|
|
54
|
+
*/
|
|
55
|
+
export const Get = Generator("Get");
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Encrypted router decorator function for the GET method.
|
|
59
|
+
*
|
|
60
|
+
* @param paths Path(s) of the HTTP request
|
|
61
|
+
* @returns Method decorator
|
|
62
|
+
*/
|
|
63
|
+
export const Post = Generator("Post");
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Encrypted router decorator function for the PATCH method.
|
|
67
|
+
*
|
|
68
|
+
* @param path Path of the HTTP request
|
|
69
|
+
* @returns Method decorator
|
|
70
|
+
*/
|
|
71
|
+
export const Patch = Generator("Patch");
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Encrypted router decorator function for the PUT method.
|
|
75
|
+
*
|
|
76
|
+
* @param path Path of the HTTP request
|
|
77
|
+
* @returns Method decorator
|
|
78
|
+
*/
|
|
79
|
+
export const Put = Generator("Put");
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Encrypted router decorator function for the DELETE method.
|
|
83
|
+
*
|
|
84
|
+
* @param path Path of the HTTP request
|
|
85
|
+
* @returns Method decorator
|
|
86
|
+
*/
|
|
87
|
+
export const Delete = Generator("Delete");
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Set the logger function for the response validation failure.
|
|
91
|
+
*
|
|
92
|
+
* If you've configured the transformation option to `validate.log`
|
|
93
|
+
* in the `tsconfig.json` file, then the error log information of the
|
|
94
|
+
* response validation failure would be logged through this function
|
|
95
|
+
* instead of throwing the 400 bad request error.
|
|
96
|
+
*
|
|
97
|
+
* By the way, be careful. If you've configured the response
|
|
98
|
+
* transformation option to be `validate.log`, client may get wrong
|
|
99
|
+
* response data. Therefore, this way is not recommended in the common
|
|
100
|
+
* backend server case.
|
|
101
|
+
*
|
|
102
|
+
* @param func Logger function
|
|
103
|
+
* @default console.log
|
|
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
|
+
/**
|
|
114
|
+
* @internal
|
|
115
|
+
*/
|
|
116
|
+
function Generator(method: "Get" | "Post" | "Put" | "Patch" | "Delete") {
|
|
117
|
+
function route(path?: string | string[]): MethodDecorator;
|
|
118
|
+
function route<T>(
|
|
119
|
+
stringify?: IResponseBodyStringifier<T> | null,
|
|
120
|
+
): MethodDecorator;
|
|
121
|
+
function route<T>(
|
|
122
|
+
path: string | string[],
|
|
123
|
+
stringify?: IResponseBodyStringifier<T> | null,
|
|
124
|
+
): MethodDecorator;
|
|
125
|
+
|
|
126
|
+
function route(...args: any[]): MethodDecorator {
|
|
127
|
+
const [path, stringify] = get_path_and_stringify(
|
|
128
|
+
() => TypedRoute.__logger,
|
|
129
|
+
)(`EncryptedRoute.${method}`)(...args);
|
|
130
|
+
return applyDecorators(
|
|
131
|
+
ROUTERS[method](path),
|
|
132
|
+
UseInterceptors(new EncryptedRouteInterceptor(method, stringify)),
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
return route;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
for (const method of [
|
|
140
|
+
typia.json.isStringify,
|
|
141
|
+
typia.json.assertStringify,
|
|
142
|
+
typia.json.validateStringify,
|
|
143
|
+
typia.json.stringify,
|
|
144
|
+
])
|
|
145
|
+
for (const [key, value] of Object.entries(method))
|
|
146
|
+
for (const deco of [
|
|
147
|
+
EncryptedRoute.Get,
|
|
148
|
+
EncryptedRoute.Delete,
|
|
149
|
+
EncryptedRoute.Post,
|
|
150
|
+
EncryptedRoute.Put,
|
|
151
|
+
EncryptedRoute.Patch,
|
|
152
|
+
])
|
|
153
|
+
(deco as any)[key] = value;
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* @internal
|
|
157
|
+
*/
|
|
158
|
+
class EncryptedRouteInterceptor implements NestInterceptor {
|
|
159
|
+
public constructor(
|
|
160
|
+
private readonly method: string,
|
|
161
|
+
private readonly stringify: (
|
|
162
|
+
input: any,
|
|
163
|
+
method: string,
|
|
164
|
+
path: string,
|
|
165
|
+
) => string,
|
|
166
|
+
) {}
|
|
167
|
+
|
|
168
|
+
public intercept(context: ExecutionContext, next: CallHandler) {
|
|
169
|
+
const http: HttpArgumentsHost = context.switchToHttp();
|
|
170
|
+
return next.handle().pipe(
|
|
171
|
+
map((value) => {
|
|
172
|
+
const param:
|
|
173
|
+
| IEncryptionPassword
|
|
174
|
+
| IEncryptionPassword.Closure
|
|
175
|
+
| undefined = Reflect.getMetadata(
|
|
176
|
+
ENCRYPTION_METADATA_KEY,
|
|
177
|
+
context.getClass(),
|
|
178
|
+
);
|
|
179
|
+
if (!param)
|
|
180
|
+
return Error(
|
|
181
|
+
`Error on EncryptedRoute.${this.method}(): no password found.`,
|
|
182
|
+
);
|
|
183
|
+
|
|
184
|
+
const request: express.Request = http.getRequest();
|
|
185
|
+
const headers: Singleton<Record<string, string>> = new Singleton(() =>
|
|
186
|
+
headers_to_object(request.headers),
|
|
187
|
+
);
|
|
188
|
+
const body: string | undefined = this.stringify(
|
|
189
|
+
value,
|
|
190
|
+
request.method,
|
|
191
|
+
request.url,
|
|
192
|
+
);
|
|
193
|
+
const password: IEncryptionPassword =
|
|
194
|
+
typeof param === "function"
|
|
195
|
+
? param({
|
|
196
|
+
headers: headers.get(),
|
|
197
|
+
body,
|
|
198
|
+
direction: "encode",
|
|
199
|
+
})
|
|
200
|
+
: param;
|
|
201
|
+
|
|
202
|
+
if (body === undefined) return body;
|
|
203
|
+
return AesPkcs5.encrypt(body, password.key, password.iv);
|
|
204
|
+
}),
|
|
205
|
+
catchError((err) => route_error(http.getRequest(), err)),
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* @internal
|
|
212
|
+
*/
|
|
213
|
+
const ROUTERS = {
|
|
214
|
+
Get,
|
|
215
|
+
Post,
|
|
216
|
+
Put,
|
|
217
|
+
Patch,
|
|
218
|
+
Delete,
|
|
219
|
+
};
|
|
@@ -1,22 +1,22 @@
|
|
|
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 (of [`@samchon/openapi`](https://github.com/samchon/openapi))
|
|
8
|
-
* excludes the API.
|
|
9
|
-
*
|
|
10
|
-
* In other words, if you adjust the `@HumanRoute()` decorator to the API,
|
|
11
|
-
* the API never participates in the LLM function calling. When calling the
|
|
12
|
-
* {@link HttpLlm.application} function, matched {@link IHttpLlmFunction} data
|
|
13
|
-
* never be composed.
|
|
14
|
-
*
|
|
15
|
-
* @returns Method decorator
|
|
16
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
17
|
-
*/
|
|
18
|
-
export function HumanRoute(): MethodDecorator {
|
|
19
|
-
return SwaggerCustomizer((props) => {
|
|
20
|
-
props.route["x-samchon-human"] = true;
|
|
21
|
-
});
|
|
22
|
-
}
|
|
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 (of [`@samchon/openapi`](https://github.com/samchon/openapi))
|
|
8
|
+
* excludes the API.
|
|
9
|
+
*
|
|
10
|
+
* In other words, if you adjust the `@HumanRoute()` decorator to the API,
|
|
11
|
+
* the API never participates in the LLM function calling. When calling the
|
|
12
|
+
* {@link HttpLlm.application} function, matched {@link IHttpLlmFunction} data
|
|
13
|
+
* never be composed.
|
|
14
|
+
*
|
|
15
|
+
* @returns Method decorator
|
|
16
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
17
|
+
*/
|
|
18
|
+
export function HumanRoute(): MethodDecorator {
|
|
19
|
+
return SwaggerCustomizer((props) => {
|
|
20
|
+
props.route["x-samchon-human"] = true;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
export function NoTransformConfigurationError(method: string) {
|
|
2
|
-
if (NoTransformConfigurationError.throws === true)
|
|
3
|
-
throw new Error(
|
|
4
|
-
[
|
|
5
|
-
`Error on nestia.core.${method}(): no transform has been configured.`,
|
|
6
|
-
`Run "npx typia setup" command, or check if you're using non-standard TypeScript compiler like Babel or SWC.`,
|
|
7
|
-
`Otherwise you're running "npx nestia sdk/swagger" or similar, run "npx tsc" command to find the reason why.`,
|
|
8
|
-
].join(" "),
|
|
9
|
-
);
|
|
10
|
-
return undefined as never;
|
|
11
|
-
}
|
|
12
|
-
export namespace NoTransformConfigurationError {
|
|
13
|
-
/**
|
|
14
|
-
* Whether to throw an error or not.
|
|
15
|
-
*
|
|
16
|
-
* If you set this value to `false`, {@link NoTransformConfigurationError} will
|
|
17
|
-
* not throw an error.
|
|
18
|
-
*
|
|
19
|
-
* Even if you've not configured the plugin transformer of `tsconfig.json` file,
|
|
20
|
-
* the error will not be thrown and the program will be continued. Instead, every
|
|
21
|
-
* validations and assertions will be skipped and the value will be returned as it is.
|
|
22
|
-
* Furthermore, unexpected behaviors may occur.
|
|
23
|
-
*
|
|
24
|
-
* Therefore, it is not recommended to set this value to `false` in production
|
|
25
|
-
* environment. Configure this value to be `false` only when you're debugging or testing.
|
|
26
|
-
*
|
|
27
|
-
* By the way, if you hope the `false` value to be set, you have to do it before the first.
|
|
28
|
-
* If you configure the `false` value after the `@nestia/core` decorator functions are
|
|
29
|
-
* composed, the value will not be applied and the error will be thrown.
|
|
30
|
-
*/
|
|
31
|
-
export let throws = true;
|
|
32
|
-
}
|
|
1
|
+
export function NoTransformConfigurationError(method: string) {
|
|
2
|
+
if (NoTransformConfigurationError.throws === true)
|
|
3
|
+
throw new Error(
|
|
4
|
+
[
|
|
5
|
+
`Error on nestia.core.${method}(): no transform has been configured.`,
|
|
6
|
+
`Run "npx typia setup" command, or check if you're using non-standard TypeScript compiler like Babel or SWC.`,
|
|
7
|
+
`Otherwise you're running "npx nestia sdk/swagger" or similar, run "npx tsc" command to find the reason why.`,
|
|
8
|
+
].join(" "),
|
|
9
|
+
);
|
|
10
|
+
return undefined as never;
|
|
11
|
+
}
|
|
12
|
+
export namespace NoTransformConfigurationError {
|
|
13
|
+
/**
|
|
14
|
+
* Whether to throw an error or not.
|
|
15
|
+
*
|
|
16
|
+
* If you set this value to `false`, {@link NoTransformConfigurationError} will
|
|
17
|
+
* not throw an error.
|
|
18
|
+
*
|
|
19
|
+
* Even if you've not configured the plugin transformer of `tsconfig.json` file,
|
|
20
|
+
* the error will not be thrown and the program will be continued. Instead, every
|
|
21
|
+
* validations and assertions will be skipped and the value will be returned as it is.
|
|
22
|
+
* Furthermore, unexpected behaviors may occur.
|
|
23
|
+
*
|
|
24
|
+
* Therefore, it is not recommended to set this value to `false` in production
|
|
25
|
+
* environment. Configure this value to be `false` only when you're debugging or testing.
|
|
26
|
+
*
|
|
27
|
+
* By the way, if you hope the `false` value to be set, you have to do it before the first.
|
|
28
|
+
* If you configure the `false` value after the `@nestia/core` decorator functions are
|
|
29
|
+
* composed, the value will not be applied and the error will be thrown.
|
|
30
|
+
*/
|
|
31
|
+
export let throws = true;
|
|
32
|
+
}
|