@nestia/core 3.0.0-dev.20231209 → 3.0.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 (132) hide show
  1. package/README.md +12 -9
  2. package/lib/decorators/DynamicModule.js +3 -3
  3. package/lib/decorators/DynamicModule.js.map +1 -1
  4. package/lib/decorators/EncryptedBody.js +14 -13
  5. package/lib/decorators/EncryptedBody.js.map +1 -1
  6. package/lib/decorators/EncryptedModule.d.ts +1 -1
  7. package/lib/decorators/EncryptedModule.js +45 -21
  8. package/lib/decorators/EncryptedModule.js.map +1 -1
  9. package/lib/decorators/EncryptedRoute.d.ts +5 -5
  10. package/lib/decorators/EncryptedRoute.js +12 -29
  11. package/lib/decorators/EncryptedRoute.js.map +1 -1
  12. package/lib/decorators/PlainBody.js +3 -0
  13. package/lib/decorators/PlainBody.js.map +1 -1
  14. package/lib/decorators/SwaggerCustomizer.d.ts +79 -0
  15. package/lib/decorators/SwaggerCustomizer.js +32 -0
  16. package/lib/decorators/SwaggerCustomizer.js.map +1 -0
  17. package/lib/decorators/TypedBody.js +3 -0
  18. package/lib/decorators/TypedBody.js.map +1 -1
  19. package/lib/decorators/TypedException.d.ts +0 -1
  20. package/lib/decorators/TypedException.js +0 -1
  21. package/lib/decorators/TypedException.js.map +1 -1
  22. package/lib/decorators/TypedFormData.d.ts +60 -0
  23. package/lib/decorators/TypedFormData.js +403 -0
  24. package/lib/decorators/TypedFormData.js.map +1 -0
  25. package/lib/decorators/TypedQuery.d.ts +11 -6
  26. package/lib/decorators/TypedQuery.js +6 -1
  27. package/lib/decorators/TypedQuery.js.map +1 -1
  28. package/lib/decorators/TypedRoute.d.ts +5 -5
  29. package/lib/decorators/internal/get_path_and_querify.js +3 -0
  30. package/lib/decorators/internal/get_path_and_querify.js.map +1 -1
  31. package/lib/decorators/internal/load_controller.js.map +1 -1
  32. package/lib/decorators/internal/validate_request_body.d.ts +1 -3
  33. package/lib/decorators/internal/validate_request_body.js +15 -0
  34. package/lib/decorators/internal/validate_request_body.js.map +1 -1
  35. package/lib/decorators/internal/validate_request_form_data.js +79 -0
  36. package/lib/decorators/internal/validate_request_form_data.js.map +1 -0
  37. package/lib/decorators/internal/validate_request_headers.d.ts +1 -3
  38. package/lib/decorators/internal/validate_request_headers.js +15 -0
  39. package/lib/decorators/internal/validate_request_headers.js.map +1 -1
  40. package/lib/decorators/internal/validate_request_query.d.ts +1 -3
  41. package/lib/decorators/internal/validate_request_query.js +15 -0
  42. package/lib/decorators/internal/validate_request_query.js.map +1 -1
  43. package/lib/module.d.ts +2 -0
  44. package/lib/module.js +2 -0
  45. package/lib/module.js.map +1 -1
  46. package/lib/options/IRequestFormDataProps.d.ts +23 -0
  47. package/lib/options/IRequestFormDataProps.js +3 -0
  48. package/lib/options/IRequestFormDataProps.js.map +1 -0
  49. package/lib/programmers/PlainBodyProgrammer.js +1 -1
  50. package/lib/programmers/PlainBodyProgrammer.js.map +1 -1
  51. package/lib/programmers/TypedExceptionProgrammer.js +5 -5
  52. package/lib/programmers/TypedExceptionProgrammer.js.map +1 -1
  53. package/lib/programmers/TypedFormDataBodyProgrammer.d.ts +6 -0
  54. package/lib/programmers/TypedFormDataBodyProgrammer.js +84 -0
  55. package/lib/programmers/TypedFormDataBodyProgrammer.js.map +1 -0
  56. package/lib/programmers/http/HttpQuerifyProgrammer.js +2 -2
  57. package/lib/programmers/http/HttpQuerifyProgrammer.js.map +1 -1
  58. package/lib/transformers/NodeTransformer.js.map +1 -1
  59. package/lib/transformers/ParameterDecoratorTransformer.js +7 -1
  60. package/lib/transformers/ParameterDecoratorTransformer.js.map +1 -1
  61. package/lib/transformers/TypedExceptionTransformer.js +1 -1
  62. package/lib/transformers/TypedExceptionTransformer.js.map +1 -1
  63. package/lib/transformers/TypedRouteTransformer.js +1 -1
  64. package/lib/transformers/TypedRouteTransformer.js.map +1 -1
  65. package/package.json +15 -16
  66. package/src/decorators/DynamicModule.ts +39 -39
  67. package/src/decorators/EncryptedBody.ts +105 -107
  68. package/src/decorators/EncryptedController.ts +38 -38
  69. package/src/decorators/EncryptedModule.ts +96 -79
  70. package/src/decorators/EncryptedRoute.ts +182 -206
  71. package/src/decorators/PlainBody.ts +75 -72
  72. package/src/decorators/SwaggerCustomizer.ts +115 -0
  73. package/src/decorators/TypedBody.ts +62 -59
  74. package/src/decorators/TypedException.ts +90 -89
  75. package/src/decorators/TypedFormData.ts +219 -0
  76. package/src/decorators/TypedHeaders.ts +69 -69
  77. package/src/decorators/TypedParam.ts +65 -65
  78. package/src/decorators/TypedQuery.ts +251 -246
  79. package/src/decorators/TypedRoute.ts +144 -144
  80. package/src/decorators/internal/EncryptedConstant.ts +4 -4
  81. package/src/decorators/internal/NoTransformConfigureError.ts +8 -8
  82. package/src/decorators/internal/get_path_and_querify.ts +106 -103
  83. package/src/decorators/internal/get_path_and_stringify.ts +91 -91
  84. package/src/decorators/internal/get_text_body.ts +20 -20
  85. package/src/decorators/internal/headers_to_object.ts +13 -13
  86. package/src/decorators/internal/load_controller.ts +51 -51
  87. package/src/decorators/internal/route_error.ts +45 -45
  88. package/src/decorators/internal/validate_request_body.ts +72 -57
  89. package/src/decorators/internal/validate_request_form_data.ts +75 -0
  90. package/src/decorators/internal/validate_request_headers.ts +83 -68
  91. package/src/decorators/internal/validate_request_query.ts +71 -56
  92. package/src/index.ts +5 -5
  93. package/src/module.ts +16 -14
  94. package/src/options/INestiaTransformOptions.ts +17 -17
  95. package/src/options/INestiaTransformProject.ts +7 -7
  96. package/src/options/IRequestBodyValidator.ts +20 -20
  97. package/src/options/IRequestFormDataProps.ts +27 -0
  98. package/src/options/IRequestHeadersValidator.ts +22 -22
  99. package/src/options/IRequestQueryValidator.ts +20 -20
  100. package/src/options/IResponseBodyQuerifier.ts +25 -25
  101. package/src/options/IResponseBodyStringifier.ts +25 -25
  102. package/src/programmers/PlainBodyProgrammer.ts +52 -52
  103. package/src/programmers/TypedBodyProgrammer.ts +108 -108
  104. package/src/programmers/TypedExceptionProgrammer.ts +71 -72
  105. package/src/programmers/TypedFormDataBodyProgrammer.ts +108 -0
  106. package/src/programmers/TypedHeadersProgrammer.ts +56 -56
  107. package/src/programmers/TypedParamProgrammer.ts +24 -24
  108. package/src/programmers/TypedQueryBodyProgrammer.ts +56 -56
  109. package/src/programmers/TypedQueryProgrammer.ts +56 -56
  110. package/src/programmers/TypedQueryRouteProgrammer.ts +51 -51
  111. package/src/programmers/TypedRouteProgrammer.ts +51 -51
  112. package/src/programmers/http/HttpAssertQuerifyProgrammer.ts +58 -58
  113. package/src/programmers/http/HttpIsQuerifyProgrammer.ts +62 -62
  114. package/src/programmers/http/HttpQuerifyProgrammer.ts +96 -96
  115. package/src/programmers/http/HttpValidateQuerifyProgrammer.ts +63 -63
  116. package/src/programmers/internal/CoreMetadataUtil.ts +21 -21
  117. package/src/transform.ts +35 -35
  118. package/src/transformers/FileTransformer.ts +66 -66
  119. package/src/transformers/MethodTransformer.ts +94 -94
  120. package/src/transformers/NodeTransformer.ts +16 -16
  121. package/src/transformers/ParameterDecoratorTransformer.ts +120 -121
  122. package/src/transformers/ParameterTransformer.ts +48 -48
  123. package/src/transformers/TypedExceptionTransformer.ts +48 -49
  124. package/src/transformers/TypedRouteTransformer.ts +88 -95
  125. package/src/typings/Creator.ts +3 -3
  126. package/src/utils/ExceptionManager.ts +112 -112
  127. package/src/utils/Singleton.ts +20 -20
  128. package/src/utils/SourceFinder.ts +57 -57
  129. package/lib/decorators/internal/get_binary_body.js +0 -66
  130. package/lib/decorators/internal/get_binary_body.js.map +0 -1
  131. package/src/decorators/internal/get_binary_body.ts +0 -18
  132. /package/lib/decorators/internal/{get_binary_body.d.ts → validate_request_form_data.d.ts} +0 -0
