@nestia/core 12.0.0-dev.20260521.6 → 12.0.0-dev.20260612.1

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 (116) hide show
  1. package/LICENSE +21 -21
  2. package/MIGRATION.md +169 -169
  3. package/README.md +93 -93
  4. package/lib/adaptors/McpAdaptor.d.ts +75 -0
  5. package/lib/adaptors/McpAdaptor.js +257 -0
  6. package/lib/adaptors/McpAdaptor.js.map +1 -0
  7. package/lib/adaptors/WebSocketAdaptor.js +4 -4
  8. package/lib/adaptors/WebSocketAdaptor.js.map +1 -1
  9. package/lib/decorators/McpRoute.d.ts +69 -0
  10. package/lib/decorators/McpRoute.js +58 -0
  11. package/lib/decorators/McpRoute.js.map +1 -0
  12. package/lib/decorators/TypedParam.js +4 -4
  13. package/lib/decorators/TypedParam.js.map +1 -1
  14. package/lib/decorators/TypedRoute.js +1 -1
  15. package/lib/decorators/TypedRoute.js.map +1 -1
  16. package/lib/decorators/internal/IMcpRouteReflect.d.ts +2 -0
  17. package/lib/decorators/internal/IMcpRouteReflect.js +3 -0
  18. package/lib/decorators/internal/IMcpRouteReflect.js.map +1 -0
  19. package/lib/decorators/internal/get_path_and_querify.js +4 -4
  20. package/lib/decorators/internal/get_path_and_querify.js.map +1 -1
  21. package/lib/decorators/internal/get_path_and_stringify.js +4 -4
  22. package/lib/decorators/internal/get_path_and_stringify.js.map +1 -1
  23. package/lib/decorators/internal/load_controller.js +34 -65
  24. package/lib/decorators/internal/load_controller.js.map +1 -1
  25. package/lib/decorators/internal/validate_request_body.js +4 -4
  26. package/lib/decorators/internal/validate_request_body.js.map +1 -1
  27. package/lib/decorators/internal/validate_request_form_data.js +4 -4
  28. package/lib/decorators/internal/validate_request_form_data.js.map +1 -1
  29. package/lib/decorators/internal/validate_request_headers.js +4 -4
  30. package/lib/decorators/internal/validate_request_headers.js.map +1 -1
  31. package/lib/decorators/internal/validate_request_query.js +4 -4
  32. package/lib/decorators/internal/validate_request_query.js.map +1 -1
  33. package/lib/module.d.ts +2 -0
  34. package/lib/module.js +2 -0
  35. package/lib/module.js.map +1 -1
  36. package/native/cmd/ttsc-nestia/main.go +11 -11
  37. package/native/go.mod +32 -32
  38. package/native/go.sum +54 -54
  39. package/native/plugin/plan.go +102 -102
  40. package/native/transform/ast.go +32 -32
  41. package/native/transform/build.go +380 -437
  42. package/native/transform/cleanup.go +408 -408
  43. package/native/transform/contributor.go +97 -68
  44. package/native/transform/core_querify.go +231 -227
  45. package/native/transform/core_transform.go +1996 -1713
  46. package/native/transform/core_websocket.go +115 -115
  47. package/native/transform/exports.go +13 -13
  48. package/native/transform/mcp_transform.go +414 -0
  49. package/native/transform/node_transform.go +357 -0
  50. package/native/transform/path_rewrite.go +285 -285
  51. package/native/transform/printer.go +244 -244
  52. package/native/transform/rewrite.go +668 -662
  53. package/native/transform/run.go +73 -73
  54. package/native/transform/transform.go +336 -387
  55. package/native/transform/typia_fast.go +352 -326
  56. package/native/transform/typia_replacement.go +24 -24
  57. package/native/transform.cjs +43 -43
  58. package/package.json +15 -8
  59. package/src/adaptors/McpAdaptor.ts +276 -0
  60. package/src/adaptors/WebSocketAdaptor.ts +429 -429
  61. package/src/decorators/DynamicModule.ts +44 -44
  62. package/src/decorators/EncryptedBody.ts +97 -97
  63. package/src/decorators/EncryptedController.ts +40 -40
  64. package/src/decorators/EncryptedModule.ts +98 -98
  65. package/src/decorators/EncryptedRoute.ts +213 -213
  66. package/src/decorators/HumanRoute.ts +21 -21
  67. package/src/decorators/McpRoute.ts +154 -0
  68. package/src/decorators/NoTransformConfigurationError.ts +40 -40
  69. package/src/decorators/PlainBody.ts +76 -76
  70. package/src/decorators/SwaggerCustomizer.ts +97 -97
  71. package/src/decorators/SwaggerExample.ts +180 -180
  72. package/src/decorators/TypedBody.ts +57 -57
  73. package/src/decorators/TypedException.ts +147 -147
  74. package/src/decorators/TypedFormData.ts +187 -187
  75. package/src/decorators/TypedHeaders.ts +66 -66
  76. package/src/decorators/TypedParam.ts +77 -77
  77. package/src/decorators/TypedQuery.ts +234 -234
  78. package/src/decorators/TypedRoute.ts +198 -196
  79. package/src/decorators/WebSocketRoute.ts +242 -242
  80. package/src/decorators/doNotThrowTransformError.ts +5 -5
  81. package/src/decorators/internal/EncryptedConstant.ts +2 -2
  82. package/src/decorators/internal/IMcpRouteReflect.ts +40 -0
  83. package/src/decorators/internal/IWebSocketRouteReflect.ts +23 -23
  84. package/src/decorators/internal/get_path_and_querify.ts +94 -94
  85. package/src/decorators/internal/get_path_and_stringify.ts +110 -110
  86. package/src/decorators/internal/get_text_body.ts +16 -16
  87. package/src/decorators/internal/headers_to_object.ts +11 -11
  88. package/src/decorators/internal/is_request_body_undefined.ts +12 -12
  89. package/src/decorators/internal/load_controller.ts +91 -76
  90. package/src/decorators/internal/route_error.ts +43 -43
  91. package/src/decorators/internal/validate_request_body.ts +64 -64
  92. package/src/decorators/internal/validate_request_form_data.ts +67 -67
  93. package/src/decorators/internal/validate_request_headers.ts +76 -76
  94. package/src/decorators/internal/validate_request_query.ts +83 -83
  95. package/src/index.ts +5 -5
  96. package/src/module.ts +25 -23
  97. package/src/options/IRequestBodyValidator.ts +20 -20
  98. package/src/options/IRequestFormDataProps.ts +27 -27
  99. package/src/options/IRequestHeadersValidator.ts +22 -22
  100. package/src/options/IRequestQueryValidator.ts +20 -20
  101. package/src/options/IResponseBodyQuerifier.ts +25 -25
  102. package/src/options/IResponseBodyStringifier.ts +30 -30
  103. package/src/transform.ts +101 -101
  104. package/src/typings/Creator.ts +3 -3
  105. package/src/typings/get-function-location.d.ts +7 -7
  106. package/src/utils/ArrayUtil.ts +7 -7
  107. package/src/utils/ExceptionManager.ts +115 -115
  108. package/src/utils/Singleton.ts +16 -16
  109. package/src/utils/SourceFinder.ts +54 -54
  110. package/src/utils/VersioningStrategy.ts +27 -27
  111. package/native/transform/cleanup_test.go +0 -76
  112. package/native/transform/commonjs_import_alias_test.go +0 -49
  113. package/native/transform/core_dispatch_test.go +0 -127
  114. package/native/transform/path_rewrite_test.go +0 -243
  115. package/native/transform/rewrite_test.go +0 -118
  116. package/native/transform/rewrite_unique_base_test.go +0 -48
