@nestia/core 12.0.0-rc.1 → 12.0.0-rc.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 (80) hide show
  1. package/LICENSE +21 -21
  2. package/MIGRATION.md +138 -169
  3. package/lib/decorators/NoTransformConfigurationError.js +5 -5
  4. package/lib/decorators/NoTransformConfigurationError.js.map +1 -1
  5. package/native/cmd/ttsc-nestia/main.go +11 -11
  6. package/native/go.mod +32 -32
  7. package/native/go.sum +54 -54
  8. package/native/plugin/plan.go +102 -102
  9. package/native/transform/ast.go +32 -32
  10. package/native/transform/build.go +388 -380
  11. package/native/transform/cleanup.go +408 -408
  12. package/native/transform/contributor.go +97 -97
  13. package/native/transform/core_querify.go +231 -231
  14. package/native/transform/core_transform.go +1996 -1996
  15. package/native/transform/core_websocket.go +115 -115
  16. package/native/transform/exports.go +13 -13
  17. package/native/transform/mcp_transform.go +414 -414
  18. package/native/transform/node_transform.go +357 -357
  19. package/native/transform/path_rewrite.go +285 -285
  20. package/native/transform/printer.go +244 -244
  21. package/native/transform/rewrite.go +668 -668
  22. package/native/transform/run.go +73 -73
  23. package/native/transform/transform.go +336 -336
  24. package/native/transform/typia_fast.go +375 -352
  25. package/native/transform/typia_replacement.go +24 -24
  26. package/native/transform.cjs +43 -43
  27. package/package.json +9 -9
  28. package/src/adaptors/McpAdaptor.ts +276 -276
  29. package/src/adaptors/WebSocketAdaptor.ts +429 -429
  30. package/src/decorators/DynamicModule.ts +44 -44
  31. package/src/decorators/EncryptedBody.ts +97 -97
  32. package/src/decorators/EncryptedController.ts +40 -40
  33. package/src/decorators/EncryptedModule.ts +98 -98
  34. package/src/decorators/EncryptedRoute.ts +213 -213
  35. package/src/decorators/HumanRoute.ts +21 -21
  36. package/src/decorators/McpRoute.ts +154 -154
  37. package/src/decorators/NoTransformConfigurationError.ts +40 -40
  38. package/src/decorators/PlainBody.ts +76 -76
  39. package/src/decorators/SwaggerCustomizer.ts +97 -97
  40. package/src/decorators/SwaggerExample.ts +180 -180
  41. package/src/decorators/TypedBody.ts +57 -57
  42. package/src/decorators/TypedException.ts +147 -147
  43. package/src/decorators/TypedFormData.ts +187 -187
  44. package/src/decorators/TypedHeaders.ts +66 -66
  45. package/src/decorators/TypedParam.ts +77 -77
  46. package/src/decorators/TypedQuery.ts +234 -234
  47. package/src/decorators/TypedRoute.ts +198 -198
  48. package/src/decorators/WebSocketRoute.ts +242 -242
  49. package/src/decorators/doNotThrowTransformError.ts +5 -5
  50. package/src/decorators/internal/EncryptedConstant.ts +2 -2
  51. package/src/decorators/internal/IMcpRouteReflect.ts +40 -40
  52. package/src/decorators/internal/IWebSocketRouteReflect.ts +23 -23
  53. package/src/decorators/internal/get_path_and_querify.ts +94 -94
  54. package/src/decorators/internal/get_path_and_stringify.ts +110 -110
  55. package/src/decorators/internal/get_text_body.ts +16 -16
  56. package/src/decorators/internal/headers_to_object.ts +11 -11
  57. package/src/decorators/internal/is_request_body_undefined.ts +12 -12
  58. package/src/decorators/internal/load_controller.ts +94 -94
  59. package/src/decorators/internal/route_error.ts +43 -43
  60. package/src/decorators/internal/validate_request_body.ts +64 -64
  61. package/src/decorators/internal/validate_request_form_data.ts +67 -67
  62. package/src/decorators/internal/validate_request_headers.ts +76 -76
  63. package/src/decorators/internal/validate_request_query.ts +83 -83
  64. package/src/index.ts +5 -5
  65. package/src/module.ts +25 -25
  66. package/src/options/IRequestBodyValidator.ts +20 -20
  67. package/src/options/IRequestFormDataProps.ts +27 -27
  68. package/src/options/IRequestHeadersValidator.ts +22 -22
  69. package/src/options/IRequestQueryValidator.ts +20 -20
  70. package/src/options/IResponseBodyQuerifier.ts +25 -25
  71. package/src/options/IResponseBodyStringifier.ts +30 -30
  72. package/src/transform.ts +26 -26
  73. package/src/typings/Creator.ts +3 -3
  74. package/src/typings/get-function-location.d.ts +7 -7
  75. package/src/utils/ArrayUtil.ts +7 -7
  76. package/src/utils/ExceptionManager.ts +115 -115
  77. package/src/utils/Singleton.ts +16 -16
  78. package/src/utils/SourceFinder.ts +54 -54
  79. package/src/utils/VersioningStrategy.ts +27 -27
  80. package/README.md +0 -93
