@kubb/plugin-vue-query 5.13.1 → 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.cjs CHANGED
@@ -36,7 +36,7 @@ var compatibility = {
36
36
  "node": ">=22.22"
37
37
  };
38
38
  // package.json
39
- var version = "5.13.1";
39
+ var version = "5.13.3";
40
40
  // ../../internals/ast/src/http/requestBody.ts
41
41
  /** The schema of the first request body entry, else `undefined` when the operation takes no body. */
42
42
  function getSchema(node) {
@@ -82,15 +82,10 @@ function findPrimary(node) {
82
82
  }
83
83
  // ../../internals/ast/src/http/index.ts
84
84
  const isOperation = _kubb_ast.ast.http.isOperation;
85
- /** Computes once per key; generators visit the same node many times. */
86
- function cached(store, key, compute) {
87
- if (!store.has(key)) store.set(key, compute());
88
- return store.get(key);
89
- }
90
85
  const parametersByNode = /* @__PURE__ */ new WeakMap();
91
86
  /** The operation's parameters by location, with a `querystring` parameter in `query`. A repeated name keeps its first parameter. */
92
87
  function groupParameters(node) {
93
- return cached(parametersByNode, node, () => {
88
+ return (0, _kubb_kit.memo)(parametersByNode, node, () => {
94
89
  const group = (...locations) => {
95
90
  const seen = /* @__PURE__ */ new Set();
96
91
  return locations.flatMap((location) => node.parameters.filter((param) => {
@@ -110,7 +105,7 @@ function groupParameters(node) {
110
105
  const requestGroupsByNode = /* @__PURE__ */ new WeakMap();
111
106
  /** Which request groups are present, which hold a required member, and the body's media types. Built once per operation. */
112
107
  function getRequestGroups(node) {
113
- return cached(requestGroupsByNode, node, () => {
108
+ return (0, _kubb_kit.memo)(requestGroupsByNode, node, () => {
114
109
  const { path, query, header, cookie } = groupParameters(node);
115
110
  const content = node.requestBody?.content ?? [];
116
111
  const body = Boolean(content[0]?.schema);
@@ -303,6 +298,22 @@ function resolveContractClient(options) {
303
298
  return resolved;
304
299
  }
305
300
  // ../../internals/client/src/resolveClientOperation.ts
301
+ const consumerBindings = /* @__PURE__ */ new Set([
302
+ "path",
303
+ "query",
304
+ "body",
305
+ "headers",
306
+ "cookies",
307
+ "config",
308
+ "signal",
309
+ "variables",
310
+ "options",
311
+ "ctx",
312
+ "res",
313
+ "pageParam",
314
+ "queryKey",
315
+ "mutationKey"
316
+ ]);
306
317
  function isRelativeImport(importPath) {
307
318
  return importPath.startsWith(".");
308
319
  }
@@ -312,8 +323,8 @@ function resolveImportPath(options) {
312
323
  }
313
324
  /**
314
325
  * Resolves the contract client `<op>` a consumer (query hook, MCP handler) imports, from the registered contract client plugin
315
- * (plugin-fetch, plugin-axios, or plugin-client). Returns `null` when the client plugin's `exclude` / `include` leaves this
316
- * operation out, since it then emits no `<op>` to import. plugin-fetch / plugin-axios inject `.kubb/client.ts` at the global
326
+ * (plugin-fetch, plugin-axios, plugin-ky, or plugin-client). Returns `null` when the client plugin's `exclude` / `include` leaves this
327
+ * operation out, since it then emits no `<op>` to import. plugin-fetch, plugin-axios and plugin-ky inject `.kubb/client.ts` at the global
317
328
  * output root, the same path consumers read `RequestConfig` / `ResponseErrorConfig` from. With plugin-client they come from
318
329
  * the user's `importPath` module instead.
319
330
  *
@@ -335,14 +346,20 @@ function resolveClientOperation({ node, pluginName }) {
335
346
  override
336
347
  });
337
348
  if (!operationOptions) return null;
338
- const name = resolver.resolveName({
349
+ const importName = resolver.resolveName({
339
350
  key: (0, _kubb_kit.operationKey)(node),
340
351
  name: resolver.name(node.operationId)
341
352
  });
353
+ const name = consumerBindings.has(importName) ? `${importName}Request` : importName;
342
354
  const file = ctx.file(node, { plugin: pluginName });
343
355
  const { importPath } = operationOptions;
344
356
  return {
345
357
  name,
358
+ moduleName: {
359
+ name: importName,
360
+ alias: name === importName ? void 0 : name,
361
+ space: "value"
362
+ },
346
363
  path: file.path,
347
364
  clientPath: importPath === void 0 ? node_path.default.resolve(ctx.root, ".kubb/client.ts") : resolveImportPath({
348
365
  importPath,
@@ -368,7 +385,7 @@ function buildResponseHeadersType({ node, types }) {
368
385
  const entries = getResponseHeadersEntries({
369
386
  node,
370
387
  types
371
- }).map(([statusCode, name]) => `'${statusCode}': ${name}`);
388
+ }).map(([statusCode, name]) => `${_kubb_kit.text.quote(statusCode)}: ${name}`);
372
389
  return entries.length ? `{ ${entries.join("; ")} }` : null;
373
390
  }
374
391
  /**
@@ -581,7 +598,7 @@ function isIdentifier(name) {
581
598
  function getNestedAccessor(param, accessor) {
582
599
  const parts = Array.isArray(param) ? param : param.split(".");
583
600
  if (parts.length === 0 || parts.length === 1 && parts[0] === "") return null;
584
- return `${accessor}?.['${`${parts.join("']?.['")}']`}`;
601
+ return `${accessor}${parts.map((part) => `?.[${_kubb_kit.text.quote(part)}]`).join("")}`;
585
602
  }
586
603
  /**
587
604
  * Escapes an `@` at the start of a line, so a multi-line description can't start a new JSDoc tag.
@@ -705,8 +722,8 @@ function buildOperationComments(node, options = {}) {
705
722
  const { splitLines = false } = options;
706
723
  const filteredComments = [
707
724
  getOperationRequestLine(node),
708
- node.description && `@description ${node.description}`,
709
- node.summary && `@summary ${node.summary}`,
725
+ node.description && `@description ${jsDocEscape(node.description)}`,
726
+ node.summary && `@summary ${jsDocEscape(node.summary)}`,
710
727
  node.deprecated && "@deprecated",
711
728
  node.externalDocs && `@see ${jsDocEscape([node.externalDocs.url, node.externalDocs.description].filter(Boolean).join(" "))}`
712
729
  ].filter((comment) => Boolean(comment));
@@ -900,10 +917,7 @@ function HookFile({ hook, imports, children }) {
900
917
  ...file,
901
918
  children: [
902
919
  /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
903
- names: [{
904
- name: contractOp.name,
905
- space: "value"
906
- }],
920
+ names: [contractOp.moduleName],
907
921
  root: file.path,
908
922
  path: contractOp.path
909
923
  }),
@@ -1110,7 +1124,7 @@ function resolvePageParamType(node, { resolver, initialPageParam, queryParam })
1110
1124
  const firstQueryParam = groupParameters(node).query[0];
1111
1125
  const groupName = firstQueryParam ? resolver.param.query(node, firstQueryParam) : null;
1112
1126
  const queryParamsTypeName = groupName !== (firstQueryParam ? resolver.param.name(node, firstQueryParam) : null) ? groupName : null;
1113
- const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : null;
1127
+ const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}[${_kubb_kit.text.quote(queryParam)}]` : null;
1114
1128
  if (!queryParamType) return {
1115
1129
  queryParamsTypeName,
1116
1130
  pageParamType: resolveFallbackPageParamType(initialPageParam)
@@ -1317,7 +1331,7 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, hasExplicitI
1317
1331
  const getNextPageParamExpr = (() => {
1318
1332
  if (serializedGetNextPageParam) return `getNextPageParam: ${serializedGetNextPageParam}`;
1319
1333
  if (nextParam) return `getNextPageParam: (lastPage) => ${getNestedAccessor(nextParam, `lastPage${dataSuffix}`)}`;
1320
- if (cursorParam) return `getNextPageParam: (lastPage) => lastPage${dataSuffix}['${cursorParam}']`;
1334
+ if (cursorParam) return `getNextPageParam: (lastPage) => lastPage${dataSuffix}[${_kubb_kit.text.quote(cursorParam)}]`;
1321
1335
  return `getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage${dataSuffix}) && lastPage${dataSuffix}.length === 0 ? undefined : lastPageParam + 1`;
1322
1336
  })();
1323
1337
  const serializedGetPreviousPageParam = typeof getPreviousPageParam === "function" ? getPreviousPageParam.toString() : getPreviousPageParam;
@@ -1325,7 +1339,7 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, hasExplicitI
1325
1339
  const getPreviousPageParamExpr = (() => {
1326
1340
  if (serializedGetPreviousPageParam) return `getPreviousPageParam: ${serializedGetPreviousPageParam}`;
1327
1341
  if (previousParam) return `getPreviousPageParam: (firstPage) => ${getNestedAccessor(previousParam, `firstPage${dataSuffix}`)}`;
1328
- if (cursorParam) return `getPreviousPageParam: (firstPage) => firstPage${dataSuffix}['${cursorParam}']`;
1342
+ if (cursorParam) return `getPreviousPageParam: (firstPage) => firstPage${dataSuffix}[${_kubb_kit.text.quote(cursorParam)}]`;
1329
1343
  if (serializedGetNextPageParam || nextParam) return null;
1330
1344
  return `getPreviousPageParam: (_firstPage, _allPages, firstPageParam) => firstPageParam <= ${defaultPreviousThreshold} ? undefined : firstPageParam - 1`;
1331
1345
  })();
@@ -1364,7 +1378,7 @@ const declarationPrinter$4 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "decla
1364
1378
  */
1365
1379
  const mutationKeyTransformer = ({ node }) => {
1366
1380
  if (!node.path) return [];
1367
- return [`{ url: '${_kubb_kit.Url.toPath(node.path)}' }`];
1381
+ return [`{ url: ${_kubb_kit.text.quote(_kubb_kit.Url.toPath(node.path))} }`];
1368
1382
  };
1369
1383
  function MutationKey({ name, node, transformer, typeName }) {
1370
1384
  const paramsNode = (0, _kubb_plugin_ts.createFunctionParameters)({ params: [] });
@@ -1402,7 +1416,7 @@ const queryKeyTransformer = ({ node, variant }) => {
1402
1416
  if (!node.path) return [];
1403
1417
  const { path, query } = groupParameters(node);
1404
1418
  const isInfinite = variant === "infiniteQuery" || variant === "suspenseInfiniteQuery";
1405
- const urlFields = [`url: '${_kubb_kit.Url.toPath(node.path)}'`];
1419
+ const urlFields = [`url: ${_kubb_kit.text.quote(_kubb_kit.Url.toPath(node.path))}`];
1406
1420
  if (path.length > 0) urlFields.push("params: path");
1407
1421
  if (isInfinite) urlFields.push("infinite: true");
1408
1422
  const result = [`{ ${urlFields.join(", ")} }`];
@@ -1493,12 +1507,17 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, t
1493
1507
  `TQueryData = ${TData}`,
1494
1508
  `TQueryKey extends QueryKey = ${queryKeyTypeName}`
1495
1509
  ];
1496
- const optionsGenerics = infinite ? [
1497
- TData,
1498
- TError,
1510
+ const pageParamType = infinite ? resolvePageParamType(node, {
1511
+ resolver: tsResolver,
1512
+ initialPageParam: infinite.initialPageParam,
1513
+ queryParam: infinite.queryParam
1514
+ }).pageParamType : null;
1515
+ const optionsGenerics = pageParamType ? [
1499
1516
  "TQueryData",
1517
+ TError,
1518
+ "TData",
1500
1519
  "TQueryKey",
1501
- "TQueryData"
1520
+ pageParamType
1502
1521
  ] : [
1503
1522
  TData,
1504
1523
  TError,
@@ -1506,12 +1525,12 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, t
1506
1525
  "TQueryData",
1507
1526
  "TQueryKey"
1508
1527
  ];
1509
- const castGenerics = infinite ? [
1528
+ const castGenerics = pageParamType ? [
1510
1529
  TData,
1511
1530
  TError,
1512
- TData,
1531
+ "TData",
1513
1532
  "TQueryKey",
1514
- TData
1533
+ pageParamType
1515
1534
  ] : [
1516
1535
  TData,
1517
1536
  TError,
@@ -1573,7 +1592,7 @@ function matchesInfiniteQuery(node, ctx) {
1573
1592
  /**
1574
1593
  * Built-in template for `useInfiniteQuery` composables. Enabled when
1575
1594
  * `pluginVueQuery({ infinite: { ... }, hooks: true })`. Emits one
1576
- * `useFooInfiniteQuery` composable per query operation, wiring the
1595
+ * `useFooInfinite` composable per query operation, wiring the
1577
1596
  * configured cursor path into TanStack Query's cursor-based pagination.
1578
1597
  */
1579
1598
  const infiniteQueryOperation = (0, _kubb_kit.defineTemplate)({
@@ -1694,7 +1713,7 @@ const infiniteQueryOperation = (0, _kubb_kit.defineTemplate)({
1694
1713
  queryKeyTypeName,
1695
1714
  node,
1696
1715
  tsResolver,
1697
- infinite: true,
1716
+ infinite: infiniteOptions,
1698
1717
  returnType: hook.returnType,
1699
1718
  typedHeaders: hook.contractOp.typedHeaders
1700
1719
  })
@@ -1783,7 +1802,7 @@ function Mutation({ name, clientName, node, tsResolver, mutationKeyName, clientR
1783
1802
  // src/templates/mutation.tsx
1784
1803
  /**
1785
1804
  * Built-in template for `useMutation` composables. Emits one
1786
- * `useFooMutation` composable per POST/PUT/DELETE operation (configurable
1805
+ * `useFoo` composable per POST/PUT/DELETE operation (configurable
1787
1806
  * via `mutation.methods`) plus the matching `fooMutationKey` helper.
1788
1807
  */
1789
1808
  const mutationOperation = (0, _kubb_kit.defineTemplate)({
@@ -1858,7 +1877,7 @@ const mutationOperation = (0, _kubb_kit.defineTemplate)({
1858
1877
  });
1859
1878
  // src/templates/query.tsx
1860
1879
  /**
1861
- * Built-in template for `useQuery` composables. Emits one `useFooQuery`
1880
+ * Built-in template for `useQuery` composables. Emits one `useFoo`
1862
1881
  * composable per GET and QUERY operation (configurable via `query.methods`) plus the
1863
1882
  * matching `fooQueryKey` / `fooQueryOptions` helpers.
1864
1883
  */