@nestia/core 10.0.2 → 11.0.0-dev.20260305

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 (155) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +93 -93
  3. package/lib/adaptors/WebSocketAdaptor.js.map +1 -1
  4. package/lib/decorators/DynamicModule.js +54 -10
  5. package/lib/decorators/DynamicModule.js.map +1 -1
  6. package/lib/decorators/EncryptedBody.js +2 -2
  7. package/lib/decorators/EncryptedBody.js.map +1 -1
  8. package/lib/decorators/EncryptedController.d.ts +1 -1
  9. package/lib/decorators/EncryptedModule.d.ts +1 -1
  10. package/lib/decorators/EncryptedModule.js +54 -10
  11. package/lib/decorators/EncryptedModule.js.map +1 -1
  12. package/lib/decorators/EncryptedRoute.js +2 -2
  13. package/lib/decorators/EncryptedRoute.js.map +1 -1
  14. package/lib/decorators/HumanRoute.d.ts +1 -2
  15. package/lib/decorators/HumanRoute.js +1 -2
  16. package/lib/decorators/HumanRoute.js.map +1 -1
  17. package/lib/decorators/NoTransformConfigurationError.js +1 -1
  18. package/lib/decorators/NoTransformConfigurationError.js.map +1 -1
  19. package/lib/decorators/SwaggerCustomizer.d.ts +1 -1
  20. package/lib/decorators/TypedFormData.js.map +1 -1
  21. package/lib/decorators/TypedParam.js +1 -1
  22. package/lib/decorators/TypedParam.js.map +1 -1
  23. package/lib/decorators/internal/get_path_and_querify.js +1 -1
  24. package/lib/decorators/internal/get_path_and_querify.js.map +1 -1
  25. package/lib/decorators/internal/get_path_and_stringify.js +1 -1
  26. package/lib/decorators/internal/get_path_and_stringify.js.map +1 -1
  27. package/lib/decorators/internal/headers_to_object.js.map +1 -1
  28. package/lib/decorators/internal/validate_request_body.js +1 -1
  29. package/lib/decorators/internal/validate_request_body.js.map +1 -1
  30. package/lib/decorators/internal/validate_request_form_data.js +1 -1
  31. package/lib/decorators/internal/validate_request_form_data.js.map +1 -1
  32. package/lib/decorators/internal/validate_request_headers.js +1 -1
  33. package/lib/decorators/internal/validate_request_headers.js.map +1 -1
  34. package/lib/decorators/internal/validate_request_query.js +1 -1
  35. package/lib/decorators/internal/validate_request_query.js.map +1 -1
  36. package/lib/module.d.ts +1 -0
  37. package/lib/module.js +1 -0
  38. package/lib/module.js.map +1 -1
  39. package/lib/options/INestiaTransformProject.d.ts +1 -1
  40. package/lib/programmers/PlainBodyProgrammer.js +5 -8
  41. package/lib/programmers/PlainBodyProgrammer.js.map +1 -1
  42. package/lib/programmers/TypedBodyProgrammer.js +13 -21
  43. package/lib/programmers/TypedBodyProgrammer.js.map +1 -1
  44. package/lib/programmers/TypedFormDataBodyProgrammer.js +11 -20
  45. package/lib/programmers/TypedFormDataBodyProgrammer.js.map +1 -1
  46. package/lib/programmers/TypedHeadersProgrammer.js +4 -6
  47. package/lib/programmers/TypedHeadersProgrammer.js.map +1 -1
  48. package/lib/programmers/TypedParamProgrammer.js +2 -2
  49. package/lib/programmers/TypedParamProgrammer.js.map +1 -1
  50. package/lib/programmers/TypedQueryBodyProgrammer.js +9 -16
  51. package/lib/programmers/TypedQueryBodyProgrammer.js.map +1 -1
  52. package/lib/programmers/TypedQueryProgrammer.js +9 -16
  53. package/lib/programmers/TypedQueryProgrammer.js.map +1 -1
  54. package/lib/programmers/TypedQueryRouteProgrammer.js +6 -10
  55. package/lib/programmers/TypedQueryRouteProgrammer.js.map +1 -1
  56. package/lib/programmers/TypedRouteProgrammer.js +8 -13
  57. package/lib/programmers/TypedRouteProgrammer.js.map +1 -1
  58. package/lib/programmers/http/HttpAssertQuerifyProgrammer.d.ts +1 -1
  59. package/lib/programmers/http/HttpAssertQuerifyProgrammer.js +5 -7
  60. package/lib/programmers/http/HttpAssertQuerifyProgrammer.js.map +1 -1
  61. package/lib/programmers/http/HttpIsQuerifyProgrammer.d.ts +1 -1
  62. package/lib/programmers/http/HttpIsQuerifyProgrammer.js +5 -7
  63. package/lib/programmers/http/HttpIsQuerifyProgrammer.js.map +1 -1
  64. package/lib/programmers/http/HttpQuerifyProgrammer.d.ts +1 -1
  65. package/lib/programmers/http/HttpQuerifyProgrammer.js +13 -19
  66. package/lib/programmers/http/HttpQuerifyProgrammer.js.map +1 -1
  67. package/lib/programmers/http/HttpValidateQuerifyProgrammer.d.ts +1 -1
  68. package/lib/programmers/http/HttpValidateQuerifyProgrammer.js +6 -8
  69. package/lib/programmers/http/HttpValidateQuerifyProgrammer.js.map +1 -1
  70. package/lib/programmers/internal/CoreMetadataUtil.d.ts +3 -3
  71. package/lib/programmers/internal/CoreMetadataUtil.js.map +1 -1
  72. package/lib/transform.d.ts +1 -1
  73. package/lib/transform.js.map +1 -1
  74. package/lib/transformers/FileTransformer.js +2 -2
  75. package/lib/transformers/FileTransformer.js.map +1 -1
  76. package/lib/transformers/MethodTransformer.js.map +1 -1
  77. package/lib/transformers/ParameterDecoratorTransformer.js +1 -1
  78. package/lib/transformers/ParameterDecoratorTransformer.js.map +1 -1
  79. package/lib/transformers/TypedRouteTransformer.js +1 -1
  80. package/lib/transformers/TypedRouteTransformer.js.map +1 -1
  81. package/lib/transformers/WebSocketRouteTransformer.js +1 -1
  82. package/lib/transformers/WebSocketRouteTransformer.js.map +1 -1
  83. package/package.json +34 -26
  84. package/src/adaptors/WebSocketAdaptor.ts +429 -429
  85. package/src/decorators/DynamicModule.ts +44 -44
  86. package/src/decorators/EncryptedBody.ts +96 -97
  87. package/src/decorators/EncryptedController.ts +40 -40
  88. package/src/decorators/EncryptedModule.ts +98 -98
  89. package/src/decorators/EncryptedRoute.ts +212 -213
  90. package/src/decorators/HumanRoute.ts +21 -22
  91. package/src/decorators/NoTransformConfigurationError.ts +34 -34
  92. package/src/decorators/PlainBody.ts +76 -76
  93. package/src/decorators/SwaggerCustomizer.ts +97 -97
  94. package/src/decorators/SwaggerExample.ts +100 -100
  95. package/src/decorators/TypedBody.ts +57 -57
  96. package/src/decorators/TypedException.ts +147 -147
  97. package/src/decorators/TypedFormData.ts +187 -195
  98. package/src/decorators/TypedHeaders.ts +66 -66
  99. package/src/decorators/TypedParam.ts +77 -77
  100. package/src/decorators/TypedQuery.ts +234 -234
  101. package/src/decorators/TypedRoute.ts +196 -196
  102. package/src/decorators/WebSocketRoute.ts +242 -242
  103. package/src/decorators/internal/EncryptedConstant.ts +2 -2
  104. package/src/decorators/internal/IWebSocketRouteReflect.ts +23 -23
  105. package/src/decorators/internal/NoTransformConfigureError.ts +2 -2
  106. package/src/decorators/internal/get_path_and_querify.ts +94 -94
  107. package/src/decorators/internal/get_path_and_stringify.ts +110 -110
  108. package/src/decorators/internal/get_text_body.ts +16 -16
  109. package/src/decorators/internal/headers_to_object.ts +11 -11
  110. package/src/decorators/internal/is_request_body_undefined.ts +12 -12
  111. package/src/decorators/internal/load_controller.ts +45 -45
  112. package/src/decorators/internal/route_error.ts +43 -43
  113. package/src/decorators/internal/validate_request_body.ts +64 -64
  114. package/src/decorators/internal/validate_request_form_data.ts +67 -67
  115. package/src/decorators/internal/validate_request_headers.ts +76 -76
  116. package/src/decorators/internal/validate_request_query.ts +64 -64
  117. package/src/index.ts +5 -5
  118. package/src/module.ts +23 -22
  119. package/src/options/INestiaTransformOptions.ts +34 -34
  120. package/src/options/INestiaTransformProject.ts +10 -8
  121. package/src/options/IRequestBodyValidator.ts +20 -20
  122. package/src/options/IRequestFormDataProps.ts +27 -27
  123. package/src/options/IRequestHeadersValidator.ts +22 -22
  124. package/src/options/IRequestQueryValidator.ts +20 -20
  125. package/src/options/IResponseBodyQuerifier.ts +25 -25
  126. package/src/options/IResponseBodyStringifier.ts +30 -30
  127. package/src/programmers/PlainBodyProgrammer.ts +72 -70
  128. package/src/programmers/TypedBodyProgrammer.ts +144 -142
  129. package/src/programmers/TypedFormDataBodyProgrammer.ts +118 -118
  130. package/src/programmers/TypedHeadersProgrammer.ts +65 -63
  131. package/src/programmers/TypedParamProgrammer.ts +33 -33
  132. package/src/programmers/TypedQueryBodyProgrammer.ts +111 -109
  133. package/src/programmers/TypedQueryProgrammer.ts +113 -111
  134. package/src/programmers/TypedQueryRouteProgrammer.ts +104 -102
  135. package/src/programmers/TypedRouteProgrammer.ts +96 -94
  136. package/src/programmers/http/HttpAssertQuerifyProgrammer.ts +74 -72
  137. package/src/programmers/http/HttpIsQuerifyProgrammer.ts +77 -75
  138. package/src/programmers/http/HttpQuerifyProgrammer.ts +110 -108
  139. package/src/programmers/http/HttpValidateQuerifyProgrammer.ts +78 -76
  140. package/src/programmers/internal/CoreMetadataUtil.ts +21 -21
  141. package/src/transform.ts +35 -35
  142. package/src/transformers/FileTransformer.ts +109 -110
  143. package/src/transformers/MethodTransformer.ts +103 -103
  144. package/src/transformers/NodeTransformer.ts +23 -23
  145. package/src/transformers/ParameterDecoratorTransformer.ts +143 -143
  146. package/src/transformers/ParameterTransformer.ts +57 -57
  147. package/src/transformers/TypedRouteTransformer.ts +85 -85
  148. package/src/transformers/WebSocketRouteTransformer.ts +120 -120
  149. package/src/typings/Creator.ts +3 -3
  150. package/src/typings/get-function-location.d.ts +7 -7
  151. package/src/utils/ArrayUtil.ts +7 -7
  152. package/src/utils/ExceptionManager.ts +115 -115
  153. package/src/utils/Singleton.ts +16 -16
  154. package/src/utils/SourceFinder.ts +54 -54
  155. package/src/utils/VersioningStrategy.ts +27 -27
