@nestia/core 7.0.0-dev.20250607 → 7.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.
- package/LICENSE +21 -21
- package/README.md +92 -92
- package/package.json +3 -3
- package/src/adaptors/WebSocketAdaptor.ts +429 -429
- package/src/decorators/DynamicModule.ts +43 -43
- package/src/decorators/EncryptedBody.ts +101 -101
- package/src/decorators/EncryptedController.ts +38 -38
- package/src/decorators/EncryptedModule.ts +100 -100
- package/src/decorators/EncryptedRoute.ts +219 -219
- package/src/decorators/HumanRoute.ts +22 -22
- package/src/decorators/NoTransformConfigurationError.ts +32 -32
- package/src/decorators/PlainBody.ts +79 -79
- package/src/decorators/SwaggerCustomizer.ts +115 -115
- package/src/decorators/SwaggerExample.ts +100 -100
- package/src/decorators/TypedBody.ts +59 -59
- package/src/decorators/TypedException.ts +166 -166
- package/src/decorators/TypedFormData.ts +195 -195
- package/src/decorators/TypedHeaders.ts +64 -64
- package/src/decorators/TypedParam.ts +77 -77
- package/src/decorators/TypedQuery.ts +245 -245
- package/src/decorators/TypedRoute.ts +214 -214
- package/src/decorators/WebSocketRoute.ts +242 -242
- package/src/decorators/internal/EncryptedConstant.ts +4 -4
- package/src/decorators/internal/IWebSocketRouteReflect.ts +23 -23
- package/src/decorators/internal/NoTransformConfigureError.ts +2 -2
- package/src/decorators/internal/get_path_and_querify.ts +108 -108
- package/src/decorators/internal/get_path_and_stringify.ts +122 -122
- package/src/decorators/internal/get_text_body.ts +20 -20
- package/src/decorators/internal/headers_to_object.ts +13 -13
- package/src/decorators/internal/is_request_body_undefined.ts +14 -14
- package/src/decorators/internal/load_controller.ts +49 -49
- package/src/decorators/internal/route_error.ts +45 -45
- package/src/decorators/internal/validate_request_body.ts +74 -74
- package/src/decorators/internal/validate_request_form_data.ts +77 -77
- package/src/decorators/internal/validate_request_headers.ts +86 -86
- package/src/decorators/internal/validate_request_query.ts +74 -74
- package/src/index.ts +5 -5
- package/src/module.ts +22 -22
- package/src/options/INestiaTransformOptions.ts +38 -38
- package/src/options/INestiaTransformProject.ts +8 -8
- package/src/options/IRequestBodyValidator.ts +20 -20
- package/src/options/IRequestFormDataProps.ts +27 -27
- package/src/options/IRequestHeadersValidator.ts +22 -22
- package/src/options/IRequestQueryValidator.ts +20 -20
- package/src/options/IResponseBodyQuerifier.ts +25 -25
- package/src/options/IResponseBodyStringifier.ts +30 -30
- package/src/programmers/PlainBodyProgrammer.ts +70 -70
- package/src/programmers/TypedBodyProgrammer.ts +142 -142
- package/src/programmers/TypedFormDataBodyProgrammer.ts +118 -118
- package/src/programmers/TypedHeadersProgrammer.ts +63 -63
- package/src/programmers/TypedParamProgrammer.ts +33 -33
- package/src/programmers/TypedQueryBodyProgrammer.ts +112 -112
- package/src/programmers/TypedQueryProgrammer.ts +114 -114
- package/src/programmers/TypedQueryRouteProgrammer.ts +105 -105
- package/src/programmers/TypedRouteProgrammer.ts +94 -94
- package/src/programmers/http/HttpAssertQuerifyProgrammer.ts +72 -72
- package/src/programmers/http/HttpIsQuerifyProgrammer.ts +75 -75
- package/src/programmers/http/HttpQuerifyProgrammer.ts +108 -108
- package/src/programmers/http/HttpValidateQuerifyProgrammer.ts +76 -76
- package/src/programmers/internal/CoreMetadataUtil.ts +21 -21
- package/src/transform.ts +35 -35
- package/src/transformers/FileTransformer.ts +110 -110
- package/src/transformers/MethodTransformer.ts +103 -103
- package/src/transformers/NodeTransformer.ts +23 -23
- package/src/transformers/ParameterDecoratorTransformer.ts +143 -143
- package/src/transformers/ParameterTransformer.ts +57 -57
- package/src/transformers/TypedRouteTransformer.ts +85 -85
- package/src/transformers/WebSocketRouteTransformer.ts +120 -120
- package/src/typings/Creator.ts +3 -3
- package/src/typings/get-function-location.d.ts +7 -7
- package/src/utils/ArrayUtil.ts +7 -7
- package/src/utils/ExceptionManager.ts +112 -112
- package/src/utils/Singleton.ts +20 -20
- package/src/utils/SourceFinder.ts +57 -57
- package/src/utils/VersioningStrategy.ts +27 -27
|
@@ -1,59 +1,59 @@
|
|
|
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
|
-
|
|
9
|
-
import { IRequestBodyValidator } from "../options/IRequestBodyValidator";
|
|
10
|
-
import { is_request_body_undefined } from "./internal/is_request_body_undefined";
|
|
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 (is_request_body_undefined(request) && checker(undefined as T) === null)
|
|
39
|
-
return undefined;
|
|
40
|
-
else if (isApplicationJson(request.headers["content-type"]) === false)
|
|
41
|
-
throw new BadRequestException(
|
|
42
|
-
`Request body type is not "application/json".`,
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
const error: Error | null = checker(request.body);
|
|
46
|
-
if (error !== null) throw error;
|
|
47
|
-
return request.body;
|
|
48
|
-
})();
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* @internal
|
|
53
|
-
*/
|
|
54
|
-
const isApplicationJson = (text?: string): boolean =>
|
|
55
|
-
text !== undefined &&
|
|
56
|
-
text
|
|
57
|
-
.split(";")
|
|
58
|
-
.map((str) => str.trim())
|
|
59
|
-
.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
|
+
|
|
9
|
+
import { IRequestBodyValidator } from "../options/IRequestBodyValidator";
|
|
10
|
+
import { is_request_body_undefined } from "./internal/is_request_body_undefined";
|
|
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 (is_request_body_undefined(request) && checker(undefined as T) === null)
|
|
39
|
+
return undefined;
|
|
40
|
+
else if (isApplicationJson(request.headers["content-type"]) === false)
|
|
41
|
+
throw new BadRequestException(
|
|
42
|
+
`Request body type is not "application/json".`,
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
const error: Error | null = checker(request.body);
|
|
46
|
+
if (error !== null) throw error;
|
|
47
|
+
return request.body;
|
|
48
|
+
})();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @internal
|
|
53
|
+
*/
|
|
54
|
+
const isApplicationJson = (text?: string): boolean =>
|
|
55
|
+
text !== undefined &&
|
|
56
|
+
text
|
|
57
|
+
.split(";")
|
|
58
|
+
.map((str) => str.trim())
|
|
59
|
+
.some((str) => str === "application/json");
|
|
@@ -1,166 +1,166 @@
|
|
|
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 occurred 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 props Properties for the exception
|
|
14
|
-
* @returns Method decorator
|
|
15
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
16
|
-
*/
|
|
17
|
-
export function TypedException(props: TypedException.IProps<unknown>): never;
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* > You must configure the generic argument `T`
|
|
21
|
-
*
|
|
22
|
-
* Exception decorator.
|
|
23
|
-
*
|
|
24
|
-
* `TypedException` is a decorator function describing HTTP exception and its type
|
|
25
|
-
* which could be occurred in the method.
|
|
26
|
-
*
|
|
27
|
-
* For reference, this decorator function does not affect to the method's behavior,
|
|
28
|
-
* but only affects to the swagger documents generation. Also, it does not affect to
|
|
29
|
-
* the SDK library generation yet, but will be used in the future.
|
|
30
|
-
*
|
|
31
|
-
* @param status Status number or pattern like "2XX", "3XX", "4XX", "5XX"
|
|
32
|
-
* @param description Description about the exception
|
|
33
|
-
* @returns Method decorator
|
|
34
|
-
*
|
|
35
|
-
* @deprecated Use {@link TypedException.IProps} typed function instead.
|
|
36
|
-
* This typed function is deprecated and will be removed in the next major update.
|
|
37
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
38
|
-
*/
|
|
39
|
-
export function TypedException(
|
|
40
|
-
status: number | "2XX" | "3XX" | "4XX" | "5XX",
|
|
41
|
-
description?: string | undefined,
|
|
42
|
-
): never;
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Exception decorator.
|
|
46
|
-
*
|
|
47
|
-
* `TypedException` is a decorator function describing HTTP exception and its type
|
|
48
|
-
* which could be occurred in the method.
|
|
49
|
-
*
|
|
50
|
-
* For reference, this decorator function does not affect to the method's behavior,
|
|
51
|
-
* but only affects to the swagger documents generation. Also, it does not affect to
|
|
52
|
-
* the SDK library generation yet, but will be used in the future.
|
|
53
|
-
*
|
|
54
|
-
* @template T Type of the exception
|
|
55
|
-
* @param props Properties for the exception
|
|
56
|
-
* @returns Method decorator
|
|
57
|
-
*
|
|
58
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
59
|
-
*/
|
|
60
|
-
export function TypedException<T>(
|
|
61
|
-
props: TypedException.IProps<T>,
|
|
62
|
-
): MethodDecorator;
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Exception decorator.
|
|
66
|
-
*
|
|
67
|
-
* `TypedException` is a decorator function describing HTTP exception and its type
|
|
68
|
-
* which could be occurred in the method.
|
|
69
|
-
*
|
|
70
|
-
* For reference, this decorator function does not affect to the method's behavior,
|
|
71
|
-
* but only affects to the swagger documents generation. Also, it does not affect to
|
|
72
|
-
* the SDK library generation yet, but will be used in the future.
|
|
73
|
-
*
|
|
74
|
-
* @template T Type of the exception
|
|
75
|
-
* @param status Status number or pattern like "2XX", "3XX", "4XX", "5XX"
|
|
76
|
-
* @param description Description about the exception
|
|
77
|
-
* @returns Method decorator
|
|
78
|
-
*
|
|
79
|
-
* @deprecated Use {@link TypedException.IProps} typed function instead.
|
|
80
|
-
* This typed function is deprecated and will be removed in the next major update.
|
|
81
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
82
|
-
*/
|
|
83
|
-
export function TypedException<T>(
|
|
84
|
-
status: number | "2XX" | "3XX" | "4XX" | "5XX",
|
|
85
|
-
description?: string | undefined,
|
|
86
|
-
): MethodDecorator;
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* @internal
|
|
90
|
-
*/
|
|
91
|
-
export function TypedException<T>(...args: any[]): MethodDecorator {
|
|
92
|
-
const props: TypedException.IProps<T> =
|
|
93
|
-
typeof args[0] === "object"
|
|
94
|
-
? args[0]
|
|
95
|
-
: { status: args[0], description: args[1] };
|
|
96
|
-
return function TypedException(
|
|
97
|
-
target: Object | T,
|
|
98
|
-
propertyKey: string | symbol,
|
|
99
|
-
descriptor: TypedPropertyDescriptor<any>,
|
|
100
|
-
) {
|
|
101
|
-
const array: TypedException.IProps<any>[] = (() => {
|
|
102
|
-
const oldbie: TypedException.IProps<any>[] | undefined =
|
|
103
|
-
Reflect.getMetadata(
|
|
104
|
-
"nestia/TypedException",
|
|
105
|
-
(target as any)[propertyKey],
|
|
106
|
-
);
|
|
107
|
-
if (oldbie !== undefined) return oldbie;
|
|
108
|
-
|
|
109
|
-
const newbie: TypedException.IProps<any>[] = [];
|
|
110
|
-
Reflect.defineMetadata(
|
|
111
|
-
"nestia/TypedException",
|
|
112
|
-
newbie,
|
|
113
|
-
(target as any)[propertyKey],
|
|
114
|
-
);
|
|
115
|
-
return newbie;
|
|
116
|
-
})();
|
|
117
|
-
array.push(props);
|
|
118
|
-
return descriptor;
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
export namespace TypedException {
|
|
122
|
-
/**
|
|
123
|
-
* Properties for the exception.
|
|
124
|
-
*/
|
|
125
|
-
export interface IProps<T> {
|
|
126
|
-
/**
|
|
127
|
-
* Status number or pattern like "2XX", "3XX", "4XX", "5XX".
|
|
128
|
-
*/
|
|
129
|
-
status: number | "2XX" | "3XX" | "4XX" | "5XX";
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Description about the exception.
|
|
133
|
-
*/
|
|
134
|
-
description?: string | undefined;
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* Example value.
|
|
138
|
-
*/
|
|
139
|
-
example?: T | undefined;
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* Collection of examples for the exception.
|
|
143
|
-
*/
|
|
144
|
-
examples?: Record<string, IExample<T>> | undefined;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* Metadata collected in the {@link IProps.examples}.
|
|
149
|
-
*/
|
|
150
|
-
export interface IExample<T> {
|
|
151
|
-
/**
|
|
152
|
-
* Summary of the example.
|
|
153
|
-
*/
|
|
154
|
-
summary?: string | undefined;
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* Description of the example.
|
|
158
|
-
*/
|
|
159
|
-
description?: string | undefined;
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* Value of the example.
|
|
163
|
-
*/
|
|
164
|
-
value: T;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
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 occurred 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 props Properties for the exception
|
|
14
|
+
* @returns Method decorator
|
|
15
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
16
|
+
*/
|
|
17
|
+
export function TypedException(props: TypedException.IProps<unknown>): never;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* > You must configure the generic argument `T`
|
|
21
|
+
*
|
|
22
|
+
* Exception decorator.
|
|
23
|
+
*
|
|
24
|
+
* `TypedException` is a decorator function describing HTTP exception and its type
|
|
25
|
+
* which could be occurred in the method.
|
|
26
|
+
*
|
|
27
|
+
* For reference, this decorator function does not affect to the method's behavior,
|
|
28
|
+
* but only affects to the swagger documents generation. Also, it does not affect to
|
|
29
|
+
* the SDK library generation yet, but will be used in the future.
|
|
30
|
+
*
|
|
31
|
+
* @param status Status number or pattern like "2XX", "3XX", "4XX", "5XX"
|
|
32
|
+
* @param description Description about the exception
|
|
33
|
+
* @returns Method decorator
|
|
34
|
+
*
|
|
35
|
+
* @deprecated Use {@link TypedException.IProps} typed function instead.
|
|
36
|
+
* This typed function is deprecated and will be removed in the next major update.
|
|
37
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
38
|
+
*/
|
|
39
|
+
export function TypedException(
|
|
40
|
+
status: number | "2XX" | "3XX" | "4XX" | "5XX",
|
|
41
|
+
description?: string | undefined,
|
|
42
|
+
): never;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Exception decorator.
|
|
46
|
+
*
|
|
47
|
+
* `TypedException` is a decorator function describing HTTP exception and its type
|
|
48
|
+
* which could be occurred in the method.
|
|
49
|
+
*
|
|
50
|
+
* For reference, this decorator function does not affect to the method's behavior,
|
|
51
|
+
* but only affects to the swagger documents generation. Also, it does not affect to
|
|
52
|
+
* the SDK library generation yet, but will be used in the future.
|
|
53
|
+
*
|
|
54
|
+
* @template T Type of the exception
|
|
55
|
+
* @param props Properties for the exception
|
|
56
|
+
* @returns Method decorator
|
|
57
|
+
*
|
|
58
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
59
|
+
*/
|
|
60
|
+
export function TypedException<T>(
|
|
61
|
+
props: TypedException.IProps<T>,
|
|
62
|
+
): MethodDecorator;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Exception decorator.
|
|
66
|
+
*
|
|
67
|
+
* `TypedException` is a decorator function describing HTTP exception and its type
|
|
68
|
+
* which could be occurred in the method.
|
|
69
|
+
*
|
|
70
|
+
* For reference, this decorator function does not affect to the method's behavior,
|
|
71
|
+
* but only affects to the swagger documents generation. Also, it does not affect to
|
|
72
|
+
* the SDK library generation yet, but will be used in the future.
|
|
73
|
+
*
|
|
74
|
+
* @template T Type of the exception
|
|
75
|
+
* @param status Status number or pattern like "2XX", "3XX", "4XX", "5XX"
|
|
76
|
+
* @param description Description about the exception
|
|
77
|
+
* @returns Method decorator
|
|
78
|
+
*
|
|
79
|
+
* @deprecated Use {@link TypedException.IProps} typed function instead.
|
|
80
|
+
* This typed function is deprecated and will be removed in the next major update.
|
|
81
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
82
|
+
*/
|
|
83
|
+
export function TypedException<T>(
|
|
84
|
+
status: number | "2XX" | "3XX" | "4XX" | "5XX",
|
|
85
|
+
description?: string | undefined,
|
|
86
|
+
): MethodDecorator;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* @internal
|
|
90
|
+
*/
|
|
91
|
+
export function TypedException<T>(...args: any[]): MethodDecorator {
|
|
92
|
+
const props: TypedException.IProps<T> =
|
|
93
|
+
typeof args[0] === "object"
|
|
94
|
+
? args[0]
|
|
95
|
+
: { status: args[0], description: args[1] };
|
|
96
|
+
return function TypedException(
|
|
97
|
+
target: Object | T,
|
|
98
|
+
propertyKey: string | symbol,
|
|
99
|
+
descriptor: TypedPropertyDescriptor<any>,
|
|
100
|
+
) {
|
|
101
|
+
const array: TypedException.IProps<any>[] = (() => {
|
|
102
|
+
const oldbie: TypedException.IProps<any>[] | undefined =
|
|
103
|
+
Reflect.getMetadata(
|
|
104
|
+
"nestia/TypedException",
|
|
105
|
+
(target as any)[propertyKey],
|
|
106
|
+
);
|
|
107
|
+
if (oldbie !== undefined) return oldbie;
|
|
108
|
+
|
|
109
|
+
const newbie: TypedException.IProps<any>[] = [];
|
|
110
|
+
Reflect.defineMetadata(
|
|
111
|
+
"nestia/TypedException",
|
|
112
|
+
newbie,
|
|
113
|
+
(target as any)[propertyKey],
|
|
114
|
+
);
|
|
115
|
+
return newbie;
|
|
116
|
+
})();
|
|
117
|
+
array.push(props);
|
|
118
|
+
return descriptor;
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
export namespace TypedException {
|
|
122
|
+
/**
|
|
123
|
+
* Properties for the exception.
|
|
124
|
+
*/
|
|
125
|
+
export interface IProps<T> {
|
|
126
|
+
/**
|
|
127
|
+
* Status number or pattern like "2XX", "3XX", "4XX", "5XX".
|
|
128
|
+
*/
|
|
129
|
+
status: number | "2XX" | "3XX" | "4XX" | "5XX";
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Description about the exception.
|
|
133
|
+
*/
|
|
134
|
+
description?: string | undefined;
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Example value.
|
|
138
|
+
*/
|
|
139
|
+
example?: T | undefined;
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Collection of examples for the exception.
|
|
143
|
+
*/
|
|
144
|
+
examples?: Record<string, IExample<T>> | undefined;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Metadata collected in the {@link IProps.examples}.
|
|
149
|
+
*/
|
|
150
|
+
export interface IExample<T> {
|
|
151
|
+
/**
|
|
152
|
+
* Summary of the example.
|
|
153
|
+
*/
|
|
154
|
+
summary?: string | undefined;
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Description of the example.
|
|
158
|
+
*/
|
|
159
|
+
description?: string | undefined;
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Value of the example.
|
|
163
|
+
*/
|
|
164
|
+
value: T;
|
|
165
|
+
}
|
|
166
|
+
}
|