@nestia/core 3.0.0-dev.20231209 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (132) hide show
  1. package/README.md +12 -9
  2. package/lib/decorators/DynamicModule.js +3 -3
  3. package/lib/decorators/DynamicModule.js.map +1 -1
  4. package/lib/decorators/EncryptedBody.js +14 -13
  5. package/lib/decorators/EncryptedBody.js.map +1 -1
  6. package/lib/decorators/EncryptedModule.d.ts +1 -1
  7. package/lib/decorators/EncryptedModule.js +45 -21
  8. package/lib/decorators/EncryptedModule.js.map +1 -1
  9. package/lib/decorators/EncryptedRoute.d.ts +5 -5
  10. package/lib/decorators/EncryptedRoute.js +12 -29
  11. package/lib/decorators/EncryptedRoute.js.map +1 -1
  12. package/lib/decorators/PlainBody.js +3 -0
  13. package/lib/decorators/PlainBody.js.map +1 -1
  14. package/lib/decorators/SwaggerCustomizer.d.ts +79 -0
  15. package/lib/decorators/SwaggerCustomizer.js +32 -0
  16. package/lib/decorators/SwaggerCustomizer.js.map +1 -0
  17. package/lib/decorators/TypedBody.js +3 -0
  18. package/lib/decorators/TypedBody.js.map +1 -1
  19. package/lib/decorators/TypedException.d.ts +0 -1
  20. package/lib/decorators/TypedException.js +0 -1
  21. package/lib/decorators/TypedException.js.map +1 -1
  22. package/lib/decorators/TypedFormData.d.ts +60 -0
  23. package/lib/decorators/TypedFormData.js +403 -0
  24. package/lib/decorators/TypedFormData.js.map +1 -0
  25. package/lib/decorators/TypedQuery.d.ts +11 -6
  26. package/lib/decorators/TypedQuery.js +6 -1
  27. package/lib/decorators/TypedQuery.js.map +1 -1
  28. package/lib/decorators/TypedRoute.d.ts +5 -5
  29. package/lib/decorators/internal/get_path_and_querify.js +3 -0
  30. package/lib/decorators/internal/get_path_and_querify.js.map +1 -1
  31. package/lib/decorators/internal/load_controller.js.map +1 -1
  32. package/lib/decorators/internal/validate_request_body.d.ts +1 -3
  33. package/lib/decorators/internal/validate_request_body.js +15 -0
  34. package/lib/decorators/internal/validate_request_body.js.map +1 -1
  35. package/lib/decorators/internal/validate_request_form_data.js +79 -0
  36. package/lib/decorators/internal/validate_request_form_data.js.map +1 -0
  37. package/lib/decorators/internal/validate_request_headers.d.ts +1 -3
  38. package/lib/decorators/internal/validate_request_headers.js +15 -0
  39. package/lib/decorators/internal/validate_request_headers.js.map +1 -1
  40. package/lib/decorators/internal/validate_request_query.d.ts +1 -3
  41. package/lib/decorators/internal/validate_request_query.js +15 -0
  42. package/lib/decorators/internal/validate_request_query.js.map +1 -1
  43. package/lib/module.d.ts +2 -0
  44. package/lib/module.js +2 -0
  45. package/lib/module.js.map +1 -1
  46. package/lib/options/IRequestFormDataProps.d.ts +23 -0
  47. package/lib/options/IRequestFormDataProps.js +3 -0
  48. package/lib/options/IRequestFormDataProps.js.map +1 -0
  49. package/lib/programmers/PlainBodyProgrammer.js +1 -1
  50. package/lib/programmers/PlainBodyProgrammer.js.map +1 -1
  51. package/lib/programmers/TypedExceptionProgrammer.js +5 -5
  52. package/lib/programmers/TypedExceptionProgrammer.js.map +1 -1
  53. package/lib/programmers/TypedFormDataBodyProgrammer.d.ts +6 -0
  54. package/lib/programmers/TypedFormDataBodyProgrammer.js +84 -0
  55. package/lib/programmers/TypedFormDataBodyProgrammer.js.map +1 -0
  56. package/lib/programmers/http/HttpQuerifyProgrammer.js +2 -2
  57. package/lib/programmers/http/HttpQuerifyProgrammer.js.map +1 -1
  58. package/lib/transformers/NodeTransformer.js.map +1 -1
  59. package/lib/transformers/ParameterDecoratorTransformer.js +7 -1
  60. package/lib/transformers/ParameterDecoratorTransformer.js.map +1 -1
  61. package/lib/transformers/TypedExceptionTransformer.js +1 -1
  62. package/lib/transformers/TypedExceptionTransformer.js.map +1 -1
  63. package/lib/transformers/TypedRouteTransformer.js +1 -1
  64. package/lib/transformers/TypedRouteTransformer.js.map +1 -1
  65. package/package.json +15 -16
  66. package/src/decorators/DynamicModule.ts +39 -39
  67. package/src/decorators/EncryptedBody.ts +105 -107
  68. package/src/decorators/EncryptedController.ts +38 -38
  69. package/src/decorators/EncryptedModule.ts +96 -79
  70. package/src/decorators/EncryptedRoute.ts +182 -206
  71. package/src/decorators/PlainBody.ts +75 -72
  72. package/src/decorators/SwaggerCustomizer.ts +115 -0
  73. package/src/decorators/TypedBody.ts +62 -59
  74. package/src/decorators/TypedException.ts +90 -89
  75. package/src/decorators/TypedFormData.ts +219 -0
  76. package/src/decorators/TypedHeaders.ts +69 -69
  77. package/src/decorators/TypedParam.ts +65 -65
  78. package/src/decorators/TypedQuery.ts +251 -246
  79. package/src/decorators/TypedRoute.ts +144 -144
  80. package/src/decorators/internal/EncryptedConstant.ts +4 -4
  81. package/src/decorators/internal/NoTransformConfigureError.ts +8 -8
  82. package/src/decorators/internal/get_path_and_querify.ts +106 -103
  83. package/src/decorators/internal/get_path_and_stringify.ts +91 -91
  84. package/src/decorators/internal/get_text_body.ts +20 -20
  85. package/src/decorators/internal/headers_to_object.ts +13 -13
  86. package/src/decorators/internal/load_controller.ts +51 -51
  87. package/src/decorators/internal/route_error.ts +45 -45
  88. package/src/decorators/internal/validate_request_body.ts +72 -57
  89. package/src/decorators/internal/validate_request_form_data.ts +75 -0
  90. package/src/decorators/internal/validate_request_headers.ts +83 -68
  91. package/src/decorators/internal/validate_request_query.ts +71 -56
  92. package/src/index.ts +5 -5
  93. package/src/module.ts +16 -14
  94. package/src/options/INestiaTransformOptions.ts +17 -17
  95. package/src/options/INestiaTransformProject.ts +7 -7
  96. package/src/options/IRequestBodyValidator.ts +20 -20
  97. package/src/options/IRequestFormDataProps.ts +27 -0
  98. package/src/options/IRequestHeadersValidator.ts +22 -22
  99. package/src/options/IRequestQueryValidator.ts +20 -20
  100. package/src/options/IResponseBodyQuerifier.ts +25 -25
  101. package/src/options/IResponseBodyStringifier.ts +25 -25
  102. package/src/programmers/PlainBodyProgrammer.ts +52 -52
  103. package/src/programmers/TypedBodyProgrammer.ts +108 -108
  104. package/src/programmers/TypedExceptionProgrammer.ts +71 -72
  105. package/src/programmers/TypedFormDataBodyProgrammer.ts +108 -0
  106. package/src/programmers/TypedHeadersProgrammer.ts +56 -56
  107. package/src/programmers/TypedParamProgrammer.ts +24 -24
  108. package/src/programmers/TypedQueryBodyProgrammer.ts +56 -56
  109. package/src/programmers/TypedQueryProgrammer.ts +56 -56
  110. package/src/programmers/TypedQueryRouteProgrammer.ts +51 -51
  111. package/src/programmers/TypedRouteProgrammer.ts +51 -51
  112. package/src/programmers/http/HttpAssertQuerifyProgrammer.ts +58 -58
  113. package/src/programmers/http/HttpIsQuerifyProgrammer.ts +62 -62
  114. package/src/programmers/http/HttpQuerifyProgrammer.ts +96 -96
  115. package/src/programmers/http/HttpValidateQuerifyProgrammer.ts +63 -63
  116. package/src/programmers/internal/CoreMetadataUtil.ts +21 -21
  117. package/src/transform.ts +35 -35
  118. package/src/transformers/FileTransformer.ts +66 -66
  119. package/src/transformers/MethodTransformer.ts +94 -94
  120. package/src/transformers/NodeTransformer.ts +16 -16
  121. package/src/transformers/ParameterDecoratorTransformer.ts +120 -121
  122. package/src/transformers/ParameterTransformer.ts +48 -48
  123. package/src/transformers/TypedExceptionTransformer.ts +48 -49
  124. package/src/transformers/TypedRouteTransformer.ts +88 -95
  125. package/src/typings/Creator.ts +3 -3
  126. package/src/utils/ExceptionManager.ts +112 -112
  127. package/src/utils/Singleton.ts +20 -20
  128. package/src/utils/SourceFinder.ts +57 -57
  129. package/lib/decorators/internal/get_binary_body.js +0 -66
  130. package/lib/decorators/internal/get_binary_body.js.map +0 -1
  131. package/src/decorators/internal/get_binary_body.ts +0 -18
  132. /package/lib/decorators/internal/{get_binary_body.d.ts → validate_request_form_data.d.ts} +0 -0