@@ -1,94 +1,94 @@
1
- import { InternalServerErrorException } from "@nestjs/common";
2
- import typia, { IValidation, TypeGuardError } from "typia";
3
-
4
- import { IResponseBodyQuerifier } from "../../options/IResponseBodyQuerifier";
5
- import { NoTransformConfigurationError } from "../NoTransformConfigurationError";
6
-
7
- /** @internal */
8
- export const get_path_and_querify =
9
- (method: string) =>
10
- (
11
- ...args: any[]
12
- ): [string | string[] | undefined, (input: any) => URLSearchParams] => {
13
- const path: string | string[] | null | undefined =
14
- args[0] === undefined ||
15
- typeof args[0] === "string" ||
16
- Array.isArray(args[0])
17
- ? args[0]
18
- : null;
19
- const functor: IResponseBodyQuerifier<any> | undefined =
20
- path === null ? args[0] : args[1];
21
- return [path ?? undefined, take(method)(functor)];
22
- };
23
-
24
- /** @internal */
25
- const take =
26
- (method: string) =>
27
- <T>(functor?: IResponseBodyQuerifier<T> | null) => {
28
- if (functor === undefined) {
29
- NoTransformConfigurationError(method);
30
- return querify;
31
- } else if (functor === null) return querify;
32
- else if (functor.type === "stringify") return functor.stringify;
33
- else if (functor.type === "assert") return assert(functor.assert);
34
- else if (functor.type === "is") return is(functor.is);
35
- else if (functor.type === "validate") return validate(functor.validate);
36
- throw new Error(
37
- `Error on nestia.core.${method}(): invalid typed stringify function.`,
38
- );
39
- };
40
-
41
- /** @internal */
42
- const querify = (input: Record<string, any>): URLSearchParams => {
43
- const output: URLSearchParams = new URLSearchParams();
44
- for (const [key, value] of Object.entries(input))
45
- if (key === undefined) continue;
46
- else if (Array.isArray(value))
47
- for (const elem of value) output.append(key, String(elem));
48
- else output.append(key, String(value));
49
- return output;
50
- };
51
-
52
- /** @internal */
53
- const assert =
54
- <T>(closure: (data: T) => URLSearchParams) =>
55
- (data: T) => {
56
- try {
57
- return closure(data);
58
- } catch (exp) {
59
- if (typia.is<TypeGuardError>(exp))
60
- throw new InternalServerErrorException({
61
- path: exp.path,
62
- reason: exp.message,
63
- expected: exp.expected,
64
- value: exp.value,
65
- message: MESSAGE,
66
- });
67
- throw exp;
68
- }
69
- };
70
-
71
- /** @internal */
72
- const is =
73
- <T>(closure: (data: T) => URLSearchParams | null) =>
74
- (data: T) => {
75
- const result: URLSearchParams | null = closure(data);
76
- if (result === null) throw new InternalServerErrorException(MESSAGE);
77
- return result;
78
- };
79
-
80
- /** @internal */
81
- const validate =
82
- <T>(closure: (data: T) => IValidation<URLSearchParams>) =>
83
- (data: T) => {
84
- const result: IValidation<URLSearchParams> = closure(data);
85
- if (result.success === false)
86
- throw new InternalServerErrorException({
87
- errors: result.errors,
88
- message: MESSAGE,
89
- });
90
- return result.data;
91
- };
92
-
93
- /** @internal */
94
- const MESSAGE = "Response body data is not following the promised type.";
1
+ import { InternalServerErrorException } from "@nestjs/common";
2
+ import typia, { IValidation, TypeGuardError } from "typia";
3
+
4
+ import { IResponseBodyQuerifier } from "../../options/IResponseBodyQuerifier";
5
+ import { NoTransformConfigurationError } from "../NoTransformConfigurationError";
6
+
7
+ /** @internal */
8
+ export const get_path_and_querify =
9
+ (method: string) =>
10
+ (
11
+ ...args: any[]
12
+ ): [string | string[] | undefined, (input: any) => URLSearchParams] => {
13
+ const path: string | string[] | null | undefined =
14
+ args[0] === undefined ||
15
+ typeof args[0] === "string" ||
16
+ Array.isArray(args[0])
17
+ ? args[0]
18
+ : null;
19
+ const functor: IResponseBodyQuerifier<any> | undefined =
20
+ path === null ? args[0] : args[1];
21
+ return [path ?? undefined, take(method)(functor)];
22
+ };
23
+
24
+ /** @internal */
25
+ const take =
26
+ (method: string) =>
27
+ <T>(functor?: IResponseBodyQuerifier<T> | null) => {
28
+ if (functor === undefined) {
29
+ NoTransformConfigurationError(method);
30
+ return querify;
31
+ } else if (functor === null) return querify;
32
+ else if (functor.type === "stringify") return functor.stringify;
33
+ else if (functor.type === "assert") return assert(functor.assert);
34
+ else if (functor.type === "is") return is(functor.is);
35
+ else if (functor.type === "validate") return validate(functor.validate);
36
+ throw new Error(
37
+ `Error on nestia.core.${method}(): invalid typed stringify function.`,
38
+ );
39
+ };
40
+
41
+ /** @internal */
42
+ const querify = (input: Record<string, any>): URLSearchParams => {
43
+ const output: URLSearchParams = new URLSearchParams();
44
+ for (const [key, value] of Object.entries(input))
45
+ if (key === undefined) continue;
46
+ else if (Array.isArray(value))
47
+ for (const elem of value) output.append(key, String(elem));
48
+ else output.append(key, String(value));
49
+ return output;
50
+ };
51
+
52
+ /** @internal */
53
+ const assert =
54
+ <T>(closure: (data: T) => URLSearchParams) =>
55
+ (data: T) => {
56
+ try {
57
+ return closure(data);
58
+ } catch (exp) {
59
+ if (typia.is<TypeGuardError>(exp))
60
+ throw new InternalServerErrorException({
61
+ path: exp.path,
62
+ reason: exp.message,
63
+ expected: exp.expected,
64
+ value: exp.value,
65
+ message: MESSAGE,
66
+ });
67
+ throw exp;
68
+ }
69
+ };
70
+
71
+ /** @internal */
72
+ const is =
73
+ <T>(closure: (data: T) => URLSearchParams | null) =>
74
+ (data: T) => {
75
+ const result: URLSearchParams | null = closure(data);
76
+ if (result === null) throw new InternalServerErrorException(MESSAGE);
77
+ return result;
78
+ };
79
+
80
+ /** @internal */
81
+ const validate =
82
+ <T>(closure: (data: T) => IValidation<URLSearchParams>) =>
83
+ (data: T) => {
84
+ const result: IValidation<URLSearchParams> = closure(data);
85
+ if (result.success === false)
86
+ throw new InternalServerErrorException({
87
+ errors: result.errors,
88
+ message: MESSAGE,
89
+ });
90
+ return result.data;
91
+ };
92
+
93
+ /** @internal */
94
+ const MESSAGE = "Response body data is not following the promised type.";
@@ -1,110 +1,110 @@
1
- import { InternalServerErrorException } from "@nestjs/common";
2
- import typia, { IValidation, TypeGuardError } from "typia";
3
-
4
- import { IResponseBodyStringifier } from "../../options/IResponseBodyStringifier";
5
- import { NoTransformConfigurationError } from "../NoTransformConfigurationError";
6
- import { TypedRoute } from "../TypedRoute";
7
-
8
- /** @internal */
9
- export const get_path_and_stringify =
10
- (logger: () => (log: TypedRoute.IValidateErrorLog) => void) =>
11
- (method: string) =>
12
- (
13
- ...args: any[]
14
- ): [
15
- string | string[] | undefined,
16
- (input: any, _method: string, _path: string) => string,
17
- ] => {
18
- const path: string | string[] | null | undefined =
19
- args[0] === undefined ||
20
- typeof args[0] === "string" ||
21
- Array.isArray(args[0])
22
- ? args[0]
23
- : null;
24
- const functor: IResponseBodyStringifier<any> | undefined =
25
- path === null ? args[0] : args[1];
26
- return [path ?? undefined, take(logger)(method)(functor)];
27
- };
28
-
29
- /** @internal */
30
- const take =
31
- (logger: () => (log: TypedRoute.IValidateErrorLog) => void) =>
32
- (method: string) =>
33
- <T>(functor?: IResponseBodyStringifier<T> | null) => {
34
- if (functor === undefined) {
35
- NoTransformConfigurationError(method);
36
- return (input: T, _method: string, _path: string) =>
37
- JSON.stringify(input);
38
- } else if (functor === null)
39
- return (input: T, _method: string, _path: string) =>
40
- JSON.stringify(input);
41
- else if (functor.type === "stringify") return functor.stringify;
42
- else if (functor.type === "assert") return assert(functor.assert);
43
- else if (functor.type === "is") return is(functor.is);
44
- else if (functor.type === "validate") return validate(functor.validate);
45
- else if (functor.type === "validate.log")
46
- return validateLog(logger)(functor.validate);
47
- throw new Error(
48
- `Error on nestia.core.${method}(): invalid typed stringify function.`,
49
- );
50
- };
51
-
52
- /** @internal */
53
- const assert =
54
- <T>(closure: (data: T) => string) =>
55
- (data: T): string => {
56
- try {
57
- return closure(data);
58
- } catch (exp) {
59
- if (typia.is<TypeGuardError>(exp))
60
- throw new InternalServerErrorException({
61
- path: exp.path,
62
- reason: exp.message,
63
- expected: exp.expected,
64
- value: exp.value,
65
- message: MESSAGE,
66
- });
67
- throw exp;
68
- }
69
- };
70
-
71
- /** @internal */
72
- const is =
73
- <T>(closure: (data: T) => string | null) =>
74
- (data: T, _method: string, _path: string) => {
75
- const result: string | null = closure(data);
76
- if (result === null) throw new InternalServerErrorException(MESSAGE);
77
- return result;
78
- };
79
-
80
- /** @internal */
81
- const validate =
82
- <T>(closure: (data: T) => IValidation<string>) =>
83
- (data: T, _method: string, _path: string): string => {
84
- const result: IValidation<string> = closure(data);
85
- if (result.success === false)
86
- throw new InternalServerErrorException({
87
- errors: result.errors,
88
- message: MESSAGE,
89
- });
90
- return result.data;
91
- };
92
-
93
- const validateLog =
94
- (logger: () => (log: TypedRoute.IValidateErrorLog) => void) =>
95
- <T>(closure: (data: T) => IValidation<any>) =>
96
- (data: T, method: string, path: string): string => {
97
- const result: IValidation<string> = closure(data);
98
- if (result.success === true) return result.data;
99
- if (result.success === false)
100
- logger()({
101
- errors: result.errors,
102
- method,
103
- path,
104
- data,
105
- });
106
- return JSON.stringify(data);
107
- };
108
-
109
- /** @internal */
110
- const MESSAGE = "Response body data is not following the promised type.";
1
+ import { InternalServerErrorException } from "@nestjs/common";
2
+ import typia, { IValidation, TypeGuardError } from "typia";
3
+
4
+ import { IResponseBodyStringifier } from "../../options/IResponseBodyStringifier";
5
+ import { NoTransformConfigurationError } from "../NoTransformConfigurationError";
6
+ import { TypedRoute } from "../TypedRoute";
7
+
8
+ /** @internal */
9
+ export const get_path_and_stringify =
10
+ (logger: () => (log: TypedRoute.IValidateErrorLog) => void) =>
11
+ (method: string) =>
12
+ (
13
+ ...args: any[]
14
+ ): [
15
+ string | string[] | undefined,
16
+ (input: any, _method: string, _path: string) => string,
17
+ ] => {
18
+ const path: string | string[] | null | undefined =
19
+ args[0] === undefined ||
20
+ typeof args[0] === "string" ||
21
+ Array.isArray(args[0])
22
+ ? args[0]
23
+ : null;
24
+ const functor: IResponseBodyStringifier<any> | undefined =
25
+ path === null ? args[0] : args[1];
26
+ return [path ?? undefined, take(logger)(method)(functor)];
27
+ };
28
+
29
+ /** @internal */
30
+ const take =
31
+ (logger: () => (log: TypedRoute.IValidateErrorLog) => void) =>
32
+ (method: string) =>
33
+ <T>(functor?: IResponseBodyStringifier<T> | null) => {
34
+ if (functor === undefined) {
35
+ NoTransformConfigurationError(method);
36
+ return (input: T, _method: string, _path: string) =>
37
+ JSON.stringify(input);
38
+ } else if (functor === null)
39
+ return (input: T, _method: string, _path: string) =>
40
+ JSON.stringify(input);
41
+ else if (functor.type === "stringify") return functor.stringify;
42
+ else if (functor.type === "assert") return assert(functor.assert);
43
+ else if (functor.type === "is") return is(functor.is);
44
+ else if (functor.type === "validate") return validate(functor.validate);
45
+ else if (functor.type === "validate.log")
46
+ return validateLog(logger)(functor.validate);
47
+ throw new Error(
48
+ `Error on nestia.core.${method}(): invalid typed stringify function.`,
49
+ );
50
+ };
51
+
52
+ /** @internal */
53
+ const assert =
54
+ <T>(closure: (data: T) => string) =>
55
+ (data: T): string => {
56
+ try {
57
+ return closure(data);
58
+ } catch (exp) {
59
+ if (typia.is<TypeGuardError>(exp))
60
+ throw new InternalServerErrorException({
61
+ path: exp.path,
62
+ reason: exp.message,
63
+ expected: exp.expected,
64
+ value: exp.value,
65
+ message: MESSAGE,
66
+ });
67
+ throw exp;
68
+ }
69
+ };
70
+
71
+ /** @internal */
72
+ const is =
73
+ <T>(closure: (data: T) => string | null) =>
74
+ (data: T, _method: string, _path: string) => {
75
+ const result: string | null = closure(data);
76
+ if (result === null) throw new InternalServerErrorException(MESSAGE);
77
+ return result;
78
+ };
79
+
80
+ /** @internal */
81
+ const validate =
82
+ <T>(closure: (data: T) => IValidation<string>) =>
83
+ (data: T, _method: string, _path: string): string => {
84
+ const result: IValidation<string> = closure(data);
85
+ if (result.success === false)
86
+ throw new InternalServerErrorException({
87
+ errors: result.errors,
88
+ message: MESSAGE,
89
+ });
90
+ return result.data;
91
+ };
92
+
93
+ const validateLog =
94
+ (logger: () => (log: TypedRoute.IValidateErrorLog) => void) =>
95
+ <T>(closure: (data: T) => IValidation<any>) =>
96
+ (data: T, method: string, path: string): string => {
97
+ const result: IValidation<string> = closure(data);
98
+ if (result.success === true) return result.data;
99
+ if (result.success === false)
100
+ logger()({
101
+ errors: result.errors,
102
+ method,
103
+ path,
104
+ data,
105
+ });
106
+ return JSON.stringify(data);
107
+ };
108
+
109
+ /** @internal */
110
+ const MESSAGE = "Response body data is not following the promised type.";
@@ -1,16 +1,16 @@
1
- import type express from "express";
2
- import type { FastifyRequest } from "fastify";
3
- import raw from "raw-body";
4
-
5
- /** @internal */
6
- export const get_text_body = async (
7
- request: express.Request | FastifyRequest,
8
- ): Promise<string> =>
9
- isExpressRequest(request)
10
- ? (await raw(request)).toString("utf8")
11
- : (request.body as string);
12
-
13
- /** @internal */
14
- const isExpressRequest = (
15
- request: express.Request | FastifyRequest,
16
- ): request is express.Request => (request as express.Request).app !== undefined;
1
+ import type express from "express";
2
+ import type { FastifyRequest } from "fastify";
3
+ import raw from "raw-body";
4
+
5
+ /** @internal */
6
+ export const get_text_body = async (
7
+ request: express.Request | FastifyRequest,
8
+ ): Promise<string> =>
9
+ isExpressRequest(request)
10
+ ? (await raw(request)).toString("utf8")
11
+ : (request.body as string);
12
+
13
+ /** @internal */
14
+ const isExpressRequest = (
15
+ request: express.Request | FastifyRequest,
16
+ ): request is express.Request => (request as express.Request).app !== undefined;
@@ -1,11 +1,11 @@
1
- import http from "http";
2
-
3
- /** @internal */
4
- export function headers_to_object(
5
- headers: http.IncomingHttpHeaders,
6
- ): Record<string, string> {
7
- const output: Record<string, string> = {};
8
- for (const [key, value] of Object.entries(headers))
9
- output[key] = value instanceof Array ? value[0] : value || "";
10
- return output;
11
- }
1
+ import http from "http";
2
+
3
+ /** @internal */
4
+ export function headers_to_object(
5
+ headers: http.IncomingHttpHeaders,
6
+ ): Record<string, string> {
7
+ const output: Record<string, string> = {};
8
+ for (const [key, value] of Object.entries(headers))
9
+ output[key] = value instanceof Array ? value[0]! : value || "";
10
+ return output;
11
+ }
@@ -1,12 +1,12 @@
1
- import type express from "express";
2
- import type { FastifyRequest } from "fastify";
3
-
4
- /** @internal */
5
- export const is_request_body_undefined = (
6
- request: express.Request | FastifyRequest,
7
- ): boolean =>
8
- request.headers["content-type"] === undefined &&
9
- (request.body === undefined ||
10
- (typeof request.body === "object" &&
11
- request.body !== null &&
12
- Object.keys(request.body).length === 0));
1
+ import type express from "express";
2
+ import type { FastifyRequest } from "fastify";
3
+
4
+ /** @internal */
5
+ export const is_request_body_undefined = (
6
+ request: express.Request | FastifyRequest,
7
+ ): boolean =>
8
+ request.headers["content-type"] === undefined &&
9
+ (request.body === undefined ||
10
+ (typeof request.body === "object" &&
11
+ request.body !== null &&
12
+ Object.keys(request.body).length === 0));
@@ -1,45 +1,45 @@
1
- import is_ts_node from "detect-ts-node";
2
-
3
- import { Creator } from "../../typings/Creator";
4
- import { SourceFinder } from "../../utils/SourceFinder";
5
-
6
- export const load_controllers = async (
7
- path: string | string[] | { include: string[]; exclude?: string[] },
8
- isTsNode?: boolean,
9
- ): Promise<Creator<object>[]> => {
10
- const sources: string[] = await SourceFinder.find({
11
- include: Array.isArray(path)
12
- ? path
13
- : typeof path === "object"
14
- ? path.include
15
- : [path],
16
- exclude:
17
- typeof path === "object" && !Array.isArray(path)
18
- ? (path.exclude ?? [])
19
- : [],
20
- filter:
21
- isTsNode === true || EXTENSION === "ts"
22
- ? (file) =>
23
- file.substring(file.length - 3) === ".ts" &&
24
- file.substring(file.length - 5) !== ".d.ts"
25
- : (flle) => flle.substring(flle.length - 3) === ".js",
26
- });
27
- return mount(sources);
28
- };
29
-
30
- /** @internal */
31
- async function mount(sources: string[]): Promise<any[]> {
32
- const controllers: any[] = [];
33
- for (const file of sources) {
34
- const external: any = await import(file);
35
- for (const key in external) {
36
- const instance: Creator<object> = external[key];
37
- if (Reflect.getMetadata("path", instance) !== undefined)
38
- controllers.push(instance);
39
- }
40
- }
41
- return controllers;
42
- }
43
-
44
- /** @internal */
45
- const EXTENSION = is_ts_node ? "ts" : "js";
1
+ import is_ts_node from "detect-ts-node";
2
+
3
+ import { Creator } from "../../typings/Creator";
4
+ import { SourceFinder } from "../../utils/SourceFinder";
5
+
6
+ export const load_controllers = async (
7
+ path: string | string[] | { include: string[]; exclude?: string[] },
8
+ isTsNode?: boolean,
9
+ ): Promise<Creator<object>[]> => {
10
+ const sources: string[] = await SourceFinder.find({
11
+ include: Array.isArray(path)
12
+ ? path
13
+ : typeof path === "object"
14
+ ? path.include
15
+ : [path],
16
+ exclude:
17
+ typeof path === "object" && !Array.isArray(path)
18
+ ? (path.exclude ?? [])
19
+ : [],
20
+ filter:
21
+ isTsNode === true || EXTENSION === "ts"
22
+ ? (file) =>
23
+ file.substring(file.length - 3) === ".ts" &&
24
+ file.substring(file.length - 5) !== ".d.ts"
25
+ : (flle) => flle.substring(flle.length - 3) === ".js",
26
+ });
27
+ return mount(sources);
28
+ };
29
+
30
+ /** @internal */
31
+ async function mount(sources: string[]): Promise<any[]> {
32
+ const controllers: any[] = [];
33
+ for (const file of sources) {
34
+ const external: any = await import(file);
35
+ for (const key in external) {
36
+ const instance: Creator<object> = external[key];
37
+ if (Reflect.getMetadata("path", instance) !== undefined)
38
+ controllers.push(instance);
39
+ }
40
+ }
41
+ return controllers;
42
+ }
43
+
44
+ /** @internal */
45
+ const EXTENSION = is_ts_node ? "ts" : "js";
@@ -1,43 +1,43 @@
1
- import { HttpException } from "@nestjs/common";
2
- import express from "express";
3
- import type { FastifyRequest } from "fastify";
4
- import { throwError } from "rxjs";
5
-
6
- import { ExceptionManager } from "../../utils/ExceptionManager";
7
-
8
- /** @internal */
9
- export function route_error(
10
- request: express.Request | FastifyRequest,
11
- error: any,
12
- ) {
13
- error = (() => {
14
- // HTTP-ERROR
15
- if (error instanceof HttpException) return error;
16
-
17
- // CUSTOM-REGISTERED ERROR
18
- for (const [creator, closure] of ExceptionManager.tuples)
19
- if (error instanceof creator) return closure(error);
20
-
21
- // MAYBE INTERNAL ERROR
22
- return error;
23
- })();
24
-
25
- try {
26
- error.method = request.method;
27
- error.path =
28
- (request as express.Request).path ??
29
- (request as FastifyRequest).routeOptions?.url ??
30
- (request as any).routerPath;
31
- } catch {}
32
-
33
- setTimeout(() => {
34
- for (const listener of ExceptionManager.listeners) {
35
- try {
36
- const res: any | Promise<any> = listener(error);
37
- if (typeof res === "object" && typeof res.catch === "function")
38
- res.catch(() => {});
39
- } catch {}
40
- }
41
- }, 0);
42
- return throwError(() => error);
43
- }
1
+ import { HttpException } from "@nestjs/common";
2
+ import express from "express";
3
+ import type { FastifyRequest } from "fastify";
4
+ import { throwError } from "rxjs";
5
+
6
+ import { ExceptionManager } from "../../utils/ExceptionManager";
7
+
8
+ /** @internal */
9
+ export function route_error(
10
+ request: express.Request | FastifyRequest,
11
+ error: any,
12
+ ) {
13
+ error = (() => {
14
+ // HTTP-ERROR
15
+ if (error instanceof HttpException) return error;
16
+
17
+ // CUSTOM-REGISTERED ERROR
18
+ for (const [creator, closure] of ExceptionManager.tuples)
19
+ if (error instanceof creator) return closure(error);
20
+
21
+ // MAYBE INTERNAL ERROR
22
+ return error;
23
+ })();
24
+
25
+ try {
26
+ error.method = request.method;
27
+ error.path =
28
+ (request as express.Request).path ??
29
+ (request as FastifyRequest).routeOptions?.url ??
30
+ (request as any).routerPath;
31
+ } catch {}
32
+
33
+ setTimeout(() => {
34
+ for (const listener of ExceptionManager.listeners) {
35
+ try {
36
+ const res: any | Promise<any> = listener(error);
37
+ if (typeof res === "object" && typeof res.catch === "function")
38
+ res.catch(() => {});
39
+ } catch {}
40
+ }
41
+ }, 0);
42
+ return throwError(() => error);
43
+ }