@nestia/core 4.6.1 → 5.0.0-dev.20250223

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 (87) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +92 -87
  3. package/lib/decorators/DynamicModule.d.ts +1 -1
  4. package/lib/decorators/DynamicModule.js +1 -1
  5. package/lib/decorators/EncryptedBody.d.ts +2 -2
  6. package/lib/decorators/EncryptedBody.js +2 -2
  7. package/lib/decorators/TypedException.d.ts +4 -4
  8. package/lib/decorators/TypedRoute.d.ts +1 -1
  9. package/lib/decorators/WebSocketRoute.d.ts +1 -1
  10. package/lib/decorators/WebSocketRoute.js +1 -1
  11. package/lib/programmers/TypedBodyProgrammer.js +4 -4
  12. package/lib/programmers/TypedBodyProgrammer.js.map +1 -1
  13. package/lib/utils/ExceptionManager.d.ts +1 -1
  14. package/lib/utils/ExceptionManager.js +1 -1
  15. package/package.json +6 -6
  16. package/src/adaptors/WebSocketAdaptor.ts +429 -429
  17. package/src/decorators/DynamicModule.ts +43 -43
  18. package/src/decorators/EncryptedBody.ts +101 -101
  19. package/src/decorators/EncryptedController.ts +38 -38
  20. package/src/decorators/EncryptedModule.ts +100 -100
  21. package/src/decorators/EncryptedRoute.ts +219 -219
  22. package/src/decorators/HumanRoute.ts +22 -22
  23. package/src/decorators/NoTransformConfigurationError.ts +32 -32
  24. package/src/decorators/PlainBody.ts +79 -79
  25. package/src/decorators/SwaggerCustomizer.ts +115 -115
  26. package/src/decorators/SwaggerExample.ts +100 -100
  27. package/src/decorators/TypedBody.ts +59 -59
  28. package/src/decorators/TypedException.ts +166 -166
  29. package/src/decorators/TypedFormData.ts +195 -195
  30. package/src/decorators/TypedHeaders.ts +64 -64
  31. package/src/decorators/TypedParam.ts +77 -77
  32. package/src/decorators/TypedQuery.ts +245 -245
  33. package/src/decorators/TypedRoute.ts +214 -214
  34. package/src/decorators/WebSocketRoute.ts +242 -242
  35. package/src/decorators/internal/EncryptedConstant.ts +4 -4
  36. package/src/decorators/internal/IWebSocketRouteReflect.ts +23 -23
  37. package/src/decorators/internal/NoTransformConfigureError.ts +2 -2
  38. package/src/decorators/internal/get_path_and_querify.ts +108 -108
  39. package/src/decorators/internal/get_path_and_stringify.ts +122 -122
  40. package/src/decorators/internal/get_text_body.ts +20 -20
  41. package/src/decorators/internal/headers_to_object.ts +13 -13
  42. package/src/decorators/internal/is_request_body_undefined.ts +14 -14
  43. package/src/decorators/internal/load_controller.ts +49 -49
  44. package/src/decorators/internal/route_error.ts +45 -45
  45. package/src/decorators/internal/validate_request_body.ts +74 -74
  46. package/src/decorators/internal/validate_request_form_data.ts +77 -77
  47. package/src/decorators/internal/validate_request_headers.ts +86 -86
  48. package/src/decorators/internal/validate_request_query.ts +74 -74
  49. package/src/index.ts +5 -5
  50. package/src/module.ts +22 -22
  51. package/src/options/INestiaTransformOptions.ts +38 -38
  52. package/src/options/INestiaTransformProject.ts +8 -8
  53. package/src/options/IRequestBodyValidator.ts +20 -20
  54. package/src/options/IRequestFormDataProps.ts +27 -27
  55. package/src/options/IRequestHeadersValidator.ts +22 -22
  56. package/src/options/IRequestQueryValidator.ts +20 -20
  57. package/src/options/IResponseBodyQuerifier.ts +25 -25
  58. package/src/options/IResponseBodyStringifier.ts +30 -30
  59. package/src/programmers/PlainBodyProgrammer.ts +70 -70
  60. package/src/programmers/TypedBodyProgrammer.ts +142 -142
  61. package/src/programmers/TypedFormDataBodyProgrammer.ts +118 -118
  62. package/src/programmers/TypedHeadersProgrammer.ts +63 -63
  63. package/src/programmers/TypedParamProgrammer.ts +33 -33
  64. package/src/programmers/TypedQueryBodyProgrammer.ts +112 -112
  65. package/src/programmers/TypedQueryProgrammer.ts +114 -114
  66. package/src/programmers/TypedQueryRouteProgrammer.ts +105 -105
  67. package/src/programmers/TypedRouteProgrammer.ts +94 -94
  68. package/src/programmers/http/HttpAssertQuerifyProgrammer.ts +72 -72
  69. package/src/programmers/http/HttpIsQuerifyProgrammer.ts +75 -75
  70. package/src/programmers/http/HttpQuerifyProgrammer.ts +108 -108
  71. package/src/programmers/http/HttpValidateQuerifyProgrammer.ts +76 -76
  72. package/src/programmers/internal/CoreMetadataUtil.ts +21 -21
  73. package/src/transform.ts +35 -35
  74. package/src/transformers/FileTransformer.ts +110 -110
  75. package/src/transformers/MethodTransformer.ts +103 -103
  76. package/src/transformers/NodeTransformer.ts +23 -23
  77. package/src/transformers/ParameterDecoratorTransformer.ts +143 -143
  78. package/src/transformers/ParameterTransformer.ts +57 -57
  79. package/src/transformers/TypedRouteTransformer.ts +85 -85
  80. package/src/transformers/WebSocketRouteTransformer.ts +120 -120
  81. package/src/typings/Creator.ts +3 -3
  82. package/src/typings/get-function-location.d.ts +7 -7
  83. package/src/utils/ArrayUtil.ts +7 -7
  84. package/src/utils/ExceptionManager.ts +112 -112
  85. package/src/utils/Singleton.ts +20 -20
  86. package/src/utils/SourceFinder.ts +57 -57
  87. package/src/utils/VersioningStrategy.ts +27 -27
