@kubb/plugin-react-query 5.2.0-canary.20261007T095624 → 5.2.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/index.cjs CHANGED
@@ -360,8 +360,8 @@ function createGroupConfig(group) {
360
360
  *
361
361
  * - `contract` — a registered contract client plugin owns the `<op>` functions and the consumer
362
362
  * imports and calls them.
363
- * - `error` — no client plugin is registered, several are registered without a selector, or the
364
- * requested one is missing.
363
+ * - `error` — no client plugin is registered, several are registered without a selector, the
364
+ * requested one is missing, or `client` is not a known selector.
365
365
  *
366
366
  * The `client` string selects explicitly (`'fetch'` / `'axios'`); when it is unset a lone registered
367
367
  * contract client plugin is picked up automatically.
@@ -402,6 +402,10 @@ function resolveClient(options) {
402
402
  pluginName
403
403
  };
404
404
  }
405
+ if (client !== void 0) return {
406
+ kind: "error",
407
+ message: `Option \`client\` is ${typeof client === "string" ? `'${client}'` : String(client)}, but it must be one of 'fetch', 'axios'. Drop \`client\` to use the registered client plugin.`
408
+ };
405
409
  const registered = contractPlugins.filter(has);
406
410
  if (registered.length === 1) return {
407
411
  kind: "contract",
@@ -834,7 +838,8 @@ function MutationKey({ name, node, transformer }) {
834
838
  const paramsSignature = declarationPrinter$6.print(paramsNode) ?? "";
835
839
  const keys = (transformer ?? mutationKeyTransformer)({
836
840
  node,
837
- casing: "camelcase"
841
+ casing: "camelcase",
842
+ variant: "mutation"
838
843
  });
839
844
  return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
840
845
  name,
@@ -905,23 +910,25 @@ function createMutationResolver() {
905
910
  //#endregion
906
911
  //#region ../../internals/tanstack-query/src/components/QueryKey.tsx
907
912
  const declarationPrinter$5 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
908
- const queryKeyTransformer = ({ node }) => {
913
+ const queryKeyTransformer = ({ node, variant }) => {
909
914
  if (!node.path) return [];
910
- const hasPathParams = getOperationParameters(node).path.length > 0;
911
- const hasQueryParams = getOperationParameters(node).query.length > 0;
912
- const hasRequestBody = !!node.requestBody?.content?.[0]?.schema;
913
- return [
914
- hasPathParams ? `{ url: '${kubb_kit.Url.toPath(node.path)}', params: path }` : `{ url: '${kubb_kit.Url.toPath(node.path)}' }`,
915
- hasQueryParams ? "...(query ? [query] : [])" : null,
916
- hasRequestBody ? "...(body ? [body] : [])" : null
917
- ].filter(Boolean);
915
+ const { path, query } = getOperationParameters(node);
916
+ const isInfinite = variant === "infiniteQuery" || variant === "suspenseInfiniteQuery";
917
+ const urlFields = [`url: '${kubb_kit.Url.toPath(node.path)}'`];
918
+ if (path.length > 0) urlFields.push("params: path");
919
+ if (isInfinite) urlFields.push("infinite: true");
920
+ const result = [`{ ${urlFields.join(", ")} }`];
921
+ if (query.length > 0) result.push("...(query ? [query] : [])");
922
+ if (node.requestBody?.content?.[0]?.schema) result.push("...(body ? [body] : [])");
923
+ return result;
918
924
  };
919
- function QueryKey({ name, node, tsResolver, typeName, transformer }) {
925
+ function QueryKey({ name, node, tsResolver, typeName, transformer, variant = "query" }) {
920
926
  const paramsNode = buildQueryKeyParams(node, { resolver: tsResolver });
921
927
  const paramsSignature = declarationPrinter$5.print(paramsNode) ?? "";
922
928
  const keys = (transformer ?? queryKeyTransformer)({
923
929
  node,
924
- casing: "camelcase"
930
+ casing: "camelcase",
931
+ variant
925
932
  });
926
933
  return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(kubb_jsx_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
927
934
  name,
@@ -1546,8 +1553,7 @@ const infiniteQueryGenerator = (0, kubb_kit.defineGenerator)({
1546
1553
  if (!kubb_kit.ast.isHttpOperationNode(node)) return null;
1547
1554
  const { config, driver, resolver, root } = ctx;
1548
1555
  const { output, query, infinite, client, group, customOptions } = ctx.options;
1549
- const pluginTs = driver.getPlugin(_kubb_plugin_ts.pluginTsName);
1550
- if (!pluginTs) return null;
1556
+ const pluginTs = ctx.requirePlugin(_kubb_plugin_ts.pluginTsName);
1551
1557
  const tsResolver = driver.getResolver(_kubb_plugin_ts.pluginTsName);
1552
1558
  const infiniteOptions = infinite && typeof infinite === "object" ? infinite : null;
1553
1559
  if (!infiniteOptions) return null;
@@ -1643,7 +1649,8 @@ const infiniteQueryGenerator = (0, kubb_kit.defineGenerator)({
1643
1649
  typeName: queryKeyTypeName,
1644
1650
  node,
1645
1651
  tsResolver,
1646
- transformer: ctx.options.queryKey
1652
+ transformer: ctx.options.queryKey,
1653
+ variant: "infiniteQuery"
1647
1654
  }),
1648
1655
  /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
1649
1656
  name: ["InfiniteData"],
@@ -1719,8 +1726,7 @@ const mutationGenerator = (0, kubb_kit.defineGenerator)({
1719
1726
  if (!kubb_kit.ast.isHttpOperationNode(node)) return null;
1720
1727
  const { config, driver, resolver, root } = ctx;
1721
1728
  const { output, mutation, client, group, customOptions, hooks } = ctx.options;
1722
- const pluginTs = driver.getPlugin(_kubb_plugin_ts.pluginTsName);
1723
- if (!pluginTs) return null;
1729
+ const pluginTs = ctx.requirePlugin(_kubb_plugin_ts.pluginTsName);
1724
1730
  const tsResolver = driver.getResolver(_kubb_plugin_ts.pluginTsName);
1725
1731
  const importPath = mutation ? mutation.importPath : "@tanstack/react-query";
1726
1732
  const contractOp = resolveClientOperation({
@@ -1868,8 +1874,7 @@ const queryGenerator = (0, kubb_kit.defineGenerator)({
1868
1874
  if (!kubb_kit.ast.isHttpOperationNode(node)) return null;
1869
1875
  const { config, driver, resolver, root } = ctx;
1870
1876
  const { output, query, client, group, customOptions, hooks } = ctx.options;
1871
- const pluginTs = driver.getPlugin(_kubb_plugin_ts.pluginTsName);
1872
- if (!pluginTs) return null;
1877
+ const pluginTs = ctx.requirePlugin(_kubb_plugin_ts.pluginTsName);
1873
1878
  const tsResolver = driver.getResolver(_kubb_plugin_ts.pluginTsName);
1874
1879
  const importPath = query ? query.importPath : "@tanstack/react-query";
1875
1880
  const contractOp = resolveClientOperation({
@@ -1954,7 +1959,8 @@ const queryGenerator = (0, kubb_kit.defineGenerator)({
1954
1959
  typeName: queryKeyTypeName,
1955
1960
  node,
1956
1961
  tsResolver,
1957
- transformer: ctx.options.queryKey
1962
+ transformer: ctx.options.queryKey,
1963
+ variant: "query"
1958
1964
  }),
1959
1965
  /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
1960
1966
  name: ["queryOptions"],
@@ -2025,8 +2031,7 @@ const suspenseInfiniteQueryGenerator = (0, kubb_kit.defineGenerator)({
2025
2031
  if (!kubb_kit.ast.isHttpOperationNode(node)) return null;
2026
2032
  const { config, driver, resolver, root } = ctx;
2027
2033
  const { output, query, infinite, client, group, customOptions } = ctx.options;
2028
- const pluginTs = driver.getPlugin(_kubb_plugin_ts.pluginTsName);
2029
- if (!pluginTs) return null;
2034
+ const pluginTs = ctx.requirePlugin(_kubb_plugin_ts.pluginTsName);
2030
2035
  const tsResolver = driver.getResolver(_kubb_plugin_ts.pluginTsName);
2031
2036
  const infiniteOptions = infinite && typeof infinite === "object" ? infinite : null;
2032
2037
  if (!infiniteOptions) return null;
@@ -2118,7 +2123,8 @@ const suspenseInfiniteQueryGenerator = (0, kubb_kit.defineGenerator)({
2118
2123
  typeName: queryKeyTypeName,
2119
2124
  node,
2120
2125
  tsResolver,
2121
- transformer: ctx.options.queryKey
2126
+ transformer: ctx.options.queryKey,
2127
+ variant: "suspenseInfiniteQuery"
2122
2128
  }),
2123
2129
  /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
2124
2130
  name: ["InfiniteData"],
@@ -2198,8 +2204,7 @@ const suspenseQueryGenerator = (0, kubb_kit.defineGenerator)({
2198
2204
  if (!kubb_kit.ast.isHttpOperationNode(node)) return null;
2199
2205
  const { config, driver, resolver, root } = ctx;
2200
2206
  const { output, query, client, group, customOptions } = ctx.options;
2201
- const pluginTs = driver.getPlugin(_kubb_plugin_ts.pluginTsName);
2202
- if (!pluginTs) return null;
2207
+ const pluginTs = ctx.requirePlugin(_kubb_plugin_ts.pluginTsName);
2203
2208
  const tsResolver = driver.getResolver(_kubb_plugin_ts.pluginTsName);
2204
2209
  const importPath = query ? query.importPath : "@tanstack/react-query";
2205
2210
  const contractOp = resolveClientOperation({
@@ -2284,7 +2289,8 @@ const suspenseQueryGenerator = (0, kubb_kit.defineGenerator)({
2284
2289
  typeName: queryKeyTypeName,
2285
2290
  node,
2286
2291
  tsResolver,
2287
- transformer: ctx.options.queryKey
2292
+ transformer: ctx.options.queryKey,
2293
+ variant: "suspenseQuery"
2288
2294
  }),
2289
2295
  /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
2290
2296
  name: ["queryOptions"],
@@ -2423,6 +2429,7 @@ const pluginReactQuery = (0, kubb_kit.definePlugin)((options) => {
2423
2429
  options,
2424
2430
  dependencies: [_kubb_plugin_ts.pluginTsName],
2425
2431
  hooks: { "kubb:plugin:setup"(ctx) {
2432
+ ctx.requirePlugin(_kubb_plugin_ts.pluginTsName);
2426
2433
  const resolver = userResolver ? kubb_kit.Resolver.merge(resolverReactQuery, userResolver) : resolverReactQuery;
2427
2434
  ctx.setOptions({
2428
2435
  output,