@nestia/core 11.0.0-dev.20260316 → 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 (47) 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/package.json +8 -8
  13. package/src/adaptors/WebSocketAdaptor.ts +429 -429
  14. package/src/decorators/EncryptedBody.ts +96 -96
  15. package/src/decorators/EncryptedController.ts +40 -40
  16. package/src/decorators/EncryptedModule.ts +98 -98
  17. package/src/decorators/EncryptedRoute.ts +212 -212
  18. package/src/decorators/HumanRoute.ts +21 -21
  19. package/src/decorators/NoTransformConfigurationError.ts +37 -34
  20. package/src/decorators/SwaggerCustomizer.ts +97 -97
  21. package/src/decorators/TypedFormData.ts +187 -187
  22. package/src/decorators/TypedRoute.ts +196 -196
  23. package/src/decorators/doNotThrowTransformError.ts +5 -0
  24. package/src/decorators/internal/headers_to_object.ts +11 -11
  25. package/src/module.ts +23 -23
  26. package/src/options/INestiaTransformOptions.ts +34 -34
  27. package/src/options/INestiaTransformProject.ts +10 -10
  28. package/src/programmers/PlainBodyProgrammer.ts +72 -72
  29. package/src/programmers/TypedBodyProgrammer.ts +148 -148
  30. package/src/programmers/TypedFormDataBodyProgrammer.ts +118 -118
  31. package/src/programmers/TypedHeadersProgrammer.ts +65 -65
  32. package/src/programmers/TypedParamProgrammer.ts +33 -33
  33. package/src/programmers/TypedQueryBodyProgrammer.ts +113 -113
  34. package/src/programmers/TypedQueryProgrammer.ts +115 -115
  35. package/src/programmers/TypedQueryRouteProgrammer.ts +107 -107
  36. package/src/programmers/TypedRouteProgrammer.ts +103 -103
  37. package/src/programmers/http/HttpAssertQuerifyProgrammer.ts +74 -74
  38. package/src/programmers/http/HttpIsQuerifyProgrammer.ts +77 -77
  39. package/src/programmers/http/HttpQuerifyProgrammer.ts +110 -110
  40. package/src/programmers/http/HttpValidateQuerifyProgrammer.ts +78 -78
  41. package/src/programmers/internal/CoreMetadataUtil.ts +21 -21
  42. package/src/transform.ts +35 -35
  43. package/src/transformers/FileTransformer.ts +109 -109
  44. package/src/transformers/MethodTransformer.ts +103 -103
  45. package/src/transformers/ParameterDecoratorTransformer.ts +143 -143
  46. package/src/transformers/TypedRouteTransformer.ts +85 -85
  47. package/src/transformers/WebSocketRouteTransformer.ts +120 -120