@@ -1,45 +1,45 @@
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
- /**
9
- * @internal
10
- */
11
- export function route_error(
12
- request: express.Request | FastifyRequest,
13
- error: any,
14
- ) {
15
- error = (() => {
16
- // HTTP-ERROR
17
- if (error instanceof HttpException) return error;
18
-
19
- // CUSTOM-REGISTERED ERROR
20
- for (const [creator, closure] of ExceptionManager.tuples)
21
- if (error instanceof creator) return closure(error);
22
-
23
- // MAYBE INTERNAL ERROR
24
- return error;
25
- })();
26
-
27
- try {
28
- error.method = request.method;
29
- error.path =
30
- (request as express.Request).path ??
31
- (request as FastifyRequest).routeOptions?.url ??
32
- (request as any).routerPath;
33
- } catch {}
34
-
35
- setTimeout(() => {
36
- for (const listener of ExceptionManager.listeners) {
37
- try {
38
- const res: any | Promise<any> = listener(error);
39
- if (typeof res === "object" && typeof res.catch === "function")
40
- res.catch(() => {});
41
- } catch {}
42
- }
43
- }, 0);
44
- return throwError(() => error);
45
- }
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
+ /**
9
+ * @internal
10
+ */
11
+ export function route_error(
12
+ request: express.Request | FastifyRequest,
13
+ error: any,
14
+ ) {
15
+ error = (() => {
16
+ // HTTP-ERROR
17
+ if (error instanceof HttpException) return error;
18
+
19
+ // CUSTOM-REGISTERED ERROR
20
+ for (const [creator, closure] of ExceptionManager.tuples)
21
+ if (error instanceof creator) return closure(error);
22
+
23
+ // MAYBE INTERNAL ERROR
24
+ return error;
25
+ })();
26
+
27
+ try {
28
+ error.method = request.method;
29
+ error.path =
30
+ (request as express.Request).path ??
31
+ (request as FastifyRequest).routeOptions?.url ??
32
+ (request as any).routerPath;
33
+ } catch {}
34
+
35
+ setTimeout(() => {
36
+ for (const listener of ExceptionManager.listeners) {
37
+ try {
38
+ const res: any | Promise<any> = listener(error);
39
+ if (typeof res === "object" && typeof res.catch === "function")
40
+ res.catch(() => {});
41
+ } catch {}
42
+ }
43
+ }, 0);
44
+ return throwError(() => error);
45
+ }
@@ -1,74 +1,74 @@
1
- import { BadRequestException } from "@nestjs/common";
2
- import typia, { IValidation, TypeGuardError } from "typia";
3
-
4
- import { IRequestBodyValidator } from "../../options/IRequestBodyValidator";
5
- import { NoTransformConfigurationError } from "../NoTransformConfigurationError";
6
-
7
- /**
8
- * @internal
9
- */
10
- export const validate_request_body =
11
- (method: string) =>
12
- <T>(validator?: IRequestBodyValidator<T>): ((input: T) => Error | null) => {
13
- if (!validator) {
14
- NoTransformConfigurationError(method);
15
- return () => null;
16
- } else if (validator.type === "assert") return assert(validator.assert);
17
- else if (validator.type === "is") return is(validator.is);
18
- else if (validator.type === "validate") return validate(validator.validate);
19
- return () =>
20
- new Error(`Error on nestia.core.${method}(): invalid typed validator.`);
21
- };
22
-
23
- /**
24
- * @internal
25
- */
26
- const assert =
27
- <T>(closure: (data: T) => T) =>
28
- (input: T) => {
29
- try {
30
- closure(input);
31
- return null;
32
- } catch (exp) {
33
- if (typia.is<TypeGuardError>(exp)) {
34
- return new BadRequestException({
35
- path: exp.path,
36
- reason: exp.message,
37
- expected: exp.expected,
38
- value: exp.value,
39
- message: MESSAGE,
40
- });
41
- }
42
- throw exp;
43
- }
44
- };
45
-
46
- /**
47
- * @internal
48
- */
49
- const is =
50
- <T>(closure: (data: T) => boolean) =>
51
- (input: T) => {
52
- const success: boolean = closure(input);
53
- return success ? null : new BadRequestException(MESSAGE);
54
- };
55
-
56
- /**
57
- * @internal
58
- */
59
- const validate =
60
- <T>(closure: (data: T) => IValidation<T>) =>
61
- (input: T) => {
62
- const result: IValidation<T> = closure(input);
63
- return result.success
64
- ? null
65
- : new BadRequestException({
66
- errors: result.errors,
67
- message: MESSAGE,
68
- });
69
- };
70
-
71
- /**
72
- * @internal
73
- */
74
- const MESSAGE = "Request body data is not following the promised type.";
1
+ import { BadRequestException } from "@nestjs/common";
2
+ import typia, { IValidation, TypeGuardError } from "typia";
3
+
4
+ import { IRequestBodyValidator } from "../../options/IRequestBodyValidator";
5
+ import { NoTransformConfigurationError } from "../NoTransformConfigurationError";
6
+
7
+ /**
8
+ * @internal
9
+ */
10
+ export const validate_request_body =
11
+ (method: string) =>
12
+ <T>(validator?: IRequestBodyValidator<T>): ((input: T) => Error | null) => {
13
+ if (!validator) {
14
+ NoTransformConfigurationError(method);
15
+ return () => null;
16
+ } else if (validator.type === "assert") return assert(validator.assert);
17
+ else if (validator.type === "is") return is(validator.is);
18
+ else if (validator.type === "validate") return validate(validator.validate);
19
+ return () =>
20
+ new Error(`Error on nestia.core.${method}(): invalid typed validator.`);
21
+ };
22
+
23
+ /**
24
+ * @internal
25
+ */
26
+ const assert =
27
+ <T>(closure: (data: T) => T) =>
28
+ (input: T) => {
29
+ try {
30
+ closure(input);
31
+ return null;
32
+ } catch (exp) {
33
+ if (typia.is<TypeGuardError>(exp)) {
34
+ return new BadRequestException({
35
+ path: exp.path,
36
+ reason: exp.message,
37
+ expected: exp.expected,
38
+ value: exp.value,
39
+ message: MESSAGE,
40
+ });
41
+ }
42
+ throw exp;
43
+ }
44
+ };
45
+
46
+ /**
47
+ * @internal
48
+ */
49
+ const is =
50
+ <T>(closure: (data: T) => boolean) =>
51
+ (input: T) => {
52
+ const success: boolean = closure(input);
53
+ return success ? null : new BadRequestException(MESSAGE);
54
+ };
55
+
56
+ /**
57
+ * @internal
58
+ */
59
+ const validate =
60
+ <T>(closure: (data: T) => IValidation<T>) =>
61
+ (input: T) => {
62
+ const result: IValidation<T> = closure(input);
63
+ return result.success
64
+ ? null
65
+ : new BadRequestException({
66
+ errors: result.errors,
67
+ message: MESSAGE,
68
+ });
69
+ };
70
+
71
+ /**
72
+ * @internal
73
+ */
74
+ const MESSAGE = "Request body data is not following the promised type.";
@@ -1,77 +1,77 @@
1
- import { BadRequestException } from "@nestjs/common";
2
- import typia, { IValidation, TypeGuardError } from "typia";
3
-
4
- import { IRequestFormDataProps } from "../../options/IRequestFormDataProps";
5
- import { NoTransformConfigurationError } from "../NoTransformConfigurationError";
6
-
7
- /**
8
- * @internal
9
- */
10
- export const validate_request_form_data = <T>(
11
- props?: IRequestFormDataProps<T>,
12
- ): ((value: FormData) => T | Error) => {
13
- if (!props) {
14
- NoTransformConfigurationError("TypedFormData.Body");
15
- return (input: FormData) => Object.entries(input) as T;
16
- } else if (props.validator.type === "assert")
17
- return assert(props.validator.assert);
18
- else if (props.validator.type === "is") return is(props.validator.is);
19
- else if (props.validator.type === "validate")
20
- return validate(props.validator.validate);
21
- return () =>
22
- new Error(
23
- `Error on nestia.core.TypedFormData.Body(): invalid typed validator.`,
24
- );
25
- };
26
-
27
- /**
28
- * @internal
29
- */
30
- const assert =
31
- <T>(closure: (input: FormData) => T) =>
32
- (input: FormData): T | BadRequestException => {
33
- try {
34
- return closure(input);
35
- } catch (exp) {
36
- if (typia.is<TypeGuardError>(exp)) {
37
- return new BadRequestException({
38
- path: exp.path,
39
- reason: exp.message,
40
- expected: exp.expected,
41
- value: exp.value,
42
- message: MESSAGE,
43
- });
44
- }
45
- throw exp;
46
- }
47
- };
48
-
49
- /**
50
- * @internal
51
- */
52
- const is =
53
- <T>(closure: (input: FormData) => T | null) =>
54
- (input: FormData): T | BadRequestException => {
55
- const result: T | null = closure(input);
56
- return result !== null ? result : new BadRequestException(MESSAGE);
57
- };
58
-
59
- /**
60
- * @internal
61
- */
62
- const validate =
63
- <T>(closure: (input: FormData) => IValidation<T>) =>
64
- (input: FormData): T | BadRequestException => {
65
- const result: IValidation<T> = closure(input);
66
- return result.success
67
- ? result.data
68
- : new BadRequestException({
69
- errors: result.errors,
70
- message: MESSAGE,
71
- });
72
- };
73
-
74
- /**
75
- * @internal
76
- */
77
- const MESSAGE = "Request multipart data is not following the promised type.";
1
+ import { BadRequestException } from "@nestjs/common";
2
+ import typia, { IValidation, TypeGuardError } from "typia";
3
+
4
+ import { IRequestFormDataProps } from "../../options/IRequestFormDataProps";
5
+ import { NoTransformConfigurationError } from "../NoTransformConfigurationError";
6
+
7
+ /**
8
+ * @internal
9
+ */
10
+ export const validate_request_form_data = <T>(
11
+ props?: IRequestFormDataProps<T>,
12
+ ): ((value: FormData) => T | Error) => {
13
+ if (!props) {
14
+ NoTransformConfigurationError("TypedFormData.Body");
15
+ return (input: FormData) => Object.entries(input) as T;
16
+ } else if (props.validator.type === "assert")
17
+ return assert(props.validator.assert);
18
+ else if (props.validator.type === "is") return is(props.validator.is);
19
+ else if (props.validator.type === "validate")
20
+ return validate(props.validator.validate);
21
+ return () =>
22
+ new Error(
23
+ `Error on nestia.core.TypedFormData.Body(): invalid typed validator.`,
24
+ );
25
+ };
26
+
27
+ /**
28
+ * @internal
29
+ */
30
+ const assert =
31
+ <T>(closure: (input: FormData) => T) =>
32
+ (input: FormData): T | BadRequestException => {
33
+ try {
34
+ return closure(input);
35
+ } catch (exp) {
36
+ if (typia.is<TypeGuardError>(exp)) {
37
+ return new BadRequestException({
38
+ path: exp.path,
39
+ reason: exp.message,
40
+ expected: exp.expected,
41
+ value: exp.value,
42
+ message: MESSAGE,
43
+ });
44
+ }
45
+ throw exp;
46
+ }
47
+ };
48
+
49
+ /**
50
+ * @internal
51
+ */
52
+ const is =
53
+ <T>(closure: (input: FormData) => T | null) =>
54
+ (input: FormData): T | BadRequestException => {
55
+ const result: T | null = closure(input);
56
+ return result !== null ? result : new BadRequestException(MESSAGE);
57
+ };
58
+
59
+ /**
60
+ * @internal
61
+ */
62
+ const validate =
63
+ <T>(closure: (input: FormData) => IValidation<T>) =>
64
+ (input: FormData): T | BadRequestException => {
65
+ const result: IValidation<T> = closure(input);
66
+ return result.success
67
+ ? result.data
68
+ : new BadRequestException({
69
+ errors: result.errors,
70
+ message: MESSAGE,
71
+ });
72
+ };
73
+
74
+ /**
75
+ * @internal
76
+ */
77
+ const MESSAGE = "Request multipart data is not following the promised type.";
@@ -1,86 +1,86 @@
1
- import { BadRequestException } from "@nestjs/common";
2
- import typia, { IValidation, TypeGuardError } from "typia";
3
-
4
- import { IRequestHeadersValidator } from "../../options/IRequestHeadersValidator";
5
- import { NoTransformConfigurationError } from "../NoTransformConfigurationError";
6
-
7
- /**
8
- * @internal
9
- */
10
- export const validate_request_headers = <T>(
11
- validator?: IRequestHeadersValidator<T>,
12
- ): ((input: Record<string, string | string[] | undefined>) => T | Error) => {
13
- if (!validator) {
14
- NoTransformConfigurationError("TypedHeaders");
15
- return (input: Record<string, string | string[] | undefined>) =>
16
- Object.entries(input) as T;
17
- } else if (validator.type === "assert") return assert(validator.assert);
18
- else if (validator.type === "is") return is(validator.is);
19
- else if (validator.type === "validate") return validate(validator.validate);
20
- return () =>
21
- new Error(`Error on nestia.core.TypedHeaders(): invalid typed validator.`);
22
- };
23
-
24
- /**
25
- * @internal
26
- */
27
- const assert =
28
- <T>(closure: (input: Record<string, string | string[] | undefined>) => T) =>
29
- (
30
- input: Record<string, string | string[] | undefined>,
31
- ): T | BadRequestException => {
32
- try {
33
- return closure(input);
34
- } catch (exp) {
35
- if (typia.is<TypeGuardError>(exp)) {
36
- return new BadRequestException({
37
- path: exp.path,
38
- reason: exp.message,
39
- expected: exp.expected,
40
- value: exp.value,
41
- message: MESSAGE,
42
- });
43
- }
44
- throw exp;
45
- }
46
- };
47
-
48
- /**
49
- * @internal
50
- */
51
- const is =
52
- <T>(
53
- closure: (input: Record<string, string | string[] | undefined>) => T | null,
54
- ) =>
55
- (
56
- input: Record<string, string | string[] | undefined>,
57
- ): T | BadRequestException => {
58
- const result: T | null = closure(input);
59
- return result !== null ? result : new BadRequestException(MESSAGE);
60
- };
61
-
62
- /**
63
- * @internal
64
- */
65
- const validate =
66
- <T>(
67
- closure: (
68
- input: Record<string, string | string[] | undefined>,
69
- ) => IValidation<T>,
70
- ) =>
71
- (
72
- input: Record<string, string | string[] | undefined>,
73
- ): T | BadRequestException => {
74
- const result: IValidation<T> = closure(input);
75
- return result.success
76
- ? result.data
77
- : new BadRequestException({
78
- errors: result.errors,
79
- message: MESSAGE,
80
- });
81
- };
82
-
83
- /**
84
- * @internal
85
- */
86
- const MESSAGE = "Request headers data is not following the promised type.";
1
+ import { BadRequestException } from "@nestjs/common";
2
+ import typia, { IValidation, TypeGuardError } from "typia";
3
+
4
+ import { IRequestHeadersValidator } from "../../options/IRequestHeadersValidator";
5
+ import { NoTransformConfigurationError } from "../NoTransformConfigurationError";
6
+
7
+ /**
8
+ * @internal
9
+ */
10
+ export const validate_request_headers = <T>(
11
+ validator?: IRequestHeadersValidator<T>,
12
+ ): ((input: Record<string, string | string[] | undefined>) => T | Error) => {
13
+ if (!validator) {
14
+ NoTransformConfigurationError("TypedHeaders");
15
+ return (input: Record<string, string | string[] | undefined>) =>
16
+ Object.entries(input) as T;
17
+ } else if (validator.type === "assert") return assert(validator.assert);
18
+ else if (validator.type === "is") return is(validator.is);
19
+ else if (validator.type === "validate") return validate(validator.validate);
20
+ return () =>
21
+ new Error(`Error on nestia.core.TypedHeaders(): invalid typed validator.`);
22
+ };
23
+
24
+ /**
25
+ * @internal
26
+ */
27
+ const assert =
28
+ <T>(closure: (input: Record<string, string | string[] | undefined>) => T) =>
29
+ (
30
+ input: Record<string, string | string[] | undefined>,
31
+ ): T | BadRequestException => {
32
+ try {
33
+ return closure(input);
34
+ } catch (exp) {
35
+ if (typia.is<TypeGuardError>(exp)) {
36
+ return new BadRequestException({
37
+ path: exp.path,
38
+ reason: exp.message,
39
+ expected: exp.expected,
40
+ value: exp.value,
41
+ message: MESSAGE,
42
+ });
43
+ }
44
+ throw exp;
45
+ }
46
+ };
47
+
48
+ /**
49
+ * @internal
50
+ */
51
+ const is =
52
+ <T>(
53
+ closure: (input: Record<string, string | string[] | undefined>) => T | null,
54
+ ) =>
55
+ (
56
+ input: Record<string, string | string[] | undefined>,
57
+ ): T | BadRequestException => {
58
+ const result: T | null = closure(input);
59
+ return result !== null ? result : new BadRequestException(MESSAGE);
60
+ };
61
+
62
+ /**
63
+ * @internal
64
+ */
65
+ const validate =
66
+ <T>(
67
+ closure: (
68
+ input: Record<string, string | string[] | undefined>,
69
+ ) => IValidation<T>,
70
+ ) =>
71
+ (
72
+ input: Record<string, string | string[] | undefined>,
73
+ ): T | BadRequestException => {
74
+ const result: IValidation<T> = closure(input);
75
+ return result.success
76
+ ? result.data
77
+ : new BadRequestException({
78
+ errors: result.errors,
79
+ message: MESSAGE,
80
+ });
81
+ };
82
+
83
+ /**
84
+ * @internal
85
+ */
86
+ const MESSAGE = "Request headers data is not following the promised type.";