@nestia/core 12.0.0 → 12.1.0

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 (60) hide show
  1. package/lib/adaptors/McpAdaptor.js +21 -18
  2. package/lib/adaptors/McpAdaptor.js.map +1 -1
  3. package/lib/decorators/EncryptedBody.js +2 -7
  4. package/lib/decorators/EncryptedBody.js.map +1 -1
  5. package/lib/decorators/EncryptedRoute.js +1 -1
  6. package/lib/decorators/EncryptedRoute.js.map +1 -1
  7. package/lib/decorators/McpRoute.js +1 -1
  8. package/lib/decorators/McpRoute.js.map +1 -1
  9. package/lib/decorators/NoTransformConfigurationError.js +2 -2
  10. package/lib/decorators/PlainBody.js +2 -7
  11. package/lib/decorators/PlainBody.js.map +1 -1
  12. package/lib/decorators/SwaggerCustomizer.js +2 -2
  13. package/lib/decorators/SwaggerCustomizer.js.map +1 -1
  14. package/lib/decorators/SwaggerExample.d.ts +37 -40
  15. package/lib/decorators/SwaggerExample.js +24 -26
  16. package/lib/decorators/SwaggerExample.js.map +1 -1
  17. package/lib/decorators/TypedBody.js +3 -7
  18. package/lib/decorators/TypedBody.js.map +1 -1
  19. package/lib/decorators/TypedException.d.ts +1 -1
  20. package/lib/decorators/TypedFormData.js +2 -7
  21. package/lib/decorators/TypedFormData.js.map +1 -1
  22. package/lib/decorators/TypedQuery.js +2 -9
  23. package/lib/decorators/TypedQuery.js.map +1 -1
  24. package/lib/decorators/WebSocketRoute.js +1 -1
  25. package/lib/decorators/WebSocketRoute.js.map +1 -1
  26. package/lib/decorators/internal/get_path_and_querify.js +1 -1
  27. package/lib/decorators/internal/get_path_and_querify.js.map +1 -1
  28. package/lib/decorators/internal/is_media_type.d.ts +1 -0
  29. package/lib/decorators/internal/is_media_type.js +11 -0
  30. package/lib/decorators/internal/is_media_type.js.map +1 -0
  31. package/lib/decorators/internal/validate_request_query.js.map +1 -1
  32. package/native/plugin/plan.go +17 -0
  33. package/native/transform/build.go +39 -80
  34. package/native/transform/contributor.go +4 -64
  35. package/native/transform/core_transform.go +42 -705
  36. package/native/transform/node_transform.go +3 -5
  37. package/native/transform/printer.go +0 -217
  38. package/native/transform/transform.go +2 -91
  39. package/native/transform/typia_fast.go +0 -320
  40. package/package.json +8 -8
  41. package/src/adaptors/McpAdaptor.ts +29 -21
  42. package/src/decorators/EncryptedBody.ts +2 -9
  43. package/src/decorators/EncryptedRoute.ts +1 -1
  44. package/src/decorators/McpRoute.ts +6 -5
  45. package/src/decorators/NoTransformConfigurationError.ts +2 -2
  46. package/src/decorators/PlainBody.ts +2 -9
  47. package/src/decorators/SwaggerCustomizer.ts +8 -2
  48. package/src/decorators/SwaggerExample.ts +43 -45
  49. package/src/decorators/TypedBody.ts +5 -9
  50. package/src/decorators/TypedException.ts +1 -1
  51. package/src/decorators/TypedFormData.ts +7 -9
  52. package/src/decorators/TypedQuery.ts +7 -12
  53. package/src/decorators/WebSocketRoute.ts +1 -1
  54. package/src/decorators/internal/get_path_and_querify.ts +1 -1
  55. package/src/decorators/internal/is_media_type.ts +10 -0
  56. package/src/decorators/internal/validate_request_query.ts +2 -1
  57. package/native/transform/cleanup.go +0 -408
  58. package/native/transform/exports.go +0 -13
  59. package/native/transform/rewrite.go +0 -668
  60. package/native/transform/typia_replacement.go +0 -24
