@zimic/http 0.3.2 → 0.4.0-canary.1
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/dist/{chunk-4OL77NXP.mjs → chunk-KVTV4E5K.mjs} +28 -100
- package/dist/chunk-KVTV4E5K.mjs.map +1 -0
- package/dist/{chunk-56PYXPSB.js → chunk-LOHINQWU.js} +28 -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 +71 -132
- package/dist/index.js +3 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +4 -13
- 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 +14 -11
- package/src/headers/HttpHeaders.ts +12 -9
- package/src/headers/types.ts +2 -2
- package/src/index.ts +1 -3
- package/src/searchParams/HttpSearchParams.ts +23 -15
- package/src/searchParams/types.ts +2 -2
- 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 +15 -18
- package/src/types/schema.ts +50 -147
- package/dist/chunk-4OL77NXP.mjs.map +0 -1
- package/dist/chunk-56PYXPSB.js.map +0 -1
|
@@ -49,6 +49,8 @@ function createImportDeclaration(importSpecifiers, moduleName, options) {
|
|
|
49
49
|
);
|
|
50
50
|
}
|
|
51
51
|
__name(createImportDeclaration, "createImportDeclaration");
|
|
52
|
+
|
|
53
|
+
// src/types/schema.ts
|
|
52
54
|
var HTTP_METHODS = Object.freeze(["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"]);
|
|
53
55
|
|
|
54
56
|
// ../zimic-utils/dist/logging/Logger.mjs
|
|
@@ -151,15 +153,6 @@ function isOperation(node) {
|
|
|
151
153
|
return ts3.isPropertySignature(node) && (ts3.isIdentifier(node.name) || ts3.isStringLiteral(node.name)) && node.type !== void 0 && ts3.isTypeLiteralNode(node.type);
|
|
152
154
|
}
|
|
153
155
|
__name(isOperation, "isOperation");
|
|
154
|
-
function wrapOperationType(type, context) {
|
|
155
|
-
context.typeImports.http.add("HttpSchema");
|
|
156
|
-
const httpSchemaMethodWrapper = ts3.factory.createQualifiedName(
|
|
157
|
-
ts3.factory.createIdentifier("HttpSchema"),
|
|
158
|
-
ts3.factory.createIdentifier("Method")
|
|
159
|
-
);
|
|
160
|
-
return ts3.factory.createTypeReferenceNode(httpSchemaMethodWrapper, [type]);
|
|
161
|
-
}
|
|
162
|
-
__name(wrapOperationType, "wrapOperationType");
|
|
163
156
|
function normalizeOperation(operation, context) {
|
|
164
157
|
if (!isOperation(operation)) {
|
|
165
158
|
return void 0;
|
|
@@ -170,7 +163,7 @@ function normalizeOperation(operation, context) {
|
|
|
170
163
|
operation.modifiers,
|
|
171
164
|
operation.name,
|
|
172
165
|
operation.questionToken,
|
|
173
|
-
|
|
166
|
+
newType
|
|
174
167
|
);
|
|
175
168
|
}
|
|
176
169
|
__name(normalizeOperation, "normalizeOperation");
|
|
@@ -235,7 +228,7 @@ function isRequestHeaders(node) {
|
|
|
235
228
|
}
|
|
236
229
|
__name(isRequestHeaders, "isRequestHeaders");
|
|
237
230
|
function isNormalizedRequestHeaders(node) {
|
|
238
|
-
return isRequestMember(node) && node.name.text === "headers" && ts3.
|
|
231
|
+
return isRequestMember(node) && node.name.text === "headers" && ts3.isTypeLiteralNode(node.type);
|
|
239
232
|
}
|
|
240
233
|
__name(isNormalizedRequestHeaders, "isNormalizedRequestHeaders");
|
|
241
234
|
function isRequestParameters(node) {
|
|
@@ -281,21 +274,15 @@ function removeRedundantNullUnionIfNecessary(type) {
|
|
|
281
274
|
__name(removeRedundantNullUnionIfNecessary, "removeRedundantNullUnionIfNecessary");
|
|
282
275
|
function wrapFormDataContentType(type, context) {
|
|
283
276
|
context.typeImports.http.add("HttpFormData");
|
|
284
|
-
context.typeImports.http.add("HttpFormDataSerialized");
|
|
285
277
|
return ts3.factory.createTypeReferenceNode(ts3.factory.createIdentifier("HttpFormData"), [
|
|
286
|
-
|
|
287
|
-
renameComponentReferences(type, context)
|
|
288
|
-
])
|
|
278
|
+
renameComponentReferences(type, context)
|
|
289
279
|
]);
|
|
290
280
|
}
|
|
291
281
|
__name(wrapFormDataContentType, "wrapFormDataContentType");
|
|
292
282
|
function wrapURLEncodedContentType(type, context) {
|
|
293
283
|
context.typeImports.http.add("HttpSearchParams");
|
|
294
|
-
context.typeImports.http.add("HttpSearchParamsSerialized");
|
|
295
284
|
return ts3.factory.createTypeReferenceNode(ts3.factory.createIdentifier("HttpSearchParams"), [
|
|
296
|
-
|
|
297
|
-
renameComponentReferences(type, context)
|
|
298
|
-
])
|
|
285
|
+
renameComponentReferences(type, context)
|
|
299
286
|
]);
|
|
300
287
|
}
|
|
301
288
|
__name(wrapURLEncodedContentType, "wrapURLEncodedContentType");
|
|
@@ -323,16 +310,7 @@ function normalizeRequestBodyMember(requestBodyMember, context, options) {
|
|
|
323
310
|
};
|
|
324
311
|
}
|
|
325
312
|
__name(normalizeRequestBodyMember, "normalizeRequestBodyMember");
|
|
326
|
-
function
|
|
327
|
-
context.typeImports.http.add("HttpHeadersSerialized");
|
|
328
|
-
const serializedWrapper = ts3.factory.createIdentifier("HttpHeadersSerialized");
|
|
329
|
-
return ts3.factory.createTypeReferenceNode(
|
|
330
|
-
serializedWrapper,
|
|
331
|
-
ts3.factory.createNodeArray([type])
|
|
332
|
-
);
|
|
333
|
-
}
|
|
334
|
-
__name(wrapHeadersType, "wrapHeadersType");
|
|
335
|
-
function normalizeHeaders(headers, context) {
|
|
313
|
+
function normalizeHeaders(headers) {
|
|
336
314
|
const newHeaderMembers = headers.members.filter((header) => {
|
|
337
315
|
if (ts3.isIndexSignatureDeclaration(header)) {
|
|
338
316
|
return false;
|
|
@@ -345,15 +323,14 @@ function normalizeHeaders(headers, context) {
|
|
|
345
323
|
if (newHeaderMembers.length === 0) {
|
|
346
324
|
return void 0;
|
|
347
325
|
}
|
|
348
|
-
|
|
349
|
-
return wrapHeadersType(newHeaders, context);
|
|
326
|
+
return ts3.factory.updateTypeLiteralNode(headers, ts3.factory.createNodeArray(newHeaderMembers));
|
|
350
327
|
}
|
|
351
328
|
__name(normalizeHeaders, "normalizeHeaders");
|
|
352
|
-
function normalizeRequestHeaders(requestHeader
|
|
329
|
+
function normalizeRequestHeaders(requestHeader) {
|
|
353
330
|
if (!isRequestHeaders(requestHeader)) {
|
|
354
331
|
return void 0;
|
|
355
332
|
}
|
|
356
|
-
const newType = normalizeHeaders(requestHeader.type
|
|
333
|
+
const newType = normalizeHeaders(requestHeader.type);
|
|
357
334
|
if (!newType) {
|
|
358
335
|
return void 0;
|
|
359
336
|
}
|
|
@@ -366,17 +343,14 @@ function normalizeRequestHeaders(requestHeader, context) {
|
|
|
366
343
|
);
|
|
367
344
|
}
|
|
368
345
|
__name(normalizeRequestHeaders, "normalizeRequestHeaders");
|
|
369
|
-
function createHeaderForUnionByContentType(existingHeader, contentTypeName
|
|
370
|
-
const existingHeaderMembers = existingHeader
|
|
346
|
+
function createHeaderForUnionByContentType(existingHeader, contentTypeName) {
|
|
347
|
+
const existingHeaderMembers = existingHeader?.type.members ?? [];
|
|
371
348
|
const contentTypeIdentifier = ts3.factory.createIdentifier('"content-type"');
|
|
372
349
|
const contentTypeValue = ts3.factory.createLiteralTypeNode(ts3.factory.createStringLiteral(contentTypeName));
|
|
373
|
-
const newHeaderType =
|
|
374
|
-
ts3.factory.
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
]),
|
|
378
|
-
context
|
|
379
|
-
);
|
|
350
|
+
const newHeaderType = ts3.factory.createTypeLiteralNode([
|
|
351
|
+
ts3.factory.createPropertySignature(void 0, contentTypeIdentifier, void 0, contentTypeValue),
|
|
352
|
+
...existingHeaderMembers
|
|
353
|
+
]);
|
|
380
354
|
return ts3.factory.createPropertySignature(
|
|
381
355
|
existingHeader?.modifiers,
|
|
382
356
|
ts3.factory.createIdentifier("headers"),
|
|
@@ -393,7 +367,7 @@ function normalizeContentType(contentType, context, options) {
|
|
|
393
367
|
if (!ts3.isTypeLiteralNode(contentType)) {
|
|
394
368
|
return contentType;
|
|
395
369
|
}
|
|
396
|
-
const newHeader = contentType.members.map(
|
|
370
|
+
const newHeader = contentType.members.map(normalizeRequestHeaders).find(isDefined_default);
|
|
397
371
|
const newBodyMembers = contentType.members.flatMap((body) => {
|
|
398
372
|
if (isContentPropertySignature(body)) {
|
|
399
373
|
return body.type.members.map((member) => normalizeRequestBodyMember(member, context, { questionToken: bodyQuestionToken })).filter(isDefined_default);
|
|
@@ -405,7 +379,7 @@ function normalizeContentType(contentType, context, options) {
|
|
|
405
379
|
return ts3.factory.updateTypeLiteralNode(contentType, ts3.factory.createNodeArray(newMembers));
|
|
406
380
|
} else {
|
|
407
381
|
const bodyMemberUnionTypes = newBodyMembers.map((bodyMember) => {
|
|
408
|
-
const headerMember = createHeaderForUnionByContentType(newHeader, bodyMember.contentTypeName
|
|
382
|
+
const headerMember = createHeaderForUnionByContentType(newHeader, bodyMember.contentTypeName);
|
|
409
383
|
return ts3.factory.createTypeLiteralNode([headerMember, bodyMember.propertySignature]);
|
|
410
384
|
});
|
|
411
385
|
return ts3.factory.createUnionTypeNode(bodyMemberUnionTypes);
|
|
@@ -424,22 +398,12 @@ function normalizeRequest(request, context) {
|
|
|
424
398
|
return ts3.factory.updatePropertySignature(request, request.modifiers, newIdentifier, void 0, newType);
|
|
425
399
|
}
|
|
426
400
|
__name(normalizeRequest, "normalizeRequest");
|
|
427
|
-
function wrapResponseType(type, context) {
|
|
428
|
-
context.typeImports.http.add("HttpSchema");
|
|
429
|
-
const httpSchemaResponseWrapper = ts3.factory.createQualifiedName(
|
|
430
|
-
ts3.factory.createIdentifier("HttpSchema"),
|
|
431
|
-
ts3.factory.createIdentifier("Response")
|
|
432
|
-
);
|
|
433
|
-
return ts3.factory.createTypeReferenceNode(httpSchemaResponseWrapper, [type]);
|
|
434
|
-
}
|
|
435
|
-
__name(wrapResponseType, "wrapResponseType");
|
|
436
401
|
function normalizeResponseType(responseType, context, options) {
|
|
437
|
-
const {
|
|
402
|
+
const { questionToken } = options;
|
|
438
403
|
if (!ts3.isTypeLiteralNode(responseType)) {
|
|
439
404
|
return responseType;
|
|
440
405
|
}
|
|
441
|
-
|
|
442
|
-
return isComponent2 ? wrapResponseType(newType, context) : newType;
|
|
406
|
+
return normalizeContentType(responseType, context, { bodyQuestionToken: questionToken });
|
|
443
407
|
}
|
|
444
408
|
__name(normalizeResponseType, "normalizeResponseType");
|
|
445
409
|
var NON_NUMERIC_RESPONSE_STATUS_TO_MAPPED_TYPE = {
|
|
@@ -456,7 +420,6 @@ function normalizeResponse(response, context, options = {}) {
|
|
|
456
420
|
return void 0;
|
|
457
421
|
}
|
|
458
422
|
const newType = normalizeResponseType(response.type, context, {
|
|
459
|
-
isComponent: isComponent2,
|
|
460
423
|
questionToken: response.questionToken
|
|
461
424
|
});
|
|
462
425
|
const statusCodeOrComponentName = response.name.text;
|
|
@@ -564,15 +527,12 @@ function normalizeRequestQueryWithParameters(requestMember, context) {
|
|
|
564
527
|
const newIdentifier = ts3.factory.createIdentifier("searchParams");
|
|
565
528
|
const newQuestionToken = void 0;
|
|
566
529
|
const newType = renameComponentReferences(requestMember.type, context);
|
|
567
|
-
context.typeImports.http.add("HttpSearchParamsSerialized");
|
|
568
|
-
const serializedWrapper = ts3.factory.createIdentifier("HttpSearchParamsSerialized");
|
|
569
|
-
const wrappedNewType = ts3.factory.createTypeReferenceNode(serializedWrapper, [newType]);
|
|
570
530
|
return ts3.factory.updatePropertySignature(
|
|
571
531
|
requestMember,
|
|
572
532
|
requestMember.modifiers,
|
|
573
533
|
newIdentifier,
|
|
574
534
|
newQuestionToken,
|
|
575
|
-
|
|
535
|
+
newType
|
|
576
536
|
);
|
|
577
537
|
}
|
|
578
538
|
__name(normalizeRequestQueryWithParameters, "normalizeRequestQueryWithParameters");
|
|
@@ -580,15 +540,12 @@ function normalizeRequestHeadersWithParameters(requestMember, context) {
|
|
|
580
540
|
const newIdentifier = ts3.factory.createIdentifier("headers");
|
|
581
541
|
const newQuestionToken = void 0;
|
|
582
542
|
const newType = renameComponentReferences(requestMember.type, context);
|
|
583
|
-
context.typeImports.http.add("HttpHeadersSerialized");
|
|
584
|
-
const serializedWrapper = ts3.factory.createIdentifier("HttpHeadersSerialized");
|
|
585
|
-
const wrappedNewType = ts3.factory.createTypeReferenceNode(serializedWrapper, [newType]);
|
|
586
543
|
return ts3.factory.updatePropertySignature(
|
|
587
544
|
requestMember,
|
|
588
545
|
requestMember.modifiers,
|
|
589
546
|
newIdentifier,
|
|
590
547
|
newQuestionToken,
|
|
591
|
-
|
|
548
|
+
newType
|
|
592
549
|
);
|
|
593
550
|
}
|
|
594
551
|
__name(normalizeRequestHeadersWithParameters, "normalizeRequestHeadersWithParameters");
|
|
@@ -606,14 +563,9 @@ function normalizeRequestMemberWithParameters(requestMember, context) {
|
|
|
606
563
|
}
|
|
607
564
|
__name(normalizeRequestMemberWithParameters, "normalizeRequestMemberWithParameters");
|
|
608
565
|
function mergeRequestHeadersMember(headers, otherHeaders) {
|
|
609
|
-
const
|
|
610
|
-
const otherHeadersTypeLiteral = otherHeaders.type.typeArguments[0];
|
|
611
|
-
const newType = ts3.factory.updateTypeReferenceNode(
|
|
566
|
+
const newType = ts3.factory.updateTypeLiteralNode(
|
|
612
567
|
headers.type,
|
|
613
|
-
headers.type.
|
|
614
|
-
ts3.factory.createNodeArray([
|
|
615
|
-
ts3.factory.createTypeLiteralNode([...otherHeadersTypeLiteral.members, ...headersTypeLiteral.members])
|
|
616
|
-
])
|
|
568
|
+
ts3.factory.createNodeArray([...otherHeaders.type.members, ...headers.type.members])
|
|
617
569
|
);
|
|
618
570
|
return ts3.factory.updatePropertySignature(
|
|
619
571
|
headers,
|
|
@@ -750,15 +702,6 @@ function normalizePathNameWithParameters(pathName) {
|
|
|
750
702
|
return pathName.replace(/{([^}]+)}/g, ":$1");
|
|
751
703
|
}
|
|
752
704
|
__name(normalizePathNameWithParameters, "normalizePathNameWithParameters");
|
|
753
|
-
function wrapComponentPathType(type, context) {
|
|
754
|
-
context.typeImports.http.add("HttpSchema");
|
|
755
|
-
const httpSchemaMethodsWrapper = ts3.factory.createQualifiedName(
|
|
756
|
-
ts3.factory.createIdentifier("HttpSchema"),
|
|
757
|
-
ts3.factory.createIdentifier("Methods")
|
|
758
|
-
);
|
|
759
|
-
return ts3.factory.createTypeReferenceNode(httpSchemaMethodsWrapper, [type]);
|
|
760
|
-
}
|
|
761
|
-
__name(wrapComponentPathType, "wrapComponentPathType");
|
|
762
705
|
function normalizePath(path4, context, options = {}) {
|
|
763
706
|
const { isComponent: isComponent2 = false } = options;
|
|
764
707
|
if (!isPath(path4)) {
|
|
@@ -776,13 +719,7 @@ function normalizePath(path4, context, options = {}) {
|
|
|
776
719
|
} else {
|
|
777
720
|
newType = renameComponentReferences(path4.type, context);
|
|
778
721
|
}
|
|
779
|
-
return ts3.factory.updatePropertySignature(
|
|
780
|
-
path4,
|
|
781
|
-
path4.modifiers,
|
|
782
|
-
newIdentifier,
|
|
783
|
-
path4.questionToken,
|
|
784
|
-
isComponent2 ? wrapComponentPathType(newType, context) : newType
|
|
785
|
-
);
|
|
722
|
+
return ts3.factory.updatePropertySignature(path4, path4.modifiers, newIdentifier, path4.questionToken, newType);
|
|
786
723
|
}
|
|
787
724
|
__name(normalizePath, "normalizePath");
|
|
788
725
|
function wrapPathsType(type, context) {
|
|
@@ -954,15 +891,6 @@ function processPendingRequestComponentActions(component, context) {
|
|
|
954
891
|
return { bodyQuestionToken };
|
|
955
892
|
}
|
|
956
893
|
__name(processPendingRequestComponentActions, "processPendingRequestComponentActions");
|
|
957
|
-
function wrapRequestComponentType(type, context) {
|
|
958
|
-
context.typeImports.http.add("HttpSchema");
|
|
959
|
-
const httpSchemaRequestWrapper = ts3.factory.createQualifiedName(
|
|
960
|
-
ts3.factory.createIdentifier("HttpSchema"),
|
|
961
|
-
ts3.factory.createIdentifier("Request")
|
|
962
|
-
);
|
|
963
|
-
return ts3.factory.createTypeReferenceNode(httpSchemaRequestWrapper, [type]);
|
|
964
|
-
}
|
|
965
|
-
__name(wrapRequestComponentType, "wrapRequestComponentType");
|
|
966
894
|
function normalizeRequestComponent(component, context) {
|
|
967
895
|
if (!isRequestComponent(component)) {
|
|
968
896
|
return void 0;
|
|
@@ -974,7 +902,7 @@ function normalizeRequestComponent(component, context) {
|
|
|
974
902
|
component.modifiers,
|
|
975
903
|
component.name,
|
|
976
904
|
component.questionToken,
|
|
977
|
-
|
|
905
|
+
newType
|
|
978
906
|
);
|
|
979
907
|
}
|
|
980
908
|
__name(normalizeRequestComponent, "normalizeRequestComponent");
|
|
@@ -1401,5 +1329,5 @@ var generate_default = generateTypesFromOpenAPI;
|
|
|
1401
1329
|
* The root import module is defined at build time. The fallback is not expected to be used. */
|
|
1402
1330
|
|
|
1403
1331
|
export { __name, generate_default, logger };
|
|
1404
|
-
//# sourceMappingURL=chunk-
|
|
1405
|
-
//# sourceMappingURL=chunk-
|
|
1332
|
+
//# sourceMappingURL=chunk-KVTV4E5K.mjs.map
|
|
1333
|
+
//# sourceMappingURL=chunk-KVTV4E5K.mjs.map
|