@nestia/core 7.3.0 → 7.3.2
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/lib/decorators/DynamicModule.d.ts +3 -2
- package/lib/decorators/DynamicModule.js +3 -2
- package/lib/decorators/DynamicModule.js.map +1 -1
- package/lib/decorators/EncryptedBody.d.ts +11 -11
- package/lib/decorators/EncryptedBody.js +13 -17
- package/lib/decorators/EncryptedBody.js.map +1 -1
- package/lib/decorators/EncryptedController.d.ts +15 -13
- package/lib/decorators/EncryptedController.js +15 -13
- package/lib/decorators/EncryptedController.js.map +1 -1
- package/lib/decorators/EncryptedModule.d.ts +22 -22
- package/lib/decorators/EncryptedModule.js +23 -25
- package/lib/decorators/EncryptedModule.js.map +1 -1
- package/lib/decorators/EncryptedRoute.d.ts +20 -20
- package/lib/decorators/EncryptedRoute.js +23 -29
- package/lib/decorators/EncryptedRoute.js.map +1 -1
- package/lib/decorators/HumanRoute.d.ts +3 -3
- package/lib/decorators/HumanRoute.js +3 -3
- package/lib/decorators/NoTransformConfigurationError.d.ts +10 -8
- package/lib/decorators/NoTransformConfigurationError.js +10 -8
- package/lib/decorators/NoTransformConfigurationError.js.map +1 -1
- package/lib/decorators/PlainBody.d.ts +7 -6
- package/lib/decorators/PlainBody.js +2 -6
- package/lib/decorators/PlainBody.js.map +1 -1
- package/lib/decorators/SwaggerCustomizer.d.ts +12 -30
- package/lib/decorators/SwaggerCustomizer.js +3 -3
- package/lib/decorators/TypedBody.d.ts +7 -7
- package/lib/decorators/TypedBody.js +8 -10
- package/lib/decorators/TypedBody.js.map +1 -1
- package/lib/decorators/TypedException.d.ts +41 -58
- package/lib/decorators/TypedException.js +1 -3
- package/lib/decorators/TypedException.js.map +1 -1
- package/lib/decorators/TypedFormData.d.ts +16 -16
- package/lib/decorators/TypedFormData.js +17 -23
- package/lib/decorators/TypedFormData.js.map +1 -1
- package/lib/decorators/TypedHeaders.d.ts +27 -25
- package/lib/decorators/TypedHeaders.js +27 -25
- package/lib/decorators/TypedHeaders.js.map +1 -1
- package/lib/decorators/TypedParam.d.ts +5 -5
- package/lib/decorators/TypedParam.js +5 -5
- package/lib/decorators/TypedQuery.d.ts +7 -6
- package/lib/decorators/TypedQuery.js +13 -24
- package/lib/decorators/TypedQuery.js.map +1 -1
- package/lib/decorators/TypedRoute.d.ts +24 -34
- package/lib/decorators/TypedRoute.js +19 -28
- package/lib/decorators/TypedRoute.js.map +1 -1
- package/lib/decorators/WebSocketRoute.d.ts +33 -31
- package/lib/decorators/WebSocketRoute.js +34 -34
- package/lib/decorators/WebSocketRoute.js.map +1 -1
- package/lib/decorators/internal/EncryptedConstant.js +1 -3
- package/lib/decorators/internal/EncryptedConstant.js.map +1 -1
- package/lib/decorators/internal/get_path_and_querify.js +7 -21
- package/lib/decorators/internal/get_path_and_querify.js.map +1 -1
- package/lib/decorators/internal/get_path_and_stringify.js +6 -18
- package/lib/decorators/internal/get_path_and_stringify.js.map +1 -1
- package/lib/decorators/internal/get_text_body.js +2 -6
- package/lib/decorators/internal/get_text_body.js.map +1 -1
- package/lib/decorators/internal/headers_to_object.js +1 -3
- package/lib/decorators/internal/headers_to_object.js.map +1 -1
- package/lib/decorators/internal/is_request_body_undefined.js +1 -3
- package/lib/decorators/internal/is_request_body_undefined.js.map +1 -1
- package/lib/decorators/internal/load_controller.js +3 -7
- package/lib/decorators/internal/load_controller.js.map +1 -1
- package/lib/decorators/internal/route_error.js +1 -3
- package/lib/decorators/internal/route_error.js.map +1 -1
- package/lib/decorators/internal/validate_request_body.js +5 -15
- package/lib/decorators/internal/validate_request_body.js.map +1 -1
- package/lib/decorators/internal/validate_request_form_data.js +5 -15
- package/lib/decorators/internal/validate_request_form_data.js.map +1 -1
- package/lib/decorators/internal/validate_request_headers.js +5 -15
- package/lib/decorators/internal/validate_request_headers.js.map +1 -1
- package/lib/decorators/internal/validate_request_query.js +5 -15
- package/lib/decorators/internal/validate_request_query.js.map +1 -1
- package/lib/utils/ExceptionManager.d.ts +27 -20
- package/lib/utils/ExceptionManager.js +20 -20
- package/lib/utils/ExceptionManager.js.map +1 -1
- package/lib/utils/Singleton.js +2 -6
- package/lib/utils/Singleton.js.map +1 -1
- package/lib/utils/SourceFinder.js +4 -8
- package/lib/utils/SourceFinder.js.map +1 -1
- package/package.json +7 -8
- package/src/decorators/DynamicModule.ts +3 -2
- package/src/decorators/EncryptedBody.ts +13 -17
- package/src/decorators/EncryptedController.ts +15 -13
- package/src/decorators/EncryptedModule.ts +23 -25
- package/src/decorators/EncryptedRoute.ts +23 -29
- package/src/decorators/HumanRoute.ts +3 -3
- package/src/decorators/NoTransformConfigurationError.ts +10 -8
- package/src/decorators/PlainBody.ts +9 -12
- package/src/decorators/SwaggerCustomizer.ts +12 -30
- package/src/decorators/TypedBody.ts +8 -10
- package/src/decorators/TypedException.ts +42 -61
- package/src/decorators/TypedFormData.ts +34 -34
- package/src/decorators/TypedHeaders.ts +27 -25
- package/src/decorators/TypedParam.ts +5 -5
- package/src/decorators/TypedQuery.ts +13 -24
- package/src/decorators/TypedRoute.ts +28 -46
- package/src/decorators/WebSocketRoute.ts +34 -34
- package/src/decorators/internal/EncryptedConstant.ts +1 -3
- package/src/decorators/internal/get_path_and_querify.ts +7 -21
- package/src/decorators/internal/get_path_and_stringify.ts +6 -18
- package/src/decorators/internal/get_text_body.ts +2 -6
- package/src/decorators/internal/headers_to_object.ts +1 -3
- package/src/decorators/internal/is_request_body_undefined.ts +1 -3
- package/src/decorators/internal/load_controller.ts +3 -7
- package/src/decorators/internal/route_error.ts +1 -3
- package/src/decorators/internal/validate_request_body.ts +5 -15
- package/src/decorators/internal/validate_request_form_data.ts +5 -15
- package/src/decorators/internal/validate_request_headers.ts +5 -15
- package/src/decorators/internal/validate_request_query.ts +5 -15
- package/src/utils/ExceptionManager.ts +29 -26
- package/src/utils/Singleton.ts +2 -6
- package/src/utils/SourceFinder.ts +5 -8
|
@@ -18,32 +18,34 @@ import { validate_request_form_data } from "./internal/validate_request_form_dat
|
|
|
18
18
|
* `multipart/form-data` content type. It automatically casts property type
|
|
19
19
|
* following its DTO definition, and performs the type validation too.
|
|
20
20
|
*
|
|
21
|
-
* Also, `TypedFormData.Body()` is much easier and type safer than
|
|
22
|
-
* If you're considering the [SDK
|
|
23
|
-
*
|
|
21
|
+
* Also, `TypedFormData.Body()` is much easier and type safer than
|
|
22
|
+
* `@nest.UploadFile()`. If you're considering the [SDK
|
|
23
|
+
* library](https://nestia.io/docs/sdk/sdk) generation, only
|
|
24
|
+
* `TypedFormData.Body()` can do it. Therefore, I recommend you to use
|
|
24
25
|
* `TypedFormData.Body()` instead of the `@nest.UploadFile()` function.
|
|
25
26
|
*
|
|
26
|
-
* For reference, target type `T` must follow such restriction. Of course, if
|
|
27
|
-
* form-data values are different with their promised type `T`,
|
|
27
|
+
* For reference, target type `T` must follow such restriction. Of course, if
|
|
28
|
+
* actual form-data values are different with their promised type `T`,
|
|
28
29
|
* `BadRequestException` error (status code: 400) would be thrown.
|
|
29
30
|
*
|
|
30
31
|
* 1. Type `T` must be an object type
|
|
31
32
|
* 2. Do not allow dynamic property
|
|
32
|
-
* 3. Only `boolean`, `bigint`, `number`, `string`, `Blob`, `File` or their array
|
|
33
|
+
* 3. Only `boolean`, `bigint`, `number`, `string`, `Blob`, `File` or their array
|
|
34
|
+
* types are allowed
|
|
33
35
|
* 4. By the way, union type never be not allowed
|
|
34
36
|
*
|
|
35
|
-
* By the way, if you're using `fastify`, you have to setup `fastify-multer`
|
|
36
|
-
*
|
|
37
|
+
* By the way, if you're using `fastify`, you have to setup `fastify-multer` and
|
|
38
|
+
* configure like below when composing the NestJS application. If you don't do
|
|
37
39
|
* that, `@TypedFormData.Body()` will not work properly, and throw 500 internal
|
|
38
40
|
* server error when `Blob` or `File` type being utilized.
|
|
39
41
|
*
|
|
40
42
|
* ```typescript
|
|
41
|
-
* import fastifyMulter from "fastify-multer";
|
|
42
43
|
* import { NestFactory } from "@nestjs/core";
|
|
43
44
|
* import {
|
|
44
45
|
* FastifyAdapter,
|
|
45
|
-
* NestFastifyApplication
|
|
46
|
+
* NestFastifyApplication,
|
|
46
47
|
* } from "@nestjs/platform-fastify";
|
|
48
|
+
* import fastifyMulter from "fastify-multer";
|
|
47
49
|
*
|
|
48
50
|
* export async function main() {
|
|
49
51
|
* const app = await NestFactory.create<NestFastifyApplication>(
|
|
@@ -55,8 +57,8 @@ import { validate_request_form_data } from "./internal/validate_request_form_dat
|
|
|
55
57
|
* }
|
|
56
58
|
* ```
|
|
57
59
|
*
|
|
58
|
-
* @todo Change to ReadableStream through configuring storage engine of multer
|
|
59
60
|
* @author Jeongho Nam - https://github.com/samchon
|
|
61
|
+
* @todo Change to ReadableStream through configuring storage engine of multer
|
|
60
62
|
*/
|
|
61
63
|
export namespace TypedFormData {
|
|
62
64
|
/**
|
|
@@ -67,16 +69,14 @@ export namespace TypedFormData {
|
|
|
67
69
|
* Much easier and type safer than `@nest.UploadFile()` decorator.
|
|
68
70
|
*
|
|
69
71
|
* @param factory Factory function ncreating the `multer` or `fastify-multer`
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
+
* instance. In the factory function, you also can specify the multer
|
|
73
|
+
* composition options like `storage` engine.
|
|
72
74
|
*/
|
|
73
75
|
export function Body<Multer extends IMulterBase>(
|
|
74
76
|
factory: () => Multer | Promise<Multer>,
|
|
75
77
|
): ParameterDecorator;
|
|
76
78
|
|
|
77
|
-
/**
|
|
78
|
-
* @internal
|
|
79
|
-
*/
|
|
79
|
+
/** @internal */
|
|
80
80
|
export function Body<T extends object>(
|
|
81
81
|
factory: () => Promise<IMulterBase>,
|
|
82
82
|
props?: IRequestFormDataProps<T> | undefined,
|
|
@@ -111,9 +111,7 @@ export namespace TypedFormData {
|
|
|
111
111
|
})();
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
-
/**
|
|
115
|
-
* Base type of the `multer` or `fastify-multer`.
|
|
116
|
-
*/
|
|
114
|
+
/** Base type of the `multer` or `fastify-multer`. */
|
|
117
115
|
export interface IMulterBase {
|
|
118
116
|
single(fieldName: string): any;
|
|
119
117
|
array(fieldName: string, maxCount?: number): any;
|
|
@@ -123,9 +121,7 @@ export namespace TypedFormData {
|
|
|
123
121
|
}
|
|
124
122
|
}
|
|
125
123
|
|
|
126
|
-
/**
|
|
127
|
-
* @internal
|
|
128
|
-
*/
|
|
124
|
+
/** @internal */
|
|
129
125
|
const decode = <T>(
|
|
130
126
|
multer: ExpressMulter.Multer,
|
|
131
127
|
props: IRequestFormDataProps<T>,
|
|
@@ -159,9 +155,7 @@ const decode = <T>(
|
|
|
159
155
|
};
|
|
160
156
|
};
|
|
161
157
|
|
|
162
|
-
/**
|
|
163
|
-
* @internal
|
|
164
|
-
*/
|
|
158
|
+
/** @internal */
|
|
165
159
|
const parseFiles =
|
|
166
160
|
(data: FormData) =>
|
|
167
161
|
(files: Express.Multer.File[] | Record<string, Express.Multer.File[]>) => {
|
|
@@ -169,24 +163,30 @@ const parseFiles =
|
|
|
169
163
|
for (const file of files)
|
|
170
164
|
data.append(
|
|
171
165
|
file.fieldname,
|
|
172
|
-
new File(
|
|
173
|
-
|
|
174
|
-
|
|
166
|
+
new File(
|
|
167
|
+
[file.buffer satisfies Uint8Array as any],
|
|
168
|
+
file.originalname,
|
|
169
|
+
{
|
|
170
|
+
type: file.mimetype,
|
|
171
|
+
},
|
|
172
|
+
),
|
|
175
173
|
);
|
|
176
174
|
else
|
|
177
175
|
for (const [key, value] of Object.entries(files))
|
|
178
176
|
for (const file of value)
|
|
179
177
|
data.append(
|
|
180
178
|
key,
|
|
181
|
-
new File(
|
|
182
|
-
|
|
183
|
-
|
|
179
|
+
new File(
|
|
180
|
+
[file.buffer satisfies Uint8Array as any],
|
|
181
|
+
file.originalname,
|
|
182
|
+
{
|
|
183
|
+
type: file.mimetype,
|
|
184
|
+
},
|
|
185
|
+
),
|
|
184
186
|
);
|
|
185
187
|
};
|
|
186
188
|
|
|
187
|
-
/**
|
|
188
|
-
* @internal
|
|
189
|
-
*/
|
|
189
|
+
/** @internal */
|
|
190
190
|
const isMultipartFormData = (text?: string): boolean =>
|
|
191
191
|
text !== undefined &&
|
|
192
192
|
text
|
|
@@ -8,13 +8,14 @@ import { validate_request_headers } from "./internal/validate_request_headers";
|
|
|
8
8
|
/**
|
|
9
9
|
* Type safe HTTP headers decorator.
|
|
10
10
|
*
|
|
11
|
-
* `TypedHeaders` is a decorator function that can parse HTTP headers. It is
|
|
12
|
-
* same with {@link nest.Headers}, but it can automatically cast property
|
|
13
|
-
* its DTO definition. Also, `TypedHeaders` performs type
|
|
11
|
+
* `TypedHeaders` is a decorator function that can parse HTTP headers. It is
|
|
12
|
+
* almost same with {@link nest.Headers}, but it can automatically cast property
|
|
13
|
+
* type following its DTO definition. Also, `TypedHeaders` performs type
|
|
14
|
+
* validation.
|
|
14
15
|
*
|
|
15
|
-
* For reference, target type `T` must follow such restrictions. Also, if actual
|
|
16
|
-
* header values are different with their promised type `T`,
|
|
17
|
-
* error (status code: 400) would be thrown.
|
|
16
|
+
* For reference, target type `T` must follow such restrictions. Also, if actual
|
|
17
|
+
* HTTP header values are different with their promised type `T`,
|
|
18
|
+
* `BadRequestException` error (status code: 400) would be thrown.
|
|
18
19
|
*
|
|
19
20
|
* 1. Type `T` must be an object type
|
|
20
21
|
* 2. Do not allow dynamic property
|
|
@@ -24,27 +25,28 @@ import { validate_request_headers } from "./internal/validate_request_headers";
|
|
|
24
25
|
* 6. By the way, union type never be not allowed
|
|
25
26
|
* 7. Property `set-cookie` must be array type
|
|
26
27
|
* 8. Those properties cannot be array type
|
|
27
|
-
* - age
|
|
28
|
-
* - authorization
|
|
29
|
-
* - content-length
|
|
30
|
-
* - content-type
|
|
31
|
-
* - etag
|
|
32
|
-
* - expires
|
|
33
|
-
* - from
|
|
34
|
-
* - host
|
|
35
|
-
* - if-modified-since
|
|
36
|
-
* - if-unmodified-since
|
|
37
|
-
* - last-modified
|
|
38
|
-
* - location
|
|
39
|
-
* - max-forwards
|
|
40
|
-
* - proxy-authorization
|
|
41
|
-
* - referer
|
|
42
|
-
* - retry-after
|
|
43
|
-
* - server
|
|
44
|
-
* - user-agent
|
|
45
28
|
*
|
|
46
|
-
*
|
|
29
|
+
* - Age
|
|
30
|
+
* - Authorization
|
|
31
|
+
* - Content-length
|
|
32
|
+
* - Content-type
|
|
33
|
+
* - Etag
|
|
34
|
+
* - Expires
|
|
35
|
+
* - From
|
|
36
|
+
* - Host
|
|
37
|
+
* - If-modified-since
|
|
38
|
+
* - If-unmodified-since
|
|
39
|
+
* - Last-modified
|
|
40
|
+
* - Location
|
|
41
|
+
* - Max-forwards
|
|
42
|
+
* - Proxy-authorization
|
|
43
|
+
* - Referer
|
|
44
|
+
* - Retry-after
|
|
45
|
+
* - Server
|
|
46
|
+
* - User-agent
|
|
47
|
+
*
|
|
47
48
|
* @author Jeongho Nam - https://github.com/samchon
|
|
49
|
+
* @returns Parameter decorator
|
|
48
50
|
*/
|
|
49
51
|
export function TypedHeaders<T extends object>(
|
|
50
52
|
validator?: IRequestHeadersValidator<T>,
|
|
@@ -12,9 +12,10 @@ import { NoTransformConfigurationError } from "./NoTransformConfigurationError";
|
|
|
12
12
|
/**
|
|
13
13
|
* Type safe URL parameter decorator.
|
|
14
14
|
*
|
|
15
|
-
* `TypedParam` is a decorator function getting specific typed parameter from
|
|
16
|
-
* HTTP request URL. It's almost same with the {@link nest.Param}, but
|
|
17
|
-
* automatically casts parameter value to be following its type,
|
|
15
|
+
* `TypedParam` is a decorator function getting specific typed parameter from
|
|
16
|
+
* the HTTP request URL. It's almost same with the {@link nest.Param}, but
|
|
17
|
+
* `TypedParam` automatically casts parameter value to be following its type,
|
|
18
|
+
* and validates it.
|
|
18
19
|
*
|
|
19
20
|
* ```typescript
|
|
20
21
|
* import { tags } from "typia";
|
|
@@ -27,10 +28,9 @@ import { NoTransformConfigurationError } from "./NoTransformConfigurationError";
|
|
|
27
28
|
* ): Promise<void>;
|
|
28
29
|
* ```
|
|
29
30
|
*
|
|
31
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
30
32
|
* @param name URL Parameter name
|
|
31
33
|
* @returns Parameter decorator
|
|
32
|
-
*
|
|
33
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
34
34
|
*/
|
|
35
35
|
export function TypedParam<T extends boolean | bigint | number | string | null>(
|
|
36
36
|
name: string,
|
|
@@ -27,12 +27,13 @@ import { validate_request_query } from "./internal/validate_request_query";
|
|
|
27
27
|
/**
|
|
28
28
|
* Type safe URL query decorator.
|
|
29
29
|
*
|
|
30
|
-
* `TypedQuery` is a decorator function that can parse URL query string. It is
|
|
31
|
-
* same with {@link nest.Query}, but it can automatically cast property
|
|
32
|
-
* its DTO definition. Also, `TypedQuery` performs type
|
|
30
|
+
* `TypedQuery` is a decorator function that can parse URL query string. It is
|
|
31
|
+
* almost same with {@link nest.Query}, but it can automatically cast property
|
|
32
|
+
* type following its DTO definition. Also, `TypedQuery` performs type
|
|
33
|
+
* validation.
|
|
33
34
|
*
|
|
34
|
-
* For reference, target type `T` must follow such restriction. Also, if
|
|
35
|
-
*
|
|
35
|
+
* For reference, target type `T` must follow such restriction. Also, if actual
|
|
36
|
+
* URL query parameter values are different with their promised type `T`,
|
|
36
37
|
* `BadRequestException` error (status code: 400) would be thrown.
|
|
37
38
|
*
|
|
38
39
|
* 1. Type `T` must be an object type
|
|
@@ -40,8 +41,8 @@ import { validate_request_query } from "./internal/validate_request_query";
|
|
|
40
41
|
* 3. Only `boolean`, `bigint`, `number`, `string` or their array types are allowed
|
|
41
42
|
* 4. By the way, union type never be not allowed
|
|
42
43
|
*
|
|
43
|
-
* @returns Parameter decorator
|
|
44
44
|
* @author Jeongho Nam - https://github.com/samchon
|
|
45
|
+
* @returns Parameter decorator
|
|
45
46
|
*/
|
|
46
47
|
export function TypedQuery<T extends object>(
|
|
47
48
|
validator?: IRequestQueryValidator<T>,
|
|
@@ -133,9 +134,7 @@ export namespace TypedQuery {
|
|
|
133
134
|
*/
|
|
134
135
|
export const Delete = Generator("Delete");
|
|
135
136
|
|
|
136
|
-
/**
|
|
137
|
-
* @internal
|
|
138
|
-
*/
|
|
137
|
+
/** @internal */
|
|
139
138
|
function Generator(method: "Get" | "Post" | "Put" | "Patch" | "Delete") {
|
|
140
139
|
function route(path?: string | string[]): MethodDecorator;
|
|
141
140
|
function route<T>(stringify?: IResponseBodyQuerifier<T>): MethodDecorator;
|
|
@@ -167,17 +166,13 @@ export namespace TypedQuery {
|
|
|
167
166
|
(deco as any)[key] = value;
|
|
168
167
|
}
|
|
169
168
|
|
|
170
|
-
/**
|
|
171
|
-
* @internal
|
|
172
|
-
*/
|
|
169
|
+
/** @internal */
|
|
173
170
|
function tail(url: string): string {
|
|
174
171
|
const index: number = url.indexOf("?");
|
|
175
172
|
return index === -1 ? "" : url.substring(index + 1);
|
|
176
173
|
}
|
|
177
174
|
|
|
178
|
-
/**
|
|
179
|
-
* @internal
|
|
180
|
-
*/
|
|
175
|
+
/** @internal */
|
|
181
176
|
function isApplicationQuery(text?: string): boolean {
|
|
182
177
|
return (
|
|
183
178
|
text !== undefined &&
|
|
@@ -188,9 +183,7 @@ function isApplicationQuery(text?: string): boolean {
|
|
|
188
183
|
);
|
|
189
184
|
}
|
|
190
185
|
|
|
191
|
-
/**
|
|
192
|
-
* @internal
|
|
193
|
-
*/
|
|
186
|
+
/** @internal */
|
|
194
187
|
class FakeURLSearchParams {
|
|
195
188
|
public constructor(private readonly target: Record<string, string[]>) {}
|
|
196
189
|
|
|
@@ -213,9 +206,7 @@ class FakeURLSearchParams {
|
|
|
213
206
|
}
|
|
214
207
|
}
|
|
215
208
|
|
|
216
|
-
/**
|
|
217
|
-
* @internal
|
|
218
|
-
*/
|
|
209
|
+
/** @internal */
|
|
219
210
|
class TypedQueryRouteInterceptor implements NestInterceptor {
|
|
220
211
|
public constructor(
|
|
221
212
|
private readonly toSearchParams: (input: any) => URLSearchParams,
|
|
@@ -233,9 +224,7 @@ class TypedQueryRouteInterceptor implements NestInterceptor {
|
|
|
233
224
|
}
|
|
234
225
|
}
|
|
235
226
|
|
|
236
|
-
/**
|
|
237
|
-
* @internal
|
|
238
|
-
*/
|
|
227
|
+
/** @internal */
|
|
239
228
|
const ROUTERS = {
|
|
240
229
|
Get,
|
|
241
230
|
Post,
|
|
@@ -22,15 +22,15 @@ import { route_error } from "./internal/route_error";
|
|
|
22
22
|
/**
|
|
23
23
|
* Type safe router decorator functions.
|
|
24
24
|
*
|
|
25
|
-
* `TypedRoute` is a module containing router decorator functions which can
|
|
26
|
-
* JSON string conversion speed about 200x times faster than
|
|
27
|
-
* Furthermore, such JSON string conversion is even type
|
|
28
|
-
* [typia](https://github.com/samchon/typia).
|
|
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
29
|
*
|
|
30
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
|
-
* JSON string through `typia.assertStringify<T>()` function, it is not
|
|
33
|
-
* modify response data through interceptors.
|
|
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
34
|
*
|
|
35
35
|
* @author Jeongho Nam - https://github.com/samchon
|
|
36
36
|
*/
|
|
@@ -78,18 +78,17 @@ export namespace TypedRoute {
|
|
|
78
78
|
/**
|
|
79
79
|
* Set the logger function for the response validation failure.
|
|
80
80
|
*
|
|
81
|
-
* If you've configured the transformation option to `validate.log`
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
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
85
|
*
|
|
86
|
-
* By the way, be careful. If you've configured the response
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
* backend server case.
|
|
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.
|
|
90
89
|
*
|
|
91
|
-
* @param func Logger function
|
|
92
90
|
* @default console.log
|
|
91
|
+
* @param func Logger function
|
|
93
92
|
*/
|
|
94
93
|
export function setValidateErrorLogger(
|
|
95
94
|
func: (log: IValidateErrorLog) => void,
|
|
@@ -100,47 +99,34 @@ export namespace TypedRoute {
|
|
|
100
99
|
/**
|
|
101
100
|
* Error log information of the response validation failure.
|
|
102
101
|
*
|
|
103
|
-
* `IValidationErrorLog` is a structure representing the error log
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
* the promised type `T`.
|
|
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`.
|
|
107
105
|
*
|
|
108
106
|
* If you've configured the transformation option to `validate.log` or
|
|
109
107
|
* `validateEquals.log` in the `tsconfig.json` file, then this error log
|
|
110
108
|
* information `IValidateErrorLog` would be logged through the
|
|
111
|
-
* {@link setValidateErrorLogger} function instead of throwing the
|
|
112
|
-
*
|
|
109
|
+
* {@link setValidateErrorLogger} function instead of throwing the 400 bad
|
|
110
|
+
* request error.
|
|
113
111
|
*/
|
|
114
112
|
export interface IValidateErrorLog {
|
|
115
|
-
/**
|
|
116
|
-
* HTTP method of the request.
|
|
117
|
-
*/
|
|
113
|
+
/** HTTP method of the request. */
|
|
118
114
|
method: string;
|
|
119
115
|
|
|
120
|
-
/**
|
|
121
|
-
* HTTP path of the request.
|
|
122
|
-
*/
|
|
116
|
+
/** HTTP path of the request. */
|
|
123
117
|
path: string;
|
|
124
118
|
|
|
125
|
-
/**
|
|
126
|
-
* Validation error information with detailed reasons.
|
|
127
|
-
*/
|
|
119
|
+
/** Validation error information with detailed reasons. */
|
|
128
120
|
errors: IValidation.IError[];
|
|
129
121
|
|
|
130
|
-
/**
|
|
131
|
-
* Data that is not following the promised type `T`.
|
|
132
|
-
*/
|
|
122
|
+
/** Data that is not following the promised type `T`. */
|
|
133
123
|
data: unknown;
|
|
134
124
|
}
|
|
135
125
|
|
|
136
|
-
/**
|
|
137
|
-
* @internal
|
|
138
|
-
*/
|
|
126
|
+
/** @internal */
|
|
139
127
|
export let __logger: (log: IValidateErrorLog) => void = console.log;
|
|
140
128
|
|
|
141
|
-
/**
|
|
142
|
-
* @internal
|
|
143
|
-
*/
|
|
129
|
+
/** @internal */
|
|
144
130
|
function Generator(method: "Get" | "Post" | "Put" | "Patch" | "Delete") {
|
|
145
131
|
function route(path?: string | string[]): MethodDecorator;
|
|
146
132
|
function route<T>(stringify?: IResponseBodyStringifier<T>): MethodDecorator;
|
|
@@ -177,9 +163,7 @@ for (const method of [
|
|
|
177
163
|
])
|
|
178
164
|
(deco as any)[key] = value;
|
|
179
165
|
|
|
180
|
-
/**
|
|
181
|
-
* @internal
|
|
182
|
-
*/
|
|
166
|
+
/** @internal */
|
|
183
167
|
class TypedRouteInterceptor implements NestInterceptor {
|
|
184
168
|
public constructor(
|
|
185
169
|
private readonly stringify: (
|
|
@@ -202,9 +186,7 @@ class TypedRouteInterceptor implements NestInterceptor {
|
|
|
202
186
|
}
|
|
203
187
|
}
|
|
204
188
|
|
|
205
|
-
/**
|
|
206
|
-
* @internal
|
|
207
|
-
*/
|
|
189
|
+
/** @internal */
|
|
208
190
|
const ROUTERS = {
|
|
209
191
|
Get,
|
|
210
192
|
Post,
|
|
@@ -8,15 +8,15 @@ import { validate_request_query } from "./internal/validate_request_query";
|
|
|
8
8
|
/**
|
|
9
9
|
* WebSocket route decorator.
|
|
10
10
|
*
|
|
11
|
-
* `@WebSocketRoute()` is a route decorator function for WebSocket routes.
|
|
12
|
-
*
|
|
13
|
-
* please don't forget to call the {@link WebSocketAdaptor.upgrade} function
|
|
14
|
-
*
|
|
11
|
+
* `@WebSocketRoute()` is a route decorator function for WebSocket routes. If
|
|
12
|
+
* you want to define a WebSocket route with this `@WebSocketRoute` decorator,
|
|
13
|
+
* please don't forget to call the {@link WebSocketAdaptor.upgrade} function to
|
|
14
|
+
* the {@link INestApplication} instance.
|
|
15
15
|
*
|
|
16
|
-
* Also, `WebSocketRoute` is a module containing parameter decorator
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
16
|
+
* Also, `WebSocketRoute` is a module containing parameter decorator functions
|
|
17
|
+
* of below for the `@WebSocketRoute` decorated method, at the same time. Note
|
|
18
|
+
* that, every parameters must be decorated by one of the parameter decorators
|
|
19
|
+
* in the `WebSocketRoute` module. One thing more important is,
|
|
20
20
|
* {@link WebSocketRoute.Acceptor} decorated parameter must be defined in the
|
|
21
21
|
* method. If not, it would be both compilation/runtime error.
|
|
22
22
|
*
|
|
@@ -28,16 +28,16 @@ import { validate_request_query } from "./internal/validate_request_query";
|
|
|
28
28
|
*
|
|
29
29
|
* For reference, key difference between `@WebSocketGateway()` of NestJS and
|
|
30
30
|
* `@WebSocketRoute()` of Nestia is, `@WebSocketRoute()` can make multiple
|
|
31
|
-
* WebSocket routes by configuring
|
|
32
|
-
*
|
|
31
|
+
* WebSocket routes by configuring _paths_, besides `@WebSocketGateway()` can't
|
|
32
|
+
* do it.
|
|
33
33
|
*
|
|
34
34
|
* Furthermore, if you build SDK (Software Development Kit) library through
|
|
35
35
|
* `@nestia/sdk`, you can make safe WebSocket client taking advantages of
|
|
36
36
|
* TypeScript type hints and checks.
|
|
37
37
|
*
|
|
38
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
38
39
|
* @param path Path(s) of the WebSocket request
|
|
39
40
|
* @returns Method decorator
|
|
40
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
41
41
|
*/
|
|
42
42
|
export function WebSocketRoute(
|
|
43
43
|
path?: undefined | string | string[],
|
|
@@ -62,7 +62,8 @@ export namespace WebSocketRoute {
|
|
|
62
62
|
* Acceptor parameter decorator.
|
|
63
63
|
*
|
|
64
64
|
* `@WebSocketRoute.Acceptor()` is a parameter decorator function for the
|
|
65
|
-
* `WebSocketAcceptor<Header, Provider, Listener>` (of `tgrid`) typed
|
|
65
|
+
* `WebSocketAcceptor<Header, Provider, Listener>` (of `tgrid`) typed
|
|
66
|
+
* parameter.
|
|
66
67
|
*
|
|
67
68
|
* In the controller method decorated by `@WebSocketRoute()` and
|
|
68
69
|
* `@WebSocketRoute.Acceptor()`, call {@link WebSocketAcceptor.accept} function
|
|
@@ -71,8 +72,8 @@ export namespace WebSocketRoute {
|
|
|
71
72
|
* {@link WebSocketAcceptor.rejcet} function instead.
|
|
72
73
|
*
|
|
73
74
|
* For reference, this `@WebSocketRoute.Acceptor()` parameter decorator is
|
|
74
|
-
* essential for the method decorated by `@WebSocketRoute()` decorator.
|
|
75
|
-
*
|
|
75
|
+
* essential for the method decorated by `@WebSocketRoute()` decorator. If you
|
|
76
|
+
* forget it, it would be both compilation/runtime error.
|
|
76
77
|
*/
|
|
77
78
|
export function Acceptor(): ParameterDecorator {
|
|
78
79
|
return function WebSocketAcceptor(
|
|
@@ -98,8 +99,8 @@ export namespace WebSocketRoute {
|
|
|
98
99
|
* by calling the `Driver<Listener>` instance.
|
|
99
100
|
*
|
|
100
101
|
* For reference, this `@WebSocketRoute.Driver()` decorator is optional, and
|
|
101
|
-
* can be substituted by `@WebSocketRoute.Acceptor()` decorated parameter
|
|
102
|
-
*
|
|
102
|
+
* can be substituted by `@WebSocketRoute.Acceptor()` decorated parameter by
|
|
103
|
+
* calling the {@link WebSocketAcceptor.getDriver} function.
|
|
103
104
|
*/
|
|
104
105
|
export function Driver(): ParameterDecorator {
|
|
105
106
|
return function WebSocketDriver(
|
|
@@ -121,12 +122,12 @@ export namespace WebSocketRoute {
|
|
|
121
122
|
* WebSocket header with type casting and assertion.
|
|
122
123
|
*
|
|
123
124
|
* For reference, `@WebSocketRoute.Header()` is different with HTTP headers.
|
|
124
|
-
* It's for WebSocket protocol, especially for TGrid's
|
|
125
|
-
* and {@link WebSocketAcceptor}'s special header.
|
|
125
|
+
* It's for WebSocket protocol, especially for TGrid's
|
|
126
|
+
* {@link WebSocketConnector} and {@link WebSocketAcceptor}'s special header.
|
|
126
127
|
*
|
|
127
|
-
* Also, this `@WebSocketRoute.Header()` decorator is optional, and
|
|
128
|
-
*
|
|
129
|
-
*
|
|
128
|
+
* Also, this `@WebSocketRoute.Header()` decorator is optional, and can be
|
|
129
|
+
* substituted by `@WebSocketRoute.Acceptor()` decorated parameter by
|
|
130
|
+
* accessting to the {@link WebSocketAcceptor.header} property.
|
|
130
131
|
*/
|
|
131
132
|
export function Header<T>(
|
|
132
133
|
validator?: IRequestBodyValidator<T>,
|
|
@@ -151,9 +152,9 @@ export namespace WebSocketRoute {
|
|
|
151
152
|
* `@WebSocketRoute.Param()` is a parameter decorator function for the URL
|
|
152
153
|
* parameter with type casting and assertion.
|
|
153
154
|
*
|
|
154
|
-
* It's almost same with the {@link TypedParam}, but
|
|
155
|
-
*
|
|
156
|
-
*
|
|
155
|
+
* It's almost same with the {@link TypedParam}, but `@WebSocketRoute.Param()`
|
|
156
|
+
* is only for WebSocket protocol router function decorated by
|
|
157
|
+
* {@link WebSocketRoute}.
|
|
157
158
|
*
|
|
158
159
|
* @param field URL parameter field name
|
|
159
160
|
*/
|
|
@@ -185,18 +186,19 @@ export namespace WebSocketRoute {
|
|
|
185
186
|
* `@WebSocketRoute.Query()` is a parameter decorator function for the URL
|
|
186
187
|
* query string with type casting and assertion.
|
|
187
188
|
*
|
|
188
|
-
* It is almost same with {@link TypedQuery}, but
|
|
189
|
-
*
|
|
190
|
-
*
|
|
189
|
+
* It is almost same with {@link TypedQuery}, but `@WebSocketRoute.Query()` is
|
|
190
|
+
* only for WebSocket protocol router function decorated by
|
|
191
|
+
* {@link WebSocketRoute}.
|
|
191
192
|
*
|
|
192
193
|
* For reference, as same with {@link TypedQuery}, `@WebSocketRoute.Query()`
|
|
193
|
-
* has same restriction for the target type `T`. If actual URL query
|
|
194
|
-
*
|
|
195
|
-
*
|
|
194
|
+
* has same restriction for the target type `T`. If actual URL query parameter
|
|
195
|
+
* values are different with their promised type `T`, it would be runtime
|
|
196
|
+
* error.
|
|
196
197
|
*
|
|
197
198
|
* 1. Type `T` must be an object type
|
|
198
199
|
* 2. Do not allow dynamic property
|
|
199
|
-
* 3. Only `boolean`, `bigint`, `number`, `string` or their array types are
|
|
200
|
+
* 3. Only `boolean`, `bigint`, `number`, `string` or their array types are
|
|
201
|
+
* allowed
|
|
200
202
|
* 4. By the way, union type never be not allowed
|
|
201
203
|
*/
|
|
202
204
|
export function Query<T extends object>(
|
|
@@ -216,9 +218,7 @@ export namespace WebSocketRoute {
|
|
|
216
218
|
};
|
|
217
219
|
}
|
|
218
220
|
|
|
219
|
-
/**
|
|
220
|
-
* @internal
|
|
221
|
-
*/
|
|
221
|
+
/** @internal */
|
|
222
222
|
const emplace = (
|
|
223
223
|
target: Object,
|
|
224
224
|
propertyKey: string | symbol,
|