@nestia/core 2.5.6 → 2.5.7-dev.20240215
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/README.md +1 -1
- package/lib/decorators/EncryptedBody.js +3 -0
- package/lib/decorators/EncryptedBody.js.map +1 -1
- package/lib/decorators/EncryptedModule.js +3 -0
- package/lib/decorators/EncryptedModule.js.map +1 -1
- package/lib/decorators/PlainBody.js +3 -0
- package/lib/decorators/PlainBody.js.map +1 -1
- package/lib/decorators/TypedBody.js +3 -0
- package/lib/decorators/TypedBody.js.map +1 -1
- package/lib/decorators/TypedException.d.ts +0 -1
- package/lib/decorators/TypedException.js +0 -1
- package/lib/decorators/TypedException.js.map +1 -1
- package/lib/decorators/TypedFormData.js +9 -0
- package/lib/decorators/TypedFormData.js.map +1 -1
- package/lib/decorators/internal/get_path_and_querify.js +3 -0
- package/lib/decorators/internal/get_path_and_querify.js.map +1 -1
- package/lib/decorators/internal/validate_request_body.d.ts +1 -3
- package/lib/decorators/internal/validate_request_body.js +15 -0
- package/lib/decorators/internal/validate_request_body.js.map +1 -1
- package/lib/decorators/internal/validate_request_form_data.d.ts +1 -3
- package/lib/decorators/internal/validate_request_form_data.js +15 -0
- package/lib/decorators/internal/validate_request_form_data.js.map +1 -1
- package/lib/decorators/internal/validate_request_headers.d.ts +1 -3
- package/lib/decorators/internal/validate_request_headers.js +15 -0
- package/lib/decorators/internal/validate_request_headers.js.map +1 -1
- package/lib/decorators/internal/validate_request_query.d.ts +1 -3
- package/lib/decorators/internal/validate_request_query.js +15 -0
- package/lib/decorators/internal/validate_request_query.js.map +1 -1
- package/lib/transformers/ParameterDecoratorTransformer.js +1 -1
- package/lib/transformers/ParameterDecoratorTransformer.js.map +1 -1
- package/lib/transformers/TypedExceptionTransformer.js +1 -1
- package/lib/transformers/TypedExceptionTransformer.js.map +1 -1
- package/lib/transformers/TypedRouteTransformer.js +1 -1
- package/lib/transformers/TypedRouteTransformer.js.map +1 -1
- package/package.json +8 -14
- package/src/decorators/EncryptedBody.ts +3 -0
- package/src/decorators/EncryptedModule.ts +3 -0
- package/src/decorators/PlainBody.ts +3 -0
- package/src/decorators/TypedBody.ts +3 -0
- package/src/decorators/TypedException.ts +3 -2
- package/src/decorators/TypedFormData.ts +15 -6
- package/src/decorators/TypedRoute.ts +144 -144
- package/src/decorators/internal/get_path_and_querify.ts +3 -0
- package/src/decorators/internal/load_controller.ts +51 -51
- package/src/decorators/internal/validate_request_body.ts +15 -0
- package/src/decorators/internal/validate_request_form_data.ts +15 -0
- package/src/decorators/internal/validate_request_headers.ts +15 -0
- package/src/decorators/internal/validate_request_query.ts +15 -0
- package/src/transformers/NodeTransformer.ts +16 -16
- package/src/transformers/ParameterDecoratorTransformer.ts +1 -7
- package/src/transformers/TypedExceptionTransformer.ts +0 -1
- package/src/transformers/TypedRouteTransformer.ts +1 -8
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import "reflect-metadata";
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* > You must configure the generic argument `T`
|
|
5
3
|
*
|
|
@@ -82,6 +80,9 @@ export function TypedException<T>(
|
|
|
82
80
|
};
|
|
83
81
|
}
|
|
84
82
|
|
|
83
|
+
/**
|
|
84
|
+
* @internal
|
|
85
|
+
*/
|
|
85
86
|
interface IProps {
|
|
86
87
|
status: number | "2XX" | "3XX" | "4XX" | "5XX";
|
|
87
88
|
description?: string | undefined;
|
|
@@ -35,20 +35,20 @@ import { validate_request_form_data } from "./internal/validate_request_form_dat
|
|
|
35
35
|
* 2. Do not allow dynamic property
|
|
36
36
|
* 3. Only `boolean`, `bigint`, `number`, `string`, `Blob`, `File` or their array types are allowed
|
|
37
37
|
* 4. By the way, union type never be not allowed
|
|
38
|
-
*
|
|
38
|
+
*
|
|
39
39
|
* By the way, if you're using `fastify`, you have to setup `@fastify/multipart`
|
|
40
40
|
* and configure like below when composing the NestJS application. If you don't do
|
|
41
41
|
* that, `@TypedFormData.Body()` will not work properly, and throw 500 internal
|
|
42
42
|
* server error when `Blob` or `File` type being utilized.
|
|
43
|
-
*
|
|
43
|
+
*
|
|
44
44
|
* ```typescript
|
|
45
45
|
* import multipart from "fastify-multipart";
|
|
46
46
|
* import { NestFactory } from "@nestjs/core";
|
|
47
|
-
* import {
|
|
48
|
-
* FastifyAdapter,
|
|
49
|
-
* NestFastifyApplication
|
|
47
|
+
* import {
|
|
48
|
+
* FastifyAdapter,
|
|
49
|
+
* NestFastifyApplication
|
|
50
50
|
* } from "@nestjs/platform-fastify";
|
|
51
|
-
*
|
|
51
|
+
*
|
|
52
52
|
* export async function main() {
|
|
53
53
|
* const app = await NestFactory.create<NestFastifyApplication>(
|
|
54
54
|
* AppModule,
|
|
@@ -108,6 +108,9 @@ export namespace TypedFormData {
|
|
|
108
108
|
Object.assign(Body, typia.http.validateFormData);
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
+
/**
|
|
112
|
+
* @internal
|
|
113
|
+
*/
|
|
111
114
|
const decodeExpress = <T>(props: IRequestFormDataProps<T>) => {
|
|
112
115
|
const upload = multerApplication.get().fields(
|
|
113
116
|
props!.files.map((file) => ({
|
|
@@ -137,6 +140,9 @@ const decodeExpress = <T>(props: IRequestFormDataProps<T>) => {
|
|
|
137
140
|
};
|
|
138
141
|
};
|
|
139
142
|
|
|
143
|
+
/**
|
|
144
|
+
* @internal
|
|
145
|
+
*/
|
|
140
146
|
const decodeFastify =
|
|
141
147
|
<T>(_props: IRequestFormDataProps<T>) =>
|
|
142
148
|
async (socket: {
|
|
@@ -200,6 +206,9 @@ const isMultipartFormData = (text?: string): boolean =>
|
|
|
200
206
|
.map((str) => str.trim())
|
|
201
207
|
.some((str) => str === "multipart/form-data");
|
|
202
208
|
|
|
209
|
+
/**
|
|
210
|
+
* @internal
|
|
211
|
+
*/
|
|
203
212
|
const isExpressRequest = (
|
|
204
213
|
request: express.Request | FastifyRequest,
|
|
205
214
|
): request is express.Request => (request as express.Request).app !== undefined;
|
|
@@ -1,144 +1,144 @@
|
|
|
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 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 boost up
|
|
26
|
-
* JSON string conversion speed about 200x times faster than `class-transformer`.
|
|
27
|
-
* Furthermore, such JSON string conversion is even type safe through
|
|
28
|
-
* [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` composes
|
|
32
|
-
* JSON string through `typia.assertStringify<T>()` function, it is not possible to
|
|
33
|
-
* 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
|
-
* @internal
|
|
80
|
-
*/
|
|
81
|
-
function Generator(method: "Get" | "Post" | "Put" | "Patch" | "Delete") {
|
|
82
|
-
function route(path?: string | string[]): MethodDecorator;
|
|
83
|
-
function route<T>(stringify?: IResponseBodyStringifier<T>): MethodDecorator;
|
|
84
|
-
function route<T>(
|
|
85
|
-
path: string | string[],
|
|
86
|
-
stringify?: IResponseBodyStringifier<T>,
|
|
87
|
-
): MethodDecorator;
|
|
88
|
-
|
|
89
|
-
function route(...args: any[]): MethodDecorator {
|
|
90
|
-
const [path, stringify] = get_path_and_stringify(`TypedRoute.${method}`)(
|
|
91
|
-
...args,
|
|
92
|
-
);
|
|
93
|
-
return applyDecorators(
|
|
94
|
-
ROUTERS[method](path),
|
|
95
|
-
UseInterceptors(new TypedRouteInterceptor(stringify)),
|
|
96
|
-
);
|
|
97
|
-
}
|
|
98
|
-
return route;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
for (const method of [
|
|
102
|
-
typia.json.stringify,
|
|
103
|
-
typia.json.isStringify,
|
|
104
|
-
typia.json.assertStringify,
|
|
105
|
-
typia.json.validateStringify,
|
|
106
|
-
])
|
|
107
|
-
for (const [key, value] of Object.entries(method))
|
|
108
|
-
for (const deco of [
|
|
109
|
-
TypedRoute.Get,
|
|
110
|
-
TypedRoute.Delete,
|
|
111
|
-
TypedRoute.Post,
|
|
112
|
-
TypedRoute.Put,
|
|
113
|
-
TypedRoute.Patch,
|
|
114
|
-
])
|
|
115
|
-
(deco as any)[key] = value;
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* @internal
|
|
119
|
-
*/
|
|
120
|
-
class TypedRouteInterceptor implements NestInterceptor {
|
|
121
|
-
public constructor(private readonly stringify: (input: any) => string) {}
|
|
122
|
-
|
|
123
|
-
public intercept(context: ExecutionContext, next: CallHandler) {
|
|
124
|
-
const http: HttpArgumentsHost = context.switchToHttp();
|
|
125
|
-
const response: express.Response = http.getResponse();
|
|
126
|
-
response.header("Content-Type", "application/json");
|
|
127
|
-
|
|
128
|
-
return next.handle().pipe(
|
|
129
|
-
map((value) => this.stringify(value)),
|
|
130
|
-
catchError((err) => route_error(http.getRequest(), err)),
|
|
131
|
-
);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* @internal
|
|
137
|
-
*/
|
|
138
|
-
const ROUTERS = {
|
|
139
|
-
Get,
|
|
140
|
-
Post,
|
|
141
|
-
Patch,
|
|
142
|
-
Put,
|
|
143
|
-
Delete,
|
|
144
|
-
};
|
|
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 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 boost up
|
|
26
|
+
* JSON string conversion speed about 200x times faster than `class-transformer`.
|
|
27
|
+
* Furthermore, such JSON string conversion is even type safe through
|
|
28
|
+
* [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` composes
|
|
32
|
+
* JSON string through `typia.assertStringify<T>()` function, it is not possible to
|
|
33
|
+
* 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
|
+
* @internal
|
|
80
|
+
*/
|
|
81
|
+
function Generator(method: "Get" | "Post" | "Put" | "Patch" | "Delete") {
|
|
82
|
+
function route(path?: string | string[]): MethodDecorator;
|
|
83
|
+
function route<T>(stringify?: IResponseBodyStringifier<T>): MethodDecorator;
|
|
84
|
+
function route<T>(
|
|
85
|
+
path: string | string[],
|
|
86
|
+
stringify?: IResponseBodyStringifier<T>,
|
|
87
|
+
): MethodDecorator;
|
|
88
|
+
|
|
89
|
+
function route(...args: any[]): MethodDecorator {
|
|
90
|
+
const [path, stringify] = get_path_and_stringify(`TypedRoute.${method}`)(
|
|
91
|
+
...args,
|
|
92
|
+
);
|
|
93
|
+
return applyDecorators(
|
|
94
|
+
ROUTERS[method](path),
|
|
95
|
+
UseInterceptors(new TypedRouteInterceptor(stringify)),
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
return route;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
for (const method of [
|
|
102
|
+
typia.json.stringify,
|
|
103
|
+
typia.json.isStringify,
|
|
104
|
+
typia.json.assertStringify,
|
|
105
|
+
typia.json.validateStringify,
|
|
106
|
+
])
|
|
107
|
+
for (const [key, value] of Object.entries(method))
|
|
108
|
+
for (const deco of [
|
|
109
|
+
TypedRoute.Get,
|
|
110
|
+
TypedRoute.Delete,
|
|
111
|
+
TypedRoute.Post,
|
|
112
|
+
TypedRoute.Put,
|
|
113
|
+
TypedRoute.Patch,
|
|
114
|
+
])
|
|
115
|
+
(deco as any)[key] = value;
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* @internal
|
|
119
|
+
*/
|
|
120
|
+
class TypedRouteInterceptor implements NestInterceptor {
|
|
121
|
+
public constructor(private readonly stringify: (input: any) => string) {}
|
|
122
|
+
|
|
123
|
+
public intercept(context: ExecutionContext, next: CallHandler) {
|
|
124
|
+
const http: HttpArgumentsHost = context.switchToHttp();
|
|
125
|
+
const response: express.Response = http.getResponse();
|
|
126
|
+
response.header("Content-Type", "application/json");
|
|
127
|
+
|
|
128
|
+
return next.handle().pipe(
|
|
129
|
+
map((value) => this.stringify(value)),
|
|
130
|
+
catchError((err) => route_error(http.getRequest(), err)),
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* @internal
|
|
137
|
+
*/
|
|
138
|
+
const ROUTERS = {
|
|
139
|
+
Get,
|
|
140
|
+
Post,
|
|
141
|
+
Patch,
|
|
142
|
+
Put,
|
|
143
|
+
Delete,
|
|
144
|
+
};
|
|
@@ -1,51 +1,51 @@
|
|
|
1
|
-
import is_ts_node from "detect-ts-node";
|
|
2
|
-
|
|
3
|
-
import { Creator } from "../../typings/Creator";
|
|
4
|
-
import { SourceFinder } from "../../utils/SourceFinder";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @internal
|
|
8
|
-
*/
|
|
9
|
-
export const load_controllers = async (
|
|
10
|
-
path: string | string[] | { include: string[]; exclude?: string[] },
|
|
11
|
-
): Promise<Creator<object>[]> => {
|
|
12
|
-
const sources: string[] = await SourceFinder.find({
|
|
13
|
-
include: Array.isArray(path)
|
|
14
|
-
? path
|
|
15
|
-
: typeof path === "object"
|
|
16
|
-
? path.include
|
|
17
|
-
: [path],
|
|
18
|
-
exclude:
|
|
19
|
-
typeof path === "object" && !Array.isArray(path)
|
|
20
|
-
? path.exclude ?? []
|
|
21
|
-
: [],
|
|
22
|
-
filter:
|
|
23
|
-
EXTENSION === "ts"
|
|
24
|
-
? (file) =>
|
|
25
|
-
file.substring(file.length - 3) === ".ts" &&
|
|
26
|
-
file.substring(file.length - 5) !== ".d.ts"
|
|
27
|
-
: (flle) => flle.substring(flle.length - 3) === ".js",
|
|
28
|
-
});
|
|
29
|
-
return mount(sources);
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* @internal
|
|
34
|
-
*/
|
|
35
|
-
async function mount(sources: string[]): Promise<any[]> {
|
|
36
|
-
const controllers: any[] = [];
|
|
37
|
-
for (const file of sources) {
|
|
38
|
-
const external: any = await import(file);
|
|
39
|
-
for (const key in external) {
|
|
40
|
-
const instance: Creator<object> = external[key];
|
|
41
|
-
if (Reflect.getMetadata("path", instance) !== undefined)
|
|
42
|
-
controllers.push(instance);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return controllers;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* @internal
|
|
50
|
-
*/
|
|
51
|
-
const EXTENSION = is_ts_node ? "ts" : "js";
|
|
1
|
+
import is_ts_node from "detect-ts-node";
|
|
2
|
+
|
|
3
|
+
import { Creator } from "../../typings/Creator";
|
|
4
|
+
import { SourceFinder } from "../../utils/SourceFinder";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export const load_controllers = async (
|
|
10
|
+
path: string | string[] | { include: string[]; exclude?: string[] },
|
|
11
|
+
): Promise<Creator<object>[]> => {
|
|
12
|
+
const sources: string[] = await SourceFinder.find({
|
|
13
|
+
include: Array.isArray(path)
|
|
14
|
+
? path
|
|
15
|
+
: typeof path === "object"
|
|
16
|
+
? path.include
|
|
17
|
+
: [path],
|
|
18
|
+
exclude:
|
|
19
|
+
typeof path === "object" && !Array.isArray(path)
|
|
20
|
+
? path.exclude ?? []
|
|
21
|
+
: [],
|
|
22
|
+
filter:
|
|
23
|
+
EXTENSION === "ts"
|
|
24
|
+
? (file) =>
|
|
25
|
+
file.substring(file.length - 3) === ".ts" &&
|
|
26
|
+
file.substring(file.length - 5) !== ".d.ts"
|
|
27
|
+
: (flle) => flle.substring(flle.length - 3) === ".js",
|
|
28
|
+
});
|
|
29
|
+
return mount(sources);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @internal
|
|
34
|
+
*/
|
|
35
|
+
async function mount(sources: string[]): Promise<any[]> {
|
|
36
|
+
const controllers: any[] = [];
|
|
37
|
+
for (const file of sources) {
|
|
38
|
+
const external: any = await import(file);
|
|
39
|
+
for (const key in external) {
|
|
40
|
+
const instance: Creator<object> = external[key];
|
|
41
|
+
if (Reflect.getMetadata("path", instance) !== undefined)
|
|
42
|
+
controllers.push(instance);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return controllers;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @internal
|
|
50
|
+
*/
|
|
51
|
+
const EXTENSION = is_ts_node ? "ts" : "js";
|
|
@@ -4,6 +4,9 @@ import typia, { IValidation, TypeGuardError } from "typia";
|
|
|
4
4
|
import { IRequestBodyValidator } from "../../options/IRequestBodyValidator";
|
|
5
5
|
import { NoTransformConfigureError } from "./NoTransformConfigureError";
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
7
10
|
export const validate_request_body =
|
|
8
11
|
(method: string) =>
|
|
9
12
|
<T>(validator?: IRequestBodyValidator<T>) => {
|
|
@@ -15,6 +18,9 @@ export const validate_request_body =
|
|
|
15
18
|
new Error(`Error on nestia.core.${method}(): invalid typed validator.`);
|
|
16
19
|
};
|
|
17
20
|
|
|
21
|
+
/**
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
18
24
|
const assert =
|
|
19
25
|
<T>(closure: (data: T) => T) =>
|
|
20
26
|
(input: T) => {
|
|
@@ -35,6 +41,9 @@ const assert =
|
|
|
35
41
|
}
|
|
36
42
|
};
|
|
37
43
|
|
|
44
|
+
/**
|
|
45
|
+
* @internal
|
|
46
|
+
*/
|
|
38
47
|
const is =
|
|
39
48
|
<T>(closure: (data: T) => boolean) =>
|
|
40
49
|
(input: T) => {
|
|
@@ -42,6 +51,9 @@ const is =
|
|
|
42
51
|
return success ? null : new BadRequestException(MESSAGE);
|
|
43
52
|
};
|
|
44
53
|
|
|
54
|
+
/**
|
|
55
|
+
* @internal
|
|
56
|
+
*/
|
|
45
57
|
const validate =
|
|
46
58
|
<T>(closure: (data: T) => IValidation<T>) =>
|
|
47
59
|
(input: T) => {
|
|
@@ -54,4 +66,7 @@ const validate =
|
|
|
54
66
|
});
|
|
55
67
|
};
|
|
56
68
|
|
|
69
|
+
/**
|
|
70
|
+
* @internal
|
|
71
|
+
*/
|
|
57
72
|
const MESSAGE = "Request body data is not following the promised type.";
|
|
@@ -4,6 +4,9 @@ import typia, { IValidation, TypeGuardError } from "typia";
|
|
|
4
4
|
import { IRequestFormDataProps } from "../../options/IRequestFormDataProps";
|
|
5
5
|
import { NoTransformConfigureError } from "./NoTransformConfigureError";
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
7
10
|
export const validate_request_form_data = <T>(
|
|
8
11
|
props?: IRequestFormDataProps<T>,
|
|
9
12
|
) => {
|
|
@@ -19,6 +22,9 @@ export const validate_request_form_data = <T>(
|
|
|
19
22
|
);
|
|
20
23
|
};
|
|
21
24
|
|
|
25
|
+
/**
|
|
26
|
+
* @internal
|
|
27
|
+
*/
|
|
22
28
|
const assert =
|
|
23
29
|
<T>(closure: (input: FormData) => T) =>
|
|
24
30
|
(input: FormData): T | BadRequestException => {
|
|
@@ -38,6 +44,9 @@ const assert =
|
|
|
38
44
|
}
|
|
39
45
|
};
|
|
40
46
|
|
|
47
|
+
/**
|
|
48
|
+
* @internal
|
|
49
|
+
*/
|
|
41
50
|
const is =
|
|
42
51
|
<T>(closure: (input: FormData) => T | null) =>
|
|
43
52
|
(input: FormData): T | BadRequestException => {
|
|
@@ -45,6 +54,9 @@ const is =
|
|
|
45
54
|
return result !== null ? result : new BadRequestException(MESSAGE);
|
|
46
55
|
};
|
|
47
56
|
|
|
57
|
+
/**
|
|
58
|
+
* @internal
|
|
59
|
+
*/
|
|
48
60
|
const validate =
|
|
49
61
|
<T>(closure: (input: FormData) => IValidation<T>) =>
|
|
50
62
|
(input: FormData): T | BadRequestException => {
|
|
@@ -57,4 +69,7 @@ const validate =
|
|
|
57
69
|
});
|
|
58
70
|
};
|
|
59
71
|
|
|
72
|
+
/**
|
|
73
|
+
* @internal
|
|
74
|
+
*/
|
|
60
75
|
const MESSAGE = "Request multipart data is not following the promised type.";
|
|
@@ -4,6 +4,9 @@ import typia, { IValidation, TypeGuardError } from "typia";
|
|
|
4
4
|
import { IRequestHeadersValidator } from "../../options/IRequestHeadersValidator";
|
|
5
5
|
import { NoTransformConfigureError } from "./NoTransformConfigureError";
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
7
10
|
export const validate_request_headers = <T>(
|
|
8
11
|
validator?: IRequestHeadersValidator<T>,
|
|
9
12
|
) => {
|
|
@@ -15,6 +18,9 @@ export const validate_request_headers = <T>(
|
|
|
15
18
|
new Error(`Error on nestia.core.TypedHeaders(): invalid typed validator.`);
|
|
16
19
|
};
|
|
17
20
|
|
|
21
|
+
/**
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
18
24
|
const assert =
|
|
19
25
|
<T>(closure: (input: Record<string, string | string[] | undefined>) => T) =>
|
|
20
26
|
(
|
|
@@ -36,6 +42,9 @@ const assert =
|
|
|
36
42
|
}
|
|
37
43
|
};
|
|
38
44
|
|
|
45
|
+
/**
|
|
46
|
+
* @internal
|
|
47
|
+
*/
|
|
39
48
|
const is =
|
|
40
49
|
<T>(
|
|
41
50
|
closure: (input: Record<string, string | string[] | undefined>) => T | null,
|
|
@@ -47,6 +56,9 @@ const is =
|
|
|
47
56
|
return result !== null ? result : new BadRequestException(MESSAGE);
|
|
48
57
|
};
|
|
49
58
|
|
|
59
|
+
/**
|
|
60
|
+
* @internal
|
|
61
|
+
*/
|
|
50
62
|
const validate =
|
|
51
63
|
<T>(
|
|
52
64
|
closure: (
|
|
@@ -65,4 +77,7 @@ const validate =
|
|
|
65
77
|
});
|
|
66
78
|
};
|
|
67
79
|
|
|
80
|
+
/**
|
|
81
|
+
* @internal
|
|
82
|
+
*/
|
|
68
83
|
const MESSAGE = "Request headers data is not following the promised type.";
|
|
@@ -4,6 +4,9 @@ import typia, { IValidation, TypeGuardError } from "typia";
|
|
|
4
4
|
import { IRequestQueryValidator } from "../../options/IRequestQueryValidator";
|
|
5
5
|
import { NoTransformConfigureError } from "./NoTransformConfigureError";
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
7
10
|
export const validate_request_query = <T>(
|
|
8
11
|
validator?: IRequestQueryValidator<T>,
|
|
9
12
|
) => {
|
|
@@ -15,6 +18,9 @@ export const validate_request_query = <T>(
|
|
|
15
18
|
new Error(`Error on nestia.core.TypedQuery(): invalid typed validator.`);
|
|
16
19
|
};
|
|
17
20
|
|
|
21
|
+
/**
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
18
24
|
const assert =
|
|
19
25
|
<T>(closure: (input: URLSearchParams) => T) =>
|
|
20
26
|
(input: URLSearchParams): T | BadRequestException => {
|
|
@@ -34,6 +40,9 @@ const assert =
|
|
|
34
40
|
}
|
|
35
41
|
};
|
|
36
42
|
|
|
43
|
+
/**
|
|
44
|
+
* @internal
|
|
45
|
+
*/
|
|
37
46
|
const is =
|
|
38
47
|
<T>(closure: (input: URLSearchParams) => T | null) =>
|
|
39
48
|
(input: URLSearchParams): T | BadRequestException => {
|
|
@@ -41,6 +50,9 @@ const is =
|
|
|
41
50
|
return result !== null ? result : new BadRequestException(MESSAGE);
|
|
42
51
|
};
|
|
43
52
|
|
|
53
|
+
/**
|
|
54
|
+
* @internal
|
|
55
|
+
*/
|
|
44
56
|
const validate =
|
|
45
57
|
<T>(closure: (input: URLSearchParams) => IValidation<T>) =>
|
|
46
58
|
(input: URLSearchParams): T | BadRequestException => {
|
|
@@ -53,4 +65,7 @@ const validate =
|
|
|
53
65
|
});
|
|
54
66
|
};
|
|
55
67
|
|
|
68
|
+
/**
|
|
69
|
+
* @internal
|
|
70
|
+
*/
|
|
56
71
|
const MESSAGE = "Request query data is not following the promised type.";
|