@@ -1,72 +1,75 @@
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 } from "typia";
9
-
10
- import { get_text_body } from "./internal/get_text_body";
11
- import { validate_request_body } from "./internal/validate_request_body";
12
-
13
- /**
14
- * Plain body decorator.
15
- *
16
- * `PlainBody` is a decorator function getting full body text from the HTTP request.
17
- *
18
- * If you adjust the regular {@link Body} decorator function to the body parameter,
19
- * you can't get the full body text because the {@link Body} tries to convert the
20
- * body text to JSON object. Therefore, `@nestia/core` provides this `PlainBody`
21
- * decorator function to get the full body text.
22
- *
23
- * ```typescript
24
- * \@TypedRoute.Post("memo")
25
- * public store
26
- * (
27
- * \@PlainBody() body: string
28
- * ): void;
29
- * ```
30
- *
31
- * @return Parameter decorator
32
- * @author Jeongho Nam - https://github.com/samchon
33
- */
34
- export function PlainBody(): ParameterDecorator;
35
-
36
- /**
37
- * @internal
38
- */
39
- export function PlainBody(
40
- assert?: (input: unknown) => string,
41
- ): ParameterDecorator {
42
- const checker = assert
43
- ? validate_request_body("PlainBody")({
44
- type: "assert",
45
- assert,
46
- })
47
- : null;
48
- return createParamDecorator(async function PlainBody(
49
- _data: any,
50
- context: ExecutionContext,
51
- ) {
52
- const request: express.Request | FastifyRequest = context
53
- .switchToHttp()
54
- .getRequest();
55
- if (!isTextPlain(request.headers["content-type"]))
56
- throw new BadRequestException(`Request body type is not "text/plain".`);
57
- const value: string = await get_text_body(request);
58
- if (checker) {
59
- const error: Error | null = checker(value);
60
- if (error !== null) throw error;
61
- }
62
- return value;
63
- })();
64
- }
65
- Object.assign(PlainBody, assert);
66
-
67
- const isTextPlain = (text?: string): boolean =>
68
- text !== undefined &&
69
- text
70
- .split(";")
71
- .map((str) => str.trim())
72
- .some((str) => str === "text/plain");
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 } from "typia";
9
+
10
+ import { get_text_body } from "./internal/get_text_body";
11
+ import { validate_request_body } from "./internal/validate_request_body";
12
+
13
+ /**
14
+ * Plain body decorator.
15
+ *
16
+ * `PlainBody` is a decorator function getting full body text from the HTTP request.
17
+ *
18
+ * If you adjust the regular {@link Body} decorator function to the body parameter,
19
+ * you can't get the full body text because the {@link Body} tries to convert the
20
+ * body text to JSON object. Therefore, `@nestia/core` provides this `PlainBody`
21
+ * decorator function to get the full body text.
22
+ *
23
+ * ```typescript
24
+ * \@TypedRoute.Post("memo")
25
+ * public store
26
+ * (
27
+ * \@PlainBody() body: string
28
+ * ): void;
29
+ * ```
30
+ *
31
+ * @return Parameter decorator
32
+ * @author Jeongho Nam - https://github.com/samchon
33
+ */
34
+ export function PlainBody(): ParameterDecorator;
35
+
36
+ /**
37
+ * @internal
38
+ */
39
+ export function PlainBody(
40
+ assert?: (input: unknown) => string,
41
+ ): ParameterDecorator {
42
+ const checker = assert
43
+ ? validate_request_body("PlainBody")({
44
+ type: "assert",
45
+ assert,
46
+ })
47
+ : null;
48
+ return createParamDecorator(async function PlainBody(
49
+ _data: any,
50
+ context: ExecutionContext,
51
+ ) {
52
+ const request: express.Request | FastifyRequest = context
53
+ .switchToHttp()
54
+ .getRequest();
55
+ if (!isTextPlain(request.headers["content-type"]))
56
+ throw new BadRequestException(`Request body type is not "text/plain".`);
57
+ const value: string = await get_text_body(request);
58
+ if (checker) {
59
+ const error: Error | null = checker(value);
60
+ if (error !== null) throw error;
61
+ }
62
+ return value;
63
+ })();
64
+ }
65
+ Object.assign(PlainBody, assert);
66
+
67
+ /**
68
+ * @internal
69
+ */
70
+ const isTextPlain = (text?: string): boolean =>
71
+ text !== undefined &&
72
+ text
73
+ .split(";")
74
+ .map((str) => str.trim())
75
+ .some((str) => str === "text/plain");
@@ -0,0 +1,115 @@
1
+ import { OpenApi } from "@samchon/openapi";
2
+
3
+ /**
4
+ * Swagger customization decorator.
5
+ *
6
+ * `SwaggerCustomizer` is a method decorator function which can used for
7
+ * customizing the swagger data with `npx nestia swagger` command. Furthermore,
8
+ * it is possible to add plugin properties starting with `x-` characters.
9
+ *
10
+ * In other words, this decorator function does not affect to the runtime,
11
+ * but only for the swagger data customization.
12
+ *
13
+ * @param closure Callback function which can customize the swagger data
14
+ * @returns Method decorator
15
+ * @author Jeongho Nam - https://github.com/samchon
16
+ */
17
+ export function SwaggerCustomizer(
18
+ closure: (props: SwaggerCustomizer.IProps) => unknown,
19
+ ): MethodDecorator {
20
+ return function SwaggerCustomizer(
21
+ target: Object,
22
+ propertyKey: string | symbol,
23
+ descriptor: TypedPropertyDescriptor<any>,
24
+ ) {
25
+ const array: Array<(props: SwaggerCustomizer.IProps) => unknown> = (() => {
26
+ if (Reflect.hasMetadata("nestia/SwaggerCustomizer", target, propertyKey))
27
+ return Reflect.getMetadata(
28
+ "nestia/SwaggerCustomizer",
29
+ target,
30
+ propertyKey,
31
+ );
32
+ const array: Array<(props: SwaggerCustomizer.IProps) => unknown> = [];
33
+ Reflect.defineMetadata(
34
+ "nestia/SwaggerCustomizer",
35
+ array,
36
+ target,
37
+ propertyKey,
38
+ );
39
+ return array;
40
+ })();
41
+ array.push(closure);
42
+ return descriptor;
43
+ };
44
+ }
45
+ export namespace SwaggerCustomizer {
46
+ /**
47
+ * Properties for the `SwaggerCustomizer` decorator.
48
+ *
49
+ * `SwaggerCustomizer.IProps` is a type for the `closure` parameter of the
50
+ * `SwaggerCustomizer` decorator. It's a callback function which can customize
51
+ * the swagger data.
52
+ */
53
+ export interface IProps {
54
+ /**
55
+ * Swagger data.
56
+ */
57
+ swagger: OpenApi.IDocument;
58
+
59
+ /**
60
+ * Method of the route.
61
+ */
62
+ method: string;
63
+
64
+ /**
65
+ * Path of the route.
66
+ */
67
+ path: string;
68
+
69
+ /**
70
+ * Route data.
71
+ */
72
+ route: OpenApi.IOperation;
73
+
74
+ /**
75
+ * Get neighbor endpoint data through the controller method.
76
+ *
77
+ * @param func Controller method to find the neighbor endpoint
78
+ * @returns Neighbor endpoint data
79
+ */
80
+ at(func: Function): ISwaggerEndpoint | undefined;
81
+
82
+ /**
83
+ * Get neighbor route data.
84
+ *
85
+ * @param accessor Accessor for getting neighbor route data
86
+ * @returns Neighbor route data
87
+ */
88
+ get(accessor: IAccessor): OpenApi.IOperation | undefined;
89
+ }
90
+
91
+ /**
92
+ * Accessor for getting neighbor route data.
93
+ */
94
+ export interface IAccessor {
95
+ /**
96
+ * Path of the neighbor route.
97
+ */
98
+ path: string;
99
+
100
+ /**
101
+ * Method of the neighbor route.
102
+ */
103
+ method: string;
104
+ }
105
+
106
+ /**
107
+ * Endpoint info of the route.
108
+ */
109
+ export interface ISwaggerEndpoint extends IAccessor {
110
+ /**
111
+ * Route data.
112
+ */
113
+ route: OpenApi.IOperation;
114
+ }
115
+ }
@@ -1,59 +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
- 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
+ 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,89 +1,90 @@
1
- import "reflect-metadata";
2
-
3
- /**
4
- * > You must configure the generic argument `T`
5
- *
6
- * Exception decorator.
7
- *
8
- * `TypedException` is a decorator function describing HTTP exception and its type
9
- * which could be occured in the method.
10
- *
11
- * For reference, this decorator function does not affect to the method's behavior,
12
- * but only affects to the swagger documents generation. Also, it does not affect to
13
- * the SDK library generation yet, but will be used in the future.
14
- *
15
- * @param status Status number or pattern like "2XX", "3XX", "4XX", "5XX"
16
- * @param description Description about the exception
17
- * @returns Method decorator
18
- *
19
- * @author Jeongho Nam - https://github.com/samchon
20
- */
21
- export function TypedException(
22
- status: number | "2XX" | "3XX" | "4XX" | "5XX",
23
- description?: string | undefined,
24
- ): never;
25
-
26
- /**
27
- * Exception decorator.
28
- *
29
- * `TypedException` is a decorator function describing HTTP exception and its type
30
- * which could be occured in the method.
31
- *
32
- * For reference, this decorator function does not affect to the method's behavior,
33
- * but only affects to the swagger documents generation. Also, it does not affect to
34
- * the SDK library generation yet, but will be used in the future.
35
- *
36
- * @template T Type of the exception
37
- * @param status Status number or pattern like "2XX", "3XX", "4XX", "5XX"
38
- * @param description Description about the exception
39
- * @returns Method decorator
40
- *
41
- * @author Jeongho Nam - https://github.com/samchon
42
- */
43
- export function TypedException<T>(
44
- status: number | "2XX" | "3XX" | "4XX" | "5XX",
45
- description?: string | undefined,
46
- ): MethodDecorator;
47
-
48
- /**
49
- * @internal
50
- */
51
- export function TypedException<T>(
52
- status: number | "2XX" | "3XX" | "4XX" | "5XX",
53
- description?: string | undefined,
54
- type?: string | undefined,
55
- ): MethodDecorator {
56
- return function TypedException(
57
- target: Object | T,
58
- propertyKey: string | symbol,
59
- descriptor: TypedPropertyDescriptor<any>,
60
- ) {
61
- const array: IProps[] = (() => {
62
- const oldbie: IProps[] | undefined = Reflect.getMetadata(
63
- `nestia/TypedException`,
64
- (target as any)[propertyKey],
65
- );
66
- if (oldbie !== undefined) return oldbie;
67
-
68
- const newbie: IProps[] = [];
69
- Reflect.defineMetadata(
70
- `nestia/TypedException`,
71
- newbie,
72
- (target as any)[propertyKey],
73
- );
74
- return newbie;
75
- })();
76
- array.push({
77
- status,
78
- description,
79
- type: type!,
80
- });
81
- return descriptor;
82
- };
83
- }
84
-
85
- interface IProps {
86
- status: number | "2XX" | "3XX" | "4XX" | "5XX";
87
- description?: string | undefined;
88
- type: string;
89
- }
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
+ }