typia 5.1.0-dev.20230923 → 5.1.0-dev.20230925

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 (150) hide show
  1. package/README.md +1 -1
  2. package/lib/functional/$HeadersReader.d.ts +6 -0
  3. package/lib/functional/$HeadersReader.js +35 -0
  4. package/lib/functional/$HeadersReader.js.map +1 -0
  5. package/lib/functional/$ParameterReader.d.ts +6 -0
  6. package/lib/functional/$ParameterReader.js +35 -0
  7. package/lib/functional/$ParameterReader.js.map +1 -0
  8. package/lib/functional/$QueryReader.d.ts +7 -0
  9. package/lib/functional/$QueryReader.js +57 -0
  10. package/lib/functional/$QueryReader.js.map +1 -0
  11. package/lib/functional/Namespace.js +9 -0
  12. package/lib/functional/Namespace.js.map +1 -1
  13. package/lib/http.d.ts +872 -0
  14. package/lib/http.js +112 -0
  15. package/lib/http.js.map +1 -0
  16. package/lib/json.js +2 -2
  17. package/lib/json.js.map +1 -1
  18. package/lib/misc.js +2 -2
  19. package/lib/misc.js.map +1 -1
  20. package/lib/module.d.ts +1 -0
  21. package/lib/module.js +2 -1
  22. package/lib/module.js.map +1 -1
  23. package/lib/programmers/helpers/HttpMetadataUtil.d.ts +5 -0
  24. package/lib/programmers/helpers/HttpMetadataUtil.js +44 -0
  25. package/lib/programmers/helpers/HttpMetadataUtil.js.map +1 -0
  26. package/lib/programmers/http/HttpAssertHeadersProgrammer.d.ts +5 -0
  27. package/lib/programmers/http/HttpAssertHeadersProgrammer.js +41 -0
  28. package/lib/programmers/http/HttpAssertHeadersProgrammer.js.map +1 -0
  29. package/lib/programmers/http/HttpAssertQueryProgrammer.d.ts +5 -0
  30. package/lib/programmers/http/HttpAssertQueryProgrammer.js +41 -0
  31. package/lib/programmers/http/HttpAssertQueryProgrammer.js.map +1 -0
  32. package/lib/programmers/http/HttpHeadersProgrammer.d.ts +6 -0
  33. package/lib/programmers/http/HttpHeadersProgrammer.js +219 -0
  34. package/lib/programmers/http/HttpHeadersProgrammer.js.map +1 -0
  35. package/lib/programmers/http/HttpIsHeadersProgrammer.d.ts +5 -0
  36. package/lib/programmers/http/HttpIsHeadersProgrammer.js +45 -0
  37. package/lib/programmers/http/HttpIsHeadersProgrammer.js.map +1 -0
  38. package/lib/programmers/http/HttpIsQueryProgrammer.d.ts +5 -0
  39. package/lib/programmers/http/HttpIsQueryProgrammer.js +45 -0
  40. package/lib/programmers/http/HttpIsQueryProgrammer.js.map +1 -0
  41. package/lib/programmers/http/HttpParameterProgrammer.d.ts +5 -0
  42. package/lib/programmers/http/HttpParameterProgrammer.js +101 -0
  43. package/lib/programmers/http/HttpParameterProgrammer.js.map +1 -0
  44. package/lib/programmers/http/HttpQueryProgrammer.d.ts +6 -0
  45. package/lib/programmers/http/HttpQueryProgrammer.js +181 -0
  46. package/lib/programmers/http/HttpQueryProgrammer.js.map +1 -0
  47. package/lib/programmers/http/HttpValidateHeadersProgrammer.d.ts +5 -0
  48. package/lib/programmers/http/HttpValidateHeadersProgrammer.js +41 -0
  49. package/lib/programmers/http/HttpValidateHeadersProgrammer.js.map +1 -0
  50. package/lib/programmers/http/HttpValidateQueryProgrammer.d.ts +5 -0
  51. package/lib/programmers/http/HttpValidateQueryProgrammer.js +41 -0
  52. package/lib/programmers/http/HttpValidateQueryProgrammer.js.map +1 -0
  53. package/lib/protobuf.d.ts +24 -24
  54. package/lib/protobuf.js +4 -4
  55. package/lib/protobuf.js.map +1 -1
  56. package/lib/transformers/CallExpressionTransformer.js +40 -0
  57. package/lib/transformers/CallExpressionTransformer.js.map +1 -1
  58. package/lib/transformers/features/http/CreateHttpAssertHeadersTransformer.d.ts +4 -0
  59. package/lib/transformers/features/http/CreateHttpAssertHeadersTransformer.js +12 -0
  60. package/lib/transformers/features/http/CreateHttpAssertHeadersTransformer.js.map +1 -0
  61. package/lib/transformers/features/http/CreateHttpAssertQueryTransformer.d.ts +4 -0
  62. package/lib/transformers/features/http/CreateHttpAssertQueryTransformer.js +12 -0
  63. package/lib/transformers/features/http/CreateHttpAssertQueryTransformer.js.map +1 -0
  64. package/lib/transformers/features/http/CreateHttpHeadersTransformer.d.ts +4 -0
  65. package/lib/transformers/features/http/CreateHttpHeadersTransformer.js +10 -0
  66. package/lib/transformers/features/http/CreateHttpHeadersTransformer.js.map +1 -0
  67. package/lib/transformers/features/http/CreateHttpIsHeadersTransformer.d.ts +4 -0
  68. package/lib/transformers/features/http/CreateHttpIsHeadersTransformer.js +10 -0
  69. package/lib/transformers/features/http/CreateHttpIsHeadersTransformer.js.map +1 -0
  70. package/lib/transformers/features/http/CreateHttpIsQueryTransformer.d.ts +4 -0
  71. package/lib/transformers/features/http/CreateHttpIsQueryTransformer.js +10 -0
  72. package/lib/transformers/features/http/CreateHttpIsQueryTransformer.js.map +1 -0
  73. package/lib/transformers/features/http/CreateHttpParameterTransformer.d.ts +4 -0
  74. package/lib/transformers/features/http/CreateHttpParameterTransformer.js +10 -0
  75. package/lib/transformers/features/http/CreateHttpParameterTransformer.js.map +1 -0
  76. package/lib/transformers/features/http/CreateHttpQueryTransformer.d.ts +4 -0
  77. package/lib/transformers/features/http/CreateHttpQueryTransformer.js +10 -0
  78. package/lib/transformers/features/http/CreateHttpQueryTransformer.js.map +1 -0
  79. package/lib/transformers/features/http/CreateHttpValidateHeadersTransformer copy.d.ts +4 -0
  80. package/lib/transformers/features/http/CreateHttpValidateHeadersTransformer copy.js +12 -0
  81. package/lib/transformers/features/http/CreateHttpValidateHeadersTransformer copy.js.map +1 -0
  82. package/lib/transformers/features/http/CreateHttpValidateQueryTransformer.d.ts +4 -0
  83. package/lib/transformers/features/http/CreateHttpValidateQueryTransformer.js +12 -0
  84. package/lib/transformers/features/http/CreateHttpValidateQueryTransformer.js.map +1 -0
  85. package/lib/transformers/features/http/HttpAssertHeadersTransformer.d.ts +4 -0
  86. package/lib/transformers/features/http/HttpAssertHeadersTransformer.js +12 -0
  87. package/lib/transformers/features/http/HttpAssertHeadersTransformer.js.map +1 -0
  88. package/lib/transformers/features/http/HttpAssertQueryTransformer.d.ts +4 -0
  89. package/lib/transformers/features/http/HttpAssertQueryTransformer.js +12 -0
  90. package/lib/transformers/features/http/HttpAssertQueryTransformer.js.map +1 -0
  91. package/lib/transformers/features/http/HttpHeadersTransformer.d.ts +4 -0
  92. package/lib/transformers/features/http/HttpHeadersTransformer.js +10 -0
  93. package/lib/transformers/features/http/HttpHeadersTransformer.js.map +1 -0
  94. package/lib/transformers/features/http/HttpIsHeadersTransformer.d.ts +4 -0
  95. package/lib/transformers/features/http/HttpIsHeadersTransformer.js +10 -0
  96. package/lib/transformers/features/http/HttpIsHeadersTransformer.js.map +1 -0
  97. package/lib/transformers/features/http/HttpIsQueryTransformer.d.ts +4 -0
  98. package/lib/transformers/features/http/HttpIsQueryTransformer.js +10 -0
  99. package/lib/transformers/features/http/HttpIsQueryTransformer.js.map +1 -0
  100. package/lib/transformers/features/http/HttpParameterTransformer.d.ts +4 -0
  101. package/lib/transformers/features/http/HttpParameterTransformer.js +10 -0
  102. package/lib/transformers/features/http/HttpParameterTransformer.js.map +1 -0
  103. package/lib/transformers/features/http/HttpQueryTransformer.d.ts +4 -0
  104. package/lib/transformers/features/http/HttpQueryTransformer.js +10 -0
  105. package/lib/transformers/features/http/HttpQueryTransformer.js.map +1 -0
  106. package/lib/transformers/features/http/HttpValidateHeadersTransformer.d.ts +4 -0
  107. package/lib/transformers/features/http/HttpValidateHeadersTransformer.js +12 -0
  108. package/lib/transformers/features/http/HttpValidateHeadersTransformer.js.map +1 -0
  109. package/lib/transformers/features/http/HttpValidateQueryTransformer.d.ts +4 -0
  110. package/lib/transformers/features/http/HttpValidateQueryTransformer.js +12 -0
  111. package/lib/transformers/features/http/HttpValidateQueryTransformer.js.map +1 -0
  112. package/package.json +1 -1
  113. package/src/functional/$HeadersReader.ts +28 -0
  114. package/src/functional/$ParameterReader.ts +31 -0
  115. package/src/functional/$QueryReader.ts +53 -0
  116. package/src/functional/Namespace.ts +9 -0
  117. package/src/http.ts +1149 -0
  118. package/src/json.ts +2 -2
  119. package/src/misc.ts +2 -2
  120. package/src/module.ts +1 -0
  121. package/src/programmers/helpers/HttpMetadataUtil.ts +21 -0
  122. package/src/programmers/http/HttpAssertHeadersProgrammer.ts +77 -0
  123. package/src/programmers/http/HttpAssertQueryProgrammer.ts +77 -0
  124. package/src/programmers/http/HttpHeadersProgrammer.ts +328 -0
  125. package/src/programmers/http/HttpIsHeadersProgrammer.ts +87 -0
  126. package/src/programmers/http/HttpIsQueryProgrammer.ts +87 -0
  127. package/src/programmers/http/HttpParameterProgrammer.ts +104 -0
  128. package/src/programmers/http/HttpQueryProgrammer.ts +286 -0
  129. package/src/programmers/http/HttpValidateHeadersProgrammer.ts +77 -0
  130. package/src/programmers/http/HttpValidateQueryProgrammer.ts +77 -0
  131. package/src/protobuf.ts +34 -28
  132. package/src/transformers/CallExpressionTransformer.ts +46 -0
  133. package/src/transformers/features/http/CreateHttpAssertHeadersTransformer.ts +12 -0
  134. package/src/transformers/features/http/CreateHttpAssertQueryTransformer.ts +12 -0
  135. package/src/transformers/features/http/CreateHttpHeadersTransformer.ts +9 -0
  136. package/src/transformers/features/http/CreateHttpIsHeadersTransformer.ts +9 -0
  137. package/src/transformers/features/http/CreateHttpIsQueryTransformer.ts +9 -0
  138. package/src/transformers/features/http/CreateHttpParameterTransformer.ts +9 -0
  139. package/src/transformers/features/http/CreateHttpQueryTransformer.ts +9 -0
  140. package/src/transformers/features/http/CreateHttpValidateHeadersTransformer copy.ts +12 -0
  141. package/src/transformers/features/http/CreateHttpValidateQueryTransformer.ts +12 -0
  142. package/src/transformers/features/http/HttpAssertHeadersTransformer.ts +10 -0
  143. package/src/transformers/features/http/HttpAssertQueryTransformer.ts +10 -0
  144. package/src/transformers/features/http/HttpHeadersTransformer.ts +9 -0
  145. package/src/transformers/features/http/HttpIsHeadersTransformer.ts +9 -0
  146. package/src/transformers/features/http/HttpIsQueryTransformer.ts +9 -0
  147. package/src/transformers/features/http/HttpParameterTransformer.ts +9 -0
  148. package/src/transformers/features/http/HttpQueryTransformer.ts +9 -0
  149. package/src/transformers/features/http/HttpValidateHeadersTransformer.ts +10 -0
  150. package/src/transformers/features/http/HttpValidateQueryTransformer.ts +10 -0
