@kubb/plugin-vue-query 5.13.2 → 5.13.3

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.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { FileNode, Macro, OperationNode, StatusCode } from "@kubb/ast";
1
+ import { Macro, OperationNode, StatusCode } from "@kubb/ast";
2
2
  import { Exclude, Group, Include, Output, OutputOptions, Override, PluginType, Resolver, ResolverInput } from "@kubb/kit";
3
3
  import { ResolverTs } from "@kubb/plugin-ts";
4
4
  /**
@@ -195,7 +195,6 @@ declare global {
195
195
  namespace Kubb {
196
196
  interface MemoRegistry {
197
197
  operation: string;
198
- file: FileNode['baseName'];
199
198
  operationTypeNames: Array<string>;
200
199
  }
201
200
  }
@@ -359,8 +358,7 @@ type Options = PluginOptions<ResolvedOptions> & {
359
358
  */
360
359
  queryKey?: QueryKey;
361
360
  /**
362
- * Configures query composables. Set to `false` to skip composable generation
363
- * and emit only `queryOptions(...)` helpers.
361
+ * Configures query composables. Set to `false` to skip the query output.
364
362
  */
365
363
  query?: Partial<Query> | false;
366
364
  /**
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { FileNode, Macro, OperationNode, StatusCode } from "@kubb/ast";
1
+ import { Macro, OperationNode, StatusCode } from "@kubb/ast";
2
2
  import { Exclude, Group, Include, Output, OutputOptions, Override, PluginType, Resolver, ResolverInput } from "@kubb/kit";
3
3
  import { ResolverTs } from "@kubb/plugin-ts";
4
4
  /**
@@ -195,7 +195,6 @@ declare global {
195
195
  namespace Kubb {
196
196
  interface MemoRegistry {
197
197
  operation: string;
198
- file: FileNode['baseName'];
199
198
  operationTypeNames: Array<string>;
200
199
  }
201
200
  }
@@ -359,8 +358,7 @@ type Options = PluginOptions<ResolvedOptions> & {
359
358
  */
360
359
  queryKey?: QueryKey;
361
360
  /**
362
- * Configures query composables. Set to `false` to skip composable generation
363
- * and emit only `queryOptions(...)` helpers.
361
+ * Configures query composables. Set to `false` to skip the query output.
364
362
  */
365
363
  query?: Partial<Query> | false;
366
364
  /**
package/dist/index.js CHANGED
@@ -10,7 +10,7 @@ var compatibility = {
10
10
  "node": ">=22.22"
11
11
  };
12
12
  // package.json
13
- var version = "5.13.2";
13
+ var version = "5.13.3";
14
14
  // ../../internals/ast/src/http/requestBody.ts
15
15
  /** The schema of the first request body entry, else `undefined` when the operation takes no body. */
