@nestia/core 11.0.0-dev.20260313-5 → 11.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.
Files changed (60) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +93 -93
  3. package/lib/decorators/NoTransformConfigurationError.d.ts +1 -24
  4. package/lib/decorators/NoTransformConfigurationError.js +2 -0
  5. package/lib/decorators/NoTransformConfigurationError.js.map +1 -1
  6. package/lib/decorators/doNotThrowTransformError.d.ts +1 -0
  7. package/lib/decorators/doNotThrowTransformError.js +9 -0
  8. package/lib/decorators/doNotThrowTransformError.js.map +1 -0
  9. package/lib/module.d.ts +1 -1
  10. package/lib/module.js +1 -1
  11. package/lib/module.js.map +1 -1
  12. package/lib/options/INestiaTransformOptions.d.ts +1 -1
  13. package/lib/programmers/PlainBodyProgrammer.js +1 -1
  14. package/lib/programmers/PlainBodyProgrammer.js.map +1 -1
  15. package/lib/programmers/TypedBodyProgrammer.js +6 -3
  16. package/lib/programmers/TypedBodyProgrammer.js.map +1 -1
  17. package/lib/programmers/TypedQueryBodyProgrammer.js +9 -4
  18. package/lib/programmers/TypedQueryBodyProgrammer.js.map +1 -1
  19. package/lib/programmers/TypedQueryProgrammer.js +9 -4
  20. package/lib/programmers/TypedQueryProgrammer.js.map +1 -1
  21. package/lib/programmers/TypedQueryRouteProgrammer.js +14 -8
  22. package/lib/programmers/TypedQueryRouteProgrammer.js.map +1 -1
  23. package/lib/programmers/TypedRouteProgrammer.js +11 -6
  24. package/lib/programmers/TypedRouteProgrammer.js.map +1 -1
  25. package/package.json +8 -8
  26. package/src/adaptors/WebSocketAdaptor.ts +429 -429
  27. package/src/decorators/EncryptedBody.ts +96 -96
  28. package/src/decorators/EncryptedController.ts +40 -40
  29. package/src/decorators/EncryptedModule.ts +98 -98
  30. package/src/decorators/EncryptedRoute.ts +212 -212
  31. package/src/decorators/HumanRoute.ts +21 -21
  32. package/src/decorators/NoTransformConfigurationError.ts +37 -34
  33. package/src/decorators/SwaggerCustomizer.ts +97 -97
  34. package/src/decorators/TypedFormData.ts +187 -187
  35. package/src/decorators/TypedRoute.ts +196 -196
  36. package/src/decorators/doNotThrowTransformError.ts +5 -0
  37. package/src/decorators/internal/headers_to_object.ts +11 -11
  38. package/src/module.ts +23 -23
  39. package/src/options/INestiaTransformOptions.ts +34 -34
  40. package/src/options/INestiaTransformProject.ts +10 -10
  41. package/src/programmers/PlainBodyProgrammer.ts +72 -72
  42. package/src/programmers/TypedBodyProgrammer.ts +148 -144
  43. package/src/programmers/TypedFormDataBodyProgrammer.ts +118 -118
  44. package/src/programmers/TypedHeadersProgrammer.ts +65 -65
  45. package/src/programmers/TypedParamProgrammer.ts +33 -33
  46. package/src/programmers/TypedQueryBodyProgrammer.ts +113 -111
  47. package/src/programmers/TypedQueryProgrammer.ts +115 -113
  48. package/src/programmers/TypedQueryRouteProgrammer.ts +107 -104
  49. package/src/programmers/TypedRouteProgrammer.ts +103 -96
  50. package/src/programmers/http/HttpAssertQuerifyProgrammer.ts +74 -74
  51. package/src/programmers/http/HttpIsQuerifyProgrammer.ts +77 -77
  52. package/src/programmers/http/HttpQuerifyProgrammer.ts +110 -110
  53. package/src/programmers/http/HttpValidateQuerifyProgrammer.ts +78 -78
  54. package/src/programmers/internal/CoreMetadataUtil.ts +21 -21
  55. package/src/transform.ts +35 -35
  56. package/src/transformers/FileTransformer.ts +109 -109
  57. package/src/transformers/MethodTransformer.ts +103 -103
  58. package/src/transformers/ParameterDecoratorTransformer.ts +143 -143
  59. package/src/transformers/TypedRouteTransformer.ts +85 -85
  60. package/src/transformers/WebSocketRouteTransformer.ts +120 -120
