@nestia/core 3.1.0-dev.20240426 → 3.1.0-dev.20240430

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 (67) hide show
  1. package/lib/adaptors/WebSocketAdaptor.js +15 -17
  2. package/lib/adaptors/WebSocketAdaptor.js.map +1 -1
  3. package/lib/transformers/MethodTransformer.js +7 -4
  4. package/lib/transformers/MethodTransformer.js.map +1 -1
  5. package/lib/transformers/TypedExceptionTransformer.js +2 -3
  6. package/lib/transformers/TypedExceptionTransformer.js.map +1 -1
  7. package/lib/transformers/TypedRouteTransformer.js +1 -3
  8. package/lib/transformers/TypedRouteTransformer.js.map +1 -1
  9. package/lib/transformers/WebSocketRouteTransformer.d.ts +6 -0
  10. package/lib/transformers/WebSocketRouteTransformer.js +72 -0
  11. package/lib/transformers/WebSocketRouteTransformer.js.map +1 -0
  12. package/package.json +4 -4
  13. package/src/adaptors/WebSocketAdaptor.ts +19 -17
  14. package/src/decorators/DynamicModule.ts +39 -39
  15. package/src/decorators/EncryptedBody.ts +105 -105
  16. package/src/decorators/EncryptedController.ts +38 -38
  17. package/src/decorators/EncryptedModule.ts +96 -96
  18. package/src/decorators/EncryptedRoute.ts +182 -182
  19. package/src/decorators/PlainBody.ts +75 -75
  20. package/src/decorators/TypedBody.ts +62 -62
  21. package/src/decorators/TypedException.ts +90 -90
  22. package/src/decorators/TypedFormData.ts +219 -219
  23. package/src/decorators/TypedHeaders.ts +69 -69
  24. package/src/decorators/TypedParam.ts +64 -64
  25. package/src/decorators/TypedRoute.ts +144 -144
  26. package/src/decorators/internal/EncryptedConstant.ts +4 -4
  27. package/src/decorators/internal/NoTransformConfigureError.ts +8 -8
  28. package/src/decorators/internal/get_path_and_querify.ts +106 -106
  29. package/src/decorators/internal/get_path_and_stringify.ts +91 -91
  30. package/src/decorators/internal/get_text_body.ts +20 -20
  31. package/src/decorators/internal/headers_to_object.ts +13 -13
  32. package/src/decorators/internal/load_controller.ts +51 -51
  33. package/src/decorators/internal/route_error.ts +45 -45
  34. package/src/index.ts +5 -5
  35. package/src/options/INestiaTransformOptions.ts +17 -17
  36. package/src/options/INestiaTransformProject.ts +7 -7
  37. package/src/options/IRequestBodyValidator.ts +20 -20
  38. package/src/options/IRequestFormDataProps.ts +27 -27
  39. package/src/options/IRequestHeadersValidator.ts +22 -22
  40. package/src/options/IRequestQueryValidator.ts +20 -20
  41. package/src/options/IResponseBodyQuerifier.ts +25 -25
  42. package/src/options/IResponseBodyStringifier.ts +25 -25
  43. package/src/programmers/PlainBodyProgrammer.ts +52 -52
  44. package/src/programmers/TypedBodyProgrammer.ts +108 -108
  45. package/src/programmers/TypedExceptionProgrammer.ts +71 -71
  46. package/src/programmers/TypedHeadersProgrammer.ts +56 -56
  47. package/src/programmers/TypedParamProgrammer.ts +24 -24
  48. package/src/programmers/TypedQueryBodyProgrammer.ts +56 -56
  49. package/src/programmers/TypedQueryProgrammer.ts +56 -56
  50. package/src/programmers/TypedQueryRouteProgrammer.ts +51 -51
  51. package/src/programmers/TypedRouteProgrammer.ts +51 -51
  52. package/src/programmers/http/HttpAssertQuerifyProgrammer.ts +58 -58
  53. package/src/programmers/http/HttpIsQuerifyProgrammer.ts +62 -62
  54. package/src/programmers/http/HttpValidateQuerifyProgrammer.ts +63 -63
  55. package/src/programmers/internal/CoreMetadataUtil.ts +21 -21
  56. package/src/transform.ts +35 -35
  57. package/src/transformers/FileTransformer.ts +66 -66
  58. package/src/transformers/MethodTransformer.ts +97 -94
  59. package/src/transformers/NodeTransformer.ts +16 -16
  60. package/src/transformers/ParameterTransformer.ts +48 -48
  61. package/src/transformers/TypedExceptionTransformer.ts +44 -48
  62. package/src/transformers/TypedRouteTransformer.ts +81 -88
  63. package/src/transformers/WebSocketRouteTransformer.ts +103 -0
  64. package/src/typings/Creator.ts +3 -3
  65. package/src/utils/ExceptionManager.ts +112 -112
  66. package/src/utils/Singleton.ts +20 -20
  67. package/src/utils/SourceFinder.ts +57 -57
