@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.cjs +50 -26
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -4
- package/dist/index.d.ts +2 -4
- package/dist/index.js +50 -26
- package/dist/index.js.map +1 -1
- package/package.json +3 -14
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.
|
|
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) {
|
|
@@ -298,6 +298,22 @@ function resolveContractClient(options) {
|
|
|
298
298
|
return resolved;
|
|
299
299
|
}
|
|
300
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
|
+
]);
|
|
301
317
|
function isRelativeImport(importPath) {
|
|
302
318
|
return importPath.startsWith(".");
|
|
303
319
|
}
|
|
@@ -307,8 +323,8 @@ function resolveImportPath(options) {
|
|
|
307
323
|
}
|
|
308
324
|
/**
|
|
309
325
|
* Resolves the contract client `<op>` a consumer (query hook, MCP handler) imports, from the registered contract client plugin
|
|
310
|
-
* (plugin-fetch, plugin-axios, or plugin-client). Returns `null` when the client plugin's `exclude` / `include` leaves this
|
|
311
|
-
* operation out, since it then emits no `<op>` to import. plugin-fetch
|
|
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
|
|
312
328
|
* output root, the same path consumers read `RequestConfig` / `ResponseErrorConfig` from. With plugin-client they come from
|
|
313
329
|
* the user's `importPath` module instead.
|
|
314
330
|
*
|
|
@@ -330,14 +346,20 @@ function resolveClientOperation({ node, pluginName }) {
|
|
|
330
346
|
override
|
|
331
347
|
});
|
|
332
348
|
if (!operationOptions) return null;
|
|
333
|
-
const
|
|
349
|
+
const importName = resolver.resolveName({
|
|
334
350
|
key: (0, _kubb_kit.operationKey)(node),
|
|
335
351
|
name: resolver.name(node.operationId)
|
|
336
352
|
});
|
|
353
|
+
const name = consumerBindings.has(importName) ? `${importName}Request` : importName;
|
|
337
354
|
const file = ctx.file(node, { plugin: pluginName });
|
|
338
355
|
const { importPath } = operationOptions;
|
|
339
356
|
return {
|
|
340
357
|
name,
|
|
358
|
+
moduleName: {
|
|
359
|
+
name: importName,
|
|
360
|
+
alias: name === importName ? void 0 : name,
|
|
361
|
+
space: "value"
|
|
362
|
+
},
|
|
341
363
|
path: file.path,
|
|
342
364
|
clientPath: importPath === void 0 ? node_path.default.resolve(ctx.root, ".kubb/client.ts") : resolveImportPath({
|
|
343
365
|
importPath,
|
|
@@ -363,7 +385,7 @@ function buildResponseHeadersType({ node, types }) {
|
|
|
363
385
|
const entries = getResponseHeadersEntries({
|
|
364
386
|
node,
|
|
365
387
|
types
|
|
366
|
-
}).map(([statusCode, name]) =>
|
|
388
|
+
}).map(([statusCode, name]) => `${_kubb_kit.text.quote(statusCode)}: ${name}`);
|
|
367
389
|
return entries.length ? `{ ${entries.join("; ")} }` : null;
|
|
368
390
|
}
|
|
369
391
|
/**
|
|
@@ -576,7 +598,7 @@ function isIdentifier(name) {
|
|
|
576
598
|
function getNestedAccessor(param, accessor) {
|
|
577
599
|
const parts = Array.isArray(param) ? param : param.split(".");
|
|
578
600
|
if (parts.length === 0 || parts.length === 1 && parts[0] === "") return null;
|
|
579
|
-
return `${accessor}
|
|
601
|
+
return `${accessor}${parts.map((part) => `?.[${_kubb_kit.text.quote(part)}]`).join("")}`;
|
|
580
602
|
}
|
|
581
603
|
/**
|
|
582
604
|
* Escapes an `@` at the start of a line, so a multi-line description can't start a new JSDoc tag.
|
|
@@ -700,8 +722,8 @@ function buildOperationComments(node, options = {}) {
|
|
|
700
722
|
const { splitLines = false } = options;
|
|
701
723
|
const filteredComments = [
|
|
702
724
|
getOperationRequestLine(node),
|
|
703
|
-
node.description && `@description ${node.description}`,
|
|
704
|
-
node.summary && `@summary ${node.summary}`,
|
|
725
|
+
node.description && `@description ${jsDocEscape(node.description)}`,
|
|
726
|
+
node.summary && `@summary ${jsDocEscape(node.summary)}`,
|
|
705
727
|
node.deprecated && "@deprecated",
|
|
706
728
|
node.externalDocs && `@see ${jsDocEscape([node.externalDocs.url, node.externalDocs.description].filter(Boolean).join(" "))}`
|
|
707
729
|
].filter((comment) => Boolean(comment));
|
|
@@ -895,10 +917,7 @@ function HookFile({ hook, imports, children }) {
|
|
|
895
917
|
...file,
|
|
896
918
|
children: [
|
|
897
919
|
/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
|
|
898
|
-
names: [
|
|
899
|
-
name: contractOp.name,
|
|
900
|
-
space: "value"
|
|
901
|
-
}],
|
|
920
|
+
names: [contractOp.moduleName],
|
|
902
921
|
root: file.path,
|
|
903
922
|
path: contractOp.path
|
|
904
923
|
}),
|
|
@@ -1105,7 +1124,7 @@ function resolvePageParamType(node, { resolver, initialPageParam, queryParam })
|
|
|
1105
1124
|
const firstQueryParam = groupParameters(node).query[0];
|
|
1106
1125
|
const groupName = firstQueryParam ? resolver.param.query(node, firstQueryParam) : null;
|
|
1107
1126
|
const queryParamsTypeName = groupName !== (firstQueryParam ? resolver.param.name(node, firstQueryParam) : null) ? groupName : null;
|
|
1108
|
-
const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}[
|
|
1127
|
+
const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}[${_kubb_kit.text.quote(queryParam)}]` : null;
|
|
1109
1128
|
if (!queryParamType) return {
|
|
1110
1129
|
queryParamsTypeName,
|
|
1111
1130
|
pageParamType: resolveFallbackPageParamType(initialPageParam)
|
|
@@ -1312,7 +1331,7 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, hasExplicitI
|
|
|
1312
1331
|
const getNextPageParamExpr = (() => {
|
|
1313
1332
|
if (serializedGetNextPageParam) return `getNextPageParam: ${serializedGetNextPageParam}`;
|
|
1314
1333
|
if (nextParam) return `getNextPageParam: (lastPage) => ${getNestedAccessor(nextParam, `lastPage${dataSuffix}`)}`;
|
|
1315
|
-
if (cursorParam) return `getNextPageParam: (lastPage) => lastPage${dataSuffix}[
|
|
1334
|
+
if (cursorParam) return `getNextPageParam: (lastPage) => lastPage${dataSuffix}[${_kubb_kit.text.quote(cursorParam)}]`;
|
|
1316
1335
|
return `getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage${dataSuffix}) && lastPage${dataSuffix}.length === 0 ? undefined : lastPageParam + 1`;
|
|
1317
1336
|
})();
|
|
1318
1337
|
const serializedGetPreviousPageParam = typeof getPreviousPageParam === "function" ? getPreviousPageParam.toString() : getPreviousPageParam;
|
|
@@ -1320,7 +1339,7 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, hasExplicitI
|
|
|
1320
1339
|
const getPreviousPageParamExpr = (() => {
|
|
1321
1340
|
if (serializedGetPreviousPageParam) return `getPreviousPageParam: ${serializedGetPreviousPageParam}`;
|
|
1322
1341
|
if (previousParam) return `getPreviousPageParam: (firstPage) => ${getNestedAccessor(previousParam, `firstPage${dataSuffix}`)}`;
|
|
1323
|
-
if (cursorParam) return `getPreviousPageParam: (firstPage) => firstPage${dataSuffix}[
|
|
1342
|
+
if (cursorParam) return `getPreviousPageParam: (firstPage) => firstPage${dataSuffix}[${_kubb_kit.text.quote(cursorParam)}]`;
|
|
1324
1343
|
if (serializedGetNextPageParam || nextParam) return null;
|
|
1325
1344
|
return `getPreviousPageParam: (_firstPage, _allPages, firstPageParam) => firstPageParam <= ${defaultPreviousThreshold} ? undefined : firstPageParam - 1`;
|
|
1326
1345
|
})();
|
|
@@ -1488,12 +1507,17 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, t
|
|
|
1488
1507
|
`TQueryData = ${TData}`,
|
|
1489
1508
|
`TQueryKey extends QueryKey = ${queryKeyTypeName}`
|
|
1490
1509
|
];
|
|
1491
|
-
const
|
|
1492
|
-
|
|
1493
|
-
|
|
1510
|
+
const pageParamType = infinite ? resolvePageParamType(node, {
|
|
1511
|
+
resolver: tsResolver,
|
|
1512
|
+
initialPageParam: infinite.initialPageParam,
|
|
1513
|
+
queryParam: infinite.queryParam
|
|
1514
|
+
}).pageParamType : null;
|
|
1515
|
+
const optionsGenerics = pageParamType ? [
|
|
1494
1516
|
"TQueryData",
|
|
1517
|
+
TError,
|
|
1518
|
+
"TData",
|
|
1495
1519
|
"TQueryKey",
|
|
1496
|
-
|
|
1520
|
+
pageParamType
|
|
1497
1521
|
] : [
|
|
1498
1522
|
TData,
|
|
1499
1523
|
TError,
|
|
@@ -1501,12 +1525,12 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, t
|
|
|
1501
1525
|
"TQueryData",
|
|
1502
1526
|
"TQueryKey"
|
|
1503
1527
|
];
|
|
1504
|
-
const castGenerics =
|
|
1528
|
+
const castGenerics = pageParamType ? [
|
|
1505
1529
|
TData,
|
|
1506
1530
|
TError,
|
|
1507
|
-
TData,
|
|
1531
|
+
"TData",
|
|
1508
1532
|
"TQueryKey",
|
|
1509
|
-
|
|
1533
|
+
pageParamType
|
|
1510
1534
|
] : [
|
|
1511
1535
|
TData,
|
|
1512
1536
|
TError,
|
|
@@ -1568,7 +1592,7 @@ function matchesInfiniteQuery(node, ctx) {
|
|
|
1568
1592
|
/**
|
|
1569
1593
|
* Built-in template for `useInfiniteQuery` composables. Enabled when
|
|
1570
1594
|
* `pluginVueQuery({ infinite: { ... }, hooks: true })`. Emits one
|
|
1571
|
-
* `
|
|
1595
|
+
* `useFooInfinite` composable per query operation, wiring the
|
|
1572
1596
|
* configured cursor path into TanStack Query's cursor-based pagination.
|
|
1573
1597
|
*/
|
|
1574
1598
|
const infiniteQueryOperation = (0, _kubb_kit.defineTemplate)({
|
|
@@ -1689,7 +1713,7 @@ const infiniteQueryOperation = (0, _kubb_kit.defineTemplate)({
|
|
|
1689
1713
|
queryKeyTypeName,
|
|
1690
1714
|
node,
|
|
1691
1715
|
tsResolver,
|
|
1692
|
-
infinite:
|
|
1716
|
+
infinite: infiniteOptions,
|
|
1693
1717
|
returnType: hook.returnType,
|
|
1694
1718
|
typedHeaders: hook.contractOp.typedHeaders
|
|
1695
1719
|
})
|
|
@@ -1778,7 +1802,7 @@ function Mutation({ name, clientName, node, tsResolver, mutationKeyName, clientR
|
|
|
1778
1802
|
// src/templates/mutation.tsx
|
|
1779
1803
|
/**
|
|
1780
1804
|
* Built-in template for `useMutation` composables. Emits one
|
|
1781
|
-
* `
|
|
1805
|
+
* `useFoo` composable per POST/PUT/DELETE operation (configurable
|
|
1782
1806
|
* via `mutation.methods`) plus the matching `fooMutationKey` helper.
|
|
1783
1807
|
*/
|
|
1784
1808
|
const mutationOperation = (0, _kubb_kit.defineTemplate)({
|
|
@@ -1853,7 +1877,7 @@ const mutationOperation = (0, _kubb_kit.defineTemplate)({
|
|
|
1853
1877
|
});
|
|
1854
1878
|
// src/templates/query.tsx
|
|
1855
1879
|
/**
|
|
1856
|
-
* Built-in template for `useQuery` composables. Emits one `
|
|
1880
|
+
* Built-in template for `useQuery` composables. Emits one `useFoo`
|
|
1857
1881
|
* composable per GET and QUERY operation (configurable via `query.methods`) plus the
|
|
1858
1882
|
* matching `fooQueryKey` / `fooQueryOptions` helpers.
|
|
1859
1883
|
*/
|