@nestia/core 2.4.2 → 2.4.3

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 (112) hide show
  1. package/lib/decorators/DynamicModule.js.map +1 -1
  2. package/lib/decorators/EncryptedBody.js.map +1 -1
  3. package/lib/decorators/EncryptedController.js.map +1 -1
  4. package/lib/decorators/EncryptedModule.js.map +1 -1
  5. package/lib/decorators/EncryptedRoute.js +0 -2
  6. package/lib/decorators/EncryptedRoute.js.map +1 -1
  7. package/lib/decorators/PlainBody.js.map +1 -1
  8. package/lib/decorators/TypedBody.js.map +1 -1
  9. package/lib/decorators/TypedException.js.map +1 -1
  10. package/lib/decorators/TypedHeaders.js.map +1 -1
  11. package/lib/decorators/TypedParam.js.map +1 -1
  12. package/lib/decorators/TypedQuery.js +1 -5
  13. package/lib/decorators/TypedQuery.js.map +1 -1
  14. package/lib/decorators/TypedRoute.js.map +1 -1
  15. package/lib/decorators/internal/NoTransformConfigureError.js.map +1 -1
  16. package/lib/decorators/internal/get_path_and_querify.js.map +1 -1
  17. package/lib/decorators/internal/get_path_and_stringify.js.map +1 -1
  18. package/lib/decorators/internal/get_text_body.js.map +1 -1
  19. package/lib/decorators/internal/headers_to_object.js.map +1 -1
  20. package/lib/decorators/internal/load_controller.js.map +1 -1
  21. package/lib/decorators/internal/route_error.js.map +1 -1
  22. package/lib/decorators/internal/validate_request_body.js.map +1 -1
  23. package/lib/decorators/internal/validate_request_headers.js.map +1 -1
  24. package/lib/decorators/internal/validate_request_query.js.map +1 -1
  25. package/lib/programmers/PlainBodyProgrammer.js.map +1 -1
  26. package/lib/programmers/TypedBodyProgrammer.js.map +1 -1
  27. package/lib/programmers/TypedExceptionProgrammer.js.map +1 -1
  28. package/lib/programmers/TypedHeadersProgrammer.js.map +1 -1
  29. package/lib/programmers/TypedParamProgrammer.js.map +1 -1
  30. package/lib/programmers/TypedQueryBodyProgrammer.js.map +1 -1
  31. package/lib/programmers/TypedQueryProgrammer.js.map +1 -1
  32. package/lib/programmers/TypedQueryRouteProgrammer.js.map +1 -1
  33. package/lib/programmers/TypedRouteProgrammer.js.map +1 -1
  34. package/lib/programmers/http/HttpAssertQuerifyProgrammer.js.map +1 -1
  35. package/lib/programmers/http/HttpIsQuerifyProgrammer.js.map +1 -1
  36. package/lib/programmers/http/HttpQuerifyProgrammer.js.map +1 -1
  37. package/lib/programmers/http/HttpValidateQuerifyProgrammer.js.map +1 -1
  38. package/lib/programmers/internal/CoreMetadataUtil.js.map +1 -1
  39. package/lib/transform.js.map +1 -1
  40. package/lib/transformers/FileTransformer.js.map +1 -1
  41. package/lib/transformers/MethodTransformer.js +1 -2
  42. package/lib/transformers/MethodTransformer.js.map +1 -1
  43. package/lib/transformers/NodeTransformer.js.map +1 -1
  44. package/lib/transformers/ParameterDecoratorTransformer.js +1 -3
  45. package/lib/transformers/ParameterDecoratorTransformer.js.map +1 -1
  46. package/lib/transformers/ParameterTransformer.js.map +1 -1
  47. package/lib/transformers/TypedExceptionTransformer.js.map +1 -1
  48. package/lib/transformers/TypedRouteTransformer.js +1 -2
  49. package/lib/transformers/TypedRouteTransformer.js.map +1 -1
  50. package/lib/utils/ExceptionManager.js.map +1 -1
  51. package/lib/utils/Singleton.js.map +1 -1
  52. package/lib/utils/SourceFinder.js +1 -3
  53. package/lib/utils/SourceFinder.js.map +1 -1
  54. package/package.json +3 -6
  55. package/src/decorators/DynamicModule.ts +39 -39
  56. package/src/decorators/EncryptedBody.ts +49 -57
  57. package/src/decorators/EncryptedController.ts +38 -38
  58. package/src/decorators/EncryptedModule.ts +79 -79
  59. package/src/decorators/EncryptedRoute.ts +126 -135
  60. package/src/decorators/PlainBody.ts +72 -75
  61. package/src/decorators/TypedBody.ts +59 -60
  62. package/src/decorators/TypedException.ts +89 -89
  63. package/src/decorators/TypedHeaders.ts +69 -70
  64. package/src/decorators/TypedParam.ts +65 -66
  65. package/src/decorators/TypedQuery.ts +246 -253
  66. package/src/decorators/TypedRoute.ts +144 -147
  67. package/src/decorators/internal/EncryptedConstant.ts +4 -4
  68. package/src/decorators/internal/NoTransformConfigureError.ts +8 -8
  69. package/src/decorators/internal/get_path_and_querify.ts +103 -104
  70. package/src/decorators/internal/get_path_and_stringify.ts +91 -94
  71. package/src/decorators/internal/get_text_body.ts +20 -20
  72. package/src/decorators/internal/headers_to_object.ts +13 -13
  73. package/src/decorators/internal/load_controller.ts +51 -51
  74. package/src/decorators/internal/route_error.ts +45 -45
  75. package/src/decorators/internal/validate_request_body.ts +57 -61
  76. package/src/decorators/internal/validate_request_headers.ts +68 -73
  77. package/src/decorators/internal/validate_request_query.ts +56 -59
  78. package/src/index.ts +5 -5
  79. package/src/module.ts +14 -14
  80. package/src/options/INestiaTransformOptions.ts +17 -17
  81. package/src/options/INestiaTransformProject.ts +7 -7
  82. package/src/options/IRequestBodyValidator.ts +20 -20
  83. package/src/options/IRequestHeadersValidator.ts +22 -22
  84. package/src/options/IRequestQueryValidator.ts +20 -20
  85. package/src/options/IResponseBodyQuerifier.ts +25 -25
  86. package/src/options/IResponseBodyStringifier.ts +25 -25
  87. package/src/programmers/PlainBodyProgrammer.ts +52 -56
  88. package/src/programmers/TypedBodyProgrammer.ts +108 -112
  89. package/src/programmers/TypedExceptionProgrammer.ts +72 -76
  90. package/src/programmers/TypedHeadersProgrammer.ts +56 -59
  91. package/src/programmers/TypedParamProgrammer.ts +24 -25
  92. package/src/programmers/TypedQueryBodyProgrammer.ts +56 -57
  93. package/src/programmers/TypedQueryProgrammer.ts +56 -57
  94. package/src/programmers/TypedQueryRouteProgrammer.ts +51 -55
  95. package/src/programmers/TypedRouteProgrammer.ts +51 -55
  96. package/src/programmers/http/HttpAssertQuerifyProgrammer.ts +58 -59
  97. package/src/programmers/http/HttpIsQuerifyProgrammer.ts +62 -63
  98. package/src/programmers/http/HttpQuerifyProgrammer.ts +96 -105
  99. package/src/programmers/http/HttpValidateQuerifyProgrammer.ts +63 -64
  100. package/src/programmers/internal/CoreMetadataUtil.ts +21 -21
  101. package/src/transform.ts +35 -36
  102. package/src/transformers/FileTransformer.ts +66 -67
  103. package/src/transformers/MethodTransformer.ts +94 -97
  104. package/src/transformers/NodeTransformer.ts +16 -16
  105. package/src/transformers/ParameterDecoratorTransformer.ts +121 -126
  106. package/src/transformers/ParameterTransformer.ts +48 -53
  107. package/src/transformers/TypedExceptionTransformer.ts +49 -51
  108. package/src/transformers/TypedRouteTransformer.ts +95 -96
  109. package/src/typings/Creator.ts +3 -3
  110. package/src/utils/ExceptionManager.ts +112 -112
  111. package/src/utils/Singleton.ts +20 -20
  112. package/src/utils/SourceFinder.ts +57 -60
