@kubb/plugin-axios 5.10.0-canary.20261025T201031 → 5.10.0

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/index.cjs CHANGED
@@ -2,7 +2,7 @@ Object.defineProperties(exports, {
2
2
  __esModule: { value: true },
3
3
  [Symbol.toStringTag]: { value: "Module" }
4
4
  });
5
- //#region \0rolldown/runtime.js
5
+ // \0rolldown/runtime.js
6
6
  var __create = Object.create;
7
7
  var __defProp = Object.defineProperty;
8
8
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -23,7 +23,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
23
23
  value: mod,
24
24
  enumerable: true
25
25
  }) : target, mod));
26
- //#endregion
27
26
  let kubb_kit = require("kubb/kit");
28
27
  let node_path = require("node:path");
29
28
  node_path = __toESM(node_path, 1);
@@ -32,7 +31,7 @@ let kubb_jsx = require("kubb/jsx");
32
31
  let _kubb_plugin_ts = require("@kubb/plugin-ts");
33
32
  let kubb_jsx_jsx_runtime = require("kubb/jsx/jsx-runtime");
34
33
  let node_url = require("node:url");
35
- //#region ../../internals/shared/src/operation.ts
34
+ // ../../internals/shared/src/operation.ts
36
35
  /**
37
36
  * Builds the `ResolverFileParams` every operation generator passes to
38
37
  * `resolver.file`: a file named `name`, tagged by the operation's first
@@ -210,6 +209,16 @@ function getOperationParameters(node) {
210
209
  operationParameterGroupsByNode.set(node, groups);
211
210
  return groups;
212
211
  }
212
+ /**
213
+ * Builds the combined `{ body, path, query, headers }` options object schema for an operation,
214
+ * referencing the already-resolved body and grouped param names. Shared by `@kubb/plugin-ts`'s
215
+ * `Options` type and `@kubb/plugin-zod`'s inferred options schema, so both printers emit the same
216
+ * shape from the same inputs. `primitive: 'object'` is a no-op for the TS printer and tells the Zod
217
+ * printer to emit `z.object(…)` rather than a record.
218
+ */
219
+ function hasRequestContentTypeChoice(node) {
220
+ return (node.requestBody?.content ?? []).filter((entry) => entry.schema).length > 1;
221
+ }
213
222
  function getStatusCodeNumber(statusCode) {
214
223
  const code = Number(statusCode);
215
224
  return Number.isNaN(code) ? null : code;
@@ -227,8 +236,7 @@ function getOperationSuccessResponses(node) {
227
236
  function getPrimarySuccessResponse(node) {
228
237
  return getOperationSuccessResponses(node)[0] ?? null;
229
238
  }
230
- //#endregion
231
- //#region ../../internals/utils/src/casing.ts
239
+ // ../../internals/utils/src/casing.ts
232
240
  /**
233
241
  * Shared implementation for camelCase and PascalCase conversion.
234
242
  * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)
@@ -277,8 +285,7 @@ function camelCase(text, { prefix = "", suffix = "" } = {}) {
277
285
  function pascalCase(text, { prefix = "", suffix = "" } = {}) {
278
286
  return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true);
279
287
  }
280
- //#endregion
281
- //#region ../../internals/utils/src/reserved.ts
288
+ // ../../internals/utils/src/reserved.ts
282
289
  /**
283
290
  * JavaScript and Java reserved words.
284
291
  * @link https://github.com/jonschlinkert/reserved/blob/master/index.js
@@ -286,6 +293,7 @@ function pascalCase(text, { prefix = "", suffix = "" } = {}) {
286
293
  const reservedWords = /* @__PURE__ */ new Set([
287
294
  "abstract",
288
295
  "arguments",
296
+ "await",
289
297
  "boolean",
290
298
  "break",
291
299
  "byte",
@@ -416,8 +424,7 @@ function ensureValidVarName(name) {
416
424
  function isIdentifier(name) {
417
425
  return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);
418
426
  }
419
- //#endregion
420
- //#region ../../internals/utils/src/codegen.ts
427
+ // ../../internals/utils/src/codegen.ts
421
428
  /**
422
429
  * Builds a JSDoc comment block from an array of lines. Returns `fallback` when there are no
423
430
  * comments.
@@ -433,8 +440,29 @@ function buildJSDoc(comments, options = {}) {
433
440
  if (comments.length === 0) return fallback;
434
441
  return `/**\n${comments.map((c) => `${indent}${c}`).join("\n")}\n */${suffix}`;
435
442
  }
436
- //#endregion
437
- //#region ../../internals/shared/src/group.ts
443
+ // ../../internals/shared/src/resolver.ts
444
+ function resolveOperationName(name) {
445
+ return ensureValidVarName(camelCase(name));
446
+ }
447
+ /**
448
+ * Builds the allocation key for a declaration an operation owns. `scope` names which declaration
449
+ * it is, so two of them never share an allocation even when a custom resolver gives both the same
450
+ * name. Leave `scope` empty for the operation's own declaration.
451
+ *
452
+ * @example
453
+ * ```ts
454
+ * resolver.resolveName({ key: operationKey(node, 'response', 'status', 404), name })
455
+ * ```
456
+ */
457
+ function operationKey(node, ...scope) {
458
+ return [
459
+ "operation",
460
+ node.method,
461
+ node.path,
462
+ ...scope.map(String)
463
+ ];
464
+ }
465
+ // ../../internals/shared/src/group.ts
438
466
  /**
439
467
  * Builds the `group` config a Kubb plugin passes to `ctx.setOptions`, applying the
440
468
  * shared default naming so every plugin groups output consistently:
@@ -464,8 +492,7 @@ function createGroupConfig(group) {
464
492
  name: group.name ? group.name : defaultName
465
493
  };
466
494
  }
467
- //#endregion
468
- //#region ../../internals/client/src/builders/validatorOptions.ts
495
+ // ../../internals/client/src/builders/validatorOptions.ts
469
496
  /**
470
497
  * Returns `true` when any direction of the validator uses zod (used for dependency checks).
471
498
  */
@@ -508,8 +535,7 @@ function buildZodErrorParse(node, zodResolver) {
508
535
  if (!node.responses.some((res) => !isSuccessStatusCode(res.statusCode) && res.content?.some((entry) => entry.schema))) return null;
509
536
  return zodResolver.response.error?.(node) || null;
510
537
  }
511
- //#endregion
512
- //#region ../../internals/client/src/builders/security.ts
538
+ // ../../internals/client/src/builders/security.ts
513
539
  function serializeAuth(auth) {
514
540
  const parts = [`type: '${auth.type}'`];
515
541
  if (auth.scheme) parts.push(`scheme: '${auth.scheme}'`);
@@ -580,8 +606,7 @@ function buildSecurityMetadata({ security }) {
580
606
  if (!security?.length) return null;
581
607
  return `[${security.map(serializeAuth).join(", ")}]`;
582
608
  }
583
- //#endregion
584
- //#region ../../internals/client/src/builders/validator.ts
609
+ // ../../internals/client/src/builders/validator.ts
585
610
  /**
586
611
  * Builds the validator-hook references for one operation. Request body and params validation run before the send.
587
612
  * Response validation runs on the success body only. Returns `null` references when the matching
@@ -623,17 +648,16 @@ function buildValidatorLiteral(hooks, keys) {
623
648
  const entries = keys.flatMap((key) => hooks?.[key] ? [`${key}: ${hooks[key]}`] : []);
624
649
  return entries.length ? `validator: { ${entries.join(", ")} }` : null;
625
650
  }
626
- //#endregion
627
- //#region ../../internals/client/src/builders/contentType.ts
651
+ // ../../internals/client/src/builders/contentType.ts
628
652
  /**
629
- * Builds the `contentType` entry baked into the call config, or `null` for the JSON default.
653
+ * Builds the `contentType` entry baked into the call config, or `null` without a request body.
630
654
  *
631
655
  * `merge` is `true` when the generated function must destructure `contentType` from `options` and
632
656
  * merge it over the baked request default, because the caller can also pick a response content type.
633
657
  */
634
658
  function buildContentType({ node }) {
635
659
  const { defaultContentType } = getContentTypeInfo(node);
636
- const requestContentType = Boolean(node.requestBody?.content?.[0]?.schema) && defaultContentType !== "application/json" ? defaultContentType : null;
660
+ const requestContentType = Boolean(node.requestBody?.content?.[0]?.schema) ? defaultContentType : null;
637
661
  if (!requestContentType) return {
638
662
  literal: null,
639
663
  merge: false
@@ -644,8 +668,7 @@ function buildContentType({ node }) {
644
668
  literal: merge ? `contentType: { request: '${requestContentType}', ...(typeof contentType === 'string' ? { request: contentType } : contentType) }` : `contentType: { request: '${requestContentType}' }`
645
669
  };
646
670
  }
647
- //#endregion
648
- //#region ../../internals/client/src/builders/generics.ts
671
+ // ../../internals/client/src/builders/generics.ts
649
672
  /**
650
673
  * Builds the `RequestResult` generic arguments for one operation: the per-status responses record
651
674
  * plus the per-call `ThrowOnError` flag. `SuccessOf` / `ErrorOf` split the record inside the
@@ -676,8 +699,7 @@ function buildResultType({ node, types, returnType }) {
676
699
  if (returnType === "plain") return `Promise<RequestResult<${generics}>>`;
677
700
  return `Unwrappable<RequestResult<${generics}>>`;
678
701
  }
679
- //#endregion
680
- //#region ../../internals/client/src/builders/returnStatement.ts
702
+ // ../../internals/client/src/builders/returnStatement.ts
681
703
  /**
682
704
  * Builds the return statement of a generated operation function. With the default
683
705
  * `returnType: 'full'` the runtime call already resolves to `{ data, error, request, response }`.
@@ -701,22 +723,22 @@ function buildResultType({ node, types, returnType }) {
701
723
  * `return request({ method: 'POST', url: '/pet', ...config }) as Promise<RequestResult<AddPetResponses, ThrowOnError>>`
702
724
  */
703
725
  function buildReturnStatement({ node, types, callConfig, returnType, throwOnErrorDefault }) {
704
- if (returnType === "data") return `return unwrapResult(request(${callConfig}), config.throwOnError ?? ${throwOnErrorDefault}) as ${buildResultType({
726
+ const request = returnType !== "plain" && hasRequestContentTypeChoice(node) ? `request<${types.response.options(node)}['body']>` : "request";
727
+ if (returnType === "data") return `return unwrapResult(${request}(${callConfig}), config.throwOnError ?? ${throwOnErrorDefault}) as ${buildResultType({
705
728
  node,
706
729
  types,
707
730
  returnType
708
731
  })}`;
709
- if (returnType === "plain") return `return request(${callConfig}) as Promise<RequestResult<${buildRequestResultGenerics({
732
+ if (returnType === "plain") return `return ${request}(${callConfig}) as Promise<RequestResult<${buildRequestResultGenerics({
710
733
  node,
711
734
  types
712
735
  })}>>`;
713
- return `return withUnwrap(request(${callConfig}) as Promise<RequestResult<${buildRequestResultGenerics({
736
+ return `return withUnwrap(${request}(${callConfig}) as Promise<RequestResult<${buildRequestResultGenerics({
714
737
  node,
715
738
  types
716
739
  })}>>)`;
717
740
  }
718
- //#endregion
719
- //#region ../../internals/client/src/builders/signature.ts
741
+ // ../../internals/client/src/builders/signature.ts
720
742
  const declarationPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
721
743
  /**
722
744
  * Builds the grouped-options signature for one operation: a single `options` object whose `TData`
@@ -744,8 +766,7 @@ function buildGroupedOptionsSignature({ node, types, returnType, throwOnErrorDef
744
766
  generics: [`ThrowOnError extends boolean = ${throwOnErrorDefault}`]
745
767
  };
746
768
  }
747
- //#endregion
748
- //#region ../../internals/client/src/builders/styles.ts
769
+ // ../../internals/client/src/builders/styles.ts
749
770
  /**
750
771
  * Renders a parameter name as an object-literal key, quoted when it is not a bare identifier. Every
751
772
  * location keeps the spec name: the runtime looks path styles up by the `{name}` placeholder in the
@@ -817,8 +838,7 @@ function buildStyles({ node }) {
817
838
  const entries = [...Object.keys(groups).filter((location) => groups[location].length > 0).map((location) => `${location}: { ${groups[location].join(", ")} }`), serializeBodyEncoding(node)].filter(Boolean);
818
839
  return entries.length > 0 ? `{ ${entries.join(", ")} }` : null;
819
840
  }
820
- //#endregion
821
- //#region ../../internals/client/src/components/Operation.tsx
841
+ // ../../internals/client/src/components/Operation.tsx
822
842
  /**
823
843
  * Renders one client operation: the grouped `<Name>Request` type and the function that forwards a
824
844
  * single `options` object to the resolved client and returns the `Unwrappable<RequestResult>`. The
@@ -895,8 +915,7 @@ function Operation({ name, node, types, zodResolver, validator, returnType, thro
895
915
  })
896
916
  });
897
917
  }
898
- //#endregion
899
- //#region ../../internals/client/src/resolveOperationTypes.ts
918
+ // ../../internals/client/src/resolveOperationTypes.ts
900
919
  /**
901
920
  * A `plugin-ts` shaped resolver whose operation type names point at the types `pluginZod({ inferred })`
902
921
  * exports next to each schema, so code written against `plugin-ts` names picks up the zod types.
@@ -962,8 +981,7 @@ function resolveOperationTypes(driver, pluginName) {
962
981
  group: pluginZod.options.group ?? void 0
963
982
  };
964
983
  }
965
- //#endregion
966
- //#region ../../internals/client/src/generators/clientGenerator.tsx
984
+ // ../../internals/client/src/generators/clientGenerator.tsx
967
985
  /**
968
986
  * Builds the built-in per-operation generator shared by the client plugins (`@kubb/plugin-fetch`,
969
987
  * `@kubb/plugin-axios`). Emits one async function per OpenAPI operation using the shared
@@ -990,8 +1008,12 @@ function createClientGenerator(name, resolveClientPath) {
990
1008
  zodResolver
991
1009
  });
992
1010
  const importedZodNames = validatorHooks.importedZodNames;
1011
+ const operationName = resolver.name(node.operationId);
993
1012
  const meta = {
994
- name: resolver.name(node.operationId),
1013
+ name: resolver.resolveName({
1014
+ key: operationKey(node),
1015
+ name: operationName
1016
+ }),
995
1017
  file: resolver.file({
996
1018
  ...operationFileEntry(node, node.operationId),
997
1019
  root,
@@ -1106,8 +1128,7 @@ function createClientGenerator(name, resolveClientPath) {
1106
1128
  }
1107
1129
  });
1108
1130
  }
1109
- //#endregion
1110
- //#region ../../internals/client/src/components/SdkClient.tsx
1131
+ // ../../internals/client/src/components/SdkClient.tsx
1111
1132
  /**
1112
1133
  * Builds the call config literal forwarded to the contract client; the `throwOnError` fallback is applied after the `...config` spread.
1113
1134
  */
@@ -1197,8 +1218,7 @@ function SdkClient({ name, operations, returnType, throwOnErrorDefault }) {
1197
1218
  children: classCode
1198
1219
  });
1199
1220
  }
1200
- //#endregion
1201
- //#region ../../internals/client/src/components/SdkFacade.tsx
1221
+ // ../../internals/client/src/components/SdkFacade.tsx
1202
1222
  /**
1203
1223
  * Renders a composed root SDK class that instantiates every tag client from one shared config, so
1204
1224
  * `new PetStore({ baseURL }).petClient.getPetById(...)` reaches an operation through a single entry
@@ -1221,8 +1241,7 @@ function SdkFacade({ name, members }) {
1221
1241
  children: classCode
1222
1242
  });
1223
1243
  }
1224
- //#endregion
1225
- //#region ../../internals/client/src/generators/sdkGenerator.tsx
1244
+ // ../../internals/client/src/generators/sdkGenerator.tsx
1226
1245
  function resolveTypeImportNames(node, types) {
1227
1246
  return [types.response.options(node), types.response.responses(node)];
1228
1247
  }
@@ -1259,9 +1278,13 @@ function buildControllers(nodes, ctx, types) {
1259
1278
  validator,
1260
1279
  zodResolver
1261
1280
  }) : null;
1281
+ const name = resolver.name(node.operationId);
1262
1282
  return {
1263
1283
  node,
1264
- name: resolver.name(node.operationId),
1284
+ name: resolver.resolveName({
1285
+ key: operationKey(node),
1286
+ name
1287
+ }),
1265
1288
  types,
1266
1289
  typeFile,
1267
1290
  zodFile,
@@ -1474,19 +1497,17 @@ function createSdkGenerator() {
1474
1497
  }
1475
1498
  });
1476
1499
  }
1477
- //#endregion
1478
- //#region ../../internals/client/src/macros.ts
1500
+ // ../../internals/client/src/macros.ts
1479
1501
  /**
1480
1502
  * Macros the client plugins apply by default, ahead of any user macros. `macroSimplifyUnion`
1481
1503
  * drops union members a broader scalar already covers, keeping the generated response and error
1482
1504
  * unions tidy. A plugin wires them with `ctx.setMacros([...defaultMacros, ...userMacros])`.
1483
1505
  */
1484
1506
  const defaultMacros = [kubb_kit.macroSimplifyUnion];
1485
- //#endregion
1486
- //#region ../../internals/client/src/resolver.ts
1507
+ // ../../internals/client/src/resolver.ts
1487
1508
  /**
1488
- * Default resolver shared by the client plugins. Functions and files inherit the built-in camelCase
1489
- * `name` and `file`; classes and tag groups use PascalCase.
1509
+ * Default resolver shared by the client plugins. Functions use safe camelCase identifiers and
1510
+ * files inherit the built-in casing; classes and tag groups use PascalCase.
1490
1511
  *
1491
1512
  * @example
1492
1513
  * ```ts
@@ -1496,6 +1517,7 @@ const defaultMacros = [kubb_kit.macroSimplifyUnion];
1496
1517
  */
1497
1518
  const resolverClient = (0, kubb_kit.createResolver)({
1498
1519
  pluginName: "plugin-contract-client",
1520
+ name: resolveOperationName,
1499
1521
  className(name) {
1500
1522
  return ensureValidVarName(pascalCase(name));
1501
1523
  },
@@ -1506,25 +1528,21 @@ const resolverClient = (0, kubb_kit.createResolver)({
1506
1528
  return ensureValidVarName(camelCase(name));
1507
1529
  }
1508
1530
  });
1509
- //#endregion
1510
- //#region src/generators/clientGenerator.tsx
1531
+ // src/generators/clientGenerator.tsx
1511
1532
  /**
1512
1533
  * Built-in operation generator for `@kubb/plugin-axios`. Emits one async function per OpenAPI
1513
1534
  * operation using the shared `Operation` component: a grouped `<Name>Request` type and a function
1514
1535
  * that forwards a single `options` object to the bundled `client` and returns the `RequestResult`.
1515
1536
  */
1516
1537
  const clientGenerator = createClientGenerator("axios");
1517
- //#endregion
1518
- //#region kubb-extension.json
1538
+ // kubb-extension.json
1519
1539
  var compatibility = {
1520
- "kubb": ">=5.8.3",
1540
+ "kubb": ">=5.14.6",
1521
1541
  "node": ">=22.22"
1522
1542
  };
1523
- //#endregion
1524
- //#region package.json
1525
- var version = "5.10.0-canary.20261025T201031";
1526
- //#endregion
1527
- //#region src/templates.ts
1543
+ // package.json
1544
+ var version = "5.10.0";
1545
+ // src/templates.ts
1528
1546
  /** Absolute path to the axios client template, copied into `.kubb/client.ts`. */
1529
1547
  const axiosClientTemplatePath = (0, node_url.fileURLToPath)(new URL("../templates/axios.ts", require("url").pathToFileURL(__filename).href));
1530
1548
  /** Absolute path to the axios serializers template, copied into `.kubb/serializers.ts`. */
@@ -1534,8 +1552,7 @@ const axiosSerializersTemplatePath = (0, node_url.fileURLToPath)(new URL("../tem
1534
1552
  * emit the helper into the generated `.kubb/standardSchema.ts` verbatim.
1535
1553
  */
1536
1554
  const standardSchemaTemplatePath = (0, node_url.fileURLToPath)(new URL("../templates/standardSchema.ts", require("url").pathToFileURL(__filename).href));
1537
- //#endregion
1538
- //#region src/plugin.ts
1555
+ // src/plugin.ts
1539
1556
  /**
1540
1557
  * Canonical plugin name for `@kubb/plugin-axios`. Used for driver lookups and cross-plugin
1541
1558
  * dependency references.
@@ -1620,7 +1637,6 @@ const pluginAxios = (0, kubb_kit.defineExtension)({
1620
1637
  return resolved;
1621
1638
  }
1622
1639
  });
1623
- //#endregion
1624
1640
  exports.clientGenerator = clientGenerator;
1625
1641
  exports.default = pluginAxios;
1626
1642
  exports.pluginAxios = pluginAxios;