@nestia/core 11.0.0-dev.20260312 → 11.0.0-dev.20260313-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 (39) hide show
  1. package/package.json +8 -8
  2. package/src/decorators/DynamicModule.ts +44 -44
  3. package/src/decorators/PlainBody.ts +76 -76
  4. package/src/decorators/SwaggerExample.ts +100 -100
  5. package/src/decorators/TypedBody.ts +57 -57
  6. package/src/decorators/TypedException.ts +147 -147
  7. package/src/decorators/TypedHeaders.ts +66 -66
  8. package/src/decorators/TypedParam.ts +77 -77
  9. package/src/decorators/TypedQuery.ts +234 -234
  10. package/src/decorators/WebSocketRoute.ts +242 -242
  11. package/src/decorators/internal/EncryptedConstant.ts +2 -2
  12. package/src/decorators/internal/IWebSocketRouteReflect.ts +23 -23
  13. package/src/decorators/internal/NoTransformConfigureError.ts +2 -2
  14. package/src/decorators/internal/get_path_and_querify.ts +94 -94
  15. package/src/decorators/internal/get_path_and_stringify.ts +110 -110
  16. package/src/decorators/internal/get_text_body.ts +16 -16
  17. package/src/decorators/internal/is_request_body_undefined.ts +12 -12
  18. package/src/decorators/internal/load_controller.ts +45 -45
  19. package/src/decorators/internal/route_error.ts +43 -43
  20. package/src/decorators/internal/validate_request_body.ts +64 -64
  21. package/src/decorators/internal/validate_request_form_data.ts +67 -67
  22. package/src/decorators/internal/validate_request_headers.ts +76 -76
  23. package/src/decorators/internal/validate_request_query.ts +64 -64
  24. package/src/index.ts +5 -5
  25. package/src/options/IRequestBodyValidator.ts +20 -20
  26. package/src/options/IRequestFormDataProps.ts +27 -27
  27. package/src/options/IRequestHeadersValidator.ts +22 -22
  28. package/src/options/IRequestQueryValidator.ts +20 -20
  29. package/src/options/IResponseBodyQuerifier.ts +25 -25
  30. package/src/options/IResponseBodyStringifier.ts +30 -30
  31. package/src/transformers/NodeTransformer.ts +23 -23
  32. package/src/transformers/ParameterTransformer.ts +57 -57
  33. package/src/typings/Creator.ts +3 -3
  34. package/src/typings/get-function-location.d.ts +7 -7
  35. package/src/utils/ArrayUtil.ts +7 -7
  36. package/src/utils/ExceptionManager.ts +115 -115
  37. package/src/utils/Singleton.ts +16 -16
  38. package/src/utils/SourceFinder.ts +54 -54
  39. package/src/utils/VersioningStrategy.ts +27 -27
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestia/core",
3
- "version": "11.0.0-dev.20260312",
3
+ "version": "11.0.0-dev.20260313-2",
4
4
  "description": "Super-fast validation decorators of NestJS",
5
5
  "main": "lib/index.js",
6
6
  "exports": {
@@ -39,9 +39,9 @@
39
39
  },
40
40
  "homepage": "https://nestia.io",
41
41
  "dependencies": {
42
- "@typia/core": "12.0.0-dev.20260312-2",
43
- "@typia/interface": "12.0.0-dev.20260312-2",
44
- "@typia/utils": "12.0.0-dev.20260312-2",
42
+ "@typia/core": "12.0.0-dev.20260313",
43
+ "@typia/interface": "12.0.0-dev.20260313",
44
+ "@typia/utils": "12.0.0-dev.20260313",
45
45
  "detect-ts-node": "^1.0.5",
46
46
  "get-function-location": "^2.0.0",
47
47
  "glob": "^11.0.3",
@@ -50,17 +50,17 @@
50
50
  "reflect-metadata": ">=0.1.12",
51
51
  "rxjs": ">=6.0.3",
52
52
  "tgrid": "^1.1.0",
53
- "typia": "12.0.0-dev.20260312-2",
53
+ "typia": "12.0.0-dev.20260313",
54
54
  "ws": "^7.5.3",
55
- "@nestia/fetcher": "^11.0.0-dev.20260312"
55
+ "@nestia/fetcher": "^11.0.0-dev.20260313-2"
56
56
  },
57
57
  "peerDependencies": {
58
58
  "@nestjs/common": ">=7.0.1",
59
59
  "@nestjs/core": ">=7.0.1",
60
60
  "reflect-metadata": ">=0.1.12",
61
61
  "rxjs": ">=6.0.3",
62
- "typia": "12.0.0-dev.20260312-2",
63
- "@nestia/fetcher": "^11.0.0-dev.20260312"
62
+ "typia": "12.0.0-dev.20260313",
63
+ "@nestia/fetcher": "^11.0.0-dev.20260313-2"
64
64
  },