@@ -1,212 +1,212 @@
1
- import { AesPkcs5, IEncryptionPassword } from "@nestia/fetcher";
2
- import {
3
- CallHandler,
4
- Delete,
5
- ExecutionContext,
6
- Get,
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 express from "express";
16
- import { catchError, map } from "rxjs/operators";
17
- import typia from "typia";
18
-
19
- import { IResponseBodyStringifier } from "../options/IResponseBodyStringifier";
20
- import { Singleton } from "../utils/Singleton";
21
- import { TypedRoute } from "./TypedRoute";
22
- import { ENCRYPTION_METADATA_KEY } from "./internal/EncryptedConstant";
23
- import { get_path_and_stringify } from "./internal/get_path_and_stringify";
24
- import { headers_to_object } from "./internal/headers_to_object";
25
- import { route_error } from "./internal/route_error";
26
-
27
- /**
28
- * Encrypted router decorator functions.
29
- *
30
- * `EncryptedRoute` is a module containing router decorator functions which
31
- * encrypts response body data through AES-128/256 encryption. Furthermore, they
32
- * can boost up JSON string conversion speed about 50x times faster than
33
- * `class-transformer`, even type safe through
34
- * [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
38
- * `EncryptedRoute` composes JSON string through `typia.assertStringify<T>()`
39
- * function, it is not 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` in the
93
- * `tsconfig.json` file, then the error log information of the response
94
- * validation failure would be logged through this function instead of
95
- * throwing the 400 bad request error.
96
- *
97
- * By the way, be careful. If you've configured the response transformation
98
- * option to be `validate.log`, client may get wrong response data. Therefore,
99
- * this way is not recommended in the common backend server case.
100
- *
101
- * @default console.log
102
- * @param func Logger function
103
- */
104
- export function setValidateErrorLogger(
105
- func: (log: IValidateErrorLog) => void,
106
- ): void {
107
- TypedRoute.setValidateErrorLogger(func);
108
- }
109
-
110
- export import IValidateErrorLog = TypedRoute.IValidateErrorLog;
111
-
112
- /** @internal */
113
- function Generator(method: "Get" | "Post" | "Put" | "Patch" | "Delete") {
114
- function route(path?: string | string[]): MethodDecorator;
115
- function route<T>(
116
- stringify?: IResponseBodyStringifier<T> | null,
117
- ): MethodDecorator;
118
- function route<T>(
119
- path: string | string[],
120
- stringify?: IResponseBodyStringifier<T> | null,
121
- ): MethodDecorator;
122
-
123
- function route(...args: any[]): MethodDecorator {
124
- const [path, stringify] = get_path_and_stringify(
125
- () => TypedRoute.__logger,
126
- )(`EncryptedRoute.${method}`)(...args);
127
- return applyDecorators(
128
- ROUTERS[method](path),
129
- UseInterceptors(new EncryptedRouteInterceptor(method, stringify)),
130
- );
131
- }
132
- return route;
133
- }
134
- }
135
-
136
- for (const method of [
137
- typia.json.isStringify,
138
- typia.json.assertStringify,
139
- typia.json.validateStringify,
140
- typia.json.stringify,
141
- ])
142
- for (const [key, value] of Object.entries(method))
143
- for (const deco of [
144
- EncryptedRoute.Get,
145
- EncryptedRoute.Delete,
146
- EncryptedRoute.Post,
147
- EncryptedRoute.Put,
148
- EncryptedRoute.Patch,
149
- ])
150
- (deco as any)[key] = value;
151
-
152
- /** @internal */
153
- class EncryptedRouteInterceptor implements NestInterceptor {
154
- public constructor(
155
- private readonly method: string,
156
- private readonly stringify: (
157
- input: any,
158
- method: string,
159
- path: string,
160
- ) => string,
161
- ) {}
162
-
163
- public intercept(context: ExecutionContext, next: CallHandler) {
164
- const http: HttpArgumentsHost = context.switchToHttp();
165
- return next.handle().pipe(
166
- map((value) => {
167
- const param:
168
- | IEncryptionPassword
169
- | IEncryptionPassword.Closure
170
- | undefined = Reflect.getMetadata(
171
- ENCRYPTION_METADATA_KEY,
172
- context.getClass(),
173
- );
174
- if (!param)
175
- return Error(
176
- `Error on EncryptedRoute.${this.method}(): no password found.`,
177
- );
178
-
179
- const request: express.Request = http.getRequest();
180
- const headers: Singleton<Record<string, string>> = new Singleton(() =>
181
- headers_to_object(request.headers),
182
- );
183
- const body: string | undefined = this.stringify(
184
- value,
185
- request.method,
186
- request.url,
187
- );
188
- const password: IEncryptionPassword =
189
- typeof param === "function"
190
- ? param({
191
- headers: headers.get(),
192
- body,
193
- direction: "encode",
194
- })
195
- : param;
196
-
197
- if (body === undefined) return body;
198
- return AesPkcs5.encrypt(body, password.key, password.iv);
199
- }),
200
- catchError((err) => route_error(http.getRequest(), err)),
201
- );
202
- }
203
- }
204
-
205
- /** @internal */
206
- const ROUTERS = {
207
- Get,
208
- Post,
209
- Put,
210
- Patch,
211
- Delete,
212
- };
1
+ import { AesPkcs5, IEncryptionPassword } from "@nestia/fetcher";
2
+ import {
3
+ CallHandler,
4
+ Delete,
5
+ ExecutionContext,
6
+ Get,
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 express from "express";
16
+ import { catchError, map } from "rxjs/operators";
17
+ import typia from "typia";
18
+
19
+ import { IResponseBodyStringifier } from "../options/IResponseBodyStringifier";
20
+ import { Singleton } from "../utils/Singleton";
21
+ import { TypedRoute } from "./TypedRoute";
22
+ import { ENCRYPTION_METADATA_KEY } from "./internal/EncryptedConstant";
23
+ import { get_path_and_stringify } from "./internal/get_path_and_stringify";
24
+ import { headers_to_object } from "./internal/headers_to_object";
25
+ import { route_error } from "./internal/route_error";
26
+
27
+ /**
28
+ * Encrypted router decorator functions.
29
+ *
30
+ * `EncryptedRoute` is a module containing router decorator functions which
31
+ * encrypts response body data through AES-128/256 encryption. Furthermore, they
32
+ * can boost up JSON string conversion speed about 50x times faster than
33
+ * `class-transformer`, even type safe through
34
+ * [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
38
+ * `EncryptedRoute` composes JSON string through `typia.assertStringify<T>()`
39
+ * function, it is not 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` in the
93
+ * `tsconfig.json` file, then the error log information of the response
94
+ * validation failure would be logged through this function instead of
95
+ * throwing the 400 bad request error.
96
+ *
97
+ * By the way, be careful. If you've configured the response transformation
98
+ * option to be `validate.log`, client may get wrong response data. Therefore,
99
+ * this way is not recommended in the common backend server case.
100
+ *
101
+ * @default console.log
102
+ * @param func Logger function
103
+ */
104
+ export function setValidateErrorLogger(
105
+ func: (log: IValidateErrorLog) => void,
106
+ ): void {
107
+ TypedRoute.setValidateErrorLogger(func);
108
+ }
109
+
110
+ export import IValidateErrorLog = TypedRoute.IValidateErrorLog;
111
+
112
+ /** @internal */
113
+ function Generator(method: "Get" | "Post" | "Put" | "Patch" | "Delete") {
114
+ function route(path?: string | string[]): MethodDecorator;
115
+ function route<T>(
116
+ stringify?: IResponseBodyStringifier<T> | null,
117
+ ): MethodDecorator;
118
+ function route<T>(
119
+ path: string | string[],
120
+ stringify?: IResponseBodyStringifier<T> | null,
121
+ ): MethodDecorator;
122
+
123
+ function route(...args: any[]): MethodDecorator {
124
+ const [path, stringify] = get_path_and_stringify(
125
+ () => TypedRoute.__logger,
126
+ )(`EncryptedRoute.${method}`)(...args);
127
+ return applyDecorators(
128
+ ROUTERS[method](path),
129
+ UseInterceptors(new EncryptedRouteInterceptor(method, stringify)),
130
+ );
131
+ }
132
+ return route;
133
+ }
134
+ }
135
+
136
+ for (const method of [
137
+ typia.json.isStringify,
138
+ typia.json.assertStringify,
139
+ typia.json.validateStringify,
140
+ typia.json.stringify,
141
+ ])
142
+ for (const [key, value] of Object.entries(method))
143
+ for (const deco of [
144
+ EncryptedRoute.Get,
145
+ EncryptedRoute.Delete,
146
+ EncryptedRoute.Post,
147
+ EncryptedRoute.Put,
148
+ EncryptedRoute.Patch,
149
+ ])
150
+ (deco as any)[key] = value;
151
+
152
+ /** @internal */
153
+ class EncryptedRouteInterceptor implements NestInterceptor {
154
+ public constructor(
155
+ private readonly method: string,
156
+ private readonly stringify: (
157
+ input: any,
158
+ method: string,
159
+ path: string,
160
+ ) => string,
161
+ ) {}
162
+
163
+ public intercept(context: ExecutionContext, next: CallHandler) {
164
+ const http: HttpArgumentsHost = context.switchToHttp();
165
+ return next.handle().pipe(
166
+ map((value) => {
167
+ const param:
168
+ | IEncryptionPassword
169
+ | IEncryptionPassword.Closure
170
+ | undefined = Reflect.getMetadata(
171
+ ENCRYPTION_METADATA_KEY,
172
+ context.getClass(),
173
+ );
174
+ if (!param)
175
+ return Error(
176
+ `Error on EncryptedRoute.${this.method}(): no password found.`,
177
+ );
178
+
179
+ const request: express.Request = http.getRequest();
180
+ const headers: Singleton<Record<string, string>> = new Singleton(() =>
181
+ headers_to_object(request.headers),
182
+ );
183
+ const body: string | undefined = this.stringify(
184
+ value,
185
+ request.method,
186
+ request.url,
187
+ );
188
+ const password: IEncryptionPassword =
189
+ typeof param === "function"
190
+ ? param({
191
+ headers: headers.get(),
192
+ body,
193
+ direction: "encode",
194
+ })
195
+ : param;
196
+
197
+ if (body === undefined) return body;
198
+ return AesPkcs5.encrypt(body, password.key, password.iv);
199
+ }),
200
+ catchError((err) => route_error(http.getRequest(), err)),
201
+ );
202
+ }
203
+ }
204
+
205
+ /** @internal */
206
+ const ROUTERS = {
207
+ Get,
208
+ Post,
209
+ Put,
210
+ Patch,
211
+ Delete,
212
+ };
@@ -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
+ }
@@ -1,34 +1,37 @@
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 nestia 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`
20
- * file, the error will not be thrown and the program will be continued.
21
- * Instead, every validations and assertions will be skipped and the value
22
- * will be returned as it is. 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
26
- * or testing.
27
- *
28
- * By the way, if you hope the `false` value to be set, you have to do it
29
- * before the first. If you configure the `false` value after the
30
- * `@nestia/core` decorator functions are composed, the value will not be
31
- * applied and the error will be thrown.
32
- */
33
- export let throws = true;
34
- }
1
+ /** @internal */
2
+ export function NoTransformConfigurationError(method: string) {
3
+ if (NoTransformConfigurationError.throws === true)
4
+ throw new Error(
5
+ [
6
+ `Error on nestia.core.${method}(): no transform has been configured.`,
7
+ `Run "npx nestia setup" command, or check if you're using non-standard TypeScript compiler like Babel or SWC.`,
8
+ `Otherwise you're running "npx nestia sdk/swagger" or similar, run "npx tsc" command to find the reason why.`,
9
+ ].join(" "),
10
+ );
11
+ return undefined as never;
12
+ }
13
+
14
+ /** @internal */
15
+ export namespace NoTransformConfigurationError {
16
+ /**
17
+ * Whether to throw an error or not.
18
+ *
19
+ * If you set this value to `false`, {@link NoTransformConfigurationError} will
20
+ * not throw an error.
21
+ *
22
+ * Even if you've not configured the plugin transformer of `tsconfig.json`
23
+ * file, the error will not be thrown and the program will be continued.
24
+ * Instead, every validations and assertions will be skipped and the value
25
+ * will be returned as it is. Furthermore, unexpected behaviors may occur.
26
+ *
27
+ * Therefore, it is not recommended to set this value to `false` in production
28
+ * environment. Configure this value to be `false` only when you're debugging
29
+ * or testing.
30
+ *
31
+ * By the way, if you hope the `false` value to be set, you have to do it
32
+ * before the first. If you configure the `false` value after the
33
+ * `@nestia/core` decorator functions are composed, the value will not be
34
+ * applied and the error will be thrown.
35
+ */
36
+ export let throws = true;
37
+ }