@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.
- package/lib/adaptors/McpAdaptor.d.ts +24 -3
- package/lib/adaptors/McpAdaptor.js +72 -34
- package/lib/adaptors/McpAdaptor.js.map +1 -1
- package/lib/adaptors/WebSocketAdaptor.d.ts +37 -0
- package/lib/adaptors/WebSocketAdaptor.js +60 -16
- package/lib/adaptors/WebSocketAdaptor.js.map +1 -1
- package/lib/adaptors/internal/external_context.js +18 -5
- package/lib/adaptors/internal/external_context.js.map +1 -1
- package/lib/decorators/DynamicModule.d.ts +13 -1
- package/lib/decorators/DynamicModule.js +12 -0
- package/lib/decorators/DynamicModule.js.map +1 -1
- package/lib/decorators/EncryptedBody.d.ts +14 -6
- package/lib/decorators/EncryptedBody.js +37 -14
- package/lib/decorators/EncryptedBody.js.map +1 -1
- package/lib/decorators/EncryptedController.d.ts +6 -1
- package/lib/decorators/EncryptedController.js +6 -1
- package/lib/decorators/EncryptedController.js.map +1 -1
- package/lib/decorators/EncryptedModule.d.ts +18 -3
- package/lib/decorators/EncryptedModule.js +18 -3
- package/lib/decorators/EncryptedModule.js.map +1 -1
- package/lib/decorators/EncryptedRoute.d.ts +20 -11
- package/lib/decorators/EncryptedRoute.js +20 -11
- package/lib/decorators/EncryptedRoute.js.map +1 -1
- package/lib/decorators/HumanRoute.d.ts +5 -0
- package/lib/decorators/HumanRoute.js +5 -0
- package/lib/decorators/HumanRoute.js.map +1 -1
- package/lib/decorators/McpRoute.d.ts +31 -19
- package/lib/decorators/McpRoute.js +12 -1
- package/lib/decorators/McpRoute.js.map +1 -1
- package/lib/decorators/PlainBody.d.ts +7 -1
- package/lib/decorators/PlainBody.js +16 -8
- package/lib/decorators/PlainBody.js.map +1 -1
- package/lib/decorators/SwaggerCustomizer.d.ts +15 -0
- package/lib/decorators/SwaggerCustomizer.js +5 -0
- package/lib/decorators/SwaggerCustomizer.js.map +1 -1
- package/lib/decorators/SwaggerExample.d.ts +51 -22
- package/lib/decorators/SwaggerExample.js +35 -22
- package/lib/decorators/SwaggerExample.js.map +1 -1
- package/lib/decorators/TypedBody.d.ts +9 -2
- package/lib/decorators/TypedBody.js +19 -9
- package/lib/decorators/TypedBody.js.map +1 -1
- package/lib/decorators/TypedException.d.ts +10 -0
- package/lib/decorators/TypedFormData.d.ts +59 -1
- package/lib/decorators/TypedFormData.js +5 -0
- package/lib/decorators/TypedFormData.js.map +1 -1
- package/lib/decorators/TypedHeaders.d.ts +5 -0
- package/lib/decorators/TypedHeaders.js +5 -0
- package/lib/decorators/TypedHeaders.js.map +1 -1
- package/lib/decorators/TypedParam.d.ts +9 -0
- package/lib/decorators/TypedParam.js +9 -0
- package/lib/decorators/TypedParam.js.map +1 -1
- package/lib/decorators/TypedQuery.d.ts +16 -0
- package/lib/decorators/TypedQuery.js +16 -0
- package/lib/decorators/TypedQuery.js.map +1 -1
- package/lib/decorators/TypedRoute.d.ts +25 -10
- package/lib/decorators/TypedRoute.js +19 -10
- package/lib/decorators/TypedRoute.js.map +1 -1
- package/lib/decorators/WebSocketRoute.d.ts +18 -1
- package/lib/decorators/WebSocketRoute.js +18 -1
- package/lib/decorators/WebSocketRoute.js.map +1 -1
- package/lib/decorators/doNotThrowTransformError.d.ts +14 -0
- package/lib/decorators/doNotThrowTransformError.js +14 -0
- package/lib/decorators/doNotThrowTransformError.js.map +1 -1
- package/lib/decorators/internal/IRequestBodyValidation.d.ts +66 -0
- package/lib/decorators/internal/IRequestBodyValidation.js +3 -0
- package/lib/decorators/internal/IRequestBodyValidation.js.map +1 -0
- package/lib/decorators/internal/IWebSocketRouteReflect.d.ts +93 -1
- package/lib/decorators/internal/get_path_and_querify.js +3 -7
- package/lib/decorators/internal/get_path_and_querify.js.map +1 -1
- package/lib/decorators/internal/get_path_and_stringify.js +3 -7
- package/lib/decorators/internal/get_path_and_stringify.js.map +1 -1
- package/lib/decorators/internal/load_controller.d.ts +14 -0
- package/lib/decorators/internal/load_controller.js +14 -0
- package/lib/decorators/internal/load_controller.js.map +1 -1
- package/lib/decorators/internal/split_route_arguments.d.ts +1 -0
- package/lib/decorators/internal/split_route_arguments.js +22 -0
- package/lib/decorators/internal/split_route_arguments.js.map +1 -0
- package/lib/decorators/internal/validate_request_body.js +68 -25
- package/lib/decorators/internal/validate_request_body.js.map +1 -1
- package/lib/options/IRequestBodyValidator.d.ts +71 -0
- package/lib/options/IRequestFormDataProps.d.ts +80 -0
- package/lib/options/IRequestHeadersValidator.d.ts +67 -0
- package/lib/options/IRequestQueryValidator.d.ts +68 -0
- package/lib/options/IResponseBodyQuerifier.d.ts +120 -0
- package/lib/options/IResponseBodyStringifier.d.ts +107 -0
- package/lib/typings/Creator.d.ts +10 -0
- package/lib/utils/ArrayUtil.d.ts +21 -0
- package/lib/utils/ArrayUtil.js +22 -1
- package/lib/utils/ArrayUtil.js.map +1 -1
- package/lib/utils/ExceptionManager.d.ts +40 -0
- package/lib/utils/ExceptionManager.js +34 -0
- package/lib/utils/ExceptionManager.js.map +1 -1
- package/lib/utils/SourceFinder.d.ts +22 -0
- package/lib/utils/SourceFinder.js +34 -7
- package/lib/utils/SourceFinder.js.map +1 -1
- package/lib/utils/VersioningStrategy.d.ts +37 -2
- package/lib/utils/VersioningStrategy.js +30 -9
- package/lib/utils/VersioningStrategy.js.map +1 -1
- package/native/go.mod +1 -1
- package/native/go.sum +2 -2
- package/native/plugin/plan.go +68 -2
- package/native/transform/ast.go +19 -1
- package/native/transform/build.go +51 -57
- package/native/transform/buildoutput/output.go +147 -0
- package/native/transform/contributor.go +9 -0
- package/native/transform/core_querify.go +37 -3
- package/native/transform/core_transform.go +105 -98
- package/native/transform/core_websocket.go +21 -5
- package/native/transform/node_transform.go +11 -8
- package/native/transform/package.go +55 -0
- package/native/transform/printer.go +1 -3
- package/native/transform/run.go +18 -0
- package/native/transform/schemaprojection/project.go +213 -0
- package/native/transform/transform.go +21 -0
- package/package.json +9 -7
- package/src/adaptors/McpAdaptor.ts +86 -26
- package/src/adaptors/WebSocketAdaptor.ts +70 -15
- package/src/adaptors/internal/external_context.ts +43 -6
- package/src/decorators/DynamicModule.ts +13 -1
- package/src/decorators/EncryptedBody.ts +37 -13
- package/src/decorators/EncryptedController.ts +6 -1
- package/src/decorators/EncryptedModule.ts +18 -3
- package/src/decorators/EncryptedRoute.ts +21 -12
- package/src/decorators/HumanRoute.ts +5 -0
- package/src/decorators/McpRoute.ts +31 -19
- package/src/decorators/PlainBody.ts +20 -10
- package/src/decorators/SwaggerCustomizer.ts +15 -0
- package/src/decorators/SwaggerExample.ts +51 -22
- package/src/decorators/TypedBody.ts +17 -8
- package/src/decorators/TypedException.ts +10 -0
- package/src/decorators/TypedFormData.ts +60 -2
- package/src/decorators/TypedHeaders.ts +5 -0
- package/src/decorators/TypedParam.ts +9 -0
- package/src/decorators/TypedQuery.ts +17 -1
- package/src/decorators/TypedRoute.ts +26 -11
- package/src/decorators/WebSocketRoute.ts +18 -1
- package/src/decorators/doNotThrowTransformError.ts +14 -0
- package/src/decorators/internal/IMcpRouteReflect.ts +7 -1
- package/src/decorators/internal/IRequestBodyValidation.ts +65 -0
- package/src/decorators/internal/IWebSocketRouteReflect.ts +95 -1
- package/src/decorators/internal/get_path_and_querify.ts +3 -9
- package/src/decorators/internal/get_path_and_stringify.ts +3 -9
- package/src/decorators/internal/load_controller.ts +14 -0
- package/src/decorators/internal/split_route_arguments.ts +20 -0
- package/src/decorators/internal/validate_request_body.ts +87 -34
- package/src/options/IRequestBodyValidator.ts +71 -0
- package/src/options/IRequestFormDataProps.ts +80 -0
- package/src/options/IRequestHeadersValidator.ts +67 -0
- package/src/options/IRequestQueryValidator.ts +68 -0
- package/src/options/IResponseBodyQuerifier.ts +120 -0
- package/src/options/IResponseBodyStringifier.ts +107 -0
- package/src/typings/Creator.ts +10 -0
- package/src/utils/ArrayUtil.ts +22 -3
- package/src/utils/ExceptionManager.ts +40 -0
- package/src/utils/SourceFinder.ts +38 -7
- package/src/utils/VersioningStrategy.ts +47 -14
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
UseInterceptors,
|
|
12
12
|
applyDecorators,
|
|
13
13
|
} from "@nestjs/common";
|
|
14
|
-
import { HttpArgumentsHost } from "@nestjs/common/interfaces";
|
|
14
|
+
import { HttpArgumentsHost } from "@nestjs/common/interfaces/index.js";
|
|
15
15
|
import type express from "express";
|
|
16
16
|
import { catchError, map } from "rxjs/operators";
|
|
17
17
|
import typia, { IValidation } from "typia";
|
|
@@ -23,17 +23,21 @@ import { route_error } from "./internal/route_error";
|
|
|
23
23
|
/**
|
|
24
24
|
* Type safe router decorator functions.
|
|
25
25
|
*
|
|
26
|
-
* `TypedRoute`
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* safe through [typia](https://github.com/samchon/typia).
|
|
26
|
+
* `TypedRoute` provides router decorators that serialize response values with
|
|
27
|
+
* [typia](https://github.com/samchon/typia) functions generated from the
|
|
28
|
+
* declared return type.
|
|
30
29
|
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
30
|
+
* The default assert serializer rejects a response outside the declared type
|
|
31
|
+
* with a 500 error. The configured stringify mode can choose a different
|
|
32
|
+
* validation policy; `validate.log` logs failures and returns JSON text.
|
|
33
|
+
* Interceptors that run after this serializer receive the serialized string.
|
|
35
34
|
*
|
|
36
35
|
* @author Jeongho Nam - https://github.com/samchon
|
|
36
|
+
* @evidence contracts/common.md#principled-implementation Each method decorator combines Nest's router decorator, a JSON content type, and an interceptor that stringifies the returned value with the function the transform selected, so the JSON text is produced by generated code; an error thrown by the handler is routed to the registered exception converters.
|
|
37
|
+
* @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.
|
|
38
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts The loop after the namespace copies the marker properties of typia's stringify functions onto the decorators for the transform, which mutates only these exported functions; the logger is a module variable, not a patched global.
|
|
39
|
+
* @evidence contracts/common.md#meaningful-documentation The comment documents the decorator family, the path and stringify arguments, and the validation modes.
|
|
40
|
+
* @evidenceExclude contracts/portability.md#os-neutral-implementation Routing paths and serialized response values are HTTP protocol data; the interceptor and logger do not define a native file or subprocess boundary.
|
|
37
41
|
*/
|
|
38
42
|
export namespace TypedRoute {
|
|
39
43
|
/**
|
|
@@ -53,7 +57,7 @@ export namespace TypedRoute {
|
|
|
53
57
|
export const Post = Generator("Post");
|
|
54
58
|
|
|
55
59
|
/**
|
|
56
|
-
* Router decorator function for the
|
|
60
|
+
* Router decorator function for the PATCH method.
|
|
57
61
|
*
|
|
58
62
|
* @param path Path of the HTTP request
|
|
59
63
|
* @returns Method decorator
|
|
@@ -82,7 +86,7 @@ export namespace TypedRoute {
|
|
|
82
86
|
* If you've configured the transformation option to `validate.log` in the
|
|
83
87
|
* `tsconfig.json` file, then the error log information of the response
|
|
84
88
|
* validation failure would be logged through this function instead of
|
|
85
|
-
* throwing the
|
|
89
|
+
* throwing the 500 internal server error.
|
|
86
90
|
*
|
|
87
91
|
* By the way, be careful. If you've configured the response transformation
|
|
88
92
|
* option to be `validate.log`, client may get wrong response data. Therefore,
|
|
@@ -90,6 +94,11 @@ export namespace TypedRoute {
|
|
|
90
94
|
*
|
|
91
95
|
* @default console.log
|
|
92
96
|
* @param func Logger function
|
|
97
|
+
* @evidence contracts/common.md#principled-implementation It replaces the module's logger variable, which the `validate.log` mode calls when a response fails validation, and the default is `console.log`.
|
|
98
|
+
* @evidence contracts/common.md#clear-and-simple-design One assignment.
|
|
99
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts It changes only the logger variable.
|
|
100
|
+
* @evidence contracts/common.md#meaningful-documentation The comment states which mode uses the logger.
|
|
101
|
+
* @evidenceExclude contracts/portability.md#os-neutral-implementation Routing paths and serialized response values are HTTP protocol data; the interceptor and logger do not define a native file or subprocess boundary.
|
|
93
102
|
*/
|
|
94
103
|
export function setValidateErrorLogger(
|
|
95
104
|
func: (log: IValidateErrorLog) => void,
|
|
@@ -109,6 +118,12 @@ export namespace TypedRoute {
|
|
|
109
118
|
* information `IValidateErrorLog` would be logged through the
|
|
110
119
|
* {@link setValidateErrorLogger} function instead of throwing the 400 bad
|
|
111
120
|
* request error.
|
|
121
|
+
*
|
|
122
|
+
* @evidence contracts/common.md#principled-implementation The record carries the method, the path, the validation errors, and the offending data, which is what a logger needs to report a response that failed its type.
|
|
123
|
+
* @evidence contracts/common.md#clear-and-simple-design A flat record with no behavior.
|
|
124
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts It is a type and adds no runtime behavior.
|
|
125
|
+
* @evidence contracts/common.md#meaningful-documentation Each member documents its meaning.
|
|
126
|
+
* @evidenceExclude contracts/portability.md#os-neutral-implementation Routing paths and serialized response values are HTTP protocol data; the interceptor and logger do not define a native file or subprocess boundary.
|
|
112
127
|
*/
|
|
113
128
|
export interface IValidateErrorLog {
|
|
114
129
|
/** HTTP method of the request. */
|
|
@@ -38,6 +38,11 @@ import { validate_request_query } from "./internal/validate_request_query";
|
|
|
38
38
|
* @author Jeongho Nam - https://github.com/samchon
|
|
39
39
|
* @param path Path(s) of the WebSocket request
|
|
40
40
|
* @returns Method decorator
|
|
41
|
+
* @evidence contracts/common.md#principled-implementation The decorator records the route paths as metadata on the method, with an empty list for no path, and the adapter reads that metadata to build the route table.
|
|
42
|
+
* @evidence contracts/common.md#clear-and-simple-design One decorator function that writes one metadata object.
|
|
43
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts It uses the reflect metadata API and does not touch the server.
|
|
44
|
+
* @evidence contracts/common.md#meaningful-documentation The comment documents the path forms and the required parameters.
|
|
45
|
+
* @evidenceExclude contracts/portability.md#os-neutral-implementation The route and parameter metadata describe WebSocket handshakes and HTTP URL fields; native files and processes are not represented.
|
|
41
46
|
*/
|
|
42
47
|
export function WebSocketRoute(
|
|
43
48
|
path?: undefined | string | string[],
|
|
@@ -57,6 +62,16 @@ export function WebSocketRoute(
|
|
|
57
62
|
return descriptor;
|
|
58
63
|
};
|
|
59
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* Parameter decorators of {@link WebSocketRoute}: `Acceptor`, `Driver`,
|
|
67
|
+
* `Header`, `Param`, and `Query`.
|
|
68
|
+
*
|
|
69
|
+
* @evidence contracts/common.md#principled-implementation Each decorator appends category and position metadata. Header registration stores the shared checker whose resolver preserves successful callback data for the decorated argument without replacing the acceptor header; legacy error-only callbacks retain raw input. Param and query keep their own decoder contracts, and every rejected handshake retains its original error handling.
|
|
70
|
+
* @evidence contracts/common.md#clear-and-simple-design Five decorators sharing one `emplace` helper for the metadata list.
|
|
71
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts The validators are generated from the types; without the transform the raw values are passed only when the configuration guard is off.
|
|
72
|
+
* @evidence contracts/common.md#meaningful-documentation Each decorator documents its meaning.
|
|
73
|
+
* @evidenceExclude contracts/portability.md#os-neutral-implementation The route and parameter metadata describe WebSocket handshakes and HTTP URL fields; native files and processes are not represented.
|
|
74
|
+
*/
|
|
60
75
|
export namespace WebSocketRoute {
|
|
61
76
|
/**
|
|
62
77
|
* Acceptor parameter decorator.
|
|
@@ -127,7 +142,9 @@ export namespace WebSocketRoute {
|
|
|
127
142
|
*
|
|
128
143
|
* Also, this `@WebSocketRoute.Header()` decorator is optional, and can be
|
|
129
144
|
* substituted by `@WebSocketRoute.Acceptor()` decorated parameter by
|
|
130
|
-
*
|
|
145
|
+
* accessing the {@link WebSocketAcceptor.header} property. Clone validators
|
|
146
|
+
* supply a separate decorated argument; the acceptor keeps its original
|
|
147
|
+
* header.
|
|
131
148
|
*/
|
|
132
149
|
export function Header<T>(
|
|
133
150
|
validator?: IRequestBodyValidator<T>,
|
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
import { NoTransformConfigurationError } from "./NoTransformConfigurationError";
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Chooses whether a decorator called without the compile-time transform throws.
|
|
5
|
+
*
|
|
6
|
+
* The initial configuration throws with instructions to build with `ttsc`.
|
|
7
|
+
* Calling this setter with `false`, including its omitted-argument default,
|
|
8
|
+
* silences the error. Passing `true` restores throwing for subsequent decorator
|
|
9
|
+
* construction. Decorators already constructed keep their selected callbacks.
|
|
10
|
+
*
|
|
11
|
+
* @evidence contracts/common.md#principled-implementation The function sets the one flag that `NoTransformConfigurationError` reads, so the choice is made once for the process.
|
|
12
|
+
* @evidence contracts/common.md#clear-and-simple-design One setter with a boolean parameter.
|
|
13
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts It changes an exported flag of this package and nothing foreign.
|
|
14
|
+
* @evidence contracts/common.md#meaningful-documentation The comment states the default and the effect of the flag.
|
|
15
|
+
* @evidenceExclude contracts/portability.md#os-neutral-implementation This setter changes an in-memory validation configuration flag and performs no filesystem or process operation.
|
|
16
|
+
*/
|
|
3
17
|
export const doNotThrowTransformError = (value: boolean = false) => {
|
|
4
18
|
NoTransformConfigurationError.throws = value;
|
|
5
19
|
};
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { IRequestBodyValidation } from "./IRequestBodyValidation";
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Reflection metadata stored by the {@link McpRoute} decorator.
|
|
3
5
|
*
|
|
@@ -29,12 +31,16 @@ export namespace IMcpRouteReflect {
|
|
|
29
31
|
*
|
|
30
32
|
* `validate` is the closure returned by `validate_request_body(...)`; it
|
|
31
33
|
* returns `null` on success or an Error carrying validation details.
|
|
34
|
+
* Factory-owned callbacks additionally resolve successful data. The optional
|
|
35
|
+
* resolver preserves compatibility with existing error-only metadata
|
|
36
|
+
* callbacks.
|
|
32
37
|
*
|
|
33
38
|
* @internal
|
|
34
39
|
*/
|
|
35
40
|
export interface IArgument {
|
|
36
41
|
category: "params";
|
|
37
42
|
index: number;
|
|
38
|
-
validate: (input: any) => Error | null
|
|
43
|
+
validate: ((input: any) => Error | null) &
|
|
44
|
+
Pick<IRequestBodyValidation<any>, "resolve">;
|
|
39
45
|
}
|
|
40
46
|
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal request validation callable with an optional successful-value
|
|
3
|
+
* resolver.
|
|
4
|
+
*
|
|
5
|
+
* The callable preserves the legacy error-or-null metadata contract. Factory
|
|
6
|
+
* validators also expose `resolve` so consumers can retain clone results
|
|
7
|
+
* without treating a valid Error, null or undefined value as a failure.
|
|
8
|
+
*
|
|
9
|
+
* @evidence contracts/common.md#principled-implementation Resolver input is untrusted unknown and only successful data is T. Existing public descriptor callbacks retain their input:T signature; the private adapter casts once at that compatibility boundary and relies on the callback's validation decision, without asserting input validity beforehand. Assert returns and validation.data are retained; is and legacy null success retain accepted input. Errors preserve 400 details and non-guard throws, and explicit tags permit successful Error/null/undefined.
|
|
10
|
+
* @evidence contracts/common.md#clear-and-simple-design One callable interface and namespace separate compatibility from successful data. The private factory installs both operations on one newly created function; descriptor adapters own their existing error translation, and the shared resolver chooses the supported protocol without request-result caching or double validation.
|
|
11
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts The private constructor composes an owned function and resolver without modifying foreign callbacks or public descriptors. Unknown descriptor tags reject; legacy error-only callbacks remain supported without an invented replacement value or data sentinel.
|
|
12
|
+
* @evidence contracts/common.md#meaningful-documentation This type explains optional resolution and tagged values; private factory/resolver native comments explain construction, single-call behavior and legacy fallback. The owning type reviews those internal operations rather than exposing them to obtain standalone documentation hosts.
|
|
13
|
+
* @evidenceExclude contracts/portability.md#os-neutral-implementation The callable and tagged result describe validated JavaScript values, not native file identities or process handles.
|
|
14
|
+
*/
|
|
15
|
+
export interface IRequestBodyValidation<T> {
|
|
16
|
+
(input: T): Error | null;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Resolves validation once, retaining its successful value when supported.
|
|
20
|
+
*
|
|
21
|
+
* @evidence contracts/common.md#principled-implementation The optional operation returns a discriminated result so successful Error, null or undefined data cannot be confused with validation failure; absence identifies legacy error-only callbacks.
|
|
22
|
+
* @evidence contracts/common.md#clear-and-simple-design One optional function supplements the existing callable without changing its failure protocol.
|
|
23
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts The member records a real factory-owned capability rather than requiring it on legacy callbacks or using raw-data sentinels.
|
|
24
|
+
* @evidence contracts/common.md#meaningful-documentation The comment states single validation and successful-value retention; the owning interface explains compatibility.
|
|
25
|
+
* @evidenceExclude contracts/portability.md#os-neutral-implementation The callable and tagged result describe validated JavaScript values, not native file identities or process handles.
|
|
26
|
+
*/
|
|
27
|
+
resolve?: (input: unknown) => IRequestBodyValidation.IResult<T>;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export namespace IRequestBodyValidation {
|
|
31
|
+
/**
|
|
32
|
+
* Successful data or a validation error, distinguished independently of data.
|
|
33
|
+
*
|
|
34
|
+
* @evidence contracts/common.md#principled-implementation The success literal distinguishes a valid Error, null or undefined from a rejected value; failure alone carries the error consumers throw.
|
|
35
|
+
* @evidence contracts/common.md#clear-and-simple-design A two-variant union gives consumers one exhaustive success check.
|
|
36
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts The result uses no data sentinel or consumer-specific exception.
|
|
37
|
+
* @evidence contracts/common.md#meaningful-documentation The description states the distinction that the union preserves.
|
|
38
|
+
* @evidenceExclude contracts/portability.md#os-neutral-implementation The callable and tagged result describe validated JavaScript values, not native file identities or process handles.
|
|
39
|
+
*/
|
|
40
|
+
export type IResult<T> =
|
|
41
|
+
| { success: true; data: T }
|
|
42
|
+
| { success: false; error: Error };
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* A factory-owned checker whose resolver is always present.
|
|
46
|
+
*
|
|
47
|
+
* @evidence contracts/common.md#principled-implementation Factory callers can resolve successful data directly because construction installs the resolver together with the legacy callable.
|
|
48
|
+
* @evidence contracts/common.md#clear-and-simple-design This interface strengthens only the optional member of the compatibility interface.
|
|
49
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts The required member describes the actual factory result rather than asserting a resolver exists on foreign legacy callbacks.
|
|
50
|
+
* @evidence contracts/common.md#meaningful-documentation The comment identifies which owner guarantees resolver availability.
|
|
51
|
+
* @evidenceExclude contracts/portability.md#os-neutral-implementation The callable and tagged result describe validated JavaScript values, not native file identities or process handles.
|
|
52
|
+
*/
|
|
53
|
+
export interface IResolved<T> extends IRequestBodyValidation<T> {
|
|
54
|
+
/**
|
|
55
|
+
* Resolves validation and retains successful data.
|
|
56
|
+
*
|
|
57
|
+
* @evidence contracts/common.md#principled-implementation Factory construction installs this operation with its callable, making successful callback data available without running validation twice.
|
|
58
|
+
* @evidence contracts/common.md#clear-and-simple-design The required function strengthens only the compatibility interface's optional resolver.
|
|
59
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts The mandatory resolver applies only to the owned factory result, never to an arbitrary legacy callback.
|
|
60
|
+
* @evidence contracts/common.md#meaningful-documentation The description identifies the operation's result and the owning interface states its construction guarantee.
|
|
61
|
+
* @evidenceExclude contracts/portability.md#os-neutral-implementation The callable and tagged result describe validated JavaScript values, not native file identities or process handles.
|
|
62
|
+
*/
|
|
63
|
+
resolve: (input: unknown) => IResult<T>;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -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
|
-
|
|
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
|
|
19
|
-
|
|
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
|
|
19
|
-
|
|
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
|
-
/**
|
|
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>(
|
|
22
|
+
<T>(
|
|
23
|
+
validator?: IRequestBodyValidator<T>,
|
|
24
|
+
): IRequestBodyValidation.IResolved<T> => {
|
|
11
25
|
if (!validator) {
|
|
12
26
|
NoTransformConfigurationError(method);
|
|
13
|
-
return () =>
|
|
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
|
-
|
|
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>(
|
|
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
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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>(
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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>(
|
|
53
|
-
|
|
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
|
-
?
|
|
57
|
-
:
|
|
58
|
-
|
|
59
|
-
|
|
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.";
|