@nestia/core 12.0.0-rc.2 → 12.0.0-rc.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/LICENSE +21 -21
  2. package/MIGRATION.md +138 -169
  3. package/lib/decorators/NoTransformConfigurationError.js +5 -5
  4. package/lib/decorators/NoTransformConfigurationError.js.map +1 -1
  5. package/native/cmd/ttsc-nestia/main.go +11 -11
  6. package/native/go.mod +32 -32
  7. package/native/go.sum +54 -54
  8. package/native/plugin/plan.go +102 -102
  9. package/native/transform/ast.go +32 -32
  10. package/native/transform/build.go +388 -380
  11. package/native/transform/cleanup.go +408 -408
  12. package/native/transform/contributor.go +97 -97
  13. package/native/transform/core_querify.go +231 -231
  14. package/native/transform/core_transform.go +1996 -1996
  15. package/native/transform/core_websocket.go +115 -115
  16. package/native/transform/exports.go +13 -13
  17. package/native/transform/mcp_transform.go +414 -414
  18. package/native/transform/node_transform.go +357 -357
  19. package/native/transform/path_rewrite.go +285 -285
  20. package/native/transform/printer.go +244 -244
  21. package/native/transform/rewrite.go +668 -668
  22. package/native/transform/run.go +73 -73
  23. package/native/transform/transform.go +336 -336
  24. package/native/transform/typia_fast.go +375 -352
  25. package/native/transform/typia_replacement.go +24 -24
  26. package/native/transform.cjs +43 -43
  27. package/package.json +9 -9
  28. package/src/adaptors/McpAdaptor.ts +276 -276
  29. package/src/adaptors/WebSocketAdaptor.ts +429 -429
  30. package/src/decorators/DynamicModule.ts +44 -44
  31. package/src/decorators/EncryptedBody.ts +97 -97
  32. package/src/decorators/EncryptedController.ts +40 -40
  33. package/src/decorators/EncryptedModule.ts +98 -98
  34. package/src/decorators/EncryptedRoute.ts +213 -213
  35. package/src/decorators/HumanRoute.ts +21 -21
  36. package/src/decorators/McpRoute.ts +154 -154
  37. package/src/decorators/NoTransformConfigurationError.ts +40 -40
  38. package/src/decorators/PlainBody.ts +76 -76
  39. package/src/decorators/SwaggerCustomizer.ts +97 -97
  40. package/src/decorators/SwaggerExample.ts +180 -180
  41. package/src/decorators/TypedBody.ts +57 -57
  42. package/src/decorators/TypedException.ts +147 -147
  43. package/src/decorators/TypedFormData.ts +187 -187
  44. package/src/decorators/TypedHeaders.ts +66 -66
  45. package/src/decorators/TypedParam.ts +77 -77
  46. package/src/decorators/TypedQuery.ts +234 -234
  47. package/src/decorators/TypedRoute.ts +198 -198
  48. package/src/decorators/WebSocketRoute.ts +242 -242
  49. package/src/decorators/doNotThrowTransformError.ts +5 -5
  50. package/src/decorators/internal/EncryptedConstant.ts +2 -2
  51. package/src/decorators/internal/IMcpRouteReflect.ts +40 -40
  52. package/src/decorators/internal/IWebSocketRouteReflect.ts +23 -23
  53. package/src/decorators/internal/get_path_and_querify.ts +94 -94
  54. package/src/decorators/internal/get_path_and_stringify.ts +110 -110
  55. package/src/decorators/internal/get_text_body.ts +16 -16
  56. package/src/decorators/internal/headers_to_object.ts +11 -11
  57. package/src/decorators/internal/is_request_body_undefined.ts +12 -12
  58. package/src/decorators/internal/load_controller.ts +94 -94
  59. package/src/decorators/internal/route_error.ts +43 -43
  60. package/src/decorators/internal/validate_request_body.ts +64 -64
  61. package/src/decorators/internal/validate_request_form_data.ts +67 -67
  62. package/src/decorators/internal/validate_request_headers.ts +76 -76
  63. package/src/decorators/internal/validate_request_query.ts +83 -83
  64. package/src/index.ts +5 -5
  65. package/src/module.ts +25 -25
  66. package/src/options/IRequestBodyValidator.ts +20 -20
  67. package/src/options/IRequestFormDataProps.ts +27 -27
  68. package/src/options/IRequestHeadersValidator.ts +22 -22
  69. package/src/options/IRequestQueryValidator.ts +20 -20
  70. package/src/options/IResponseBodyQuerifier.ts +25 -25
  71. package/src/options/IResponseBodyStringifier.ts +30 -30
  72. package/src/transform.ts +26 -26
  73. package/src/typings/Creator.ts +3 -3
  74. package/src/typings/get-function-location.d.ts +7 -7
  75. package/src/utils/ArrayUtil.ts +7 -7
  76. package/src/utils/ExceptionManager.ts +115 -115
  77. package/src/utils/Singleton.ts +16 -16
  78. package/src/utils/SourceFinder.ts +54 -54
  79. package/src/utils/VersioningStrategy.ts +27 -27
  80. package/README.md +0 -93
