@nestia/core 14.0.1 → 14.0.2

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 +12 -0
  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 +36 -1
  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 +5 -4
  116. package/src/adaptors/McpAdaptor.ts +86 -26
  117. package/src/adaptors/WebSocketAdaptor.ts +66 -14
  118. package/src/adaptors/internal/external_context.ts +37 -6
  119. package/src/decorators/DynamicModule.ts +12 -0
  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 +20 -11
  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 +59 -1
  132. package/src/decorators/TypedHeaders.ts +5 -0
  133. package/src/decorators/TypedParam.ts +9 -0
  134. package/src/decorators/TypedQuery.ts +16 -0
  135. package/src/decorators/TypedRoute.ts +25 -10
  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 +43 -13
@@ -1,18 +1,112 @@
1
+ import { IRequestBodyValidation } from "./IRequestBodyValidation";
2
+
3
+ /**
4
+ * The metadata `@WebSocketRoute()` writes on a method: its route paths.
5
+ *
6
+ * @evidence contracts/common.md#principled-implementation The record holds the paths, which the adapter turns into the route table; the parameter records are a separate metadata list.
7
+ * @evidence contracts/common.md#clear-and-simple-design A one-member record and a namespace of the parameter record types.
8
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts It is a type and adds no runtime behavior.
9
+ * @evidence contracts/common.md#meaningful-documentation The comment states which metadata the type describes.
10
+ * @evidenceExclude contracts/portability.md#os-neutral-implementation Handshake paths, parameter positions and callback signatures describe protocol metadata without native filesystem identities.
11
+ */
1
12
  export interface IWebSocketRouteReflect {
2
13
  paths: string[];
3
14
  }
