@nestia/core 7.0.0-dev.20250607 → 7.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 (75) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +92 -92
  3. package/package.json +3 -3
  4. package/src/adaptors/WebSocketAdaptor.ts +429 -429
  5. package/src/decorators/DynamicModule.ts +43 -43
  6. package/src/decorators/EncryptedBody.ts +101 -101
  7. package/src/decorators/EncryptedController.ts +38 -38
  8. package/src/decorators/EncryptedModule.ts +100 -100
  9. package/src/decorators/EncryptedRoute.ts +219 -219
  10. package/src/decorators/HumanRoute.ts +22 -22
  11. package/src/decorators/NoTransformConfigurationError.ts +32 -32
  12. package/src/decorators/PlainBody.ts +79 -79
  13. package/src/decorators/SwaggerCustomizer.ts +115 -115
  14. package/src/decorators/SwaggerExample.ts +100 -100
  15. package/src/decorators/TypedBody.ts +59 -59
  16. package/src/decorators/TypedException.ts +166 -166
  17. package/src/decorators/TypedFormData.ts +195 -195
  18. package/src/decorators/TypedHeaders.ts +64 -64
  19. package/src/decorators/TypedParam.ts +77 -77
  20. package/src/decorators/TypedQuery.ts +245 -245
  21. package/src/decorators/TypedRoute.ts +214 -214
  22. package/src/decorators/WebSocketRoute.ts +242 -242
  23. package/src/decorators/internal/EncryptedConstant.ts +4 -4
  24. package/src/decorators/internal/IWebSocketRouteReflect.ts +23 -23
  25. package/src/decorators/internal/NoTransformConfigureError.ts +2 -2
  26. package/src/decorators/internal/get_path_and_querify.ts +108 -108
  27. package/src/decorators/internal/get_path_and_stringify.ts +122 -122
  28. package/src/decorators/internal/get_text_body.ts +20 -20
  29. package/src/decorators/internal/headers_to_object.ts +13 -13
  30. package/src/decorators/internal/is_request_body_undefined.ts +14 -14
  31. package/src/decorators/internal/load_controller.ts +49 -49
  32. package/src/decorators/internal/route_error.ts +45 -45
  33. package/src/decorators/internal/validate_request_body.ts +74 -74
  34. package/src/decorators/internal/validate_request_form_data.ts +77 -77
  35. package/src/decorators/internal/validate_request_headers.ts +86 -86
  36. package/src/decorators/internal/validate_request_query.ts +74 -74
  37. package/src/index.ts +5 -5
  38. package/src/module.ts +22 -22
  39. package/src/options/INestiaTransformOptions.ts +38 -38
  40. package/src/options/INestiaTransformProject.ts +8 -8
  41. package/src/options/IRequestBodyValidator.ts +20 -20
  42. package/src/options/IRequestFormDataProps.ts +27 -27
  43. package/src/options/IRequestHeadersValidator.ts +22 -22
  44. package/src/options/IRequestQueryValidator.ts +20 -20
  45. package/src/options/IResponseBodyQuerifier.ts +25 -25
  46. package/src/options/IResponseBodyStringifier.ts +30 -30
  47. package/src/programmers/PlainBodyProgrammer.ts +70 -70
  48. package/src/programmers/TypedBodyProgrammer.ts +142 -142
  49. package/src/programmers/TypedFormDataBodyProgrammer.ts +118 -118
  50. package/src/programmers/TypedHeadersProgrammer.ts +63 -63
  51. package/src/programmers/TypedParamProgrammer.ts +33 -33
  52. package/src/programmers/TypedQueryBodyProgrammer.ts +112 -112
  53. package/src/programmers/TypedQueryProgrammer.ts +114 -114
  54. package/src/programmers/TypedQueryRouteProgrammer.ts +105 -105
  55. package/src/programmers/TypedRouteProgrammer.ts +94 -94
  56. package/src/programmers/http/HttpAssertQuerifyProgrammer.ts +72 -72
  57. package/src/programmers/http/HttpIsQuerifyProgrammer.ts +75 -75
  58. package/src/programmers/http/HttpQuerifyProgrammer.ts +108 -108
  59. package/src/programmers/http/HttpValidateQuerifyProgrammer.ts +76 -76
  60. package/src/programmers/internal/CoreMetadataUtil.ts +21 -21
  61. package/src/transform.ts +35 -35
  62. package/src/transformers/FileTransformer.ts +110 -110
  63. package/src/transformers/MethodTransformer.ts +103 -103
  64. package/src/transformers/NodeTransformer.ts +23 -23
  65. package/src/transformers/ParameterDecoratorTransformer.ts +143 -143
  66. package/src/transformers/ParameterTransformer.ts +57 -57
  67. package/src/transformers/TypedRouteTransformer.ts +85 -85
  68. package/src/transformers/WebSocketRouteTransformer.ts +120 -120
  69. package/src/typings/Creator.ts +3 -3
  70. package/src/typings/get-function-location.d.ts +7 -7
  71. package/src/utils/ArrayUtil.ts +7 -7
  72. package/src/utils/ExceptionManager.ts +112 -112
  73. package/src/utils/Singleton.ts +20 -20
  74. package/src/utils/SourceFinder.ts +57 -57
  75. package/src/utils/VersioningStrategy.ts +27 -27