@@ -1,17 +1,17 @@
1
- export interface INestiaTransformOptions {
2
- validate?: // NORMAL
3
- | "assert"
4
- | "is"
5
- | "validate"
6
- // STRICT
7
- | "assertEquals"
8
- | "equals"
9
- | "validateEquals"
10
- // CLONE
11
- | "assertClone"
12
- | "validateClone"
13
- // PRUNE
14
- | "assertPrune"
15
- | "validatePrune";
16
- stringify?: "stringify" | "assert" | "is" | "validate" | null;
17
- }
1
+ export interface INestiaTransformOptions {
2
+ validate?: // NORMAL
3
+ | "assert"
4
+ | "is"
5
+ | "validate"
6
+ // STRICT
7
+ | "assertEquals"
8
+ | "equals"
9
+ | "validateEquals"
10
+ // CLONE
11
+ | "assertClone"
12
+ | "validateClone"
13
+ // PRUNE
14
+ | "assertPrune"
15
+ | "validatePrune";
16
+ stringify?: "stringify" | "assert" | "is" | "validate" | null;
17
+ }
@@ -1,7 +1,7 @@
1
- import { IProject } from "typia/lib/transformers/IProject";
2
-
3
- import { INestiaTransformOptions } from "./INestiaTransformOptions";
4
-
5
- export interface INestiaTransformProject extends Omit<IProject, "options"> {
6
- options: INestiaTransformOptions;
7
- }
1
+ import { IProject } from "typia/lib/transformers/IProject";
2
+
3
+ import { INestiaTransformOptions } from "./INestiaTransformOptions";
4
+
5
+ export interface INestiaTransformProject extends Omit<IProject, "options"> {
6
+ options: INestiaTransformOptions;
7
+ }
@@ -1,20 +1,20 @@
1
- import { IValidation } from "typia";
2
-
3
- export type IRequestBodyValidator<T> =
4
- | IRequestBodyValidator.IAssert<T>
5
- | IRequestBodyValidator.IIs<T>
6
- | IRequestBodyValidator.IValidate<T>;
7
- export namespace IRequestBodyValidator {
8
- export interface IAssert<T> {
9
- type: "assert";
10
- assert: (input: T) => T;
11
- }
12
- export interface IIs<T> {
13
- type: "is";
14
- is: (input: T) => boolean;
15
- }
16
- export interface IValidate<T> {
17
- type: "validate";
18
- validate: (input: T) => IValidation<T>;
19
- }
20
- }
1
+ import { IValidation } from "typia";
2
+
3
+ export type IRequestBodyValidator<T> =
4
+ | IRequestBodyValidator.IAssert<T>
5
+ | IRequestBodyValidator.IIs<T>
6
+ | IRequestBodyValidator.IValidate<T>;
7
+ export namespace IRequestBodyValidator {
8
+ export interface IAssert<T> {
9
+ type: "assert";
10
+ assert: (input: T) => T;
11
+ }
12
+ export interface IIs<T> {
13
+ type: "is";
14
+ is: (input: T) => boolean;
15
+ }
16
+ export interface IValidate<T> {
17
+ type: "validate";
18
+ validate: (input: T) => IValidation<T>;
19
+ }
20
+ }
@@ -1,27 +1,27 @@
1
- import { IValidation } from "typia";
2
-
3
- export interface IRequestFormDataProps<T> {
4
- files: Array<IRequestFormDataProps.IFile>;
5
- validator:
6
- | IRequestFormDataProps.IAssert<T>
7
- | IRequestFormDataProps.IIs<T>
8
- | IRequestFormDataProps.IValidate<T>;
9
- }
10
- export namespace IRequestFormDataProps {
11
- export interface IAssert<T> {
12
- type: "assert";
13
- assert: (input: FormData) => T;
14
- }
15
- export interface IIs<T> {
16
- type: "is";
17
- is: (input: FormData) => T | null;
18
- }
19
- export interface IValidate<T> {
20
- type: "validate";
21
- validate: (input: FormData) => IValidation<T>;
22
- }
23
- export interface IFile {
24
- name: string;
25
- limit: number | null;
26
- }
27
- }
1
+ import { IValidation } from "typia";
2
+
3
+ export interface IRequestFormDataProps<T> {
4
+ files: Array<IRequestFormDataProps.IFile>;
5
+ validator:
6
+ | IRequestFormDataProps.IAssert<T>
7
+ | IRequestFormDataProps.IIs<T>
8
+ | IRequestFormDataProps.IValidate<T>;
9
+ }
10
+ export namespace IRequestFormDataProps {
11
+ export interface IAssert<T> {
12
+ type: "assert";
13
+ assert: (input: FormData) => T;
14
+ }
15
+ export interface IIs<T> {
16
+ type: "is";
17
+ is: (input: FormData) => T | null;
18
+ }
19
+ export interface IValidate<T> {
20
+ type: "validate";
21
+ validate: (input: FormData) => IValidation<T>;
22
+ }
23
+ export interface IFile {
24
+ name: string;
25
+ limit: number | null;
26
+ }
27
+ }
@@ -1,22 +1,22 @@
1
- import { IValidation } from "typia";
2
-
3
- export type IRequestHeadersValidator<T> =
4
- | IRequestHeadersValidator.IAssert<T>
5
- | IRequestHeadersValidator.IIs<T>
6
- | IRequestHeadersValidator.IValidate<T>;
7
- export namespace IRequestHeadersValidator {
8
- export interface IAssert<T> {
9
- type: "assert";
10
- assert: (input: Record<string, string | string[] | undefined>) => T;
11
- }
12
- export interface IIs<T> {
13
- type: "is";
14
- is: (input: Record<string, string | string[] | undefined>) => T | null;
15
- }
16
- export interface IValidate<T> {
17
- type: "validate";
18
- validate: (
19
- input: Record<string, string | string[] | undefined>,
20
- ) => IValidation<T>;
21
- }
22
- }
1
+ import { IValidation } from "typia";
2
+
3
+ export type IRequestHeadersValidator<T> =
4
+ | IRequestHeadersValidator.IAssert<T>
5
+ | IRequestHeadersValidator.IIs<T>
6
+ | IRequestHeadersValidator.IValidate<T>;
7
+ export namespace IRequestHeadersValidator {
8
+ export interface IAssert<T> {
9
+ type: "assert";
10
+ assert: (input: Record<string, string | string[] | undefined>) => T;
11
+ }
12
+ export interface IIs<T> {
13
+ type: "is";
14
+ is: (input: Record<string, string | string[] | undefined>) => T | null;
15
+ }
16
+ export interface IValidate<T> {
17
+ type: "validate";
18
+ validate: (
19
+ input: Record<string, string | string[] | undefined>,
20
+ ) => IValidation<T>;
21
+ }
22
+ }
@@ -1,20 +1,20 @@
1
- import { IValidation } from "typia";
2
-
3
- export type IRequestQueryValidator<T> =
4
- | IRequestQueryValidator.IAssert<T>
5
- | IRequestQueryValidator.IIs<T>
6
- | IRequestQueryValidator.IValidate<T>;
7
- export namespace IRequestQueryValidator {
8
- export interface IAssert<T> {
9
- type: "assert";
10
- assert: (input: URLSearchParams) => T;
11
- }
12
- export interface IIs<T> {
13
- type: "is";
14
- is: (input: URLSearchParams) => T | null;
15
- }
16
- export interface IValidate<T> {
17
- type: "validate";
18
- validate: (input: URLSearchParams) => IValidation<T>;
19
- }
20
- }
1
+ import { IValidation } from "typia";
2
+
3
+ export type IRequestQueryValidator<T> =
4
+ | IRequestQueryValidator.IAssert<T>
5
+ | IRequestQueryValidator.IIs<T>
6
+ | IRequestQueryValidator.IValidate<T>;
7
+ export namespace IRequestQueryValidator {
8
+ export interface IAssert<T> {
9
+ type: "assert";
10
+ assert: (input: URLSearchParams) => T;
11
+ }
12
+ export interface IIs<T> {
13
+ type: "is";
14
+ is: (input: URLSearchParams) => T | null;
15
+ }
16
+ export interface IValidate<T> {
17
+ type: "validate";
18
+ validate: (input: URLSearchParams) => IValidation<T>;
19
+ }
20
+ }
@@ -1,25 +1,25 @@
1
- import { IValidation } from "typia";
2
-
3
- export type IResponseBodyQuerifier<T> =
4
- | IResponseBodyquerifier.IStringify<T>
5
- | IResponseBodyquerifier.IIs<T>
6
- | IResponseBodyquerifier.IAssert<T>
7
- | IResponseBodyquerifier.IValidate<T>;
8
- export namespace IResponseBodyquerifier {
9
- export interface IStringify<T> {
10
- type: "stringify";
11
- stringify: (input: T) => URLSearchParams;
12
- }
13
- export interface IIs<T> {
14
- type: "is";
15
- is: (input: T) => URLSearchParams | null;
16
- }
17
- export interface IAssert<T> {
18
- type: "assert";
19
- assert: (input: T) => URLSearchParams;
20
- }
21
- export interface IValidate<T> {
22
- type: "validate";
23
- validate: (input: T) => IValidation<URLSearchParams>;
24
- }
25
- }
1
+ import { IValidation } from "typia";
2
+
3
+ export type IResponseBodyQuerifier<T> =
4
+ | IResponseBodyquerifier.IStringify<T>
5
+ | IResponseBodyquerifier.IIs<T>
6
+ | IResponseBodyquerifier.IAssert<T>
7
+ | IResponseBodyquerifier.IValidate<T>;
8
+ export namespace IResponseBodyquerifier {
9
+ export interface IStringify<T> {
10
+ type: "stringify";
11
+ stringify: (input: T) => URLSearchParams;
12
+ }
13
+ export interface IIs<T> {
14
+ type: "is";
15
+ is: (input: T) => URLSearchParams | null;
16
+ }
17
+ export interface IAssert<T> {
18
+ type: "assert";
19
+ assert: (input: T) => URLSearchParams;
20
+ }
21
+ export interface IValidate<T> {
22
+ type: "validate";
23
+ validate: (input: T) => IValidation<URLSearchParams>;
24
+ }
25
+ }
@@ -1,25 +1,25 @@
1
- import { IValidation } from "typia";
2
-
3
- export type IResponseBodyStringifier<T> =
4
- | IResponseBodyStringifier.IStringify<T>
5
- | IResponseBodyStringifier.IIs<T>
6
- | IResponseBodyStringifier.IAssert<T>
7
- | IResponseBodyStringifier.IValidate<T>;
8
- export namespace IResponseBodyStringifier {
9
- export interface IStringify<T> {
10
- type: "stringify";
11
- stringify: (input: T) => string;
12
- }
13
- export interface IIs<T> {
14
- type: "is";
15
- is: (input: T) => string | null;
16
- }
17
- export interface IAssert<T> {
18
- type: "assert";
19
- assert: (input: T) => string;
20
- }
21
- export interface IValidate<T> {
22
- type: "validate";
23
- validate: (input: T) => IValidation<string>;
24
- }
25
- }
1
+ import { IValidation } from "typia";
2
+
3
+ export type IResponseBodyStringifier<T> =
4
+ | IResponseBodyStringifier.IStringify<T>
5
+ | IResponseBodyStringifier.IIs<T>
6
+ | IResponseBodyStringifier.IAssert<T>
7
+ | IResponseBodyStringifier.IValidate<T>;
8
+ export namespace IResponseBodyStringifier {
9
+ export interface IStringify<T> {
10
+ type: "stringify";
11
+ stringify: (input: T) => string;
12
+ }
13
+ export interface IIs<T> {
14
+ type: "is";
15
+ is: (input: T) => string | null;
16
+ }
17
+ export interface IAssert<T> {
18
+ type: "assert";
19
+ assert: (input: T) => string;
20
+ }
21
+ export interface IValidate<T> {
22
+ type: "validate";
23
+ validate: (input: T) => IValidation<string>;
24
+ }
25
+ }
@@ -1,52 +1,52 @@
1
- import ts from "typescript";
2
- import { MetadataCollection } from "typia/lib/factories/MetadataCollection";
3
- import { MetadataFactory } from "typia/lib/factories/MetadataFactory";
4
- import { AssertProgrammer } from "typia/lib/programmers/AssertProgrammer";
5
- import { Metadata } from "typia/lib/schemas/metadata/Metadata";
6
- import { TransformerError } from "typia/lib/transformers/TransformerError";
7
-
8
- import { INestiaTransformProject } from "../options/INestiaTransformProject";
9
-
10
- export namespace PlainBodyProgrammer {
11
- export const generate =
12
- (project: INestiaTransformProject) =>
13
- (modulo: ts.LeftHandSideExpression) =>
14
- (type: ts.Type): ts.Expression => {
15
- const result = MetadataFactory.analyze(project.checker)({
16
- escape: false,
17
- constant: true,
18
- absorb: true,
19
- validate,
20
- })(new MetadataCollection())(type);
21
- if (result.success === false)
22
- throw TransformerError.from("nestia.core.TypedParam")(result.errors);
23
- return AssertProgrammer.write({
24
- ...project,
25
- options: {
26
- numeric: false,
27
- finite: false,
28
- functional: false,
29
- },
30
- })(modulo)(false)(type);
31
- };
32
- }
33
-
34
- const validate = (metadata: Metadata): string[] => {
35
- const errors: string[] = [];
36
- const insert = (msg: string) => errors.push(msg);
37
-
38
- const expected: number =
39
- (metadata.atomics.some((a) => a.type === "string") ? 1 : 0) +
40
- metadata.templates.length +
41
- metadata.constants
42
- .filter((c) => c.type === "string")
43
- .map((c) => c.values.length)
44
- .reduce((a, b) => a + b, 0);
45
- if (expected === 0 || expected !== metadata.size())
46
- insert(`only string type is allowed`);
47
- if (metadata.isRequired() === false) insert(`do not allow undefindable type`);
48
- if (metadata.nullable === true) insert(`do not allow nullable type`);
49
- else if (metadata.any === true) insert(`do not allow any type`);
50
-
51
- return errors;
52
- };
1
+ import ts from "typescript";
2
+ import { MetadataCollection } from "typia/lib/factories/MetadataCollection";
3
+ import { MetadataFactory } from "typia/lib/factories/MetadataFactory";
4
+ import { AssertProgrammer } from "typia/lib/programmers/AssertProgrammer";
5
+ import { Metadata } from "typia/lib/schemas/metadata/Metadata";
6
+ import { TransformerError } from "typia/lib/transformers/TransformerError";
7
+
8
+ import { INestiaTransformProject } from "../options/INestiaTransformProject";
9
+
10
+ export namespace PlainBodyProgrammer {
11
+ export const generate =
12
+ (project: INestiaTransformProject) =>
13
+ (modulo: ts.LeftHandSideExpression) =>
14
+ (type: ts.Type): ts.Expression => {
15
+ const result = MetadataFactory.analyze(project.checker)({
16
+ escape: false,
17
+ constant: true,
18
+ absorb: true,
19
+ validate,
20
+ })(new MetadataCollection())(type);
21
+ if (result.success === false)
22
+ throw TransformerError.from("nestia.core.TypedParam")(result.errors);
23
+ return AssertProgrammer.write({
24
+ ...project,
25
+ options: {
26
+ numeric: false,
27
+ finite: false,
28
+ functional: false,
29
+ },
30
+ })(modulo)(false)(type);
31
+ };
32
+ }
33
+
34
+ const validate = (metadata: Metadata): string[] => {
35
+ const errors: string[] = [];
36
+ const insert = (msg: string) => errors.push(msg);
37
+
38
+ const expected: number =
39
+ (metadata.atomics.some((a) => a.type === "string") ? 1 : 0) +
40
+ metadata.templates.length +
41
+ metadata.constants
42
+ .filter((c) => c.type === "string")
43
+ .map((c) => c.values.length)
44
+ .reduce((a, b) => a + b, 0);
45
+ if (expected === 0 || expected !== metadata.size())
46
+ insert(`only string type is allowed`);
47
+ if (metadata.isRequired() === false) insert(`do not allow undefindable type`);
48
+ if (metadata.nullable === true) insert(`do not allow nullable type`);
49
+ else if (metadata.any === true) insert(`do not allow any type`);
50
+
51
+ return errors;
52
+ };
@@ -1,108 +1,108 @@
1
- import ts from "typescript";
2
- import { JsonMetadataFactory } from "typia/lib/factories/JsonMetadataFactory";
3
- import { AssertProgrammer } from "typia/lib/programmers/AssertProgrammer";
4
- import { IsProgrammer } from "typia/lib/programmers/IsProgrammer";
5
- import { ValidateProgrammer } from "typia/lib/programmers/ValidateProgrammer";
6
- import { MiscAssertCloneProgrammer } from "typia/lib/programmers/misc/MiscAssertCloneProgrammer";
7
- import { MiscAssertPruneProgrammer } from "typia/lib/programmers/misc/MiscAssertPruneProgrammer";
8
- import { MiscValidateCloneProgrammer } from "typia/lib/programmers/misc/MiscValidateCloneProgrammer";
9
- import { MiscValidatePruneProgrammer } from "typia/lib/programmers/misc/MiscValidatePruneProgrammer";
10
- import { IProject } from "typia/lib/transformers/IProject";
11
-
12
- import { INestiaTransformProject } from "../options/INestiaTransformProject";
13
- import { IRequestBodyValidator } from "../options/IRequestBodyValidator";
14
-
15
- export namespace TypedBodyProgrammer {
16
- export const generate =
17
- (project: INestiaTransformProject) =>
18
- (modulo: ts.LeftHandSideExpression) =>
19
- (type: ts.Type): ts.ObjectLiteralExpression => {
20
- // VALIDATE TYPE
21
- JsonMetadataFactory.analyze("@nestia.core.TypedBody")(project.checker)(
22
- type,
23
- );
24
-
25
- // GENERATE VALIDATION PLAN
26
- const check =
27
- (key: IRequestBodyValidator<any>["type"]) =>
28
- (equals: boolean) =>
29
- (
30
- programmer: (
31
- project: IProject,
32
- ) => (
33
- modulo: ts.LeftHandSideExpression,
34
- ) => (equals: boolean) => (type: ts.Type) => ts.ArrowFunction,
35
- ) =>
36
- ts.factory.createObjectLiteralExpression([
37
- ts.factory.createPropertyAssignment(
38
- ts.factory.createIdentifier("type"),
39
- ts.factory.createStringLiteral(key),
40
- ),
41
- ts.factory.createPropertyAssignment(
42
- ts.factory.createIdentifier(key),
43
- programmer({
44
- ...project,
45
- options: {
46
- numeric: false,
47
- finite: false,
48
- functional: false,
49
- },
50
- })(modulo)(equals)(type),
51
- ),
52
- ]);
53
- const misc =
54
- (key: IRequestBodyValidator<any>["type"]) =>
55
- (
56
- programmer: (
57
- project: IProject,
58
- ) => (
59
- modulo: ts.LeftHandSideExpression,
60
- ) => (type: ts.Type) => ts.ArrowFunction,
61
- ) =>
62
- ts.factory.createObjectLiteralExpression([
63
- ts.factory.createPropertyAssignment(
64
- ts.factory.createIdentifier("type"),
65
- ts.factory.createStringLiteral(key),
66
- ),
67
- ts.factory.createPropertyAssignment(
68
- ts.factory.createIdentifier(key),
69
- programmer({
70
- ...project,
71
- options: {
72
- numeric: false,
73
- finite: false,
74
- functional: false,
75
- },
76
- })(modulo)(type),
77
- ),
78
- ]);
79
-
80
- //----
81
- // RETURNS
82
- //----
83
- const category = project.options.validate;
84
- // NORMAL
85
- if (category === "is") return check("is")(false)(IsProgrammer.write);
86
- else if (category === "validate")
87
- return check("validate")(false)(ValidateProgrammer.write);
88
- // STRICT
89
- else if (category === "validateEquals")
90
- return check("validate")(true)(ValidateProgrammer.write);
91
- else if (category === "equals")
92
- return check("is")(true)(IsProgrammer.write);
93
- else if (category === "assertEquals")
94
- return check("assert")(true)(AssertProgrammer.write);
95
- // CLONE
96
- else if (category === "assertClone")
97
- return misc("assert")(MiscAssertCloneProgrammer.write);
98
- else if (category === "validateClone")
99
- return misc("validate")(MiscValidateCloneProgrammer.write);
100
- // PRUNE
101
- else if (category === "assertPrune")
102
- return misc("assert")(MiscAssertPruneProgrammer.write);
103
- else if (category === "validatePrune")
104
- return misc("validate")(MiscValidatePruneProgrammer.write);
105
- // DEFAULT
106
- return check("assert")(false)(AssertProgrammer.write);
107
- };
108
- }
1
+ import ts from "typescript";
2
+ import { JsonMetadataFactory } from "typia/lib/factories/JsonMetadataFactory";
3
+ import { AssertProgrammer } from "typia/lib/programmers/AssertProgrammer";
4
+ import { IsProgrammer } from "typia/lib/programmers/IsProgrammer";
5
+ import { ValidateProgrammer } from "typia/lib/programmers/ValidateProgrammer";
6
+ import { MiscAssertCloneProgrammer } from "typia/lib/programmers/misc/MiscAssertCloneProgrammer";
7
+ import { MiscAssertPruneProgrammer } from "typia/lib/programmers/misc/MiscAssertPruneProgrammer";
8
+ import { MiscValidateCloneProgrammer } from "typia/lib/programmers/misc/MiscValidateCloneProgrammer";
9
+ import { MiscValidatePruneProgrammer } from "typia/lib/programmers/misc/MiscValidatePruneProgrammer";
10
+ import { IProject } from "typia/lib/transformers/IProject";
11
+
12
+ import { INestiaTransformProject } from "../options/INestiaTransformProject";
13
+ import { IRequestBodyValidator } from "../options/IRequestBodyValidator";
14
+
15
+ export namespace TypedBodyProgrammer {
16
+ export const generate =
17
+ (project: INestiaTransformProject) =>
18
+ (modulo: ts.LeftHandSideExpression) =>
19
+ (type: ts.Type): ts.ObjectLiteralExpression => {
20
+ // VALIDATE TYPE
21
+ JsonMetadataFactory.analyze("@nestia.core.TypedBody")(project.checker)(
22
+ type,
23
+ );
24
+
25
+ // GENERATE VALIDATION PLAN
26
+ const check =
27
+ (key: IRequestBodyValidator<any>["type"]) =>
28
+ (equals: boolean) =>
29
+ (
30
+ programmer: (
31
+ project: IProject,
32
+ ) => (
33
+ modulo: ts.LeftHandSideExpression,
34
+ ) => (equals: boolean) => (type: ts.Type) => ts.ArrowFunction,
35
+ ) =>
36
+ ts.factory.createObjectLiteralExpression([
37
+ ts.factory.createPropertyAssignment(
38
+ ts.factory.createIdentifier("type"),
39
+ ts.factory.createStringLiteral(key),
40
+ ),
41
+ ts.factory.createPropertyAssignment(
42
+ ts.factory.createIdentifier(key),
43
+ programmer({
44
+ ...project,
45
+ options: {
46
+ numeric: false,
47
+ finite: false,
48
+ functional: false,
49
+ },
50
+ })(modulo)(equals)(type),
51
+ ),
52
+ ]);
53
+ const misc =
54
+ (key: IRequestBodyValidator<any>["type"]) =>
55
+ (
56
+ programmer: (
57
+ project: IProject,
58
+ ) => (
59
+ modulo: ts.LeftHandSideExpression,
60
+ ) => (type: ts.Type) => ts.ArrowFunction,
61
+ ) =>
62
+ ts.factory.createObjectLiteralExpression([
63
+ ts.factory.createPropertyAssignment(
64
+ ts.factory.createIdentifier("type"),
65
+ ts.factory.createStringLiteral(key),
66
+ ),
67
+ ts.factory.createPropertyAssignment(
68
+ ts.factory.createIdentifier(key),
69
+ programmer({
70
+ ...project,
71
+ options: {
72
+ numeric: false,
73
+ finite: false,
74
+ functional: false,
75
+ },
76
+ })(modulo)(type),
77
+ ),
78
+ ]);
79
+
80
+ //----
81
+ // RETURNS
82
+ //----
83
+ const category = project.options.validate;
84
+ // NORMAL
85
+ if (category === "is") return check("is")(false)(IsProgrammer.write);
86
+ else if (category === "validate")
87
+ return check("validate")(false)(ValidateProgrammer.write);
88
+ // STRICT
89
+ else if (category === "validateEquals")
90
+ return check("validate")(true)(ValidateProgrammer.write);
91
+ else if (category === "equals")
92
+ return check("is")(true)(IsProgrammer.write);
93
+ else if (category === "assertEquals")
94
+ return check("assert")(true)(AssertProgrammer.write);
95
+ // CLONE
96
+ else if (category === "assertClone")
97
+ return misc("assert")(MiscAssertCloneProgrammer.write);
98
+ else if (category === "validateClone")
99
+ return misc("validate")(MiscValidateCloneProgrammer.write);
100
+ // PRUNE
101
+ else if (category === "assertPrune")
102
+ return misc("assert")(MiscAssertPruneProgrammer.write);
103
+ else if (category === "validatePrune")
104
+ return misc("validate")(MiscValidatePruneProgrammer.write);
105
+ // DEFAULT
106
+ return check("assert")(false)(AssertProgrammer.write);
107
+ };
108
+ }