@kubb/plugin-axios 5.10.0-canary.20261025T193221 → 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,16 +766,14 @@ 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
- * Renders a parameter name as an object-literal key, quoted when it is not a bare identifier.
751
- * Path keys are camelCased to match the URL template placeholders. Query, header, and cookie keys
752
- * keep the spec name, matching the remapped keys the runtime serializes.
771
+ * Renders a parameter name as an object-literal key, quoted when it is not a bare identifier. Every
772
+ * location keeps the spec name: the runtime looks path styles up by the `{name}` placeholder in the
773
+ * URL, and the other locations by the key it serializes.
753
774
  */
754
- function toKey(name, location) {
755
- const key = location === "path" ? camelCase(name) : name;
756
- return isValidVarName(key) ? key : JSON.stringify(key);
775
+ function toKey(name) {
776
+ return isValidVarName(name) ? name : JSON.stringify(name);
757
777
  }
758
778
  /**
759
779
  * Serializes one parameter's metadata into a `{ style, explode, allowReserved, contentType }`
@@ -790,8 +810,7 @@ function serializeBodyEncoding(node) {
790
810
  }
791
811
  /**
792
812
  * Builds the per-operation `styles` literal from the operation's parameters, grouped by location.
793
- * Path entries are keyed by the camelCased name to match the URL template placeholders; query,
794
- * header, and cookie entries keep the spec name to match the keys the runtime serializes.
813
+ * Entries are keyed by the spec name of the parameter.
795
814
  * Only parameters whose source defines `style`, `explode`, `allowReserved`, or `contentType` are
796
815
  * emitted, so calls without serialization metadata keep the runtime defaults and existing output
797
816
  * is unchanged. A form request body adds a `body` group keyed by property name from its `encoding`.
@@ -814,13 +833,12 @@ function buildStyles({ node }) {
814
833
  for (const parameter of node.parameters) {
815
834
  const literal = serializeParameter(parameter);
816
835
  if (!literal) continue;
817
- groups[parameter.in].push(`${toKey(parameter.name, parameter.in)}: ${literal}`);
836
+ groups[parameter.in].push(`${toKey(parameter.name)}: ${literal}`);
818
837
  }
819
838
  const entries = [...Object.keys(groups).filter((location) => groups[location].length > 0).map((location) => `${location}: { ${groups[location].join(", ")} }`), serializeBodyEncoding(node)].filter(Boolean);
820
839
  return entries.length > 0 ? `{ ${entries.join(", ")} }` : null;
821
840
  }
822
- //#endregion
823
- //#region ../../internals/client/src/components/Operation.tsx
841
+ // ../../internals/client/src/components/Operation.tsx
824
842
  /**
825
843
  * Renders one client operation: the grouped `<Name>Request` type and the function that forwards a
826
844
  * single `options` object to the resolved client and returns the `Unwrappable<RequestResult>`. The
@@ -897,8 +915,7 @@ function Operation({ name, node, types, zodResolver, validator, returnType, thro
897
915
  })
898
916
  });
899
917
  }
900
- //#endregion
901
- //#region ../../internals/client/src/resolveOperationTypes.ts
918
+ // ../../internals/client/src/resolveOperationTypes.ts
902
919
  /**
903
920
  * A `plugin-ts` shaped resolver whose operation type names point at the types `pluginZod({ inferred })`
904
921
  * exports next to each schema, so code written against `plugin-ts` names picks up the zod types.
@@ -964,8 +981,7 @@ function resolveOperationTypes(driver, pluginName) {
964
981
  group: pluginZod.options.group ?? void 0
965
982
  };
966
983
  }
967
- //#endregion
968
- //#region ../../internals/client/src/generators/clientGenerator.tsx
984
+ // ../../internals/client/src/generators/clientGenerator.tsx
969
985
  /**
970
986
  * Builds the built-in per-operation generator shared by the client plugins (`@kubb/plugin-fetch`,
971
987
  * `@kubb/plugin-axios`). Emits one async function per OpenAPI operation using the shared
@@ -992,8 +1008,12 @@ function createClientGenerator(name, resolveClientPath) {
992
1008
  zodResolver
993
1009
  });
994
1010
  const importedZodNames = validatorHooks.importedZodNames;
1011
+ const operationName = resolver.name(node.operationId);
995
1012
  const meta = {
996
- name: resolver.name(node.operationId),
1013
+ name: resolver.resolveName({
1014
+ key: operationKey(node),
1015
+ name: operationName
1016
+ }),
997
1017
  file: resolver.file({
998
1018
  ...operationFileEntry(node, node.operationId),
999
1019
  root,
@@ -1108,8 +1128,7 @@ function createClientGenerator(name, resolveClientPath) {
1108
1128
  }
1109
1129
  });
1110
1130
  }
1111
- //#endregion
1112
- //#region ../../internals/client/src/components/SdkClient.tsx
1131
+ // ../../internals/client/src/components/SdkClient.tsx
1113
1132
  /**
1114
1133
  * Builds the call config literal forwarded to the contract client; the `throwOnError` fallback is applied after the `...config` spread.
1115
1134
  */
@@ -1199,8 +1218,7 @@ function SdkClient({ name, operations, returnType, throwOnErrorDefault }) {
1199
1218
  children: classCode
1200
1219
  });
1201
1220
  }
