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