65
65
  "devDependencies": {
66
66
  "@nestjs/common": "^11.1.4",
@@ -1,44 +1,44 @@
1
- import { Module } from "@nestjs/common";
2
- import { ModuleMetadata } from "@nestjs/common/interfaces";
3
-
4
- import { Creator } from "../typings/Creator";
5
- import { load_controllers } from "./internal/load_controller";
6
-
7
- /**
8
- * Dynamic module.
9
- *
10
- * `DynamicModule` is a namespace wrapping a convenient function, which can load
11
- * controller classes dynamically just by specifying their directory path.
12
- *
13
- * @author Jeongho Nam - https://github.com/samchon
14
- */
15
- export namespace DynamicModule {
16
- /**
17
- * Mount dynamic module.
18
- *
19
- * Constructs a module instance with directory path of controller classes.
20
- *
21
- * Every controller classes in the target directory would be dynamically
22
- * mounted.
23
- *
24
- * @param path Path of controllers
25
- * @param metadata Additional metadata except controllers
26
- * @returns Module instance
27
- */
28
- export async function mount(
29
- path: string | string[] | { include: string[]; exclude?: string[] },
30
- metadata: Omit<ModuleMetadata, "controllers"> = {},
31
- isTsNode?: boolean,
32
- ) {
33
- // LOAD CONTROLLERS
34
- const controllers: Creator<object>[] = await load_controllers(
35
- path,
36
- isTsNode,
37
- );
38
-
39
- // RETURN WITH DECORATING
40
- @Module({ ...metadata, controllers })
41
- class NestiaModule {}
42
- return NestiaModule;
43
- }
44
- }
1
+ import { Module } from "@nestjs/common";
2
+ import { ModuleMetadata } from "@nestjs/common/interfaces";
3
+
4
+ import { Creator } from "../typings/Creator";
5
+ import { load_controllers } from "./internal/load_controller";
6
+
7
+ /**
8
+ * Dynamic module.
9
+ *
10
+ * `DynamicModule` is a namespace wrapping a convenient function, which can load
11
+ * controller classes dynamically just by specifying their directory path.
12
+ *
13
+ * @author Jeongho Nam - https://github.com/samchon
14
+ */
15
+ export namespace DynamicModule {
16
+ /**
17
+ * Mount dynamic module.
18
+ *
19
+ * Constructs a module instance with directory path of controller classes.
20
+ *
21
+ * Every controller classes in the target directory would be dynamically
22
+ * mounted.
23
+ *
24
+ * @param path Path of controllers
25
+ * @param metadata Additional metadata except controllers
26
+ * @returns Module instance
27
+ */
28
+ export async function mount(
29
+ path: string | string[] | { include: string[]; exclude?: string[] },
30
+ metadata: Omit<ModuleMetadata, "controllers"> = {},
31
+ isTsNode?: boolean,
32
+ ) {
33
+ // LOAD CONTROLLERS
34
+ const controllers: Creator<object>[] = await load_controllers(
35
+ path,
36
+ isTsNode,
37
+ );
38
+
39
+ // RETURN WITH DECORATING
40
+ @Module({ ...metadata, controllers })
41
+ class NestiaModule {}
42
+ return NestiaModule;
43
+ }
44
+ }
@@ -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");
@@ -1,100 +1,100 @@
1
- export namespace SwaggerExample {
2
- export function Response<T>(value: T): MethodDecorator;
3
- export function Response<T>(key: string, value: T): MethodDecorator;
4
- export function Response(...args: any[]): MethodDecorator {
5
- return function SwaggerExampleResponse(
6
- _target: Object,
7
- _propertyKey: string | symbol,
8
- descriptor: TypedPropertyDescriptor<any>,
9
- ): TypedPropertyDescriptor<any> {
10
- emplaceValue(emplaceOfResponse(descriptor))(args);
11
- return descriptor;
12
- };
13
- }
14
-
15
- export function Parameter<T>(value: T): ParameterDecorator;
16
- export function Parameter<T>(key: string, value: T): ParameterDecorator;
17
- export function Parameter(...args: any[]): ParameterDecorator {
18
- return function SwaggerExampleParameter(
19
- target: Object,
20
- propertyKey: string | symbol | undefined,
21
- index: number,
22
- ): void {
23
- emplaceValue(emplaceOfParameter(target, propertyKey ?? "", index))(args);
24
- };
25
- }
26
-
27
- export interface IData<T> {
28
- examples?: Record<string, T>;
29
- example?: T;
30
- index?: number;
31
- }
32
- }
33
-
34
- const emplaceValue =
35
- <T>(data: SwaggerExample.IData<T>) =>
36
- (args: any[]) => {
37
- if (args.length === 1) data.example = args[0];
38
- else {
39
- const key: string = args[0];
40
- const value: T = args[1];
41
- data.examples ??= {};
42
- data.examples[key] = value;
43
- }
44
- };
45
-
46
- const emplaceOfResponse = <T>(
47
- descriptor: TypedPropertyDescriptor<any>,
48
- ): SwaggerExample.IData<T> => {
49
- const oldbie: SwaggerExample.IData<T> | undefined = Reflect.getMetadata(
50
- "nestia/SwaggerExample/Response",
51
- descriptor.value,
52
- );
53
- if (oldbie !== undefined) return oldbie;
54
- const newbie: SwaggerExample.IData<T> = {};
55
- Reflect.defineMetadata(
56
- "nestia/SwaggerExample/Response",
57
- newbie,
58
- descriptor.value,
59
- );
60
- return newbie;
61
- };
62
-
63
- const emplaceOfParameter = (
64
- target: Object,
65
- propertyKey: string | symbol,
66
- index: number,
67
- ): SwaggerExample.IData<any> => {
68
- const array: SwaggerExample.IData<any>[] = emplaceArrayOfParameters(
69
- target,
70
- propertyKey,
71
- );
72
- const oldibe: SwaggerExample.IData<any> | undefined = array.find(
73
- (e) => e.index === index,
74
- );
75
- if (oldibe !== undefined) return oldibe;
76
-
77
- const data: SwaggerExample.IData<any> = { index };
78
- array.push(data);
79
- return data;
80
- };
81
-
82
- const emplaceArrayOfParameters = (
83
- target: Object,
84
- propertyKey: string | symbol,
85
- ): SwaggerExample.IData<any>[] => {
86
- const array: SwaggerExample.IData<any>[] | undefined = Reflect.getMetadata(
87
- "nestia/SwaggerExample/Parameters",
88
- target,
89
- propertyKey,
90
- );
91
- if (array !== undefined) return array;
92
- const newbie: SwaggerExample.IData<any>[] = [];
93
- Reflect.defineMetadata(
94
- "nestia/SwaggerExample/Parameters",
95
- newbie,
96
- target,
97
- propertyKey,
98
- );
99
- return newbie;
100
- };
1
+ export namespace SwaggerExample {
2
+ export function Response<T>(value: T): MethodDecorator;
3
+ export function Response<T>(key: string, value: T): MethodDecorator;
4
+ export function Response(...args: any[]): MethodDecorator {
5
+ return function SwaggerExampleResponse(
6
+ _target: Object,
7
+ _propertyKey: string | symbol,
8
+ descriptor: TypedPropertyDescriptor<any>,
9
+ ): TypedPropertyDescriptor<any> {
10
+ emplaceValue(emplaceOfResponse(descriptor))(args);
11
+ return descriptor;
12
+ };
13
+ }
14
+
15
+ export function Parameter<T>(value: T): ParameterDecorator;
16
+ export function Parameter<T>(key: string, value: T): ParameterDecorator;
17
+ export function Parameter(...args: any[]): ParameterDecorator {
18
+ return function SwaggerExampleParameter(
19
+ target: Object,
20
+ propertyKey: string | symbol | undefined,
21
+ index: number,
22
+ ): void {
23
+ emplaceValue(emplaceOfParameter(target, propertyKey ?? "", index))(args);
24
+ };
25
+ }
26
+
27
+ export interface IData<T> {
28
+ examples?: Record<string, T>;
29
+ example?: T;
30
+ index?: number;
31
+ }
32
+ }
33
+
34
+ const emplaceValue =
35
+ <T>(data: SwaggerExample.IData<T>) =>
36
+ (args: any[]) => {
37
+ if (args.length === 1) data.example = args[0];
38
+ else {
39
+ const key: string = args[0];
40
+ const value: T = args[1];
41
+ data.examples ??= {};
42
+ data.examples[key] = value;
43
+ }
44
+ };
45
+
46
+ const emplaceOfResponse = <T>(
47
+ descriptor: TypedPropertyDescriptor<any>,
48
+ ): SwaggerExample.IData<T> => {
49
+ const oldbie: SwaggerExample.IData<T> | undefined = Reflect.getMetadata(
50
+ "nestia/SwaggerExample/Response",
51
+ descriptor.value,
52
+ );
53
+ if (oldbie !== undefined) return oldbie;
54
+ const newbie: SwaggerExample.IData<T> = {};
55
+ Reflect.defineMetadata(
56
+ "nestia/SwaggerExample/Response",
57
+ newbie,
58
+ descriptor.value,
59
+ );
60
+ return newbie;
61
+ };
62
+
63
+ const emplaceOfParameter = (
64
+ target: Object,
65
+ propertyKey: string | symbol,
66
+ index: number,
67
+ ): SwaggerExample.IData<any> => {
68
+ const array: SwaggerExample.IData<any>[] = emplaceArrayOfParameters(
69
+ target,
70
+ propertyKey,
71
+ );
72
+ const oldibe: SwaggerExample.IData<any> | undefined = array.find(
73
+ (e) => e.index === index,
74
+ );
75
+ if (oldibe !== undefined) return oldibe;
76
+
77
+ const data: SwaggerExample.IData<any> = { index };
78
+ array.push(data);
79
+ return data;
80
+ };
81
+
82
+ const emplaceArrayOfParameters = (
83
+ target: Object,
84
+ propertyKey: string | symbol,
85
+ ): SwaggerExample.IData<any>[] => {
86
+ const array: SwaggerExample.IData<any>[] | undefined = Reflect.getMetadata(
87
+ "nestia/SwaggerExample/Parameters",
88
+ target,
89
+ propertyKey,
90
+ );
91
+ if (array !== undefined) return array;
92
+ const newbie: SwaggerExample.IData<any>[] = [];
93
+ Reflect.defineMetadata(
94
+ "nestia/SwaggerExample/Parameters",
95
+ newbie,
96
+ target,
97
+ propertyKey,
98
+ );
99
+ return newbie;
100
+ };
@@ -1,57 +1,57 @@
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 { IRequestBodyValidator } from "../options/IRequestBodyValidator";
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
- * Type safe body decorator.
15
- *
16
- * `TypedBody` is a decorator function getting `application/json` typed data
17
- * from request body. Also, it validates the request body data type through
18
- * [typia](https://github.com/samchon/typia) and the validation speed is maximum
19
- * 20,000x times faster than `class-validator`.
20
- *
21
- * For reference, when the request body data is not following the promised type
22
- * `T`, `BadRequestException` error (status code: 400) would be thrown.
23
- *
24
- * @author Jeongho Nam - https://github.com/samchon
25
- * @param validator Custom validator if required. Default is `typia.assert()`
26
- */
27
- export function TypedBody<T>(
28
- validator?: IRequestBodyValidator<T>,
29
- ): ParameterDecorator {
30
- const checker = validate_request_body("TypedBody")(validator);
31
- return createParamDecorator(function TypedBody(
32
- _unknown: any,
33
- context: ExecutionContext,
34
- ) {
35
- const request: express.Request | FastifyRequest = context
36
- .switchToHttp()
37
- .getRequest();
38
- if (is_request_body_undefined(request) && checker(undefined as T) === null)
39
- return undefined;
40
- else if (isApplicationJson(request.headers["content-type"]) === false)
41
- throw new BadRequestException(
42
- `Request body type is not "application/json".`,
43
- );
44
-
45
- const error: Error | null = checker(request.body);
46
- if (error !== null) throw error;
47
- return request.body;
48
- })();
49
- }
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");
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 { IRequestBodyValidator } from "../options/IRequestBodyValidator";
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
+ * Type safe body decorator.
15
+ *
16
+ * `TypedBody` is a decorator function getting `application/json` typed data
17
+ * from request body. Also, it validates the request body data type through
18
+ * [typia](https://github.com/samchon/typia) and the validation speed is maximum
19
+ * 20,000x times faster than `class-validator`.
20
+ *
21
+ * For reference, when the request body data is not following the promised type
22
+ * `T`, `BadRequestException` error (status code: 400) would be thrown.
23
+ *
24
+ * @author Jeongho Nam - https://github.com/samchon
25
+ * @param validator Custom validator if required. Default is `typia.assert()`
26
+ */
27
+ export function TypedBody<T>(
28
+ validator?: IRequestBodyValidator<T>,
29
+ ): ParameterDecorator {
30
+ const checker = validate_request_body("TypedBody")(validator);
31
+ return createParamDecorator(function TypedBody(
32
+ _unknown: any,
33
+ context: ExecutionContext,
34
+ ) {
35
+ const request: express.Request | FastifyRequest = context
36
+ .switchToHttp()
37
+ .getRequest();
38
+ if (is_request_body_undefined(request) && checker(undefined as T) === null)
39
+ return undefined;
40
+ else if (isApplicationJson(request.headers["content-type"]) === false)
41
+ throw new BadRequestException(
42
+ `Request body type is not "application/json".`,
43
+ );
44
+
45
+ const error: Error | null = checker(request.body);
46
+ if (error !== null) throw error;
47
+ return request.body;
48
+ })();
49
+ }
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");