@@ -0,0 +1,87 @@
1
+ import ts from "typescript";
2
+
3
+ import { IdentifierFactory } from "../../factories/IdentifierFactory";
4
+ import { StatementFactory } from "../../factories/StatementFactory";
5
+ import { TypeFactory } from "../../factories/TypeFactory";
6
+
7
+ import { IProject } from "../../transformers/IProject";
8
+
9
+ import { IsProgrammer } from "../IsProgrammer";
10
+ import { HttpQueryProgrammer } from "./HttpQueryProgrammer";
11
+
12
+ export namespace HttpIsQueryProgrammer {
13
+ export const write =
14
+ (project: IProject) =>
15
+ (modulo: ts.LeftHandSideExpression) =>
16
+ (type: ts.Type, name?: string): ts.ArrowFunction =>
17
+ ts.factory.createArrowFunction(
18
+ undefined,
19
+ undefined,
20
+ [
21
+ IdentifierFactory.parameter(
22
+ "input",
23
+ ts.factory.createTypeReferenceNode(
24
+ HttpQueryProgrammer.INPUT_TYPE,
25
+ ),
26
+ ),
27
+ ],
28
+ ts.factory.createUnionTypeNode([
29
+ ts.factory.createTypeReferenceNode(
30
+ `typia.Resolved<${
31
+ name ??
32
+ TypeFactory.getFullName(project.checker)(type)
33
+ }>`,
34
+ ),
35
+ ts.factory.createLiteralTypeNode(ts.factory.createNull()),
36
+ ]),
37
+ undefined,
38
+ ts.factory.createBlock([
39
+ StatementFactory.constant(
40
+ "is",
41
+ IsProgrammer.write({
42
+ ...project,
43
+ options: {
44
+ ...project.options,
45
+ functional: false,
46
+ numeric: false,
47
+ },
48
+ })(modulo)(false)(type, name),
49
+ ),
50
+ StatementFactory.constant(
51
+ "query",
52
+ HttpQueryProgrammer.write({
53
+ ...project,
54
+ options: {
55
+ ...project.options,
56
+ functional: false,
57
+ numeric: false,
58
+ },
59
+ })(modulo)(type, name),
60
+ ),
61
+ StatementFactory.constant(
62
+ "output",
63
+ ts.factory.createCallExpression(
64
+ ts.factory.createIdentifier("query"),
65
+ undefined,
66
+ [ts.factory.createIdentifier("input")],
67
+ ),
68
+ ),
69
+ ts.factory.createIfStatement(
70
+ ts.factory.createPrefixUnaryExpression(
71
+ ts.SyntaxKind.ExclamationToken,
72
+ ts.factory.createCallExpression(
73
+ ts.factory.createIdentifier("is"),
74
+ undefined,
75
+ [ts.factory.createIdentifier("output")],
76
+ ),
77
+ ),
78
+ ts.factory.createReturnStatement(
79
+ ts.factory.createNull(),
80
+ ),
81
+ ),
82
+ ts.factory.createReturnStatement(
83
+ ts.factory.createIdentifier("output"),
84
+ ),
85
+ ]),
86
+ );
87
+ }
@@ -0,0 +1,104 @@
1
+ import ts from "typescript";
2
+
3
+ import { IdentifierFactory } from "../../factories/IdentifierFactory";
4
+ import { MetadataCollection } from "../../factories/MetadataCollection";
5
+ import { MetadataFactory } from "../../factories/MetadataFactory";
6
+ import { StatementFactory } from "../../factories/StatementFactory";
7
+ import { TypeFactory } from "../../factories/TypeFactory";
8
+
9
+ import { Metadata } from "../../schemas/metadata/Metadata";
10
+
11
+ import { IProject } from "../../transformers/IProject";
12
+ import { TransformerError } from "../../transformers/TransformerError";
13
+
14
+ import { AssertProgrammer } from "../AssertProgrammer";
15
+ import { FunctionImporter } from "../helpers/FunctionImporeter";
16
+ import { HttpMetadataUtil } from "../helpers/HttpMetadataUtil";
17
+
18
+ export namespace HttpParameterProgrammer {
19
+ export const write =
20
+ (project: IProject) =>
21
+ (modulo: ts.LeftHandSideExpression) =>
22
+ (type: ts.Type, name?: string): ts.ArrowFunction => {
23
+ const result = MetadataFactory.analyze(project.checker)({
24
+ escape: false,
25
+ constant: true,
26
+ absorb: true,
27
+ validate,
28
+ })(new MetadataCollection())(type);
29
+ if (result.success === false)
30
+ throw TransformerError.from(modulo.getText())(result.errors);
31
+
32
+ const atomic = [...HttpMetadataUtil.atomics(result.data)][0]!;
33
+ const importer: FunctionImporter = new FunctionImporter(
34
+ modulo.getText(),
35
+ );
36
+ const block: ts.Statement[] = [
37
+ StatementFactory.constant(
38
+ "assert",
39
+ AssertProgrammer.write({
40
+ ...project,
41
+ options: {
42
+ numeric: true,
43
+ },
44
+ })(modulo)(false)(type, name),
45
+ ),
46
+ StatementFactory.constant(
47
+ "value",
48
+ ts.factory.createCallExpression(
49
+ importer.use(atomic),
50
+ undefined,
51
+ [ts.factory.createIdentifier("input")],
52
+ ),
53
+ ),
54
+ ts.factory.createReturnStatement(
55
+ ts.factory.createCallExpression(
56
+ ts.factory.createIdentifier("assert"),
57
+ undefined,
58
+ [ts.factory.createIdentifier("value")],
59
+ ),
60
+ ),
61
+ ];
62
+
63
+ return ts.factory.createArrowFunction(
64
+ undefined,
65
+ undefined,
66
+ [
67
+ IdentifierFactory.parameter(
68
+ "input",
69
+ ts.factory.createTypeReferenceNode("string"),
70
+ ),
71
+ ],
72
+ ts.factory.createTypeReferenceNode(
73
+ name ?? TypeFactory.getFullName(project.checker)(type),
74
+ ),
75
+ undefined,
76
+ ts.factory.createBlock(
77
+ [...importer.declare(modulo), ...block],
78
+ true,
79
+ ),
80
+ );
81
+ };
82
+
83
+ const validate = (meta: Metadata): string[] => {
84
+ const errors: string[] = [];
85
+ const insert = (msg: string) => errors.push(msg);
86
+
87
+ if (meta.any) insert("do not allow any type");
88
+ if (meta.isRequired() === false)
89
+ insert("do not allow undefindable type");
90
+
91
+ const atomics = HttpMetadataUtil.atomics(meta);
92
+ const expected: number =
93
+ meta.atomics.length +
94
+ meta.templates.length +
95
+ meta.constants
96
+ .map((c) => c.values.length)
97
+ .reduce((a, b) => a + b, 0);
98
+ if (meta.size() !== expected || atomics.size === 0)
99
+ insert("only atomic or constant types are allowed");
100
+ if (atomics.size > 1) insert("do not allow union type");
101
+
102
+ return errors;
103
+ };
104
+ }
@@ -0,0 +1,286 @@
1
+ import ts from "typescript";
2
+
3
+ import { IdentifierFactory } from "../../factories/IdentifierFactory";
4
+ import { MetadataCollection } from "../../factories/MetadataCollection";
5
+ import { MetadataFactory } from "../../factories/MetadataFactory";
6
+ import { StatementFactory } from "../../factories/StatementFactory";
7
+ import { TypeFactory } from "../../factories/TypeFactory";
8
+
9
+ import { Metadata } from "../../schemas/metadata/Metadata";
10
+ import { MetadataArrayType } from "../../schemas/metadata/MetadataArrayType";
11
+ import { MetadataObject } from "../../schemas/metadata/MetadataObject";
12
+ import { MetadataProperty } from "../../schemas/metadata/MetadataProperty";
13
+
14
+ import { IProject } from "../../transformers/IProject";
15
+ import { TransformerError } from "../../transformers/TransformerError";
16
+
17
+ import { Atomic } from "../../typings/Atomic";
18
+
19
+ import { Escaper } from "../../utils/Escaper";
20
+
21
+ import { FunctionImporter } from "../helpers/FunctionImporeter";
22
+ import { HttpMetadataUtil } from "../helpers/HttpMetadataUtil";
23
+
24
+ export namespace HttpQueryProgrammer {
25
+ export const INPUT_TYPE = "string | URLSearchParams";
26
+
27
+ export const write =
28
+ (project: IProject) =>
29
+ (modulo: ts.LeftHandSideExpression) =>
30
+ (type: ts.Type, name?: string): ts.ArrowFunction => {
31
+ // GET OBJECT TYPE
32
+ const importer: FunctionImporter = new FunctionImporter(
33
+ modulo.getText(),
34
+ );
35
+ const collection: MetadataCollection = new MetadataCollection();
36
+ const result = MetadataFactory.analyze(project.checker)({
37
+ escape: false,
38
+ constant: true,
39
+ absorb: true,
40
+ validate,
41
+ })(collection)(type);
42
+ if (result.success === false)
43
+ throw TransformerError.from(`typia.http.${importer.method}`)(
44
+ result.errors,
45
+ );
46
+
47
+ // DO TRANSFORM
48
+ const object: MetadataObject = result.data.objects[0]!;
49
+ const statements: ts.Statement[] = decode_object(importer)(object);
50
+ return ts.factory.createArrowFunction(
51
+ undefined,
52
+ undefined,
53
+ [
54
+ IdentifierFactory.parameter(
55
+ "input",
56
+ ts.factory.createTypeReferenceNode(INPUT_TYPE),
57
+ ),
58
+ ],
59
+ ts.factory.createTypeReferenceNode(
60
+ `typia.Resolved<${
61
+ name ?? TypeFactory.getFullName(project.checker)(type)
62
+ }>`,
63
+ ),
64
+ undefined,
65
+ ts.factory.createBlock(
66
+ [...importer.declare(modulo), ...statements],
67
+ true,
68
+ ),
69
+ );
70
+ };
71
+
72
+ const validate = (
73
+ meta: Metadata,
74
+ explore: MetadataFactory.IExplore,
75
+ ): string[] => {
76
+ const errors: string[] = [];
77
+ const insert = (msg: string) => errors.push(msg);
78
+
79
+ if (explore.top === true) {
80
+ // TOP MUST BE ONLY OBJECT
81
+ if (meta.objects.length !== 1 || meta.bucket() !== 1)
82
+ insert("only one object type is allowed.");
83
+ if (meta.nullable === true)
84
+ insert("query parameters cannot be null.");
85
+ if (meta.isRequired() === false)
86
+ insert("query parameters cannot be undefined.");
87
+ } else if (
88
+ explore.nested !== null &&
89
+ explore.nested instanceof MetadataArrayType
90
+ ) {
91
+ const atomics = HttpMetadataUtil.atomics(meta);
92
+ const expected: number =
93
+ meta.atomics.length +
94
+ meta.templates.length +
95
+ meta.constants
96
+ .map((c) => c.values.length)
97
+ .reduce((a, b) => a + b, 0);
98
+ if (atomics.size > 1) insert("union type is not allowed in array.");
99
+ if (meta.nullable) insert("nullable type is not allowed in array.");
100
+ if (meta.isRequired() === false)
101
+ insert("optional type is not allowed in array.");
102
+ if (meta.size() !== expected)
103
+ insert("only atomic or constant types are allowed in array.");
104
+ } else if (explore.object && explore.property !== null) {
105
+ //----
106
+ // COMMON
107
+ //----
108
+ // PROPERTY MUST BE SOLE
109
+ if (typeof explore.property === "object")
110
+ insert("dynamic property is not allowed.");
111
+ // DO NOT ALLOW TUPLE TYPE
112
+ if (meta.tuples.length) insert("tuple type is not allowed.");
113
+ // DO NOT ALLOW UNION TYPE
114
+ if (HttpMetadataUtil.isUnion(meta))
115
+ insert("union type is not allowed.");
116
+ // DO NOT ALLOW NESTED OBJECT
117
+ if (
118
+ meta.objects.length ||
119
+ meta.sets.length ||
120
+ meta.maps.length ||
121
+ meta.natives.length
122
+ )
123
+ insert("nested object type is not allowed.");
124
+
125
+ //----
126
+ // ARRAY CASES
127
+ //----
128
+ const isArray: boolean =
129
+ meta.arrays.length > 1 || meta.tuples.length > 1;
130
+ // ARRAY TYPE MUST BE REQUIRED
131
+ if (isArray && meta.isRequired() === false)
132
+ insert("optional type is not allowed when array.");
133
+ // SET-COOKIE MUST BE ARRAY
134
+ if (explore.property === "set-cookie" && !isArray)
135
+ insert("set-cookie property must be array.");
136
+ }
137
+ return errors;
138
+ };
139
+
140
+ const decode_object =
141
+ (importer: FunctionImporter) =>
142
+ (object: MetadataObject): ts.Statement[] => {
143
+ const input: ts.Identifier = ts.factory.createIdentifier("input");
144
+ const output: ts.Identifier = ts.factory.createIdentifier("output");
145
+ const optionals: string[] = [];
146
+
147
+ return [
148
+ ts.factory.createExpressionStatement(
149
+ ts.factory.createBinaryExpression(
150
+ input,
151
+ ts.factory.createToken(ts.SyntaxKind.EqualsToken),
152
+ ts.factory.createAsExpression(
153
+ ts.factory.createCallExpression(
154
+ importer.use("params"),
155
+ undefined,
156
+ [input],
157
+ ),
158
+ ts.factory.createTypeReferenceNode(
159
+ "URLSearchParams",
160
+ ),
161
+ ),
162
+ ),
163
+ ),
164
+ StatementFactory.constant(
165
+ "output",
166
+ ts.factory.createObjectLiteralExpression(
167
+ object.properties.map((prop) => {
168
+ if (
169
+ !prop.value.isRequired() &&
170
+ prop.value.arrays.length +
171
+ prop.value.tuples.length >
172
+ 0
173
+ )
174
+ optionals.push(
175
+ prop.key.constants[0]!.values[0] as string,
176
+ );
177
+ return decode_regular_property(importer)(prop);
178
+ }),
179
+ true,
180
+ ),
181
+ ),
182
+ ...optionals.map((key) => {
183
+ const access = IdentifierFactory.access(output)(key);
184
+ return ts.factory.createIfStatement(
185
+ ts.factory.createStrictEquality(
186
+ ts.factory.createNumericLiteral(0),
187
+ IdentifierFactory.access(access)("length"),
188
+ ),
189
+ ts.factory.createExpressionStatement(
190
+ ts.factory.createDeleteExpression(access),
191
+ ),
192
+ );
193
+ }),
194
+ ts.factory.createReturnStatement(
195
+ ts.factory.createAsExpression(
196
+ output,
197
+ TypeFactory.keyword("any"),
198
+ ),
199
+ ),
200
+ ];
201
+ };
202
+
203
+ const decode_regular_property =
204
+ (importer: FunctionImporter) =>
205
+ (property: MetadataProperty): ts.PropertyAssignment => {
206
+ const key: string = property.key.constants[0]!.values[0] as string;
207
+ const value: Metadata = property.value;
208
+
209
+ const [type, isArray]: [Atomic.Literal, boolean] = value.atomics
210
+ .length
211
+ ? [value.atomics[0]!.type, false]
212
+ : value.constants.length
213
+ ? [value.constants[0]!.type, false]
214
+ : value.templates.length
215
+ ? ["string", false]
216
+ : (() => {
217
+ const meta =
218
+ value.arrays[0]?.type.value ??
219
+ value.tuples[0]!.type.elements[0]!;
220
+ return meta.atomics.length
221
+ ? [meta.atomics[0]!.type, true]
222
+ : meta.templates.length
223
+ ? ["string", true]
224
+ : [meta.constants[0]!.type, true];
225
+ })();
226
+ return ts.factory.createPropertyAssignment(
227
+ Escaper.variable(key)
228
+ ? key
229
+ : ts.factory.createStringLiteral(key),
230
+ isArray
231
+ ? ts.factory.createCallExpression(
232
+ IdentifierFactory.access(
233
+ ts.factory.createCallExpression(
234
+ ts.factory.createIdentifier("input.getAll"),
235
+ undefined,
236
+ [ts.factory.createStringLiteral(key)],
237
+ ),
238
+ )("map"),
239
+ undefined,
240
+ [
241
+ ts.factory.createArrowFunction(
242
+ undefined,
243
+ undefined,
244
+ [IdentifierFactory.parameter("elem")],
245
+ undefined,
246
+ undefined,
247
+ decode_value(importer)(type)(false)(
248
+ ts.factory.createIdentifier("elem"),
249
+ ),
250
+ ),
251
+ ],
252
+ )
253
+ : decode_value(importer)(type)(
254
+ value.nullable === false &&
255
+ value.isRequired() === false,
256
+ )(
257
+ ts.factory.createCallExpression(
258
+ ts.factory.createIdentifier("input.get"),
259
+ undefined,
260
+ [ts.factory.createStringLiteral(key)],
261
+ ),
262
+ ),
263
+ );
264
+ };
265
+
266
+ const decode_value =
267
+ (importer: FunctionImporter) =>
268
+ (type: Atomic.Literal) =>
269
+ (onlyUndefindable: boolean) =>
270
+ (value: ts.Expression) => {
271
+ const call = ts.factory.createCallExpression(
272
+ importer.use(type),
273
+ undefined,
274
+ [value],
275
+ );
276
+ return onlyUndefindable
277
+ ? ts.factory.createBinaryExpression(
278
+ call,
279
+ ts.factory.createToken(
280
+ ts.SyntaxKind.QuestionQuestionToken,
281
+ ),
282
+ ts.factory.createIdentifier("undefined"),
283
+ )
284
+ : call;
285
+ };
286
+ }
@@ -0,0 +1,77 @@
1
+ import ts from "typescript";
2
+
3
+ import { IdentifierFactory } from "../../factories/IdentifierFactory";
4
+ import { StatementFactory } from "../../factories/StatementFactory";
5
+ import { TypeFactory } from "../../factories/TypeFactory";
6
+
7
+ import { IProject } from "../../transformers/IProject";
8
+
9
+ import { ValidateProgrammer } from "../ValidateProgrammer";
10
+ import { HttpHeadersProgrammer } from "./HttpHeadersProgrammer";
11
+
12
+ export namespace HttpValidateHeadersProgrammer {
13
+ export const write =
14
+ (project: IProject) =>
15
+ (modulo: ts.LeftHandSideExpression) =>
16
+ (type: ts.Type, name?: string): ts.ArrowFunction =>
17
+ ts.factory.createArrowFunction(
18
+ undefined,
19
+ undefined,
20
+ [
21
+ IdentifierFactory.parameter(
22
+ "input",
23
+ ts.factory.createTypeReferenceNode(
24
+ HttpHeadersProgrammer.INPUT_TYPE,
25
+ ),
26
+ ),
27
+ ],
28
+ ts.factory.createTypeReferenceNode(
29
+ `typia.IValidation<typia.Resolved<${
30
+ name ?? TypeFactory.getFullName(project.checker)(type)
31
+ }>>`,
32
+ ),
33
+ undefined,
34
+ ts.factory.createBlock([
35
+ StatementFactory.constant(
36
+ "validate",
37
+ ValidateProgrammer.write({
38
+ ...project,
39
+ options: {
40
+ ...project.options,
41
+ functional: false,
42
+ numeric: true,
43
+ },
44
+ })(modulo)(false)(type, name),
45
+ ),
46
+ StatementFactory.constant(
47
+ "headers",
48
+ HttpHeadersProgrammer.write({
49
+ ...project,
50
+ options: {
51
+ ...project.options,
52
+ functional: false,
53
+ numeric: false,
54
+ },
55
+ })(modulo)(type, name),
56
+ ),
57
+ StatementFactory.constant(
58
+ "output",
59
+ ts.factory.createCallExpression(
60
+ ts.factory.createIdentifier("headers"),
61
+ undefined,
62
+ [ts.factory.createIdentifier("input")],
63
+ ),
64
+ ),
65
+ ts.factory.createReturnStatement(
66
+ ts.factory.createAsExpression(
67
+ ts.factory.createCallExpression(
68
+ ts.factory.createIdentifier("validate"),
69
+ undefined,
70
+ [ts.factory.createIdentifier("output")],
71
+ ),
72
+ ts.factory.createTypeReferenceNode("any"),
73
+ ),
74
+ ),
75
+ ]),
76
+ );
77
+ }
@@ -0,0 +1,77 @@
1
+ import ts from "typescript";
2
+
3
+ import { IdentifierFactory } from "../../factories/IdentifierFactory";
4
+ import { StatementFactory } from "../../factories/StatementFactory";
5
+ import { TypeFactory } from "../../factories/TypeFactory";
6
+
7
+ import { IProject } from "../../transformers/IProject";
8
+
9
+ import { ValidateProgrammer } from "../ValidateProgrammer";
10
+ import { HttpQueryProgrammer } from "./HttpQueryProgrammer";
11
+
12
+ export namespace HttpValidateQueryProgrammer {
13
+ export const write =
14
+ (project: IProject) =>
15
+ (modulo: ts.LeftHandSideExpression) =>
16
+ (type: ts.Type, name?: string): ts.ArrowFunction =>
17
+ ts.factory.createArrowFunction(
18
+ undefined,
19
+ undefined,
20
+ [
21
+ IdentifierFactory.parameter(
22
+ "input",
23
+ ts.factory.createTypeReferenceNode(
24
+ HttpQueryProgrammer.INPUT_TYPE,
25
+ ),
26
+ ),
27
+ ],
28
+ ts.factory.createTypeReferenceNode(
29
+ `typia.IValidation<typia.Resolved<${
30
+ name ?? TypeFactory.getFullName(project.checker)(type)
31
+ }>>`,
32
+ ),
33
+ undefined,
34
+ ts.factory.createBlock([
35
+ StatementFactory.constant(
36
+ "validate",
37
+ ValidateProgrammer.write({
38
+ ...project,
39
+ options: {
40
+ ...project.options,
41
+ functional: false,
42
+ numeric: true,
43
+ },
44
+ })(modulo)(false)(type, name),
45
+ ),
46
+ StatementFactory.constant(
47
+ "query",
48
+ HttpQueryProgrammer.write({
49
+ ...project,
50
+ options: {
51
+ ...project.options,
52
+ functional: false,
53
+ numeric: false,
54
+ },
55
+ })(modulo)(type, name),
56
+ ),
57
+ StatementFactory.constant(
58
+ "output",
59
+ ts.factory.createCallExpression(
60
+ ts.factory.createIdentifier("query"),
61
+ undefined,
62
+ [ts.factory.createIdentifier("input")],
63
+ ),
64
+ ),
65
+ ts.factory.createReturnStatement(
66
+ ts.factory.createAsExpression(
67
+ ts.factory.createCallExpression(
68
+ ts.factory.createIdentifier("validate"),
69
+ undefined,
70
+ [ts.factory.createIdentifier("output")],
71
+ ),
72
+ ts.factory.createTypeReferenceNode("any"),
73
+ ),
74
+ ),
75
+ ]),
76
+ );
77
+ }