@kubb/plugin-vue-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.d.ts CHANGED
@@ -13,8 +13,8 @@ import "@kubb/plugin-zod";
13
13
  *
14
14
  * - `contract` — a registered contract client plugin owns the `<op>` functions and the consumer
15
15
  * imports and calls them.
16
- * - `error` — no client plugin is registered, several are registered without a selector, or the
17
- * requested one is missing.
16
+ * - `error` — no client plugin is registered, several are registered without a selector, the
17
+ * requested one is missing, or `client` is not a known selector.
18
18
  *
19
19
  * The `client` string selects explicitly (`'fetch'` / `'axios'`); when it is unset a lone registered
20
20
  * contract client plugin is picked up automatically.
@@ -36,9 +36,19 @@ type ResolvedContractClient = {
36
36
  //#endregion
37
37
  //#region ../../internals/tanstack-query/src/types.d.ts
38
38
  type ParamsCasing = 'camelcase' | undefined;
39
+ /**
40
+ * The hook a key is built for. Plain and suspense queries can share a key, but an infinite query
41
+ * caches `InfiniteData` and must never share one with a plain query.
42
+ */
43
+ type KeyVariant = 'query' | 'suspenseQuery' | 'infiniteQuery' | 'suspenseInfiniteQuery' | 'mutation';
44
+ /**
45
+ * Builds query or mutation key segments for an operation node.
46
+ * Receives `variant` indicating which hook or composable the key is built for.
47
+ */
39
48
  type Transformer = (props: {
40
49
  node: ast.OperationNode;
41
50
  casing: ParamsCasing;
51
+ variant: KeyVariant;
42
52
  }) => Array<unknown>;
43
53
  /**
44
54
  * Configures the query side of a TanStack-family plugin: which HTTP methods produce query
@@ -187,7 +197,8 @@ type ResolverVueQuery = Resolver & {
187
197
  };
188
198
  };
189
199
  /**
190
- * Builds the `queryKey` used by each generated query composable.
200
+ * Builds the `queryKey` used by each generated query composable. `variant` tells which composable
201
+ * the key is for, so infinite keys can stay apart from plain ones.
191
202
  *
192
203
  * @note String values are inlined verbatim into generated code. Wrap literal
193
204
  * strings in `JSON.stringify(...)`.
@@ -259,8 +270,8 @@ type Options = OutputOptions & {
259
270
  */
260
271
  resolver?: ResolverPatch<ResolverVueQuery>;
261
272
  /**
262
- * Set to `false` to skip generating `use*` composable functions. `queryOptions`,
263
- * `queryKey`, and `mutationKey` helpers are still emitted.
273
+ * Set to `true` to also generate `use*` composable functions. By default only the
274
+ * `queryOptions`, `queryKey`, and `mutationKey` helpers are emitted.
264
275
  *
265
276
  * @default false
266
277
  */
package/dist/index.js CHANGED
@@ -646,7 +646,8 @@ function MutationKey({ name, node, transformer }) {
646
646
  const paramsSignature = declarationPrinter$6.print(paramsNode) ?? "";
647
647
  const keys = (transformer ?? mutationKeyTransformer)({
648
648
  node,
649
- casing: "camelcase"
649
+ casing: "camelcase",
650
+ variant: "mutation"
650
651
  });
651
652
  return /* @__PURE__ */ jsx(File.Source, {
652
653
  name,
@@ -715,16 +716,17 @@ function createMutationResolver() {
715
716
  };
716
717
  }
717
718
  functionPrinter({ mode: "declaration" });
718
- const queryKeyTransformer = ({ node }) => {
719
+ const queryKeyTransformer = ({ node, variant }) => {
719
720
  if (!node.path) return [];
720
- const hasPathParams = getOperationParameters(node).path.length > 0;
721
- const hasQueryParams = getOperationParameters(node).query.length > 0;
722
- const hasRequestBody = !!node.requestBody?.content?.[0]?.schema;
723
- return [
724
- hasPathParams ? `{ url: '${Url.toPath(node.path)}', params: path }` : `{ url: '${Url.toPath(node.path)}' }`,
725
- hasQueryParams ? "...(query ? [query] : [])" : null,
726
- hasRequestBody ? "...(body ? [body] : [])" : null
727
- ].filter(Boolean);
721
+ const { path, query } = getOperationParameters(node);
722
+ const isInfinite = variant === "infiniteQuery" || variant === "suspenseInfiniteQuery";
723
+ const urlFields = [`url: '${Url.toPath(node.path)}'`];
724
+ if (path.length > 0) urlFields.push("params: path");
725
+ if (isInfinite) urlFields.push("infinite: true");
726
+ const result = [`{ ${urlFields.join(", ")} }`];
727
+ if (query.length > 0) result.push("...(query ? [query] : [])");
728
+ if (node.requestBody?.content?.[0]?.schema) result.push("...(body ? [body] : [])");
729
+ return result;
728
730
  };
729
731
  //#endregion
730
732
  //#region ../../internals/client/src/resolveClient.ts
@@ -737,8 +739,8 @@ const queryKeyTransformer = ({ node }) => {
737
739
  *
738
740
  * - `contract` — a registered contract client plugin owns the `<op>` functions and the consumer
739
741
  * imports and calls them.
740
- * - `error` — no client plugin is registered, several are registered without a selector, or the
741
- * requested one is missing.
742
+ * - `error` — no client plugin is registered, several are registered without a selector, the
743
+ * requested one is missing, or `client` is not a known selector.
742
744
  *
743
745
  * The `client` string selects explicitly (`'fetch'` / `'axios'`); when it is unset a lone registered
744
746
  * contract client plugin is picked up automatically.
@@ -779,6 +781,10 @@ function resolveClient(options) {
779
781
  pluginName
780
782
  };
781
783
  }
784
+ if (client !== void 0) return {
785
+ kind: "error",
786
+ 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.`
787
+ };
782
788
  const registered = contractPlugins.filter(has);
783
789
  if (registered.length === 1) return {
784
790
  kind: "contract",
@@ -880,12 +886,13 @@ function buildQueryKeyParamsNode(node, options) {
880
886
  });
881
887
  return createFunctionParameters({ params: groupedParam ? [groupedParam] : [] });
882
888
  }
883
- function QueryKey({ name, node, tsResolver, typeName, transformer }) {
889
+ function QueryKey({ name, node, tsResolver, typeName, transformer, variant = "query" }) {
884
890
  const paramsNode = buildQueryKeyParamsNode(node, { resolver: tsResolver });
885
891
  const paramsSignature = declarationPrinter$4.print(paramsNode) ?? "";
886
892
  const keys = (transformer ?? queryKeyTransformer)({
887
893
  node,
888
- casing: "camelcase"
894
+ casing: "camelcase",
895
+ variant
889
896
  });
890
897
  return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(File.Source, {
891
898
  name,
@@ -1189,8 +1196,7 @@ const infiniteQueryGenerator = defineGenerator({
1189
1196
  if (!ast.isHttpOperationNode(node)) return null;
1190
1197
  const { config, driver, resolver, root } = ctx;
1191
1198
  const { output, query, mutation, infinite, client, group, hooks } = ctx.options;
1192
- const pluginTs = driver.getPlugin(pluginTsName);
1193
- if (!pluginTs) return null;
1199
+ const pluginTs = ctx.requirePlugin(pluginTsName);
1194
1200
  const tsResolver = driver.getResolver(pluginTsName);
1195
1201
  const { isQuery, isMutation } = classifyOperation(node, {
1196
1202
  query,
@@ -1298,7 +1304,8 @@ const infiniteQueryGenerator = defineGenerator({
1298
1304
  typeName: queryKeyTypeName,
1299
1305
  node,
1300
1306
  tsResolver,
1301
- transformer: ctx.options.queryKey
1307
+ transformer: ctx.options.queryKey,
1308
+ variant: "infiniteQuery"
1302
1309
  }),
1303
1310
  /* @__PURE__ */ jsx(File.Import, {
1304
1311
  name: ["InfiniteData"],
@@ -1364,8 +1371,7 @@ const mutationGenerator = defineGenerator({
1364
1371
  if (!ast.isHttpOperationNode(node)) return null;
1365
1372
  const { config, driver, resolver, root } = ctx;
1366
1373
  const { output, query, mutation, client, group, hooks } = ctx.options;
1367
- const pluginTs = driver.getPlugin(pluginTsName);
1368
- if (!pluginTs) return null;
1374
+ const pluginTs = ctx.requirePlugin(pluginTsName);
1369
1375
  const tsResolver = driver.getResolver(pluginTsName);
1370
1376
  const { isMutation } = classifyOperation(node, {
1371
1377
  query,
@@ -1498,8 +1504,7 @@ const queryGenerator = defineGenerator({
1498
1504
  if (!ast.isHttpOperationNode(node)) return null;
1499
1505
  const { config, driver, resolver, root } = ctx;
1500
1506
  const { output, query, mutation, client, group, hooks } = ctx.options;
1501
- const pluginTs = driver.getPlugin(pluginTsName);
1502
- if (!pluginTs) return null;
1507
+ const pluginTs = ctx.requirePlugin(pluginTsName);
1503
1508
  const tsResolver = driver.getResolver(pluginTsName);
1504
1509
  const { isQuery, isMutation } = classifyOperation(node, {
1505
1510
  query,
@@ -1594,7 +1599,8 @@ const queryGenerator = defineGenerator({
1594
1599
  typeName: queryKeyTypeName,
1595
1600
  node,
1596
1601
  tsResolver,
1597
- transformer: ctx.options.queryKey
1602
+ transformer: ctx.options.queryKey,
1603
+ variant: "query"
1598
1604
  }),
1599
1605
  /* @__PURE__ */ jsx(File.Import, {
1600
1606
  name: ["queryOptions"],
@@ -1714,6 +1720,7 @@ const pluginVueQuery = definePlugin((options) => {
1714
1720
  options,
1715
1721
  dependencies: [pluginTsName],
1716
1722
  hooks: { "kubb:plugin:setup"(ctx) {
1723
+ ctx.requirePlugin(pluginTsName);
1717
1724
  const resolver = userResolver ? Resolver.merge(resolverVueQuery, userResolver) : resolverVueQuery;
1718
1725
  ctx.setOptions({
1719
1726
  output,