@nestia/core 11.0.0-dev.20260313-4 → 11.0.0-dev.20260316

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 (59) hide show
  1. package/lib/options/INestiaTransformOptions.d.ts +1 -1
  2. package/lib/programmers/PlainBodyProgrammer.js +1 -1
  3. package/lib/programmers/PlainBodyProgrammer.js.map +1 -1
  4. package/lib/programmers/TypedBodyProgrammer.js +6 -3
  5. package/lib/programmers/TypedBodyProgrammer.js.map +1 -1
  6. package/lib/programmers/TypedQueryBodyProgrammer.js +9 -4
  7. package/lib/programmers/TypedQueryBodyProgrammer.js.map +1 -1
  8. package/lib/programmers/TypedQueryProgrammer.js +9 -4
  9. package/lib/programmers/TypedQueryProgrammer.js.map +1 -1
  10. package/lib/programmers/TypedQueryRouteProgrammer.js +14 -8
  11. package/lib/programmers/TypedQueryRouteProgrammer.js.map +1 -1
  12. package/lib/programmers/TypedRouteProgrammer.js +11 -6
  13. package/lib/programmers/TypedRouteProgrammer.js.map +1 -1
  14. package/package.json +8 -8
  15. package/src/decorators/DynamicModule.ts +44 -44
  16. package/src/decorators/PlainBody.ts +76 -76
  17. package/src/decorators/SwaggerExample.ts +100 -100
  18. package/src/decorators/TypedBody.ts +57 -57
  19. package/src/decorators/TypedException.ts +147 -147
  20. package/src/decorators/TypedHeaders.ts +66 -66
  21. package/src/decorators/TypedParam.ts +77 -77
  22. package/src/decorators/TypedQuery.ts +234 -234
  23. package/src/decorators/WebSocketRoute.ts +242 -242
  24. package/src/decorators/internal/EncryptedConstant.ts +2 -2
  25. package/src/decorators/internal/IWebSocketRouteReflect.ts +23 -23
  26. package/src/decorators/internal/NoTransformConfigureError.ts +2 -2
  27. package/src/decorators/internal/get_path_and_querify.ts +94 -94
  28. package/src/decorators/internal/get_path_and_stringify.ts +110 -110
  29. package/src/decorators/internal/get_text_body.ts +16 -16
  30. package/src/decorators/internal/is_request_body_undefined.ts +12 -12
  31. package/src/decorators/internal/load_controller.ts +45 -45
  32. package/src/decorators/internal/route_error.ts +43 -43
  33. package/src/decorators/internal/validate_request_body.ts +64 -64
  34. package/src/decorators/internal/validate_request_form_data.ts +67 -67
  35. package/src/decorators/internal/validate_request_headers.ts +76 -76
  36. package/src/decorators/internal/validate_request_query.ts +64 -64
  37. package/src/index.ts +5 -5
  38. package/src/options/INestiaTransformOptions.ts +1 -1
  39. package/src/options/IRequestBodyValidator.ts +20 -20
  40. package/src/options/IRequestFormDataProps.ts +27 -27
  41. package/src/options/IRequestHeadersValidator.ts +22 -22
  42. package/src/options/IRequestQueryValidator.ts +20 -20
  43. package/src/options/IResponseBodyQuerifier.ts +25 -25
  44. package/src/options/IResponseBodyStringifier.ts +30 -30
  45. package/src/programmers/PlainBodyProgrammer.ts +1 -1
  46. package/src/programmers/TypedBodyProgrammer.ts +7 -3
  47. package/src/programmers/TypedQueryBodyProgrammer.ts +11 -9
  48. package/src/programmers/TypedQueryProgrammer.ts +11 -9
  49. package/src/programmers/TypedQueryRouteProgrammer.ts +19 -16
  50. package/src/programmers/TypedRouteProgrammer.ts +14 -7
  51. package/src/transformers/NodeTransformer.ts +23 -23
  52. package/src/transformers/ParameterTransformer.ts +57 -57
  53. package/src/typings/Creator.ts +3 -3
  54. package/src/typings/get-function-location.d.ts +7 -7
  55. package/src/utils/ArrayUtil.ts +7 -7
  56. package/src/utils/ExceptionManager.ts +115 -115
  57. package/src/utils/Singleton.ts +16 -16
  58. package/src/utils/SourceFinder.ts +54 -54
  59. package/src/utils/VersioningStrategy.ts +27 -27