4
15
  export namespace IWebSocketRouteReflect {
16
+ /**
17
+ * A parameter record: one of acceptor, driver, header, param, or query.
18
+ *
19
+ * @evidence contracts/common.md#principled-implementation The union is discriminated by the `category` literal, so the adapter can build the argument list with one comparison per parameter.
20
+ * @evidence contracts/common.md#clear-and-simple-design A union of five records.
21
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts It is a type and adds no runtime behavior.
22
+ * @evidence contracts/common.md#meaningful-documentation The comment lists the categories.
23
+ * @evidenceExclude contracts/portability.md#os-neutral-implementation Handshake paths, parameter positions and callback signatures describe protocol metadata without native filesystem identities.
24
+ */
5
25
  export type IArgument = IAcceptor | IDriver | IHeader | IParam | IQuery;
26
+ /**
27
+ * The record of an acceptor parameter, which receives the WebSocket acceptor.
28
+ *
29
+ * @evidence contracts/common.md#principled-implementation The record has only the category and the position, because the adapter supplies the acceptor itself.
30
+ * @evidence contracts/common.md#clear-and-simple-design It extends the shared base and adds nothing.
31
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts It is a type and adds no runtime behavior.
32
+ * @evidence contracts/common.md#meaningful-documentation The comment states which argument it stands for.
33
+ * @evidenceExclude contracts/portability.md#os-neutral-implementation Handshake paths, parameter positions and callback signatures describe protocol metadata without native filesystem identities.
34
+ */
6
35
  export interface IAcceptor extends IBase<"acceptor"> {}
36
+ /**
37
+ * The record of a driver parameter, which receives the remote driver of the
38
+ * connection.
39
+ *
40
+ * @evidence contracts/common.md#principled-implementation The record has only the category and the position, because the adapter supplies the driver from the acceptor.
41
+ * @evidence contracts/common.md#clear-and-simple-design It extends the shared base and adds nothing.
42
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts It is a type and adds no runtime behavior.
43
+ * @evidence contracts/common.md#meaningful-documentation The comment states which argument it stands for.
44
+ * @evidenceExclude contracts/portability.md#os-neutral-implementation Handshake paths, parameter positions and callback signatures describe protocol metadata without native filesystem identities.
45
+ */
7
46
  export interface IDriver extends IBase<"driver"> {}
47
+ /**
48
+ * The record of a header parameter: the position and the validator of the
49
+ * handshake header.
50
+ *
51
+ * @evidence contracts/common.md#principled-implementation The callable retains its error-or-null signature. An optional resolver carries successful callback data to the route argument; legacy callbacks without it preserve the raw header and any validation error rejects the handshake.
52
+ * @evidence contracts/common.md#clear-and-simple-design It extends the shared base with one function member.
53
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts It is a type and adds no runtime behavior.
54
+ * @evidence contracts/common.md#meaningful-documentation The comment states which argument it stands for and what the validator returns.
55
+ * @evidenceExclude contracts/portability.md#os-neutral-implementation Handshake paths, parameter positions and callback signatures describe protocol metadata without native filesystem identities.
56
+ */
8
57
  export interface IHeader extends IBase<"header"> {
9
- validate: (input?: any) => Error | null;
58
+ /**
59
+ * Validates the handshake header and returns an error, or `null` when it is
60
+ * valid. Factory-owned callbacks also resolve successful data for the
61
+ * decorated argument without replacing the acceptor's raw header.
62
+ */
63
+ validate: ((input?: any) => Error | null) &
64
+ Pick<IRequestBodyValidation<any>, "resolve">;
10
65
  }
66
+ /**
67
+ * The record of a path parameter: its position, the field name, and the
68
+ * conversion function.
69
+ *
70
+ * @evidence contracts/common.md#principled-implementation The field names the placeholder of the path, and the function converts the matched text to the declared type.
71
+ * @evidence contracts/common.md#clear-and-simple-design It extends the shared base with two members.
72
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts It is a type and adds no runtime behavior.
73
+ * @evidence contracts/common.md#meaningful-documentation The comment states which argument it stands for.
74
+ * @evidenceExclude contracts/portability.md#os-neutral-implementation Handshake paths, parameter positions and callback signatures describe protocol metadata without native filesystem identities.
75
+ */
11
76
  export interface IParam extends IBase<"param"> {
12
77
  field: string;
78
+ /**
79
+ * Converts the matched path text to the declared type, or throws.
80
+ *
81
+ * @evidence contracts/common.md#principled-implementation The function is the assertion the transform generated for the declared type, and a throw rejects the handshake.
82
+ * @evidence contracts/common.md#clear-and-simple-design One function member.
83
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts It is a type and adds no runtime behavior.
84
+ * @evidence contracts/common.md#meaningful-documentation The comment states the conversion and the failure.
85
+ * @evidenceExclude contracts/portability.md#os-neutral-implementation Handshake paths, parameter positions and callback signatures describe protocol metadata without native filesystem identities.
86
+ */
13
87
  assert: (value: string) => any;
14
88
  }
89
+ /**
90
+ * The record of a query parameter: the position and the validator of the
91
+ * query string.
92
+ *
93
+ * @evidence contracts/common.md#principled-implementation The validator receives the `URLSearchParams` after the first question mark of the path and returns the typed object or an error.
94
+ * @evidence contracts/common.md#clear-and-simple-design It extends the shared base with one function member.
95
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts It is a type and adds no runtime behavior.
96
+ * @evidence contracts/common.md#meaningful-documentation The comment states which argument it stands for.
97
+ * @evidenceExclude contracts/portability.md#os-neutral-implementation Handshake paths, parameter positions and callback signatures describe protocol metadata without native filesystem identities.
98
+ */
15
99
  export interface IQuery extends IBase<"query"> {
100
+ /**
101
+ * Validates the query of the handshake and returns the typed object, or an
102
+ * error.
103
+ *
104
+ * @evidence contracts/common.md#principled-implementation The function is the query decoder generated for the declared type, and an `Error` result rejects the handshake.
105
+ * @evidence contracts/common.md#clear-and-simple-design One function member.
106
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts It is a type and adds no runtime behavior.
107
+ * @evidence contracts/common.md#meaningful-documentation The comment states the result.
108
+ * @evidenceExclude contracts/portability.md#os-neutral-implementation Handshake paths, parameter positions and callback signatures describe protocol metadata without native filesystem identities.
109
+ */
16
110
  validate: (input: URLSearchParams) => any | Error;
17
111
  }
18
112
 
@@ -4,6 +4,7 @@ import typia, { IValidation, TypeGuardError } from "typia";
4
4
  import { IResponseBodyQuerifier } from "../../options/IResponseBodyQuerifier";
5
5
  import { NoTransformConfigurationError } from "../NoTransformConfigurationError";
6
6
  import type { TypedRoute } from "../TypedRoute";
7
+ import { split_route_arguments } from "./split_route_arguments";
7
8
 
8
9
  /** @internal */
9
10
  export const get_path_and_querify =
@@ -15,15 +16,8 @@ export const get_path_and_querify =
15
16
  string | string[] | undefined,
16
17
  (input: any, method: string, path: string) => URLSearchParams,
17
18
  ] => {
18
- const path: string | string[] | null | undefined =
19
- args[0] === undefined ||
20
- typeof args[0] === "string" ||
21
- Array.isArray(args[0])
22
- ? args[0]
23
- : null;
24
- const functor: IResponseBodyQuerifier<any> | undefined =
25
- path === null ? args[0] : args[1];
26
- return [path ?? undefined, take(logger)(method)(functor)];
19
+ const [path, functor] = split_route_arguments<any>(args);
20
+ return [path, take(logger)(method)(functor)];
27
21
  };
28
22
 
29
23
  /** @internal */
@@ -4,6 +4,7 @@ import typia, { IValidation, TypeGuardError } from "typia";
4
4
  import { IResponseBodyStringifier } from "../../options/IResponseBodyStringifier";