@@ -1,63 +1,63 @@
1
- import ts from "typescript";
2
- import { HttpAssertHeadersProgrammer } from "typia/lib/programmers/http/HttpAssertHeadersProgrammer";
3
- import { HttpIsHeadersProgrammer } from "typia/lib/programmers/http/HttpIsHeadersProgrammer";
4
- import { HttpValidateHeadersProgrammer } from "typia/lib/programmers/http/HttpValidateHeadersProgrammer";
5
- import { ITypiaContext } from "typia/lib/transformers/ITypiaContext";
6
-
7
- import { INestiaTransformContext } from "../options/INestiaTransformProject";
8
- import { IRequestHeadersValidator } from "../options/IRequestHeadersValidator";
9
-
10
- export namespace TypedHeadersProgrammer {
11
- export const generate = (props: {
12
- context: INestiaTransformContext;
13
- modulo: ts.LeftHandSideExpression;
14
- type: ts.Type;
15
- }): ts.Expression => {
16
- // GENERATE VALIDATION PLAN
17
- const parameter =
18
- (key: IRequestHeadersValidator<any>["type"]) =>
19
- (
20
- programmer: (next: {
21
- context: ITypiaContext;
22
- modulo: ts.LeftHandSideExpression;
23
- type: ts.Type;
24
- name: string | undefined;
25
- }) => ts.Expression,
26
- ) =>
27
- ts.factory.createObjectLiteralExpression([
28
- ts.factory.createPropertyAssignment(
29
- ts.factory.createIdentifier("type"),
30
- ts.factory.createStringLiteral(key),
31
- ),
32
- ts.factory.createPropertyAssignment(
33
- ts.factory.createIdentifier(key),
34
- programmer({
35
- context: {
36
- ...props.context,
37
- options: {
38
- numeric: false,
39
- finite: false,
40
- functional: false,
41
- },
42
- },
43
- modulo: props.modulo,
44
- type: props.type,
45
- name: undefined,
46
- }),
47
- ),
48
- ]);
49
-
50
- // RETURNS
51
- const category = props.context.options.validate;
52
- if (category === "is" || category === "equals")
53
- return parameter("is")(HttpIsHeadersProgrammer.write);
54
- else if (
55
- category === "validate" ||
56
- category === "validateEquals" ||
57
- category === "validateClone" ||
58
- category === "validatePrune"
59
- )
60
- return parameter("validate")(HttpValidateHeadersProgrammer.write);
61
- return parameter("assert")(HttpAssertHeadersProgrammer.write);
62
- };
63
- }
1
+ import ts from "typescript";
2
+ import { HttpAssertHeadersProgrammer } from "typia/lib/programmers/http/HttpAssertHeadersProgrammer";
3
+ import { HttpIsHeadersProgrammer } from "typia/lib/programmers/http/HttpIsHeadersProgrammer";
4
+ import { HttpValidateHeadersProgrammer } from "typia/lib/programmers/http/HttpValidateHeadersProgrammer";
5
+ import { ITypiaContext } from "typia/lib/transformers/ITypiaContext";
6
+
7
+ import { INestiaTransformContext } from "../options/INestiaTransformProject";
8
+ import { IRequestHeadersValidator } from "../options/IRequestHeadersValidator";
9
+
10
+ export namespace TypedHeadersProgrammer {
11
+ export const generate = (props: {
12
+ context: INestiaTransformContext;
13
+ modulo: ts.LeftHandSideExpression;
14
+ type: ts.Type;
15
+ }): ts.Expression => {
16
+ // GENERATE VALIDATION PLAN
17
+ const parameter =
18
+ (key: IRequestHeadersValidator<any>["type"]) =>
19
+ (
20
+ programmer: (next: {
21
+ context: ITypiaContext;
22
+ modulo: ts.LeftHandSideExpression;
23
+ type: ts.Type;
24
+ name: string | undefined;
25
+ }) => ts.Expression,
26
+ ) =>
27
+ ts.factory.createObjectLiteralExpression([
28
+ ts.factory.createPropertyAssignment(
29
+ ts.factory.createIdentifier("type"),
30
+ ts.factory.createStringLiteral(key),
31
+ ),
32
+ ts.factory.createPropertyAssignment(
33
+ ts.factory.createIdentifier(key),
34
+ programmer({
35
+ context: {
36
+ ...props.context,
37
+ options: {
38
+ numeric: false,
39
+ finite: false,
40
+ functional: false,
41
+ },
42
+ },
43
+ modulo: props.modulo,
44
+ type: props.type,
45
+ name: undefined,
46
+ }),
47
+ ),
48
+ ]);
49
+
50
+ // RETURNS
51
+ const category = props.context.options.validate;
52
+ if (category === "is" || category === "equals")
53
+ return parameter("is")(HttpIsHeadersProgrammer.write);
54
+ else if (
55
+ category === "validate" ||
56
+ category === "validateEquals" ||
57
+ category === "validateClone" ||
58
+ category === "validatePrune"
59
+ )
60
+ return parameter("validate")(HttpValidateHeadersProgrammer.write);
61
+ return parameter("assert")(HttpAssertHeadersProgrammer.write);
62
+ };
63
+ }
@@ -1,33 +1,33 @@
1
- import ts from "typescript";
2
- import { HttpParameterProgrammer } from "typia/lib/programmers/http/HttpParameterProgrammer";
3
-
4
- import { INestiaTransformContext } from "../options/INestiaTransformProject";
5
-
6
- export namespace TypedParamProgrammer {
7
- export const generate = (props: {
8
- context: INestiaTransformContext;
9
- modulo: ts.LeftHandSideExpression;
10
- arguments: readonly ts.Expression[];
11
- type: ts.Type;
12
- }): readonly ts.Expression[] => {
13
- // ALREADY BEING TRANSFORMED
14
- if (props.arguments.length !== 1) return props.arguments;
15
- return [
16
- props.arguments[0],
17
- HttpParameterProgrammer.write({
18
- context: {
19
- ...props.context,
20
- options: {
21
- numeric: true,
22
- },
23
- },
24
- modulo: props.modulo,
25
- type: props.type,
26
- name: undefined,
27
- }),
28
- ...(props.context.options?.validate?.startsWith("validate")
29
- ? [ts.factory.createTrue()]
30
- : []),
31
- ];
32
- };
33
- }
1
+ import ts from "typescript";
2
+ import { HttpParameterProgrammer } from "typia/lib/programmers/http/HttpParameterProgrammer";
3
+
4
+ import { INestiaTransformContext } from "../options/INestiaTransformProject";
5
+
6
+ export namespace TypedParamProgrammer {
7
+ export const generate = (props: {
8
+ context: INestiaTransformContext;
9
+ modulo: ts.LeftHandSideExpression;
10
+ arguments: readonly ts.Expression[];
11
+ type: ts.Type;
12
+ }): readonly ts.Expression[] => {
13
+ // ALREADY BEING TRANSFORMED
14
+ if (props.arguments.length !== 1) return props.arguments;
15
+ return [
16
+ props.arguments[0],
17
+ HttpParameterProgrammer.write({
18
+ context: {
19
+ ...props.context,
20
+ options: {
21
+ numeric: true,
22
+ },
23
+ },
24
+ modulo: props.modulo,
25
+ type: props.type,
26
+ name: undefined,
27
+ }),
28
+ ...(props.context.options?.validate?.startsWith("validate")
29
+ ? [ts.factory.createTrue()]
30
+ : []),
31
+ ];
32
+ };
33
+ }
@@ -1,112 +1,112 @@
1
- import { ILlmSchema } from "@samchon/openapi";
2
- import ts from "typescript";
3
- import { MetadataCollection } from "typia/lib/factories/MetadataCollection";
4
- import { MetadataFactory } from "typia/lib/factories/MetadataFactory";
5
- import { HttpAssertQueryProgrammer } from "typia/lib/programmers/http/HttpAssertQueryProgrammer";
6
- import { HttpIsQueryProgrammer } from "typia/lib/programmers/http/HttpIsQueryProgrammer";
7
- import { HttpQueryProgrammer } from "typia/lib/programmers/http/HttpQueryProgrammer";
8
- import { HttpValidateQueryProgrammer } from "typia/lib/programmers/http/HttpValidateQueryProgrammer";
9
- import { LlmSchemaProgrammer } from "typia/lib/programmers/llm/LlmSchemaProgrammer";
10
- import { Metadata } from "typia/lib/schemas/metadata/Metadata";
11
- import { ITypiaContext } from "typia/lib/transformers/ITypiaContext";
12
- import { TransformerError } from "typia/lib/transformers/TransformerError";
13
- import { ValidationPipe } from "typia/lib/typings/ValidationPipe";
14
-
15
- import { INestiaTransformOptions } from "../options/INestiaTransformOptions";
16
- import { INestiaTransformContext } from "../options/INestiaTransformProject";
17
- import { IRequestQueryValidator } from "../options/IRequestQueryValidator";
18
-
19
- export namespace TypedQueryBodyProgrammer {
20
- export const generate = (props: {
21
- context: INestiaTransformContext;
22
- modulo: ts.LeftHandSideExpression;
23
- type: ts.Type;
24
- }): ts.ObjectLiteralExpression => {
25
- // VALIDATE TYPE
26
- if (props.context.options.llm) {
27
- const llm: INestiaTransformOptions.ILlm<ILlmSchema.Model> =
28
- props.context.options.llm;
29
- const result: ValidationPipe<Metadata, MetadataFactory.IError> =
30
- MetadataFactory.analyze({
31
- checker: props.context.checker,
32
- transformer: props.context.transformer,
33
- options: {
34
- escape: false,
35
- constant: true,
36
- absorb: true,
37
- validate: (meta, explore) => {
38
- const errors: string[] = HttpQueryProgrammer.validate(
39
- meta,
40
- explore,
41
- true,
42
- );
43
- errors.push(
44
- ...LlmSchemaProgrammer.validate({
45
- model: llm.model,
46
- config: {
47
- strict: llm.strict,
48
- recursive: llm.recursive,
49
- },
50
- })(meta),
51
- );
52
- return errors;
53
- },
54
- },
55
- collection: new MetadataCollection(),
56
- type: props.type,
57
- });
58
- if (result.success === false)
59
- throw TransformerError.from({
60
- code: props.modulo.getText(),
61
- errors: result.errors,
62
- });
63
- }
64
-
65
- // GENERATE VALIDATION PLAN
66
- const parameter =
67
- (key: IRequestQueryValidator<any>["type"]) =>
68
- (
69
- programmer: (next: {
70
- context: ITypiaContext;
71
- modulo: ts.LeftHandSideExpression;
72
- type: ts.Type;
73
- name: string | undefined;
74
- }) => ts.Expression,
75
- ) =>
76
- ts.factory.createObjectLiteralExpression([
77
- ts.factory.createPropertyAssignment(
78
- ts.factory.createIdentifier("type"),
79
- ts.factory.createStringLiteral(key),
80
- ),
81
- ts.factory.createPropertyAssignment(
82
- ts.factory.createIdentifier(key),
83
- programmer({
84
- context: {
85
- ...props.context,
86
- options: {
87
- numeric: false,
88
- finite: false,
89
- functional: false,
90
- },
91
- },
92
- modulo: props.modulo,
93
- type: props.type,
94
- name: undefined,
95
- }),
96
- ),
97
- ]);
98
-
99
- // RETURNS
100
- const category = props.context.options.validate;
101
- if (category === "is" || category === "equals")
102
- return parameter("is")(HttpIsQueryProgrammer.write);
103
- else if (
104
- category === "validate" ||
105
- category === "validateEquals" ||
106
- category === "validateClone" ||
107
- category === "validatePrune"
108
- )
109
- return parameter("validate")(HttpValidateQueryProgrammer.write);
110
- return parameter("assert")(HttpAssertQueryProgrammer.write);
111
- };
112
- }
1
+ import { ILlmSchema } from "@samchon/openapi";
2
+ import ts from "typescript";
3
+ import { MetadataCollection } from "typia/lib/factories/MetadataCollection";
4
+ import { MetadataFactory } from "typia/lib/factories/MetadataFactory";
5
+ import { HttpAssertQueryProgrammer } from "typia/lib/programmers/http/HttpAssertQueryProgrammer";
6
+ import { HttpIsQueryProgrammer } from "typia/lib/programmers/http/HttpIsQueryProgrammer";
7
+ import { HttpQueryProgrammer } from "typia/lib/programmers/http/HttpQueryProgrammer";
8
+ import { HttpValidateQueryProgrammer } from "typia/lib/programmers/http/HttpValidateQueryProgrammer";
9
+ import { LlmSchemaProgrammer } from "typia/lib/programmers/llm/LlmSchemaProgrammer";
10
+ import { Metadata } from "typia/lib/schemas/metadata/Metadata";
11
+ import { ITypiaContext } from "typia/lib/transformers/ITypiaContext";
12
+ import { TransformerError } from "typia/lib/transformers/TransformerError";
13
+ import { ValidationPipe } from "typia/lib/typings/ValidationPipe";
14
+
15
+ import { INestiaTransformOptions } from "../options/INestiaTransformOptions";
16
+ import { INestiaTransformContext } from "../options/INestiaTransformProject";
17
+ import { IRequestQueryValidator } from "../options/IRequestQueryValidator";
18
+
19
+ export namespace TypedQueryBodyProgrammer {
20
+ export const generate = (props: {
21
+ context: INestiaTransformContext;
22
+ modulo: ts.LeftHandSideExpression;
23
+ type: ts.Type;
24
+ }): ts.ObjectLiteralExpression => {
25
+ // VALIDATE TYPE
26
+ if (props.context.options.llm) {
27
+ const llm: INestiaTransformOptions.ILlm<ILlmSchema.Model> =
28
+ props.context.options.llm;
29
+ const result: ValidationPipe<Metadata, MetadataFactory.IError> =
30
+ MetadataFactory.analyze({
31
+ checker: props.context.checker,
32
+ transformer: props.context.transformer,
33
+ options: {
34
+ escape: false,
35
+ constant: true,
36
+ absorb: true,
37
+ validate: (meta, explore) => {
38
+ const errors: string[] = HttpQueryProgrammer.validate(
39
+ meta,
40
+ explore,
41
+ true,
42
+ );
43
+ errors.push(
44
+ ...LlmSchemaProgrammer.validate({
45
+ model: llm.model,
46
+ config: {
47
+ strict: llm.strict,
48
+ recursive: llm.recursive,
49
+ },
50
+ })(meta),
51
+ );
52
+ return errors;
53
+ },
54
+ },
55
+ collection: new MetadataCollection(),
56
+ type: props.type,
57
+ });
58
+ if (result.success === false)
59
+ throw TransformerError.from({
60
+ code: props.modulo.getText(),
61
+ errors: result.errors,
62
+ });
63
+ }
64
+
65
+ // GENERATE VALIDATION PLAN
66
+ const parameter =
67
+ (key: IRequestQueryValidator<any>["type"]) =>
68
+ (
69
+ programmer: (next: {
70
+ context: ITypiaContext;
71
+ modulo: ts.LeftHandSideExpression;
72
+ type: ts.Type;
73
+ name: string | undefined;
74
+ }) => ts.Expression,
75
+ ) =>
76
+ ts.factory.createObjectLiteralExpression([
77
+ ts.factory.createPropertyAssignment(
78
+ ts.factory.createIdentifier("type"),
79
+ ts.factory.createStringLiteral(key),
80
+ ),
81
+ ts.factory.createPropertyAssignment(
82
+ ts.factory.createIdentifier(key),
83
+ programmer({
84
+ context: {
85
+ ...props.context,
86
+ options: {
87
+ numeric: false,
88
+ finite: false,
89
+ functional: false,
90
+ },
91
+ },
92
+ modulo: props.modulo,
93
+ type: props.type,
94
+ name: undefined,
95
+ }),
96
+ ),
97
+ ]);
98
+
99
+ // RETURNS
100
+ const category = props.context.options.validate;
101
+ if (category === "is" || category === "equals")
102
+ return parameter("is")(HttpIsQueryProgrammer.write);
103
+ else if (
104
+ category === "validate" ||
105
+ category === "validateEquals" ||
106
+ category === "validateClone" ||
107
+ category === "validatePrune"
108
+ )
109
+ return parameter("validate")(HttpValidateQueryProgrammer.write);
110
+ return parameter("assert")(HttpAssertQueryProgrammer.write);
111
+ };
112
+ }
@@ -1,114 +1,114 @@
1
- import { ILlmSchema } from "@samchon/openapi";
2
- import ts from "typescript";
3
- import { MetadataCollection } from "typia/lib/factories/MetadataCollection";
4
- import { MetadataFactory } from "typia/lib/factories/MetadataFactory";
5
- import { HttpAssertQueryProgrammer } from "typia/lib/programmers/http/HttpAssertQueryProgrammer";
6
- import { HttpIsQueryProgrammer } from "typia/lib/programmers/http/HttpIsQueryProgrammer";
7
- import { HttpQueryProgrammer } from "typia/lib/programmers/http/HttpQueryProgrammer";
8
- import { HttpValidateQueryProgrammer } from "typia/lib/programmers/http/HttpValidateQueryProgrammer";
9
- import { LlmSchemaProgrammer } from "typia/lib/programmers/llm/LlmSchemaProgrammer";
10
- import { Metadata } from "typia/lib/schemas/metadata/Metadata";
11
- import { ITypiaContext } from "typia/lib/transformers/ITypiaContext";
12
- import { TransformerError } from "typia/lib/transformers/TransformerError";
13
- import { ValidationPipe } from "typia/lib/typings/ValidationPipe";
14
-
15
- import { INestiaTransformOptions } from "../options/INestiaTransformOptions";
16
- import { INestiaTransformContext } from "../options/INestiaTransformProject";
17
- import { IRequestQueryValidator } from "../options/IRequestQueryValidator";
18
-
19
- export namespace TypedQueryProgrammer {
20
- export const generate = (props: {
21
- context: INestiaTransformContext;
22
- modulo: ts.LeftHandSideExpression;
23
- type: ts.Type;
24
- }): ts.Expression => {
25
- // VALIDATE TYPE
26
- if (props.context.options.llm) {
27
- const llm: INestiaTransformOptions.ILlm<ILlmSchema.Model> =
28
- props.context.options.llm;
29
- const result: ValidationPipe<Metadata, MetadataFactory.IError> =
30
- MetadataFactory.analyze({
31
- checker: props.context.checker,
32
- transformer: props.context.transformer,
33
- options: {
34
- escape: false,
35
- constant: true,
36
- absorb: true,
37
- validate: (meta, explore) => {
38
- const errors: string[] = HttpQueryProgrammer.validate(
39
- meta,
40
- explore,
41
- true,
42
- );
43
- errors.push(
44
- ...LlmSchemaProgrammer.validate({
45
- model: llm.model,
46
- config: {
47
- strict: llm.strict,
48
- recursive: llm.recursive,
49
- },
50
- })(meta),
51
- );
52
- return errors;
53
- },
54
- },
55
- collection: new MetadataCollection(),
56
- type: props.type,
57
- });
58
- if (result.success === false)
59
- throw TransformerError.from({
60
- code: "@nestia.core.TypedQuery",
61
- errors: result.errors,
62
- });
63
- }
64
-
65
- // GENERATE VALIDATION PLAN
66
- const parameter =
67
- (key: IRequestQueryValidator<any>["type"]) =>
68
- (
69
- programmer: (next: {
70
- context: ITypiaContext;
71
- modulo: ts.LeftHandSideExpression;
72
- type: ts.Type;
73
- name: string | undefined;
74
- allowOptional: boolean;
75
- }) => ts.Expression,
76
- ) =>
77
- ts.factory.createObjectLiteralExpression([
78
- ts.factory.createPropertyAssignment(
79
- ts.factory.createIdentifier("type"),
80
- ts.factory.createStringLiteral(key),
81
- ),
82
- ts.factory.createPropertyAssignment(
83
- ts.factory.createIdentifier(key),
84
- programmer({
85
- context: {
86
- ...props.context,
87
- options: {
88
- numeric: false,
89
- finite: false,
90
- functional: false,
91
- },
92
- },
93
- modulo: props.modulo,
94
- type: props.type,
95
- name: undefined,
96
- allowOptional: true,
97
- }),
98
- ),
99
- ]);
100
-
101
- // RETURNS
102
- const category = props.context.options.validate;
103
- if (category === "is" || category === "equals")
104
- return parameter("is")(HttpIsQueryProgrammer.write);
105
- else if (
106
- category === "validate" ||
107
- category === "validateEquals" ||
108
- category === "validateClone" ||
109
- category === "validatePrune"
110
- )
111
- return parameter("validate")(HttpValidateQueryProgrammer.write);
112
- return parameter("assert")(HttpAssertQueryProgrammer.write);
113
- };
114
- }
1
+ import { ILlmSchema } from "@samchon/openapi";
2
+ import ts from "typescript";
3
+ import { MetadataCollection } from "typia/lib/factories/MetadataCollection";
4
+ import { MetadataFactory } from "typia/lib/factories/MetadataFactory";
5
+ import { HttpAssertQueryProgrammer } from "typia/lib/programmers/http/HttpAssertQueryProgrammer";
6
+ import { HttpIsQueryProgrammer } from "typia/lib/programmers/http/HttpIsQueryProgrammer";
7
+ import { HttpQueryProgrammer } from "typia/lib/programmers/http/HttpQueryProgrammer";
8
+ import { HttpValidateQueryProgrammer } from "typia/lib/programmers/http/HttpValidateQueryProgrammer";
9
+ import { LlmSchemaProgrammer } from "typia/lib/programmers/llm/LlmSchemaProgrammer";
10
+ import { Metadata } from "typia/lib/schemas/metadata/Metadata";
11
+ import { ITypiaContext } from "typia/lib/transformers/ITypiaContext";
12
+ import { TransformerError } from "typia/lib/transformers/TransformerError";
13
+ import { ValidationPipe } from "typia/lib/typings/ValidationPipe";
14
+
15
+ import { INestiaTransformOptions } from "../options/INestiaTransformOptions";
16
+ import { INestiaTransformContext } from "../options/INestiaTransformProject";
17
+ import { IRequestQueryValidator } from "../options/IRequestQueryValidator";
18
+
19
+ export namespace TypedQueryProgrammer {
20
+ export const generate = (props: {
21
+ context: INestiaTransformContext;
22
+ modulo: ts.LeftHandSideExpression;
23
+ type: ts.Type;
24
+ }): ts.Expression => {
25
+ // VALIDATE TYPE
26
+ if (props.context.options.llm) {
27
+ const llm: INestiaTransformOptions.ILlm<ILlmSchema.Model> =
28
+ props.context.options.llm;
29
+ const result: ValidationPipe<Metadata, MetadataFactory.IError> =
30
+ MetadataFactory.analyze({
31
+ checker: props.context.checker,
32
+ transformer: props.context.transformer,
33
+ options: {
34
+ escape: false,
35
+ constant: true,
36
+ absorb: true,
37
+ validate: (meta, explore) => {
38
+ const errors: string[] = HttpQueryProgrammer.validate(
39
+ meta,
40
+ explore,
41
+ true,
42
+ );
43
+ errors.push(
44
+ ...LlmSchemaProgrammer.validate({
45
+ model: llm.model,
46
+ config: {
47
+ strict: llm.strict,
48
+ recursive: llm.recursive,
49
+ },
50
+ })(meta),
51
+ );
52
+ return errors;
53
+ },
54
+ },
55
+ collection: new MetadataCollection(),
56
+ type: props.type,
57
+ });
58
+ if (result.success === false)
59
+ throw TransformerError.from({
60
+ code: "@nestia.core.TypedQuery",
61
+ errors: result.errors,
62
+ });
63
+ }
64
+
65
+ // GENERATE VALIDATION PLAN
66
+ const parameter =
67
+ (key: IRequestQueryValidator<any>["type"]) =>
68
+ (
69
+ programmer: (next: {
70
+ context: ITypiaContext;
71
+ modulo: ts.LeftHandSideExpression;
72
+ type: ts.Type;
73
+ name: string | undefined;
74
+ allowOptional: boolean;
75
+ }) => ts.Expression,
76
+ ) =>
77
+ ts.factory.createObjectLiteralExpression([
78
+ ts.factory.createPropertyAssignment(
79
+ ts.factory.createIdentifier("type"),
80
+ ts.factory.createStringLiteral(key),
81
+ ),
82
+ ts.factory.createPropertyAssignment(
83
+ ts.factory.createIdentifier(key),
84
+ programmer({
85
+ context: {
86
+ ...props.context,
87
+ options: {
88
+ numeric: false,
89
+ finite: false,
90
+ functional: false,
91
+ },
92
+ },
93
+ modulo: props.modulo,
94
+ type: props.type,
95
+ name: undefined,
96
+ allowOptional: true,
97
+ }),
98
+ ),
99
+ ]);
100
+
101
+ // RETURNS
102
+ const category = props.context.options.validate;
103
+ if (category === "is" || category === "equals")
104
+ return parameter("is")(HttpIsQueryProgrammer.write);
105
+ else if (
106
+ category === "validate" ||
107
+ category === "validateEquals" ||
108
+ category === "validateClone" ||
109
+ category === "validatePrune"
110
+ )
111
+ return parameter("validate")(HttpValidateQueryProgrammer.write);
112
+ return parameter("assert")(HttpAssertQueryProgrammer.write);
113
+ };
114
+ }