@@ -1,144 +1,144 @@
1
- import {
2
- CallHandler,
3
- Delete,
4
- ExecutionContext,
5
- Get,
6
- NestInterceptor,
7
- Patch,
8
- Post,
9
- Put,
10
- UseInterceptors,
11
- applyDecorators,
12
- } from "@nestjs/common";
13
- import { HttpArgumentsHost } from "@nestjs/common/interfaces";
14
- import express from "express";
15
- import { catchError, map } from "rxjs/operators";
16
- import typia from "typia";
17
-
18
- import { IResponseBodyStringifier } from "../options/IResponseBodyStringifier";
19
- import { get_path_and_stringify } from "./internal/get_path_and_stringify";
20
- import { route_error } from "./internal/route_error";
21
-
22
- /**
23
- * Type safe router decorator functions.
24
- *
25
- * `TypedRoute` is a module containing router decorator functions which can boost up
26
- * JSON string conversion speed about 200x times faster than `class-transformer`.
27
- * Furthermore, such JSON string conversion is even type safe through
28
- * [typia](https://github.com/samchon/typia).
29
- *
30
- * For reference, if you try to invalid data that is not following the promised
31
- * type `T`, 500 internal server error would be thrown. Also, as `TypedRoute` composes
32
- * JSON string through `typia.assertStringify<T>()` function, it is not possible to
33
- * modify response data through interceptors.
34
- *
35
- * @author Jeongho Nam - https://github.com/samchon
36
- */
37
- export namespace TypedRoute {
38
- /**
39
- * Router decorator function for the GET method.
40
- *
41
- * @param path Path of the HTTP request
42
- * @returns Method decorator
43
- */
44
- export const Get = Generator("Get");
45
-
46
- /**
47
- * Router decorator function for the POST method.
48
- *
49
- * @param path Path of the HTTP request
50
- * @returns Method decorator
51
- */
52
- export const Post = Generator("Post");
53
-
54
- /**
55
- * Router decorator function for the PATH method.
56
- *
57
- * @param path Path of the HTTP request
58
- * @returns Method decorator
59
- */
60
- export const Patch = Generator("Patch");
61
-
62
- /**
63
- * Router decorator function for the PUT method.
64
- *
65
- * @param path Path of the HTTP request
66
- * @returns Method decorator
67
- */
68
- export const Put = Generator("Put");
69
-
70
- /**
71
- * Router decorator function for the DELETE method.
72
- *
73
- * @param path Path of the HTTP request
74
- * @returns Method decorator
75
- */
76
- export const Delete = Generator("Delete");
77
-
78
- /**
79
- * @internal
80
- */
81
- function Generator(method: "Get" | "Post" | "Put" | "Patch" | "Delete") {
82
- function route(path?: string | string[]): MethodDecorator;
83
- function route<T>(stringify?: IResponseBodyStringifier<T>): MethodDecorator;
84
- function route<T>(
85
- path: string | string[],
86
- stringify?: IResponseBodyStringifier<T>,
87
- ): MethodDecorator;
88
-
89
- function route(...args: any[]): MethodDecorator {
90
- const [path, stringify] = get_path_and_stringify(`TypedRoute.${method}`)(
91
- ...args,
92
- );
93
- return applyDecorators(
94
- ROUTERS[method](path),
95
- UseInterceptors(new TypedRouteInterceptor(stringify)),
96
- );
97
- }
98
- return route;
99
- }
100
- }
101
- for (const method of [
102
- typia.json.stringify,
103
- typia.json.isStringify,
104
- typia.json.assertStringify,
105
- typia.json.validateStringify,
106
- ])
107
- for (const [key, value] of Object.entries(method))
108
- for (const deco of [
109
- TypedRoute.Get,
110
- TypedRoute.Delete,
111
- TypedRoute.Post,
112
- TypedRoute.Put,
113
- TypedRoute.Patch,
114
- ])
115
- (deco as any)[key] = value;
116
-
117
- /**
118
- * @internal
119
- */
120
- class TypedRouteInterceptor implements NestInterceptor {
121
- public constructor(private readonly stringify: (input: any) => string) {}
122
-
123
- public intercept(context: ExecutionContext, next: CallHandler) {
124
- const http: HttpArgumentsHost = context.switchToHttp();
125
- const response: express.Response = http.getResponse();
126
- response.header("Content-Type", "application/json");
127
-
128
- return next.handle().pipe(
129
- map((value) => this.stringify(value)),
130
- catchError((err) => route_error(http.getRequest(), err)),
131
- );
132
- }
133
- }
134
-
135
- /**
136
- * @internal
137
- */
138
- const ROUTERS = {
139
- Get,
140
- Post,
141
- Patch,
142
- Put,
143
- Delete,
144
- };
1
+ import {
2
+ CallHandler,
3
+ Delete,
4
+ ExecutionContext,
5
+ Get,
6
+ NestInterceptor,
7
+ Patch,
8
+ Post,
9
+ Put,
10
+ UseInterceptors,
11
+ applyDecorators,
12
+ } from "@nestjs/common";
13
+ import { HttpArgumentsHost } from "@nestjs/common/interfaces";
14
+ import type express from "express";
15
+ import { catchError, map } from "rxjs/operators";
16
+ import typia from "typia";
17
+
18
+ import { IResponseBodyStringifier } from "../options/IResponseBodyStringifier";
19
+ import { get_path_and_stringify } from "./internal/get_path_and_stringify";
20
+ import { route_error } from "./internal/route_error";
21
+
22
+ /**
23
+ * Type safe router decorator functions.
24
+ *
25
+ * `TypedRoute` is a module containing router decorator functions which can boost up
26
+ * JSON string conversion speed about 200x times faster than `class-transformer`.
27
+ * Furthermore, such JSON string conversion is even type safe through
28
+ * [typia](https://github.com/samchon/typia).
29
+ *
30
+ * For reference, if you try to invalid data that is not following the promised
31
+ * type `T`, 500 internal server error would be thrown. Also, as `TypedRoute` composes
32
+ * JSON string through `typia.assertStringify<T>()` function, it is not possible to
33
+ * modify response data through interceptors.
34
+ *
35
+ * @author Jeongho Nam - https://github.com/samchon
36
+ */
37
+ export namespace TypedRoute {
38
+ /**
39
+ * Router decorator function for the GET method.
40
+ *
41
+ * @param path Path of the HTTP request
42
+ * @returns Method decorator
43
+ */
44
+ export const Get = Generator("Get");
45
+
46
+ /**
47
+ * Router decorator function for the POST method.
48
+ *
49
+ * @param path Path of the HTTP request
50
+ * @returns Method decorator
51
+ */
52
+ export const Post = Generator("Post");
53
+
54
+ /**
55
+ * Router decorator function for the PATH method.
56
+ *
57
+ * @param path Path of the HTTP request
58
+ * @returns Method decorator
59
+ */
60
+ export const Patch = Generator("Patch");
61
+
62
+ /**
63
+ * Router decorator function for the PUT method.
64
+ *
65
+ * @param path Path of the HTTP request
66
+ * @returns Method decorator
67
+ */
68
+ export const Put = Generator("Put");
69
+
70
+ /**
71
+ * Router decorator function for the DELETE method.
72
+ *
73
+ * @param path Path of the HTTP request
74
+ * @returns Method decorator
75
+ */
76
+ export const Delete = Generator("Delete");
77
+
78
+ /**
79
+ * @internal
80
+ */
81
+ function Generator(method: "Get" | "Post" | "Put" | "Patch" | "Delete") {
82
+ function route(path?: string | string[]): MethodDecorator;
83
+ function route<T>(stringify?: IResponseBodyStringifier<T>): MethodDecorator;
84
+ function route<T>(
85
+ path: string | string[],
86
+ stringify?: IResponseBodyStringifier<T>,
87
+ ): MethodDecorator;
88
+
89
+ function route(...args: any[]): MethodDecorator {
90
+ const [path, stringify] = get_path_and_stringify(`TypedRoute.${method}`)(
91
+ ...args,
92
+ );
93
+ return applyDecorators(
94
+ ROUTERS[method](path),
95
+ UseInterceptors(new TypedRouteInterceptor(stringify)),
96
+ );
97
+ }
98
+ return route;
99
+ }
100
+ }
101
+ for (const method of [
102
+ typia.json.stringify,
103
+ typia.json.isStringify,
104
+ typia.json.assertStringify,
105
+ typia.json.validateStringify,
106
+ ])
107
+ for (const [key, value] of Object.entries(method))
108
+ for (const deco of [
109
+ TypedRoute.Get,
110
+ TypedRoute.Delete,
111
+ TypedRoute.Post,
112
+ TypedRoute.Put,
113
+ TypedRoute.Patch,
114
+ ])
115
+ (deco as any)[key] = value;
116
+
117
+ /**
118
+ * @internal
119
+ */
120
+ class TypedRouteInterceptor implements NestInterceptor {
121
+ public constructor(private readonly stringify: (input: any) => string) {}
122
+
123
+ public intercept(context: ExecutionContext, next: CallHandler) {
124
+ const http: HttpArgumentsHost = context.switchToHttp();
125
+ const response: express.Response = http.getResponse();
126
+ response.header("Content-Type", "application/json");
127
+
128
+ return next.handle().pipe(
129
+ map((value) => this.stringify(value)),
130
+ catchError((err) => route_error(http.getRequest(), err)),
131
+ );
132
+ }
133
+ }
134
+
135
+ /**
136
+ * @internal
137
+ */
138
+ const ROUTERS = {
139
+ Get,
140
+ Post,
141
+ Patch,
142
+ Put,
143
+ Delete,
144
+ };
@@ -1,4 +1,4 @@
1
- /**
2
- * @internal
3
- */
4
- export const ENCRYPTION_METADATA_KEY = "nestia:core:encryption:password";
1
+ /**
2
+ * @internal
3
+ */
4
+ export const ENCRYPTION_METADATA_KEY = "nestia:core:encryption:password";
@@ -1,8 +1,8 @@
1
- /**
2
- * @internal
3
- */
4
- export function NoTransformConfigureError(method: string): Error {
5
- return new Error(
6
- `Error on nestia.core.${method}(): no transform has been configured. Run "npx typia setup" command, or check if you're using non-standard TypeScript compiler like Babel or SWC.`,
7
- );
8
- }
1
+ /**
2
+ * @internal
3
+ */
4
+ export function NoTransformConfigureError(method: string): Error {
5
+ return new Error(
6
+ `Error on nestia.core.${method}(): no transform has been configured. Run "npx typia setup" command, or check if you're using non-standard TypeScript compiler like Babel or SWC.`,
7
+ );
8
+ }
@@ -1,103 +1,106 @@
1
- import { InternalServerErrorException } from "@nestjs/common";
2
- import typia, { IValidation, TypeGuardError } from "typia";
3
-
4
- import { IResponseBodyQuerifier } from "../../options/IResponseBodyQuerifier";
5
- import { NoTransformConfigureError } from "./NoTransformConfigureError";
6
-
7
- /**
8
- * @internal
9
- */
10
- export const get_path_and_querify =
11
- (method: string) =>
12
- (
13
- ...args: any[]
14
- ): [string | string[] | undefined, (input: any) => URLSearchParams] => {
15
- const path: string | string[] | null | undefined =
16
- args[0] === undefined ||
17
- typeof args[0] === "string" ||
18
- Array.isArray(args[0])
19
- ? args[0]
20
- : null;
21
- const functor: IResponseBodyQuerifier<any> | undefined =
22
- path === null ? args[0] : args[1];
23
- return [path ?? undefined, take(method)(functor)];
24
- };
25
-
26
- /**
27
- * @internal
28
- */
29
- const take =
30
- (method: string) =>
31
- <T>(functor?: IResponseBodyQuerifier<T> | null) => {
32
- if (functor === undefined) throw NoTransformConfigureError(method);
33
- else if (functor === null) return querify;
34
- else if (functor.type === "stringify") return functor.stringify;
35
- else if (functor.type === "assert") return assert(functor.assert);
36
- else if (functor.type === "is") return is(functor.is);
37
- else if (functor.type === "validate") return validate(functor.validate);
38
- throw new Error(
39
- `Error on nestia.core.${method}(): invalid typed stringify function.`,
40
- );
41
- };
42
-
43
- const querify = (input: Record<string, any>): URLSearchParams => {
44
- const output: URLSearchParams = new URLSearchParams();
45
- for (const [key, value] of Object.entries(input))
46
- if (key === undefined) continue;
47
- else if (Array.isArray(value))
48
- for (const elem of value) output.append(key, String(elem));
49
- else output.append(key, String(value));
50
- return output;
51
- };
52
-
53
- /**
54
- * @internal
55
- */
56
- const assert =
57
- <T>(closure: (data: T) => URLSearchParams) =>
58
- (data: T) => {
59
- try {
60
- return closure(data);
61
- } catch (exp) {
62
- if (typia.is<TypeGuardError>(exp))
63
- throw new InternalServerErrorException({
64
- path: exp.path,
65
- reason: exp.message,
66
- expected: exp.expected,
67
- value: exp.value,
68
- message: MESSAGE,
69
- });
70
- throw exp;
71
- }
72
- };
73
-
74
- /**
75
- * @internal
76
- */
77
- const is =
78
- <T>(closure: (data: T) => URLSearchParams | null) =>
79
- (data: T) => {
80
- const result: URLSearchParams | null = closure(data);
81
- if (result === null) throw new InternalServerErrorException(MESSAGE);
82
- return result;
83
- };
84
-
85
- /**
86
- * @internal
87
- */
88
- const validate =
89
- <T>(closure: (data: T) => IValidation<URLSearchParams>) =>
90
- (data: T) => {
91
- const result: IValidation<URLSearchParams> = closure(data);
92
- if (result.success === false)
93
- throw new InternalServerErrorException({
94
- errors: result.errors,
95
- message: MESSAGE,
96
- });
97
- return result.data;
98
- };
99
-
100
- /**
101
- * @internal
102
- */
103
- const MESSAGE = "Response body data is not following the promised type.";
1
+ import { InternalServerErrorException } from "@nestjs/common";
2
+ import typia, { IValidation, TypeGuardError } from "typia";
3
+
4
+ import { IResponseBodyQuerifier } from "../../options/IResponseBodyQuerifier";
5
+ import { NoTransformConfigureError } from "./NoTransformConfigureError";
6
+
7
+ /**
8
+ * @internal
9
+ */
10
+ export const get_path_and_querify =
11
+ (method: string) =>
12
+ (
13
+ ...args: any[]
14
+ ): [string | string[] | undefined, (input: any) => URLSearchParams] => {
15
+ const path: string | string[] | null | undefined =
16
+ args[0] === undefined ||
17
+ typeof args[0] === "string" ||
18
+ Array.isArray(args[0])
19
+ ? args[0]
20
+ : null;
21
+ const functor: IResponseBodyQuerifier<any> | undefined =
22
+ path === null ? args[0] : args[1];
23
+ return [path ?? undefined, take(method)(functor)];
24
+ };
25
+
26
+ /**
27
+ * @internal
28
+ */
29
+ const take =
30
+ (method: string) =>
31
+ <T>(functor?: IResponseBodyQuerifier<T> | null) => {
32
+ if (functor === undefined) throw NoTransformConfigureError(method);
33
+ else if (functor === null) return querify;
34
+ else if (functor.type === "stringify") return functor.stringify;
35
+ else if (functor.type === "assert") return assert(functor.assert);
36
+ else if (functor.type === "is") return is(functor.is);
37
+ else if (functor.type === "validate") return validate(functor.validate);
38
+ throw new Error(
39
+ `Error on nestia.core.${method}(): invalid typed stringify function.`,
40
+ );
41
+ };
42
+
43
+ /**
44
+ * @internal
45
+ */
46
+ const querify = (input: Record<string, any>): URLSearchParams => {
47
+ const output: URLSearchParams = new URLSearchParams();
48
+ for (const [key, value] of Object.entries(input))
49
+ if (key === undefined) continue;
50
+ else if (Array.isArray(value))
51
+ for (const elem of value) output.append(key, String(elem));
52
+ else output.append(key, String(value));
53
+ return output;
54
+ };
55
+
56
+ /**
57
+ * @internal
58
+ */
59
+ const assert =
60
+ <T>(closure: (data: T) => URLSearchParams) =>
61
+ (data: T) => {
62
+ try {
63
+ return closure(data);
64
+ } catch (exp) {
65
+ if (typia.is<TypeGuardError>(exp))
66
+ throw new InternalServerErrorException({
67
+ path: exp.path,
68
+ reason: exp.message,
69
+ expected: exp.expected,
70
+ value: exp.value,
71
+ message: MESSAGE,
72
+ });
73
+ throw exp;
74
+ }
75
+ };
76
+
77
+ /**
78
+ * @internal
79
+ */
80
+ const is =
81
+ <T>(closure: (data: T) => URLSearchParams | null) =>
82
+ (data: T) => {
83
+ const result: URLSearchParams | null = closure(data);
84
+ if (result === null) throw new InternalServerErrorException(MESSAGE);
85
+ return result;
86
+ };
87
+
88
+ /**
89
+ * @internal
90
+ */
91
+ const validate =
92
+ <T>(closure: (data: T) => IValidation<URLSearchParams>) =>
93
+ (data: T) => {
94
+ const result: IValidation<URLSearchParams> = closure(data);
95
+ if (result.success === false)
96
+ throw new InternalServerErrorException({
97
+ errors: result.errors,
98
+ message: MESSAGE,
99
+ });
100
+ return result.data;
101
+ };
102
+
103
+ /**
104
+ * @internal
105
+ */
106
+ const MESSAGE = "Response body data is not following the promised type.";