@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 +54 -35
- 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 +55 -36
- package/dist/index.js.map +1 -1
- package/package.json +3 -14
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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
|
|
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 {
|
|
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
|
|
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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Diagnostics, Resolver, Url, addMacro, addTemplate, casing, code, createResolver, defineExtension, defineTemplate, operationKey, setResolver, useConfig, useKubb } from "@kubb/kit";
|
|
1
|
+
import { Diagnostics, Resolver, Url, addMacro, addTemplate, casing, code, createResolver, defineExtension, defineTemplate, memo, operationKey, setResolver, text, useConfig, useKubb } from "@kubb/kit";
|
|
2
2
|
import { createFunctionParameter, createFunctionParameters, createObjectBindingPattern, createTypeLiteral, functionPrinter, pluginTsName } from "@kubb/plugin-ts";
|
|
3
3
|
import { ast, file as file$1, node, ref } from "@kubb/ast";
|
|
4
4
|
import path from "node:path";
|
|
@@ -10,7 +10,7 @@ var compatibility = {
|
|
|
10
10
|
"node": ">=22.22"
|
|
11
11
|
};
|
|
12
12
|
// package.json
|
|
13
|
-
var version = "5.13.
|
|
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) {
|
|
@@ -56,15 +56,10 @@ function findPrimary(node) {
|
|
|
56
56
|
}
|
|
57
57
|
// ../../internals/ast/src/http/index.ts
|
|
58
58
|
const isOperation = ast.http.isOperation;
|
|
59
|
-
/** Computes once per key; generators visit the same node many times. */
|
|
60
|
-
function cached(store, key, compute) {
|
|
61
|
-
if (!store.has(key)) store.set(key, compute());
|
|
62
|
-
return store.get(key);
|
|
63
|
-
}
|
|
64
59
|
const parametersByNode = /* @__PURE__ */ new WeakMap();
|
|
65
60
|
/** The operation's parameters by location, with a `querystring` parameter in `query`. A repeated name keeps its first parameter. */
|
|
66
61
|
function groupParameters(node) {
|
|
67
|
-
return
|
|
62
|
+
return memo(parametersByNode, node, () => {
|
|
68
63
|
const group = (...locations) => {
|
|
69
64
|
const seen = /* @__PURE__ */ new Set();
|
|
70
65
|
return locations.flatMap((location) => node.parameters.filter((param) => {
|
|
@@ -84,7 +79,7 @@ function groupParameters(node) {
|
|
|
84
79
|
const requestGroupsByNode = /* @__PURE__ */ new WeakMap();
|
|
85
80
|
/** Which request groups are present, which hold a required member, and the body's media types. Built once per operation. */
|
|
86
81
|
function getRequestGroups(node) {
|
|
87
|
-
return
|
|
82
|
+
return memo(requestGroupsByNode, node, () => {
|
|
88
83
|
const { path, query, header, cookie } = groupParameters(node);
|
|
89
84
|
const content = node.requestBody?.content ?? [];
|
|
90
85
|
const body = Boolean(content[0]?.schema);
|
|
@@ -277,6 +272,22 @@ function resolveContractClient(options) {
|
|
|
277
272
|
return resolved;
|
|
278
273
|
}
|
|
279
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
|
+
]);
|
|
280
291
|
function isRelativeImport(importPath) {
|
|
281
292
|
return importPath.startsWith(".");
|
|
282
293
|
}
|
|
@@ -286,8 +297,8 @@ function resolveImportPath(options) {
|
|
|
286
297
|
}
|
|
287
298
|
/**
|
|
288
299
|
* Resolves the contract client `<op>` a consumer (query hook, MCP handler) imports, from the registered contract client plugin
|
|
289
|
-
* (plugin-fetch, plugin-axios, or plugin-client). Returns `null` when the client plugin's `exclude` / `include` leaves this
|
|
290
|
-
* operation out, since it then emits no `<op>` to import. plugin-fetch
|
|
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
|
|
291
302
|
* output root, the same path consumers read `RequestConfig` / `ResponseErrorConfig` from. With plugin-client they come from
|
|
292
303
|
* the user's `importPath` module instead.
|
|
293
304
|
*
|
|
@@ -309,14 +320,20 @@ function resolveClientOperation({ node, pluginName }) {
|
|
|
309
320
|
override
|
|
310
321
|
});
|
|
311
322
|
if (!operationOptions) return null;
|
|
312
|
-
const
|
|
323
|
+
const importName = resolver.resolveName({
|
|
313
324
|
key: operationKey(node),
|
|
314
325
|
name: resolver.name(node.operationId)
|
|
315
326
|
});
|
|
327
|
+
const name = consumerBindings.has(importName) ? `${importName}Request` : importName;
|
|
316
328
|
const file = ctx.file(node, { plugin: pluginName });
|
|
317
329
|
const { importPath } = operationOptions;
|
|
318
330
|
return {
|
|
319
331
|
name,
|
|
332
|
+
moduleName: {
|
|
333
|
+
name: importName,
|
|
334
|
+
alias: name === importName ? void 0 : name,
|
|
335
|
+
space: "value"
|
|
336
|
+
},
|
|
320
337
|
path: file.path,
|
|
321
338
|
clientPath: importPath === void 0 ? path.resolve(ctx.root, ".kubb/client.ts") : resolveImportPath({
|
|
322
339
|
importPath,
|
|
@@ -342,7 +359,7 @@ function buildResponseHeadersType({ node, types }) {
|
|
|
342
359
|
const entries = getResponseHeadersEntries({
|
|
343
360
|
node,
|
|
344
361
|
types
|
|
345
|
-
}).map(([statusCode, name]) =>
|
|
362
|
+
}).map(([statusCode, name]) => `${text.quote(statusCode)}: ${name}`);
|
|
346
363
|
return entries.length ? `{ ${entries.join("; ")} }` : null;
|
|
347
364
|
}
|
|
348
365
|
/**
|
|
@@ -555,7 +572,7 @@ function isIdentifier(name) {
|
|
|
555
572
|
function getNestedAccessor(param, accessor) {
|
|
556
573
|
const parts = Array.isArray(param) ? param : param.split(".");
|
|
557
574
|
if (parts.length === 0 || parts.length === 1 && parts[0] === "") return null;
|
|
558
|
-
return `${accessor}
|
|
575
|
+
return `${accessor}${parts.map((part) => `?.[${text.quote(part)}]`).join("")}`;
|
|
559
576
|
}
|
|
560
577
|
/**
|
|
561
578
|
* Escapes an `@` at the start of a line, so a multi-line description can't start a new JSDoc tag.
|
|
@@ -679,8 +696,8 @@ function buildOperationComments(node, options = {}) {
|
|
|
679
696
|
const { splitLines = false } = options;
|
|
680
697
|
const filteredComments = [
|
|
681
698
|
getOperationRequestLine(node),
|
|
682
|
-
node.description && `@description ${node.description}`,
|
|
683
|
-
node.summary && `@summary ${node.summary}`,
|
|
699
|
+
node.description && `@description ${jsDocEscape(node.description)}`,
|
|
700
|
+
node.summary && `@summary ${jsDocEscape(node.summary)}`,
|
|
684
701
|
node.deprecated && "@deprecated",
|
|
685
702
|
node.externalDocs && `@see ${jsDocEscape([node.externalDocs.url, node.externalDocs.description].filter(Boolean).join(" "))}`
|
|
686
703
|
].filter((comment) => Boolean(comment));
|
|
@@ -874,10 +891,7 @@ function HookFile({ hook, imports, children }) {
|
|
|
874
891
|
...file,
|
|
875
892
|
children: [
|
|
876
893
|
/* @__PURE__ */ jsx(File.Import, {
|
|
877
|
-
names: [
|
|
878
|
-
name: contractOp.name,
|
|
879
|
-
space: "value"
|
|
880
|
-
}],
|
|
894
|
+
names: [contractOp.moduleName],
|
|
881
895
|
root: file.path,
|
|
882
896
|
path: contractOp.path
|
|
883
897
|
}),
|
|
@@ -1084,7 +1098,7 @@ function resolvePageParamType(node, { resolver, initialPageParam, queryParam })
|
|
|
1084
1098
|
const firstQueryParam = groupParameters(node).query[0];
|
|
1085
1099
|
const groupName = firstQueryParam ? resolver.param.query(node, firstQueryParam) : null;
|
|
1086
1100
|
const queryParamsTypeName = groupName !== (firstQueryParam ? resolver.param.name(node, firstQueryParam) : null) ? groupName : null;
|
|
1087
|
-
const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}[
|
|
1101
|
+
const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}[${text.quote(queryParam)}]` : null;
|
|
1088
1102
|
if (!queryParamType) return {
|
|
1089
1103
|
queryParamsTypeName,
|
|
1090
1104
|
pageParamType: resolveFallbackPageParamType(initialPageParam)
|
|
@@ -1291,7 +1305,7 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, hasExplicitI
|
|
|
1291
1305
|
const getNextPageParamExpr = (() => {
|
|
1292
1306
|
if (serializedGetNextPageParam) return `getNextPageParam: ${serializedGetNextPageParam}`;
|
|
1293
1307
|
if (nextParam) return `getNextPageParam: (lastPage) => ${getNestedAccessor(nextParam, `lastPage${dataSuffix}`)}`;
|
|
1294
|
-
if (cursorParam) return `getNextPageParam: (lastPage) => lastPage${dataSuffix}[
|
|
1308
|
+
if (cursorParam) return `getNextPageParam: (lastPage) => lastPage${dataSuffix}[${text.quote(cursorParam)}]`;
|
|
1295
1309
|
return `getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage${dataSuffix}) && lastPage${dataSuffix}.length === 0 ? undefined : lastPageParam + 1`;
|
|
1296
1310
|
})();
|
|
1297
1311
|
const serializedGetPreviousPageParam = typeof getPreviousPageParam === "function" ? getPreviousPageParam.toString() : getPreviousPageParam;
|
|
@@ -1299,7 +1313,7 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, hasExplicitI
|
|
|
1299
1313
|
const getPreviousPageParamExpr = (() => {
|
|
1300
1314
|
if (serializedGetPreviousPageParam) return `getPreviousPageParam: ${serializedGetPreviousPageParam}`;
|
|
1301
1315
|
if (previousParam) return `getPreviousPageParam: (firstPage) => ${getNestedAccessor(previousParam, `firstPage${dataSuffix}`)}`;
|
|
1302
|
-
if (cursorParam) return `getPreviousPageParam: (firstPage) => firstPage${dataSuffix}[
|
|
1316
|
+
if (cursorParam) return `getPreviousPageParam: (firstPage) => firstPage${dataSuffix}[${text.quote(cursorParam)}]`;
|
|
1303
1317
|
if (serializedGetNextPageParam || nextParam) return null;
|
|
1304
1318
|
return `getPreviousPageParam: (_firstPage, _allPages, firstPageParam) => firstPageParam <= ${defaultPreviousThreshold} ? undefined : firstPageParam - 1`;
|
|
1305
1319
|
})();
|
|
@@ -1338,7 +1352,7 @@ const declarationPrinter$4 = functionPrinter({ mode: "declaration" });
|
|
|
1338
1352
|
*/
|
|
1339
1353
|
const mutationKeyTransformer = ({ node }) => {
|
|
1340
1354
|
if (!node.path) return [];
|
|
1341
|
-
return [`{ url:
|
|
1355
|
+
return [`{ url: ${text.quote(Url.toPath(node.path))} }`];
|
|
1342
1356
|
};
|
|
1343
1357
|
function MutationKey({ name, node, transformer, typeName }) {
|
|
1344
1358
|
const paramsNode = createFunctionParameters({ params: [] });
|
|
@@ -1376,7 +1390,7 @@ const queryKeyTransformer = ({ node, variant }) => {
|
|
|
1376
1390
|
if (!node.path) return [];
|
|
1377
1391
|
const { path, query } = groupParameters(node);
|
|
1378
1392
|
const isInfinite = variant === "infiniteQuery" || variant === "suspenseInfiniteQuery";
|
|
1379
|
-
const urlFields = [`url:
|
|
1393
|
+
const urlFields = [`url: ${text.quote(Url.toPath(node.path))}`];
|
|
1380
1394
|
if (path.length > 0) urlFields.push("params: path");
|
|
1381
1395
|
if (isInfinite) urlFields.push("infinite: true");
|
|
1382
1396
|
const result = [`{ ${urlFields.join(", ")} }`];
|
|
@@ -1467,12 +1481,17 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, t
|
|
|
1467
1481
|
`TQueryData = ${TData}`,
|
|
1468
1482
|
`TQueryKey extends QueryKey = ${queryKeyTypeName}`
|
|
1469
1483
|
];
|
|
1470
|
-
const
|
|
1471
|
-
|
|
1472
|
-
|
|
1484
|
+
const pageParamType = infinite ? resolvePageParamType(node, {
|
|
1485
|
+
resolver: tsResolver,
|
|
1486
|
+
initialPageParam: infinite.initialPageParam,
|
|
1487
|
+
queryParam: infinite.queryParam
|
|
1488
|
+
}).pageParamType : null;
|
|
1489
|
+
const optionsGenerics = pageParamType ? [
|
|
1473
1490
|
"TQueryData",
|
|
1491
|
+
TError,
|
|
1492
|
+
"TData",
|
|
1474
1493
|
"TQueryKey",
|
|
1475
|
-
|
|
1494
|
+
pageParamType
|
|
1476
1495
|
] : [
|
|
1477
1496
|
TData,
|
|
1478
1497
|
TError,
|
|
@@ -1480,12 +1499,12 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, t
|
|
|
1480
1499
|
"TQueryData",
|
|
1481
1500
|
"TQueryKey"
|
|
1482
1501
|
];
|
|
1483
|
-
const castGenerics =
|
|
1502
|
+
const castGenerics = pageParamType ? [
|
|
1484
1503
|
TData,
|
|
1485
1504
|
TError,
|
|
1486
|
-
TData,
|
|
1505
|
+
"TData",
|
|
1487
1506
|
"TQueryKey",
|
|
1488
|
-
|
|
1507
|
+
pageParamType
|
|
1489
1508
|
] : [
|
|
1490
1509
|
TData,
|
|
1491
1510
|
TError,
|
|
@@ -1547,7 +1566,7 @@ function matchesInfiniteQuery(node, ctx) {
|
|
|
1547
1566
|
/**
|
|
1548
1567
|
* Built-in template for `useInfiniteQuery` composables. Enabled when
|
|
1549
1568
|
* `pluginVueQuery({ infinite: { ... }, hooks: true })`. Emits one
|
|
1550
|
-
* `
|
|
1569
|
+
* `useFooInfinite` composable per query operation, wiring the
|
|
1551
1570
|
* configured cursor path into TanStack Query's cursor-based pagination.
|
|
1552
1571
|
*/
|
|
1553
1572
|
const infiniteQueryOperation = defineTemplate({
|
|
@@ -1668,7 +1687,7 @@ const infiniteQueryOperation = defineTemplate({
|
|
|
1668
1687
|
queryKeyTypeName,
|
|
1669
1688
|
node,
|
|
1670
1689
|
tsResolver,
|
|
1671
|
-
infinite:
|
|
1690
|
+
infinite: infiniteOptions,
|
|
1672
1691
|
returnType: hook.returnType,
|
|
1673
1692
|
typedHeaders: hook.contractOp.typedHeaders
|
|
1674
1693
|
})
|
|
@@ -1757,7 +1776,7 @@ function Mutation({ name, clientName, node, tsResolver, mutationKeyName, clientR
|
|
|
1757
1776
|
// src/templates/mutation.tsx
|
|
1758
1777
|
/**
|
|
1759
1778
|
* Built-in template for `useMutation` composables. Emits one
|
|
1760
|
-
* `
|
|
1779
|
+
* `useFoo` composable per POST/PUT/DELETE operation (configurable
|
|
1761
1780
|
* via `mutation.methods`) plus the matching `fooMutationKey` helper.
|
|
1762
1781
|
*/
|
|
1763
1782
|
const mutationOperation = defineTemplate({
|
|
@@ -1832,7 +1851,7 @@ const mutationOperation = defineTemplate({
|
|
|
1832
1851
|
});
|
|
1833
1852
|
// src/templates/query.tsx
|
|
1834
1853
|
/**
|
|
1835
|
-
* Built-in template for `useQuery` composables. Emits one `
|
|
1854
|
+
* Built-in template for `useQuery` composables. Emits one `useFoo`
|
|
1836
1855
|
* composable per GET and QUERY operation (configurable via `query.methods`) plus the
|
|
1837
1856
|
* matching `fooQueryKey` / `fooQueryOptions` helpers.
|
|
1838
1857
|
*/
|