@@ -1,40 +1,38 @@
1
1
  /**
2
2
  * Attach example values to Swagger documents.
3
3
  *
4
- * `SwaggerExample` is a namespace of decorators that attach example values
5
- * to controller methods (request/response bodies, parameters), so that
4
+ * `SwaggerExample` is a namespace of decorators that attach example values to
5
+ * controller methods (request/response bodies, parameters), so that
6
6
  * `@nestia/sdk`'s Swagger generator can populate the `example` / `examples`
7
7
  * fields of the generated OpenAPI document.
8
8
  *
9
9
  * The decorators only affect Swagger document generation. They do not change
10
10
  * runtime behavior, validation, or SDK function signatures.
11
11
  *
12
+ * @author Jeongho Nam - https://github.com/samchon
12
13
  * @example
14
+ * ```typescript
15
+ * import core from "@nestia/core";
16
+ * import { Controller } from "@nestjs/common";
17
+ * import typia from "typia";
13
18
  *
14
- * ```typescript
15
- * import core from "@nestia/core";
16
- * import { Controller } from "@nestjs/common";
17
- * import typia from "typia";
18
- *
19
- * @Controller("bbs/articles")
20
- * export class BbsArticlesController {
21
- * // Single response example.
22
- * @core.SwaggerExample.Response(typia.random<IBbsArticle>())
23
- * @core.TypedRoute.Post()
24
- * public async create(
25
- * // Multiple named parameter examples plus a default one.
26
- * @core.SwaggerExample.Parameter(typia.random<IBbsArticle.ICreate>())
27
- * @core.SwaggerExample.Parameter("x", typia.random<IBbsArticle.ICreate>())
28
- * @core.SwaggerExample.Parameter("y", typia.random<IBbsArticle.ICreate>())
29
- * @core.TypedBody()
30
- * input: IBbsArticle.ICreate,
31
- * ): Promise<IBbsArticle> {
32
- * // ...
19
+ * @Controller("bbs/articles")
20
+ * export class BbsArticlesController {
21
+ * // Single response example.
22
+ * @core.SwaggerExample.Response(typia.random<IBbsArticle>())
23
+ * @core.TypedRoute.Post()
24
+ * public async create(
25
+ * // Multiple named parameter examples plus a default one.
26
+ * @core.SwaggerExample.Parameter(typia.random<IBbsArticle.ICreate>())
27
+ * @core.SwaggerExample.Parameter("x", typia.random<IBbsArticle.ICreate>())
28
+ * @core.SwaggerExample.Parameter("y", typia.random<IBbsArticle.ICreate>())
29
+ * @core.TypedBody()
30
+ * input: IBbsArticle.ICreate,
31
+ * ): Promise<IBbsArticle> {
32
+ * // ...
33
+ * }
33
34
  * }
34
- * }
35
- * ```
36
- *
37
- * @author Jeongho Nam - https://github.com/samchon
35
+ * ```;
38
36
  */