@@ -1,66 +1,66 @@
1
- import { ExecutionContext, createParamDecorator } from "@nestjs/common";
2
- import type express from "express";
3
- import type { FastifyRequest } from "fastify";
4
-
5
- import { IRequestHeadersValidator } from "../options/IRequestHeadersValidator";
6
- import { validate_request_headers } from "./internal/validate_request_headers";
7
-
8
- /**
9
- * Type safe HTTP headers decorator.
10
- *
11
- * `TypedHeaders` is a decorator function that can parse HTTP headers. It is
12
- * almost same with {@link nest.Headers}, but it can automatically cast property
13
- * type following its DTO definition. Also, `TypedHeaders` performs type
14
- * validation.
15
- *
16
- * For reference, target type `T` must follow such restrictions. Also, if actual
17
- * HTTP header values are different with their promised type `T`,
18
- * `BadRequestException` 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
- *
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
- * @author Jeongho Nam - https://github.com/samchon
49
- * @returns Parameter decorator
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
- ): T {
59
- const request: express.Request | FastifyRequest = context
60
- .switchToHttp()
61
- .getRequest();
62
- const output: T | Error = checker(request.headers);
63
- if (output instanceof Error) throw output;
64
- return output;
65
- })();
66
- }
1
+ import { ExecutionContext, createParamDecorator } from "@nestjs/common";
2
+ import type express from "express";
3
+ import type { FastifyRequest } from "fastify";
4
+
5
+ import { IRequestHeadersValidator } from "../options/IRequestHeadersValidator";
6
+ import { validate_request_headers } from "./internal/validate_request_headers";
7
+
8
+ /**
9
+ * Type safe HTTP headers decorator.
10
+ *
11
+ * `TypedHeaders` is a decorator function that can parse HTTP headers. It is
12
+ * almost same with {@link nest.Headers}, but it can automatically cast property
13
+ * type following its DTO definition. Also, `TypedHeaders` performs type
14
+ * validation.
15
+ *
16
+ * For reference, target type `T` must follow such restrictions. Also, if actual
17
+ * HTTP header values are different with their promised type `T`,
18
+ * `BadRequestException` 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
+ *
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
+ * @author Jeongho Nam - https://github.com/samchon
49
+ * @returns Parameter decorator
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
+ ): T {
59
+ const request: express.Request | FastifyRequest = context
60
+ .switchToHttp()
61
+ .getRequest();
62
+ const output: T | Error = checker(request.headers);
63
+ if (output instanceof Error) throw output;
64
+ return output;
65
+ })();
66
+ }
@@ -1,77 +1,77 @@
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, { IValidation, TypeGuardError } from "typia";
9
-
10
- import { NoTransformConfigurationError } from "./NoTransformConfigurationError";
11
-
12
- /**
13
- * Type safe URL parameter decorator.
14
- *
15
- * `TypedParam` is a decorator function getting specific typed parameter from
16
- * the HTTP request URL. It's almost same with the {@link nest.Param}, but
17
- * `TypedParam` automatically casts parameter value to be following its type,
18
- * 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
- * \@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
- * @author Jeongho Nam - https://github.com/samchon
32
- * @param name URL Parameter name
33
- * @returns Parameter decorator
34
- */
35
- export function TypedParam<T extends boolean | bigint | number | string | null>(
36
- name: string,
37
- assert?: (value: string) => T,
38
- validate?: boolean,
39
- ): ParameterDecorator {
40
- if (assert === undefined) {
41
- NoTransformConfigurationError("TypedParam");
42
- assert = (value) => value as T;
43
- }
44
-
45
- return createParamDecorator(function TypedParam(
46
- {}: any,
47
- context: ExecutionContext,
48
- ) {
49
- const request: express.Request | FastifyRequest = context
50
- .switchToHttp()
51
- .getRequest();
52
- const str: string = (request.params as any)[name];
53
- try {
54
- return assert(str);
55
- } catch (exp) {
56
- if (typia.is<TypeGuardError>(exp)) {
57
- const trace: IValidation.IError = {
58
- path: exp.path ?? "$input",
59
- expected: exp.expected,
60
- value: exp.value,
61
- };
62
- throw new BadRequestException({
63
- message: `Invalid URL parameter value on "${name}".`,
64
- ...(validate === true
65
- ? {
66
- errors: [trace],
67
- }
68
- : {
69
- ...trace,
70
- reason: exp.message,
71
- }),
72
- });
73
- }
74
- throw exp;
75
- }
76
- })(name);
77
- }
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, { IValidation, TypeGuardError } from "typia";
9
+
10
+ import { NoTransformConfigurationError } from "./NoTransformConfigurationError";
11
+
12
+ /**
13
+ * Type safe URL parameter decorator.
14
+ *
15
+ * `TypedParam` is a decorator function getting specific typed parameter from
16
+ * the HTTP request URL. It's almost same with the {@link nest.Param}, but
17
+ * `TypedParam` automatically casts parameter value to be following its type,
18
+ * 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
+ * \@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
+ * @author Jeongho Nam - https://github.com/samchon
32
+ * @param name URL Parameter name
33
+ * @returns Parameter decorator
34
+ */
35
+ export function TypedParam<T extends boolean | bigint | number | string | null>(
36
+ name: string,
37
+ assert?: (value: string) => T,
38
+ validate?: boolean,
39
+ ): ParameterDecorator {
40
+ if (assert === undefined) {
41
+ NoTransformConfigurationError("TypedParam");
42
+ assert = (value) => value as T;
43
+ }
44
+
45
+ return createParamDecorator(function TypedParam(
46
+ {}: any,
47
+ context: ExecutionContext,
48
+ ) {
49
+ const request: express.Request | FastifyRequest = context
50
+ .switchToHttp()
51
+ .getRequest();
52
+ const str: string = (request.params as any)[name];
53
+ try {
54
+ return assert(str);
55
+ } catch (exp) {
56
+ if (typia.is<TypeGuardError>(exp)) {
57
+ const trace: IValidation.IError = {
58
+ path: exp.path ?? "$input",
59
+ expected: exp.expected,
60
+ value: exp.value,
61
+ };
62
+ throw new BadRequestException({
63
+ message: `Invalid URL parameter value on "${name}".`,
64
+ ...(validate === true
65
+ ? {
66
+ errors: [trace],
67
+ }
68
+ : {
69
+ ...trace,
70
+ reason: exp.message,
71
+ }),
72
+ });
73
+ }
74
+ throw exp;
75
+ }
76
+ })(name);
77
+ }