16
16
  function getSchema(node) {
@@ -272,6 +272,22 @@ function resolveContractClient(options) {
272
272
  return resolved;
273
273
  }
274
274
  // ../../internals/client/src/resolveClientOperation.ts
275
+ const consumerBindings = /* @__PURE__ */ new Set([
276
+ "path",
277
+ "query",
278
+ "body",
279
+ "headers",
280
+ "cookies",
281
+ "config",
282
+ "signal",
283
+ "variables",
284
+ "options",
285
+ "ctx",
286
+ "res",
287
+ "pageParam",
288
+ "queryKey",
289
+ "mutationKey"
290
+ ]);
275
291
  function isRelativeImport(importPath) {
276
292
  return importPath.startsWith(".");
277
293
  }
@@ -281,8 +297,8 @@ function resolveImportPath(options) {
281
297
  }
282
298
  /**
283
299
  * Resolves the contract client `<op>` a consumer (query hook, MCP handler) imports, from the registered contract client plugin
284
- * (plugin-fetch, plugin-axios, or plugin-client). Returns `null` when the client plugin's `exclude` / `include` leaves this
285
- * operation out, since it then emits no `<op>` to import. plugin-fetch / plugin-axios inject `.kubb/client.ts` at the global
300
+ * (plugin-fetch, plugin-axios, plugin-ky, or plugin-client). Returns `null` when the client plugin's `exclude` / `include` leaves this
301
+ * operation out, since it then emits no `<op>` to import. plugin-fetch, plugin-axios and plugin-ky inject `.kubb/client.ts` at the global
286
302
  * output root, the same path consumers read `RequestConfig` / `ResponseErrorConfig` from. With plugin-client they come from
287
303
  * the user's `importPath` module instead.
288
304
  *
@@ -304,14 +320,20 @@ function resolveClientOperation({ node, pluginName }) {
304
320
  override
305
321
  });
306
322
  if (!operationOptions) return null;
307
- const name = resolver.resolveName({
323
+ const importName = resolver.resolveName({
308
324
  key: operationKey(node),
309
325
  name: resolver.name(node.operationId)
310
326
  });
327
+ const name = consumerBindings.has(importName) ? `${importName}Request` : importName;
311
328
  const file = ctx.file(node, { plugin: pluginName });
312
329
  const { importPath } = operationOptions;
313
330
  return {
314
331
  name,
332
+ moduleName: {
333
+ name: importName,
334
+ alias: name === importName ? void 0 : name,
335
+ space: "value"
336
+ },
315
337
  path: file.path,
316
338
  clientPath: importPath === void 0 ? path.resolve(ctx.root, ".kubb/client.ts") : resolveImportPath({
317
339
  importPath,
@@ -337,7 +359,7 @@ function buildResponseHeadersType({ node, types }) {
337
359
  const entries = getResponseHeadersEntries({
338
360
  node,
339
361
  types
340
- }).map(([statusCode, name]) => `'${statusCode}': ${name}`);
362
+ }).map(([statusCode, name]) => `${text.quote(statusCode)}: ${name}`);
341
363
  return entries.length ? `{ ${entries.join("; ")} }` : null;
342
364
  }
343
365
  /**
@@ -550,7 +572,7 @@ function isIdentifier(name) {
550
572
  function getNestedAccessor(param, accessor) {
551
573
  const parts = Array.isArray(param) ? param : param.split(".");
552
574
  if (parts.length === 0 || parts.length === 1 && parts[0] === "") return null;
553
- return `${accessor}?.['${`${parts.join("']?.['")}']`}`;
575
+ return `${accessor}${parts.map((part) => `?.[${text.quote(part)}]`).join("")}`;
554
576
  }
555
577
  /**
556
578
  * Escapes an `@` at the start of a line, so a multi-line description can't start a new JSDoc tag.
@@ -674,8 +696,8 @@ function buildOperationComments(node, options = {}) {
674
696
  const { splitLines = false } = options;
675
697
  const filteredComments = [
676
698
  getOperationRequestLine(node),
677
- node.description && `@description ${node.description}`,
678
- node.summary && `@summary ${node.summary}`,
699
+ node.description && `@description ${jsDocEscape(node.description)}`,
700
+ node.summary && `@summary ${jsDocEscape(node.summary)}`,
679
701
  node.deprecated && "@deprecated",
680
702
  node.externalDocs && `@see ${jsDocEscape([node.externalDocs.url, node.externalDocs.description].filter(Boolean).join(" "))}`
681
703
  ].filter((comment) => Boolean(comment));
@@ -869,10 +891,7 @@ function HookFile({ hook, imports, children }) {
869
891
  ...file,
870
892
  children: [
871
893
  /* @__PURE__ */ jsx(File.Import, {
872
- names: [{
873
- name: contractOp.name,
874
- space: "value"
875
- }],
894
+ names: [contractOp.moduleName],
876
895
  root: file.path,
877
896
  path: contractOp.path
878
897
  }),
@@ -1079,7 +1098,7 @@ function resolvePageParamType(node, { resolver, initialPageParam, queryParam })
1079
1098
  const firstQueryParam = groupParameters(node).query[0];
1080
1099
  const groupName = firstQueryParam ? resolver.param.query(node, firstQueryParam) : null;
1081
1100
  const queryParamsTypeName = groupName !== (firstQueryParam ? resolver.param.name(node, firstQueryParam) : null) ? groupName : null;
1082
- const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : null;
1101
+ const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}[${text.quote(queryParam)}]` : null;
1083
1102
  if (!queryParamType) return {
1084
1103
  queryParamsTypeName,
1085
1104
  pageParamType: resolveFallbackPageParamType(initialPageParam)
@@ -1286,7 +1305,7 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, hasExplicitI
1286
1305
  const getNextPageParamExpr = (() => {
1287
1306
  if (serializedGetNextPageParam) return `getNextPageParam: ${serializedGetNextPageParam}`;
1288
1307
  if (nextParam) return `getNextPageParam: (lastPage) => ${getNestedAccessor(nextParam, `lastPage${dataSuffix}`)}`;
1289
- if (cursorParam) return `getNextPageParam: (lastPage) => lastPage${dataSuffix}['${cursorParam}']`;
1308
+ if (cursorParam) return `getNextPageParam: (lastPage) => lastPage${dataSuffix}[${text.quote(cursorParam)}]`;
1290
1309
  return `getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage${dataSuffix}) && lastPage${dataSuffix}.length === 0 ? undefined : lastPageParam + 1`;
1291
1310
  })();
1292
1311
  const serializedGetPreviousPageParam = typeof getPreviousPageParam === "function" ? getPreviousPageParam.toString() : getPreviousPageParam;
@@ -1294,7 +1313,7 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, hasExplicitI
1294
1313
  const getPreviousPageParamExpr = (() => {
1295
1314
  if (serializedGetPreviousPageParam) return `getPreviousPageParam: ${serializedGetPreviousPageParam}`;
1296
1315
  if (previousParam) return `getPreviousPageParam: (firstPage) => ${getNestedAccessor(previousParam, `firstPage${dataSuffix}`)}`;
1297
- if (cursorParam) return `getPreviousPageParam: (firstPage) => firstPage${dataSuffix}['${cursorParam}']`;
1316
+ if (cursorParam) return `getPreviousPageParam: (firstPage) => firstPage${dataSuffix}[${text.quote(cursorParam)}]`;
1298
1317
  if (serializedGetNextPageParam || nextParam) return null;
1299
1318
  return `getPreviousPageParam: (_firstPage, _allPages, firstPageParam) => firstPageParam <= ${defaultPreviousThreshold} ? undefined : firstPageParam - 1`;
1300
1319
  })();
@@ -1462,12 +1481,17 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, t
1462
1481
  `TQueryData = ${TData}`,
1463
1482
  `TQueryKey extends QueryKey = ${queryKeyTypeName}`
1464
1483
  ];
1465
- const optionsGenerics = infinite ? [
1466
- TData,
1467
- TError,
1484
+ const pageParamType = infinite ? resolvePageParamType(node, {
1485
+ resolver: tsResolver,
1486
+ initialPageParam: infinite.initialPageParam,
1487
+ queryParam: infinite.queryParam
1488
+ }).pageParamType : null;
1489
+ const optionsGenerics = pageParamType ? [
1468
1490
  "TQueryData",
1491
+ TError,
1492
+ "TData",
1469
1493
  "TQueryKey",
1470
- "TQueryData"
1494
+ pageParamType
1471
1495
  ] : [
1472
1496
  TData,
1473
1497
  TError,
@@ -1475,12 +1499,12 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, t
1475
1499
  "TQueryData",
1476
1500
  "TQueryKey"
1477
1501
  ];
1478
- const castGenerics = infinite ? [
1502
+ const castGenerics = pageParamType ? [
1479
1503
  TData,
1480
1504
  TError,
1481
- TData,
1505
+ "TData",
1482
1506
  "TQueryKey",
1483
- TData
1507
+ pageParamType
1484
1508
  ] : [
1485
1509
  TData,
1486
1510
  TError,
@@ -1542,7 +1566,7 @@ function matchesInfiniteQuery(node, ctx) {
1542
1566
  /**
1543
1567
  * Built-in template for `useInfiniteQuery` composables. Enabled when
1544
1568
  * `pluginVueQuery({ infinite: { ... }, hooks: true })`. Emits one
1545
- * `useFooInfiniteQuery` composable per query operation, wiring the
1569
+ * `useFooInfinite` composable per query operation, wiring the
1546
1570
  * configured cursor path into TanStack Query's cursor-based pagination.
1547
1571
  */
1548
1572
  const infiniteQueryOperation = defineTemplate({
@@ -1663,7 +1687,7 @@ const infiniteQueryOperation = defineTemplate({
1663
1687
  queryKeyTypeName,
1664
1688
  node,
1665
1689
  tsResolver,
1666
- infinite: true,
1690
+ infinite: infiniteOptions,
1667
1691
  returnType: hook.returnType,
1668
1692
  typedHeaders: hook.contractOp.typedHeaders
1669
1693
  })
@@ -1752,7 +1776,7 @@ function Mutation({ name, clientName, node, tsResolver, mutationKeyName, clientR
1752
1776
  // src/templates/mutation.tsx
1753
1777
  /**
1754
1778
  * Built-in template for `useMutation` composables. Emits one
1755
- * `useFooMutation` composable per POST/PUT/DELETE operation (configurable
1779
+ * `useFoo` composable per POST/PUT/DELETE operation (configurable
1756
1780
  * via `mutation.methods`) plus the matching `fooMutationKey` helper.
1757
1781
  */
1758
1782
  const mutationOperation = defineTemplate({
@@ -1827,7 +1851,7 @@ const mutationOperation = defineTemplate({
1827
1851
  });
1828
1852
  // src/templates/query.tsx
1829
1853
  /**
1830
- * Built-in template for `useQuery` composables. Emits one `useFooQuery`
1854
+ * Built-in template for `useQuery` composables. Emits one `useFoo`
1831
1855
  * composable per GET and QUERY operation (configurable via `query.methods`) plus the
1832
1856
  * matching `fooQueryKey` / `fooQueryOptions` helpers.
1833
1857
  */