1202
- //#endregion
1203
- //#region ../../internals/client/src/components/SdkFacade.tsx
1221
+ // ../../internals/client/src/components/SdkFacade.tsx
1204
1222
  /**
1205
1223
  * Renders a composed root SDK class that instantiates every tag client from one shared config, so
1206
1224
  * `new PetStore({ baseURL }).petClient.getPetById(...)` reaches an operation through a single entry
@@ -1223,8 +1241,7 @@ function SdkFacade({ name, members }) {
1223
1241
  children: classCode
1224
1242
  });
1225
1243
  }
1226
- //#endregion
1227
- //#region ../../internals/client/src/generators/sdkGenerator.tsx
1244
+ // ../../internals/client/src/generators/sdkGenerator.tsx
1228
1245
  function resolveTypeImportNames(node, types) {
1229
1246
  return [types.response.options(node), types.response.responses(node)];
1230
1247
  }
@@ -1261,9 +1278,13 @@ function buildControllers(nodes, ctx, types) {
1261
1278
  validator,
1262
1279
  zodResolver
1263
1280
  }) : null;
1281
+ const name = resolver.name(node.operationId);
1264
1282
  return {
1265
1283
  node,
1266
- name: resolver.name(node.operationId),
1284
+ name: resolver.resolveName({
1285
+ key: operationKey(node),
1286
+ name
1287
+ }),
1267
1288
  types,
1268
1289
  typeFile,
1269
1290
  zodFile,
@@ -1476,19 +1497,17 @@ function createSdkGenerator() {
1476
1497
  }
1477
1498
  });
1478
1499
  }
1479
- //#endregion
1480
- //#region ../../internals/client/src/macros.ts
1500
+ // ../../internals/client/src/macros.ts
1481
1501
  /**
1482
1502
  * Macros the client plugins apply by default, ahead of any user macros. `macroSimplifyUnion`
1483
1503
  * drops union members a broader scalar already covers, keeping the generated response and error
1484
1504
  * unions tidy. A plugin wires them with `ctx.setMacros([...defaultMacros, ...userMacros])`.
1485
1505
  */
1486
1506
  const defaultMacros = [kubb_kit.macroSimplifyUnion];
1487
- //#endregion
1488
- //#region ../../internals/client/src/resolver.ts
1507
+ // ../../internals/client/src/resolver.ts
1489
1508
  /**
1490
- * Default resolver shared by the client plugins. Functions and files inherit the built-in camelCase
1491
- * `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.
1492
1511
  *
1493
1512
  * @example
1494
1513
  * ```ts
@@ -1498,6 +1517,7 @@ const defaultMacros = [kubb_kit.macroSimplifyUnion];
1498
1517
  */
1499
1518
  const resolverClient = (0, kubb_kit.createResolver)({
1500
1519
  pluginName: "plugin-contract-client",
1520
+ name: resolveOperationName,
1501
1521
  className(name) {
1502
1522
  return ensureValidVarName(pascalCase(name));
1503
1523
  },
@@ -1508,25 +1528,21 @@ const resolverClient = (0, kubb_kit.createResolver)({
1508
1528
  return ensureValidVarName(camelCase(name));
1509
1529
  }
1510
1530
  });
1511
- //#endregion
1512
- //#region src/generators/clientGenerator.tsx
1531
+ // src/generators/clientGenerator.tsx
1513
1532
  /**
1514
1533
  * Built-in operation generator for `@kubb/plugin-axios`. Emits one async function per OpenAPI
1515
1534
  * operation using the shared `Operation` component: a grouped `<Name>Request` type and a function
1516
1535
  * that forwards a single `options` object to the bundled `client` and returns the `RequestResult`.
1517
1536
  */
1518
1537
  const clientGenerator = createClientGenerator("axios");
1519
- //#endregion
1520
- //#region kubb-extension.json
1538
+ // kubb-extension.json
1521
1539
  var compatibility = {
1522
- "kubb": ">=5.8.3",
1540
+ "kubb": ">=5.14.6",
1523
1541
  "node": ">=22.22"
1524
1542
  };
1525
- //#endregion
1526
- //#region package.json
1527
- var version = "5.10.0-canary.20261025T193221";
1528
- //#endregion
1529
- //#region src/templates.ts
1543
+ // package.json
1544
+ var version = "5.10.0";
1545
+ // src/templates.ts
1530
1546
  /** Absolute path to the axios client template, copied into `.kubb/client.ts`. */
1531
1547
  const axiosClientTemplatePath = (0, node_url.fileURLToPath)(new URL("../templates/axios.ts", require("url").pathToFileURL(__filename).href));
1532
1548
  /** Absolute path to the axios serializers template, copied into `.kubb/serializers.ts`. */
@@ -1536,8 +1552,7 @@ const axiosSerializersTemplatePath = (0, node_url.fileURLToPath)(new URL("../tem
1536
1552
  * emit the helper into the generated `.kubb/standardSchema.ts` verbatim.
1537
1553
  */
1538
1554
  const standardSchemaTemplatePath = (0, node_url.fileURLToPath)(new URL("../templates/standardSchema.ts", require("url").pathToFileURL(__filename).href));
1539
- //#endregion
1540
- //#region src/plugin.ts
1555
+ // src/plugin.ts
1541
1556
  /**
1542
1557
  * Canonical plugin name for `@kubb/plugin-axios`. Used for driver lookups and cross-plugin
1543
1558
  * dependency references.
@@ -1622,7 +1637,6 @@ const pluginAxios = (0, kubb_kit.defineExtension)({
1622
1637
  return resolved;
1623
1638
  }
1624
1639
  });
1625
- //#endregion
1626
1640
  exports.clientGenerator = clientGenerator;
1627
1641
  exports.default = pluginAxios;
1628
1642
  exports.pluginAxios = pluginAxios;