@kubb/plugin-react-query 5.10.0-canary.20261109T201601 → 5.11.0-canary.20261109T211319

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
@@ -72,10 +72,11 @@ function resolveDependencyOperationFile(options) {
72
72
  group: group ?? void 0
73
73
  }));
74
74
  }
75
- function getOperationLink(node, link) {
76
- if (!link) return null;
77
- if (typeof link === "function") return link(node) ?? null;
78
- return node.path ? `{@link ${_kubb_kit.Url.toPath(node.path)}}` : null;
75
+ /**
76
+ * The operation's method and path as plain text, such as `` `GET /pet/{petId}` ``. A path is not a valid `{@link}` target.
77
+ */
78
+ function getOperationRequestLine(node) {
79
+ return _kubb_kit.ast.isHttpOperationNode(node) && node.path ? `\`${node.method.toUpperCase()} ${node.path}\`` : null;
79
80
  }
80
81
  /**
81
82
  * Derives the shared `ContentTypeInfo` shape from a list of content types, tracking whether several
@@ -137,19 +138,31 @@ function isEventStream(node) {
137
138
  }
138
139
  /**
139
140
  * Builds the `client?:` option type shared by the generated query hooks (`useQuery`,
140
- * `useInfiniteQuery`, `useSWR`, ...). Unlike {@link buildRequestConfigType}, it never adds a
141
- * `contentType?:` member: query hooks wrap GET operations, which carry no request body to select a
142
- * content type for. It drops the data-shape keys to stay assignable to `Options`, which omits them
143
- * from `RequestConfig`. `cookies` is a group only on an operation that declares one.
141
+ * `useInfiniteQuery`, `useSWR`, ...): `RequestConfig` minus what the
142
+ * hook fills in, which is every request group and `throwOnError`. Unlike {@link buildRequestConfigType},
143
+ * it never narrows `contentType`: query hooks wrap GET operations, which carry no request body to select
144
+ * a content type for.
144
145
  */
145
- function buildClientOptionType(node) {
146
- return `Partial<Omit<RequestConfig, 'path' | 'query' | 'body' | 'headers'${getOperationParameters(node).cookie.length > 0 ? ` | 'cookies'` : ""} | 'url'>>`;
146
+ function buildClientOptionType(options = {}) {
147
+ return `Partial<Omit<RequestConfig, ${[
148
+ ...requestGroupOrder,
149
+ "url",
150
+ ...options.omit ?? [],
151
+ "throwOnError"
152
+ ].map((key) => `'${key}'`).join(" | ")}>>`;
147
153
  }
154
+ /**
155
+ * The `client?:` option type of a mutation hook. When the operation has a request content type choice,
156
+ * the mutation variables carry `contentType`, so the config leaves it out. Otherwise the ambiguous side is
157
+ * narrowed to the operation's media types; a single-type side has nothing to pick, so it stays baked in the
158
+ * generated call.
159
+ */
148
160
  function buildRequestConfigType(node) {
161
+ if (hasRequestContentTypeChoice(node)) return buildClientOptionType({ omit: ["contentType"] });
149
162
  const request = getContentTypeInfo(node);
150
163
  const response = getResponseContentTypeInfo(node);
151
164
  const members = [request.isMultipleContentTypes ? `request?: ${request.contentTypeUnion}` : null, response.isMultipleContentTypes ? `response?: ${response.contentTypeUnion}` : null].filter(Boolean);
152
- const base = buildClientOptionType(node);
165
+ const base = buildClientOptionType();
153
166
  return members.length ? `${base} & { contentType?: { ${members.join("; ")} } }` : base;
154
167
  }
155
168
  /** The grouped request options, in the order generated signatures and calls list them. */
@@ -193,19 +206,13 @@ function getRequestGroupOptionality(node) {
193
206
  };
194
207
  }
195
208
  function buildOperationComments(node, options = {}) {
196
- const { link = "pathTemplate", linkPosition = "afterDeprecated", splitLines = false } = options;
197
- const linkComment = getOperationLink(node, link);
198
- const filteredComments = (linkPosition === "beforeDeprecated" ? [
209
+ const { splitLines = false } = options;
210
+ const filteredComments = [
211
+ getOperationRequestLine(node),
199
212
  node.description && `@description ${node.description}`,
200
213
  node.summary && `@summary ${node.summary}`,
201
- linkComment,
202
214
  node.deprecated && "@deprecated"
203
- ] : [
204
- node.description && `@description ${node.description}`,
205
- node.summary && `@summary ${node.summary}`,
206
- node.deprecated && "@deprecated",
207
- linkComment
208
- ]).filter((comment) => Boolean(comment));
215
+ ].filter((comment) => Boolean(comment));
209
216
  if (!splitLines) return filteredComments;
210
217
  return filteredComments.flatMap((text) => text.split(/\r?\n/).map((line) => line.trim())).filter((comment) => Boolean(comment));
211
218
  }
@@ -259,12 +266,6 @@ function getOperationParameters(node) {
259
266
  function hasRequestContentTypeChoice(node) {
260
267
  return (node.requestBody?.content ?? []).filter((entry) => entry.schema).length > 1;
261
268
  }
262
- /**
263
- * Casts a call argument to the client's parameter type; a `'plain'` client is non-generic.
264
- */
265
- function castToClientOptions(callArg, clientName, returnType = "full") {
266
- return `${callArg} as Parameters<typeof ${clientName}${returnType === "plain" ? "" : "<true>"}>[0]`;
267
- }
268
269
  function getStatusCodeNumber(statusCode) {
269
270
  const code = Number(statusCode);
270
271
  return Number.isNaN(code) ? null : code;
@@ -550,7 +551,7 @@ var compatibility = {
550
551
  "node": ">=22.22"
551
552
  };
552
553
  // package.json
553
- var version = "5.10.0-canary.20261109T201601";
554
+ var version = "5.11.0-canary.20261109T211319";
554
555
  // ../../internals/client/src/resolveOperationTypes.ts
555
556
  /**
556
557
  * A `plugin-ts` shaped resolver whose operation type names point at the types `pluginZod({ inferred })`
@@ -956,8 +957,8 @@ function buildGroupedRequestParam(node, options) {
956
957
  /**
957
958
  * Builds the shared `({ path, query, body, headers, cookies }, config = {})` parameter list for a
958
959
  * TanStack query-options function. The leading parameter mirrors the client signature, and the
959
- * trailing `config` is a partial `RequestConfig` minus the grouped data-shape keys, which are passed
960
- * explicitly. Framework plugins wrap the result when needed, for example vue-query applies `MaybeRefOrGetter`.
960
+ * trailing `config` is the client's `Options` minus the request groups and `throwOnError`, which the
961
+ * hook passes itself. Framework plugins wrap the result when needed, for example vue-query applies `MaybeRefOrGetter`.
961
962
  */
962
963
  function buildQueryOptionsParams(node, options) {
963
964
  const { resolver, memberTypeWrapper } = options;
@@ -967,7 +968,7 @@ function buildQueryOptionsParams(node, options) {
967
968
  });
968
969
  const configParam = (0, _kubb_plugin_ts.createFunctionParameter)({
969
970
  name: "config",
970
- type: buildClientOptionType(node),
971
+ type: buildClientOptionType(),
971
972
  default: "{}"
972
973
  });
973
974
  return (0, _kubb_plugin_ts.createFunctionParameters)({ params: [groupedParam, configParam].filter((param) => param !== null) });
@@ -979,26 +980,30 @@ function buildQueryOptionsParams(node, options) {
979
980
  * can't flip the query's error semantics. Queries thread the TanStack `signal`; mutations omit it.
980
981
  *
981
982
  * When `unwrapName` is set, each request group is passed as an explicit member unwrapped through it,
982
- * used by vue-query to resolve refs and getters with `toValue(...)` at call time.
983
+ * used by vue-query to resolve refs and getters with `toValue(...)` at call time. `pageParam` names the
984
+ * query parameter an infinite query sets from TanStack's `pageParam`.
983
985
  *
984
986
  * @example
985
987
  * ```ts
986
988
  * buildClientCall(node, { clientName: 'getPetById', signal: true })
987
- * // getPetById({ path, ...config, signal: config.signal ?? signal, throwOnError: true })
989
+ * // getPetById({ ...config, path, signal: config.signal ?? signal, throwOnError: true })
988
990
  * ```
989
991
  */
990
992
  function buildClientCall(node, options) {
991
- const { clientName, signal = false, unwrapName, withContentType = false, returnType = "full" } = options;
993
+ const { clientName, signal = false, unwrapName, withContentType = false, pageParam } = options;
992
994
  const { groups } = getRequestGroupOptionality(node);
993
995
  const names = requestGroupOrder.filter((key) => groups[key]);
994
- const args = [
996
+ const member = (name) => {
997
+ const value = unwrapName ? unwrapName(name) : name;
998
+ if (name === "query" && pageParam) return `query: { ...${value}, ${JSON.stringify(pageParam)}: pageParam }`;
999
+ return unwrapName ? `${name}: ${value}` : name;
1000
+ };
1001
+ return `${clientName}({ ${[
995
1002
  "...config",
996
- ...withContentType && hasRequestContentTypeChoice(node) ? ["...variables"] : names.map((name) => unwrapName ? `${name}: ${unwrapName(name)}` : name),
1003
+ ...withContentType && hasRequestContentTypeChoice(node) ? ["...variables"] : names.map(member),
997
1004
  signal ? "signal: config.signal ?? signal" : null,
998
1005
  "throwOnError: true"
999
- ].filter((part) => part !== null);
1000
- if (withContentType && hasRequestContentTypeChoice(node)) return `${clientName}(${castToClientOptions(`{ ${args.join(", ")} }`, clientName, returnType)})`;
1001
- return `${clientName}({ ${args.join(", ")} })`;
1006
+ ].filter((part) => part !== null).join(", ")} })`;
1002
1007
  }
1003
1008
  /**
1004
1009
  * Builds the query/mutation body that resolves a `buildClientCall` expression down to the bare
@@ -1247,9 +1252,15 @@ function buildHookParams(node, options) {
1247
1252
  }
1248
1253
  /**
1249
1254
  * The `TRequest` type argument of a mutation hook: the options type when the operation takes a request, else `undefined`.
1255
+ * When the variables carry the request media type and the response has several, `contentType` can pick the
1256
+ * response one too, as `{ request, response }`.
1250
1257
  */
1251
1258
  function resolveMutationRequestType(node, resolver) {
1252
- return buildGroupedRequestParam(node, { resolver }) ? resolver.response.options(node) : "undefined";
1259
+ if (!buildGroupedRequestParam(node, { resolver })) return "undefined";
1260
+ const optionsName = resolver.response.options(node);
1261
+ const response = getResponseContentTypeInfo(node);
1262
+ if (!hasRequestContentTypeChoice(node) || !response.isMultipleContentTypes) return optionsName;
1263
+ return `${/^[\w$]+$/.test(optionsName) ? optionsName : `(${optionsName})`} & { contentType?: string | { response?: ${response.contentTypeUnion} } }`;
1253
1264
  }
1254
1265
  /**
1255
1266
  * Builds the object literal that unwraps each request group's getter before it reaches `queryKey`/`queryOptions`; `null` without a request group.
@@ -1283,10 +1294,12 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, hasExplicitI
1283
1294
  memberTypeWrapper
1284
1295
  });
1285
1296
  const paramsSignature = declarationPrinter$6.print(paramsNode) ?? "";
1297
+ const pageParam = queryParam && queryParamsTypeName ? queryParam : void 0;
1286
1298
  const queryFnBody = buildCallResultBody(buildClientCall(node, {
1287
1299
  clientName,
1288
1300
  signal: true,
1289
- unwrapName
1301
+ unwrapName,
1302
+ pageParam
1290
1303
  }), {
1291
1304
  clientReturnType,
1292
1305
  returnType
@@ -1313,12 +1326,7 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, hasExplicitI
1313
1326
  getNextPageParamExpr,
1314
1327
  getPreviousPageParamExpr
1315
1328
  ].filter(Boolean);
1316
- const infiniteOverrideParams = queryParam && queryParamsTypeName ? `query = {
1317
- ...(query ?? {}),
1318
- ['${queryParam}']: pageParam as unknown as ${queryParamsTypeName}['${queryParam}'],
1319
- } as ${queryParamsTypeName}` : "";
1320
- const queryFnArgs = infiniteOverrideParams ? "{ signal, pageParam }" : "{ signal }";
1321
- const queryFnStatements = infiniteOverrideParams ? `${infiniteOverrideParams}\n ${queryFnBody}` : queryFnBody;
1329
+ const queryFnArgs = pageParam ? "{ signal, pageParam }" : "{ signal }";
1322
1330
  return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
1323
1331
  name,
1324
1332
  isExportable: true,
@@ -1332,7 +1340,7 @@ const queryKey = ${queryKeyName}(${queryKeyParamsCall})
1332
1340
  return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, ${queryKeyType}, ${pageParamType}>({
1333
1341
  queryKey,
1334
1342
  queryFn: async (${queryFnArgs}) => {
1335
- ${queryFnStatements}
1343
+ ${queryFnBody}
1336
1344
  },
1337
1345
  ${queryOptionsArr.join(",\n ")}
1338
1346
  })
@@ -1793,7 +1801,7 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, t
1793
1801
  memberTypeWrapper: maybeValueOrGetter,
1794
1802
  optionsType: `{
1795
1803
  query?: Partial<${observerOptionsType}> & { client?: QueryClient },
1796
- client?: ${buildClientOptionType(node)}
1804
+ client?: ${buildClientOptionType()}
1797
1805
  }`
1798
1806
  });
1799
1807
  const paramsSignature = declarationPrinter$3.print(paramsNode) ?? "";
@@ -2057,13 +2065,12 @@ function MutationOptions({ name, clientName, node, tsResolver, mutationKeyName,
2057
2065
  });
2058
2066
  const hasMutationParams = groupedParam !== null;
2059
2067
  const groupedParamsNode = (0, _kubb_plugin_ts.createFunctionParameters)({ params: groupedParam ? [groupedParam] : [] });
2060
- const TRequest = hasMutationParams ? tsResolver.response.options(node) : "undefined";
2068
+ const TRequest = resolveMutationRequestType(node, tsResolver);
2061
2069
  const argBindingStr = hasMutationParams ? callPrinter$1.print(groupedParamsNode) ?? "" : "_";
2062
2070
  const mutationFnBody = buildCallResultBody(buildClientCall(node, {
2063
2071
  clientName,
2064
2072
  signal: false,
2065
- withContentType: true,
2066
- returnType: clientReturnType
2073
+ withContentType: true
2067
2074
  }), {
2068
2075
  clientReturnType,
2069
2076
  returnType