@nestia/core 2.6.3-dev.20240328 → 2.6.3
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/package.json +3 -3
- package/src/decorators/EncryptedBody.ts +105 -105
- package/src/decorators/EncryptedModule.ts +96 -96
- package/src/decorators/PlainBody.ts +75 -75
- package/src/decorators/SwaggerCustomizer.ts +116 -116
- package/src/decorators/TypedBody.ts +62 -62
- package/src/decorators/TypedException.ts +90 -90
- package/src/decorators/TypedFormData.ts +219 -219
- package/src/decorators/TypedQuery.ts +251 -251
- package/src/decorators/TypedRoute.ts +144 -144
- package/src/decorators/internal/get_path_and_querify.ts +106 -106
- package/src/decorators/internal/load_controller.ts +51 -51
- package/src/decorators/internal/validate_request_body.ts +72 -72
- package/src/decorators/internal/validate_request_form_data.ts +75 -75
- package/src/decorators/internal/validate_request_headers.ts +83 -83
- package/src/decorators/internal/validate_request_query.ts +71 -71
- package/src/module.ts +16 -16
- package/src/options/IRequestFormDataProps.ts +27 -27
- package/src/programmers/PlainBodyProgrammer.ts +52 -52
- package/src/programmers/TypedExceptionProgrammer.ts +71 -71
- package/src/programmers/TypedFormDataBodyProgrammer.ts +108 -108
- package/src/programmers/http/HttpQuerifyProgrammer.ts +96 -96
- package/src/structures/ISwagger.ts +91 -91
- package/src/structures/ISwaggerComponents.ts +29 -29
- package/src/structures/ISwaggerInfo.ts +80 -80
- package/src/structures/ISwaggerRoute.ts +50 -50
- package/src/structures/ISwaggerSecurityScheme.ts +65 -65
- package/src/transformers/NodeTransformer.ts +16 -16
- package/src/transformers/ParameterDecoratorTransformer.ts +120 -120
- package/src/transformers/TypedExceptionTransformer.ts +48 -48
- package/src/transformers/TypedRouteTransformer.ts +88 -88
- package/src/utils/Singleton.ts +20 -20
|
@@ -1,116 +1,116 @@
|
|
|
1
|
-
import { ISwagger } from "../structures/ISwagger";
|
|
2
|
-
import { ISwaggerRoute } from "../structures/ISwaggerRoute";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Swagger customization decorator.
|
|
6
|
-
*
|
|
7
|
-
* `SwaggerCustomizer` is a method decorator function which can used for
|
|
8
|
-
* customizing the swagger data with `npx nestia swagger` command. Furthermore,
|
|
9
|
-
* it is possible to add plugin properties starting with `x-` characters.
|
|
10
|
-
*
|
|
11
|
-
* In other words, this decorator function does not affect to the runtime,
|
|
12
|
-
* but only for the swagger data customization.
|
|
13
|
-
*
|
|
14
|
-
* @param closure Callback function which can customize the swagger data
|
|
15
|
-
* @returns Method decorator
|
|
16
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
17
|
-
*/
|
|
18
|
-
export function SwaggerCustomizer(
|
|
19
|
-
closure: (props: SwaggerCustomizer.IProps) => unknown,
|
|
20
|
-
): MethodDecorator {
|
|
21
|
-
return function SwaggerCustomizer(
|
|
22
|
-
target: Object,
|
|
23
|
-
propertyKey: string | symbol,
|
|
24
|
-
descriptor: TypedPropertyDescriptor<any>,
|
|
25
|
-
) {
|
|
26
|
-
const array: Array<(props: SwaggerCustomizer.IProps) => unknown> = (() => {
|
|
27
|
-
if (Reflect.hasMetadata("nestia/SwaggerCustomizer", target, propertyKey))
|
|
28
|
-
return Reflect.getMetadata(
|
|
29
|
-
"nestia/SwaggerCustomizer",
|
|
30
|
-
target,
|
|
31
|
-
propertyKey,
|
|
32
|
-
);
|
|
33
|
-
const array: Array<(props: SwaggerCustomizer.IProps) => unknown> = [];
|
|
34
|
-
Reflect.defineMetadata(
|
|
35
|
-
"nestia/SwaggerCustomizer",
|
|
36
|
-
array,
|
|
37
|
-
target,
|
|
38
|
-
propertyKey,
|
|
39
|
-
);
|
|
40
|
-
return array;
|
|
41
|
-
})();
|
|
42
|
-
array.push(closure);
|
|
43
|
-
return descriptor;
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
export namespace SwaggerCustomizer {
|
|
47
|
-
/**
|
|
48
|
-
* Properties for the `SwaggerCustomizer` decorator.
|
|
49
|
-
*
|
|
50
|
-
* `SwaggerCustomizer.IProps` is a type for the `closure` parameter of the
|
|
51
|
-
* `SwaggerCustomizer` decorator. It's a callback function which can customize
|
|
52
|
-
* the swagger data.
|
|
53
|
-
*/
|
|
54
|
-
export interface IProps {
|
|
55
|
-
/**
|
|
56
|
-
* Swagger data.
|
|
57
|
-
*/
|
|
58
|
-
swagger: ISwagger;
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Method of the route.
|
|
62
|
-
*/
|
|
63
|
-
method: string;
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Path of the route.
|
|
67
|
-
*/
|
|
68
|
-
path: string;
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Route data.
|
|
72
|
-
*/
|
|
73
|
-
route: ISwaggerRoute;
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Get neighbor endpoint data through the controller method.
|
|
77
|
-
*
|
|
78
|
-
* @param func Controller method to find the neighbor endpoint
|
|
79
|
-
* @returns Neighbor endpoint data
|
|
80
|
-
*/
|
|
81
|
-
at(func: Function): ISwaggerEndpoint | undefined;
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Get neighbor route data.
|
|
85
|
-
*
|
|
86
|
-
* @param accessor Accessor for getting neighbor route data
|
|
87
|
-
* @returns Neighbor route data
|
|
88
|
-
*/
|
|
89
|
-
get(accessor: IAccessor): ISwaggerRoute | undefined;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Accessor for getting neighbor route data.
|
|
94
|
-
*/
|
|
95
|
-
export interface IAccessor {
|
|
96
|
-
/**
|
|
97
|
-
* Path of the neighbor route.
|
|
98
|
-
*/
|
|
99
|
-
path: string;
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Method of the neighbor route.
|
|
103
|
-
*/
|
|
104
|
-
method: string;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Endpoint info of the route.
|
|
109
|
-
*/
|
|
110
|
-
export interface ISwaggerEndpoint extends IAccessor {
|
|
111
|
-
/**
|
|
112
|
-
* Route data.
|
|
113
|
-
*/
|
|
114
|
-
route: ISwaggerRoute;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
1
|
+
import { ISwagger } from "../structures/ISwagger";
|
|
2
|
+
import { ISwaggerRoute } from "../structures/ISwaggerRoute";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Swagger customization decorator.
|
|
6
|
+
*
|
|
7
|
+
* `SwaggerCustomizer` is a method decorator function which can used for
|
|
8
|
+
* customizing the swagger data with `npx nestia swagger` command. Furthermore,
|
|
9
|
+
* it is possible to add plugin properties starting with `x-` characters.
|
|
10
|
+
*
|
|
11
|
+
* In other words, this decorator function does not affect to the runtime,
|
|
12
|
+
* but only for the swagger data customization.
|
|
13
|
+
*
|
|
14
|
+
* @param closure Callback function which can customize the swagger data
|
|
15
|
+
* @returns Method decorator
|
|
16
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
17
|
+
*/
|
|
18
|
+
export function SwaggerCustomizer(
|
|
19
|
+
closure: (props: SwaggerCustomizer.IProps) => unknown,
|
|
20
|
+
): MethodDecorator {
|
|
21
|
+
return function SwaggerCustomizer(
|
|
22
|
+
target: Object,
|
|
23
|
+
propertyKey: string | symbol,
|
|
24
|
+
descriptor: TypedPropertyDescriptor<any>,
|
|
25
|
+
) {
|
|
26
|
+
const array: Array<(props: SwaggerCustomizer.IProps) => unknown> = (() => {
|
|
27
|
+
if (Reflect.hasMetadata("nestia/SwaggerCustomizer", target, propertyKey))
|
|
28
|
+
return Reflect.getMetadata(
|
|
29
|
+
"nestia/SwaggerCustomizer",
|
|
30
|
+
target,
|
|
31
|
+
propertyKey,
|
|
32
|
+
);
|
|
33
|
+
const array: Array<(props: SwaggerCustomizer.IProps) => unknown> = [];
|
|
34
|
+
Reflect.defineMetadata(
|
|
35
|
+
"nestia/SwaggerCustomizer",
|
|
36
|
+
array,
|
|
37
|
+
target,
|
|
38
|
+
propertyKey,
|
|
39
|
+
);
|
|
40
|
+
return array;
|
|
41
|
+
})();
|
|
42
|
+
array.push(closure);
|
|
43
|
+
return descriptor;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
export namespace SwaggerCustomizer {
|
|
47
|
+
/**
|
|
48
|
+
* Properties for the `SwaggerCustomizer` decorator.
|
|
49
|
+
*
|
|
50
|
+
* `SwaggerCustomizer.IProps` is a type for the `closure` parameter of the
|
|
51
|
+
* `SwaggerCustomizer` decorator. It's a callback function which can customize
|
|
52
|
+
* the swagger data.
|
|
53
|
+
*/
|
|
54
|
+
export interface IProps {
|
|
55
|
+
/**
|
|
56
|
+
* Swagger data.
|
|
57
|
+
*/
|
|
58
|
+
swagger: ISwagger;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Method of the route.
|
|
62
|
+
*/
|
|
63
|
+
method: string;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Path of the route.
|
|
67
|
+
*/
|
|
68
|
+
path: string;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Route data.
|
|
72
|
+
*/
|
|
73
|
+
route: ISwaggerRoute;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Get neighbor endpoint data through the controller method.
|
|
77
|
+
*
|
|
78
|
+
* @param func Controller method to find the neighbor endpoint
|
|
79
|
+
* @returns Neighbor endpoint data
|
|
80
|
+
*/
|
|
81
|
+
at(func: Function): ISwaggerEndpoint | undefined;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Get neighbor route data.
|
|
85
|
+
*
|
|
86
|
+
* @param accessor Accessor for getting neighbor route data
|
|
87
|
+
* @returns Neighbor route data
|
|
88
|
+
*/
|
|
89
|
+
get(accessor: IAccessor): ISwaggerRoute | undefined;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Accessor for getting neighbor route data.
|
|
94
|
+
*/
|
|
95
|
+
export interface IAccessor {
|
|
96
|
+
/**
|
|
97
|
+
* Path of the neighbor route.
|
|
98
|
+
*/
|
|
99
|
+
path: string;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Method of the neighbor route.
|
|
103
|
+
*/
|
|
104
|
+
method: string;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Endpoint info of the route.
|
|
109
|
+
*/
|
|
110
|
+
export interface ISwaggerEndpoint extends IAccessor {
|
|
111
|
+
/**
|
|
112
|
+
* Route data.
|
|
113
|
+
*/
|
|
114
|
+
route: ISwaggerRoute;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
@@ -1,62 +1,62 @@
|
|
|
1
|
-
import {
|
|
2
|
-
BadRequestException,
|
|
3
|
-
ExecutionContext,
|
|
4
|
-
createParamDecorator,
|
|
5
|
-
} from "@nestjs/common";
|
|
6
|
-
import type express from "express";
|
|
7
|
-
import type { FastifyRequest } from "fastify";
|
|
8
|
-
import { assert, is, misc, validate } from "typia";
|
|
9
|
-
|
|
10
|
-
import { IRequestBodyValidator } from "../options/IRequestBodyValidator";
|
|
11
|
-
import { validate_request_body } from "./internal/validate_request_body";
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Type safe body decorator.
|
|
15
|
-
*
|
|
16
|
-
* `TypedBody` is a decorator function getting `application/json` typed data from
|
|
17
|
-
* request body. Also, it validates the request body data type through
|
|
18
|
-
* [typia](https://github.com/samchon/typia) and the validation speed is
|
|
19
|
-
* maximum 20,000x times faster than `class-validator`.
|
|
20
|
-
*
|
|
21
|
-
* For reference, when the request body data is not following the promised type `T`,
|
|
22
|
-
* `BadRequestException` error (status code: 400) would be thrown.
|
|
23
|
-
*
|
|
24
|
-
* @param validator Custom validator if required. Default is `typia.assert()`
|
|
25
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
26
|
-
*/
|
|
27
|
-
export function TypedBody<T>(
|
|
28
|
-
validator?: IRequestBodyValidator<T>,
|
|
29
|
-
): ParameterDecorator {
|
|
30
|
-
const checker = validate_request_body("TypedBody")(validator);
|
|
31
|
-
return createParamDecorator(function TypedBody(
|
|
32
|
-
_unknown: any,
|
|
33
|
-
context: ExecutionContext,
|
|
34
|
-
) {
|
|
35
|
-
const request: express.Request | FastifyRequest = context
|
|
36
|
-
.switchToHttp()
|
|
37
|
-
.getRequest();
|
|
38
|
-
if (isApplicationJson(request.headers["content-type"]) === false)
|
|
39
|
-
throw new BadRequestException(
|
|
40
|
-
`Request body type is not "application/json".`,
|
|
41
|
-
);
|
|
42
|
-
|
|
43
|
-
const error: Error | null = checker(request.body);
|
|
44
|
-
if (error !== null) throw error;
|
|
45
|
-
return request.body;
|
|
46
|
-
})();
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
Object.assign(TypedBody, misc.clone);
|
|
50
|
-
Object.assign(TypedBody, is);
|
|
51
|
-
Object.assign(TypedBody, assert);
|
|
52
|
-
Object.assign(TypedBody, validate);
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* @internal
|
|
56
|
-
*/
|
|
57
|
-
const isApplicationJson = (text?: string): boolean =>
|
|
58
|
-
text !== undefined &&
|
|
59
|
-
text
|
|
60
|
-
.split(";")
|
|
61
|
-
.map((str) => str.trim())
|
|
62
|
-
.some((str) => str === "application/json");
|
|
1
|
+
import {
|
|
2
|
+
BadRequestException,
|
|
3
|
+
ExecutionContext,
|
|
4
|
+
createParamDecorator,
|
|
5
|
+
} from "@nestjs/common";
|
|
6
|
+
import type express from "express";
|
|
7
|
+
import type { FastifyRequest } from "fastify";
|
|
8
|
+
import { assert, is, misc, validate } from "typia";
|
|
9
|
+
|
|
10
|
+
import { IRequestBodyValidator } from "../options/IRequestBodyValidator";
|
|
11
|
+
import { validate_request_body } from "./internal/validate_request_body";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Type safe body decorator.
|
|
15
|
+
*
|
|
16
|
+
* `TypedBody` is a decorator function getting `application/json` typed data from
|
|
17
|
+
* request body. Also, it validates the request body data type through
|
|
18
|
+
* [typia](https://github.com/samchon/typia) and the validation speed is
|
|
19
|
+
* maximum 20,000x times faster than `class-validator`.
|
|
20
|
+
*
|
|
21
|
+
* For reference, when the request body data is not following the promised type `T`,
|
|
22
|
+
* `BadRequestException` error (status code: 400) would be thrown.
|
|
23
|
+
*
|
|
24
|
+
* @param validator Custom validator if required. Default is `typia.assert()`
|
|
25
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
26
|
+
*/
|
|
27
|
+
export function TypedBody<T>(
|
|
28
|
+
validator?: IRequestBodyValidator<T>,
|
|
29
|
+
): ParameterDecorator {
|
|
30
|
+
const checker = validate_request_body("TypedBody")(validator);
|
|
31
|
+
return createParamDecorator(function TypedBody(
|
|
32
|
+
_unknown: any,
|
|
33
|
+
context: ExecutionContext,
|
|
34
|
+
) {
|
|
35
|
+
const request: express.Request | FastifyRequest = context
|
|
36
|
+
.switchToHttp()
|
|
37
|
+
.getRequest();
|
|
38
|
+
if (isApplicationJson(request.headers["content-type"]) === false)
|
|
39
|
+
throw new BadRequestException(
|
|
40
|
+
`Request body type is not "application/json".`,
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
const error: Error | null = checker(request.body);
|
|
44
|
+
if (error !== null) throw error;
|
|
45
|
+
return request.body;
|
|
46
|
+
})();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
Object.assign(TypedBody, misc.clone);
|
|
50
|
+
Object.assign(TypedBody, is);
|
|
51
|
+
Object.assign(TypedBody, assert);
|
|
52
|
+
Object.assign(TypedBody, validate);
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @internal
|
|
56
|
+
*/
|
|
57
|
+
const isApplicationJson = (text?: string): boolean =>
|
|
58
|
+
text !== undefined &&
|
|
59
|
+
text
|
|
60
|
+
.split(";")
|
|
61
|
+
.map((str) => str.trim())
|
|
62
|
+
.some((str) => str === "application/json");
|
|
@@ -1,90 +1,90 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* > You must configure the generic argument `T`
|
|
3
|
-
*
|
|
4
|
-
* Exception decorator.
|
|
5
|
-
*
|
|
6
|
-
* `TypedException` is a decorator function describing HTTP exception and its type
|
|
7
|
-
* which could be occured in the method.
|
|
8
|
-
*
|
|
9
|
-
* For reference, this decorator function does not affect to the method's behavior,
|
|
10
|
-
* but only affects to the swagger documents generation. Also, it does not affect to
|
|
11
|
-
* the SDK library generation yet, but will be used in the future.
|
|
12
|
-
*
|
|
13
|
-
* @param status Status number or pattern like "2XX", "3XX", "4XX", "5XX"
|
|
14
|
-
* @param description Description about the exception
|
|
15
|
-
* @returns Method decorator
|
|
16
|
-
*
|
|
17
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
18
|
-
*/
|
|
19
|
-
export function TypedException(
|
|
20
|
-
status: number | "2XX" | "3XX" | "4XX" | "5XX",
|
|
21
|
-
description?: string | undefined,
|
|
22
|
-
): never;
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Exception decorator.
|
|
26
|
-
*
|
|
27
|
-
* `TypedException` is a decorator function describing HTTP exception and its type
|
|
28
|
-
* which could be occured in the method.
|
|
29
|
-
*
|
|
30
|
-
* For reference, this decorator function does not affect to the method's behavior,
|
|
31
|
-
* but only affects to the swagger documents generation. Also, it does not affect to
|
|
32
|
-
* the SDK library generation yet, but will be used in the future.
|
|
33
|
-
*
|
|
34
|
-
* @template T Type of the exception
|
|
35
|
-
* @param status Status number or pattern like "2XX", "3XX", "4XX", "5XX"
|
|
36
|
-
* @param description Description about the exception
|
|
37
|
-
* @returns Method decorator
|
|
38
|
-
*
|
|
39
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
40
|
-
*/
|
|
41
|
-
export function TypedException<T>(
|
|
42
|
-
status: number | "2XX" | "3XX" | "4XX" | "5XX",
|
|
43
|
-
description?: string | undefined,
|
|
44
|
-
): MethodDecorator;
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* @internal
|
|
48
|
-
*/
|
|
49
|
-
export function TypedException<T>(
|
|
50
|
-
status: number | "2XX" | "3XX" | "4XX" | "5XX",
|
|
51
|
-
description?: string | undefined,
|
|
52
|
-
type?: string | undefined,
|
|
53
|
-
): MethodDecorator {
|
|
54
|
-
return function TypedException(
|
|
55
|
-
target: Object | T,
|
|
56
|
-
propertyKey: string | symbol,
|
|
57
|
-
descriptor: TypedPropertyDescriptor<any>,
|
|
58
|
-
) {
|
|
59
|
-
const array: IProps[] = (() => {
|
|
60
|
-
const oldbie: IProps[] | undefined = Reflect.getMetadata(
|
|
61
|
-
"nestia/TypedException",
|
|
62
|
-
(target as any)[propertyKey],
|
|
63
|
-
);
|
|
64
|
-
if (oldbie !== undefined) return oldbie;
|
|
65
|
-
|
|
66
|
-
const newbie: IProps[] = [];
|
|
67
|
-
Reflect.defineMetadata(
|
|
68
|
-
"nestia/TypedException",
|
|
69
|
-
newbie,
|
|
70
|
-
(target as any)[propertyKey],
|
|
71
|
-
);
|
|
72
|
-
return newbie;
|
|
73
|
-
})();
|
|
74
|
-
array.push({
|
|
75
|
-
status,
|
|
76
|
-
description,
|
|
77
|
-
type: type!,
|
|
78
|
-
});
|
|
79
|
-
return descriptor;
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* @internal
|
|
85
|
-
*/
|
|
86
|
-
interface IProps {
|
|
87
|
-
status: number | "2XX" | "3XX" | "4XX" | "5XX";
|
|
88
|
-
description?: string | undefined;
|
|
89
|
-
type: string;
|
|
90
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* > You must configure the generic argument `T`
|
|
3
|
+
*
|
|
4
|
+
* Exception decorator.
|
|
5
|
+
*
|
|
6
|
+
* `TypedException` is a decorator function describing HTTP exception and its type
|
|
7
|
+
* which could be occured in the method.
|
|
8
|
+
*
|
|
9
|
+
* For reference, this decorator function does not affect to the method's behavior,
|
|
10
|
+
* but only affects to the swagger documents generation. Also, it does not affect to
|
|
11
|
+
* the SDK library generation yet, but will be used in the future.
|
|
12
|
+
*
|
|
13
|
+
* @param status Status number or pattern like "2XX", "3XX", "4XX", "5XX"
|
|
14
|
+
* @param description Description about the exception
|
|
15
|
+
* @returns Method decorator
|
|
16
|
+
*
|
|
17
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
18
|
+
*/
|
|
19
|
+
export function TypedException(
|
|
20
|
+
status: number | "2XX" | "3XX" | "4XX" | "5XX",
|
|
21
|
+
description?: string | undefined,
|
|
22
|
+
): never;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Exception decorator.
|
|
26
|
+
*
|
|
27
|
+
* `TypedException` is a decorator function describing HTTP exception and its type
|
|
28
|
+
* which could be occured in the method.
|
|
29
|
+
*
|
|
30
|
+
* For reference, this decorator function does not affect to the method's behavior,
|
|
31
|
+
* but only affects to the swagger documents generation. Also, it does not affect to
|
|
32
|
+
* the SDK library generation yet, but will be used in the future.
|
|
33
|
+
*
|
|
34
|
+
* @template T Type of the exception
|
|
35
|
+
* @param status Status number or pattern like "2XX", "3XX", "4XX", "5XX"
|
|
36
|
+
* @param description Description about the exception
|
|
37
|
+
* @returns Method decorator
|
|
38
|
+
*
|
|
39
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
40
|
+
*/
|
|
41
|
+
export function TypedException<T>(
|
|
42
|
+
status: number | "2XX" | "3XX" | "4XX" | "5XX",
|
|
43
|
+
description?: string | undefined,
|
|
44
|
+
): MethodDecorator;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @internal
|
|
48
|
+
*/
|
|
49
|
+
export function TypedException<T>(
|
|
50
|
+
status: number | "2XX" | "3XX" | "4XX" | "5XX",
|
|
51
|
+
description?: string | undefined,
|
|
52
|
+
type?: string | undefined,
|
|
53
|
+
): MethodDecorator {
|
|
54
|
+
return function TypedException(
|
|
55
|
+
target: Object | T,
|
|
56
|
+
propertyKey: string | symbol,
|
|
57
|
+
descriptor: TypedPropertyDescriptor<any>,
|
|
58
|
+
) {
|
|
59
|
+
const array: IProps[] = (() => {
|
|
60
|
+
const oldbie: IProps[] | undefined = Reflect.getMetadata(
|
|
61
|
+
"nestia/TypedException",
|
|
62
|
+
(target as any)[propertyKey],
|
|
63
|
+
);
|
|
64
|
+
if (oldbie !== undefined) return oldbie;
|
|
65
|
+
|
|
66
|
+
const newbie: IProps[] = [];
|
|
67
|
+
Reflect.defineMetadata(
|
|
68
|
+
"nestia/TypedException",
|
|
69
|
+
newbie,
|
|
70
|
+
(target as any)[propertyKey],
|
|
71
|
+
);
|
|
72
|
+
return newbie;
|
|
73
|
+
})();
|
|
74
|
+
array.push({
|
|
75
|
+
status,
|
|
76
|
+
description,
|
|
77
|
+
type: type!,
|
|
78
|
+
});
|
|
79
|
+
return descriptor;
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* @internal
|
|
85
|
+
*/
|
|
86
|
+
interface IProps {
|
|
87
|
+
status: number | "2XX" | "3XX" | "4XX" | "5XX";
|
|
88
|
+
description?: string | undefined;
|
|
89
|
+
type: string;
|
|
90
|
+
}
|