@nestia/core 14.0.1 → 14.0.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 (156) hide show
  1. package/lib/adaptors/McpAdaptor.d.ts +24 -3
  2. package/lib/adaptors/McpAdaptor.js +72 -34
  3. package/lib/adaptors/McpAdaptor.js.map +1 -1
  4. package/lib/adaptors/WebSocketAdaptor.d.ts +37 -0
  5. package/lib/adaptors/WebSocketAdaptor.js +60 -16
  6. package/lib/adaptors/WebSocketAdaptor.js.map +1 -1
  7. package/lib/adaptors/internal/external_context.js +18 -5
  8. package/lib/adaptors/internal/external_context.js.map +1 -1
  9. package/lib/decorators/DynamicModule.d.ts +13 -1
  10. package/lib/decorators/DynamicModule.js +12 -0
  11. package/lib/decorators/DynamicModule.js.map +1 -1
  12. package/lib/decorators/EncryptedBody.d.ts +14 -6
  13. package/lib/decorators/EncryptedBody.js +37 -14
  14. package/lib/decorators/EncryptedBody.js.map +1 -1
  15. package/lib/decorators/EncryptedController.d.ts +6 -1
  16. package/lib/decorators/EncryptedController.js +6 -1
  17. package/lib/decorators/EncryptedController.js.map +1 -1
  18. package/lib/decorators/EncryptedModule.d.ts +18 -3
  19. package/lib/decorators/EncryptedModule.js +18 -3
  20. package/lib/decorators/EncryptedModule.js.map +1 -1
  21. package/lib/decorators/EncryptedRoute.d.ts +20 -11
  22. package/lib/decorators/EncryptedRoute.js +20 -11
  23. package/lib/decorators/EncryptedRoute.js.map +1 -1
  24. package/lib/decorators/HumanRoute.d.ts +5 -0
  25. package/lib/decorators/HumanRoute.js +5 -0
  26. package/lib/decorators/HumanRoute.js.map +1 -1
  27. package/lib/decorators/McpRoute.d.ts +31 -19
  28. package/lib/decorators/McpRoute.js +12 -1
  29. package/lib/decorators/McpRoute.js.map +1 -1
  30. package/lib/decorators/PlainBody.d.ts +7 -1
  31. package/lib/decorators/PlainBody.js +16 -8
  32. package/lib/decorators/PlainBody.js.map +1 -1
  33. package/lib/decorators/SwaggerCustomizer.d.ts +15 -0
  34. package/lib/decorators/SwaggerCustomizer.js +5 -0
  35. package/lib/decorators/SwaggerCustomizer.js.map +1 -1
  36. package/lib/decorators/SwaggerExample.d.ts +51 -22
  37. package/lib/decorators/SwaggerExample.js +35 -22
  38. package/lib/decorators/SwaggerExample.js.map +1 -1
  39. package/lib/decorators/TypedBody.d.ts +9 -2
  40. package/lib/decorators/TypedBody.js +19 -9
  41. package/lib/decorators/TypedBody.js.map +1 -1
  42. package/lib/decorators/TypedException.d.ts +10 -0
  43. package/lib/decorators/TypedFormData.d.ts +59 -1
  44. package/lib/decorators/TypedFormData.js +5 -0
  45. package/lib/decorators/TypedFormData.js.map +1 -1
  46. package/lib/decorators/TypedHeaders.d.ts +5 -0
  47. package/lib/decorators/TypedHeaders.js +5 -0
  48. package/lib/decorators/TypedHeaders.js.map +1 -1
  49. package/lib/decorators/TypedParam.d.ts +9 -0
  50. package/lib/decorators/TypedParam.js +9 -0
  51. package/lib/decorators/TypedParam.js.map +1 -1
  52. package/lib/decorators/TypedQuery.d.ts +16 -0
  53. package/lib/decorators/TypedQuery.js +16 -0
  54. package/lib/decorators/TypedQuery.js.map +1 -1
  55. package/lib/decorators/TypedRoute.d.ts +25 -10
  56. package/lib/decorators/TypedRoute.js +19 -10
  57. package/lib/decorators/TypedRoute.js.map +1 -1
  58. package/lib/decorators/WebSocketRoute.d.ts +18 -1
  59. package/lib/decorators/WebSocketRoute.js +18 -1
  60. package/lib/decorators/WebSocketRoute.js.map +1 -1
  61. package/lib/decorators/doNotThrowTransformError.d.ts +14 -0
  62. package/lib/decorators/doNotThrowTransformError.js +14 -0
  63. package/lib/decorators/doNotThrowTransformError.js.map +1 -1
  64. package/lib/decorators/internal/IRequestBodyValidation.d.ts +66 -0
  65. package/lib/decorators/internal/IRequestBodyValidation.js +3 -0
  66. package/lib/decorators/internal/IRequestBodyValidation.js.map +1 -0
  67. package/lib/decorators/internal/IWebSocketRouteReflect.d.ts +93 -1
  68. package/lib/decorators/internal/get_path_and_querify.js +3 -7
  69. package/lib/decorators/internal/get_path_and_querify.js.map +1 -1
  70. package/lib/decorators/internal/get_path_and_stringify.js +3 -7
  71. package/lib/decorators/internal/get_path_and_stringify.js.map +1 -1
  72. package/lib/decorators/internal/load_controller.d.ts +14 -0
  73. package/lib/decorators/internal/load_controller.js +14 -0
  74. package/lib/decorators/internal/load_controller.js.map +1 -1
  75. package/lib/decorators/internal/split_route_arguments.d.ts +1 -0
  76. package/lib/decorators/internal/split_route_arguments.js +22 -0
  77. package/lib/decorators/internal/split_route_arguments.js.map +1 -0
  78. package/lib/decorators/internal/validate_request_body.js +68 -25
  79. package/lib/decorators/internal/validate_request_body.js.map +1 -1
  80. package/lib/options/IRequestBodyValidator.d.ts +71 -0
  81. package/lib/options/IRequestFormDataProps.d.ts +80 -0
  82. package/lib/options/IRequestHeadersValidator.d.ts +67 -0
  83. package/lib/options/IRequestQueryValidator.d.ts +68 -0
  84. package/lib/options/IResponseBodyQuerifier.d.ts +120 -0
  85. package/lib/options/IResponseBodyStringifier.d.ts +107 -0
  86. package/lib/typings/Creator.d.ts +10 -0
  87. package/lib/utils/ArrayUtil.d.ts +21 -0
  88. package/lib/utils/ArrayUtil.js +22 -1
  89. package/lib/utils/ArrayUtil.js.map +1 -1
  90. package/lib/utils/ExceptionManager.d.ts +40 -0
  91. package/lib/utils/ExceptionManager.js +34 -0
  92. package/lib/utils/ExceptionManager.js.map +1 -1
  93. package/lib/utils/SourceFinder.d.ts +22 -0
  94. package/lib/utils/SourceFinder.js +34 -7
  95. package/lib/utils/SourceFinder.js.map +1 -1
  96. package/lib/utils/VersioningStrategy.d.ts +37 -2
  97. package/lib/utils/VersioningStrategy.js +30 -9
  98. package/lib/utils/VersioningStrategy.js.map +1 -1
  99. package/native/go.mod +1 -1
  100. package/native/go.sum +2 -2
  101. package/native/plugin/plan.go +68 -2
  102. package/native/transform/ast.go +19 -1
  103. package/native/transform/build.go +51 -57
  104. package/native/transform/buildoutput/output.go +147 -0
  105. package/native/transform/contributor.go +9 -0
  106. package/native/transform/core_querify.go +37 -3
  107. package/native/transform/core_transform.go +105 -98
  108. package/native/transform/core_websocket.go +21 -5
  109. package/native/transform/node_transform.go +11 -8
  110. package/native/transform/package.go +55 -0
  111. package/native/transform/printer.go +1 -3
  112. package/native/transform/run.go +18 -0
  113. package/native/transform/schemaprojection/project.go +213 -0
  114. package/native/transform/transform.go +21 -0
  115. package/package.json +9 -7
  116. package/src/adaptors/McpAdaptor.ts +86 -26
  117. package/src/adaptors/WebSocketAdaptor.ts +70 -15
  118. package/src/adaptors/internal/external_context.ts +43 -6
  119. package/src/decorators/DynamicModule.ts +13 -1
  120. package/src/decorators/EncryptedBody.ts +37 -13
  121. package/src/decorators/EncryptedController.ts +6 -1
  122. package/src/decorators/EncryptedModule.ts +18 -3
  123. package/src/decorators/EncryptedRoute.ts +21 -12
  124. package/src/decorators/HumanRoute.ts +5 -0
  125. package/src/decorators/McpRoute.ts +31 -19
  126. package/src/decorators/PlainBody.ts +20 -10
  127. package/src/decorators/SwaggerCustomizer.ts +15 -0
  128. package/src/decorators/SwaggerExample.ts +51 -22
  129. package/src/decorators/TypedBody.ts +17 -8
  130. package/src/decorators/TypedException.ts +10 -0
  131. package/src/decorators/TypedFormData.ts +60 -2
  132. package/src/decorators/TypedHeaders.ts +5 -0
  133. package/src/decorators/TypedParam.ts +9 -0
  134. package/src/decorators/TypedQuery.ts +17 -1
  135. package/src/decorators/TypedRoute.ts +26 -11
  136. package/src/decorators/WebSocketRoute.ts +18 -1
  137. package/src/decorators/doNotThrowTransformError.ts +14 -0
  138. package/src/decorators/internal/IMcpRouteReflect.ts +7 -1
  139. package/src/decorators/internal/IRequestBodyValidation.ts +65 -0
  140. package/src/decorators/internal/IWebSocketRouteReflect.ts +95 -1
  141. package/src/decorators/internal/get_path_and_querify.ts +3 -9
  142. package/src/decorators/internal/get_path_and_stringify.ts +3 -9
  143. package/src/decorators/internal/load_controller.ts +14 -0
  144. package/src/decorators/internal/split_route_arguments.ts +20 -0
  145. package/src/decorators/internal/validate_request_body.ts +87 -34
  146. package/src/options/IRequestBodyValidator.ts +71 -0
  147. package/src/options/IRequestFormDataProps.ts +80 -0
  148. package/src/options/IRequestHeadersValidator.ts +67 -0
  149. package/src/options/IRequestQueryValidator.ts +68 -0
  150. package/src/options/IResponseBodyQuerifier.ts +120 -0
  151. package/src/options/IResponseBodyStringifier.ts +107 -0
  152. package/src/typings/Creator.ts +10 -0
  153. package/src/utils/ArrayUtil.ts +22 -3
  154. package/src/utils/ExceptionManager.ts +40 -0
  155. package/src/utils/SourceFinder.ts +38 -7
  156. package/src/utils/VersioningStrategy.ts +47 -14