@@ -1,40 +1,40 @@
1
- /** @internal */
2
- export function NoTransformConfigurationError(method: string) {
3
- if (NoTransformConfigurationError.throws === true)
4
- throw new Error(
5
- [
6
- `Error on nestia.core.${method}(): no transform has been configured.`,
7
- `Build the project with "ttsc" (not stock "tsc"); the Go-backed @nestia/core transform attaches automatically through ttsc plugin auto-discovery.`,
8
- `If "ttsc" is missing, run "npx nestia setup" to install the toolchain and runtime packages.`,
9
- `If you're using a non-standard TypeScript compiler like Babel or SWC, the @nestia/core transformer is not available.`,
10
- `If you're running "npx nestia sdk/swagger" or similar, run "npx ttsc --noEmit" to surface the underlying compilation error.`,
11
- `See https://nestia.io/docs/setup for the full setup (tsgo and legacy paths); migration notes are at node_modules/@nestia/core/MIGRATION.md.`,
12
- ].join(" "),
13
- );
14
- return undefined as never;
15
- }
16
-
17
- /** @internal */
18
- export namespace NoTransformConfigurationError {
19
- /**
20
- * Whether to throw an error or not.
21
- *
22
- * If you set this value to `false`, {@link NoTransformConfigurationError} will
23
- * not throw an error.
24
- *
25
- * Even if you've not configured the plugin transformer of `tsconfig.json`
26
- * file, the error will not be thrown and the program will be continued.
27
- * Instead, every validations and assertions will be skipped and the value
28
- * will be returned as it is. Furthermore, unexpected behaviors may occur.
29
- *
30
- * Therefore, it is not recommended to set this value to `false` in production
31
- * environment. Configure this value to be `false` only when you're debugging
32
- * or testing.
33
- *
34
- * By the way, if you hope the `false` value to be set, you have to do it
35
- * before the first. If you configure the `false` value after the
36
- * `@nestia/core` decorator functions are composed, the value will not be
37
- * applied and the error will be thrown.
38
- */
39
- export let throws = true;
40
- }
1
+ /** @internal */
2
+ export function NoTransformConfigurationError(method: string) {
3
+ if (NoTransformConfigurationError.throws === true)
4
+ throw new Error(
5
+ [
6
+ `Error on nestia.core.${method}(): no transform has been configured.`,
7
+ `Build the project with "ttsc" (not stock "tsc"); the Go-backed @nestia/core transform attaches automatically through ttsc plugin auto-discovery.`,
8
+ `If "ttsc" is missing, run "npx nestia setup" to install the toolchain and runtime packages.`,
9
+ `If you're using a non-standard TypeScript compiler like Babel or SWC, the @nestia/core transformer is not available.`,
10
+ `If you're running "npx nestia sdk/swagger" or similar, run "npx ttsc --noEmit" to surface the underlying compilation error.`,
11
+ `See https://nestia.io/docs/setup for the full setup (tsgo and legacy paths); migration notes are at node_modules/@nestia/core/MIGRATION.md.`,
12
+ ].join(" "),
13
+ );
14
+ return undefined as never;
15
+ }
16
+
17
+ /** @internal */
18
+ export namespace NoTransformConfigurationError {
19
+ /**
20
+ * Whether to throw an error or not.
21
+ *
22
+ * If you set this value to `false`, {@link NoTransformConfigurationError} will
23
+ * not throw an error.
24
+ *
25
+ * Even if you've not configured the plugin transformer of `tsconfig.json`
26
+ * file, the error will not be thrown and the program will be continued.
27
+ * Instead, every validations and assertions will be skipped and the value
28
+ * will be returned as it is. Furthermore, unexpected behaviors may occur.
29
+ *
30
+ * Therefore, it is not recommended to set this value to `false` in production
31
+ * environment. Configure this value to be `false` only when you're debugging
32
+ * or testing.
33
+ *
34
+ * By the way, if you hope the `false` value to be set, you have to do it
35
+ * before the first. If you configure the `false` value after the
36
+ * `@nestia/core` decorator functions are composed, the value will not be
37
+ * applied and the error will be thrown.
38
+ */
39
+ export let throws = true;
40
+ }
@@ -1,76 +1,76 @@
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 { get_text_body } from "./internal/get_text_body";
10
- import { is_request_body_undefined } from "./internal/is_request_body_undefined";
11
- import { validate_request_body } from "./internal/validate_request_body";
12
-
13
- /**
14
- * Plain body decorator.
15
- *
16
- * `PlainBody` is a decorator function getting full body text from the HTTP
17
- * request.
18
- *
19
- * If you adjust the regular {@link Body} decorator function to the body
20
- * parameter, you can't get the full body text because the {@link Body} tries to
21
- * convert the body text to JSON object. Therefore, `@nestia/core` provides this
22
- * `PlainBody` decorator function to get the full body text.
23
- *
24
- * ```typescript
25
- * \@TypedRoute.Post("memo")
26
- * public store
27
- * (
28
- * \@PlainBody() body: string
29
- * ): void;
30
- * ```
31
- *
32
- * @author Jeongho Nam - https://github.com/samchon
33
- * @returns Parameter decorator
34
- */
35
- export function PlainBody(): ParameterDecorator;
36
-
37
- /** @internal */
38
- export function PlainBody(
39
- assert?: (input: unknown) => string,
40
- ): ParameterDecorator {
41
- const checker = assert
42
- ? validate_request_body("PlainBody")({
43
- type: "assert",
44
- assert,
45
- })
46
- : null;
47
- return createParamDecorator(async function PlainBody(
48
- _data: any,
49
- context: ExecutionContext,
50
- ) {
51
- const request: express.Request | FastifyRequest = context
52
- .switchToHttp()
53
- .getRequest();
54
- if (
55
- is_request_body_undefined(request) &&
56
- (checker ?? (() => null))(undefined as any) === null
57
- )
58
- return undefined;
59
- else if (!isTextPlain(request.headers["content-type"]))
60
- throw new BadRequestException(`Request body type is not "text/plain".`);
61
- const value: string = await get_text_body(request);
62
- if (checker) {
63
- const error: Error | null = checker(value);
64
- if (error !== null) throw error;
65
- }
66
- return value;
67
- })();
68
- }
69
-
70
- /** @internal */
71
- const isTextPlain = (text?: string): boolean =>
72
- text !== undefined &&
73
- text
74
- .split(";")
75
- .map((str) => str.trim())
76
- .some((str) => str === "text/plain");
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 { get_text_body } from "./internal/get_text_body";
10
+ import { is_request_body_undefined } from "./internal/is_request_body_undefined";
11
+ import { validate_request_body } from "./internal/validate_request_body";
12
+
13
+ /**
14
+ * Plain body decorator.
15
+ *
16
+ * `PlainBody` is a decorator function getting full body text from the HTTP
17
+ * request.
18
+ *
19
+ * If you adjust the regular {@link Body} decorator function to the body
20
+ * parameter, you can't get the full body text because the {@link Body} tries to
21
+ * convert the body text to JSON object. Therefore, `@nestia/core` provides this
22
+ * `PlainBody` decorator function to get the full body text.
23
+ *
24
+ * ```typescript
25
+ * \@TypedRoute.Post("memo")
26
+ * public store
27
+ * (
28
+ * \@PlainBody() body: string
29
+ * ): void;
30
+ * ```
31
+ *
32
+ * @author Jeongho Nam - https://github.com/samchon
33
+ * @returns Parameter decorator
34
+ */
35
+ export function PlainBody(): ParameterDecorator;
36
+
37
+ /** @internal */
38
+ export function PlainBody(
39
+ assert?: (input: unknown) => string,
40
+ ): ParameterDecorator {
41
+ const checker = assert
42
+ ? validate_request_body("PlainBody")({
43
+ type: "assert",
44
+ assert,
45
+ })
46
+ : null;
47
+ return createParamDecorator(async function PlainBody(
48
+ _data: any,
49
+ context: ExecutionContext,
50
+ ) {
51
+ const request: express.Request | FastifyRequest = context
52
+ .switchToHttp()
53
+ .getRequest();
54
+ if (
55
+ is_request_body_undefined(request) &&
56
+ (checker ?? (() => null))(undefined as any) === null
57
+ )
58
+ return undefined;
59
+ else if (!isTextPlain(request.headers["content-type"]))
60
+ throw new BadRequestException(`Request body type is not "text/plain".`);
61
+ const value: string = await get_text_body(request);
62
+ if (checker) {
63
+ const error: Error | null = checker(value);
64
+ if (error !== null) throw error;
65
+ }
66
+ return value;
67
+ })();
68
+ }
69
+
70
+ /** @internal */
71
+ const isTextPlain = (text?: string): boolean =>
72
+ text !== undefined &&
73
+ text
74
+ .split(";")
75
+ .map((str) => str.trim())
76
+ .some((str) => str === "text/plain");
@@ -1,97 +1,97 @@
1
- import { OpenApi } from "@typia/interface";
2
-
3
- /**
4
- * Swagger customization decorator.
5
- *
6
- * `SwaggerCustomizer` is a method decorator function which can used for
7
- * customizing the swagger data with `npx nestia swagger` command. Furthermore,
8
- * it is possible to add plugin properties starting with `x-` characters.
9
- *
10
- * In other words, this decorator function does not affect to the runtime, but
11
- * only for the swagger data customization.
12
- *
13
- * @author Jeongho Nam - https://github.com/samchon
14
- * @param closure Callback function which can customize the swagger data
15
- * @returns Method decorator
16
- */
17
- export function SwaggerCustomizer(
18
- closure: (props: SwaggerCustomizer.IProps) => unknown,
19
- ): MethodDecorator {
20
- return function SwaggerCustomizer(
21
- target: Object,
22
- propertyKey: string | symbol,
23
- descriptor: TypedPropertyDescriptor<any>,
24
- ) {
25
- const array: Array<(props: SwaggerCustomizer.IProps) => unknown> = (() => {
26
- if (Reflect.hasMetadata("nestia/SwaggerCustomizer", target, propertyKey))
27
- return Reflect.getMetadata(
28
- "nestia/SwaggerCustomizer",
29
- target,
30
- propertyKey,
31
- );
32
- const array: Array<(props: SwaggerCustomizer.IProps) => unknown> = [];
33
- Reflect.defineMetadata(
34
- "nestia/SwaggerCustomizer",
35
- array,
36
- target,
37
- propertyKey,
38
- );
39
- return array;
40
- })();
41
- array.push(closure);
42
- return descriptor;
43
- };
44
- }
45
- export namespace SwaggerCustomizer {
46
- /**
47
- * Properties for the `SwaggerCustomizer` decorator.
48
- *
49
- * `SwaggerCustomizer.IProps` is a type for the `closure` parameter of the
50
- * `SwaggerCustomizer` decorator. It's a callback function which can customize
51
- * the swagger data.
52
- */
53
- export interface IProps {
54
- /** Swagger data. */
55
- swagger: OpenApi.IDocument;
56
-
57
- /** Method of the route. */
58
- method: string;
59
-
60
- /** Path of the route. */
61
- path: string;
62
-
63
- /** Route data. */
64
- route: OpenApi.IOperation;
65
-
66
- /**
67
- * Get neighbor endpoint data through the controller method.
68
- *
69
- * @param func Controller method to find the neighbor endpoint
70
- * @returns Neighbor endpoint data
71
- */
72
- at(func: Function): ISwaggerEndpoint | undefined;
73
-
74
- /**
75
- * Get neighbor route data.
76
- *
77
- * @param accessor Accessor for getting neighbor route data
78
- * @returns Neighbor route data
79
- */
80
- get(accessor: IAccessor): OpenApi.IOperation | undefined;
81
- }
82
-
83
- /** Accessor for getting neighbor route data. */
84
- export interface IAccessor {
85
- /** Path of the neighbor route. */
86
- path: string;
87
-
88
- /** Method of the neighbor route. */
89
- method: string;
90
- }
91
-
92
- /** Endpoint info of the route. */
93
- export interface ISwaggerEndpoint extends IAccessor {
94
- /** Route data. */
95
- route: OpenApi.IOperation;
96
- }
97
- }
1
+ import { OpenApi } from "@typia/interface";
2
+
3
+ /**
4
+ * Swagger customization decorator.
5
+ *
6
+ * `SwaggerCustomizer` is a method decorator function which can used for
7
+ * customizing the swagger data with `npx nestia swagger` command. Furthermore,
8
+ * it is possible to add plugin properties starting with `x-` characters.
9
+ *
10
+ * In other words, this decorator function does not affect to the runtime, but
11
+ * only for the swagger data customization.
12
+ *
13
+ * @author Jeongho Nam - https://github.com/samchon
14
+ * @param closure Callback function which can customize the swagger data
15
+ * @returns Method decorator
16
+ */
17
+ export function SwaggerCustomizer(
18
+ closure: (props: SwaggerCustomizer.IProps) => unknown,
19
+ ): MethodDecorator {
20
+ return function SwaggerCustomizer(
21
+ target: Object,
22
+ propertyKey: string | symbol,
23
+ descriptor: TypedPropertyDescriptor<any>,
24
+ ) {
25
+ const array: Array<(props: SwaggerCustomizer.IProps) => unknown> = (() => {
26
+ if (Reflect.hasMetadata("nestia/SwaggerCustomizer", target, propertyKey))
27
+ return Reflect.getMetadata(
28
+ "nestia/SwaggerCustomizer",
29
+ target,
30
+ propertyKey,
31
+ );
32
+ const array: Array<(props: SwaggerCustomizer.IProps) => unknown> = [];
33
+ Reflect.defineMetadata(
34
+ "nestia/SwaggerCustomizer",
35
+ array,
36
+ target,
37
+ propertyKey,
38
+ );
39
+ return array;
40
+ })();
41
+ array.push(closure);
42
+ return descriptor;
43
+ };
44
+ }
45
+ export namespace SwaggerCustomizer {
46
+ /**
47
+ * Properties for the `SwaggerCustomizer` decorator.
48
+ *
49
+ * `SwaggerCustomizer.IProps` is a type for the `closure` parameter of the
50
+ * `SwaggerCustomizer` decorator. It's a callback function which can customize
51
+ * the swagger data.
52
+ */
53
+ export interface IProps {
54
+ /** Swagger data. */
55
+ swagger: OpenApi.IDocument;
56
+
57
+ /** Method of the route. */
58
+ method: string;
59
+
60
+ /** Path of the route. */
61
+ path: string;
62
+
63
+ /** Route data. */
64
+ route: OpenApi.IOperation;
65
+
66
+ /**
67
+ * Get neighbor endpoint data through the controller method.
68
+ *
69
+ * @param func Controller method to find the neighbor endpoint
70
+ * @returns Neighbor endpoint data
71
+ */
72
+ at(func: Function): ISwaggerEndpoint | undefined;
73
+
74
+ /**
75
+ * Get neighbor route data.
76
+ *
77
+ * @param accessor Accessor for getting neighbor route data
78
+ * @returns Neighbor route data
79
+ */
80
+ get(accessor: IAccessor): OpenApi.IOperation | undefined;
81
+ }
82
+
83
+ /** Accessor for getting neighbor route data. */
84
+ export interface IAccessor {
85
+ /** Path of the neighbor route. */
86
+ path: string;
87
+
88
+ /** Method of the neighbor route. */
89
+ method: string;
90
+ }
91
+
92
+ /** Endpoint info of the route. */
93
+ export interface ISwaggerEndpoint extends IAccessor {
94
+ /** Route data. */
95
+ route: OpenApi.IOperation;
96
+ }
97
+ }