5
5
  import { NoTransformConfigurationError } from "../NoTransformConfigurationError";
6
6
  import { TypedRoute } from "../TypedRoute";
7
+ import { split_route_arguments } from "./split_route_arguments";
7
8
 
8
9
  /** @internal */
9
10
  export const get_path_and_stringify =
@@ -15,15 +16,8 @@ export const get_path_and_stringify =
15
16
  string | string[] | undefined,
16
17
  (input: any, _method: string, _path: string) => string,
17
18
  ] => {
18
- const path: string | string[] | null | undefined =
19
- args[0] === undefined ||
20
- typeof args[0] === "string" ||
21
- Array.isArray(args[0])
22
- ? args[0]
23
- : null;
24
- const functor: IResponseBodyStringifier<any> | undefined =
25
- path === null ? args[0] : args[1];
26
- return [path ?? undefined, take(logger)(method)(functor)];
19
+ const [path, functor] = split_route_arguments<any>(args);
20
+ return [path, take(logger)(method)(functor)];
27
21
  };
28
22
 
29
23
  /** @internal */
@@ -3,6 +3,20 @@ import { pathToFileURL } from "url";
3
3
  import { Creator } from "../../typings/Creator";
4
4
  import { SourceFinder } from "../../utils/SourceFinder";
5
5
 
