typia 5.1.0-dev.20230923 → 5.1.0-dev.20230924

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