@zimic/http 0.4.0-canary.0 → 0.4.0-canary.2
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.
- package/README.md +1 -1
- package/dist/{chunk-IJVT4RDC.mjs → chunk-KVTV4E5K.mjs} +26 -100
- package/dist/chunk-KVTV4E5K.mjs.map +1 -0
- package/dist/{chunk-DIZB36SQ.js → chunk-LOHINQWU.js} +26 -100
- package/dist/chunk-LOHINQWU.js.map +1 -0
- package/dist/cli.js +7 -7
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +2 -2
- package/dist/cli.mjs.map +1 -1
- package/dist/index.d.ts +140 -195
- package/dist/index.js +6 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +6 -3
- package/dist/index.mjs.map +1 -1
- package/dist/typegen.js +2 -2
- package/dist/typegen.mjs +1 -1
- package/package.json +2 -2
- package/src/formData/HttpFormData.ts +44 -54
- package/src/formData/types.ts +36 -42
- package/src/headers/HttpHeaders.ts +38 -35
- package/src/headers/types.ts +2 -2
- package/src/pathParams/types.ts +29 -40
- package/src/searchParams/HttpSearchParams.ts +57 -49
- package/src/searchParams/types.ts +39 -45
- package/src/typegen/openapi/transform/components.ts +1 -11
- package/src/typegen/openapi/transform/context.ts +0 -3
- package/src/typegen/openapi/transform/methods.ts +23 -88
- package/src/typegen/openapi/transform/operations.ts +1 -11
- package/src/typegen/openapi/transform/paths.ts +1 -17
- package/src/types/requests.ts +60 -19
- package/src/types/schema.ts +50 -134
- package/dist/chunk-DIZB36SQ.js.map +0 -1
- package/dist/chunk-IJVT4RDC.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -144,7 +144,7 @@ Check our [getting started guide](https://github.com/zimicjs/zimic/wiki/getting
|
|
|
144
144
|
type UserListHeaders = Schema['/users']['GET']['request']['headers'];
|
|
145
145
|
|
|
146
146
|
const headers = new HttpHeaders<UserListHeaders>({
|
|
147
|
-
authorization: 'Bearer token',
|
|
147
|
+
authorization: 'Bearer my-token',
|
|
148
148
|
});
|
|
149
149
|
|
|
150
150
|
type UserListSearchParams = Schema['/users']['GET']['request']['searchParams'];
|
|
@@ -153,15 +153,6 @@ function isOperation(node) {
|
|
|
153
153
|
return ts3.isPropertySignature(node) && (ts3.isIdentifier(node.name) || ts3.isStringLiteral(node.name)) && node.type !== void 0 && ts3.isTypeLiteralNode(node.type);
|
|
154
154
|
}
|
|
155
155
|
__name(isOperation, "isOperation");
|
|
156
|
-
function wrapOperationType(type, context) {
|
|
157
|
-
context.typeImports.http.add("HttpSchema");
|
|
158
|
-
const httpSchemaMethodWrapper = ts3.factory.createQualifiedName(
|
|
159
|
-
ts3.factory.createIdentifier("HttpSchema"),
|
|
160
|
-
ts3.factory.createIdentifier("Method")
|
|
161
|
-
);
|
|
162
|
-
return ts3.factory.createTypeReferenceNode(httpSchemaMethodWrapper, [type]);
|
|
163
|
-
}
|
|
164
|
-
__name(wrapOperationType, "wrapOperationType");
|
|
165
156
|
function normalizeOperation(operation, context) {
|
|
166
157
|
if (!isOperation(operation)) {
|
|
167
158
|
return void 0;
|
|
@@ -172,7 +163,7 @@ function normalizeOperation(operation, context) {
|
|
|
172
163
|
operation.modifiers,
|
|
173
164
|
operation.name,
|
|
174
165
|
operation.questionToken,
|
|
175
|
-
|
|
166
|
+
newType
|
|
176
167
|
);
|
|
177
168
|
}
|
|
178
169
|
__name(normalizeOperation, "normalizeOperation");
|
|
@@ -237,7 +228,7 @@ function isRequestHeaders(node) {
|
|
|
237
228
|
}
|
|
238
229
|
__name(isRequestHeaders, "isRequestHeaders");
|
|
239
230
|
function isNormalizedRequestHeaders(node) {
|
|
240
|
-
return isRequestMember(node) && node.name.text === "headers" && ts3.
|
|
231
|
+
return isRequestMember(node) && node.name.text === "headers" && ts3.isTypeLiteralNode(node.type);
|
|
241
232
|
}
|
|
242
233
|
__name(isNormalizedRequestHeaders, "isNormalizedRequestHeaders");
|
|
243
234
|
function isRequestParameters(node) {
|
|
@@ -283,21 +274,15 @@ function removeRedundantNullUnionIfNecessary(type) {
|
|
|
283
274
|
__name(removeRedundantNullUnionIfNecessary, "removeRedundantNullUnionIfNecessary");
|
|
284
275
|
function wrapFormDataContentType(type, context) {
|
|
285
276
|
context.typeImports.http.add("HttpFormData");
|
|
286
|
-
context.typeImports.http.add("HttpFormDataSerialized");
|
|
287
277
|
return ts3.factory.createTypeReferenceNode(ts3.factory.createIdentifier("HttpFormData"), [
|
|
288
|
-
|
|
289
|
-
renameComponentReferences(type, context)
|
|
290
|
-
])
|
|
278
|
+
renameComponentReferences(type, context)
|
|
291
279
|
]);
|
|
292
280
|
}
|
|
293
281
|
__name(wrapFormDataContentType, "wrapFormDataContentType");
|
|
294
282
|
function wrapURLEncodedContentType(type, context) {
|
|
295
283
|
context.typeImports.http.add("HttpSearchParams");
|
|
296
|
-
context.typeImports.http.add("HttpSearchParamsSerialized");
|
|
297
284
|
return ts3.factory.createTypeReferenceNode(ts3.factory.createIdentifier("HttpSearchParams"), [
|
|
298
|
-
|
|
299
|
-
renameComponentReferences(type, context)
|
|
300
|
-
])
|
|
285
|
+
renameComponentReferences(type, context)
|
|
301
286
|
]);
|
|
302
287
|
}
|
|
303
288
|
__name(wrapURLEncodedContentType, "wrapURLEncodedContentType");
|
|
@@ -325,16 +310,7 @@ function normalizeRequestBodyMember(requestBodyMember, context, options) {
|
|
|
325
310
|
};
|
|
326
311
|
}
|
|
327
312
|
__name(normalizeRequestBodyMember, "normalizeRequestBodyMember");
|
|
328
|
-
function
|
|
329
|
-
context.typeImports.http.add("HttpHeadersSerialized");
|
|
330
|
-
const serializedWrapper = ts3.factory.createIdentifier("HttpHeadersSerialized");
|
|
331
|
-
return ts3.factory.createTypeReferenceNode(
|
|
332
|
-
serializedWrapper,
|
|
333
|
-
ts3.factory.createNodeArray([type])
|
|
334
|
-
);
|
|
335
|
-
}
|
|
336
|
-
__name(wrapHeadersType, "wrapHeadersType");
|
|
337
|
-
function normalizeHeaders(headers, context) {
|
|
313
|
+
function normalizeHeaders(headers) {
|
|
338
314
|
const newHeaderMembers = headers.members.filter((header) => {
|
|
339
315
|
if (ts3.isIndexSignatureDeclaration(header)) {
|
|
340
316
|
return false;
|
|
@@ -347,15 +323,14 @@ function normalizeHeaders(headers, context) {
|
|
|
347
323
|
if (newHeaderMembers.length === 0) {
|
|
348
324
|
return void 0;
|
|
349
325
|
}
|
|
350
|
-
|
|
351
|
-
return wrapHeadersType(newHeaders, context);
|
|
326
|
+
return ts3.factory.updateTypeLiteralNode(headers, ts3.factory.createNodeArray(newHeaderMembers));
|
|
352
327
|
}
|
|
353
328
|
__name(normalizeHeaders, "normalizeHeaders");
|
|
354
|
-
function normalizeRequestHeaders(requestHeader
|
|
329
|
+
function normalizeRequestHeaders(requestHeader) {
|
|
355
330
|
if (!isRequestHeaders(requestHeader)) {
|
|
356
331
|
return void 0;
|
|
357
332
|
}
|
|
358
|
-
const newType = normalizeHeaders(requestHeader.type
|
|
333
|
+
const newType = normalizeHeaders(requestHeader.type);
|
|
359
334
|
if (!newType) {
|
|
360
335
|
return void 0;
|
|
361
336
|
}
|
|
@@ -368,17 +343,14 @@ function normalizeRequestHeaders(requestHeader, context) {
|
|
|
368
343
|
);
|
|
369
344
|
}
|
|
370
345
|
__name(normalizeRequestHeaders, "normalizeRequestHeaders");
|
|
371
|
-
function createHeaderForUnionByContentType(existingHeader, contentTypeName
|
|
372
|
-
const existingHeaderMembers = existingHeader
|
|
346
|
+
function createHeaderForUnionByContentType(existingHeader, contentTypeName) {
|
|
347
|
+
const existingHeaderMembers = existingHeader?.type.members ?? [];
|
|
373
348
|
const contentTypeIdentifier = ts3.factory.createIdentifier('"content-type"');
|
|
374
349
|
const contentTypeValue = ts3.factory.createLiteralTypeNode(ts3.factory.createStringLiteral(contentTypeName));
|
|
375
|
-
const newHeaderType =
|
|
376
|
-
ts3.factory.
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
]),
|
|
380
|
-
context
|
|
381
|
-
);
|
|
350
|
+
const newHeaderType = ts3.factory.createTypeLiteralNode([
|
|
351
|
+
ts3.factory.createPropertySignature(void 0, contentTypeIdentifier, void 0, contentTypeValue),
|
|
352
|
+
...existingHeaderMembers
|
|
353
|
+
]);
|
|
382
354
|
return ts3.factory.createPropertySignature(
|
|
383
355
|
existingHeader?.modifiers,
|
|
384
356
|
ts3.factory.createIdentifier("headers"),
|
|
@@ -395,7 +367,7 @@ function normalizeContentType(contentType, context, options) {
|
|
|
395
367
|
if (!ts3.isTypeLiteralNode(contentType)) {
|
|
396
368
|
return contentType;
|
|
397
369
|
}
|
|
398
|
-
const newHeader = contentType.members.map(
|
|
370
|
+
const newHeader = contentType.members.map(normalizeRequestHeaders).find(isDefined_default);
|
|
399
371
|
const newBodyMembers = contentType.members.flatMap((body) => {
|
|
400
372
|
if (isContentPropertySignature(body)) {
|
|
401
373
|
return body.type.members.map((member) => normalizeRequestBodyMember(member, context, { questionToken: bodyQuestionToken })).filter(isDefined_default);
|
|
@@ -407,7 +379,7 @@ function normalizeContentType(contentType, context, options) {
|
|
|
407
379
|
return ts3.factory.updateTypeLiteralNode(contentType, ts3.factory.createNodeArray(newMembers));
|
|
408
380
|
} else {
|
|
409
381
|
const bodyMemberUnionTypes = newBodyMembers.map((bodyMember) => {
|
|
410
|
-
const headerMember = createHeaderForUnionByContentType(newHeader, bodyMember.contentTypeName
|
|
382
|
+
const headerMember = createHeaderForUnionByContentType(newHeader, bodyMember.contentTypeName);
|
|
411
383
|
return ts3.factory.createTypeLiteralNode([headerMember, bodyMember.propertySignature]);
|
|
412
384
|
});
|
|
413
385
|
return ts3.factory.createUnionTypeNode(bodyMemberUnionTypes);
|
|
@@ -426,22 +398,12 @@ function normalizeRequest(request, context) {
|
|
|
426
398
|
return ts3.factory.updatePropertySignature(request, request.modifiers, newIdentifier, void 0, newType);
|
|
427
399
|
}
|
|
428
400
|
__name(normalizeRequest, "normalizeRequest");
|
|
429
|
-
function wrapResponseType(type, context) {
|
|
430
|
-
context.typeImports.http.add("HttpSchema");
|
|
431
|
-
const httpSchemaResponseWrapper = ts3.factory.createQualifiedName(
|
|
432
|
-
ts3.factory.createIdentifier("HttpSchema"),
|
|
433
|
-
ts3.factory.createIdentifier("Response")
|
|
434
|
-
);
|
|
435
|
-
return ts3.factory.createTypeReferenceNode(httpSchemaResponseWrapper, [type]);
|
|
436
|
-
}
|
|
437
|
-
__name(wrapResponseType, "wrapResponseType");
|
|
438
401
|
function normalizeResponseType(responseType, context, options) {
|
|
439
|
-
const {
|
|
402
|
+
const { questionToken } = options;
|
|
440
403
|
if (!ts3.isTypeLiteralNode(responseType)) {
|
|
441
404
|
return responseType;
|
|
442
405
|
}
|
|
443
|
-
|
|
444
|
-
return isComponent2 ? wrapResponseType(newType, context) : newType;
|
|
406
|
+
return normalizeContentType(responseType, context, { bodyQuestionToken: questionToken });
|
|
445
407
|
}
|
|
446
408
|
__name(normalizeResponseType, "normalizeResponseType");
|
|
447
409
|
var NON_NUMERIC_RESPONSE_STATUS_TO_MAPPED_TYPE = {
|
|
@@ -458,7 +420,6 @@ function normalizeResponse(response, context, options = {}) {
|
|
|
458
420
|
return void 0;
|
|
459
421
|
}
|
|
460
422
|
const newType = normalizeResponseType(response.type, context, {
|
|
461
|
-
isComponent: isComponent2,
|
|
462
423
|
questionToken: response.questionToken
|
|
463
424
|
});
|
|
464
425
|
const statusCodeOrComponentName = response.name.text;
|
|
@@ -566,15 +527,12 @@ function normalizeRequestQueryWithParameters(requestMember, context) {
|
|
|
566
527
|
const newIdentifier = ts3.factory.createIdentifier("searchParams");
|
|
567
528
|
const newQuestionToken = void 0;
|
|
568
529
|
const newType = renameComponentReferences(requestMember.type, context);
|
|
569
|
-
context.typeImports.http.add("HttpSearchParamsSerialized");
|
|
570
|
-
const serializedWrapper = ts3.factory.createIdentifier("HttpSearchParamsSerialized");
|
|
571
|
-
const wrappedNewType = ts3.factory.createTypeReferenceNode(serializedWrapper, [newType]);
|
|
572
530
|
return ts3.factory.updatePropertySignature(
|
|
573
531
|
requestMember,
|
|
574
532
|
requestMember.modifiers,
|
|
575
533
|
newIdentifier,
|
|
576
534
|
newQuestionToken,
|
|
577
|
-
|
|
535
|
+
newType
|
|
578
536
|
);
|
|
579
537
|
}
|
|
580
538
|
__name(normalizeRequestQueryWithParameters, "normalizeRequestQueryWithParameters");
|
|
@@ -582,15 +540,12 @@ function normalizeRequestHeadersWithParameters(requestMember, context) {
|
|
|
582
540
|
const newIdentifier = ts3.factory.createIdentifier("headers");
|
|
583
541
|
const newQuestionToken = void 0;
|
|
584
542
|
const newType = renameComponentReferences(requestMember.type, context);
|
|
585
|
-
context.typeImports.http.add("HttpHeadersSerialized");
|
|
586
|
-
const serializedWrapper = ts3.factory.createIdentifier("HttpHeadersSerialized");
|
|
587
|
-
const wrappedNewType = ts3.factory.createTypeReferenceNode(serializedWrapper, [newType]);
|
|
588
543
|
return ts3.factory.updatePropertySignature(
|
|
589
544
|
requestMember,
|
|
590
545
|
requestMember.modifiers,
|
|
591
546
|
newIdentifier,
|
|
592
547
|
newQuestionToken,
|
|
593
|
-
|
|
548
|
+
newType
|
|
594
549
|
);
|
|
595
550
|
}
|
|
596
551
|
__name(normalizeRequestHeadersWithParameters, "normalizeRequestHeadersWithParameters");
|
|
@@ -608,14 +563,9 @@ function normalizeRequestMemberWithParameters(requestMember, context) {
|
|
|
608
563
|
}
|
|
609
564
|
__name(normalizeRequestMemberWithParameters, "normalizeRequestMemberWithParameters");
|
|
610
565
|
function mergeRequestHeadersMember(headers, otherHeaders) {
|
|
611
|
-
const
|
|
612
|
-
const otherHeadersTypeLiteral = otherHeaders.type.typeArguments[0];
|
|
613
|
-
const newType = ts3.factory.updateTypeReferenceNode(
|
|
566
|
+
const newType = ts3.factory.updateTypeLiteralNode(
|
|
614
567
|
headers.type,
|
|
615
|
-
headers.type.
|
|
616
|
-
ts3.factory.createNodeArray([
|
|
617
|
-
ts3.factory.createTypeLiteralNode([...otherHeadersTypeLiteral.members, ...headersTypeLiteral.members])
|
|
618
|
-
])
|
|
568
|
+
ts3.factory.createNodeArray([...otherHeaders.type.members, ...headers.type.members])
|
|
619
569
|
);
|
|
620
570
|
return ts3.factory.updatePropertySignature(
|
|
621
571
|
headers,
|
|
@@ -752,15 +702,6 @@ function normalizePathNameWithParameters(pathName) {
|
|
|
752
702
|
return pathName.replace(/{([^}]+)}/g, ":$1");
|
|
753
703
|
}
|
|
754
704
|
__name(normalizePathNameWithParameters, "normalizePathNameWithParameters");
|
|
755
|
-
function wrapComponentPathType(type, context) {
|
|
756
|
-
context.typeImports.http.add("HttpSchema");
|
|
757
|
-
const httpSchemaMethodsWrapper = ts3.factory.createQualifiedName(
|
|
758
|
-
ts3.factory.createIdentifier("HttpSchema"),
|
|
759
|
-
ts3.factory.createIdentifier("Methods")
|
|
760
|
-
);
|
|
761
|
-
return ts3.factory.createTypeReferenceNode(httpSchemaMethodsWrapper, [type]);
|
|
762
|
-
}
|
|
763
|
-
__name(wrapComponentPathType, "wrapComponentPathType");
|
|
764
705
|
function normalizePath(path4, context, options = {}) {
|
|
765
706
|
const { isComponent: isComponent2 = false } = options;
|
|
766
707
|
if (!isPath(path4)) {
|
|
@@ -778,13 +719,7 @@ function normalizePath(path4, context, options = {}) {
|
|
|
778
719
|
} else {
|
|
779
720
|
newType = renameComponentReferences(path4.type, context);
|
|
780
721
|
}
|
|
781
|
-
return ts3.factory.updatePropertySignature(
|
|
782
|
-
path4,
|
|
783
|
-
path4.modifiers,
|
|
784
|
-
newIdentifier,
|
|
785
|
-
path4.questionToken,
|
|
786
|
-
isComponent2 ? wrapComponentPathType(newType, context) : newType
|
|
787
|
-
);
|
|
722
|
+
return ts3.factory.updatePropertySignature(path4, path4.modifiers, newIdentifier, path4.questionToken, newType);
|
|
788
723
|
}
|
|
789
724
|
__name(normalizePath, "normalizePath");
|
|
790
725
|
function wrapPathsType(type, context) {
|
|
@@ -956,15 +891,6 @@ function processPendingRequestComponentActions(component, context) {
|
|
|
956
891
|
return { bodyQuestionToken };
|
|
957
892
|
}
|
|
958
893
|
__name(processPendingRequestComponentActions, "processPendingRequestComponentActions");
|
|
959
|
-
function wrapRequestComponentType(type, context) {
|
|
960
|
-
context.typeImports.http.add("HttpSchema");
|
|
961
|
-
const httpSchemaRequestWrapper = ts3.factory.createQualifiedName(
|
|
962
|
-
ts3.factory.createIdentifier("HttpSchema"),
|
|
963
|
-
ts3.factory.createIdentifier("Request")
|
|
964
|
-
);
|
|
965
|
-
return ts3.factory.createTypeReferenceNode(httpSchemaRequestWrapper, [type]);
|
|
966
|
-
}
|
|
967
|
-
__name(wrapRequestComponentType, "wrapRequestComponentType");
|
|
968
894
|
function normalizeRequestComponent(component, context) {
|
|
969
895
|
if (!isRequestComponent(component)) {
|
|
970
896
|
return void 0;
|
|
@@ -976,7 +902,7 @@ function normalizeRequestComponent(component, context) {
|
|
|
976
902
|
component.modifiers,
|
|
977
903
|
component.name,
|
|
978
904
|
component.questionToken,
|
|
979
|
-
|
|
905
|
+
newType
|
|
980
906
|
);
|
|
981
907
|
}
|
|
982
908
|
__name(normalizeRequestComponent, "normalizeRequestComponent");
|
|
@@ -1403,5 +1329,5 @@ var generate_default = generateTypesFromOpenAPI;
|
|
|
1403
1329
|
* The root import module is defined at build time. The fallback is not expected to be used. */
|
|
1404
1330
|
|
|
1405
1331
|
export { __name, generate_default, logger };
|
|
1406
|
-
//# sourceMappingURL=chunk-
|
|
1407
|
-
//# sourceMappingURL=chunk-
|
|
1332
|
+
//# sourceMappingURL=chunk-KVTV4E5K.mjs.map
|
|
1333
|
+
//# sourceMappingURL=chunk-KVTV4E5K.mjs.map
|