@kubb/plugin-react-query 5.7.0-canary.20261025T193222 → 5.8.0-canary.20261025T212117

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
@@ -193,6 +193,22 @@ function getOperationParameters(node) {
193
193
  operationParameterGroupsByNode.set(node, groups);
194
194
  return groups;
195
195
  }
196
+ /**
197
+ * Builds the combined `{ body, path, query, headers }` options object schema for an operation,
198
+ * referencing the already-resolved body and grouped param names. Shared by `@kubb/plugin-ts`'s
199
+ * `Options` type and `@kubb/plugin-zod`'s inferred options schema, so both printers emit the same
200
+ * shape from the same inputs. `primitive: 'object'` is a no-op for the TS printer and tells the Zod
201
+ * printer to emit `z.object(…)` rather than a record.
202
+ */
203
+ function hasRequestContentTypeChoice(node) {
204
+ return (node.requestBody?.content ?? []).filter((entry) => entry.schema).length > 1;
205
+ }
206
+ /**
207
+ * Casts a call argument to the client's parameter type; a `'plain'` client is non-generic.
208
+ */
209
+ function castToClientOptions(callArg, clientName, returnType = "full") {
210
+ return `${callArg} as Parameters<typeof ${clientName}${returnType === "plain" ? "" : "<true>"}>[0]`;
211
+ }
196
212
  function getStatusCodeNumber(statusCode) {
197
213
  const code = Number(statusCode);
198
214
  return Number.isNaN(code) ? null : code;
@@ -359,7 +375,7 @@ var compatibility = {
359
375
  };
360
376
  //#endregion
361
377
  //#region package.json
362
- var version = "5.7.0-canary.20261025T193222";
378
+ var version = "5.8.0-canary.20261025T212117";
363
379
  //#endregion
364
380
  //#region ../../internals/client/src/resolveOperationTypes.ts
365
381
  /**
@@ -715,7 +731,7 @@ function maybeValueOrGetter(type) {
715
731
  * `MaybeRefOrGetter` per group.
716
732
  */
717
733
  function buildGroupedRequestParam(node, options) {
718
- const { resolver, keys = requestGroupOrder, memberTypeWrapper } = options;
734
+ const { resolver, keys = requestGroupOrder, memberTypeWrapper, withContentType = false } = options;
719
735
  const { groups, hasRequiredPath, hasRequiredQuery, hasRequiredHeader } = getRequestGroupOptionality(node);
720
736
  const names = keys.filter((key) => groups[key]);
721
737
  if (names.length === 0) return null;
@@ -727,6 +743,11 @@ function buildGroupedRequestParam(node, options) {
727
743
  };
728
744
  const isOptional = names.every((name) => !requiredByGroup[name]);
729
745
  const optionsName = resolver.response.options(node);
746
+ if (withContentType && hasRequestContentTypeChoice(node)) return (0, _kubb_plugin_ts.createFunctionParameter)({
747
+ name: "variables",
748
+ type: optionsName,
749
+ optional: false
750
+ });
730
751
  const omittedKeys = requestGroupOrder.filter((key) => !keys.includes(key));
731
752
  const optionsType = omittedKeys.length > 0 ? `Omit<${optionsName}, ${omittedKeys.map((key) => `'${key}'`).join(" | ")}>` : optionsName;
732
753
  if (memberTypeWrapper) {
@@ -784,14 +805,17 @@ function buildQueryOptionsParams(node, options) {
784
805
  * ```
785
806
  */
786
807
  function buildClientCall(node, options) {
787
- const { clientName, signal = false, unwrapName } = options;
808
+ const { clientName, signal = false, unwrapName, withContentType = false, returnType = "full" } = options;
788
809
  const { groups } = getRequestGroupOptionality(node);
789
- return `${clientName}({ ${[
810
+ const names = requestGroupOrder.filter((key) => groups[key]);
811
+ const args = [
790
812
  "...config",
791
- ...requestGroupOrder.filter((key) => groups[key]).map((name) => unwrapName ? `${name}: ${unwrapName(name)}` : name),
813
+ ...withContentType && hasRequestContentTypeChoice(node) ? ["...variables"] : names.map((name) => unwrapName ? `${name}: ${unwrapName(name)}` : name),
792
814
  signal ? "signal: config.signal ?? signal" : null,
793
815
  "throwOnError: true"
794
- ].filter((part) => part !== null).join(", ")} })`;
816
+ ].filter((part) => part !== null);
817
+ if (withContentType && hasRequestContentTypeChoice(node)) return `${clientName}(${castToClientOptions(`{ ${args.join(", ")} }`, clientName, returnType)})`;
818
+ return `${clientName}({ ${args.join(", ")} })`;
795
819
  }
796
820
  /**
797
821
  * Builds the query/mutation body that resolves a `buildClientCall` expression down to the bare
@@ -1870,14 +1894,19 @@ function MutationOptions({ name, clientName, node, tsResolver, mutationKeyName,
1870
1894
  const { TData, TError } = buildResponseTypes(node, tsResolver);
1871
1895
  const configParamsNode = buildMutationConfigParamsNode(node);
1872
1896
  const paramsSignature = declarationPrinter$1.print(configParamsNode) ?? "";
1873
- const groupedParam = buildGroupedRequestParam(node, { resolver: tsResolver });
1897
+ const groupedParam = buildGroupedRequestParam(node, {
1898
+ resolver: tsResolver,
1899
+ withContentType: true
1900
+ });
1874
1901
  const hasMutationParams = groupedParam !== null;
1875
1902
  const groupedParamsNode = (0, _kubb_plugin_ts.createFunctionParameters)({ params: groupedParam ? [groupedParam] : [] });
1876
1903
  const TRequest = hasMutationParams ? tsResolver.response.options(node) : "undefined";
1877
1904
  const argBindingStr = hasMutationParams ? callPrinter$1.print(groupedParamsNode) ?? "" : "_";
1878
1905
  const mutationFnBody = buildCallResultBody(buildClientCall(node, {
1879
1906
  clientName,
1880
- signal: false
1907
+ signal: false,
1908
+ withContentType: true,
1909
+ returnType
1881
1910
  }), { returnType });
1882
1911
  return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
1883
1912
  name,