39
37
  export namespace SwaggerExample {
40
38
  /**
@@ -45,12 +43,12 @@ export namespace SwaggerExample {
45
43
  * - {@link Response | `Response(value)`}: registers `value` as the single
46
44
  * default `example`.
47
45
  * - {@link Response | `Response(key, value)`}: registers `value` under
48
- * `examples[key]`. May be applied multiple times to attach several
49
- * named examples.
46
+ * `examples[key]`. May be applied multiple times to attach several named
47
+ * examples.
50
48
  *
51
- * Both forms can coexist on the same method — the default `example` and
52
- * any number of named `examples` will all surface in the generated
53
- * Swagger document.
49
+ * Both forms can coexist on the same method — the default `example` and any
50
+ * number of named `examples` will all surface in the generated Swagger
51
+ * document.
54
52
  *
55
53
  * @template T Type of the example value (typically the route's response DTO).
56
54
  */
@@ -68,20 +66,19 @@ export namespace SwaggerExample {
68
66
  }
69
67
 
70
68
  /**
71
- * Attach an example value to a request parameter (body, path, query, etc.)
72
- * of a controller method.
69
+ * Attach an example value to a request parameter (body, path, query, etc.) of
70
+ * a controller method.
73
71
  *
74
72
  * Two forms are supported:
75
73
  *
76
74
  * - {@link Parameter | `Parameter(value)`}: registers `value` as the single
77
75
  * default `example` for that parameter.
78
76
  * - {@link Parameter | `Parameter(key, value)`}: registers `value` under
79
- * `examples[key]`. May be applied multiple times to attach several
80
- * named examples to the same parameter.
77
+ * `examples[key]`. May be applied multiple times to attach several named
78
+ * examples to the same parameter.
81
79
  *
82
- * Apply alongside the actual parameter decorator
83
- * (`@TypedBody()`, `@TypedParam()`, `@TypedQuery()`, etc.); decorator
84
- * order does not matter.
80
+ * Apply alongside the actual parameter decorator (`@TypedBody()`,
81
+ * `@TypedParam()`, `@TypedQuery()`, etc.); decorator order does not matter.
85
82
  *
86
83
  * @template T Type of the example value (typically the parameter's DTO).
87
84
  */
@@ -100,9 +97,9 @@ export namespace SwaggerExample {
100
97
  /**
101
98
  * Internal storage shape for `SwaggerExample` metadata.
102
99
  *
103
- * Reflects the OpenAPI spec's two example fields: a single default
104
- * `example`, and/or a named map `examples`. `index` is used internally
105
- * to associate parameter examples with the right parameter position.
100
+ * Reflects the OpenAPI spec's two example fields: a single default `example`,
101
+ * and/or a named map `examples`. `index` is used internally to associate
102
+ * parameter examples with the right parameter position.
106
103
  */
107
104
  export interface IData<T> {
108
105
  examples?: Record<string, T>;
@@ -163,11 +160,12 @@ const emplaceArrayOfParameters = (
163
160
  target: Object,
164
161
  propertyKey: string | symbol,
165
162
  ): SwaggerExample.IData<any>[] => {
166
- const array: SwaggerExample.IData<any>[] | undefined = Reflect.getMetadata(
167
- "nestia/SwaggerExample/Parameters",
168
- target,
169
- propertyKey,
170
- );
163
+ const array: SwaggerExample.IData<any>[] | undefined =
164
+ Reflect.getOwnMetadata(
165
+ "nestia/SwaggerExample/Parameters",
166
+ target,
167
+ propertyKey,
168
+ );
171
169
  if (array !== undefined) return array;
172
170
  const newbie: SwaggerExample.IData<any>[] = [];
173
171
  Reflect.defineMetadata(
@@ -7,6 +7,7 @@ import type express from "express";
7
7
  import type { FastifyRequest } from "fastify";
8
8
 
9
9
  import { IRequestBodyValidator } from "../options/IRequestBodyValidator";
10
+ import { is_media_type } from "./internal/is_media_type";
10
11
  import { is_request_body_undefined } from "./internal/is_request_body_undefined";
11
12
  import { validate_request_body } from "./internal/validate_request_body";
12
13
 
@@ -37,7 +38,10 @@ export function TypedBody<T>(
37
38
  .getRequest();
38
39
  if (is_request_body_undefined(request) && checker(undefined as T) === null)
39
40
  return undefined;
40
- else if (isApplicationJson(request.headers["content-type"]) === false)
41
+ else if (
42
+ is_media_type(request.headers["content-type"], "application/json") ===
43
+ false
44
+ )
41
45
  throw new BadRequestException(
42
46
  `Request body type is not "application/json".`,
43
47
  );
@@ -47,11 +51,3 @@ export function TypedBody<T>(
47
51
  return request.body;
48
52
  })();
49
53
  }
50
-
51
- /** @internal */
52
- const isApplicationJson = (text?: string): boolean =>
53
- text !== undefined &&
54
- text
55
- .split(";")
56
- .map((str) => str.trim())
57
- .some((str) => str === "application/json");
@@ -84,7 +84,7 @@ export function TypedException<T>(
84
84
  export function TypedException<T>(
85
85
  status: number | "2XX" | "3XX" | "4XX" | "5XX",
86
86
  description?: string | undefined,
87
- ): MethodDecorator;
87
+ ): MethodDecorator & Pick<TypedException.IProps<T>, never>;
88
88
 
89
89
  /** @internal */
90
90
  export function TypedException<T>(...args: any[]): MethodDecorator {
@@ -9,6 +9,7 @@ import type ExpressMulter from "multer";
9
9
 
10
10
  import type { IRequestFormDataProps } from "../options/IRequestFormDataProps";
11
11
  import { Singleton } from "../utils/Singleton";
12
+ import { is_media_type } from "./internal/is_media_type";
12
13
  import { validate_request_form_data } from "./internal/validate_request_form_data";
13
14
 
14
15
  /**
@@ -95,7 +96,12 @@ export namespace TypedFormData {
95
96
  ): Promise<T> {
96
97
  const http: HttpArgumentsHost = context.switchToHttp();
97
98
  const request: express.Request = http.getRequest();
98
- if (isMultipartFormData(request.headers["content-type"]) === false)
99
+ if (
100
+ is_media_type(
101
+ request.headers["content-type"],
102
+ "multipart/form-data",
103
+ ) === false
104
+ )
99
105
  throw new BadRequestException(
100
106
  `Request body type is not "multipart/form-data".`,
101
107
  );
@@ -177,11 +183,3 @@ const parseFiles =
177
183
  }),
178
184
  );
179
185
  };
180
-
181
- /** @internal */
182
- const isMultipartFormData = (text?: string): boolean =>
183
- text !== undefined &&
184
- text
185
- .split(";")
186
- .map((str) => str.trim())
187
- .some((str) => str === "multipart/form-data");
@@ -21,6 +21,7 @@ import typia from "typia";
21
21
  import { IRequestQueryValidator } from "../options/IRequestQueryValidator";
22
22
  import { IResponseBodyQuerifier } from "../options/IResponseBodyQuerifier";
23
23
  import { get_path_and_querify } from "./internal/get_path_and_querify";
24
+ import { is_media_type } from "./internal/is_media_type";
24
25
  import { route_error } from "./internal/route_error";
25
26
  import { validate_request_query } from "./internal/validate_request_query";
26
27
 
@@ -79,7 +80,12 @@ export namespace TypedQuery {
79
80
  const request: express.Request | FastifyRequest = context
80
81
  .switchToHttp()
81
82
  .getRequest();
82
- if (isApplicationQuery(request.headers["content-type"]) === false)
83
+ if (
84
+ is_media_type(
85
+ request.headers["content-type"],
86
+ "application/x-www-form-urlencoded",
87
+ ) === false
88
+ )
83
89
  throw new BadRequestException(
84
90
  `Request body type is not "application/x-www-form-urlencoded".`,
85
91
  );
@@ -172,17 +178,6 @@ function tail(url: string): string {
172
178
  return index === -1 ? "" : url.substring(index + 1);
173
179
  }
174
180
 
175
- /** @internal */
176
- function isApplicationQuery(text?: string): boolean {
177
- return (
178
- text !== undefined &&
179
- text
180
- .split(";")
181
- .map((str) => str.trim())
182
- .some((str) => str === "application/x-www-form-urlencoded")
183
- );
184
- }
185
-
186
181
  /** @internal */
187
182
  class FakeURLSearchParams {
188
183
  public constructor(private readonly target: Record<string, string[]>) {}
@@ -225,7 +225,7 @@ export namespace WebSocketRoute {
225
225
  value: IWebSocketRouteReflect.IArgument,
226
226
  ) => {
227
227
  const array: IWebSocketRouteReflect.IArgument[] | undefined =
228
- Reflect.getMetadata(
228
+ Reflect.getOwnMetadata(
229
229
  "nestia/WebSocketRoute/Parameters",
230
230
  target,
231
231
  propertyKey,
@@ -42,7 +42,7 @@ const take =
42
42
  const querify = (input: Record<string, any>): URLSearchParams => {
43
43
  const output: URLSearchParams = new URLSearchParams();
44
44
  for (const [key, value] of Object.entries(input))
45
- if (key === undefined) continue;
45
+ if (value === undefined) continue;
46
46
  else if (Array.isArray(value))
47
47
  for (const elem of value) output.append(key, String(elem));
48
48
  else output.append(key, String(value));
@@ -0,0 +1,10 @@
1
+ /** @internal */
2
+ export const is_media_type = (
3
+ text: string | undefined,
4
+ expected: string,
5
+ ): boolean =>
6
+ text !== undefined &&
7
+ text
8
+ .split(";")
9
+ .map((str) => str.trim().toLowerCase())
10
+ .some((str) => str === expected.toLowerCase());
@@ -35,7 +35,8 @@ const assert =
35
35
  message: MESSAGE,
36
36
  });
37
37
  }
38
- if (is_missing_query_property(exp)) return new BadRequestException(MESSAGE);
38
+ if (is_missing_query_property(exp))
39
+ return new BadRequestException(MESSAGE);
39
40
  throw exp;
40
41
  }
41
42
  };