@@ -1,100 +1,100 @@
1
- export namespace SwaggerExample {
2
- export function Response<T>(value: T): MethodDecorator;
3
- export function Response<T>(key: string, value: T): MethodDecorator;
4
- export function Response(...args: any[]): MethodDecorator {
5
- return function SwaggerExampleResponse(
6
- _target: Object,
7
- _propertyKey: string | symbol,
8
- descriptor: TypedPropertyDescriptor<any>,
9
- ): TypedPropertyDescriptor<any> {
10
- emplaceValue(emplaceOfResponse(descriptor))(args);
11
- return descriptor;
12
- };
13
- }
14
-
15
- export function Parameter<T>(value: T): ParameterDecorator;
16
- export function Parameter<T>(key: string, value: T): ParameterDecorator;
17
- export function Parameter(...args: any[]): ParameterDecorator {
18
- return function SwaggerExampleParameter(
19
- target: Object,
20
- propertyKey: string | symbol | undefined,
21
- index: number,
22
- ): void {
23
- emplaceValue(emplaceOfParameter(target, propertyKey ?? "", index))(args);
24
- };
25
- }
26
-
27
- export interface IData<T> {
28
- examples?: Record<string, T>;
29
- example?: T;
30
- index?: number;
31
- }
32
- }
33
-
34
- const emplaceValue =
35
- <T>(data: SwaggerExample.IData<T>) =>
36
- (args: any[]) => {
37
- if (args.length === 1) data.example = args[0];
38
- else {
39
- const key: string = args[0];
40
- const value: T = args[1];
41
- data.examples ??= {};
42
- data.examples[key] = value;
43
- }
44
- };
45
-
46
- const emplaceOfResponse = <T>(
47
- descriptor: TypedPropertyDescriptor<any>,
48
- ): SwaggerExample.IData<T> => {
49
- const oldbie: SwaggerExample.IData<T> | undefined = Reflect.getMetadata(
50
- "nestia/SwaggerExample/Response",
51
- descriptor.value,
52
- );
53
- if (oldbie !== undefined) return oldbie;
54
- const newbie: SwaggerExample.IData<T> = {};
55
- Reflect.defineMetadata(
56
- "nestia/SwaggerExample/Response",
57
- newbie,
58
- descriptor.value,
59
- );
60
- return newbie;
61
- };
62
-
63
- const emplaceOfParameter = (
64
- target: Object,
65
- propertyKey: string | symbol,
66
- index: number,
67
- ): SwaggerExample.IData<any> => {
68
- const array: SwaggerExample.IData<any>[] = emplaceArrayOfParameters(
69
- target,
70
- propertyKey,
71
- );
72
- const oldibe: SwaggerExample.IData<any> | undefined = array.find(
73
- (e) => e.index === index,
74
- );
75
- if (oldibe !== undefined) return oldibe;
76
-
77
- const data: SwaggerExample.IData<any> = { index };
78
- array.push(data);
79
- return data;
80
- };
81
-
82
- const emplaceArrayOfParameters = (
83
- target: Object,
84
- propertyKey: string | symbol,
85
- ): SwaggerExample.IData<any>[] => {
86
- const array: SwaggerExample.IData<any>[] | undefined = Reflect.getMetadata(
87
- "nestia/SwaggerExample/Parameters",
88
- target,
89
- propertyKey,
90
- );
91
- if (array !== undefined) return array;
92
- const newbie: SwaggerExample.IData<any>[] = [];
93
- Reflect.defineMetadata(
94
- "nestia/SwaggerExample/Parameters",
95
- newbie,
96
- target,
97
- propertyKey,
98
- );
99
- return newbie;
100
- };
1
+ export namespace SwaggerExample {
2
+ export function Response<T>(value: T): MethodDecorator;
3
+ export function Response<T>(key: string, value: T): MethodDecorator;
4
+ export function Response(...args: any[]): MethodDecorator {
5
+ return function SwaggerExampleResponse(
6
+ _target: Object,
7
+ _propertyKey: string | symbol,
8
+ descriptor: TypedPropertyDescriptor<any>,
9
+ ): TypedPropertyDescriptor<any> {
10
+ emplaceValue(emplaceOfResponse(descriptor))(args);
11
+ return descriptor;
12
+ };
13
+ }
14
+
15
+ export function Parameter<T>(value: T): ParameterDecorator;
16
+ export function Parameter<T>(key: string, value: T): ParameterDecorator;
17
+ export function Parameter(...args: any[]): ParameterDecorator {
18
+ return function SwaggerExampleParameter(
19
+ target: Object,
20
+ propertyKey: string | symbol | undefined,
21
+ index: number,
22
+ ): void {
23
+ emplaceValue(emplaceOfParameter(target, propertyKey ?? "", index))(args);
24
+ };
25
+ }
26
+
27
+ export interface IData<T> {
28
+ examples?: Record<string, T>;
29
+ example?: T;
30
+ index?: number;
31
+ }
32
+ }
33
+
34
+ const emplaceValue =
35
+ <T>(data: SwaggerExample.IData<T>) =>
36
+ (args: any[]) => {
37
+ if (args.length === 1) data.example = args[0];
38
+ else {
39
+ const key: string = args[0];
40
+ const value: T = args[1];
41
+ data.examples ??= {};
42
+ data.examples[key] = value;
43
+ }
44
+ };
45
+
46
+ const emplaceOfResponse = <T>(
47
+ descriptor: TypedPropertyDescriptor<any>,
48
+ ): SwaggerExample.IData<T> => {
49
+ const oldbie: SwaggerExample.IData<T> | undefined = Reflect.getMetadata(
50
+ "nestia/SwaggerExample/Response",
51
+ descriptor.value,
52
+ );
53
+ if (oldbie !== undefined) return oldbie;
54
+ const newbie: SwaggerExample.IData<T> = {};
55
+ Reflect.defineMetadata(
56
+ "nestia/SwaggerExample/Response",
57
+ newbie,
58
+ descriptor.value,
59
+ );
60
+ return newbie;
61
+ };
62
+
63
+ const emplaceOfParameter = (
64
+ target: Object,
65
+ propertyKey: string | symbol,
66
+ index: number,
67
+ ): SwaggerExample.IData<any> => {
68
+ const array: SwaggerExample.IData<any>[] = emplaceArrayOfParameters(
69
+ target,
70
+ propertyKey,
71
+ );
72
+ const oldibe: SwaggerExample.IData<any> | undefined = array.find(
73
+ (e) => e.index === index,
74
+ );
75
+ if (oldibe !== undefined) return oldibe;
76
+
77
+ const data: SwaggerExample.IData<any> = { index };
78
+ array.push(data);
79
+ return data;
80
+ };
81
+
82
+ const emplaceArrayOfParameters = (
83
+ target: Object,
84
+ propertyKey: string | symbol,
85
+ ): SwaggerExample.IData<any>[] => {
86
+ const array: SwaggerExample.IData<any>[] | undefined = Reflect.getMetadata(
87
+ "nestia/SwaggerExample/Parameters",
88
+ target,
89
+ propertyKey,
90
+ );
91
+ if (array !== undefined) return array;
92
+ const newbie: SwaggerExample.IData<any>[] = [];
93
+ Reflect.defineMetadata(
94
+ "nestia/SwaggerExample/Parameters",
95
+ newbie,
96
+ target,
97
+ propertyKey,
98
+ );
99
+ return newbie;
100
+ };
@@ -1,57 +1,57 @@
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
17
- * from request body. Also, it validates the request body data type through
18
- * [typia](https://github.com/samchon/typia) and the validation speed is maximum
19
- * 20,000x times faster than `class-validator`.
20
- *
21
- * For reference, when the request body data is not following the promised type
22
- * `T`, `BadRequestException` error (status code: 400) would be thrown.
23
- *
24
- * @author Jeongho Nam - https://github.com/samchon
25
- * @param validator Custom validator if required. Default is `typia.assert()`
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
- /** @internal */
52
- const isApplicationJson = (text?: string): boolean =>
53
- text !== undefined &&
54
- text
55
- .split(";")
56
- .map((str) => str.trim())
57
- .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
17
+ * from request body. Also, it validates the request body data type through
18
+ * [typia](https://github.com/samchon/typia) and the validation speed is maximum
19
+ * 20,000x times faster than `class-validator`.
20
+ *
21
+ * For reference, when the request body data is not following the promised type
22
+ * `T`, `BadRequestException` error (status code: 400) would be thrown.
23
+ *
24
+ * @author Jeongho Nam - https://github.com/samchon
25
+ * @param validator Custom validator if required. Default is `typia.assert()`
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
+ /** @internal */
52
+ const isApplicationJson = (text?: string): boolean =>
53
+ text !== undefined &&
54
+ text
55
+ .split(";")
56
+ .map((str) => str.trim())
57
+ .some((str) => str === "application/json");
@@ -1,147 +1,147 @@
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
7
- * type which could be occurred in the method.
8
- *
9
- * For reference, this decorator function does not affect to the method's
10
- * behavior, but only affects to the swagger documents generation. Also, it does
11
- * not affect to the SDK library generation yet, but will be used in the
12
- * future.
13
- *
14
- * @author Jeongho Nam - https://github.com/samchon
15
- * @param props Properties for the exception
16
- * @returns Method decorator
17
- */
18
- export function TypedException(props: TypedException.IProps<unknown>): never;
19
-
20
- /**
21
- * > You must configure the generic argument `T`
22
- *
23
- * Exception decorator.
24
- *
25
- * `TypedException` is a decorator function describing HTTP exception and its
26
- * type which could be occurred in the method.
27
- *
28
- * For reference, this decorator function does not affect to the method's
29
- * behavior, but only affects to the swagger documents generation. Also, it does
30
- * not affect to the SDK library generation yet, but will be used in the
31
- * future.
32
- *
33
- * @author Jeongho Nam - https://github.com/samchon
34
- * @deprecated Use {@link TypedException.IProps} typed function instead. This
35
- * typed function is deprecated and will be removed in the next major update.
36
- * @param status Status number or pattern like "2XX", "3XX", "4XX", "5XX"
37
- * @param description Description about the exception
38
- * @returns Method decorator
39
- */
40
- export function TypedException(
41
- status: number | "2XX" | "3XX" | "4XX" | "5XX",
42
- description?: string | undefined,
43
- ): never;
44
-
45
- /**
46
- * Exception decorator.
47
- *
48
- * `TypedException` is a decorator function describing HTTP exception and its
49
- * type which could be occurred in the method.
50
- *
51
- * For reference, this decorator function does not affect to the method's
52
- * behavior, but only affects to the swagger documents generation. Also, it does
53
- * not affect to the SDK library generation yet, but will be used in the
54
- * future.
55
- *
56
- * @author Jeongho Nam - https://github.com/samchon
57
- * @template T Type of the exception
58
- * @param props Properties for the exception
59
- * @returns Method decorator
60
- */
61
- export function TypedException<T>(
62
- props: TypedException.IProps<T>,
63
- ): MethodDecorator;
64
-
65
- /**
66
- * Exception decorator.
67
- *
68
- * `TypedException` is a decorator function describing HTTP exception and its
69
- * type which could be occurred in the method.
70
- *
71
- * For reference, this decorator function does not affect to the method's
72
- * behavior, but only affects to the swagger documents generation. Also, it does
73
- * not affect to the SDK library generation yet, but will be used in the
74
- * future.
75
- *
76
- * @author Jeongho Nam - https://github.com/samchon
77
- * @deprecated Use {@link TypedException.IProps} typed function instead. This
78
- * typed function is deprecated and will be removed in the next major update.
79
- * @template T Type of the exception
80
- * @param status Status number or pattern like "2XX", "3XX", "4XX", "5XX"
81
- * @param description Description about the exception
82
- * @returns Method decorator
83
- */
84
- export function TypedException<T>(
85
- status: number | "2XX" | "3XX" | "4XX" | "5XX",
86
- description?: string | undefined,
87
- ): MethodDecorator;
88
-
89
- /** @internal */
90
- export function TypedException<T>(...args: any[]): MethodDecorator {
91
- const props: TypedException.IProps<T> =
92
- typeof args[0] === "object"
93
- ? args[0]
94
- : { status: args[0], description: args[1] };
95
- return function TypedException(
96
- target: Object | T,
97
- propertyKey: string | symbol,
98
- descriptor: TypedPropertyDescriptor<any>,
99
- ) {
100
- const array: TypedException.IProps<any>[] = (() => {
101
- const oldbie: TypedException.IProps<any>[] | undefined =
102
- Reflect.getMetadata(
103
- "nestia/TypedException",
104
- (target as any)[propertyKey],
105
- );
106
- if (oldbie !== undefined) return oldbie;
107
-
108
- const newbie: TypedException.IProps<any>[] = [];
109
- Reflect.defineMetadata(
110
- "nestia/TypedException",
111
- newbie,
112
- (target as any)[propertyKey],
113
- );
114
- return newbie;
115
- })();
116
- array.push(props);
117
- return descriptor;
118
- };
119
- }
120
- export namespace TypedException {
121
- /** Properties for the exception. */
122
- export interface IProps<T> {
123
- /** Status number or pattern like "2XX", "3XX", "4XX", "5XX". */
124
- status: number | "2XX" | "3XX" | "4XX" | "5XX";
125
-
126
- /** Description about the exception. */
127
- description?: string | undefined;
128
-
129
- /** Example value. */
130
- example?: T | undefined;
131
-
132
- /** Collection of examples for the exception. */
133
- examples?: Record<string, IExample<T>> | undefined;
134
- }
135
-
136
- /** Metadata collected in the {@link IProps.examples}. */
137
- export interface IExample<T> {
138
- /** Summary of the example. */
139
- summary?: string | undefined;
140
-
141
- /** Description of the example. */
142
- description?: string | undefined;
143
-
144
- /** Value of the example. */
145
- value: T;
146
- }
147
- }
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
7
+ * type which could be occurred in the method.
8
+ *
9
+ * For reference, this decorator function does not affect to the method's
10
+ * behavior, but only affects to the swagger documents generation. Also, it does
11
+ * not affect to the SDK library generation yet, but will be used in the
12
+ * future.
13
+ *
14
+ * @author Jeongho Nam - https://github.com/samchon
15
+ * @param props Properties for the exception
16
+ * @returns Method decorator
17
+ */
18
+ export function TypedException(props: TypedException.IProps<unknown>): never;
19
+
20
+ /**
21
+ * > You must configure the generic argument `T`
22
+ *
23
+ * Exception decorator.
24
+ *
25
+ * `TypedException` is a decorator function describing HTTP exception and its
26
+ * type which could be occurred in the method.
27
+ *
28
+ * For reference, this decorator function does not affect to the method's
29
+ * behavior, but only affects to the swagger documents generation. Also, it does
30
+ * not affect to the SDK library generation yet, but will be used in the
31
+ * future.
32
+ *
33
+ * @author Jeongho Nam - https://github.com/samchon
34
+ * @deprecated Use {@link TypedException.IProps} typed function instead. This
35
+ * typed function is deprecated and will be removed in the next major update.
36
+ * @param status Status number or pattern like "2XX", "3XX", "4XX", "5XX"
37
+ * @param description Description about the exception
38
+ * @returns Method decorator
39
+ */
40
+ export function TypedException(
41
+ status: number | "2XX" | "3XX" | "4XX" | "5XX",
42
+ description?: string | undefined,
43
+ ): never;
44
+
45
+ /**
46
+ * Exception decorator.
47
+ *
48
+ * `TypedException` is a decorator function describing HTTP exception and its
49
+ * type which could be occurred in the method.
50
+ *
51
+ * For reference, this decorator function does not affect to the method's
52
+ * behavior, but only affects to the swagger documents generation. Also, it does
53
+ * not affect to the SDK library generation yet, but will be used in the
54
+ * future.
55
+ *
56
+ * @author Jeongho Nam - https://github.com/samchon
57
+ * @template T Type of the exception
58
+ * @param props Properties for the exception
59
+ * @returns Method decorator
60
+ */
61
+ export function TypedException<T>(
62
+ props: TypedException.IProps<T>,
63
+ ): MethodDecorator;
64
+
65
+ /**
66
+ * Exception decorator.
67
+ *
68
+ * `TypedException` is a decorator function describing HTTP exception and its
69
+ * type which could be occurred in the method.
70
+ *
71
+ * For reference, this decorator function does not affect to the method's
72
+ * behavior, but only affects to the swagger documents generation. Also, it does
73
+ * not affect to the SDK library generation yet, but will be used in the
74
+ * future.
75
+ *
76
+ * @author Jeongho Nam - https://github.com/samchon
77
+ * @deprecated Use {@link TypedException.IProps} typed function instead. This
78
+ * typed function is deprecated and will be removed in the next major update.
79
+ * @template T Type of the exception
80
+ * @param status Status number or pattern like "2XX", "3XX", "4XX", "5XX"
81
+ * @param description Description about the exception
82
+ * @returns Method decorator
83
+ */
84
+ export function TypedException<T>(
85
+ status: number | "2XX" | "3XX" | "4XX" | "5XX",
86
+ description?: string | undefined,
87
+ ): MethodDecorator;
88
+
89
+ /** @internal */
90
+ export function TypedException<T>(...args: any[]): MethodDecorator {
91
+ const props: TypedException.IProps<T> =
92
+ typeof args[0] === "object"
93
+ ? args[0]
94
+ : { status: args[0], description: args[1] };
95
+ return function TypedException(
96
+ target: Object | T,
97
+ propertyKey: string | symbol,
98
+ descriptor: TypedPropertyDescriptor<any>,
99
+ ) {
100
+ const array: TypedException.IProps<any>[] = (() => {
101
+ const oldbie: TypedException.IProps<any>[] | undefined =
102
+ Reflect.getMetadata(
103
+ "nestia/TypedException",
104
+ (target as any)[propertyKey],
105
+ );
106
+ if (oldbie !== undefined) return oldbie;
107
+
108
+ const newbie: TypedException.IProps<any>[] = [];
109
+ Reflect.defineMetadata(
110
+ "nestia/TypedException",
111
+ newbie,
112
+ (target as any)[propertyKey],
113
+ );
114
+ return newbie;
115
+ })();
116
+ array.push(props);
117
+ return descriptor;
118
+ };
119
+ }
120
+ export namespace TypedException {
121
+ /** Properties for the exception. */
122
+ export interface IProps<T> {
123
+ /** Status number or pattern like "2XX", "3XX", "4XX", "5XX". */
124
+ status: number | "2XX" | "3XX" | "4XX" | "5XX";
125
+
126
+ /** Description about the exception. */
127
+ description?: string | undefined;
128
+
129
+ /** Example value. */
130
+ example?: T | undefined;
131
+
132
+ /** Collection of examples for the exception. */
133
+ examples?: Record<string, IExample<T>> | undefined;
134
+ }
135
+
136
+ /** Metadata collected in the {@link IProps.examples}. */
137
+ export interface IExample<T> {
138
+ /** Summary of the example. */
139
+ summary?: string | undefined;
140
+
141
+ /** Description of the example. */
142
+ description?: string | undefined;
143
+
144
+ /** Value of the example. */
145
+ value: T;
146
+ }
147
+ }