@@ -1,196 +1,196 @@
1
- import {
2
- CallHandler,
3
- Delete,
4
- ExecutionContext,
5
- Get,
6
- NestInterceptor,
7
- Patch,
8
- Post,
9
- Put,
10
- UseInterceptors,
11
- applyDecorators,
12
- } from "@nestjs/common";
13
- import { HttpArgumentsHost } from "@nestjs/common/interfaces";
14
- import type express from "express";
15
- import { catchError, map } from "rxjs/operators";
16
- import typia, { IValidation } from "typia";
17
-
18
- import { IResponseBodyStringifier } from "../options/IResponseBodyStringifier";
19
- import { get_path_and_stringify } from "./internal/get_path_and_stringify";
20
- import { route_error } from "./internal/route_error";
21
-
22
- /**
23
- * Type safe router decorator functions.
24
- *
25
- * `TypedRoute` is a module containing router decorator functions which can
26
- * boost up JSON string conversion speed about 200x times faster than
27
- * `class-transformer`. Furthermore, such JSON string conversion is even type
28
- * safe through [typia](https://github.com/samchon/typia).
29
- *
30
- * For reference, if you try to invalid data that is not following the promised
31
- * type `T`, 500 internal server error would be thrown. Also, as `TypedRoute`
32
- * composes JSON string through `typia.assertStringify<T>()` function, it is not
33
- * possible to modify response data through interceptors.
34
- *
35
- * @author Jeongho Nam - https://github.com/samchon
36
- */
37
- export namespace TypedRoute {
38
- /**
39
- * Router decorator function for the GET method.
40
- *
41
- * @param path Path of the HTTP request
42
- * @returns Method decorator
43
- */
44
- export const Get = Generator("Get");
45
-
46
- /**
47
- * Router decorator function for the POST method.
48
- *
49
- * @param path Path of the HTTP request
50
- * @returns Method decorator
51
- */
52
- export const Post = Generator("Post");
53
-
54
- /**
55
- * Router decorator function for the PATH method.
56
- *
57
- * @param path Path of the HTTP request
58
- * @returns Method decorator
59
- */
60
- export const Patch = Generator("Patch");
61
-
62
- /**
63
- * Router decorator function for the PUT method.
64
- *
65
- * @param path Path of the HTTP request
66
- * @returns Method decorator
67
- */
68
- export const Put = Generator("Put");
69
-
70
- /**
71
- * Router decorator function for the DELETE method.
72
- *
73
- * @param path Path of the HTTP request
74
- * @returns Method decorator
75
- */
76
- export const Delete = Generator("Delete");
77
-
78
- /**
79
- * Set the logger function for the response validation failure.
80
- *
81
- * If you've configured the transformation option to `validate.log` in the
82
- * `tsconfig.json` file, then the error log information of the response
83
- * validation failure would be logged through this function instead of
84
- * throwing the 400 bad request error.
85
- *
86
- * By the way, be careful. If you've configured the response transformation
87
- * option to be `validate.log`, client may get wrong response data. Therefore,
88
- * this way is not recommended in the common backend server case.
89
- *
90
- * @default console.log
91
- * @param func Logger function
92
- */
93
- export function setValidateErrorLogger(
94
- func: (log: IValidateErrorLog) => void,
95
- ): void {
96
- __logger = func;
97
- }
98
-
99
- /**
100
- * Error log information of the response validation failure.
101
- *
102
- * `IValidationErrorLog` is a structure representing the error log information
103
- * when the returned value from the `@TypedRoute` or `@EncryptedRoute`
104
- * decorated controller method is not following the promised type `T`.
105
- *
106
- * If you've configured the transformation option to `validate.log` or
107
- * `validateEquals.log` in the `tsconfig.json` file, then this error log
108
- * information `IValidateErrorLog` would be logged through the
109
- * {@link setValidateErrorLogger} function instead of throwing the 400 bad
110
- * request error.
111
- */
112
- export interface IValidateErrorLog {
113
- /** HTTP method of the request. */
114
- method: string;
115
-
116
- /** HTTP path of the request. */
117
- path: string;
118
-
119
- /** Validation error information with detailed reasons. */
120
- errors: IValidation.IError[];
121
-
122
- /** Data that is not following the promised type `T`. */
123
- data: unknown;
124
- }
125
-
126
- /** @internal */
127
- export let __logger: (log: IValidateErrorLog) => void = console.log;
128
-
129
- /** @internal */
130
- function Generator(method: "Get" | "Post" | "Put" | "Patch" | "Delete") {
131
- function route(path?: string | string[]): MethodDecorator;
132
- function route<T>(stringify?: IResponseBodyStringifier<T>): MethodDecorator;
133
- function route<T>(
134
- path: string | string[],
135
- stringify?: IResponseBodyStringifier<T>,
136
- ): MethodDecorator;
137
-
138
- function route(...args: any[]): MethodDecorator {
139
- const [path, stringify] = get_path_and_stringify(() => __logger)(
140
- `TypedRoute.${method}`,
141
- )(...args);
142
- return applyDecorators(
143
- ROUTERS[method](path),
144
- UseInterceptors(new TypedRouteInterceptor(stringify)),
145
- );
146
- }
147
- return route;
148
- }
149
- }
150
- for (const method of [
151
- typia.json.stringify,
152
- typia.json.isStringify,
153
- typia.json.assertStringify,
154
- typia.json.validateStringify,
155
- ])
156
- for (const [key, value] of Object.entries(method))
157
- for (const deco of [
158
- TypedRoute.Get,
159
- TypedRoute.Delete,
160
- TypedRoute.Post,
161
- TypedRoute.Put,
162
- TypedRoute.Patch,
163
- ])
164
- (deco as any)[key] = value;
165
-
166
- /** @internal */
167
- class TypedRouteInterceptor implements NestInterceptor {
168
- public constructor(
169
- private readonly stringify: (
170
- input: any,
171
- method: string,
172
- path: string,
173
- ) => string,
174
- ) {}
175
-
176
- public intercept(context: ExecutionContext, next: CallHandler) {
177
- const http: HttpArgumentsHost = context.switchToHttp();
178
- const request: express.Request = http.getRequest();
179
- const response: express.Response = http.getResponse();
180
- response.header("Content-Type", "application/json");
181
-
182
- return next.handle().pipe(
183
- map((value) => this.stringify(value, request.method, request.url)),
184
- catchError((err) => route_error(http.getRequest(), err)),
185
- );
186
- }
187
- }
188
-
189
- /** @internal */
190
- const ROUTERS = {
191
- Get,
192
- Post,
193
- Patch,
194
- Put,
195
- Delete,
196
- };
1
+ import {
2
+ CallHandler,
3
+ Delete,
4
+ ExecutionContext,
5
+ Get,
6
+ NestInterceptor,
7
+ Patch,
8
+ Post,
9
+ Put,
10
+ UseInterceptors,
11
+ applyDecorators,
12
+ } from "@nestjs/common";
13
+ import { HttpArgumentsHost } from "@nestjs/common/interfaces";
14
+ import type express from "express";
15
+ import { catchError, map } from "rxjs/operators";
16
+ import typia, { IValidation } from "typia";
17
+
18
+ import { IResponseBodyStringifier } from "../options/IResponseBodyStringifier";
19
+ import { get_path_and_stringify } from "./internal/get_path_and_stringify";
20
+ import { route_error } from "./internal/route_error";
21
+
22
+ /**
23
+ * Type safe router decorator functions.
24
+ *
25
+ * `TypedRoute` is a module containing router decorator functions which can
26
+ * boost up JSON string conversion speed about 200x times faster than
27
+ * `class-transformer`. Furthermore, such JSON string conversion is even type
28
+ * safe through [typia](https://github.com/samchon/typia).
29
+ *
30
+ * For reference, if you try to invalid data that is not following the promised
31
+ * type `T`, 500 internal server error would be thrown. Also, as `TypedRoute`
32
+ * composes JSON string through `typia.assertStringify<T>()` function, it is not
33
+ * possible to modify response data through interceptors.
34
+ *
35
+ * @author Jeongho Nam - https://github.com/samchon
36
+ */
37
+ export namespace TypedRoute {
38
+ /**
39
+ * Router decorator function for the GET method.
40
+ *
41
+ * @param path Path of the HTTP request
42
+ * @returns Method decorator
43
+ */
44
+ export const Get = Generator("Get");
45
+
46
+ /**
47
+ * Router decorator function for the POST method.
48
+ *
49
+ * @param path Path of the HTTP request
50
+ * @returns Method decorator
51
+ */
52
+ export const Post = Generator("Post");
53
+
54
+ /**
55
+ * Router decorator function for the PATH method.
56
+ *
57
+ * @param path Path of the HTTP request
58
+ * @returns Method decorator
59
+ */
60
+ export const Patch = Generator("Patch");
61
+
62
+ /**
63
+ * Router decorator function for the PUT method.
64
+ *
65
+ * @param path Path of the HTTP request
66
+ * @returns Method decorator
67
+ */
68
+ export const Put = Generator("Put");
69
+
70
+ /**
71
+ * Router decorator function for the DELETE method.
72
+ *
73
+ * @param path Path of the HTTP request
74
+ * @returns Method decorator
75
+ */
76
+ export const Delete = Generator("Delete");
77
+
78
+ /**
79
+ * Set the logger function for the response validation failure.
80
+ *
81
+ * If you've configured the transformation option to `validate.log` in the
82
+ * `tsconfig.json` file, then the error log information of the response
83
+ * validation failure would be logged through this function instead of
84
+ * throwing the 400 bad request error.
85
+ *
86
+ * By the way, be careful. If you've configured the response transformation
87
+ * option to be `validate.log`, client may get wrong response data. Therefore,
88
+ * this way is not recommended in the common backend server case.
89
+ *
90
+ * @default console.log
91
+ * @param func Logger function
92
+ */
93
+ export function setValidateErrorLogger(
94
+ func: (log: IValidateErrorLog) => void,
95
+ ): void {
96
+ __logger = func;
97
+ }
98
+
99
+ /**
100
+ * Error log information of the response validation failure.
101
+ *
102
+ * `IValidationErrorLog` is a structure representing the error log information
103
+ * when the returned value from the `@TypedRoute` or `@EncryptedRoute`
104
+ * decorated controller method is not following the promised type `T`.
105
+ *
106
+ * If you've configured the transformation option to `validate.log` or
107
+ * `validateEquals.log` in the `tsconfig.json` file, then this error log
108
+ * information `IValidateErrorLog` would be logged through the
109
+ * {@link setValidateErrorLogger} function instead of throwing the 400 bad
110
+ * request error.
111
+ */
112
+ export interface IValidateErrorLog {
113
+ /** HTTP method of the request. */
114
+ method: string;
115
+
116
+ /** HTTP path of the request. */
117
+ path: string;
118
+
119
+ /** Validation error information with detailed reasons. */
120
+ errors: IValidation.IError[];
121
+
122
+ /** Data that is not following the promised type `T`. */
123
+ data: unknown;
124
+ }
125
+
126
+ /** @internal */
127
+ export let __logger: (log: IValidateErrorLog) => void = console.log;
128
+
129
+ /** @internal */
130
+ function Generator(method: "Get" | "Post" | "Put" | "Patch" | "Delete") {
131
+ function route(path?: string | string[]): MethodDecorator;
132
+ function route<T>(stringify?: IResponseBodyStringifier<T>): MethodDecorator;
133
+ function route<T>(
134
+ path: string | string[],
135
+ stringify?: IResponseBodyStringifier<T>,
136
+ ): MethodDecorator;
137
+
138
+ function route(...args: any[]): MethodDecorator {
139
+ const [path, stringify] = get_path_and_stringify(() => __logger)(
140
+ `TypedRoute.${method}`,
141
+ )(...args);
142
+ return applyDecorators(
143
+ ROUTERS[method](path),
144
+ UseInterceptors(new TypedRouteInterceptor(stringify)),
145
+ );
146
+ }
147
+ return route;
148
+ }
149
+ }
150
+ for (const method of [
151
+ typia.json.stringify,
152
+ typia.json.isStringify,
153
+ typia.json.assertStringify,
154
+ typia.json.validateStringify,
155
+ ])
156
+ for (const [key, value] of Object.entries(method))
157
+ for (const deco of [
158
+ TypedRoute.Get,
159
+ TypedRoute.Delete,
160
+ TypedRoute.Post,
161
+ TypedRoute.Put,
162
+ TypedRoute.Patch,
163
+ ])
164
+ (deco as any)[key] = value;
165
+
166
+ /** @internal */
167
+ class TypedRouteInterceptor implements NestInterceptor {
168
+ public constructor(
169
+ private readonly stringify: (
170
+ input: any,
171
+ method: string,
172
+ path: string,
173
+ ) => string,
174
+ ) {}
175
+
176
+ public intercept(context: ExecutionContext, next: CallHandler) {
177
+ const http: HttpArgumentsHost = context.switchToHttp();
178
+ const request: express.Request = http.getRequest();
179
+ const response: express.Response = http.getResponse();
180
+ response.header("Content-Type", "application/json");
181
+
182
+ return next.handle().pipe(
183
+ map((value) => this.stringify(value, request.method, request.url)),
184
+ catchError((err) => route_error(http.getRequest(), err)),
185
+ );
186
+ }
187
+ }
188
+
189
+ /** @internal */
190
+ const ROUTERS = {
191
+ Get,
192
+ Post,
193
+ Patch,
194
+ Put,
195
+ Delete,
196
+ };
@@ -0,0 +1,5 @@
1
+ import { NoTransformConfigurationError } from "./NoTransformConfigurationError";
2
+
3
+ export const doNotThrowTransformError = (value: boolean = false) => {
4
+ NoTransformConfigurationError.throws = value;
5
+ };
@@ -1,11 +1,11 @@
1
- import http from "http";
2
-
3
- /** @internal */
4
- export function headers_to_object(
5
- headers: http.IncomingHttpHeaders,
6
- ): Record<string, string> {
7
- const output: Record<string, string> = {};
8
- for (const [key, value] of Object.entries(headers))
9
- output[key] = value instanceof Array ? value[0]! : value || "";
10
- return output;
11
- }
1
+ import http from "http";
2
+
3
+ /** @internal */
4
+ export function headers_to_object(
5
+ headers: http.IncomingHttpHeaders,
6
+ ): Record<string, string> {
7
+ const output: Record<string, string> = {};
8
+ for (const [key, value] of Object.entries(headers))
9
+ output[key] = value instanceof Array ? value[0]! : value || "";
10
+ return output;
11
+ }
package/src/module.ts CHANGED
@@ -1,23 +1,23 @@
1
- export * from "./decorators/DynamicModule";
2
- export * from "./utils/ExceptionManager";
3
-
4
- export * from "./decorators/HumanRoute";
5
- export * from "./decorators/TypedRoute";
6
- export * from "./decorators/TypedBody";
7
- export * from "./decorators/TypedQuery";
8
- export * from "./decorators/TypedException";
9
- export * from "./decorators/TypedHeaders";
10
- export * from "./decorators/TypedFormData";
11
- export * from "./decorators/TypedParam";
12
-
13
- export * from "./decorators/EncryptedController";
14
- export * from "./decorators/EncryptedRoute";
15
- export * from "./decorators/EncryptedBody";
16
- export * from "./decorators/EncryptedModule";
17
- export * from "./decorators/PlainBody";
18
- export * from "./decorators/SwaggerCustomizer";
19
- export * from "./decorators/SwaggerExample";
20
-
21
- export * from "./adaptors/WebSocketAdaptor";
22
- export * from "./decorators/WebSocketRoute";
23
- export * from "./decorators/NoTransformConfigurationError";
1
+ export * from "./decorators/DynamicModule";
2
+ export * from "./utils/ExceptionManager";
3
+
4
+ export * from "./decorators/HumanRoute";
5
+ export * from "./decorators/TypedRoute";
6
+ export * from "./decorators/TypedBody";
7
+ export * from "./decorators/TypedQuery";
8
+ export * from "./decorators/TypedException";
9
+ export * from "./decorators/TypedHeaders";
10
+ export * from "./decorators/TypedFormData";
11
+ export * from "./decorators/TypedParam";
12
+
13
+ export * from "./decorators/EncryptedController";
14
+ export * from "./decorators/EncryptedRoute";
15
+ export * from "./decorators/EncryptedBody";
16
+ export * from "./decorators/EncryptedModule";
17
+ export * from "./decorators/PlainBody";
18
+ export * from "./decorators/SwaggerCustomizer";
19
+ export * from "./decorators/SwaggerExample";
20
+
21
+ export * from "./adaptors/WebSocketAdaptor";
22
+ export * from "./decorators/WebSocketRoute";
23
+ export * from "./decorators/doNotThrowTransformError";
@@ -1,34 +1,34 @@
1
- export interface INestiaTransformOptions {
2
- validate?: INestiaTransformOptions.Validate;
3
- stringify?: INestiaTransformOptions.Stringify | null;
4
- llm?: boolean | INestiaTransformOptions.ILlm;
5
- throws?: boolean;
6
- }
7
- export namespace INestiaTransformOptions {
8
- export type Validate =
9
- // NORMAL
10
- | "assert"
11
- | "is"
12
- | "validate"
13
- // STRICT
14
- | "assertEquals"
15
- | "equals"
16
- | "validateEquals"
17
- // CLONE
18
- | "assertClone"
19
- | "validateClone"
20
- // PRUNE
21
- | "assertPrune"
22
- | "validatePrune";
23
-
24
- export type Stringify =
25
- | "stringify"
26
- | "assert"
27
- | "is"
28
- | "validate"
29
- | "validate.log";
30
-
31
- export interface ILlm {
32
- strict?: boolean;
33
- }
34
- }
1
+ export interface INestiaTransformOptions {
2
+ validate?: INestiaTransformOptions.Validate;
3
+ stringify?: INestiaTransformOptions.Stringify | null;
4
+ llm?: boolean | INestiaTransformOptions.ILlm;
5
+ throws?: boolean;
6
+ }
7
+ export namespace INestiaTransformOptions {
8
+ export type Validate =
9
+ // NORMAL
10
+ | "assert"
11
+ | "is"
12
+ | "validate"
13
+ // STRICT
14
+ | "assertEquals"
15
+ | "equals"
16
+ | "validateEquals"
17
+ // CLONE
18
+ | "assertClone"
19
+ | "validateClone"
20
+ // PRUNE
21
+ | "assertPrune"
22
+ | "validatePrune";
23
+
24
+ export type Stringify =
25
+ | "stringify"
26
+ | "assert"
27
+ | "is"
28
+ | "validate"
29
+ | "validate.log";
30
+
31
+ export interface ILlm {
32
+ strict?: boolean;
33
+ }
34
+ }
@@ -1,10 +1,10 @@
1
- import { ITypiaContext } from "@typia/core";
2
-
3
- import { INestiaTransformOptions } from "./INestiaTransformOptions";
4
-
5
- export interface INestiaTransformContext extends Omit<
6
- ITypiaContext,
7
- "options"
8
- > {
9
- options: INestiaTransformOptions;
10
- }
1
+ import { ITypiaContext } from "@typia/core";
2
+
3
+ import { INestiaTransformOptions } from "./INestiaTransformOptions";
4
+
5
+ export interface INestiaTransformContext extends Omit<
6
+ ITypiaContext,
7
+ "options"
8
+ > {
9
+ options: INestiaTransformOptions;
10
+ }