@kubb/plugin-react-query 5.6.0-canary.20261014T145134 → 5.6.0-canary.20261015T094516
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 +498 -956
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.js +498 -956
- package/dist/index.js.map +1 -1
- package/package.json +9 -9
package/dist/index.cjs
CHANGED
|
@@ -27,29 +27,11 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
27
27
|
let kubb_kit = require("kubb/kit");
|
|
28
28
|
let node_path = require("node:path");
|
|
29
29
|
node_path = __toESM(node_path, 1);
|
|
30
|
-
let _kubb_plugin_ts = require("@kubb/plugin-ts");
|
|
31
30
|
let kubb_jsx = require("kubb/jsx");
|
|
31
|
+
let _kubb_plugin_ts = require("@kubb/plugin-ts");
|
|
32
32
|
let kubb_jsx_jsx_runtime = require("kubb/jsx/jsx-runtime");
|
|
33
33
|
let node_fs = require("node:fs");
|
|
34
34
|
node_fs = __toESM(node_fs, 1);
|
|
35
|
-
//#region ../../internals/shared/src/params.ts
|
|
36
|
-
/**
|
|
37
|
-
* Drops parameters that share the same name, keeping the first.
|
|
38
|
-
*
|
|
39
|
-
* A malformed spec can declare the same parameter name twice within one `in` location. Both would
|
|
40
|
-
* resolve to the same output property, so emitting both would yield an object type with a duplicate
|
|
41
|
-
* member, which TypeScript rejects. This is a defensive guard against that case, not a casing guard:
|
|
42
|
-
* parameter names flow through unchanged, so no two distinct names ever collide here anymore.
|
|
43
|
-
*/
|
|
44
|
-
function dedupeParams(params) {
|
|
45
|
-
const seen = /* @__PURE__ */ new Set();
|
|
46
|
-
return params.filter((param) => {
|
|
47
|
-
if (seen.has(param.name)) return false;
|
|
48
|
-
seen.add(param.name);
|
|
49
|
-
return true;
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
//#endregion
|
|
53
35
|
//#region ../../internals/shared/src/operation.ts
|
|
54
36
|
/**
|
|
55
37
|
* Builds the `ResolverFileParams` every operation generator passes to
|
|
@@ -119,12 +101,12 @@ function getContentTypeInfo(node) {
|
|
|
119
101
|
function getResponseContentTypeInfo(node) {
|
|
120
102
|
return buildContentTypeInfo(getPrimarySuccessResponse(node)?.content?.map((e) => e.contentType) ?? []);
|
|
121
103
|
}
|
|
104
|
+
const requestConfigBaseType = `Partial<Omit<RequestConfig, 'path' | 'query' | 'body' | 'headers' | 'url'>>`;
|
|
122
105
|
function buildRequestConfigType(node) {
|
|
123
106
|
const request = getContentTypeInfo(node);
|
|
124
107
|
const response = getResponseContentTypeInfo(node);
|
|
125
|
-
const configType = `Partial<Omit<RequestConfig, 'path' | 'query' | 'body' | 'headers' | 'url'>>`;
|
|
126
108
|
const members = [request.isMultipleContentTypes ? `request?: ${request.contentTypeUnion}` : null, response.isMultipleContentTypes ? `response?: ${response.contentTypeUnion}` : null].filter(Boolean);
|
|
127
|
-
return members.length ? `${
|
|
109
|
+
return members.length ? `${requestConfigBaseType} & { contentType?: { ${members.join("; ")} } }` : requestConfigBaseType;
|
|
128
110
|
}
|
|
129
111
|
/**
|
|
130
112
|
* Builds the `client?:` option type shared by the generated query hooks (`useQuery`,
|
|
@@ -133,7 +115,7 @@ function buildRequestConfigType(node) {
|
|
|
133
115
|
* content type for.
|
|
134
116
|
*/
|
|
135
117
|
function buildClientOptionType() {
|
|
136
|
-
return
|
|
118
|
+
return requestConfigBaseType;
|
|
137
119
|
}
|
|
138
120
|
/**
|
|
139
121
|
* Which of the grouped request options an operation carries.
|
|
@@ -193,11 +175,19 @@ const operationParameterGroupsByNode = /* @__PURE__ */ new WeakMap();
|
|
|
193
175
|
function getOperationParameters(node) {
|
|
194
176
|
const cached = operationParameterGroupsByNode.get(node);
|
|
195
177
|
if (cached) return cached;
|
|
178
|
+
const group = (location) => {
|
|
179
|
+
const seen = /* @__PURE__ */ new Set();
|
|
180
|
+
return node.parameters.filter((param) => {
|
|
181
|
+
if (param.in !== location || seen.has(param.name)) return false;
|
|
182
|
+
seen.add(param.name);
|
|
183
|
+
return true;
|
|
184
|
+
});
|
|
185
|
+
};
|
|
196
186
|
const groups = {
|
|
197
|
-
path:
|
|
198
|
-
query:
|
|
199
|
-
header:
|
|
200
|
-
cookie:
|
|
187
|
+
path: group("path"),
|
|
188
|
+
query: group("query"),
|
|
189
|
+
header: group("header"),
|
|
190
|
+
cookie: group("cookie")
|
|
201
191
|
};
|
|
202
192
|
operationParameterGroupsByNode.set(node, groups);
|
|
203
193
|
return groups;
|
|
@@ -357,7 +347,7 @@ var compatibility = {
|
|
|
357
347
|
};
|
|
358
348
|
//#endregion
|
|
359
349
|
//#region package.json
|
|
360
|
-
var version = "5.6.0-canary.
|
|
350
|
+
var version = "5.6.0-canary.20261015T094516";
|
|
361
351
|
//#endregion
|
|
362
352
|
//#region ../../internals/client/src/resolveClient.ts
|
|
363
353
|
/**
|
|
@@ -511,12 +501,101 @@ function resolveClientOperation(options) {
|
|
|
511
501
|
});
|
|
512
502
|
}
|
|
513
503
|
//#endregion
|
|
504
|
+
//#region ../../internals/tanstack-query/src/components/HookFile.tsx
|
|
505
|
+
/**
|
|
506
|
+
* Resolves what every TanStack hook file shares: its file, the `@kubb/plugin-ts` file and type names, banner and footer.
|
|
507
|
+
*/
|
|
508
|
+
function resolveHookFile(node, ctx, options) {
|
|
509
|
+
const { name, output, group, contractOp, keyTypeName, extraTypeNames = [] } = options;
|
|
510
|
+
const { config, root, resolver } = ctx;
|
|
511
|
+
const pluginTs = ctx.requirePlugin(_kubb_plugin_ts.pluginTsName);
|
|
512
|
+
const tsResolver = ctx.driver.getResolver(_kubb_plugin_ts.pluginTsName);
|
|
513
|
+
const file = resolver.file({
|
|
514
|
+
...operationFileEntry(node, name),
|
|
515
|
+
root,
|
|
516
|
+
output,
|
|
517
|
+
group: group ?? void 0
|
|
518
|
+
});
|
|
519
|
+
const fileTs = resolveDependencyOperationFile({
|
|
520
|
+
cache: ctx.cache,
|
|
521
|
+
node,
|
|
522
|
+
resolver: tsResolver,
|
|
523
|
+
root,
|
|
524
|
+
output: pluginTs.options?.output ?? output,
|
|
525
|
+
group: pluginTs.options?.group
|
|
526
|
+
});
|
|
527
|
+
const importedTypeNames = [
|
|
528
|
+
tsResolver.response.options(node),
|
|
529
|
+
...extraTypeNames,
|
|
530
|
+
...resolveOperationTypeNames(node, tsResolver, {
|
|
531
|
+
exclude: keyTypeName ? [keyTypeName] : void 0,
|
|
532
|
+
order: "body-response-first",
|
|
533
|
+
includeParams: false
|
|
534
|
+
})
|
|
535
|
+
].filter((typeName) => Boolean(typeName));
|
|
536
|
+
const fileMeta = {
|
|
537
|
+
path: file.path,
|
|
538
|
+
baseName: file.baseName
|
|
539
|
+
};
|
|
540
|
+
return {
|
|
541
|
+
file,
|
|
542
|
+
fileTs,
|
|
543
|
+
tsResolver,
|
|
544
|
+
contractOp,
|
|
545
|
+
importedTypeNames,
|
|
546
|
+
banner: resolver.default.banner(ctx.meta, {
|
|
547
|
+
output,
|
|
548
|
+
config,
|
|
549
|
+
file: fileMeta
|
|
550
|
+
}),
|
|
551
|
+
footer: resolver.default.footer(ctx.meta, {
|
|
552
|
+
output,
|
|
553
|
+
config,
|
|
554
|
+
file: fileMeta
|
|
555
|
+
})
|
|
556
|
+
};
|
|
557
|
+
}
|
|
558
|
+
/**
|
|
559
|
+
* The `<File>` shell shared by the TanStack hook generators; renders `children` after the imports.
|
|
560
|
+
*/
|
|
561
|
+
function HookFile({ hook, imports, children }) {
|
|
562
|
+
const { file, fileTs, contractOp, importedTypeNames, banner, footer } = hook;
|
|
563
|
+
return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(kubb_jsx.File, {
|
|
564
|
+
baseName: file.baseName,
|
|
565
|
+
path: file.path,
|
|
566
|
+
meta: file.meta,
|
|
567
|
+
banner,
|
|
568
|
+
footer,
|
|
569
|
+
children: [
|
|
570
|
+
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
571
|
+
name: [contractOp.name],
|
|
572
|
+
root: file.path,
|
|
573
|
+
path: contractOp.path
|
|
574
|
+
}),
|
|
575
|
+
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
576
|
+
name: ["RequestConfig", "ResponseErrorConfig"],
|
|
577
|
+
root: contractOp.clientPathIsFile ? file.path : void 0,
|
|
578
|
+
path: contractOp.clientPath,
|
|
579
|
+
isTypeOnly: true
|
|
580
|
+
}),
|
|
581
|
+
imports,
|
|
582
|
+
fileTs && importedTypeNames.length > 0 && /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
583
|
+
name: Array.from(new Set(importedTypeNames)),
|
|
584
|
+
root: file.path,
|
|
585
|
+
path: fileTs.path,
|
|
586
|
+
isTypeOnly: true
|
|
587
|
+
}),
|
|
588
|
+
children
|
|
589
|
+
]
|
|
590
|
+
});
|
|
591
|
+
}
|
|
592
|
+
//#endregion
|
|
514
593
|
//#region ../../internals/tanstack-query/src/utils.ts
|
|
515
594
|
/**
|
|
516
595
|
* The grouped request options, ordered for both the destructured signature and the
|
|
517
596
|
* call passed to the underlying client.
|
|
518
597
|
*/
|
|
519
|
-
const requestGroupOrder
|
|
598
|
+
const requestGroupOrder = [
|
|
520
599
|
"path",
|
|
521
600
|
"query",
|
|
522
601
|
"body",
|
|
@@ -537,7 +616,7 @@ function maybeValueOrGetter(type) {
|
|
|
537
616
|
* `MaybeRefOrGetter` per group.
|
|
538
617
|
*/
|
|
539
618
|
function buildGroupedRequestParam(node, options) {
|
|
540
|
-
const { resolver, keys = requestGroupOrder
|
|
619
|
+
const { resolver, keys = requestGroupOrder, memberTypeWrapper } = options;
|
|
541
620
|
const { groups, hasRequiredPath, hasRequiredQuery, hasRequiredHeader } = getRequestGroupOptionality(node);
|
|
542
621
|
const names = keys.filter((key) => groups[key]);
|
|
543
622
|
if (names.length === 0) return null;
|
|
@@ -549,7 +628,7 @@ function buildGroupedRequestParam(node, options) {
|
|
|
549
628
|
};
|
|
550
629
|
const isOptional = names.every((name) => !requiredByGroup[name]);
|
|
551
630
|
const optionsName = resolver.response.options(node);
|
|
552
|
-
const omittedKeys = requestGroupOrder
|
|
631
|
+
const omittedKeys = requestGroupOrder.filter((key) => !keys.includes(key));
|
|
553
632
|
const optionsType = omittedKeys.length > 0 ? `Omit<${optionsName}, ${omittedKeys.map((key) => `'${key}'`).join(" | ")}>` : optionsName;
|
|
554
633
|
if (memberTypeWrapper) {
|
|
555
634
|
const members = names.map((name) => ({
|
|
@@ -610,7 +689,7 @@ function buildClientCall(node, options) {
|
|
|
610
689
|
const { groups } = getRequestGroupOptionality(node);
|
|
611
690
|
return `${clientName}({ ${[
|
|
612
691
|
"...config",
|
|
613
|
-
...requestGroupOrder
|
|
692
|
+
...requestGroupOrder.filter((key) => groups[key]).map((name) => unwrapName ? `${name}: ${unwrapName(name)}` : name),
|
|
614
693
|
signal ? "signal: config.signal ?? signal" : null,
|
|
615
694
|
"throwOnError: true"
|
|
616
695
|
].filter((part) => part !== null).join(", ")} })`;
|
|
@@ -820,16 +899,48 @@ function hasQueryKeyParams(node) {
|
|
|
820
899
|
* grouped `path`/`query`/`body` bindings.
|
|
821
900
|
*/
|
|
822
901
|
function buildQueryKeyParams(node, options) {
|
|
823
|
-
const { resolver } = options;
|
|
902
|
+
const { resolver, memberTypeWrapper } = options;
|
|
824
903
|
const groupedParam = buildGroupedRequestParam(node, {
|
|
825
904
|
resolver,
|
|
826
|
-
keys: queryKeyGroupOrder
|
|
905
|
+
keys: queryKeyGroupOrder,
|
|
906
|
+
memberTypeWrapper
|
|
827
907
|
});
|
|
828
908
|
return (0, _kubb_plugin_ts.createFunctionParameters)({ params: groupedParam ? [groupedParam] : [] });
|
|
829
909
|
}
|
|
910
|
+
/**
|
|
911
|
+
* Builds the hook parameter list: the grouped request param (omitted when `withRequest` is `false`) then `options` typed as `optionsType`.
|
|
912
|
+
*/
|
|
913
|
+
function buildHookParams(node, options) {
|
|
914
|
+
const { resolver, optionsType, memberTypeWrapper, withRequest = true } = options;
|
|
915
|
+
const optionsParam = (0, _kubb_plugin_ts.createFunctionParameter)({
|
|
916
|
+
name: "options",
|
|
917
|
+
type: optionsType,
|
|
918
|
+
default: "{}"
|
|
919
|
+
});
|
|
920
|
+
const groupedParam = withRequest ? buildGroupedRequestParam(node, {
|
|
921
|
+
resolver,
|
|
922
|
+
memberTypeWrapper
|
|
923
|
+
}) : null;
|
|
924
|
+
return (0, _kubb_plugin_ts.createFunctionParameters)({ params: [groupedParam, optionsParam].filter((param) => param !== null) });
|
|
925
|
+
}
|
|
926
|
+
/**
|
|
927
|
+
* The `TRequest` type argument of a mutation hook: the options type when the operation takes a request, else `undefined`.
|
|
928
|
+
*/
|
|
929
|
+
function resolveMutationRequestType(node, resolver) {
|
|
930
|
+
return buildGroupedRequestParam(node, { resolver }) ? resolver.response.options(node) : "undefined";
|
|
931
|
+
}
|
|
932
|
+
/**
|
|
933
|
+
* Builds the object literal that unwraps each request group's getter before it reaches `queryKey`/`queryOptions`; `null` without a request group.
|
|
934
|
+
*/
|
|
935
|
+
function buildResolvedRequestParams(node) {
|
|
936
|
+
const groups = getRequestGroups(node);
|
|
937
|
+
const names = requestGroupOrder.filter((key) => groups[key]);
|
|
938
|
+
if (names.length === 0) return null;
|
|
939
|
+
return `{ ${names.map((name) => `${name}: typeof ${name} === 'function' ? ${name}() : ${name}`).join(", ")} }`;
|
|
940
|
+
}
|
|
830
941
|
//#endregion
|
|
831
942
|
//#region ../../internals/tanstack-query/src/components/InfiniteQueryOptions.tsx
|
|
832
|
-
const declarationPrinter$
|
|
943
|
+
const declarationPrinter$6 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
833
944
|
const callPrinter$3 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
834
945
|
function InfiniteQueryOptions({ name, clientName, initialPageParam, hasExplicitInitialPageParam, cursorParam, nextParam, previousParam, getNextPageParam, getPreviousPageParam, node, tsResolver, queryParam, queryKeyName, queryKeyType = "typeof queryKey", memberTypeWrapper, unwrapName, returnType = "full" }) {
|
|
835
946
|
const { TData: queryFnDataType, TError: errorType } = buildResponseTypes(node, tsResolver);
|
|
@@ -849,7 +960,7 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, hasExplicitI
|
|
|
849
960
|
resolver: tsResolver,
|
|
850
961
|
memberTypeWrapper
|
|
851
962
|
});
|
|
852
|
-
const paramsSignature = declarationPrinter$
|
|
963
|
+
const paramsSignature = declarationPrinter$6.print(paramsNode) ?? "";
|
|
853
964
|
const queryFnBody = buildCallResultBody(buildClientCall(node, {
|
|
854
965
|
clientName,
|
|
855
966
|
signal: true,
|
|
@@ -906,20 +1017,20 @@ return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${que
|
|
|
906
1017
|
}
|
|
907
1018
|
//#endregion
|
|
908
1019
|
//#region ../../internals/tanstack-query/src/components/MutationKey.tsx
|
|
909
|
-
const declarationPrinter$
|
|
1020
|
+
const declarationPrinter$5 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
910
1021
|
const mutationKeyTransformer = ({ node }) => {
|
|
911
1022
|
if (!node.path) return [];
|
|
912
1023
|
return [`{ url: '${kubb_kit.Url.toPath(node.path)}' }`];
|
|
913
1024
|
};
|
|
914
|
-
function MutationKey({ name, node, transformer }) {
|
|
1025
|
+
function MutationKey({ name, node, transformer, typeName }) {
|
|
915
1026
|
const paramsNode = (0, _kubb_plugin_ts.createFunctionParameters)({ params: [] });
|
|
916
|
-
const paramsSignature = declarationPrinter$
|
|
1027
|
+
const paramsSignature = declarationPrinter$5.print(paramsNode) ?? "";
|
|
917
1028
|
const keys = (transformer ?? mutationKeyTransformer)({
|
|
918
1029
|
node,
|
|
919
1030
|
casing: "camelcase",
|
|
920
1031
|
variant: "mutation"
|
|
921
1032
|
});
|
|
922
|
-
return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
|
|
1033
|
+
return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(kubb_jsx_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
|
|
923
1034
|
name,
|
|
924
1035
|
isExportable: true,
|
|
925
1036
|
isIndexable: true,
|
|
@@ -930,7 +1041,17 @@ function MutationKey({ name, node, transformer }) {
|
|
|
930
1041
|
singleLine: true,
|
|
931
1042
|
children: `[${keys.join(", ")}] as const`
|
|
932
1043
|
})
|
|
933
|
-
})
|
|
1044
|
+
}), typeName && /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
|
|
1045
|
+
name: typeName,
|
|
1046
|
+
isExportable: true,
|
|
1047
|
+
isIndexable: true,
|
|
1048
|
+
isTypeOnly: true,
|
|
1049
|
+
children: /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.Type, {
|
|
1050
|
+
export: true,
|
|
1051
|
+
name: typeName,
|
|
1052
|
+
children: `ReturnType<typeof ${name}>`
|
|
1053
|
+
})
|
|
1054
|
+
})] });
|
|
934
1055
|
}
|
|
935
1056
|
//#endregion
|
|
936
1057
|
//#region ../../internals/tanstack-query/src/resolver.ts
|
|
@@ -987,7 +1108,7 @@ function createMutationResolver() {
|
|
|
987
1108
|
}
|
|
988
1109
|
//#endregion
|
|
989
1110
|
//#region ../../internals/tanstack-query/src/components/QueryKey.tsx
|
|
990
|
-
const declarationPrinter$
|
|
1111
|
+
const declarationPrinter$4 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
991
1112
|
const queryKeyTransformer = ({ node, variant }) => {
|
|
992
1113
|
if (!node.path) return [];
|
|
993
1114
|
const { path, query } = getOperationParameters(node);
|
|
@@ -1000,9 +1121,12 @@ const queryKeyTransformer = ({ node, variant }) => {
|
|
|
1000
1121
|
if (node.requestBody?.content?.[0]?.schema) result.push("...(body !== undefined ? [body] : [])");
|
|
1001
1122
|
return result;
|
|
1002
1123
|
};
|
|
1003
|
-
function QueryKey({ name, node, tsResolver, typeName, transformer, variant = "query" }) {
|
|
1004
|
-
const paramsNode = buildQueryKeyParams(node, {
|
|
1005
|
-
|
|
1124
|
+
function QueryKey({ name, node, tsResolver, typeName, transformer, variant = "query", memberTypeWrapper, exportType }) {
|
|
1125
|
+
const paramsNode = buildQueryKeyParams(node, {
|
|
1126
|
+
resolver: tsResolver,
|
|
1127
|
+
memberTypeWrapper
|
|
1128
|
+
});
|
|
1129
|
+
const paramsSignature = declarationPrinter$4.print(paramsNode) ?? "";
|
|
1006
1130
|
const keys = (transformer ?? queryKeyTransformer)({
|
|
1007
1131
|
node,
|
|
1008
1132
|
casing: "camelcase",
|
|
@@ -1021,9 +1145,12 @@ function QueryKey({ name, node, tsResolver, typeName, transformer, variant = "qu
|
|
|
1021
1145
|
})
|
|
1022
1146
|
}), /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
|
|
1023
1147
|
name: typeName,
|
|
1148
|
+
isExportable: exportType,
|
|
1149
|
+
isIndexable: exportType,
|
|
1024
1150
|
isTypeOnly: true,
|
|
1025
1151
|
children: /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.Type, {
|
|
1026
1152
|
name: typeName,
|
|
1153
|
+
export: exportType,
|
|
1027
1154
|
children: `ReturnType<typeof ${name}>`
|
|
1028
1155
|
})
|
|
1029
1156
|
})] });
|
|
@@ -1127,30 +1254,6 @@ const customHookOptionsFileGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1127
1254
|
}
|
|
1128
1255
|
});
|
|
1129
1256
|
//#endregion
|
|
1130
|
-
//#region src/utils.ts
|
|
1131
|
-
const requestGroupOrder = [
|
|
1132
|
-
"path",
|
|
1133
|
-
"query",
|
|
1134
|
-
"body",
|
|
1135
|
-
"headers"
|
|
1136
|
-
];
|
|
1137
|
-
/**
|
|
1138
|
-
* Builds the object literal that resolves each request group to a concrete value, unwrapping a getter
|
|
1139
|
-
* once before the value reaches the plain `queryKey`/`queryOptions` helpers. A getter must never reach a
|
|
1140
|
-
* React Query key, which is hashed structurally. Returns `null` when the operation carries no request group.
|
|
1141
|
-
*
|
|
1142
|
-
* @example
|
|
1143
|
-
* ```ts
|
|
1144
|
-
* buildResolvedRequestParams(node) // { path: typeof path === 'function' ? path() : path }
|
|
1145
|
-
* ```
|
|
1146
|
-
*/
|
|
1147
|
-
function buildResolvedRequestParams(node) {
|
|
1148
|
-
const groups = getRequestGroups(node);
|
|
1149
|
-
const names = requestGroupOrder.filter((key) => groups[key]);
|
|
1150
|
-
if (names.length === 0) return null;
|
|
1151
|
-
return `{ ${names.map((name) => `${name}: typeof ${name} === 'function' ? ${name}() : ${name}`).join(", ")} }`;
|
|
1152
|
-
}
|
|
1153
|
-
//#endregion
|
|
1154
1257
|
//#region src/generators/hookOptionsGenerator.tsx
|
|
1155
1258
|
/**
|
|
1156
1259
|
* Emits the `HookOptions` type used by `customOptions`. Enabled when
|
|
@@ -1187,9 +1290,10 @@ const hookOptionsGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1187
1290
|
const nodeMutation = "mutation" in opOverrides ? opOverrides.mutation : mutation;
|
|
1188
1291
|
const nodeInfinite = "infinite" in opOverrides ? opOverrides.infinite : infinite;
|
|
1189
1292
|
const nodeInfiniteOptions = nodeInfinite && typeof nodeInfinite === "object" ? nodeInfinite : null;
|
|
1190
|
-
const
|
|
1191
|
-
|
|
1192
|
-
|
|
1293
|
+
const { isQuery: isQueryOp, isMutation: isMutationOp } = classifyOperation(node, {
|
|
1294
|
+
query: nodeQuery === false ? query : nodeQuery,
|
|
1295
|
+
mutation: nodeMutation
|
|
1296
|
+
});
|
|
1193
1297
|
const isSuspenseOp = !!suspense;
|
|
1194
1298
|
const isInfiniteOp = !!nodeInfiniteOptions;
|
|
1195
1299
|
if (isQueryOp) {
|
|
@@ -1224,9 +1328,7 @@ const hookOptionsGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1224
1328
|
hookOptions[suspenseHookName] = `Partial<ReturnType<typeof ${suspenseOptionsName}>>`;
|
|
1225
1329
|
}
|
|
1226
1330
|
if (isInfiniteOp) {
|
|
1227
|
-
|
|
1228
|
-
const queryParamKeys = getOperationParameters(node).query.map((p) => p.name);
|
|
1229
|
-
if (nodeInfiniteOptions.queryParam ? queryParamKeys.some((k) => normalizeKey(k) === nodeInfiniteOptions.queryParam) : false) {
|
|
1331
|
+
if (matchesInfinite(node, nodeInfiniteOptions)) {
|
|
1230
1332
|
const infiniteOptionsName = resolver.infiniteQuery.optionsName(node);
|
|
1231
1333
|
const infiniteHookName = resolver.infiniteQuery.name(node);
|
|
1232
1334
|
const infiniteHookFile = resolver.file({
|
|
@@ -1312,50 +1414,87 @@ const hookOptionsGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1312
1414
|
}
|
|
1313
1415
|
});
|
|
1314
1416
|
//#endregion
|
|
1315
|
-
//#region src/components/
|
|
1316
|
-
const declarationPrinter$
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1417
|
+
//#region src/components/Query.tsx
|
|
1418
|
+
const declarationPrinter$3 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
1419
|
+
const OBSERVER_OPTIONS_NAMES = {
|
|
1420
|
+
infinite: {
|
|
1421
|
+
suspense: "UseSuspenseInfiniteQueryOptions",
|
|
1422
|
+
standard: "InfiniteQueryObserverOptions"
|
|
1423
|
+
},
|
|
1424
|
+
plain: {
|
|
1425
|
+
suspense: "UseSuspenseQueryOptions",
|
|
1426
|
+
standard: "QueryObserverOptions"
|
|
1427
|
+
}
|
|
1428
|
+
};
|
|
1429
|
+
function buildHookTypes({ node, tsResolver, infinite, suspense, TData, TError, queryKeyTypeName, observerOptionsName, resultTypeName }) {
|
|
1430
|
+
if (infinite) {
|
|
1431
|
+
const { pageParamType } = resolvePageParamType(node, {
|
|
1432
|
+
resolver: tsResolver,
|
|
1433
|
+
initialPageParam: infinite.initialPageParam,
|
|
1434
|
+
queryParam: infinite.queryParam
|
|
1435
|
+
});
|
|
1436
|
+
return {
|
|
1437
|
+
generics: [
|
|
1438
|
+
`TQueryFnData = ${TData}`,
|
|
1439
|
+
`TError = ${TError}`,
|
|
1440
|
+
"TData = InfiniteData<TQueryFnData>",
|
|
1441
|
+
`TQueryKey extends QueryKey = ${queryKeyTypeName}`,
|
|
1442
|
+
`TPageParam = ${pageParamType}`
|
|
1443
|
+
],
|
|
1444
|
+
observerOptionsType: `${observerOptionsName}<TQueryFnData, TError, TData, TQueryKey, TPageParam>`,
|
|
1445
|
+
returnType: `${resultTypeName}<TData, TError> & { queryKey: TQueryKey }`
|
|
1446
|
+
};
|
|
1447
|
+
}
|
|
1448
|
+
return {
|
|
1449
|
+
generics: suspense ? [`TData = ${TData}`, `TQueryKey extends QueryKey = ${queryKeyTypeName}`] : [
|
|
1450
|
+
`TData = ${TData}`,
|
|
1451
|
+
`TQueryData = ${TData}`,
|
|
1452
|
+
`TQueryKey extends QueryKey = ${queryKeyTypeName}`
|
|
1453
|
+
],
|
|
1454
|
+
observerOptionsType: `${observerOptionsName}<${(suspense ? [
|
|
1455
|
+
TData,
|
|
1456
|
+
TError,
|
|
1457
|
+
"TData",
|
|
1458
|
+
"TQueryKey"
|
|
1459
|
+
] : [
|
|
1460
|
+
TData,
|
|
1461
|
+
TError,
|
|
1462
|
+
"TData",
|
|
1463
|
+
"TQueryData",
|
|
1464
|
+
"TQueryKey"
|
|
1465
|
+
]).join(", ")}>`,
|
|
1466
|
+
returnType: `${resultTypeName}<TData, ${TError}> & { queryKey: TQueryKey }`
|
|
1467
|
+
};
|
|
1332
1468
|
}
|
|
1333
|
-
function
|
|
1334
|
-
const { TData
|
|
1335
|
-
const
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1469
|
+
function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, tsResolver, customOptions, suspense, infinite }) {
|
|
1470
|
+
const { TData, TError } = buildResponseTypes(node, tsResolver);
|
|
1471
|
+
const prefix = suspense ? "UseSuspense" : "Use";
|
|
1472
|
+
const hookName = `${suspense ? "useSuspense" : "use"}${infinite ? "InfiniteQuery" : "Query"}`;
|
|
1473
|
+
const observerOptionsName = OBSERVER_OPTIONS_NAMES[infinite ? "infinite" : "plain"][suspense ? "suspense" : "standard"];
|
|
1474
|
+
const { generics, observerOptionsType, returnType } = buildHookTypes({
|
|
1475
|
+
node,
|
|
1476
|
+
tsResolver,
|
|
1477
|
+
infinite,
|
|
1478
|
+
suspense,
|
|
1479
|
+
TData,
|
|
1480
|
+
TError,
|
|
1481
|
+
queryKeyTypeName,
|
|
1482
|
+
observerOptionsName,
|
|
1483
|
+
resultTypeName: `${prefix}${infinite ? "Infinite" : ""}QueryResult`
|
|
1339
1484
|
});
|
|
1340
|
-
const
|
|
1341
|
-
const observerOptionsName = suspense ? "UseSuspenseInfiniteQueryOptions" : "InfiniteQueryObserverOptions";
|
|
1342
|
-
const returnType = `${suspense ? "UseSuspenseInfiniteQueryResult" : "UseInfiniteQueryResult"}<TData, TError> & { queryKey: TQueryKey }`;
|
|
1343
|
-
const generics = [
|
|
1344
|
-
`TQueryFnData = ${responseType}`,
|
|
1345
|
-
`TError = ${errorType}`,
|
|
1346
|
-
"TData = InfiniteData<TQueryFnData>",
|
|
1347
|
-
`TQueryKey extends QueryKey = ${queryKeyTypeName}`,
|
|
1348
|
-
`TPageParam = ${pageParamType}`
|
|
1349
|
-
];
|
|
1485
|
+
const castType = infinite ? observerOptionsType : observerOptionsName;
|
|
1350
1486
|
const resolvedParams = buildResolvedRequestParams(node);
|
|
1351
1487
|
const queryKeyArgs = resolvedParams && hasQueryKeyParams(node) ? "resolvedParams" : "";
|
|
1352
1488
|
const queryOptionsArgs = resolvedParams ? "resolvedParams, config" : "config";
|
|
1353
|
-
const paramsNode =
|
|
1489
|
+
const paramsNode = buildHookParams(node, {
|
|
1354
1490
|
resolver: tsResolver,
|
|
1355
|
-
|
|
1356
|
-
|
|
1491
|
+
memberTypeWrapper: maybeValueOrGetter,
|
|
1492
|
+
optionsType: `{
|
|
1493
|
+
query?: Partial<${observerOptionsType}> & { client?: QueryClient },
|
|
1494
|
+
client?: ${buildClientOptionType()}
|
|
1495
|
+
}`
|
|
1357
1496
|
});
|
|
1358
|
-
const paramsSignature = declarationPrinter$
|
|
1497
|
+
const paramsSignature = declarationPrinter$3.print(paramsNode) ?? "";
|
|
1359
1498
|
return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
|
|
1360
1499
|
name,
|
|
1361
1500
|
isExportable: true,
|
|
@@ -1376,7 +1515,7 @@ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
1376
1515
|
...${queryOptionsName}(${queryOptionsArgs}),${customOptions ? "\n ...customOptions," : ""}
|
|
1377
1516
|
...resolvedOptions,
|
|
1378
1517
|
queryKey,
|
|
1379
|
-
} as unknown as ${
|
|
1518
|
+
} as unknown as ${castType}, queryClient) as ${returnType}
|
|
1380
1519
|
|
|
1381
1520
|
queryResult.queryKey = queryKey as TQueryKey
|
|
1382
1521
|
|
|
@@ -1386,9 +1525,216 @@ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
1386
1525
|
});
|
|
1387
1526
|
}
|
|
1388
1527
|
//#endregion
|
|
1389
|
-
//#region src/components/
|
|
1390
|
-
const declarationPrinter$
|
|
1528
|
+
//#region src/components/QueryOptions.tsx
|
|
1529
|
+
const declarationPrinter$2 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
1391
1530
|
const callPrinter$2 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
1531
|
+
function QueryOptions({ name, clientName, node, tsResolver, queryKeyName, returnType = "full" }) {
|
|
1532
|
+
const { TData, TError } = buildResponseTypes(node, tsResolver);
|
|
1533
|
+
const queryKeyParamsNode = buildQueryKeyParams(node, { resolver: tsResolver });
|
|
1534
|
+
const queryKeyParamsCall = callPrinter$2.print(queryKeyParamsNode) ?? "";
|
|
1535
|
+
const paramsNode = buildQueryOptionsParams(node, { resolver: tsResolver });
|
|
1536
|
+
const paramsSignature = declarationPrinter$2.print(paramsNode) ?? "";
|
|
1537
|
+
const queryFnBody = buildCallResultBody(buildClientCall(node, {
|
|
1538
|
+
clientName,
|
|
1539
|
+
signal: true
|
|
1540
|
+
}), { returnType });
|
|
1541
|
+
return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
|
|
1542
|
+
name,
|
|
1543
|
+
isExportable: true,
|
|
1544
|
+
isIndexable: true,
|
|
1545
|
+
children: /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.Function, {
|
|
1546
|
+
name,
|
|
1547
|
+
export: true,
|
|
1548
|
+
params: paramsSignature,
|
|
1549
|
+
children: `
|
|
1550
|
+
const queryKey = ${queryKeyName}(${queryKeyParamsCall})
|
|
1551
|
+
return queryOptions<${TData}, ${TError}, ${TData}, typeof queryKey>({
|
|
1552
|
+
queryKey,
|
|
1553
|
+
queryFn: async ({ signal }) => {
|
|
1554
|
+
${queryFnBody}
|
|
1555
|
+
},
|
|
1556
|
+
})
|
|
1557
|
+
`
|
|
1558
|
+
})
|
|
1559
|
+
});
|
|
1560
|
+
}
|
|
1561
|
+
//#endregion
|
|
1562
|
+
//#region src/generators/createQueryGenerator.tsx
|
|
1563
|
+
const OBSERVER_IMPORTS = {
|
|
1564
|
+
query: ["QueryObserverOptions", "UseQueryResult"],
|
|
1565
|
+
suspenseQuery: ["UseSuspenseQueryOptions", "UseSuspenseQueryResult"],
|
|
1566
|
+
infiniteQuery: ["InfiniteQueryObserverOptions", "UseInfiniteQueryResult"],
|
|
1567
|
+
suspenseInfiniteQuery: ["UseSuspenseInfiniteQueryOptions", "UseSuspenseInfiniteQueryResult"]
|
|
1568
|
+
};
|
|
1569
|
+
/**
|
|
1570
|
+
* Builds the generator for one `useQuery` flavor. `variant` picks the resolver namespace
|
|
1571
|
+
* (`resolver.query`, `resolver.suspenseQuery`, ...), the TanStack hook, and the options it needs.
|
|
1572
|
+
*/
|
|
1573
|
+
function createQueryGenerator({ name, variant }) {
|
|
1574
|
+
const suspense = variant === "suspenseQuery" || variant === "suspenseInfiniteQuery";
|
|
1575
|
+
const infinite = variant === "infiniteQuery" || variant === "suspenseInfiniteQuery";
|
|
1576
|
+
const hookImport = `use${suspense ? "Suspense" : ""}${infinite ? "InfiniteQuery" : "Query"}`;
|
|
1577
|
+
const observerImports = OBSERVER_IMPORTS[variant];
|
|
1578
|
+
return (0, kubb_kit.defineGenerator)({
|
|
1579
|
+
name,
|
|
1580
|
+
renderer: kubb_jsx.jsxRenderer,
|
|
1581
|
+
match(node, ctx) {
|
|
1582
|
+
const operationNode = node;
|
|
1583
|
+
if (!kubb_kit.ast.isHttpOperationNode(operationNode)) return false;
|
|
1584
|
+
const { query, mutation, infinite: infiniteConfig, suspense: suspenseConfig, hooks } = ctx.options;
|
|
1585
|
+
const { isQuery, isMutation } = classifyOperation(operationNode, {
|
|
1586
|
+
query,
|
|
1587
|
+
mutation
|
|
1588
|
+
});
|
|
1589
|
+
if (!isQuery || isMutation) return false;
|
|
1590
|
+
if (suspense && !suspenseConfig) return false;
|
|
1591
|
+
if (variant === "query") return true;
|
|
1592
|
+
if (!hooks) return false;
|
|
1593
|
+
if (!infinite) return true;
|
|
1594
|
+
const infiniteOptions = infiniteConfig && typeof infiniteConfig === "object" ? infiniteConfig : null;
|
|
1595
|
+
return !!infiniteOptions && matchesInfinite(operationNode, infiniteOptions);
|
|
1596
|
+
},
|
|
1597
|
+
operation(node, ctx) {
|
|
1598
|
+
if (!kubb_kit.ast.isHttpOperationNode(node)) return null;
|
|
1599
|
+
const { driver, resolver, root } = ctx;
|
|
1600
|
+
const { output, query, infinite: infiniteConfig, client, group, customOptions, hooks } = ctx.options;
|
|
1601
|
+
const infiniteOptions = infinite && infiniteConfig && typeof infiniteConfig === "object" ? infiniteConfig : null;
|
|
1602
|
+
if (infinite && !infiniteOptions) return null;
|
|
1603
|
+
if (variant === "infiniteQuery" && infiniteOptions) {
|
|
1604
|
+
const pageParamsWarning = getDefaultPageParamsWarning(node, infiniteOptions);
|
|
1605
|
+
if (pageParamsWarning) ctx.warn(pageParamsWarning);
|
|
1606
|
+
}
|
|
1607
|
+
const contractOp = resolveClientOperation({
|
|
1608
|
+
clientPlugin: { pluginName: client.pluginName },
|
|
1609
|
+
driver,
|
|
1610
|
+
node,
|
|
1611
|
+
root,
|
|
1612
|
+
output,
|
|
1613
|
+
cache: ctx.cache
|
|
1614
|
+
});
|
|
1615
|
+
if (!contractOp) return null;
|
|
1616
|
+
const importPath = query ? query.importPath : "@tanstack/react-query";
|
|
1617
|
+
const variantResolver = resolver[variant];
|
|
1618
|
+
const queryName = variantResolver.name(node);
|
|
1619
|
+
const queryOptionsName = variantResolver.optionsName(node);
|
|
1620
|
+
const queryKeyName = variantResolver.keyName(node);
|
|
1621
|
+
const queryKeyTypeName = variantResolver.keyTypeName(node);
|
|
1622
|
+
const tsResolver = driver.getResolver(_kubb_plugin_ts.pluginTsName);
|
|
1623
|
+
const hook = resolveHookFile(node, ctx, {
|
|
1624
|
+
name: queryName,
|
|
1625
|
+
output,
|
|
1626
|
+
group,
|
|
1627
|
+
contractOp,
|
|
1628
|
+
keyTypeName: queryKeyTypeName,
|
|
1629
|
+
extraTypeNames: infiniteOptions ? [resolvePageParamType(node, {
|
|
1630
|
+
resolver: tsResolver,
|
|
1631
|
+
initialPageParam: infiniteOptions.initialPageParam,
|
|
1632
|
+
queryParam: infiniteOptions.queryParam
|
|
1633
|
+
}).queryParamsTypeName] : []
|
|
1634
|
+
});
|
|
1635
|
+
return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(HookFile, {
|
|
1636
|
+
hook,
|
|
1637
|
+
imports: customOptions && /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
1638
|
+
name: [customOptions.name],
|
|
1639
|
+
path: customOptions.importPath
|
|
1640
|
+
}),
|
|
1641
|
+
children: [
|
|
1642
|
+
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(QueryKey, {
|
|
1643
|
+
name: queryKeyName,
|
|
1644
|
+
typeName: queryKeyTypeName,
|
|
1645
|
+
node,
|
|
1646
|
+
tsResolver: hook.tsResolver,
|
|
1647
|
+
transformer: ctx.options.queryKey,
|
|
1648
|
+
variant
|
|
1649
|
+
}),
|
|
1650
|
+
infiniteOptions ? /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(kubb_jsx_jsx_runtime.Fragment, { children: [
|
|
1651
|
+
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
1652
|
+
name: ["InfiniteData"],
|
|
1653
|
+
isTypeOnly: true,
|
|
1654
|
+
path: importPath
|
|
1655
|
+
}),
|
|
1656
|
+
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
1657
|
+
name: ["infiniteQueryOptions"],
|
|
1658
|
+
path: importPath
|
|
1659
|
+
}),
|
|
1660
|
+
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(InfiniteQueryOptions, {
|
|
1661
|
+
name: queryOptionsName,
|
|
1662
|
+
clientName: contractOp.name,
|
|
1663
|
+
queryKeyName,
|
|
1664
|
+
node,
|
|
1665
|
+
tsResolver: hook.tsResolver,
|
|
1666
|
+
cursorParam: infiniteOptions.cursorParam,
|
|
1667
|
+
nextParam: infiniteOptions.nextParam,
|
|
1668
|
+
previousParam: infiniteOptions.previousParam,
|
|
1669
|
+
getNextPageParam: infiniteOptions.getNextPageParam,
|
|
1670
|
+
getPreviousPageParam: infiniteOptions.getPreviousPageParam,
|
|
1671
|
+
initialPageParam: infiniteOptions.initialPageParam,
|
|
1672
|
+
hasExplicitInitialPageParam: infiniteOptions.hasExplicitInitialPageParam,
|
|
1673
|
+
queryParam: infiniteOptions.queryParam,
|
|
1674
|
+
returnType: contractOp.returnType
|
|
1675
|
+
})
|
|
1676
|
+
] }) : /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(kubb_jsx_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
1677
|
+
name: ["queryOptions"],
|
|
1678
|
+
path: importPath
|
|
1679
|
+
}), /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(QueryOptions, {
|
|
1680
|
+
name: queryOptionsName,
|
|
1681
|
+
clientName: contractOp.name,
|
|
1682
|
+
queryKeyName,
|
|
1683
|
+
node,
|
|
1684
|
+
tsResolver: hook.tsResolver,
|
|
1685
|
+
returnType: contractOp.returnType
|
|
1686
|
+
})] }),
|
|
1687
|
+
(variant !== "query" || query && hooks) && /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(kubb_jsx_jsx_runtime.Fragment, { children: [
|
|
1688
|
+
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
1689
|
+
name: [hookImport],
|
|
1690
|
+
path: importPath
|
|
1691
|
+
}),
|
|
1692
|
+
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
1693
|
+
name: [
|
|
1694
|
+
"QueryKey",
|
|
1695
|
+
"QueryClient",
|
|
1696
|
+
...observerImports
|
|
1697
|
+
],
|
|
1698
|
+
path: importPath,
|
|
1699
|
+
isTypeOnly: true
|
|
1700
|
+
}),
|
|
1701
|
+
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(Query, {
|
|
1702
|
+
name: queryName,
|
|
1703
|
+
queryOptionsName,
|
|
1704
|
+
queryKeyName,
|
|
1705
|
+
queryKeyTypeName,
|
|
1706
|
+
node,
|
|
1707
|
+
tsResolver: hook.tsResolver,
|
|
1708
|
+
customOptions,
|
|
1709
|
+
suspense,
|
|
1710
|
+
infinite: infiniteOptions ? {
|
|
1711
|
+
initialPageParam: infiniteOptions.initialPageParam,
|
|
1712
|
+
queryParam: infiniteOptions.queryParam
|
|
1713
|
+
} : void 0
|
|
1714
|
+
})
|
|
1715
|
+
] })
|
|
1716
|
+
]
|
|
1717
|
+
});
|
|
1718
|
+
}
|
|
1719
|
+
});
|
|
1720
|
+
}
|
|
1721
|
+
//#endregion
|
|
1722
|
+
//#region src/generators/infiniteQueryGenerator.tsx
|
|
1723
|
+
/**
|
|
1724
|
+
* Built-in generator for `useInfiniteQuery` hooks. Enabled when
|
|
1725
|
+
* `pluginReactQuery({ infinite: { ... }, hooks: true })`. Emits one
|
|
1726
|
+
* `useFooInfiniteQuery` hook per query operation, wiring the configured
|
|
1727
|
+
* `nextParam` / `previousParam` paths into TanStack Query's cursor-based
|
|
1728
|
+
* pagination.
|
|
1729
|
+
*/
|
|
1730
|
+
const infiniteQueryGenerator = createQueryGenerator({
|
|
1731
|
+
name: "react-infinite-query",
|
|
1732
|
+
variant: "infiniteQuery"
|
|
1733
|
+
});
|
|
1734
|
+
//#endregion
|
|
1735
|
+
//#region src/components/MutationOptions.tsx
|
|
1736
|
+
const declarationPrinter$1 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
1737
|
+
const callPrinter$1 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
1392
1738
|
function buildMutationConfigParamsNode(node) {
|
|
1393
1739
|
return (0, _kubb_plugin_ts.createFunctionParameters)({ params: [(0, _kubb_plugin_ts.createFunctionParameter)({
|
|
1394
1740
|
name: "config",
|
|
@@ -1399,12 +1745,12 @@ function buildMutationConfigParamsNode(node) {
|
|
|
1399
1745
|
function MutationOptions({ name, clientName, node, tsResolver, mutationKeyName, returnType = "full" }) {
|
|
1400
1746
|
const { TData, TError } = buildResponseTypes(node, tsResolver);
|
|
1401
1747
|
const configParamsNode = buildMutationConfigParamsNode(node);
|
|
1402
|
-
const paramsSignature = declarationPrinter$
|
|
1748
|
+
const paramsSignature = declarationPrinter$1.print(configParamsNode) ?? "";
|
|
1403
1749
|
const groupedParam = buildGroupedRequestParam(node, { resolver: tsResolver });
|
|
1404
1750
|
const hasMutationParams = groupedParam !== null;
|
|
1405
1751
|
const groupedParamsNode = (0, _kubb_plugin_ts.createFunctionParameters)({ params: groupedParam ? [groupedParam] : [] });
|
|
1406
1752
|
const TRequest = hasMutationParams ? tsResolver.response.options(node) : "undefined";
|
|
1407
|
-
const argBindingStr = hasMutationParams ? callPrinter$
|
|
1753
|
+
const argBindingStr = hasMutationParams ? callPrinter$1.print(groupedParamsNode) ?? "" : "_";
|
|
1408
1754
|
const mutationFnBody = buildCallResultBody(buildClientCall(node, {
|
|
1409
1755
|
clientName,
|
|
1410
1756
|
signal: false
|
|
@@ -1432,28 +1778,24 @@ function MutationOptions({ name, clientName, node, tsResolver, mutationKeyName,
|
|
|
1432
1778
|
}
|
|
1433
1779
|
//#endregion
|
|
1434
1780
|
//#region src/components/Mutation.tsx
|
|
1435
|
-
const declarationPrinter
|
|
1436
|
-
const callPrinter
|
|
1437
|
-
function resolveMutationRequestType(node, resolver) {
|
|
1438
|
-
return buildGroupedRequestParam(node, { resolver }) ? resolver.response.options(node) : "undefined";
|
|
1439
|
-
}
|
|
1781
|
+
const declarationPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
1782
|
+
const callPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
1440
1783
|
function buildMutationParamsNode(node, options) {
|
|
1441
1784
|
const { resolver } = options;
|
|
1442
1785
|
const { TData, TError } = buildResponseTypes(node, resolver);
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1786
|
+
return buildHookParams(node, {
|
|
1787
|
+
resolver,
|
|
1788
|
+
withRequest: false,
|
|
1789
|
+
optionsType: `{
|
|
1790
|
+
mutation?: UseMutationOptions<${[
|
|
1791
|
+
TData,
|
|
1792
|
+
TError,
|
|
1793
|
+
resolveMutationRequestType(node, resolver),
|
|
1794
|
+
"TContext"
|
|
1795
|
+
].join(", ")}> & { client?: QueryClient },
|
|
1453
1796
|
client?: ${buildRequestConfigType(node)},
|
|
1454
|
-
}
|
|
1455
|
-
|
|
1456
|
-
})] });
|
|
1797
|
+
}`
|
|
1798
|
+
});
|
|
1457
1799
|
}
|
|
1458
1800
|
function Mutation({ name, mutationOptionsName, node, tsResolver, mutationKeyName, customOptions }) {
|
|
1459
1801
|
const { TData, TError } = buildResponseTypes(node, tsResolver);
|
|
@@ -1465,9 +1807,9 @@ function Mutation({ name, mutationOptionsName, node, tsResolver, mutationKeyName
|
|
|
1465
1807
|
].join(", ");
|
|
1466
1808
|
const returnType = `UseMutationResult<${generics}>`;
|
|
1467
1809
|
const mutationOptionsConfigNode = buildMutationConfigParamsNode(node);
|
|
1468
|
-
const mutationOptionsParamsCall = callPrinter
|
|
1810
|
+
const mutationOptionsParamsCall = callPrinter.print(mutationOptionsConfigNode) ?? "";
|
|
1469
1811
|
const paramsNode = buildMutationParamsNode(node, { resolver: tsResolver });
|
|
1470
|
-
const paramsSignature = declarationPrinter
|
|
1812
|
+
const paramsSignature = declarationPrinter.print(paramsNode) ?? "";
|
|
1471
1813
|
return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
|
|
1472
1814
|
name,
|
|
1473
1815
|
isExportable: true,
|
|
@@ -1495,301 +1837,6 @@ function Mutation({ name, mutationOptionsName, node, tsResolver, mutationKeyName
|
|
|
1495
1837
|
});
|
|
1496
1838
|
}
|
|
1497
1839
|
//#endregion
|
|
1498
|
-
//#region src/components/Query.tsx
|
|
1499
|
-
const declarationPrinter$1 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
1500
|
-
function buildQueryParamsNode(node, options) {
|
|
1501
|
-
const { resolver, observerOptionsType } = options;
|
|
1502
|
-
const optionsParam = (0, _kubb_plugin_ts.createFunctionParameter)({
|
|
1503
|
-
name: "options",
|
|
1504
|
-
type: `{
|
|
1505
|
-
query?: Partial<${observerOptionsType}> & { client?: QueryClient },
|
|
1506
|
-
client?: ${buildClientOptionType()}
|
|
1507
|
-
}`,
|
|
1508
|
-
default: "{}"
|
|
1509
|
-
});
|
|
1510
|
-
const groupedParam = buildGroupedRequestParam(node, {
|
|
1511
|
-
resolver,
|
|
1512
|
-
memberTypeWrapper: maybeValueOrGetter
|
|
1513
|
-
});
|
|
1514
|
-
return (0, _kubb_plugin_ts.createFunctionParameters)({ params: [groupedParam, optionsParam].filter((param) => param !== null) });
|
|
1515
|
-
}
|
|
1516
|
-
function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, tsResolver, customOptions, suspense }) {
|
|
1517
|
-
const { TData, TError } = buildResponseTypes(node, tsResolver);
|
|
1518
|
-
const hookName = suspense ? "useSuspenseQuery" : "useQuery";
|
|
1519
|
-
const observerOptionsName = suspense ? "UseSuspenseQueryOptions" : "QueryObserverOptions";
|
|
1520
|
-
const observerOptionsType = suspense ? `${observerOptionsName}<${[
|
|
1521
|
-
TData,
|
|
1522
|
-
TError,
|
|
1523
|
-
"TData",
|
|
1524
|
-
"TQueryKey"
|
|
1525
|
-
].join(", ")}>` : `${observerOptionsName}<${[
|
|
1526
|
-
TData,
|
|
1527
|
-
TError,
|
|
1528
|
-
"TData",
|
|
1529
|
-
"TQueryData",
|
|
1530
|
-
"TQueryKey"
|
|
1531
|
-
].join(", ")}>`;
|
|
1532
|
-
const returnType = `${suspense ? "UseSuspenseQueryResult" : "UseQueryResult"}<TData, ${TError}> & { queryKey: TQueryKey }`;
|
|
1533
|
-
const generics = suspense ? [`TData = ${TData}`, `TQueryKey extends QueryKey = ${queryKeyTypeName}`] : [
|
|
1534
|
-
`TData = ${TData}`,
|
|
1535
|
-
`TQueryData = ${TData}`,
|
|
1536
|
-
`TQueryKey extends QueryKey = ${queryKeyTypeName}`
|
|
1537
|
-
];
|
|
1538
|
-
const resolvedParams = buildResolvedRequestParams(node);
|
|
1539
|
-
const queryKeyArgs = resolvedParams && hasQueryKeyParams(node) ? "resolvedParams" : "";
|
|
1540
|
-
const queryOptionsArgs = resolvedParams ? "resolvedParams, config" : "config";
|
|
1541
|
-
const paramsNode = buildQueryParamsNode(node, {
|
|
1542
|
-
resolver: tsResolver,
|
|
1543
|
-
observerOptionsType
|
|
1544
|
-
});
|
|
1545
|
-
const paramsSignature = declarationPrinter$1.print(paramsNode) ?? "";
|
|
1546
|
-
return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
|
|
1547
|
-
name,
|
|
1548
|
-
isExportable: true,
|
|
1549
|
-
isIndexable: true,
|
|
1550
|
-
children: /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.Function, {
|
|
1551
|
-
name,
|
|
1552
|
-
export: true,
|
|
1553
|
-
generics: generics.join(", "),
|
|
1554
|
-
params: paramsSignature,
|
|
1555
|
-
returnType: void 0,
|
|
1556
|
-
JSDoc: { comments: buildOperationComments(node) },
|
|
1557
|
-
children: `
|
|
1558
|
-
const { query: queryConfig = {}, client: config = {} } = options ?? {}
|
|
1559
|
-
const { client: queryClient, ...resolvedOptions } = queryConfig${resolvedParams ? `\n const resolvedParams = ${resolvedParams}` : ""}
|
|
1560
|
-
const queryKey = resolvedOptions?.queryKey ?? ${queryKeyName}(${queryKeyArgs})${customOptions ? `\n const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${node.operationId}' })` : ""}
|
|
1561
|
-
|
|
1562
|
-
const queryResult = ${hookName}({
|
|
1563
|
-
...${queryOptionsName}(${queryOptionsArgs}),${customOptions ? "\n ...customOptions," : ""}
|
|
1564
|
-
...resolvedOptions,
|
|
1565
|
-
queryKey,
|
|
1566
|
-
} as unknown as ${observerOptionsName}, queryClient) as ${returnType}
|
|
1567
|
-
|
|
1568
|
-
queryResult.queryKey = queryKey as TQueryKey
|
|
1569
|
-
|
|
1570
|
-
return queryResult
|
|
1571
|
-
`
|
|
1572
|
-
})
|
|
1573
|
-
});
|
|
1574
|
-
}
|
|
1575
|
-
//#endregion
|
|
1576
|
-
//#region src/components/QueryOptions.tsx
|
|
1577
|
-
const declarationPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
1578
|
-
const callPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
1579
|
-
function QueryOptions({ name, clientName, node, tsResolver, queryKeyName, returnType = "full" }) {
|
|
1580
|
-
const { TData, TError } = buildResponseTypes(node, tsResolver);
|
|
1581
|
-
const queryKeyParamsNode = buildQueryKeyParams(node, { resolver: tsResolver });
|
|
1582
|
-
const queryKeyParamsCall = callPrinter.print(queryKeyParamsNode) ?? "";
|
|
1583
|
-
const paramsNode = buildQueryOptionsParams(node, { resolver: tsResolver });
|
|
1584
|
-
const paramsSignature = declarationPrinter.print(paramsNode) ?? "";
|
|
1585
|
-
const queryFnBody = buildCallResultBody(buildClientCall(node, {
|
|
1586
|
-
clientName,
|
|
1587
|
-
signal: true
|
|
1588
|
-
}), { returnType });
|
|
1589
|
-
return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
|
|
1590
|
-
name,
|
|
1591
|
-
isExportable: true,
|
|
1592
|
-
isIndexable: true,
|
|
1593
|
-
children: /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.Function, {
|
|
1594
|
-
name,
|
|
1595
|
-
export: true,
|
|
1596
|
-
params: paramsSignature,
|
|
1597
|
-
children: `
|
|
1598
|
-
const queryKey = ${queryKeyName}(${queryKeyParamsCall})
|
|
1599
|
-
return queryOptions<${TData}, ${TError}, ${TData}, typeof queryKey>({
|
|
1600
|
-
queryKey,
|
|
1601
|
-
queryFn: async ({ signal }) => {
|
|
1602
|
-
${queryFnBody}
|
|
1603
|
-
},
|
|
1604
|
-
})
|
|
1605
|
-
`
|
|
1606
|
-
})
|
|
1607
|
-
});
|
|
1608
|
-
}
|
|
1609
|
-
//#endregion
|
|
1610
|
-
//#region src/generators/infiniteQueryGenerator.tsx
|
|
1611
|
-
/**
|
|
1612
|
-
* Built-in generator for `useInfiniteQuery` hooks. Enabled when
|
|
1613
|
-
* `pluginReactQuery({ infinite: { ... }, hooks: true })`. Emits one
|
|
1614
|
-
* `useFooInfiniteQuery` hook per query operation, wiring the configured
|
|
1615
|
-
* `nextParam` / `previousParam` paths into TanStack Query's cursor-based
|
|
1616
|
-
* pagination.
|
|
1617
|
-
*/
|
|
1618
|
-
const infiniteQueryGenerator = (0, kubb_kit.defineGenerator)({
|
|
1619
|
-
name: "react-infinite-query",
|
|
1620
|
-
renderer: kubb_jsx.jsxRenderer,
|
|
1621
|
-
match(node, ctx) {
|
|
1622
|
-
const operationNode = node;
|
|
1623
|
-
if (!kubb_kit.ast.isHttpOperationNode(operationNode)) return false;
|
|
1624
|
-
const { query, mutation, infinite, hooks } = ctx.options;
|
|
1625
|
-
const { isQuery, isMutation } = classifyOperation(operationNode, {
|
|
1626
|
-
query,
|
|
1627
|
-
mutation
|
|
1628
|
-
});
|
|
1629
|
-
const infiniteOptions = infinite && typeof infinite === "object" ? infinite : null;
|
|
1630
|
-
if (!isQuery || isMutation || !infiniteOptions || !hooks) return false;
|
|
1631
|
-
return matchesInfinite(operationNode, infiniteOptions);
|
|
1632
|
-
},
|
|
1633
|
-
operation(node, ctx) {
|
|
1634
|
-
if (!kubb_kit.ast.isHttpOperationNode(node)) return null;
|
|
1635
|
-
const { config, driver, resolver, root } = ctx;
|
|
1636
|
-
const { output, query, infinite, client, group, customOptions } = ctx.options;
|
|
1637
|
-
const pluginTs = ctx.requirePlugin(_kubb_plugin_ts.pluginTsName);
|
|
1638
|
-
const tsResolver = driver.getResolver(_kubb_plugin_ts.pluginTsName);
|
|
1639
|
-
const infiniteOptions = infinite && typeof infinite === "object" ? infinite : null;
|
|
1640
|
-
if (!infiniteOptions) return null;
|
|
1641
|
-
const pageParamsWarning = getDefaultPageParamsWarning(node, infiniteOptions);
|
|
1642
|
-
if (pageParamsWarning) ctx.warn(pageParamsWarning);
|
|
1643
|
-
const importPath = query ? query.importPath : "@tanstack/react-query";
|
|
1644
|
-
const contractOp = resolveClientOperation({
|
|
1645
|
-
clientPlugin: { pluginName: client.pluginName },
|
|
1646
|
-
driver,
|
|
1647
|
-
node,
|
|
1648
|
-
root,
|
|
1649
|
-
output,
|
|
1650
|
-
cache: ctx.cache
|
|
1651
|
-
});
|
|
1652
|
-
if (!contractOp) return null;
|
|
1653
|
-
const queryName = resolver.infiniteQuery.name(node);
|
|
1654
|
-
const queryOptionsName = resolver.infiniteQuery.optionsName(node);
|
|
1655
|
-
const queryKeyName = resolver.infiniteQuery.keyName(node);
|
|
1656
|
-
const queryKeyTypeName = resolver.infiniteQuery.keyTypeName(node);
|
|
1657
|
-
const meta = {
|
|
1658
|
-
file: resolver.file({
|
|
1659
|
-
...operationFileEntry(node, queryName),
|
|
1660
|
-
root,
|
|
1661
|
-
output,
|
|
1662
|
-
group: group ?? void 0
|
|
1663
|
-
}),
|
|
1664
|
-
fileTs: resolveDependencyOperationFile({
|
|
1665
|
-
cache: ctx.cache,
|
|
1666
|
-
node,
|
|
1667
|
-
resolver: tsResolver,
|
|
1668
|
-
root,
|
|
1669
|
-
output: pluginTs.options?.output ?? output,
|
|
1670
|
-
group: pluginTs.options?.group
|
|
1671
|
-
})
|
|
1672
|
-
};
|
|
1673
|
-
const { queryParamsTypeName } = resolvePageParamType(node, {
|
|
1674
|
-
resolver: tsResolver,
|
|
1675
|
-
initialPageParam: infiniteOptions.initialPageParam,
|
|
1676
|
-
queryParam: infiniteOptions.queryParam
|
|
1677
|
-
});
|
|
1678
|
-
const importedTypeNames = [
|
|
1679
|
-
tsResolver.response.options(node),
|
|
1680
|
-
queryParamsTypeName,
|
|
1681
|
-
...resolveOperationTypeNames(node, tsResolver, {
|
|
1682
|
-
exclude: [queryKeyTypeName],
|
|
1683
|
-
order: "body-response-first",
|
|
1684
|
-
includeParams: false
|
|
1685
|
-
})
|
|
1686
|
-
].filter((name) => Boolean(name));
|
|
1687
|
-
const calledClientName = contractOp.name;
|
|
1688
|
-
return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(kubb_jsx.File, {
|
|
1689
|
-
baseName: meta.file.baseName,
|
|
1690
|
-
path: meta.file.path,
|
|
1691
|
-
meta: meta.file.meta,
|
|
1692
|
-
banner: resolver.default.banner(ctx.meta, {
|
|
1693
|
-
output,
|
|
1694
|
-
config,
|
|
1695
|
-
file: {
|
|
1696
|
-
path: meta.file.path,
|
|
1697
|
-
baseName: meta.file.baseName
|
|
1698
|
-
}
|
|
1699
|
-
}),
|
|
1700
|
-
footer: resolver.default.footer(ctx.meta, {
|
|
1701
|
-
output,
|
|
1702
|
-
config,
|
|
1703
|
-
file: {
|
|
1704
|
-
path: meta.file.path,
|
|
1705
|
-
baseName: meta.file.baseName
|
|
1706
|
-
}
|
|
1707
|
-
}),
|
|
1708
|
-
children: [
|
|
1709
|
-
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
1710
|
-
name: [contractOp.name],
|
|
1711
|
-
root: meta.file.path,
|
|
1712
|
-
path: contractOp.path
|
|
1713
|
-
}),
|
|
1714
|
-
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
1715
|
-
name: ["RequestConfig", "ResponseErrorConfig"],
|
|
1716
|
-
root: contractOp.clientPathIsFile ? meta.file.path : void 0,
|
|
1717
|
-
path: contractOp.clientPath,
|
|
1718
|
-
isTypeOnly: true
|
|
1719
|
-
}),
|
|
1720
|
-
customOptions && /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
1721
|
-
name: [customOptions.name],
|
|
1722
|
-
path: customOptions.importPath
|
|
1723
|
-
}),
|
|
1724
|
-
meta.fileTs && importedTypeNames.length > 0 && /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
1725
|
-
name: Array.from(new Set(importedTypeNames)),
|
|
1726
|
-
root: meta.file.path,
|
|
1727
|
-
path: meta.fileTs.path,
|
|
1728
|
-
isTypeOnly: true
|
|
1729
|
-
}),
|
|
1730
|
-
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(QueryKey, {
|
|
1731
|
-
name: queryKeyName,
|
|
1732
|
-
typeName: queryKeyTypeName,
|
|
1733
|
-
node,
|
|
1734
|
-
tsResolver,
|
|
1735
|
-
transformer: ctx.options.queryKey,
|
|
1736
|
-
variant: "infiniteQuery"
|
|
1737
|
-
}),
|
|
1738
|
-
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
1739
|
-
name: ["InfiniteData"],
|
|
1740
|
-
isTypeOnly: true,
|
|
1741
|
-
path: importPath
|
|
1742
|
-
}),
|
|
1743
|
-
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
1744
|
-
name: ["infiniteQueryOptions"],
|
|
1745
|
-
path: importPath
|
|
1746
|
-
}),
|
|
1747
|
-
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(InfiniteQueryOptions, {
|
|
1748
|
-
name: queryOptionsName,
|
|
1749
|
-
clientName: calledClientName,
|
|
1750
|
-
queryKeyName,
|
|
1751
|
-
node,
|
|
1752
|
-
tsResolver,
|
|
1753
|
-
cursorParam: infiniteOptions.cursorParam,
|
|
1754
|
-
nextParam: infiniteOptions.nextParam,
|
|
1755
|
-
previousParam: infiniteOptions.previousParam,
|
|
1756
|
-
getNextPageParam: infiniteOptions.getNextPageParam,
|
|
1757
|
-
getPreviousPageParam: infiniteOptions.getPreviousPageParam,
|
|
1758
|
-
initialPageParam: infiniteOptions.initialPageParam,
|
|
1759
|
-
hasExplicitInitialPageParam: infiniteOptions.hasExplicitInitialPageParam,
|
|
1760
|
-
queryParam: infiniteOptions.queryParam,
|
|
1761
|
-
returnType: contractOp.returnType
|
|
1762
|
-
}),
|
|
1763
|
-
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
1764
|
-
name: ["useInfiniteQuery"],
|
|
1765
|
-
path: importPath
|
|
1766
|
-
}),
|
|
1767
|
-
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
1768
|
-
name: [
|
|
1769
|
-
"QueryKey",
|
|
1770
|
-
"QueryClient",
|
|
1771
|
-
"InfiniteQueryObserverOptions",
|
|
1772
|
-
"UseInfiniteQueryResult"
|
|
1773
|
-
],
|
|
1774
|
-
path: importPath,
|
|
1775
|
-
isTypeOnly: true
|
|
1776
|
-
}),
|
|
1777
|
-
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(InfiniteQuery, {
|
|
1778
|
-
name: queryName,
|
|
1779
|
-
queryOptionsName,
|
|
1780
|
-
queryKeyName,
|
|
1781
|
-
queryKeyTypeName,
|
|
1782
|
-
node,
|
|
1783
|
-
tsResolver,
|
|
1784
|
-
initialPageParam: infiniteOptions.initialPageParam,
|
|
1785
|
-
queryParam: infiniteOptions.queryParam,
|
|
1786
|
-
customOptions
|
|
1787
|
-
})
|
|
1788
|
-
]
|
|
1789
|
-
});
|
|
1790
|
-
}
|
|
1791
|
-
});
|
|
1792
|
-
//#endregion
|
|
1793
1840
|
//#region src/generators/mutationGenerator.tsx
|
|
1794
1841
|
/**
|
|
1795
1842
|
* Built-in generator for `useMutation` hooks. Emits one `useFooMutation` hook
|
|
@@ -1810,10 +1857,8 @@ const mutationGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1810
1857
|
},
|
|
1811
1858
|
operation(node, ctx) {
|
|
1812
1859
|
if (!kubb_kit.ast.isHttpOperationNode(node)) return null;
|
|
1813
|
-
const {
|
|
1860
|
+
const { driver, resolver, root } = ctx;
|
|
1814
1861
|
const { output, mutation, client, group, customOptions, hooks } = ctx.options;
|
|
1815
|
-
const pluginTs = ctx.requirePlugin(_kubb_plugin_ts.pluginTsName);
|
|
1816
|
-
const tsResolver = driver.getResolver(_kubb_plugin_ts.pluginTsName);
|
|
1817
1862
|
const importPath = mutation ? mutation.importPath : "@tanstack/react-query";
|
|
1818
1863
|
const contractOp = resolveClientOperation({
|
|
1819
1864
|
clientPlugin: { pluginName: client.pluginName },
|
|
@@ -1825,72 +1870,22 @@ const mutationGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1825
1870
|
});
|
|
1826
1871
|
if (!contractOp) return null;
|
|
1827
1872
|
const mutationHookName = resolver.mutation.name(node);
|
|
1828
|
-
const mutationTypeName = resolver.mutation.typeName(node);
|
|
1829
1873
|
const mutationOptionsName = resolver.mutation.optionsName(node);
|
|
1830
1874
|
const mutationKeyName = resolver.mutation.keyName(node);
|
|
1831
|
-
const
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
output: pluginTs.options?.output ?? output,
|
|
1844
|
-
group: pluginTs.options?.group
|
|
1845
|
-
})
|
|
1846
|
-
};
|
|
1847
|
-
const importedTypeNames = [tsResolver.response.options(node), ...resolveOperationTypeNames(node, tsResolver, {
|
|
1848
|
-
order: "body-response-first",
|
|
1849
|
-
includeParams: false
|
|
1850
|
-
})].filter((name) => Boolean(name));
|
|
1851
|
-
const calledClientName = contractOp.name;
|
|
1852
|
-
return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(kubb_jsx.File, {
|
|
1853
|
-
baseName: meta.file.baseName,
|
|
1854
|
-
path: meta.file.path,
|
|
1855
|
-
meta: meta.file.meta,
|
|
1856
|
-
banner: resolver.default.banner(ctx.meta, {
|
|
1857
|
-
output,
|
|
1858
|
-
config,
|
|
1859
|
-
file: {
|
|
1860
|
-
path: meta.file.path,
|
|
1861
|
-
baseName: meta.file.baseName
|
|
1862
|
-
}
|
|
1863
|
-
}),
|
|
1864
|
-
footer: resolver.default.footer(ctx.meta, {
|
|
1865
|
-
output,
|
|
1866
|
-
config,
|
|
1867
|
-
file: {
|
|
1868
|
-
path: meta.file.path,
|
|
1869
|
-
baseName: meta.file.baseName
|
|
1870
|
-
}
|
|
1875
|
+
const hook = resolveHookFile(node, ctx, {
|
|
1876
|
+
name: mutationHookName,
|
|
1877
|
+
output,
|
|
1878
|
+
group,
|
|
1879
|
+
contractOp
|
|
1880
|
+
});
|
|
1881
|
+
const { tsResolver } = hook;
|
|
1882
|
+
return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(HookFile, {
|
|
1883
|
+
hook,
|
|
1884
|
+
imports: customOptions && /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
1885
|
+
name: [customOptions.name],
|
|
1886
|
+
path: customOptions.importPath
|
|
1871
1887
|
}),
|
|
1872
1888
|
children: [
|
|
1873
|
-
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
1874
|
-
name: [contractOp.name],
|
|
1875
|
-
root: meta.file.path,
|
|
1876
|
-
path: contractOp.path
|
|
1877
|
-
}),
|
|
1878
|
-
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
1879
|
-
name: ["RequestConfig", "ResponseErrorConfig"],
|
|
1880
|
-
root: contractOp.clientPathIsFile ? meta.file.path : void 0,
|
|
1881
|
-
path: contractOp.clientPath,
|
|
1882
|
-
isTypeOnly: true
|
|
1883
|
-
}),
|
|
1884
|
-
customOptions && /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
1885
|
-
name: [customOptions.name],
|
|
1886
|
-
path: customOptions.importPath
|
|
1887
|
-
}),
|
|
1888
|
-
meta.fileTs && importedTypeNames.length > 0 && /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
1889
|
-
name: Array.from(new Set(importedTypeNames)),
|
|
1890
|
-
root: meta.file.path,
|
|
1891
|
-
path: meta.fileTs.path,
|
|
1892
|
-
isTypeOnly: true
|
|
1893
|
-
}),
|
|
1894
1889
|
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(MutationKey, {
|
|
1895
1890
|
name: mutationKeyName,
|
|
1896
1891
|
node,
|
|
@@ -1902,7 +1897,7 @@ const mutationGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1902
1897
|
}),
|
|
1903
1898
|
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(MutationOptions, {
|
|
1904
1899
|
name: mutationOptionsName,
|
|
1905
|
-
clientName:
|
|
1900
|
+
clientName: contractOp.name,
|
|
1906
1901
|
mutationKeyName,
|
|
1907
1902
|
node,
|
|
1908
1903
|
tsResolver,
|
|
@@ -1924,7 +1919,6 @@ const mutationGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1924
1919
|
}),
|
|
1925
1920
|
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(Mutation, {
|
|
1926
1921
|
name: mutationHookName,
|
|
1927
|
-
typeName: mutationTypeName,
|
|
1928
1922
|
mutationOptionsName,
|
|
1929
1923
|
mutationKeyName,
|
|
1930
1924
|
node,
|
|
@@ -1943,151 +1937,9 @@ const mutationGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1943
1937
|
* GET and QUERY operation (configurable via `query.methods`) plus the matching
|
|
1944
1938
|
* `fooQueryKey` / `fooQueryOptions` helpers.
|
|
1945
1939
|
*/
|
|
1946
|
-
const queryGenerator = (
|
|
1940
|
+
const queryGenerator = createQueryGenerator({
|
|
1947
1941
|
name: "react-query",
|
|
1948
|
-
|
|
1949
|
-
match(node, ctx) {
|
|
1950
|
-
const operationNode = node;
|
|
1951
|
-
if (!kubb_kit.ast.isHttpOperationNode(operationNode)) return false;
|
|
1952
|
-
const { query, mutation } = ctx.options;
|
|
1953
|
-
const { isQuery, isMutation } = classifyOperation(operationNode, {
|
|
1954
|
-
query,
|
|
1955
|
-
mutation
|
|
1956
|
-
});
|
|
1957
|
-
return isQuery && !isMutation;
|
|
1958
|
-
},
|
|
1959
|
-
operation(node, ctx) {
|
|
1960
|
-
if (!kubb_kit.ast.isHttpOperationNode(node)) return null;
|
|
1961
|
-
const { config, driver, resolver, root } = ctx;
|
|
1962
|
-
const { output, query, client, group, customOptions, hooks } = ctx.options;
|
|
1963
|
-
const pluginTs = ctx.requirePlugin(_kubb_plugin_ts.pluginTsName);
|
|
1964
|
-
const tsResolver = driver.getResolver(_kubb_plugin_ts.pluginTsName);
|
|
1965
|
-
const importPath = query ? query.importPath : "@tanstack/react-query";
|
|
1966
|
-
const contractOp = resolveClientOperation({
|
|
1967
|
-
clientPlugin: { pluginName: client.pluginName },
|
|
1968
|
-
driver,
|
|
1969
|
-
node,
|
|
1970
|
-
root,
|
|
1971
|
-
output,
|
|
1972
|
-
cache: ctx.cache
|
|
1973
|
-
});
|
|
1974
|
-
if (!contractOp) return null;
|
|
1975
|
-
const queryName = resolver.query.name(node);
|
|
1976
|
-
const queryOptionsName = resolver.query.optionsName(node);
|
|
1977
|
-
const queryKeyName = resolver.query.keyName(node);
|
|
1978
|
-
const queryKeyTypeName = resolver.query.keyTypeName(node);
|
|
1979
|
-
const meta = {
|
|
1980
|
-
file: resolver.file({
|
|
1981
|
-
...operationFileEntry(node, queryName),
|
|
1982
|
-
root,
|
|
1983
|
-
output,
|
|
1984
|
-
group: group ?? void 0
|
|
1985
|
-
}),
|
|
1986
|
-
fileTs: resolveDependencyOperationFile({
|
|
1987
|
-
cache: ctx.cache,
|
|
1988
|
-
node,
|
|
1989
|
-
resolver: tsResolver,
|
|
1990
|
-
root,
|
|
1991
|
-
output: pluginTs.options?.output ?? output,
|
|
1992
|
-
group: pluginTs.options?.group
|
|
1993
|
-
})
|
|
1994
|
-
};
|
|
1995
|
-
const importedTypeNames = [tsResolver.response.options(node), ...resolveOperationTypeNames(node, tsResolver, {
|
|
1996
|
-
exclude: [queryKeyTypeName],
|
|
1997
|
-
order: "body-response-first",
|
|
1998
|
-
includeParams: false
|
|
1999
|
-
})].filter((name) => Boolean(name));
|
|
2000
|
-
const calledClientName = contractOp.name;
|
|
2001
|
-
return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(kubb_jsx.File, {
|
|
2002
|
-
baseName: meta.file.baseName,
|
|
2003
|
-
path: meta.file.path,
|
|
2004
|
-
meta: meta.file.meta,
|
|
2005
|
-
banner: resolver.default.banner(ctx.meta, {
|
|
2006
|
-
output,
|
|
2007
|
-
config,
|
|
2008
|
-
file: {
|
|
2009
|
-
path: meta.file.path,
|
|
2010
|
-
baseName: meta.file.baseName
|
|
2011
|
-
}
|
|
2012
|
-
}),
|
|
2013
|
-
footer: resolver.default.footer(ctx.meta, {
|
|
2014
|
-
output,
|
|
2015
|
-
config,
|
|
2016
|
-
file: {
|
|
2017
|
-
path: meta.file.path,
|
|
2018
|
-
baseName: meta.file.baseName
|
|
2019
|
-
}
|
|
2020
|
-
}),
|
|
2021
|
-
children: [
|
|
2022
|
-
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
2023
|
-
name: [contractOp.name],
|
|
2024
|
-
root: meta.file.path,
|
|
2025
|
-
path: contractOp.path
|
|
2026
|
-
}),
|
|
2027
|
-
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
2028
|
-
name: ["RequestConfig", "ResponseErrorConfig"],
|
|
2029
|
-
root: contractOp.clientPathIsFile ? meta.file.path : void 0,
|
|
2030
|
-
path: contractOp.clientPath,
|
|
2031
|
-
isTypeOnly: true
|
|
2032
|
-
}),
|
|
2033
|
-
customOptions && /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
2034
|
-
name: [customOptions.name],
|
|
2035
|
-
path: customOptions.importPath
|
|
2036
|
-
}),
|
|
2037
|
-
meta.fileTs && importedTypeNames.length > 0 && /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
2038
|
-
name: Array.from(new Set(importedTypeNames)),
|
|
2039
|
-
root: meta.file.path,
|
|
2040
|
-
path: meta.fileTs.path,
|
|
2041
|
-
isTypeOnly: true
|
|
2042
|
-
}),
|
|
2043
|
-
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(QueryKey, {
|
|
2044
|
-
name: queryKeyName,
|
|
2045
|
-
typeName: queryKeyTypeName,
|
|
2046
|
-
node,
|
|
2047
|
-
tsResolver,
|
|
2048
|
-
transformer: ctx.options.queryKey,
|
|
2049
|
-
variant: "query"
|
|
2050
|
-
}),
|
|
2051
|
-
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
2052
|
-
name: ["queryOptions"],
|
|
2053
|
-
path: importPath
|
|
2054
|
-
}),
|
|
2055
|
-
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(QueryOptions, {
|
|
2056
|
-
name: queryOptionsName,
|
|
2057
|
-
clientName: calledClientName,
|
|
2058
|
-
queryKeyName,
|
|
2059
|
-
node,
|
|
2060
|
-
tsResolver,
|
|
2061
|
-
returnType: contractOp.returnType
|
|
2062
|
-
}),
|
|
2063
|
-
query && hooks && /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(kubb_jsx_jsx_runtime.Fragment, { children: [
|
|
2064
|
-
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
2065
|
-
name: ["useQuery"],
|
|
2066
|
-
path: importPath
|
|
2067
|
-
}),
|
|
2068
|
-
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
2069
|
-
name: [
|
|
2070
|
-
"QueryKey",
|
|
2071
|
-
"QueryClient",
|
|
2072
|
-
"QueryObserverOptions",
|
|
2073
|
-
"UseQueryResult"
|
|
2074
|
-
],
|
|
2075
|
-
path: importPath,
|
|
2076
|
-
isTypeOnly: true
|
|
2077
|
-
}),
|
|
2078
|
-
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(Query, {
|
|
2079
|
-
name: queryName,
|
|
2080
|
-
queryOptionsName,
|
|
2081
|
-
queryKeyName,
|
|
2082
|
-
queryKeyTypeName,
|
|
2083
|
-
node,
|
|
2084
|
-
tsResolver,
|
|
2085
|
-
customOptions
|
|
2086
|
-
})
|
|
2087
|
-
] })
|
|
2088
|
-
]
|
|
2089
|
-
});
|
|
2090
|
-
}
|
|
1942
|
+
variant: "query"
|
|
2091
1943
|
});
|
|
2092
1944
|
//#endregion
|
|
2093
1945
|
//#region src/generators/suspenseInfiniteQueryGenerator.tsx
|
|
@@ -2097,178 +1949,9 @@ const queryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
2097
1949
|
* semantics with cursor-based pagination. Handlers throw promises while
|
|
2098
1950
|
* loading and pull additional pages on demand.
|
|
2099
1951
|
*/
|
|
2100
|
-
const suspenseInfiniteQueryGenerator = (
|
|
1952
|
+
const suspenseInfiniteQueryGenerator = createQueryGenerator({
|
|
2101
1953
|
name: "react-suspense-infinite-query",
|
|
2102
|
-
|
|
2103
|
-
match(node, ctx) {
|
|
2104
|
-
const operationNode = node;
|
|
2105
|
-
if (!kubb_kit.ast.isHttpOperationNode(operationNode)) return false;
|
|
2106
|
-
const { query, mutation, infinite, suspense, hooks } = ctx.options;
|
|
2107
|
-
const { isQuery, isMutation } = classifyOperation(operationNode, {
|
|
2108
|
-
query,
|
|
2109
|
-
mutation
|
|
2110
|
-
});
|
|
2111
|
-
const infiniteOptions = infinite && typeof infinite === "object" ? infinite : null;
|
|
2112
|
-
if (!isQuery || isMutation || !suspense || !infiniteOptions || !hooks) return false;
|
|
2113
|
-
return matchesInfinite(operationNode, infiniteOptions);
|
|
2114
|
-
},
|
|
2115
|
-
operation(node, ctx) {
|
|
2116
|
-
if (!kubb_kit.ast.isHttpOperationNode(node)) return null;
|
|
2117
|
-
const { config, driver, resolver, root } = ctx;
|
|
2118
|
-
const { output, query, infinite, client, group, customOptions } = ctx.options;
|
|
2119
|
-
const pluginTs = ctx.requirePlugin(_kubb_plugin_ts.pluginTsName);
|
|
2120
|
-
const tsResolver = driver.getResolver(_kubb_plugin_ts.pluginTsName);
|
|
2121
|
-
const infiniteOptions = infinite && typeof infinite === "object" ? infinite : null;
|
|
2122
|
-
if (!infiniteOptions) return null;
|
|
2123
|
-
const importPath = query ? query.importPath : "@tanstack/react-query";
|
|
2124
|
-
const contractOp = resolveClientOperation({
|
|
2125
|
-
clientPlugin: { pluginName: client.pluginName },
|
|
2126
|
-
driver,
|
|
2127
|
-
node,
|
|
2128
|
-
root,
|
|
2129
|
-
output,
|
|
2130
|
-
cache: ctx.cache
|
|
2131
|
-
});
|
|
2132
|
-
if (!contractOp) return null;
|
|
2133
|
-
const queryName = resolver.suspenseInfiniteQuery.name(node);
|
|
2134
|
-
const queryOptionsName = resolver.suspenseInfiniteQuery.optionsName(node);
|
|
2135
|
-
const queryKeyName = resolver.suspenseInfiniteQuery.keyName(node);
|
|
2136
|
-
const queryKeyTypeName = resolver.suspenseInfiniteQuery.keyTypeName(node);
|
|
2137
|
-
const meta = {
|
|
2138
|
-
file: resolver.file({
|
|
2139
|
-
...operationFileEntry(node, queryName),
|
|
2140
|
-
root,
|
|
2141
|
-
output,
|
|
2142
|
-
group: group ?? void 0
|
|
2143
|
-
}),
|
|
2144
|
-
fileTs: resolveDependencyOperationFile({
|
|
2145
|
-
cache: ctx.cache,
|
|
2146
|
-
node,
|
|
2147
|
-
resolver: tsResolver,
|
|
2148
|
-
root,
|
|
2149
|
-
output: pluginTs.options?.output ?? output,
|
|
2150
|
-
group: pluginTs.options?.group
|
|
2151
|
-
})
|
|
2152
|
-
};
|
|
2153
|
-
const { queryParamsTypeName } = resolvePageParamType(node, {
|
|
2154
|
-
resolver: tsResolver,
|
|
2155
|
-
initialPageParam: infiniteOptions.initialPageParam,
|
|
2156
|
-
queryParam: infiniteOptions.queryParam
|
|
2157
|
-
});
|
|
2158
|
-
const importedTypeNames = [
|
|
2159
|
-
tsResolver.response.options(node),
|
|
2160
|
-
queryParamsTypeName,
|
|
2161
|
-
...resolveOperationTypeNames(node, tsResolver, {
|
|
2162
|
-
exclude: [queryKeyTypeName],
|
|
2163
|
-
order: "body-response-first",
|
|
2164
|
-
includeParams: false
|
|
2165
|
-
})
|
|
2166
|
-
].filter((name) => Boolean(name));
|
|
2167
|
-
const calledClientName = contractOp.name;
|
|
2168
|
-
return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(kubb_jsx.File, {
|
|
2169
|
-
baseName: meta.file.baseName,
|
|
2170
|
-
path: meta.file.path,
|
|
2171
|
-
meta: meta.file.meta,
|
|
2172
|
-
banner: resolver.default.banner(ctx.meta, {
|
|
2173
|
-
output,
|
|
2174
|
-
config,
|
|
2175
|
-
file: {
|
|
2176
|
-
path: meta.file.path,
|
|
2177
|
-
baseName: meta.file.baseName
|
|
2178
|
-
}
|
|
2179
|
-
}),
|
|
2180
|
-
footer: resolver.default.footer(ctx.meta, {
|
|
2181
|
-
output,
|
|
2182
|
-
config,
|
|
2183
|
-
file: {
|
|
2184
|
-
path: meta.file.path,
|
|
2185
|
-
baseName: meta.file.baseName
|
|
2186
|
-
}
|
|
2187
|
-
}),
|
|
2188
|
-
children: [
|
|
2189
|
-
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
2190
|
-
name: [contractOp.name],
|
|
2191
|
-
root: meta.file.path,
|
|
2192
|
-
path: contractOp.path
|
|
2193
|
-
}),
|
|
2194
|
-
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
2195
|
-
name: ["RequestConfig", "ResponseErrorConfig"],
|
|
2196
|
-
root: contractOp.clientPathIsFile ? meta.file.path : void 0,
|
|
2197
|
-
path: contractOp.clientPath,
|
|
2198
|
-
isTypeOnly: true
|
|
2199
|
-
}),
|
|
2200
|
-
customOptions && /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
2201
|
-
name: [customOptions.name],
|
|
2202
|
-
path: customOptions.importPath
|
|
2203
|
-
}),
|
|
2204
|
-
meta.fileTs && importedTypeNames.length > 0 && /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
2205
|
-
name: Array.from(new Set(importedTypeNames)),
|
|
2206
|
-
root: meta.file.path,
|
|
2207
|
-
path: meta.fileTs.path,
|
|
2208
|
-
isTypeOnly: true
|
|
2209
|
-
}),
|
|
2210
|
-
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(QueryKey, {
|
|
2211
|
-
name: queryKeyName,
|
|
2212
|
-
typeName: queryKeyTypeName,
|
|
2213
|
-
node,
|
|
2214
|
-
tsResolver,
|
|
2215
|
-
transformer: ctx.options.queryKey,
|
|
2216
|
-
variant: "suspenseInfiniteQuery"
|
|
2217
|
-
}),
|
|
2218
|
-
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
2219
|
-
name: ["InfiniteData"],
|
|
2220
|
-
isTypeOnly: true,
|
|
2221
|
-
path: importPath
|
|
2222
|
-
}),
|
|
2223
|
-
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
2224
|
-
name: ["infiniteQueryOptions"],
|
|
2225
|
-
path: importPath
|
|
2226
|
-
}),
|
|
2227
|
-
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(InfiniteQueryOptions, {
|
|
2228
|
-
name: queryOptionsName,
|
|
2229
|
-
clientName: calledClientName,
|
|
2230
|
-
queryKeyName,
|
|
2231
|
-
node,
|
|
2232
|
-
tsResolver,
|
|
2233
|
-
cursorParam: infiniteOptions.cursorParam,
|
|
2234
|
-
nextParam: infiniteOptions.nextParam,
|
|
2235
|
-
previousParam: infiniteOptions.previousParam,
|
|
2236
|
-
getNextPageParam: infiniteOptions.getNextPageParam,
|
|
2237
|
-
getPreviousPageParam: infiniteOptions.getPreviousPageParam,
|
|
2238
|
-
initialPageParam: infiniteOptions.initialPageParam,
|
|
2239
|
-
hasExplicitInitialPageParam: infiniteOptions.hasExplicitInitialPageParam,
|
|
2240
|
-
queryParam: infiniteOptions.queryParam,
|
|
2241
|
-
returnType: contractOp.returnType
|
|
2242
|
-
}),
|
|
2243
|
-
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
2244
|
-
name: ["useSuspenseInfiniteQuery"],
|
|
2245
|
-
path: importPath
|
|
2246
|
-
}),
|
|
2247
|
-
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
2248
|
-
name: [
|
|
2249
|
-
"QueryKey",
|
|
2250
|
-
"QueryClient",
|
|
2251
|
-
"UseSuspenseInfiniteQueryOptions",
|
|
2252
|
-
"UseSuspenseInfiniteQueryResult"
|
|
2253
|
-
],
|
|
2254
|
-
path: importPath,
|
|
2255
|
-
isTypeOnly: true
|
|
2256
|
-
}),
|
|
2257
|
-
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(InfiniteQuery, {
|
|
2258
|
-
name: queryName,
|
|
2259
|
-
queryOptionsName,
|
|
2260
|
-
queryKeyName,
|
|
2261
|
-
queryKeyTypeName,
|
|
2262
|
-
node,
|
|
2263
|
-
tsResolver,
|
|
2264
|
-
initialPageParam: infiniteOptions.initialPageParam,
|
|
2265
|
-
queryParam: infiniteOptions.queryParam,
|
|
2266
|
-
customOptions,
|
|
2267
|
-
suspense: true
|
|
2268
|
-
})
|
|
2269
|
-
]
|
|
2270
|
-
});
|
|
2271
|
-
}
|
|
1954
|
+
variant: "suspenseInfiniteQuery"
|
|
2272
1955
|
});
|
|
2273
1956
|
//#endregion
|
|
2274
1957
|
//#region src/generators/suspenseQueryGenerator.tsx
|
|
@@ -2279,150 +1962,9 @@ const suspenseInfiniteQueryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
2279
1962
|
* promises while loading and require a `<Suspense>` boundary in the React
|
|
2280
1963
|
* tree. TanStack Query v5+ only.
|
|
2281
1964
|
*/
|
|
2282
|
-
const suspenseQueryGenerator = (
|
|
1965
|
+
const suspenseQueryGenerator = createQueryGenerator({
|
|
2283
1966
|
name: "react-suspense-query",
|
|
2284
|
-
|
|
2285
|
-
match(node, ctx) {
|
|
2286
|
-
const operationNode = node;
|
|
2287
|
-
if (!kubb_kit.ast.isHttpOperationNode(operationNode)) return false;
|
|
2288
|
-
const { query, mutation, suspense, hooks } = ctx.options;
|
|
2289
|
-
const { isQuery, isMutation } = classifyOperation(operationNode, {
|
|
2290
|
-
query,
|
|
2291
|
-
mutation
|
|
2292
|
-
});
|
|
2293
|
-
return isQuery && !isMutation && !!suspense && hooks;
|
|
2294
|
-
},
|
|
2295
|
-
operation(node, ctx) {
|
|
2296
|
-
if (!kubb_kit.ast.isHttpOperationNode(node)) return null;
|
|
2297
|
-
const { config, driver, resolver, root } = ctx;
|
|
2298
|
-
const { output, query, client, group, customOptions } = ctx.options;
|
|
2299
|
-
const pluginTs = ctx.requirePlugin(_kubb_plugin_ts.pluginTsName);
|
|
2300
|
-
const tsResolver = driver.getResolver(_kubb_plugin_ts.pluginTsName);
|
|
2301
|
-
const importPath = query ? query.importPath : "@tanstack/react-query";
|
|
2302
|
-
const contractOp = resolveClientOperation({
|
|
2303
|
-
clientPlugin: { pluginName: client.pluginName },
|
|
2304
|
-
driver,
|
|
2305
|
-
node,
|
|
2306
|
-
root,
|
|
2307
|
-
output,
|
|
2308
|
-
cache: ctx.cache
|
|
2309
|
-
});
|
|
2310
|
-
if (!contractOp) return null;
|
|
2311
|
-
const queryName = resolver.suspenseQuery.name(node);
|
|
2312
|
-
const queryOptionsName = resolver.suspenseQuery.optionsName(node);
|
|
2313
|
-
const queryKeyName = resolver.suspenseQuery.keyName(node);
|
|
2314
|
-
const queryKeyTypeName = resolver.suspenseQuery.keyTypeName(node);
|
|
2315
|
-
const meta = {
|
|
2316
|
-
file: resolver.file({
|
|
2317
|
-
...operationFileEntry(node, queryName),
|
|
2318
|
-
root,
|
|
2319
|
-
output,
|
|
2320
|
-
group: group ?? void 0
|
|
2321
|
-
}),
|
|
2322
|
-
fileTs: resolveDependencyOperationFile({
|
|
2323
|
-
cache: ctx.cache,
|
|
2324
|
-
node,
|
|
2325
|
-
resolver: tsResolver,
|
|
2326
|
-
root,
|
|
2327
|
-
output: pluginTs.options?.output ?? output,
|
|
2328
|
-
group: pluginTs.options?.group
|
|
2329
|
-
})
|
|
2330
|
-
};
|
|
2331
|
-
const importedTypeNames = [tsResolver.response.options(node), ...resolveOperationTypeNames(node, tsResolver, {
|
|
2332
|
-
exclude: [queryKeyTypeName],
|
|
2333
|
-
order: "body-response-first",
|
|
2334
|
-
includeParams: false
|
|
2335
|
-
})].filter((name) => Boolean(name));
|
|
2336
|
-
const calledClientName = contractOp.name;
|
|
2337
|
-
return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(kubb_jsx.File, {
|
|
2338
|
-
baseName: meta.file.baseName,
|
|
2339
|
-
path: meta.file.path,
|
|
2340
|
-
meta: meta.file.meta,
|
|
2341
|
-
banner: resolver.default.banner(ctx.meta, {
|
|
2342
|
-
output,
|
|
2343
|
-
config,
|
|
2344
|
-
file: {
|
|
2345
|
-
path: meta.file.path,
|
|
2346
|
-
baseName: meta.file.baseName
|
|
2347
|
-
}
|
|
2348
|
-
}),
|
|
2349
|
-
footer: resolver.default.footer(ctx.meta, {
|
|
2350
|
-
output,
|
|
2351
|
-
config,
|
|
2352
|
-
file: {
|
|
2353
|
-
path: meta.file.path,
|
|
2354
|
-
baseName: meta.file.baseName
|
|
2355
|
-
}
|
|
2356
|
-
}),
|
|
2357
|
-
children: [
|
|
2358
|
-
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
2359
|
-
name: [contractOp.name],
|
|
2360
|
-
root: meta.file.path,
|
|
2361
|
-
path: contractOp.path
|
|
2362
|
-
}),
|
|
2363
|
-
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
2364
|
-
name: ["RequestConfig", "ResponseErrorConfig"],
|
|
2365
|
-
root: contractOp.clientPathIsFile ? meta.file.path : void 0,
|
|
2366
|
-
path: contractOp.clientPath,
|
|
2367
|
-
isTypeOnly: true
|
|
2368
|
-
}),
|
|
2369
|
-
customOptions && /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
2370
|
-
name: [customOptions.name],
|
|
2371
|
-
path: customOptions.importPath
|
|
2372
|
-
}),
|
|
2373
|
-
meta.fileTs && importedTypeNames.length > 0 && /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
2374
|
-
name: Array.from(new Set(importedTypeNames)),
|
|
2375
|
-
root: meta.file.path,
|
|
2376
|
-
path: meta.fileTs.path,
|
|
2377
|
-
isTypeOnly: true
|
|
2378
|
-
}),
|
|
2379
|
-
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(QueryKey, {
|
|
2380
|
-
name: queryKeyName,
|
|
2381
|
-
typeName: queryKeyTypeName,
|
|
2382
|
-
node,
|
|
2383
|
-
tsResolver,
|
|
2384
|
-
transformer: ctx.options.queryKey,
|
|
2385
|
-
variant: "suspenseQuery"
|
|
2386
|
-
}),
|
|
2387
|
-
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
2388
|
-
name: ["queryOptions"],
|
|
2389
|
-
path: importPath
|
|
2390
|
-
}),
|
|
2391
|
-
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(QueryOptions, {
|
|
2392
|
-
name: queryOptionsName,
|
|
2393
|
-
clientName: calledClientName,
|
|
2394
|
-
queryKeyName,
|
|
2395
|
-
node,
|
|
2396
|
-
tsResolver,
|
|
2397
|
-
returnType: contractOp.returnType
|
|
2398
|
-
}),
|
|
2399
|
-
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
2400
|
-
name: ["useSuspenseQuery"],
|
|
2401
|
-
path: importPath
|
|
2402
|
-
}),
|
|
2403
|
-
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
2404
|
-
name: [
|
|
2405
|
-
"QueryKey",
|
|
2406
|
-
"QueryClient",
|
|
2407
|
-
"UseSuspenseQueryOptions",
|
|
2408
|
-
"UseSuspenseQueryResult"
|
|
2409
|
-
],
|
|
2410
|
-
path: importPath,
|
|
2411
|
-
isTypeOnly: true
|
|
2412
|
-
}),
|
|
2413
|
-
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(Query, {
|
|
2414
|
-
name: queryName,
|
|
2415
|
-
queryOptionsName,
|
|
2416
|
-
queryKeyName,
|
|
2417
|
-
queryKeyTypeName,
|
|
2418
|
-
node,
|
|
2419
|
-
tsResolver,
|
|
2420
|
-
customOptions,
|
|
2421
|
-
suspense: true
|
|
2422
|
-
})
|
|
2423
|
-
]
|
|
2424
|
-
});
|
|
2425
|
-
}
|
|
1967
|
+
variant: "suspenseQuery"
|
|
2426
1968
|
});
|
|
2427
1969
|
//#endregion
|
|
2428
1970
|
//#region src/resolvers/resolverReactQuery.ts
|