6
+ /**
7
+ * Finds and imports the controllers under the given paths.
8
+ *
9
+ * A path, a list, or include and exclude lists are matched with globs, imported
10
+ * by file URL, and every export that carries Nest's `path` metadata is a
11
+ * controller. When no compiled `.js` controller is found and the process runs
12
+ * from source under `ttsx`, the TypeScript files are used instead.
13
+ *
14
+ * @evidence contracts/common.md#principled-implementation Files are selected by a filter chosen from the runtime (JavaScript modules, or TypeScript sources without declaration files), each is imported by `file:` URL through a native dynamic import that survives CommonJS downleveling, and a controller is recognized by Nest's own `path` metadata, so no naming convention is assumed.
15
+ * @evidence contracts/common.md#clear-and-simple-design One function with the fallback for the source-run case inside it and the filters and the mount loop as private helpers.
16
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts Discovery follows the metadata Nest itself writes; the `ttsx` fallback is decided by the runtime's own environment variable, not by a project name.
17
+ * @evidence contracts/common.md#meaningful-documentation The comment states the path forms, the recognition rule, and the source-run fallback.
18
+ * @evidence contracts/portability.md#os-neutral-implementation SourceFinder returns native absolute file paths and pathToFileURL converts them to escaped file URLs before dynamic import, including drive letters, spaces and URL punctuation. Extension matching selects source formats rather than defining filesystem identity.
19
+ */
6
20
  export const load_controllers = async (
7
21
  path: string | string[] | { include: string[]; exclude?: string[] },
8
22
  isTsNode?: boolean,
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Splits the arguments of a route decorator into its path and its functor.
3
+ *
4
+ * A route decorator is called as `Route()`, `Route(path)`, `Route(functor)`, or
5
+ * `Route(path, functor)`. The first argument is the path when it is absent, a
6
+ * string, or an array of strings, and the functor otherwise.
7
+ *
8
+ * @internal
9
+ */
10
+ export const split_route_arguments = <Functor>(
11
+ args: any[],
12
+ ): [string | string[] | undefined, Functor | null | undefined] => {
13
+ const path: string | string[] | undefined | null =
14
+ args[0] === undefined ||
15
+ typeof args[0] === "string" ||
16
+ Array.isArray(args[0])
17
+ ? args[0]
18
+ : null;
19
+ return [path ?? undefined, path === null ? args[0] : args[1]];
20
+ };
@@ -3,62 +3,115 @@ import typia, { IValidation, TypeGuardError } from "typia";
3
3
 
4
4
  import { IRequestBodyValidator } from "../../options/IRequestBodyValidator";
5
5
  import { NoTransformConfigurationError } from "../NoTransformConfigurationError";
6
+ import { IRequestBodyValidation } from "./IRequestBodyValidation";
6
7
 
7
- /** @internal */
8
+ /**
9
+ * Builds the shared body checker while preserving successful callback values.
10
+ *
11
+ * The legacy callable returns an error or null; its resolver returns the same
12
+ * validation decision and the callback's successful data without validating
13
+ * twice. Private assert/is/validate adapters preserve each descriptor's error
14
+ * details. Resolver input is untrusted. The descriptor's existing input:T
15
+ * signature is retained for compatibility; adapters cast at invocation and rely
16
+ * on its validation result before exposing successful T data.
17
+ *
18
+ * @internal
19
+ */
8
20
  export const validate_request_body =
9
21
  (method: string) =>
10
- <T>(validator?: IRequestBodyValidator<T>): ((input: T) => Error | null) => {
22
+ <T>(
23
+ validator?: IRequestBodyValidator<T>,
24
+ ): IRequestBodyValidation.IResolved<T> => {
11
25
  if (!validator) {
12
26
  NoTransformConfigurationError(method);
13
- return () => null;
27
+ return create<T>((input: unknown) => ({
28
+ success: true,
29
+ data: input as T,
30
+ }));
14
31
  } else if (validator.type === "assert") return assert(validator.assert);
15
32
  else if (validator.type === "is") return is(validator.is);
16
33
  else if (validator.type === "validate") return validate(validator.validate);
17
- return () =>
18
- new Error(`Error on nestia.core.${method}(): invalid typed validator.`);
34
+ return create<T>(() => ({
35
+ success: false,
36
+ error: new Error(
37
+ `Error on nestia.core.${method}(): invalid typed validator.`,
38
+ ),
39
+ }));
19
40
  };
20
41
 
42
+ /**
43
+ * Resolves factory checkers or the existing error-only metadata protocol once.
44
+ *
45
+ * @internal
46
+ */
47
+ export const resolve_request_body = <T>(
48
+ checker: IRequestBodyValidation<T>,
49
+ input: unknown,
50
+ ): IRequestBodyValidation.IResult<T> => {
51
+ if (checker.resolve) return checker.resolve(input);
52
+ const error = checker(input as T);
53
+ return error === null
54
+ ? { success: true, data: input as T }
55
+ : { success: false, error };
56
+ };
57
+
58
+ /** Installs both protocols on one newly created, session-independent checker. */
59
+ const create = <T>(
60
+ resolve: (input: unknown) => IRequestBodyValidation.IResult<T>,
61
+ ): IRequestBodyValidation.IResolved<T> =>
62
+ Object.assign(
63
+ (input: T): Error | null => {
64
+ const result = resolve(input);
65
+ return result.success ? null : result.error;
66
+ },
67
+ { resolve },
68
+ );
69
+
21
70
  /** @internal */
22
- const assert =
23
- <T>(closure: (data: T) => T) =>
24
- (input: T) => {
71
+ const assert = <T>(closure: (data: T) => T) =>
72
+ create<T>((input: unknown): IRequestBodyValidation.IResult<T> => {
25
73
  try {
26
- closure(input);
27
- return null;
74
+ return { success: true, data: closure(input as T) };
28
75
  } catch (exp) {
29
76
  if (typia.is<TypeGuardError>(exp)) {
30
- return new BadRequestException({
31
- path: exp.path,
32
- reason: exp.message,
33
- expected: exp.expected,
34
- value: exp.value,
35
- message: MESSAGE,
36
- });
77
+ return {
78
+ success: false,
79
+ error: new BadRequestException({
80
+ path: exp.path,
81
+ reason: exp.message,
82
+ expected: exp.expected,
83
+ value: exp.value,
84
+ message: MESSAGE,
85
+ }),
86
+ };
37
87
  }
38
88
  throw exp;
39
89
  }
40
- };
90
+ });
41
91
 
42
92
  /** @internal */
43
- const is =
44
- <T>(closure: (data: T) => boolean) =>
45
- (input: T) => {
46
- const success: boolean = closure(input);
47
- return success ? null : new BadRequestException(MESSAGE);
48
- };
93
+ const is = <T>(closure: (data: T) => boolean) =>
94
+ create<T>((input: unknown): IRequestBodyValidation.IResult<T> => {
95
+ const success: boolean = closure(input as T);
96
+ return success
97
+ ? { success: true, data: input as T }
98
+ : { success: false, error: new BadRequestException(MESSAGE) };
99
+ });
49
100
 
50
101
  /** @internal */
51
- const validate =
52
- <T>(closure: (data: T) => IValidation<T>) =>
53
- (input: T) => {
54
- const result: IValidation<T> = closure(input);
102
+ const validate = <T>(closure: (data: T) => IValidation<T>) =>
103
+ create<T>((input: unknown): IRequestBodyValidation.IResult<T> => {
104
+ const result: IValidation<T> = closure(input as T);
55
105
  return result.success
56
- ? null
57
- : new BadRequestException({
58
- errors: result.errors,
59
- message: MESSAGE,
60
- });
61
- };
106
+ ? { success: true, data: result.data }
107
+ : {
108
+ success: false,
109
+ error: new BadRequestException({
110
+ errors: result.errors,
111
+ message: MESSAGE,
112
+ }),
113
+ };
114
+ });
62
115
 
63
116
  /** @internal */
64
117
  const MESSAGE = "Request body data is not following the promised type.";
@@ -4,17 +4,88 @@ export type IRequestBodyValidator<T> =
4
4
  | IRequestBodyValidator.IAssert<T>
5
5
  | IRequestBodyValidator.IIs<T>
6
6
  | IRequestBodyValidator.IValidate<T>;
7
+ /**
8
+ * The request body validator that the transform passes to `TypedBody`,
9
+ * `EncryptedBody`, `PlainBody`, `WebSocketRoute.Header`, and
10
+ * `McpRoute.Params`.
11
+ *
12
+ * The literal `type` field selects which typia function generated the
13
+ * validator: `assert`, `is`, or `validate`. `validate_request_body` turns a
14
+ * failure of any variant into a 400 response. Assert and validate success
15
+ * supply their returned data to the decorated argument; is success keeps the
16
+ * input.
17
+ *
18
+ * @evidence contracts/common.md#principled-implementation The union is discriminated by the literal `type`, so the runtime selects the assert, is, or validate path with one comparison and the compiler checks that each variant carries the function its tag names.
19
+ * @evidence contracts/common.md#clear-and-simple-design Three variants, one per typia function family, with no shared base because each function has a different shape.
20
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts It is a type and adds no runtime behavior; the runtime rejects an unknown `type` with an error instead of accepting it.
21
+ * @evidence contracts/common.md#meaningful-documentation The comment names the decorators that receive the validator, the meaning of the discriminant, and the response a failure becomes.
22
+ * @evidenceExclude contracts/portability.md#os-neutral-implementation The union and callback members describe validation of parsed body values without native platform resources.
23
+ */
7
24
  export namespace IRequestBodyValidator {
25
+ /**
26
+ * Validator generated from `typia.assert`.
27
+ *
28
+ * @evidence contracts/common.md#principled-implementation The variant tags a function returning validated data, which may be a clone, or throwing TypeGuardError. The shared runner retains successful data and converts the guard error to BadRequestException carrying the first failure's path, reason, expected type and value.
29
+ * @evidence contracts/common.md#clear-and-simple-design A two-member record, the tag and the function.
30
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts It is a type and adds no runtime behavior.
31
+ * @evidence contracts/common.md#meaningful-documentation The comment names the typia function the variant comes from; the failure response is stated on the union.
32
+ * @evidenceExclude contracts/portability.md#os-neutral-implementation The union and callback members describe validation of parsed body values without native platform resources.
33
+ */
8
34
  export interface IAssert<T> {
9
35
  type: "assert";
36
+ /**
37
+ * The typia assertion function generated for the requested type.
38
+ *
39
+ * @evidence contracts/common.md#principled-implementation The generated assertion returns the validated value, including a separate clone for clone modes, or throws TypeGuardError. Successful data becomes the decorated argument without requiring identity with the parsed input.
40
+ * @evidence contracts/common.md#clear-and-simple-design One function member with the input the decorator has.
41
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts The function is generated from the type, and the runtime never edits its result.
42
+ * @evidence contracts/common.md#meaningful-documentation The comment states that the function is generated for the requested type; its input is in the signature.
43
+ * @evidenceExclude contracts/portability.md#os-neutral-implementation The union and callback members describe validation of parsed body values without native platform resources.
44
+ */
10
45
  assert: (input: T) => T;
11
46
  }
47
+ /**
48
+ * Validator generated from `typia.is`.
49
+ *
50
+ * @evidence contracts/common.md#principled-implementation The variant tags a function of the parsed value that returns a boolean, because the value is already parsed and is returned as it is; a failing result becomes a `BadRequestException` with only the fixed message, because `typia.is` records no failure detail.
51
+ * @evidence contracts/common.md#clear-and-simple-design A two-member record, the tag and the function.
52
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts It is a type and adds no runtime behavior.
53
+ * @evidence contracts/common.md#meaningful-documentation The comment names the typia function the variant comes from.
54
+ * @evidenceExclude contracts/portability.md#os-neutral-implementation The union and callback members describe validation of parsed body values without native platform resources.
55
+ */
12
56
  export interface IIs<T> {
13
57
  type: "is";
58
+ /**
59
+ * The typia check function generated for the requested type.
60
+ *
61
+ * @evidence contracts/common.md#principled-implementation The transform generates the function for the type argument of the decorator, taking the parsed value and returning a boolean, because the value is already parsed and is returned as it is.
62
+ * @evidence contracts/common.md#clear-and-simple-design One function member with the input the decorator has.
63
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts The function is generated from the type, and the runtime never edits its result.
64
+ * @evidence contracts/common.md#meaningful-documentation The comment states that the function is generated for the requested type; its result is in the signature.
65
+ * @evidenceExclude contracts/portability.md#os-neutral-implementation The union and callback members describe validation of parsed body values without native platform resources.
66
+ */
14
67
  is: (input: T) => boolean;
15
68
  }
69
+ /**
70
+ * Validator generated from `typia.validate`.
71
+ *
72
+ * @evidence contracts/common.md#principled-implementation The callback returns IValidation; successful result.data becomes the decorated argument, including a clone, while failure becomes BadRequestException carrying every validation error.
73
+ * @evidence contracts/common.md#clear-and-simple-design A two-member record, the tag and the function.
74
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts It is a type and adds no runtime behavior.
75
+ * @evidence contracts/common.md#meaningful-documentation The comment names the typia function the variant comes from.
76
+ * @evidenceExclude contracts/portability.md#os-neutral-implementation The union and callback members describe validation of parsed body values without native platform resources.
77
+ */
16
78
  export interface IValidate<T> {
17
79
  type: "validate";
80
+ /**
81
+ * The typia validation function generated for the requested type.
82
+ *
83
+ * @evidence contracts/common.md#principled-implementation The transform generates the function for the type argument of the decorator, taking the parsed value and returning the validation result with every error.
84
+ * @evidence contracts/common.md#clear-and-simple-design One function member with the input the decorator has.
85
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts The function is generated from the type, and the runtime never edits its result.
86
+ * @evidence contracts/common.md#meaningful-documentation The comment states that the function is generated for the requested type; its result is in the signature.
87
+ * @evidenceExclude contracts/portability.md#os-neutral-implementation The union and callback members describe validation of parsed body values without native platform resources.
88
+ */
18
89
  validate: (input: T) => IValidation<T>;
19
90
  }
20
91
  }
@@ -7,19 +7,99 @@ export interface IRequestFormDataProps<T> {
7
7
  | IRequestFormDataProps.IIs<T>
8
8
  | IRequestFormDataProps.IValidate<T>;
9
9
  }
10
+ /**
11
+ * Properties that the transform passes to `TypedFormData.Body`: the file fields
12
+ * and the validator.
13
+ *
14
+ * `files` names the file fields of the type with their limits, and `validator`
15
+ * validates the `FormData` made from the fields and the uploaded files.
16
+ *
17
+ * @evidence contracts/common.md#principled-implementation The record carries what the multipart handling needs: which fields are files, with how many each may hold, and how to validate the assembled form.
18
+ * @evidence contracts/common.md#clear-and-simple-design A two-member record whose nested types describe the variants and the file entries.
19
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts It is a type and adds no runtime behavior.
20
+ * @evidence contracts/common.md#meaningful-documentation The comment names the two members and the decorator that receives them.
21
+ * @evidenceExclude contracts/portability.md#os-neutral-implementation FormData validators and file-field names describe multipart protocol data; no member is a native storage path or handle.
22
+ */
10
23
  export namespace IRequestFormDataProps {
24
+ /**
25
+ * Validator generated from `typia.assert`.
26
+ *
27
+ * @evidence contracts/common.md#principled-implementation The variant tags a function of `FormData` that returns the decoded object or throws the `TypeGuardError` of typia, which becomes a `BadRequestException` with the path, reason, expected type, and value.
28
+ * @evidence contracts/common.md#clear-and-simple-design A two-member record, the tag and the function.
29
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts It is a type and adds no runtime behavior.
30
+ * @evidence contracts/common.md#meaningful-documentation The comment names the typia function the variant comes from.
31
+ * @evidenceExclude contracts/portability.md#os-neutral-implementation FormData validators and file-field names describe multipart protocol data; no member is a native storage path or handle.
32
+ */
11
33
  export interface IAssert<T> {
12
34
  type: "assert";
35
+ /**
36
+ * The typia assertion function generated for the requested type.
37
+ *
38
+ * @evidence contracts/common.md#principled-implementation The transform generates the function for the type argument, taking the form and returning the decoded object or throwing.
39
+ * @evidence contracts/common.md#clear-and-simple-design One function member.
40
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts The function is generated from the type, and the runtime never edits its result.
41
+ * @evidence contracts/common.md#meaningful-documentation The comment states that the function is generated for the requested type.
42
+ * @evidenceExclude contracts/portability.md#os-neutral-implementation FormData validators and file-field names describe multipart protocol data; no member is a native storage path or handle.
43
+ */
13
44
  assert: (input: FormData) => T;
14
45
  }
46
+ /**
47
+ * Validator generated from `typia.is`.
48
+ *
49
+ * @evidence contracts/common.md#principled-implementation The variant tags a function of `FormData` that returns the decoded object or `null`; `null` becomes a `BadRequestException` with only the fixed message.
50
+ * @evidence contracts/common.md#clear-and-simple-design A two-member record, the tag and the function.
51
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts It is a type and adds no runtime behavior.
52
+ * @evidence contracts/common.md#meaningful-documentation The comment names the typia function the variant comes from.
53
+ * @evidenceExclude contracts/portability.md#os-neutral-implementation FormData validators and file-field names describe multipart protocol data; no member is a native storage path or handle.
54
+ */
15
55
  export interface IIs<T> {
16
56
  type: "is";
57
+ /**
58
+ * The typia check function generated for the requested type.
59
+ *
60
+ * @evidence contracts/common.md#principled-implementation The transform generates the function for the type argument, taking the form and returning the decoded object or `null`.
61
+ * @evidence contracts/common.md#clear-and-simple-design One function member.
62
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts The function is generated from the type, and the runtime never edits its result.
63
+ * @evidence contracts/common.md#meaningful-documentation The comment states that the function is generated for the requested type.
64
+ * @evidenceExclude contracts/portability.md#os-neutral-implementation FormData validators and file-field names describe multipart protocol data; no member is a native storage path or handle.
65
+ */
17
66
  is: (input: FormData) => T | null;
18
67
  }
68
+ /**
69
+ * Validator generated from `typia.validate`.
70
+ *
71
+ * @evidence contracts/common.md#principled-implementation The variant tags a function of `FormData` that returns the `IValidation` of typia; a failure becomes a `BadRequestException` carrying every error.
72
+ * @evidence contracts/common.md#clear-and-simple-design A two-member record, the tag and the function.
73
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts It is a type and adds no runtime behavior.
74
+ * @evidence contracts/common.md#meaningful-documentation The comment names the typia function the variant comes from.
75
+ * @evidenceExclude contracts/portability.md#os-neutral-implementation FormData validators and file-field names describe multipart protocol data; no member is a native storage path or handle.
76
+ */
19
77
  export interface IValidate<T> {
20
78
  type: "validate";
79
+ /**
80
+ * The typia validation function generated for the requested type.
81
+ *
82
+ * @evidence contracts/common.md#principled-implementation The transform generates the function for the type argument, taking the form and returning the validation result.
83
+ * @evidence contracts/common.md#clear-and-simple-design One function member.
84
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts The function is generated from the type, and the runtime never edits its result.
85
+ * @evidence contracts/common.md#meaningful-documentation The comment states that the function is generated for the requested type.
86
+ * @evidenceExclude contracts/portability.md#os-neutral-implementation FormData validators and file-field names describe multipart protocol data; no member is a native storage path or handle.
87
+ */
21
88
  validate: (input: FormData) => IValidation<T>;
22
89
  }
90
+ /**
91
+ * A file field of a multipart form: its name and the number of files it may
92
+ * hold, or `null` for no limit.
93
+ *
94
+ * A limit of 1 makes the multer field accept one file; any other value leaves
95
+ * the field unlimited.
96
+ *
97
+ * @evidence contracts/common.md#principled-implementation A limit of 1 makes the multer field accept one file and any other value leaves the field unlimited, which is how the runtime configures `multer.fields`.
98
+ * @evidence contracts/common.md#clear-and-simple-design A two-field record with no behavior.
99
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts The values come from the type through the transform, not from a fixture.
100
+ * @evidence contracts/common.md#meaningful-documentation The comment states the meaning of the name and of the limit.
101
+ * @evidenceExclude contracts/portability.md#os-neutral-implementation FormData validators and file-field names describe multipart protocol data; no member is a native storage path or handle.
102
+ */
23
103
  export interface IFile {
24
104
  name: string;
25
105
  limit: number | null;
@@ -4,17 +4,84 @@ export type IRequestHeadersValidator<T> =
4
4
  | IRequestHeadersValidator.IAssert<T>
5
5
  | IRequestHeadersValidator.IIs<T>
6
6
  | IRequestHeadersValidator.IValidate<T>;
7
+ /**
8
+ * The request headers validator that the transform passes to `TypedHeaders`.
9
+ *
10
+ * The literal `type` field selects which typia function generated the
11
+ * validator: `assert`, `is`, or `validate`. `validate_request_headers` turns a
12
+ * failure of any variant into a 400 response.
13
+ *
14
+ * @evidence contracts/common.md#principled-implementation The union is discriminated by the literal `type`, so the runtime selects the assert, is, or validate path with one comparison and the compiler checks that each variant carries the function its tag names.
15
+ * @evidence contracts/common.md#clear-and-simple-design Three variants, one per typia function family, with no shared base because each function has a different shape.
16
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts It is a type and adds no runtime behavior; the runtime rejects an unknown `type` with an error instead of accepting it.
17
+ * @evidence contracts/common.md#meaningful-documentation The comment names the decorators that receive the validator, the meaning of the discriminant, and the response a failure becomes.
18
+ * @evidenceExclude contracts/portability.md#os-neutral-implementation The validator consumes HTTP header records and returns decoded values independently of native filesystem or process spelling.
19
+ */
7
20
  export namespace IRequestHeadersValidator {
21
+ /**
22
+ * Validator generated from `typia.assert`.
23
+ *
24
+ * @evidence contracts/common.md#principled-implementation The variant tags a function of the header record of the request, whose values are strings, string arrays, or undefined that returns the decoded object or throws the `TypeGuardError` of typia; `validate_request_headers` catches the error and converts it to a `BadRequestException` carrying the path, reason, expected type, and value of the first failure.
25
+ * @evidence contracts/common.md#clear-and-simple-design A two-member record, the tag and the function.
26
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts It is a type and adds no runtime behavior.
27
+ * @evidence contracts/common.md#meaningful-documentation The comment names the typia function the variant comes from; the failure response is stated on the union.
28
+ * @evidenceExclude contracts/portability.md#os-neutral-implementation The validator consumes HTTP header records and returns decoded values independently of native filesystem or process spelling.
29
+ */
8
30
  export interface IAssert<T> {
9
31
  type: "assert";
32
+ /**
33
+ * The typia assertion function generated for the requested type.
34
+ *
35
+ * @evidence contracts/common.md#principled-implementation The transform generates the function for the type argument of the decorator, taking the header record of the request, whose values are strings, string arrays, or undefined and it returns the decoded object or throws the `TypeGuardError` of typia.
36
+ * @evidence contracts/common.md#clear-and-simple-design One function member with the input the decorator has.
37
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts The function is generated from the type, and the runtime never edits its result.
38
+ * @evidence contracts/common.md#meaningful-documentation The comment states that the function is generated for the requested type; its input is in the signature.
39
+ * @evidenceExclude contracts/portability.md#os-neutral-implementation The validator consumes HTTP header records and returns decoded values independently of native filesystem or process spelling.
40
+ */
10
41
  assert: (input: Record<string, string | string[] | undefined>) => T;
11
42
  }
43
+ /**
44
+ * Validator generated from `typia.is`.
45
+ *
46
+ * @evidence contracts/common.md#principled-implementation The variant tags a function of the header record of the request, whose values are strings, string arrays, or undefined that returns the decoded object or `null`; a failing result becomes a `BadRequestException` with only the fixed message, because `typia.is` records no failure detail.
47
+ * @evidence contracts/common.md#clear-and-simple-design A two-member record, the tag and the function.
48
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts It is a type and adds no runtime behavior.
49
+ * @evidence contracts/common.md#meaningful-documentation The comment names the typia function the variant comes from.
50
+ * @evidenceExclude contracts/portability.md#os-neutral-implementation The validator consumes HTTP header records and returns decoded values independently of native filesystem or process spelling.
51
+ */
12
52
  export interface IIs<T> {
13
53
  type: "is";
54
+ /**
55
+ * The typia check function generated for the requested type.
56
+ *
57
+ * @evidence contracts/common.md#principled-implementation The transform generates the function for the type argument of the decorator, taking the header record of the request, whose values are strings, string arrays, or undefined and returning the decoded object or `null`.
58
+ * @evidence contracts/common.md#clear-and-simple-design One function member with the input the decorator has.
59
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts The function is generated from the type, and the runtime never edits its result.
60
+ * @evidence contracts/common.md#meaningful-documentation The comment states that the function is generated for the requested type; its result is in the signature.
61
+ * @evidenceExclude contracts/portability.md#os-neutral-implementation The validator consumes HTTP header records and returns decoded values independently of native filesystem or process spelling.
62
+ */
14
63
  is: (input: Record<string, string | string[] | undefined>) => T | null;
15
64
  }
65
+ /**
66
+ * Validator generated from `typia.validate`.
67
+ *
68
+ * @evidence contracts/common.md#principled-implementation The variant tags a function of the header record of the request, whose values are strings, string arrays, or undefined that returns the `IValidation` of typia; a failed result becomes a `BadRequestException` carrying every error of the validation.
69
+ * @evidence contracts/common.md#clear-and-simple-design A two-member record, the tag and the function.
70
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts It is a type and adds no runtime behavior.
71
+ * @evidence contracts/common.md#meaningful-documentation The comment names the typia function the variant comes from.
72
+ * @evidenceExclude contracts/portability.md#os-neutral-implementation The validator consumes HTTP header records and returns decoded values independently of native filesystem or process spelling.
73
+ */
16
74
  export interface IValidate<T> {
17
75
  type: "validate";
76
+ /**
77
+ * The typia validation function generated for the requested type.
78
+ *
79
+ * @evidence contracts/common.md#principled-implementation The transform generates the function for the type argument of the decorator, taking the header record of the request, whose values are strings, string arrays, or undefined and returning the validation result with every error.
80
+ * @evidence contracts/common.md#clear-and-simple-design One function member with the input the decorator has.
81
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts The function is generated from the type, and the runtime never edits its result.
82
+ * @evidence contracts/common.md#meaningful-documentation The comment states that the function is generated for the requested type; its result is in the signature.
83
+ * @evidenceExclude contracts/portability.md#os-neutral-implementation The validator consumes HTTP header records and returns decoded values independently of native filesystem or process spelling.
84
+ */
18
85
  validate: (
19
86
  input: Record<string, string | string[] | undefined>,
20
87
  ) => IValidation<T>;