@@ -12,7 +12,7 @@ import {
12
12
  UseInterceptors,
13
13
  applyDecorators,
14
14
  } from "@nestjs/common";
15
- import { HttpArgumentsHost } from "@nestjs/common/interfaces";
15
+ import { HttpArgumentsHost } from "@nestjs/common/interfaces/index.js";
16
16
  import express from "express";
17
17
  import { catchError, map } from "rxjs/operators";
18
18
  import typia from "typia";
@@ -29,22 +29,26 @@ import { route_error } from "./internal/route_error";
29
29
  * Encrypted router decorator functions.
30
30
  *
31
31
  * `EncryptedRoute` is a module containing router decorator functions which
32
- * encrypts response body data through AES-128/256 encryption. Furthermore, they
33
- * can boost up JSON string conversion speed about 50x times faster than
34
- * `class-transformer`, even type safe through
35
- * [typia](https://github.com/samchon/typia).
32
+ * encrypts response body data through AES-128/192/256 encryption after
33
+ * serializing it with a [typia](https://github.com/samchon/typia) function
34
+ * generated from the declared return type.
36
35
  *
37
- * For reference, if you try to invalid data that is not following the promised
38
- * type `T`, 500 internal server error would be thrown. Also, as
39
- * `EncryptedRoute` composes JSON string through `typia.assertStringify<T>()`
40
- * function, it is not possible to modify response data through interceptors.
36
+ * The default assert serializer rejects a response outside the declared type
37
+ * with a 500 error. The configured stringify mode chooses the validation policy
38
+ * before encryption; `validate.log` logs failures and serializes the original
39
+ * value. Interceptors running afterwards receive ciphertext.
41
40
  *
42
- * - AES-128/256
41
+ * - AES-128/192/256
43
42
  * - CBC mode
44
43
  * - PKCS #5 Padding
45
44
  * - Base64 Encoding
46
45
  *
47
46
  * @author Jeongho Nam - https://github.com/samchon
47
+ * @evidence contracts/common.md#principled-implementation Each route method decorates Nest's router decorator with an interceptor that serializes the value as the transform chose, encrypts it with the password of the controller or module, and answers `text/plain` on success only, so an error keeps its own JSON type.
48
+ * @evidence contracts/common.md#clear-and-simple-design One generator function creates the five HTTP-method decorators, and the interceptor and the router table are module-private.
49
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts The password lookup and the serializer come from shared modules; the loop after the namespace copies the marker properties of typia's stringify functions onto the five decorators as the transform expects, which mutates only these exported functions.
50
+ * @evidence contracts/common.md#meaningful-documentation The comment documents the decorator family and its password requirement.
51
+ * @evidenceExclude contracts/portability.md#os-neutral-implementation Route paths and serialized ciphertext are HTTP protocol values; response interception does not access native files or launch a process.
48
52
  */
49
53
  export namespace EncryptedRoute {
50
54
  /**
@@ -56,7 +60,7 @@ export namespace EncryptedRoute {
56
60
  export const Get = Generator("Get");
57
61
 
58
62
  /**
59
- * Encrypted router decorator function for the GET method.
63
+ * Encrypted router decorator function for the POST method.
60
64
  *
61
65
  * @param paths Path(s) of the HTTP request
62
66
  * @returns Method decorator
@@ -93,7 +97,7 @@ export namespace EncryptedRoute {
93
97
  * If you've configured the transformation option to `validate.log` in the
94
98
  * `tsconfig.json` file, then the error log information of the response
95
99
  * validation failure would be logged through this function instead of
96
- * throwing the 400 bad request error.
100
+ * throwing the 500 internal server error.
97
101
  *
98
102
  * By the way, be careful. If you've configured the response transformation
99
103
  * option to be `validate.log`, client may get wrong response data. Therefore,
@@ -101,6 +105,11 @@ export namespace EncryptedRoute {
101
105
  *
102
106
  * @default console.log
103
107
  * @param func Logger function
108
+ * @evidence contracts/common.md#principled-implementation It stores the logger in `TypedRoute`, which owns the single logger both route families use.
109
+ * @evidence contracts/common.md#clear-and-simple-design A one-line delegation, so the logger has one owner.
110
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts It changes only the logger variable.
111
+ * @evidence contracts/common.md#meaningful-documentation The comment states which validate mode uses the logger.
112
+ * @evidenceExclude contracts/portability.md#os-neutral-implementation Route paths and serialized ciphertext are HTTP protocol values; response interception does not access native files or launch a process.
104
113
  */
105
114
  export function setValidateErrorLogger(
106
115
  func: (log: IValidateErrorLog) => void,
@@ -13,6 +13,11 @@ import { SwaggerCustomizer } from "./SwaggerCustomizer";
13
13
  *
14
14
  * @author Jeongho Nam - https://github.com/samchon
15
15
  * @returns Method decorator
16
+ * @evidence contracts/common.md#principled-implementation The decorator marks the operation with the `x-samchon-human` extension through `SwaggerCustomizer`, so the generated document carries the mark without another metadata path.
17
+ * @evidence contracts/common.md#clear-and-simple-design One call to the customizer.
18
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts The extension name is the documented contract of the generated document.
19
+ * @evidence contracts/common.md#meaningful-documentation The comment states that a marked API is left out of the LLM function calling schema.
20
+ * @evidenceExclude contracts/portability.md#os-neutral-implementation The OpenAPI extension is an in-memory document property and has no native path or process representation.
16
21
  */
17
22
  export function HumanRoute(): MethodDecorator {
18
23
  return SwaggerCustomizer((props) => {
@@ -25,27 +25,28 @@ import { validate_request_body } from "./internal/validate_request_body";
25
25
  * the {@link INestApplication} instance at bootstrap. The decorator alone only
26
26
  * stores reflection metadata.
27
27
  *
28
- * @author wildduck - https://github.com/wildduck2
29
- * @example
30
- * ```typescript
31
- * import core from "@nestia/core";
28
+ * Example:
29
+ *
30
+ * ```typescript
31
+ * import core from "@nestia/core";
32
32
  *
33
- * @Controller()
34
- * export class WeatherController {
35
- * /**
36
- * * Return current weather for a city.
37
- * *
38
- * * @title Get weather
39
- * *\/
40
- * @core.McpRoute("get_weather")
41
- * public async get(
42
- * @core.McpRoute.Params() params: { city: string },
43
- * ): Promise<{ temp: number }> {
44
- * return { temp: 22 };
45
- * }
33
+ * @Controller()
34
+ * export class WeatherController {
35
+ * /**
36
+ * * Return current weather for a city.
37
+ * *
38
+ * * @title Get weather
39
+ * *\/
40
+ * @core.McpRoute("get_weather")
41
+ * public async get(
42
+ * @core.McpRoute.Params() params: { city: string },
43
+ * ): Promise<{ temp: number }> {
44
+ * return { temp: 22 };
46
45
  * }
47
- * ```;
46
+ * }
47
+ * ```
48
48
  *
49
+ * @author wildduck - https://github.com/wildduck2
49
50
  * @param name Unique tool identifier exposed to MCP clients via `tools/list`.
50
51
  * @returns Method decorator.
51
52
  */
@@ -78,6 +79,16 @@ export function McpRoute(input: string | McpRoute.IConfig): MethodDecorator {
78
79
  };
79
80
  }
80
81
 
82
+ /**
83
+ * Types and parameter decorator of {@link McpRoute}: the tool configuration and
84
+ * `McpRoute.Params`.
85
+ *
86
+ * @evidence contracts/common.md#principled-implementation Tool metadata retains its definition and default empty-object schema. Params records its argument position and shared checker; successful assert/validate data becomes the tool argument, while errors retain InvalidParams mapping and legacy error-only callbacks retain raw input. The adaptor reads the same metadata field names when registering tools.
87
+ * @evidence contracts/common.md#clear-and-simple-design Two decorators and one config type in one namespace, sharing one `emplace` helper for parameter metadata.
88
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts It uses the reflect metadata API and no NestJS internals; the input schema is filled by the generator, not hardcoded here.
89
+ * @evidence contracts/common.md#meaningful-documentation The comment documents the two call forms, the configuration fields, and the parameter decorator.
90
+ * @evidenceExclude contracts/portability.md#os-neutral-implementation Tool schemas and parameter metadata are protocol data held on controller methods, without native filesystem access.
91
+ */
81
92
  export namespace McpRoute {
82
93
  /**
83
94
  * Configuration object emitted by the nestia transformer at compile time.
@@ -104,7 +115,8 @@ export namespace McpRoute {
104
115
  * `tools/call` request against the TypeScript type `T` using typia. A failed
105
116
  * validation surfaces to the client as a JSON-RPC `-32602` (`InvalidParams`)
106
117
  * error with structured diagnostics, giving the LLM precise feedback to
107
- * self-correct.
118
+ * self-correct. Successful assert and validate data becomes the tool
119
+ * argument, so clone validators can supply a copy of the incoming arguments.
108
120
  *
109
121
  * MCP tools accept exactly one arguments object; applying this decorator more
110
122
  * than once on a single method is a compile-time error. The decorated type
@@ -15,7 +15,8 @@ import { validate_request_body } from "./internal/validate_request_body";
15
15
  * Plain body decorator.
16
16
  *
17
17
  * `PlainBody` is a decorator function getting full body text from the HTTP
18
- * request.
18
+ * request. The transformed assertion's successful string is the decorated
19
+ * argument.
19
20
  *
20
21
  * If you adjust the regular {@link Body} decorator function to the body
21
22
  * parameter, you can't get the full body text because the {@link Body} tries to
@@ -32,10 +33,18 @@ import { validate_request_body } from "./internal/validate_request_body";
32
33
  *
33
34
  * @author Jeongho Nam - https://github.com/samchon
34
35
  * @returns Parameter decorator
36
+ * @evidence contracts/common.md#principled-implementation The decorator reads text only for text/plain requests; an installed assertion resolves the argument value through the shared body checker, while no assertion retains raw text. Absent input is accepted when its assertion accepts undefined and otherwise continues through the media-type error path.
37
+ * @evidence contracts/common.md#clear-and-simple-design One parameter decorator shares body absence, media recognition, text reading and successful-value resolution with the other request decorators.
38
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts Text comes from the request parser or shared raw-body reader, not a fabricated value; no runtime controller or body identity is special-cased.
39
+ * @evidence contracts/common.md#meaningful-documentation The comment distinguishes full body text from JSON parsing and states that the transformed assertion supplies the argument.
40
+ * @evidenceExclude contracts/portability.md#os-neutral-implementation HTTP text bodies and decoded string values carry no native filesystem or subprocess boundary.
35
41
  */
36
42
  export function PlainBody(): ParameterDecorator;
37
43
 
38
- /** @internal */
44
+ /**
45
+ * Registers the transformed text assertion and binds its successful value. The
46
+ * public overload accepts no runtime assertion; the transform supplies it.
47
+ */
39
48
  export function PlainBody(
40
49
  assert?: (input: unknown) => string,
41
50
  ): ParameterDecorator {
@@ -52,17 +61,18 @@ export function PlainBody(
52
61
  const request: express.Request | FastifyRequest = context
53
62
  .switchToHttp()
54
63
  .getRequest();
55
- if (
56
- is_request_body_undefined(request) &&
57
- (checker ?? (() => null))(undefined as any) === null
58
- )
59
- return undefined;
60
- else if (!is_media_type(request.headers["content-type"], "text/plain"))
64
+ if (is_request_body_undefined(request)) {
65
+ if (checker === null) return undefined;
66
+ const result = checker.resolve(undefined);
67
+ if (result.success) return result.data;
68
+ }
69
+ if (!is_media_type(request.headers["content-type"], "text/plain"))
61
70
  throw new BadRequestException(`Request body type is not "text/plain".`);
62
71
  const value: string = await get_text_body(request);
63
72
  if (checker) {
64
- const error: Error | null = checker(value);
65
- if (error !== null) throw error;
73
+ const result = checker.resolve(value);
74
+ if (!result.success) throw result.error;
75
+ return result.data;
66
76
  }
67
77
  return value;
68
78
  })();
@@ -13,6 +13,11 @@ import { OpenApi } from "@typia/interface";
13
13
  * @author Jeongho Nam - https://github.com/samchon
14
14
  * @param closure Callback function which can customize the swagger data
15
15
  * @returns Method decorator
16
+ * @evidence contracts/common.md#principled-implementation Each use appends the closure to an array of metadata owned by the method, created on first use, so several customizers on one method run in order.
17
+ * @evidence contracts/common.md#clear-and-simple-design One decorator function with one metadata list per method.
18
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts It uses the reflect metadata API; the closure is the caller's.
19
+ * @evidence contracts/common.md#meaningful-documentation The comment documents that the closure receives the document, the operation, and lookup helpers.
20
+ * @evidenceExclude contracts/portability.md#os-neutral-implementation The callback and endpoint accessors edit an OpenAPI document; their path fields are HTTP routes rather than native file identities.
16
21
  */
17
22
  export function SwaggerCustomizer(
18
23
  closure: (props: SwaggerCustomizer.IProps) => unknown,
@@ -44,6 +49,16 @@ export function SwaggerCustomizer(
44
49
  return descriptor;
45
50
  };
46
51
  }
52
+ /**
53
+ * Types of {@link SwaggerCustomizer}: the properties the closure receives and
54
+ * the endpoint accessors.
55
+ *
56
+ * @evidence contracts/common.md#principled-implementation The types describe the document, the current operation, and lookups by function or by path and method, which is what a customization needs to edit the generated document.
57
+ * @evidence contracts/common.md#clear-and-simple-design Three types with no runtime members.
58
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts It contains types only.
59
+ * @evidence contracts/common.md#meaningful-documentation Each type and member documents its meaning.
60
+ * @evidenceExclude contracts/portability.md#os-neutral-implementation The callback and endpoint accessors edit an OpenAPI document; their path fields are HTTP routes rather than native file identities.
61
+ */
47
62
  export namespace SwaggerCustomizer {
48
63
  /**
49
64
  * Properties for the `SwaggerCustomizer` decorator.
@@ -9,30 +9,43 @@
9
9
  * The decorators only affect Swagger document generation. They do not change
10
10
  * runtime behavior, validation, or SDK function signatures.
11
11
  *
12
- * @author Jeongho Nam - https://github.com/samchon
13
- * @example
14
- * ```typescript
15
- * import core from "@nestia/core";
16
- * import { Controller } from "@nestjs/common";
17
- * import typia from "typia";
12
+ * Example:
13
+ *
14
+ * ```typescript
15
+ * import core from "@nestia/core";
16
+ * import { Controller } from "@nestjs/common";
17
+ * import typia from "typia";
18
18
  *
19
- * @Controller("bbs/articles")
20
- * export class BbsArticlesController {
21
- * // Single response example.
22
- * @core.SwaggerExample.Response(typia.random<IBbsArticle>())
23
- * @core.TypedRoute.Post()
24
- * public async create(
25
- * // Multiple named parameter examples plus a default one.
26
- * @core.SwaggerExample.Parameter(typia.random<IBbsArticle.ICreate>())
27
- * @core.SwaggerExample.Parameter("x", typia.random<IBbsArticle.ICreate>())
28
- * @core.SwaggerExample.Parameter("y", typia.random<IBbsArticle.ICreate>())
29
- * @core.TypedBody()
30
- * input: IBbsArticle.ICreate,
31
- * ): Promise<IBbsArticle> {
32
- * // ...
33
- * }
19
+ * @Controller("bbs/articles")
20
+ * export class BbsArticlesController {
21
+ * // Single response example.
22
+ * @core.SwaggerExample.Response(typia.random<IBbsArticle>())
23
+ * @core.TypedRoute.Post()
24
+ * public async create(
25
+ * // Multiple named parameter examples plus a default one.
26
+ * @core.SwaggerExample.Parameter(typia.random<IBbsArticle.ICreate>())
27
+ * @core.SwaggerExample.Parameter(
28
+ * "x",
29
+ * typia.random<IBbsArticle.ICreate>(),
30
+ * )
31
+ * @core.SwaggerExample.Parameter(
32
+ * "y",
33
+ * typia.random<IBbsArticle.ICreate>(),
34
+ * )
35
+ * @core.TypedBody()
36
+ * input: IBbsArticle.ICreate,
37
+ * ): Promise<IBbsArticle> {
38
+ * // ...
34
39
  * }
35
- * ```;
40
+ * }
41
+ * ```
42
+ *
43
+ * @author Jeongho Nam - https://github.com/samchon
44
+ * @evidence contracts/common.md#principled-implementation Examples are stored as metadata on the method or on the parameter position; a call with one argument sets the single example, and a call with a key and a value adds a named example, so both OpenAPI forms are expressible.
45
+ * @evidence contracts/common.md#clear-and-simple-design Two decorators over three private metadata helpers that find or create the record.
46
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts The examples are caller data, and nothing is generated here.
47
+ * @evidence contracts/common.md#meaningful-documentation The comment documents both decorators and the two call forms.
48
+ * @evidenceExclude contracts/portability.md#os-neutral-implementation Example metadata contains caller values and parameter indices without a native path or process boundary.
36
49
  */
37
50
  export namespace SwaggerExample {
38
51
  /**
@@ -51,6 +64,11 @@ export namespace SwaggerExample {
51
64
  * document.
52
65
  *
53
66
  * @template T Type of the example value (typically the route's response DTO).
67
+ * @evidence contracts/common.md#principled-implementation The value or the keyed value is recorded on the method's response example record, which the document generator reads.
68
+ * @evidence contracts/common.md#clear-and-simple-design One decorator with two overloads.
69
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts The value is stored as given.
70
+ * @evidence contracts/common.md#meaningful-documentation The comment documents the overloads with an example.
71
+ * @evidenceExclude contracts/portability.md#os-neutral-implementation Example metadata contains caller values and parameter indices without a native path or process boundary.
54
72
  */
55
73
  export function Response<T>(value: T): MethodDecorator;
56
74
  export function Response<T>(key: string, value: T): MethodDecorator;
@@ -81,6 +99,11 @@ export namespace SwaggerExample {
81
99
  * `@TypedParam()`, `@TypedQuery()`, etc.); decorator order does not matter.
82
100
  *
83
101
  * @template T Type of the example value (typically the parameter's DTO).
102
+ * @evidence contracts/common.md#principled-implementation The value or the keyed value is recorded on the record for that parameter index, so several parameters keep separate examples.
103
+ * @evidence contracts/common.md#clear-and-simple-design One decorator with two overloads.
104
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts The value is stored as given.
105
+ * @evidence contracts/common.md#meaningful-documentation The comment documents the overloads with an example.
106
+ * @evidenceExclude contracts/portability.md#os-neutral-implementation Example metadata contains caller values and parameter indices without a native path or process boundary.
84
107
  */
85
108
  export function Parameter<T>(value: T): ParameterDecorator;
86
109
  export function Parameter<T>(key: string, value: T): ParameterDecorator;
@@ -100,6 +123,12 @@ export namespace SwaggerExample {
100
123
  * Reflects the OpenAPI spec's two example fields: a single default `example`,
101
124
  * and/or a named map `examples`. `index` is used internally to associate
102
125
  * parameter examples with the right parameter position.
126
+ *
127
+ * @evidence contracts/common.md#principled-implementation The record holds the single example, the named examples, and the parameter index, which is everything the generator needs to attach examples.
128
+ * @evidence contracts/common.md#clear-and-simple-design A flat record whose members are all optional.
129
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts It is a type and adds no runtime behavior.
130
+ * @evidence contracts/common.md#meaningful-documentation The comment states the meaning of the members.
131
+ * @evidenceExclude contracts/portability.md#os-neutral-implementation Example metadata contains caller values and parameter indices without a native path or process boundary.
103
132
  */
104
133
  export interface IData<T> {
105
134
  examples?: Record<string, T>;
@@ -16,14 +16,21 @@ import { validate_request_body } from "./internal/validate_request_body";
16
16
  *
17
17
  * `TypedBody` is a decorator function getting `application/json` typed data
18
18
  * from request body. Also, it validates the request body data type through
19
- * [typia](https://github.com/samchon/typia) and the validation speed is maximum
20
- * 20,000x times faster than `class-validator`.
19
+ * [typia](https://github.com/samchon/typia) using the declared TypeScript
20
+ * type.
21
21
  *
22
22
  * For reference, when the request body data is not following the promised type
23
23
  * `T`, `BadRequestException` error (status code: 400) would be thrown.
24
+ * Successful assert and validate callbacks supply the decorated argument; clone
25
+ * validators can therefore return a copy without replacing the raw body.
24
26
  *
25
27
  * @author Jeongho Nam - https://github.com/samchon
26
28
  * @param validator Custom validator if required. Default is `typia.validate()`
29
+ * @evidence contracts/common.md#principled-implementation An absent body with no content type is accepted only when the validator accepts undefined; any other body must be application/json. The checker returns explicitly tagged successful data or the existing validation error, so cloned values reach the argument while raw request.body retains its identity and errors retain their response priority.
30
+ * @evidence contracts/common.md#clear-and-simple-design One parameter decorator composes shared media/absence checks and tagged resolution. The shared internal runner owns descriptor selection and error translation; PlainBody uses the same successful-value protocol for its optional transformed text assertion, preserving raw text when no assertion exists and preserving its absent-input/media error priority.
31
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts The validator is generated from the type by the transform; without it the decorator throws the configuration error unless the guard is turned off.
32
+ * @evidence contracts/common.md#meaningful-documentation The comment documents the decorator, the media type rule, and the validation modes.
33
+ * @evidenceExclude contracts/portability.md#os-neutral-implementation Parsed HTTP bodies and validation callbacks are independent of native filesystem and process representation.
27
34
  */
28
35
  export function TypedBody<T>(
29
36
  validator?: IRequestBodyValidator<T>,
@@ -36,9 +43,11 @@ export function TypedBody<T>(
36
43
  const request: express.Request | FastifyRequest = context
37
44
  .switchToHttp()
38
45
  .getRequest();
39
- if (is_request_body_undefined(request) && checker(undefined as T) === null)
40
- return undefined;
41
- else if (
46
+ if (is_request_body_undefined(request)) {
47
+ const result = checker.resolve(undefined);
48
+ if (result.success) return result.data;
49
+ }
50
+ if (
42
51
  is_media_type(request.headers["content-type"], "application/json") ===
43
52
  false
44
53
  )
@@ -46,8 +55,8 @@ export function TypedBody<T>(
46
55
  `Request body type is not "application/json".`,
47
56
  );
48
57
 
49
- const error: Error | null = checker(request.body);
50
- if (error !== null) throw error;
51
- return request.body;
58
+ const result = checker.resolve(request.body);
59
+ if (!result.success) throw result.error;
60
+ return result.data;
52
61
  })();
53
62
  }
@@ -117,6 +117,16 @@ export function TypedException<T>(...args: any[]): MethodDecorator {
117
117
  return descriptor;
118
118
  };
119
119
  }
120
+ /**
121
+ * Types of {@link TypedException}: the response properties a declaration
122
+ * carries, and its named examples.
123
+ *
124
+ * @evidence contracts/common.md#principled-implementation The decorator records each declared status, description, and example on the method's metadata list, so the document generator can add the responses; the overloads without a type argument return `never` so a missing type argument is a compile error.
125
+ * @evidence contracts/common.md#clear-and-simple-design One decorator whose overloads split the property form and the positional form.
126
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts It records declarations and never changes how the route responds.
127
+ * @evidence contracts/common.md#meaningful-documentation The comment documents the forms and that the status accepts range spellings.
128
+ * @evidenceExclude contracts/portability.md#os-neutral-implementation Response declarations contain HTTP status codes and examples, without native files or subprocesses.
129
+ */
120
130
  export namespace TypedException {
121
131
  /** Properties for the exception. */
122
132
  export interface IProps<T> {
@@ -5,7 +5,7 @@ import {
5
5
  PayloadTooLargeException,
6
6
  createParamDecorator,
7
7
  } from "@nestjs/common";
8
- import type { HttpArgumentsHost } from "@nestjs/common/interfaces";
8
+ import type { HttpArgumentsHost } from "@nestjs/common/interfaces/index.js";
9
9
  import type express from "express";
10
10
  import fs from "fs";
11
11
  import type ExpressMulter from "multer";
@@ -74,6 +74,11 @@ import { validate_request_form_data } from "./internal/validate_request_form_dat
74
74
  * ```
75
75
  *
76
76
  * @author Jeongho Nam - https://github.com/samchon
77
+ * @evidence contracts/common.md#principled-implementation The body must be multipart; multer parses it through the caller's factory into a `FormData` of fields and `File` objects, uploaded temp files are read and always removed afterwards, multer limits map to 413 or 400 responses, and the assembled form is checked by the transformed validator.
78
+ * @evidence contracts/common.md#clear-and-simple-design One decorator with the multipart decoding, the error mapping, and the file conversion as separate module-private functions, and the multer instance created once by a `Singleton`.
79
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts Errors are mapped by multer's documented codes and by exact busboy messages, and no file name is special-cased; a runtime without `File` is refused up front.
80
+ * @evidence contracts/common.md#meaningful-documentation The comment documents the factory, the memory and disk storage requirement, and the validation.
81
+ * @evidence contracts/portability.md#os-neutral-implementation Uploaded disk paths come from the storage engine and are consumed directly by Node fs readFile and rm; filename is File metadata rather than a reconstructed native path. Structural multer method signatures specify middleware rather than native path spelling.
77
82
  * @todo Change to ReadableStream through configuring storage engine of multer
78
83
  */
79
84
  export namespace TypedFormData {
@@ -134,12 +139,65 @@ export namespace TypedFormData {
134
139
  })();
135
140
  }
136
141
 
137
- /** Base type of the `multer` or `fastify-multer`. */
142
+ /**
143
+ * Base type of the `multer` or `fastify-multer`.
144
+ *
145
+ * @evidence contracts/common.md#principled-implementation The interface names the multer methods that identify a multer instance structurally, so an application can pass its own instance without this package depending on a multer type at runtime.
146
+ * @evidence contracts/common.md#clear-and-simple-design Five method members with no behavior.
147
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts It is a type and adds no runtime behavior.
148
+ * @evidence contracts/common.md#meaningful-documentation The comment states its purpose as the structural stand-in for multer.
149
+ * @evidence contracts/portability.md#os-neutral-implementation Uploaded disk paths come from the storage engine and are consumed directly by Node fs readFile and rm; filename is File metadata rather than a reconstructed native path. Structural multer method signatures specify middleware rather than native path spelling.
150
+ */
138
151
  export interface IMulterBase {
152
+ /**
153
+ * Middleware factory for a single file field.
154
+ *
155
+ * @evidence contracts/common.md#principled-implementation The member mirrors multer's single-file middleware factory.
156
+ * @evidence contracts/common.md#clear-and-simple-design One method signature.
157
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts It is a type and adds no runtime behavior.
158
+ * @evidence contracts/common.md#meaningful-documentation The member is named after the multer method it mirrors.
159
+ * @evidence contracts/portability.md#os-neutral-implementation Uploaded disk paths come from the storage engine and are consumed directly by Node fs readFile and rm; filename is File metadata rather than a reconstructed native path. Structural multer method signatures specify middleware rather than native path spelling.
160
+ */
139
161
  single(fieldName: string): any;
162
+ /**
163
+ * Middleware factory for an array of files under one field.
164
+ *
165
+ * @evidence contracts/common.md#principled-implementation The member mirrors multer's array-of-files middleware factory.
166
+ * @evidence contracts/common.md#clear-and-simple-design One method signature.
167
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts It is a type and adds no runtime behavior.
168
+ * @evidence contracts/common.md#meaningful-documentation The member is named after the multer method it mirrors.
169
+ * @evidence contracts/portability.md#os-neutral-implementation Uploaded disk paths come from the storage engine and are consumed directly by Node fs readFile and rm; filename is File metadata rather than a reconstructed native path. Structural multer method signatures specify middleware rather than native path spelling.
170
+ */
140
171
  array(fieldName: string, maxCount?: number): any;
172
+ /**
173
+ * Middleware factory for several named file fields.
174
+ *
175
+ * @evidence contracts/common.md#principled-implementation The member mirrors multer's named-fields middleware factory, which is the one the decorator uses when the transform lists the file fields.
176
+ * @evidence contracts/common.md#clear-and-simple-design One method signature.
177
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts It is a type and adds no runtime behavior.
178
+ * @evidence contracts/common.md#meaningful-documentation The member is named after the multer method it mirrors.
179
+ * @evidence contracts/portability.md#os-neutral-implementation Uploaded disk paths come from the storage engine and are consumed directly by Node fs readFile and rm; filename is File metadata rather than a reconstructed native path. Structural multer method signatures specify middleware rather than native path spelling.
180
+ */
141
181
  fields(fields: readonly object[]): any;
182
+ /**
183
+ * Middleware factory that accepts every file field.
184
+ *
185
+ * @evidence contracts/common.md#principled-implementation The member mirrors multer's accept-any-file middleware factory, which the decorator uses when no transform names the file fields.
186
+ * @evidence contracts/common.md#clear-and-simple-design One method signature.
187
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts It is a type and adds no runtime behavior.
188
+ * @evidence contracts/common.md#meaningful-documentation The member is named after the multer method it mirrors.
189
+ * @evidence contracts/portability.md#os-neutral-implementation Uploaded disk paths come from the storage engine and are consumed directly by Node fs readFile and rm; filename is File metadata rather than a reconstructed native path. Structural multer method signatures specify middleware rather than native path spelling.
190
+ */
142
191
  any(): any;
192
+ /**
193
+ * Middleware factory that accepts text fields only.
194
+ *
195
+ * @evidence contracts/common.md#principled-implementation The member mirrors multer's text-fields-only middleware factory.
196
+ * @evidence contracts/common.md#clear-and-simple-design One method signature.
197
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts It is a type and adds no runtime behavior.
198
+ * @evidence contracts/common.md#meaningful-documentation The member is named after the multer method it mirrors.
199
+ * @evidence contracts/portability.md#os-neutral-implementation Uploaded disk paths come from the storage engine and are consumed directly by Node fs readFile and rm; filename is File metadata rather than a reconstructed native path. Structural multer method signatures specify middleware rather than native path spelling.
200
+ */
143
201
  none(): any;
144
202
  }
145
203
  }
@@ -47,6 +47,11 @@ import { validate_request_headers } from "./internal/validate_request_headers";
47
47
  *
48
48
  * @author Jeongho Nam - https://github.com/samchon
49
49
  * @returns Parameter decorator
50
+ * @evidence contracts/common.md#principled-implementation The header record of the request is decoded by the transformed function into the typed object, whose failure is thrown as the response; header names arrive lower-cased from Node, which the generated decoder expects.
51
+ * @evidence contracts/common.md#clear-and-simple-design One parameter decorator built from the shared header validator runner.
52
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts The decoder is generated from the type by the transform; without it the request headers are passed through only when the configuration guard is off.
53
+ * @evidence contracts/common.md#meaningful-documentation The comment documents the decoding, the supported property types, and the validation modes.
54
+ * @evidenceExclude contracts/portability.md#os-neutral-implementation Header names and decoded values belong to the HTTP protocol and are not native filesystem identities.
50
55
  */
51
56
  export function TypedHeaders<T extends object>(
52
57
  validator?: IRequestHeadersValidator<T>,
@@ -30,7 +30,16 @@ import { NoTransformConfigurationError } from "./NoTransformConfigurationError";
30
30
  *
31
31
  * @author Jeongho Nam - https://github.com/samchon
32
32
  * @param name URL Parameter name
33
+ * @param assert Conversion and assertion supplied by the compile-time transform
34
+ * @param validate Emit an errors array on validation failure when true;
35
+ * otherwise expose the first failure as flat path, reason, expected and value
36
+ * fields.
33
37
  * @returns Parameter decorator
38
+ * @evidence contracts/common.md#principled-implementation The path parameter arrives as a string and is converted by the assertion function the transform generated for the declared type, so a value of the wrong type produces a 400 that names the parameter; the `validate` flag only changes the error body from the flat form to an `errors` array.
39
+ * @evidence contracts/common.md#clear-and-simple-design One decorator with one conversion function and one error-shaping branch.
40
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts The conversion is generated from the declared type; without the transform the raw string is returned only when the configuration guard is off.
41
+ * @evidence contracts/common.md#meaningful-documentation The comment documents the supported types and the two error shapes.
42
+ * @evidenceExclude contracts/portability.md#os-neutral-implementation The named path segment is an HTTP route parameter whose text is decoded by the generated validator; no native path is resolved.
34
43
  */
35
44
  export function TypedParam<T extends boolean | bigint | number | string | null>(
36
45
  name: string,
@@ -12,7 +12,7 @@ import {
12
12
  applyDecorators,
13
13
  createParamDecorator,
14
14
  } from "@nestjs/common";
15
- import { HttpArgumentsHost } from "@nestjs/common/interfaces";
15
+ import { HttpArgumentsHost } from "@nestjs/common/interfaces/index.js";
16
16
  import type express from "express";
17
17
  import type { FastifyRequest } from "fastify";
18
18
  import { catchError, map } from "rxjs/operators";
@@ -45,6 +45,11 @@ import { validate_request_query } from "./internal/validate_request_query";
45
45
  *
46
46
  * @author Jeongho Nam - https://github.com/samchon
47
47
  * @returns Parameter decorator
48
+ * @evidence contracts/common.md#principled-implementation The query string is read from the request URL after the first question mark, grouped by the transformed decoder into the typed object, and a failure is thrown as the 400 response; the decoder receives a `URLSearchParams`, so both Express and Fastify requests are handled by the same code.
49
+ * @evidence contracts/common.md#clear-and-simple-design One parameter decorator on top of the shared query validator runner.
50
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts The decoder is generated from the type by the transform; without it the grouped raw query is returned only when the configuration guard is off.
51
+ * @evidence contracts/common.md#meaningful-documentation The comment documents the supported property types and the validation modes.
52
+ * @evidenceExclude contracts/portability.md#os-neutral-implementation Query decoding and response encoding operate on URLSearchParams and HTTP route metadata rather than native filesystem paths.
48
53
  */
49
54
  export function TypedQuery<T extends object>(
50
55
  validator?: IRequestQueryValidator<T>,
@@ -64,6 +69,17 @@ export function TypedQuery<T extends object>(
64
69
  return output;
65
70
  })();
66
71
  }
72
+ /**
73
+ * Variants of {@link TypedQuery}: `TypedQuery.Body` reads an urlencoded body,
74
+ * and `TypedQuery.Get`, `Post`, `Put`, `Patch`, and `Delete` return the value
75
+ * as an urlencoded response.
76
+ *
77
+ * @evidence contracts/common.md#principled-implementation `Body` requires the `application/x-www-form-urlencoded` media type and decodes the parsed body, and the route decorators serialize the returned value through the querifier the transform chose and set the response content type.
78
+ * @evidence contracts/common.md#clear-and-simple-design One body decorator and one generator that creates the five route decorators, with a small adapter class for parsed bodies.
79
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts The route decorators copy typia's marker properties onto themselves exactly as `TypedRoute` does, which mutates only these exported functions.
80
+ * @evidence contracts/common.md#meaningful-documentation The comment documents the body decorator and the route decorators.
81
+ * @evidenceExclude contracts/portability.md#os-neutral-implementation Query decoding and response encoding operate on URLSearchParams and HTTP route metadata rather than native filesystem paths.
82
+ */
67
83
  export namespace TypedQuery {
68
84
  /**
69
85
  * Request body decorator.