@@ -1,89 +1,89 @@
1
- import "reflect-metadata";
2
-
3
- /**
4
- * > You must configure the generic argument `T`
5
- *
6
- * Exception decorator.
7
- *
8
- * `TypedException` is a decorator function describing HTTP exception and its type
9
- * which could be occured in the method.
10
- *
11
- * For reference, this decorator function does not affect to the method's behavior,
12
- * but only affects to the swagger documents generation. Also, it does not affect to
13
- * the SDK library generation yet, but will be used in the future.
14
- *
15
- * @param status Status number or pattern like "2XX", "3XX", "4XX", "5XX"
16
- * @param description Description about the exception
17
- * @returns Method decorator
18
- *
19
- * @author Jeongho Nam - https://github.com/samchon
20
- */
21
- export function TypedException(
22
- status: number | "2XX" | "3XX" | "4XX" | "5XX",
23
- description?: string | undefined,
24
- ): never;
25
-
26
- /**
27
- * Exception decorator.
28
- *
29
- * `TypedException` is a decorator function describing HTTP exception and its type
30
- * which could be occured in the method.
31
- *
32
- * For reference, this decorator function does not affect to the method's behavior,
33
- * but only affects to the swagger documents generation. Also, it does not affect to
34
- * the SDK library generation yet, but will be used in the future.
35
- *
36
- * @template T Type of the exception
37
- * @param status Status number or pattern like "2XX", "3XX", "4XX", "5XX"
38
- * @param description Description about the exception
39
- * @returns Method decorator
40
- *
41
- * @author Jeongho Nam - https://github.com/samchon
42
- */
43
- export function TypedException<T>(
44
- status: number | "2XX" | "3XX" | "4XX" | "5XX",
45
- description?: string | undefined,
46
- ): MethodDecorator;
47
-
48
- /**
49
- * @internal
50
- */
51
- export function TypedException<T>(
52
- status: number | "2XX" | "3XX" | "4XX" | "5XX",
53
- description?: string | undefined,
54
- type?: string | undefined,
55
- ): MethodDecorator {
56
- return function TypedException(
57
- target: Object | T,
58
- propertyKey: string | symbol,
59
- descriptor: TypedPropertyDescriptor<any>,
60
- ) {
61
- const array: IProps[] = (() => {
62
- const oldbie: IProps[] | undefined = Reflect.getMetadata(
63
- `nestia/TypedException`,
64
- (target as any)[propertyKey],
65
- );
66
- if (oldbie !== undefined) return oldbie;
67
-
68
- const newbie: IProps[] = [];
69
- Reflect.defineMetadata(
70
- `nestia/TypedException`,
71
- newbie,
72
- (target as any)[propertyKey],
73
- );
74
- return newbie;
75
- })();
76
- array.push({
77
- status,
78
- description,
79
- type: type!,
80
- });
81
- return descriptor;
82
- };
83
- }
84
-
85
- interface IProps {
86
- status: number | "2XX" | "3XX" | "4XX" | "5XX";
87
- description?: string | undefined;
88
- type: string;
89
- }
1
+ import "reflect-metadata";
2
+
3
+ /**
4
+ * > You must configure the generic argument `T`
5
+ *
6
+ * Exception decorator.
7
+ *
8
+ * `TypedException` is a decorator function describing HTTP exception and its type
9
+ * which could be occured in the method.
10
+ *
11
+ * For reference, this decorator function does not affect to the method's behavior,
12
+ * but only affects to the swagger documents generation. Also, it does not affect to
13
+ * the SDK library generation yet, but will be used in the future.
14
+ *
15
+ * @param status Status number or pattern like "2XX", "3XX", "4XX", "5XX"
16
+ * @param description Description about the exception
17
+ * @returns Method decorator
18
+ *
19
+ * @author Jeongho Nam - https://github.com/samchon
20
+ */
21
+ export function TypedException(
22
+ status: number | "2XX" | "3XX" | "4XX" | "5XX",
23
+ description?: string | undefined,
24
+ ): never;
25
+
26
+ /**
27
+ * Exception decorator.
28
+ *
29
+ * `TypedException` is a decorator function describing HTTP exception and its type
30
+ * which could be occured in the method.
31
+ *
32
+ * For reference, this decorator function does not affect to the method's behavior,
33
+ * but only affects to the swagger documents generation. Also, it does not affect to
34
+ * the SDK library generation yet, but will be used in the future.
35
+ *
36
+ * @template T Type of the exception
37
+ * @param status Status number or pattern like "2XX", "3XX", "4XX", "5XX"
38
+ * @param description Description about the exception
39
+ * @returns Method decorator
40
+ *
41
+ * @author Jeongho Nam - https://github.com/samchon
42
+ */
43
+ export function TypedException<T>(
44
+ status: number | "2XX" | "3XX" | "4XX" | "5XX",
45
+ description?: string | undefined,
46
+ ): MethodDecorator;
47
+
48
+ /**
49
+ * @internal
50
+ */
51
+ export function TypedException<T>(
52
+ status: number | "2XX" | "3XX" | "4XX" | "5XX",
53
+ description?: string | undefined,
54
+ type?: string | undefined,
55
+ ): MethodDecorator {
56
+ return function TypedException(
57
+ target: Object | T,
58
+ propertyKey: string | symbol,
59
+ descriptor: TypedPropertyDescriptor<any>,
60
+ ) {
61
+ const array: IProps[] = (() => {
62
+ const oldbie: IProps[] | undefined = Reflect.getMetadata(
63
+ `nestia/TypedException`,
64
+ (target as any)[propertyKey],
65
+ );
66
+ if (oldbie !== undefined) return oldbie;
67
+
68
+ const newbie: IProps[] = [];
69
+ Reflect.defineMetadata(
70
+ `nestia/TypedException`,
71
+ newbie,
72
+ (target as any)[propertyKey],
73
+ );
74
+ return newbie;
75
+ })();
76
+ array.push({
77
+ status,
78
+ description,
79
+ type: type!,
80
+ });
81
+ return descriptor;
82
+ };
83
+ }
84
+
85
+ interface IProps {
86
+ status: number | "2XX" | "3XX" | "4XX" | "5XX";
87
+ description?: string | undefined;
88
+ type: string;
89
+ }
@@ -1,70 +1,69 @@
1
- import { ExecutionContext, createParamDecorator } from "@nestjs/common";
2
- import type express from "express";
3
- import type { FastifyRequest } from "fastify";
4
-
5
- import typia from "typia";
6
-
7
- import { IRequestHeadersValidator } from "../options/IRequestHeadersValidator";
8
- import { validate_request_headers } from "./internal/validate_request_headers";
9
-
10
- /**
11
- * Type safe HTTP headers decorator.
12
- *
13
- * `TypedHeaders` is a decorator function that can parse HTTP headers. It is almost
14
- * same with {@link nest.Headers}, but it can automatically cast property type following
15
- * its DTO definition. Also, `TypedHeaders` performs type validation.
16
- *
17
- * For reference, target type `T` must follow such restrictions. Also, if actual HTTP
18
- * header values are different with their promised type `T`, `BadRequestException`
19
- * error (status code: 400) would be thrown.
20
- *
21
- * 1. Type `T` must be an object type
22
- * 2. Do not allow dynamic property
23
- * 3. Property key must be lower case
24
- * 4. Property value cannot be `null`, but `undefined` is possible
25
- * 5. Only `boolean`, `bigint`, `number`, `string` or their array types are allowed
26
- * 6. By the way, union type never be not allowed
27
- * 7. Property `set-cookie` must be array type
28
- * 8. Those properties cannot be array type
29
- * - age
30
- * - authorization
31
- * - content-length
32
- * - content-type
33
- * - etag
34
- * - expires
35
- * - from
36
- * - host
37
- * - if-modified-since
38
- * - if-unmodified-since
39
- * - last-modified
40
- * - location
41
- * - max-forwards
42
- * - proxy-authorization
43
- * - referer
44
- * - retry-after
45
- * - server
46
- * - user-agent
47
- *
48
- * @returns Parameter decorator
49
- * @author Jeongho Nam - https://github.com/samchon
50
- */
51
- export function TypedHeaders<T extends object>(
52
- validator?: IRequestHeadersValidator<T>,
53
- ): ParameterDecorator {
54
- const checker = validate_request_headers(validator);
55
- return createParamDecorator(function TypedHeaders(
56
- _unknown: any,
57
- context: ExecutionContext,
58
- ) {
59
- const request: express.Request | FastifyRequest = context
60
- .switchToHttp()
61
- .getRequest();
62
-
63
- const output: T | Error = checker(request.headers);
64
- if (output instanceof Error) throw output;
65
- return output;
66
- })();
67
- }
68
- Object.assign(TypedHeaders, typia.http.assertHeaders);
69
- Object.assign(TypedHeaders, typia.http.isHeaders);
70
- Object.assign(TypedHeaders, typia.http.validateHeaders);
1
+ import { ExecutionContext, createParamDecorator } from "@nestjs/common";
2
+ import type express from "express";
3
+ import type { FastifyRequest } from "fastify";
4
+ import typia from "typia";
5
+
6
+ import { IRequestHeadersValidator } from "../options/IRequestHeadersValidator";
7
+ import { validate_request_headers } from "./internal/validate_request_headers";
8
+
9
+ /**
10
+ * Type safe HTTP headers decorator.
11
+ *
12
+ * `TypedHeaders` is a decorator function that can parse HTTP headers. It is almost
13
+ * same with {@link nest.Headers}, but it can automatically cast property type following
14
+ * its DTO definition. Also, `TypedHeaders` performs type validation.
15
+ *
16
+ * For reference, target type `T` must follow such restrictions. Also, if actual HTTP
17
+ * header values are different with their promised type `T`, `BadRequestException`
18
+ * error (status code: 400) would be thrown.
19
+ *
20
+ * 1. Type `T` must be an object type
21
+ * 2. Do not allow dynamic property
22
+ * 3. Property key must be lower case
23
+ * 4. Property value cannot be `null`, but `undefined` is possible
24
+ * 5. Only `boolean`, `bigint`, `number`, `string` or their array types are allowed
25
+ * 6. By the way, union type never be not allowed
26
+ * 7. Property `set-cookie` must be array type
27
+ * 8. Those properties cannot be array type
28
+ * - age
29
+ * - authorization
30
+ * - content-length
31
+ * - content-type
32
+ * - etag
33
+ * - expires
34
+ * - from
35
+ * - host
36
+ * - if-modified-since
37
+ * - if-unmodified-since
38
+ * - last-modified
39
+ * - location
40
+ * - max-forwards
41
+ * - proxy-authorization
42
+ * - referer
43
+ * - retry-after
44
+ * - server
45
+ * - user-agent
46
+ *
47
+ * @returns Parameter decorator
48
+ * @author Jeongho Nam - https://github.com/samchon
49
+ */
50
+ export function TypedHeaders<T extends object>(
51
+ validator?: IRequestHeadersValidator<T>,
52
+ ): ParameterDecorator {
53
+ const checker = validate_request_headers(validator);
54
+ return createParamDecorator(function TypedHeaders(
55
+ _unknown: any,
56
+ context: ExecutionContext,
57
+ ) {
58
+ const request: express.Request | FastifyRequest = context
59
+ .switchToHttp()
60
+ .getRequest();
61
+
62
+ const output: T | Error = checker(request.headers);
63
+ if (output instanceof Error) throw output;
64
+ return output;
65
+ })();
66
+ }
67
+ Object.assign(TypedHeaders, typia.http.assertHeaders);
68
+ Object.assign(TypedHeaders, typia.http.isHeaders);
69
+ Object.assign(TypedHeaders, typia.http.validateHeaders);
@@ -1,66 +1,65 @@
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 typia, { TypeGuardError } from "typia";
10
-
11
- import { NoTransformConfigureError } from "./internal/NoTransformConfigureError";
12
-
13
- /**
14
- * Type safe URL parameter decorator.
15
- *
16
- * `TypedParam` is a decorator function getting specific typed parameter from the
17
- * HTTP request URL. It's almost same with the {@link nest.Param}, but `TypedParam`
18
- * automatically casts parameter value to be following its type, and validates it.
19
- *
20
- * ```typescript
21
- * import { tags } from "typia";
22
- *
23
- * \@TypedRoute.Get("shopping/sales/:id/:no/:paused")
24
- * public async pause
25
- * (
26
- * \@TypedParam("id", "uuid"), id: string & tags.Format<"uuid">,
27
- * \@TypedParam("no") id: number & tags.Type<"uint32">
28
- * \@TypedParam("paused") paused: boolean | null
29
- * ): Promise<void>;
30
- * ```
31
- *
32
- * @param name URL Parameter name
33
- * @returns Parameter decorator
34
- *
35
- * @author Jeongho Nam - https://github.com/samchon
36
- */
37
- export function TypedParam<T extends boolean | bigint | number | string | null>(
38
- name: string,
39
- assert?: (value: string) => T,
40
- ): ParameterDecorator {
41
- if (assert === undefined) throw NoTransformConfigureError("TypedParam");
42
-
43
- return createParamDecorator(function TypedParam(
44
- {}: any,
45
- context: ExecutionContext,
46
- ) {
47
- const request: express.Request | FastifyRequest = context
48
- .switchToHttp()
49
- .getRequest();
50
- const str: string = (request.params as any)[name];
51
- try {
52
- return assert(str);
53
- } catch (exp) {
54
- if (typia.is<TypeGuardError>(exp))
55
- throw new BadRequestException({
56
- path: exp.path,
57
- reason: exp.message,
58
- expected: exp.expected,
59
- value: exp.value,
60
- message: `Invalid URL parameter value on "${name}".`,
61
- });
62
- throw exp;
63
- }
64
- })(name);
65
- }
66
- Object.assign(TypedParam, typia.http.parameter);
1
+ import {
2
+ BadRequestException,
3
+ ExecutionContext,
4
+ createParamDecorator,
5
+ } from "@nestjs/common";
6
+ import type express from "express";
7
+ import type { FastifyRequest } from "fastify";
8
+ import typia, { TypeGuardError } from "typia";
9
+
10
+ import { NoTransformConfigureError } from "./internal/NoTransformConfigureError";
11
+
12
+ /**
13
+ * Type safe URL parameter decorator.
14
+ *
15
+ * `TypedParam` is a decorator function getting specific typed parameter from the
16
+ * HTTP request URL. It's almost same with the {@link nest.Param}, but `TypedParam`
17
+ * automatically casts parameter value to be following its type, and validates it.
18
+ *
19
+ * ```typescript
20
+ * import { tags } from "typia";
21
+ *
22
+ * \@TypedRoute.Get("shopping/sales/:id/:no/:paused")
23
+ * public async pause
24
+ * (
25
+ * \@TypedParam("id", "uuid"), id: string & tags.Format<"uuid">,
26
+ * \@TypedParam("no") id: number & tags.Type<"uint32">
27
+ * \@TypedParam("paused") paused: boolean | null
28
+ * ): Promise<void>;
29
+ * ```
30
+ *
31
+ * @param name URL Parameter name
32
+ * @returns Parameter decorator
33
+ *
34
+ * @author Jeongho Nam - https://github.com/samchon
35
+ */
36
+ export function TypedParam<T extends boolean | bigint | number | string | null>(
37
+ name: string,
38
+ assert?: (value: string) => T,
39
+ ): ParameterDecorator {
40
+ if (assert === undefined) throw NoTransformConfigureError("TypedParam");
41
+
42
+ return createParamDecorator(function TypedParam(
43
+ {}: any,
44
+ context: ExecutionContext,
45
+ ) {
46
+ const request: express.Request | FastifyRequest = context
47
+ .switchToHttp()
48
+ .getRequest();
49
+ const str: string = (request.params as any)[name];
50
+ try {
51
+ return assert(str);
52
+ } catch (exp) {
53
+ if (typia.is<TypeGuardError>(exp))
54
+ throw new BadRequestException({
55
+ path: exp.path,
56
+ reason: exp.message,
57
+ expected: exp.expected,
58
+ value: exp.value,
59
+ message: `Invalid URL parameter value on "${name}".`,
60
+ });
61
+ throw exp;
62
+ }
63
+ })(name);
64
+ }
65
+ Object.assign(TypedParam, typia.http.parameter);