@@ -1,154 +1,154 @@
1
- import { IRequestBodyValidator } from "../options/IRequestBodyValidator";
2
- import { IMcpRouteReflect } from "./internal/IMcpRouteReflect";
3
- import { validate_request_body } from "./internal/validate_request_body";
4
-
5
- /**
6
- * MCP (Model Context Protocol) route decorator.
7
- *
8
- * `@McpRoute()` marks a controller method as a callable MCP tool. When the
9
- * application bootstraps, every method annotated with this decorator is
10
- * registered on the MCP server built by {@link McpAdaptor.upgrade}, making it
11
- * reachable by LLM clients through the standard Streamable HTTP transport.
12
- *
13
- * The public form takes only the tool's `name` (string). Human-readable
14
- * `description` and `title` are read from the method's JSDoc:
15
- *
16
- * - `description`: the JSDoc comment body.
17
- * - `title`: the value of an optional `@title` JSDoc tag.
18
- *
19
- * For type-safe tool inputs, decorate exactly one parameter of the method with
20
- * {@link McpRoute.Params}. The parameter type `T` is analyzed at compile time by
21
- * the nestia transformer, which generates both a runtime validator and the JSON
22
- * Schema attached to `inputSchema` in `tools/list` responses.
23
- *
24
- * For the MCP endpoint to actually be served, call {@link McpAdaptor.upgrade} on
25
- * the {@link INestApplication} instance at bootstrap. The decorator alone only
26
- * stores reflection metadata.
27
- *
28
- * @author wildduck - https://github.com/wildduck2
29
- * @example
30
- * ```typescript
31
- * import core from "@nestia/core";
32
- *
33
- * @Controller()
34
- * export class WeatherController {
35
- * /**
36
- * * Return current weather for a city.
37
- * *
38
- * * @title Get weather
39
- * *\/
40
- * @core.McpRoute("get_weather")
41
- * public async get(
42
- * @core.McpRoute.Params() params: { city: string },
43
- * ): Promise<{ temp: number }> {
44
- * return { temp: 22 };
45
- * }
46
- * }
47
- * ```;
48
- *
49
- * @param name Unique tool identifier exposed to MCP clients via `tools/list`.
50
- * @returns Method decorator.
51
- */
52
- export function McpRoute(name: string): MethodDecorator;
53
-
54
- /** @internal */
55
- export function McpRoute(config: McpRoute.IConfig): MethodDecorator;
56
-
57
- export function McpRoute(input: string | McpRoute.IConfig): MethodDecorator {
58
- const config: McpRoute.IConfig =
59
- typeof input === "string" ? { name: input } : input;
60
- return function McpRoute(
61
- _target: Object,
62
- _propertyKey: string | symbol,
63
- descriptor: TypedPropertyDescriptor<any>,
64
- ): TypedPropertyDescriptor<any> {
65
- Reflect.defineMetadata(
66
- "nestia/McpRoute",
67
- {
68
- name: config.name,
69
- title: config.title,
70
- description: config.description,
71
- inputSchema: config.inputSchema ?? { type: "object", properties: {} },
72
- outputSchema: config.outputSchema,
73
- annotations: config.annotations,
74
- } satisfies IMcpRouteReflect,
75
- descriptor.value,
76
- );
77
- return descriptor;
78
- };
79
- }
80
-
81
- export namespace McpRoute {
82
- /**
83
- * Configuration object emitted by the nestia transformer at compile time.
84
- *
85
- * Users call `@McpRoute("name")`; the transformer rewrites the call to
86
- * `@McpRoute({ name, description, title, inputSchema, ... })` after parsing
87
- * method JSDoc and analyzing the `@McpRoute.Params<T>()` parameter type.
88
- *
89
- * @internal
90
- */
91
- export interface IConfig {
92
- name: string;
93
- title?: string;
94
- description?: string;
95
- inputSchema?: object;
96
- outputSchema?: object;
97
- annotations?: IMcpRouteReflect["annotations"];
98
- }
99
-
100
- /**
101
- * Parameter decorator for an MCP tool's input arguments.
102
- *
103
- * `@McpRoute.Params<T>()` validates the `arguments` object from a
104
- * `tools/call` request against the TypeScript type `T` using typia. A failed
105
- * validation surfaces to the client as a JSON-RPC `-32602` (`InvalidParams`)
106
- * error with structured diagnostics, giving the LLM precise feedback to
107
- * self-correct.
108
- *
109
- * MCP tools accept exactly one arguments object; applying this decorator more
110
- * than once on a single method is a compile-time error. The decorated type
111
- * `T` must be an object type without dynamic properties.
112
- *
113
- * @author wildduck - https://github.com/wildduck2
114
- * @param validator Optional custom validator. Default is `typia.assert()`.
115
- * @returns Parameter decorator.
116
- */
117
- export function Params<T>(
118
- validator?: IRequestBodyValidator<T>,
119
- ): ParameterDecorator {
120
- const validate = validate_request_body("McpRoute.Params")(validator);
121
- return function McpRouteParams(
122
- target: Object,
123
- propertyKey: string | symbol | undefined,
124
- parameterIndex: number,
125
- ) {
126
- emplace(target, propertyKey ?? "", {
127
- category: "params",
128
- index: parameterIndex,
129
- validate,
130
- });
131
- };
132
- }
133
-
134
- /** @internal */
135
- const emplace = (
136
- target: Object,
137
- propertyKey: string | symbol,
138
- value: IMcpRouteReflect.IArgument,
139
- ) => {
140
- const array: IMcpRouteReflect.IArgument[] | undefined = Reflect.getMetadata(
141
- "nestia/McpRoute/Parameters",
142
- target,
143
- propertyKey,
144
- );
145
- if (array !== undefined) array.push(value);
146
- else
147
- Reflect.defineMetadata(
148
- "nestia/McpRoute/Parameters",
149
- [value],
150
- target,
151
- propertyKey,
152
- );
153
- };
154
- }
1
+ import { IRequestBodyValidator } from "../options/IRequestBodyValidator";
2
+ import { IMcpRouteReflect } from "./internal/IMcpRouteReflect";
3
+ import { validate_request_body } from "./internal/validate_request_body";
4
+
5
+ /**
6
+ * MCP (Model Context Protocol) route decorator.
7
+ *
8
+ * `@McpRoute()` marks a controller method as a callable MCP tool. When the
9
+ * application bootstraps, every method annotated with this decorator is
10
+ * registered on the MCP server built by {@link McpAdaptor.upgrade}, making it
11
+ * reachable by LLM clients through the standard Streamable HTTP transport.
12
+ *
13
+ * The public form takes only the tool's `name` (string). Human-readable
14
+ * `description` and `title` are read from the method's JSDoc:
15
+ *
16
+ * - `description`: the JSDoc comment body.
17
+ * - `title`: the value of an optional `@title` JSDoc tag.
18
+ *
19
+ * For type-safe tool inputs, decorate exactly one parameter of the method with
20
+ * {@link McpRoute.Params}. The parameter type `T` is analyzed at compile time by
21
+ * the nestia transformer, which generates both a runtime validator and the JSON
22
+ * Schema attached to `inputSchema` in `tools/list` responses.
23
+ *
24
+ * For the MCP endpoint to actually be served, call {@link McpAdaptor.upgrade} on
25
+ * the {@link INestApplication} instance at bootstrap. The decorator alone only
26
+ * stores reflection metadata.
27
+ *
28
+ * @author wildduck - https://github.com/wildduck2
29
+ * @example
30
+ * ```typescript
31
+ * import core from "@nestia/core";
32
+ *
33
+ * @Controller()
34
+ * export class WeatherController {
35
+ * /**
36
+ * * Return current weather for a city.
37
+ * *
38
+ * * @title Get weather
39
+ * *\/
40
+ * @core.McpRoute("get_weather")
41
+ * public async get(
42
+ * @core.McpRoute.Params() params: { city: string },
43
+ * ): Promise<{ temp: number }> {
44
+ * return { temp: 22 };
45
+ * }
46
+ * }
47
+ * ```;
48
+ *
49
+ * @param name Unique tool identifier exposed to MCP clients via `tools/list`.
50
+ * @returns Method decorator.
51
+ */
52
+ export function McpRoute(name: string): MethodDecorator;
53
+
54
+ /** @internal */
55
+ export function McpRoute(config: McpRoute.IConfig): MethodDecorator;
56
+
57
+ export function McpRoute(input: string | McpRoute.IConfig): MethodDecorator {
58
+ const config: McpRoute.IConfig =
59
+ typeof input === "string" ? { name: input } : input;
60
+ return function McpRoute(
61
+ _target: Object,
62
+ _propertyKey: string | symbol,
63
+ descriptor: TypedPropertyDescriptor<any>,
64
+ ): TypedPropertyDescriptor<any> {
65
+ Reflect.defineMetadata(
66
+ "nestia/McpRoute",
67
+ {
68
+ name: config.name,
69
+ title: config.title,
70
+ description: config.description,
71
+ inputSchema: config.inputSchema ?? { type: "object", properties: {} },
72
+ outputSchema: config.outputSchema,
73
+ annotations: config.annotations,
74
+ } satisfies IMcpRouteReflect,
75
+ descriptor.value,
76
+ );
77
+ return descriptor;
78
+ };
79
+ }
80
+
81
+ export namespace McpRoute {
82
+ /**
83
+ * Configuration object emitted by the nestia transformer at compile time.
84
+ *
85
+ * Users call `@McpRoute("name")`; the transformer rewrites the call to
86
+ * `@McpRoute({ name, description, title, inputSchema, ... })` after parsing
87
+ * method JSDoc and analyzing the `@McpRoute.Params<T>()` parameter type.
88
+ *
89
+ * @internal
90
+ */
91
+ export interface IConfig {
92
+ name: string;
93
+ title?: string;
94
+ description?: string;
95
+ inputSchema?: object;
96
+ outputSchema?: object;
97
+ annotations?: IMcpRouteReflect["annotations"];
98
+ }
99
+
100
+ /**
101
+ * Parameter decorator for an MCP tool's input arguments.
102
+ *
103
+ * `@McpRoute.Params<T>()` validates the `arguments` object from a
104
+ * `tools/call` request against the TypeScript type `T` using typia. A failed
105
+ * validation surfaces to the client as a JSON-RPC `-32602` (`InvalidParams`)
106
+ * error with structured diagnostics, giving the LLM precise feedback to
107
+ * self-correct.
108
+ *
109
+ * MCP tools accept exactly one arguments object; applying this decorator more
110
+ * than once on a single method is a compile-time error. The decorated type
111
+ * `T` must be an object type without dynamic properties.
112
+ *
113
+ * @author wildduck - https://github.com/wildduck2
114
+ * @param validator Optional custom validator. Default is `typia.assert()`.
115
+ * @returns Parameter decorator.
116
+ */
117
+ export function Params<T>(
118
+ validator?: IRequestBodyValidator<T>,
119
+ ): ParameterDecorator {
120
+ const validate = validate_request_body("McpRoute.Params")(validator);
121
+ return function McpRouteParams(
122
+ target: Object,
123
+ propertyKey: string | symbol | undefined,
124
+ parameterIndex: number,
125
+ ) {
126
+ emplace(target, propertyKey ?? "", {
127
+ category: "params",
128
+ index: parameterIndex,
129
+ validate,
130
+ });
131
+ };
132
+ }
133
+
134
+ /** @internal */
135
+ const emplace = (
136
+ target: Object,
137
+ propertyKey: string | symbol,
138
+ value: IMcpRouteReflect.IArgument,
139
+ ) => {
140
+ const array: IMcpRouteReflect.IArgument[] | undefined = Reflect.getMetadata(
141
+ "nestia/McpRoute/Parameters",
142
+ target,
143
+ propertyKey,
144
+ );
145
+ if (array !== undefined) array.push(value);
146
+ else
147
+ Reflect.defineMetadata(
148
+ "nestia/McpRoute/Parameters",
149
+ [value],
150
+ target,
151
+ propertyKey,
152
+ );
153
+ };
154
+ }
@@ -1,40 +1,40 @@
1
- /** @internal */
2
- export function NoTransformConfigurationError(method: string) {
3
- if (NoTransformConfigurationError.throws === true)
4
- throw new Error(
5
- [
6
- `Error on nestia.core.${method}(): no transform has been configured.`,
7
- `Build the project with "ttsc" (not stock "tsc"); the Go-backed @nestia/core transform attaches automatically through ttsc plugin auto-discovery.`,
8
- `If "ttsc" is missing, run "npx nestia setup" to install the toolchain and runtime packages.`,
9
- `If you're using a non-standard TypeScript compiler like Babel or SWC, the @nestia/core transformer is not available.`,
10
- `If you're running "npx nestia sdk/swagger" or similar, run "npx ttsc --noEmit" to surface the underlying compilation error.`,
11
- `See https://nestia.io/docs/setup for the full setup (tsgo and legacy paths); migration notes are at node_modules/@nestia/core/MIGRATION.md.`,
12
- ].join(" "),
13
- );
14
- return undefined as never;
15
- }
16
-
17
- /** @internal */
18
- export namespace NoTransformConfigurationError {
19
- /**
20
- * Whether to throw an error or not.
21
- *
22
- * If you set this value to `false`, {@link NoTransformConfigurationError} will
23
- * not throw an error.
24
- *
25
- * Even if you've not configured the plugin transformer of `tsconfig.json`
26
- * file, the error will not be thrown and the program will be continued.
27
- * Instead, every validations and assertions will be skipped and the value
28
- * will be returned as it is. Furthermore, unexpected behaviors may occur.
29
- *
30
- * Therefore, it is not recommended to set this value to `false` in production
31
- * environment. Configure this value to be `false` only when you're debugging
32
- * or testing.
33
- *
34
- * By the way, if you hope the `false` value to be set, you have to do it
35
- * before the first. If you configure the `false` value after the
36
- * `@nestia/core` decorator functions are composed, the value will not be
37
- * applied and the error will be thrown.
38
- */
39
- export let throws = true;
40
- }
1
+ /** @internal */
2
+ export function NoTransformConfigurationError(method: string) {
3
+ if (NoTransformConfigurationError.throws === true)
4
+ throw new Error(
5
+ [
6
+ `Error on nestia.core.${method}(): no transform has been configured.`,
7
+ `Build the project with "ttsc" (not stock "tsc"); the Go-backed @nestia/core transform attaches automatically through ttsc plugin auto-discovery.`,
8
+ `If "ttsc" is missing, install the toolchain manually: npm i -D ttsc typescript.`,
9
+ `If you're using a non-standard TypeScript compiler like Babel or SWC, the @nestia/core transformer is not available.`,
10
+ `If you're running "npx nestia sdk/swagger" or similar, run "npx ttsc --noEmit" to surface the underlying compilation error.`,
11
+ `See https://nestia.io/docs/setup for the full setup; migration notes are at node_modules/@nestia/core/MIGRATION.md.`,
12
+ ].join(" "),
13
+ );
14
+ return undefined as never;
15
+ }
16
+
17
+ /** @internal */
18
+ export namespace NoTransformConfigurationError {
19
+ /**
20
+ * Whether to throw an error or not.
21
+ *
22
+ * If you set this value to `false`, {@link NoTransformConfigurationError} will
23
+ * not throw an error.
24
+ *
25
+ * Even if the transform did not run, the error will not be thrown and the
26
+ * program will be continued. Instead, every validation and assertion will be
27
+ * skipped and the value
28
+ * will be returned as it is. Furthermore, unexpected behaviors may occur.
29
+ *
30
+ * Therefore, it is not recommended to set this value to `false` in production
31
+ * environment. Configure this value to be `false` only when you're debugging
32
+ * or testing.
33
+ *
34
+ * By the way, if you hope the `false` value to be set, you have to do it
35
+ * before the first. If you configure the `false` value after the
36
+ * `@nestia/core` decorator functions are composed, the value will not be
37
+ * applied and the error will be thrown.
38
+ */
39
+ export let throws = true;
40
+ }
@@ -1,76 +1,76 @@
1
- import {
2
- BadRequestException,
3
- ExecutionContext,
4
- createParamDecorator,
5
- } from "@nestjs/common";
6
- import type express from "express";
7
- import type { FastifyRequest } from "fastify";
8
-
9
- import { get_text_body } from "./internal/get_text_body";
10
- import { is_request_body_undefined } from "./internal/is_request_body_undefined";
11
- import { validate_request_body } from "./internal/validate_request_body";
12
-
13
- /**
14
- * Plain body decorator.
15
- *
16
- * `PlainBody` is a decorator function getting full body text from the HTTP
17
- * request.
18
- *
19
- * If you adjust the regular {@link Body} decorator function to the body
20
- * parameter, you can't get the full body text because the {@link Body} tries to
21
- * convert the body text to JSON object. Therefore, `@nestia/core` provides this
22
- * `PlainBody` decorator function to get the full body text.
23
- *
24
- * ```typescript
25
- * \@TypedRoute.Post("memo")
26
- * public store
27
- * (
28
- * \@PlainBody() body: string
29
- * ): void;
30
- * ```
31
- *
32
- * @author Jeongho Nam - https://github.com/samchon
33
- * @returns Parameter decorator
34
- */
35
- export function PlainBody(): ParameterDecorator;
36
-
37
- /** @internal */
38
- export function PlainBody(
39
- assert?: (input: unknown) => string,
40
- ): ParameterDecorator {
41
- const checker = assert
42
- ? validate_request_body("PlainBody")({
43
- type: "assert",
44
- assert,
45
- })
46
- : null;
47
- return createParamDecorator(async function PlainBody(
48
- _data: any,
49
- context: ExecutionContext,
50
- ) {
51
- const request: express.Request | FastifyRequest = context
52
- .switchToHttp()
53
- .getRequest();
54
- if (
55
- is_request_body_undefined(request) &&
56
- (checker ?? (() => null))(undefined as any) === null
57
- )
58
- return undefined;
59
- else if (!isTextPlain(request.headers["content-type"]))
60
- throw new BadRequestException(`Request body type is not "text/plain".`);
61
- const value: string = await get_text_body(request);
62
- if (checker) {
63
- const error: Error | null = checker(value);
64
- if (error !== null) throw error;
65
- }
66
- return value;
67
- })();
68
- }
69
-
70
- /** @internal */
71
- const isTextPlain = (text?: string): boolean =>
72
- text !== undefined &&
73
- text
74
- .split(";")
75
- .map((str) => str.trim())
76
- .some((str) => str === "text/plain");
1
+ import {
2
+ BadRequestException,
3
+ ExecutionContext,
4
+ createParamDecorator,
5
+ } from "@nestjs/common";
6
+ import type express from "express";
7
+ import type { FastifyRequest } from "fastify";
8
+
9
+ import { get_text_body } from "./internal/get_text_body";
10
+ import { is_request_body_undefined } from "./internal/is_request_body_undefined";
11
+ import { validate_request_body } from "./internal/validate_request_body";
12
+
13
+ /**
14
+ * Plain body decorator.
15
+ *
16
+ * `PlainBody` is a decorator function getting full body text from the HTTP
17
+ * request.
18
+ *
19
+ * If you adjust the regular {@link Body} decorator function to the body
20
+ * parameter, you can't get the full body text because the {@link Body} tries to
21
+ * convert the body text to JSON object. Therefore, `@nestia/core` provides this
22
+ * `PlainBody` decorator function to get the full body text.
23
+ *
24
+ * ```typescript
25
+ * \@TypedRoute.Post("memo")
26
+ * public store
27
+ * (
28
+ * \@PlainBody() body: string
29
+ * ): void;
30
+ * ```
31
+ *
32
+ * @author Jeongho Nam - https://github.com/samchon
33
+ * @returns Parameter decorator
34
+ */
35
+ export function PlainBody(): ParameterDecorator;
36
+
37
+ /** @internal */
38
+ export function PlainBody(
39
+ assert?: (input: unknown) => string,
40
+ ): ParameterDecorator {
41
+ const checker = assert
42
+ ? validate_request_body("PlainBody")({
43
+ type: "assert",
44
+ assert,
45
+ })
46
+ : null;
47
+ return createParamDecorator(async function PlainBody(
48
+ _data: any,
49
+ context: ExecutionContext,
50
+ ) {
51
+ const request: express.Request | FastifyRequest = context
52
+ .switchToHttp()
53
+ .getRequest();
54
+ if (
55
+ is_request_body_undefined(request) &&
56
+ (checker ?? (() => null))(undefined as any) === null
57
+ )
58
+ return undefined;
59
+ else if (!isTextPlain(request.headers["content-type"]))
60
+ throw new BadRequestException(`Request body type is not "text/plain".`);
61
+ const value: string = await get_text_body(request);
62
+ if (checker) {
63
+ const error: Error | null = checker(value);
64
+ if (error !== null) throw error;
65
+ }
66
+ return value;
67
+ })();
68
+ }
69
+
70
+ /** @internal */
71
+ const isTextPlain = (text?: string): boolean =>
72
+ text !== undefined &&
73
+ text
74
+ .split(";")
75
+ .map((str) => str.trim())
76
+ .some((str) => str === "text/plain");