@nestia/core 7.0.0-dev.20250607 → 7.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +92 -92
  3. package/package.json +3 -3
  4. package/src/adaptors/WebSocketAdaptor.ts +429 -429
  5. package/src/decorators/DynamicModule.ts +43 -43
  6. package/src/decorators/EncryptedBody.ts +101 -101
  7. package/src/decorators/EncryptedController.ts +38 -38
  8. package/src/decorators/EncryptedModule.ts +100 -100
  9. package/src/decorators/EncryptedRoute.ts +219 -219
  10. package/src/decorators/HumanRoute.ts +22 -22
  11. package/src/decorators/NoTransformConfigurationError.ts +32 -32
  12. package/src/decorators/PlainBody.ts +79 -79
  13. package/src/decorators/SwaggerCustomizer.ts +115 -115
  14. package/src/decorators/SwaggerExample.ts +100 -100
  15. package/src/decorators/TypedBody.ts +59 -59
  16. package/src/decorators/TypedException.ts +166 -166
  17. package/src/decorators/TypedFormData.ts +195 -195
  18. package/src/decorators/TypedHeaders.ts +64 -64
  19. package/src/decorators/TypedParam.ts +77 -77
  20. package/src/decorators/TypedQuery.ts +245 -245
  21. package/src/decorators/TypedRoute.ts +214 -214
  22. package/src/decorators/WebSocketRoute.ts +242 -242
  23. package/src/decorators/internal/EncryptedConstant.ts +4 -4
  24. package/src/decorators/internal/IWebSocketRouteReflect.ts +23 -23
  25. package/src/decorators/internal/NoTransformConfigureError.ts +2 -2
  26. package/src/decorators/internal/get_path_and_querify.ts +108 -108
  27. package/src/decorators/internal/get_path_and_stringify.ts +122 -122
  28. package/src/decorators/internal/get_text_body.ts +20 -20
  29. package/src/decorators/internal/headers_to_object.ts +13 -13
  30. package/src/decorators/internal/is_request_body_undefined.ts +14 -14
  31. package/src/decorators/internal/load_controller.ts +49 -49
  32. package/src/decorators/internal/route_error.ts +45 -45
  33. package/src/decorators/internal/validate_request_body.ts +74 -74
  34. package/src/decorators/internal/validate_request_form_data.ts +77 -77
  35. package/src/decorators/internal/validate_request_headers.ts +86 -86
  36. package/src/decorators/internal/validate_request_query.ts +74 -74
  37. package/src/index.ts +5 -5
  38. package/src/module.ts +22 -22
  39. package/src/options/INestiaTransformOptions.ts +38 -38
  40. package/src/options/INestiaTransformProject.ts +8 -8
  41. package/src/options/IRequestBodyValidator.ts +20 -20
  42. package/src/options/IRequestFormDataProps.ts +27 -27
  43. package/src/options/IRequestHeadersValidator.ts +22 -22
  44. package/src/options/IRequestQueryValidator.ts +20 -20
  45. package/src/options/IResponseBodyQuerifier.ts +25 -25
  46. package/src/options/IResponseBodyStringifier.ts +30 -30
  47. package/src/programmers/PlainBodyProgrammer.ts +70 -70
  48. package/src/programmers/TypedBodyProgrammer.ts +142 -142
  49. package/src/programmers/TypedFormDataBodyProgrammer.ts +118 -118
  50. package/src/programmers/TypedHeadersProgrammer.ts +63 -63
  51. package/src/programmers/TypedParamProgrammer.ts +33 -33
  52. package/src/programmers/TypedQueryBodyProgrammer.ts +112 -112
  53. package/src/programmers/TypedQueryProgrammer.ts +114 -114
  54. package/src/programmers/TypedQueryRouteProgrammer.ts +105 -105
  55. package/src/programmers/TypedRouteProgrammer.ts +94 -94
  56. package/src/programmers/http/HttpAssertQuerifyProgrammer.ts +72 -72
  57. package/src/programmers/http/HttpIsQuerifyProgrammer.ts +75 -75
  58. package/src/programmers/http/HttpQuerifyProgrammer.ts +108 -108
  59. package/src/programmers/http/HttpValidateQuerifyProgrammer.ts +76 -76
  60. package/src/programmers/internal/CoreMetadataUtil.ts +21 -21
  61. package/src/transform.ts +35 -35
  62. package/src/transformers/FileTransformer.ts +110 -110
  63. package/src/transformers/MethodTransformer.ts +103 -103
  64. package/src/transformers/NodeTransformer.ts +23 -23
  65. package/src/transformers/ParameterDecoratorTransformer.ts +143 -143
  66. package/src/transformers/ParameterTransformer.ts +57 -57
  67. package/src/transformers/TypedRouteTransformer.ts +85 -85
  68. package/src/transformers/WebSocketRouteTransformer.ts +120 -120
  69. package/src/typings/Creator.ts +3 -3
  70. package/src/typings/get-function-location.d.ts +7 -7
  71. package/src/utils/ArrayUtil.ts +7 -7
  72. package/src/utils/ExceptionManager.ts +112 -112
  73. package/src/utils/Singleton.ts +20 -20
  74. package/src/utils/SourceFinder.ts +57 -57
  75. 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.";