@kubb/plugin-react-query 5.2.0-canary.20261007T095624 → 5.3.0-canary.20261008T204013
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 +23 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +12 -1
- package/dist/index.js +23 -16
- package/dist/index.js.map +1 -1
- package/package.json +9 -9
package/dist/index.d.ts
CHANGED
|
@@ -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
|
|
@@ -287,7 +297,8 @@ type ResolverReactQuery = Resolver & {
|
|
|
287
297
|
};
|
|
288
298
|
type Suspense = object;
|
|
289
299
|
/**
|
|
290
|
-
* Builds the `queryKey` used by each generated query hook.
|
|
300
|
+
* Builds the `queryKey` used by each generated query hook. `variant` tells which hook the key is for,
|
|
301
|
+
* so infinite keys can stay apart from plain ones.
|
|
291
302
|
*
|
|
292
303
|
* @note String values are inlined verbatim into generated code. Wrap literal
|
|
293
304
|
* strings in `JSON.stringify(...)`.
|
package/dist/index.js
CHANGED
|
@@ -807,7 +807,8 @@ function MutationKey({ name, node, transformer }) {
|
|
|
807
807
|
const paramsSignature = declarationPrinter$6.print(paramsNode) ?? "";
|
|
808
808
|
const keys = (transformer ?? mutationKeyTransformer)({
|
|
809
809
|
node,
|
|
810
|
-
casing: "camelcase"
|
|
810
|
+
casing: "camelcase",
|
|
811
|
+
variant: "mutation"
|
|
811
812
|
});
|
|
812
813
|
return /* @__PURE__ */ jsx(File.Source, {
|
|
813
814
|
name,
|
|
@@ -878,23 +879,25 @@ function createMutationResolver() {
|
|
|
878
879
|
//#endregion
|
|
879
880
|
//#region ../../internals/tanstack-query/src/components/QueryKey.tsx
|
|
880
881
|
const declarationPrinter$5 = functionPrinter({ mode: "declaration" });
|
|
881
|
-
const queryKeyTransformer = ({ node }) => {
|
|
882
|
+
const queryKeyTransformer = ({ node, variant }) => {
|
|
882
883
|
if (!node.path) return [];
|
|
883
|
-
const
|
|
884
|
-
const
|
|
885
|
-
const
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
].
|
|
884
|
+
const { path, query } = getOperationParameters(node);
|
|
885
|
+
const isInfinite = variant === "infiniteQuery" || variant === "suspenseInfiniteQuery";
|
|
886
|
+
const urlFields = [`url: '${Url.toPath(node.path)}'`];
|
|
887
|
+
if (path.length > 0) urlFields.push("params: path");
|
|
888
|
+
if (isInfinite) urlFields.push("infinite: true");
|
|
889
|
+
const result = [`{ ${urlFields.join(", ")} }`];
|
|
890
|
+
if (query.length > 0) result.push("...(query ? [query] : [])");
|
|
891
|
+
if (node.requestBody?.content?.[0]?.schema) result.push("...(body ? [body] : [])");
|
|
892
|
+
return result;
|
|
891
893
|
};
|
|
892
|
-
function QueryKey({ name, node, tsResolver, typeName, transformer }) {
|
|
894
|
+
function QueryKey({ name, node, tsResolver, typeName, transformer, variant = "query" }) {
|
|
893
895
|
const paramsNode = buildQueryKeyParams(node, { resolver: tsResolver });
|
|
894
896
|
const paramsSignature = declarationPrinter$5.print(paramsNode) ?? "";
|
|
895
897
|
const keys = (transformer ?? queryKeyTransformer)({
|
|
896
898
|
node,
|
|
897
|
-
casing: "camelcase"
|
|
899
|
+
casing: "camelcase",
|
|
900
|
+
variant
|
|
898
901
|
});
|
|
899
902
|
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(File.Source, {
|
|
900
903
|
name,
|
|
@@ -1616,7 +1619,8 @@ const infiniteQueryGenerator = defineGenerator({
|
|
|
1616
1619
|
typeName: queryKeyTypeName,
|
|
1617
1620
|
node,
|
|
1618
1621
|
tsResolver,
|
|
1619
|
-
transformer: ctx.options.queryKey
|
|
1622
|
+
transformer: ctx.options.queryKey,
|
|
1623
|
+
variant: "infiniteQuery"
|
|
1620
1624
|
}),
|
|
1621
1625
|
/* @__PURE__ */ jsx(File.Import, {
|
|
1622
1626
|
name: ["InfiniteData"],
|
|
@@ -1927,7 +1931,8 @@ const queryGenerator = defineGenerator({
|
|
|
1927
1931
|
typeName: queryKeyTypeName,
|
|
1928
1932
|
node,
|
|
1929
1933
|
tsResolver,
|
|
1930
|
-
transformer: ctx.options.queryKey
|
|
1934
|
+
transformer: ctx.options.queryKey,
|
|
1935
|
+
variant: "query"
|
|
1931
1936
|
}),
|
|
1932
1937
|
/* @__PURE__ */ jsx(File.Import, {
|
|
1933
1938
|
name: ["queryOptions"],
|
|
@@ -2091,7 +2096,8 @@ const suspenseInfiniteQueryGenerator = defineGenerator({
|
|
|
2091
2096
|
typeName: queryKeyTypeName,
|
|
2092
2097
|
node,
|
|
2093
2098
|
tsResolver,
|
|
2094
|
-
transformer: ctx.options.queryKey
|
|
2099
|
+
transformer: ctx.options.queryKey,
|
|
2100
|
+
variant: "suspenseInfiniteQuery"
|
|
2095
2101
|
}),
|
|
2096
2102
|
/* @__PURE__ */ jsx(File.Import, {
|
|
2097
2103
|
name: ["InfiniteData"],
|
|
@@ -2257,7 +2263,8 @@ const suspenseQueryGenerator = defineGenerator({
|
|
|
2257
2263
|
typeName: queryKeyTypeName,
|
|
2258
2264
|
node,
|
|
2259
2265
|
tsResolver,
|
|
2260
|
-
transformer: ctx.options.queryKey
|
|
2266
|
+
transformer: ctx.options.queryKey,
|
|
2267
|
+
variant: "suspenseQuery"
|
|
2261
2268
|
}),
|
|
2262
2269
|
/* @__PURE__ */ jsx(File.Import, {
|
|
2263
2270
|
name: ["queryOptions"],
|