@kubb/plugin-react-query 5.0.0-beta.3 → 5.0.0-beta.31
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/README.md +34 -83
- package/dist/{components-DTGLu4UV.js → components-BVmVgpLX.js} +379 -279
- package/dist/components-BVmVgpLX.js.map +1 -0
- package/dist/{components-dAKJEn9b.cjs → components-DLUeLMsz.cjs} +409 -279
- package/dist/components-DLUeLMsz.cjs.map +1 -0
- package/dist/components.cjs +1 -1
- package/dist/components.d.ts +4 -76
- package/dist/components.js +1 -1
- package/dist/{generators-CWEQsdO9.cjs → generators--AcF4Y4n.cjs} +332 -410
- package/dist/generators--AcF4Y4n.cjs.map +1 -0
- package/dist/{generators-C_fbcjpG.js → generators-BFn9CLBS.js} +333 -411
- package/dist/generators-BFn9CLBS.js.map +1 -0
- package/dist/generators.cjs +1 -1
- package/dist/generators.d.ts +41 -1
- package/dist/generators.js +1 -1
- package/dist/index.cjs +179 -26
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +30 -1
- package/dist/index.js +179 -26
- package/dist/index.js.map +1 -1
- package/dist/types-DiZPLTXl.d.ts +400 -0
- package/extension.yaml +1507 -0
- package/package.json +16 -18
- package/src/components/InfiniteQuery.tsx +24 -13
- package/src/components/InfiniteQueryOptions.tsx +37 -55
- package/src/components/Mutation.tsx +35 -15
- package/src/components/MutationOptions.tsx +14 -13
- package/src/components/Query.tsx +14 -10
- package/src/components/QueryOptions.tsx +17 -34
- package/src/components/SuspenseInfiniteQuery.tsx +19 -13
- package/src/components/SuspenseInfiniteQueryOptions.tsx +28 -52
- package/src/components/SuspenseQuery.tsx +9 -10
- package/src/generators/customHookOptionsFileGenerator.tsx +18 -14
- package/src/generators/hookOptionsGenerator.tsx +42 -49
- package/src/generators/infiniteQueryGenerator.tsx +55 -76
- package/src/generators/mutationGenerator.tsx +51 -62
- package/src/generators/queryGenerator.tsx +52 -61
- package/src/generators/suspenseInfiniteQueryGenerator.tsx +50 -63
- package/src/generators/suspenseQueryGenerator.tsx +54 -74
- package/src/plugin.ts +45 -31
- package/src/resolvers/resolverReactQuery.ts +102 -6
- package/src/types.ts +199 -61
- package/src/utils.ts +10 -33
- package/dist/components-DTGLu4UV.js.map +0 -1
- package/dist/components-dAKJEn9b.cjs.map +0 -1
- package/dist/generators-CWEQsdO9.cjs.map +0 -1
- package/dist/generators-C_fbcjpG.js.map +0 -1
- package/dist/types-DfaFRSBf.d.ts +0 -284
|
@@ -1,30 +1,37 @@
|
|
|
1
1
|
import "./chunk--u3MIqq1.js";
|
|
2
|
-
import { a as Mutation, c as InfiniteQuery,
|
|
2
|
+
import { _ as operationFileEntry, a as Mutation, c as InfiniteQuery, f as resolveOperationOverrides, g as getOperationParameters, i as Query, l as QueryOptions, m as MutationKey, n as SuspenseInfiniteQueryOptions, o as MutationOptions, p as resolveZodSchemaNames, r as SuspenseInfiniteQuery, s as InfiniteQueryOptions, t as SuspenseQuery, u as QueryKey, v as resolveOperationTypeNames } from "./components-BVmVgpLX.js";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { ast, defineGenerator } from "@kubb/core";
|
|
5
5
|
import { Client, pluginClientName } from "@kubb/plugin-client";
|
|
6
6
|
import { pluginTsName } from "@kubb/plugin-ts";
|
|
7
7
|
import { pluginZodName } from "@kubb/plugin-zod";
|
|
8
|
-
import { File, Function, Type,
|
|
8
|
+
import { File, Function, Type, jsxRendererSync } from "@kubb/renderer-jsx";
|
|
9
9
|
import { Fragment, jsx, jsxs } from "@kubb/renderer-jsx/jsx-runtime";
|
|
10
10
|
import fs from "node:fs";
|
|
11
11
|
import { difference } from "remeda";
|
|
12
12
|
//#region src/generators/customHookOptionsFileGenerator.tsx
|
|
13
|
+
/**
|
|
14
|
+
* Scaffolds the user-editable `useCustomHookOptions` file when
|
|
15
|
+
* `pluginReactQuery({ customOptions: { ... } })` is configured. The file is
|
|
16
|
+
* only created when it does not already exist, so user edits persist across
|
|
17
|
+
* regeneration.
|
|
18
|
+
*/
|
|
13
19
|
const customHookOptionsFileGenerator = defineGenerator({
|
|
14
20
|
name: "react-query-custom-hook-options-file",
|
|
15
|
-
renderer:
|
|
21
|
+
renderer: jsxRendererSync,
|
|
16
22
|
operations(nodes, ctx) {
|
|
17
23
|
const { resolver, config, root } = ctx;
|
|
18
|
-
const { output, customOptions, query, group
|
|
24
|
+
const { output, customOptions, query, group } = ctx.options;
|
|
19
25
|
if (!customOptions) return null;
|
|
20
26
|
const override = output.override ?? config.output.override ?? false;
|
|
21
27
|
const { importPath, name } = customOptions;
|
|
28
|
+
const hookOptionsName = resolver.resolveHookOptionsName();
|
|
29
|
+
const customHookOptionsName = resolver.resolveCustomHookOptionsName();
|
|
22
30
|
const reactQueryImportPath = query ? query.importPath : "@tanstack/react-query";
|
|
23
|
-
const capitalize = (s) => s.charAt(0).toUpperCase() + s.slice(1);
|
|
24
31
|
let hookFilePath;
|
|
25
32
|
const firstNode = nodes[0];
|
|
26
33
|
if (firstNode) {
|
|
27
|
-
const hookName =
|
|
34
|
+
const hookName = resolver.resolveQueryName(firstNode);
|
|
28
35
|
hookFilePath = resolver.resolveFile({
|
|
29
36
|
name: hookName,
|
|
30
37
|
extname: ".ts",
|
|
@@ -33,7 +40,7 @@ const customHookOptionsFileGenerator = defineGenerator({
|
|
|
33
40
|
}, {
|
|
34
41
|
root,
|
|
35
42
|
output,
|
|
36
|
-
group
|
|
43
|
+
group: group ?? void 0
|
|
37
44
|
}).path;
|
|
38
45
|
} else hookFilePath = path.resolve(root, "index.ts");
|
|
39
46
|
const ensureExtension = (filePath, extname) => {
|
|
@@ -62,7 +69,7 @@ const customHookOptionsFileGenerator = defineGenerator({
|
|
|
62
69
|
path: reactQueryImportPath
|
|
63
70
|
}),
|
|
64
71
|
/* @__PURE__ */ jsx(File.Import, {
|
|
65
|
-
name: [
|
|
72
|
+
name: [hookOptionsName],
|
|
66
73
|
root: file.path,
|
|
67
74
|
path: path.resolve(root, "./index.ts")
|
|
68
75
|
}),
|
|
@@ -71,9 +78,9 @@ const customHookOptionsFileGenerator = defineGenerator({
|
|
|
71
78
|
isExportable: true,
|
|
72
79
|
isIndexable: true,
|
|
73
80
|
children: [/* @__PURE__ */ jsx(Function, {
|
|
74
|
-
name:
|
|
81
|
+
name: customHookOptionsName,
|
|
75
82
|
params: "{ queryClient }: { queryClient: QueryClient }",
|
|
76
|
-
returnType:
|
|
83
|
+
returnType: `Partial<${hookOptionsName}>`,
|
|
77
84
|
children: `return {
|
|
78
85
|
// TODO: Define custom hook options here
|
|
79
86
|
// Example:
|
|
@@ -85,12 +92,12 @@ const customHookOptionsFileGenerator = defineGenerator({
|
|
|
85
92
|
}`
|
|
86
93
|
}), /* @__PURE__ */ jsx(Function, {
|
|
87
94
|
name,
|
|
88
|
-
generics:
|
|
95
|
+
generics: `T extends keyof ${hookOptionsName}`,
|
|
89
96
|
params: "{ hookName, operationId }: { hookName: T, operationId: string }",
|
|
90
|
-
returnType:
|
|
97
|
+
returnType: `${hookOptionsName}[T]`,
|
|
91
98
|
export: true,
|
|
92
99
|
children: `const queryClient = useQueryClient()
|
|
93
|
-
const customOptions =
|
|
100
|
+
const customOptions = ${customHookOptionsName}({ queryClient })
|
|
94
101
|
return customOptions[hookName] ?? {}`
|
|
95
102
|
})]
|
|
96
103
|
})
|
|
@@ -100,52 +107,53 @@ const customHookOptionsFileGenerator = defineGenerator({
|
|
|
100
107
|
});
|
|
101
108
|
//#endregion
|
|
102
109
|
//#region src/generators/hookOptionsGenerator.tsx
|
|
110
|
+
/**
|
|
111
|
+
* Emits the `HookOptions` type used by `customOptions`. Enabled when
|
|
112
|
+
* `pluginReactQuery({ customOptions: { ... } })`. The generated type lists
|
|
113
|
+
* every hook keyed by name so user-supplied options stay in sync with the
|
|
114
|
+
* generated hooks at compile time.
|
|
115
|
+
*/
|
|
103
116
|
const hookOptionsGenerator = defineGenerator({
|
|
104
117
|
name: "react-query-hook-options",
|
|
105
|
-
renderer:
|
|
118
|
+
renderer: jsxRendererSync,
|
|
106
119
|
operations(nodes, ctx) {
|
|
107
|
-
const { resolver, config, root
|
|
108
|
-
const { output, customOptions, query, mutation, suspense, infinite, group,
|
|
120
|
+
const { resolver, config, root } = ctx;
|
|
121
|
+
const { output, customOptions, query, mutation, suspense, infinite, group, override } = ctx.options;
|
|
109
122
|
if (!customOptions) return null;
|
|
123
|
+
const name = resolver.resolveHookOptionsName();
|
|
110
124
|
const resolvedFile = resolver.resolveFile({
|
|
111
|
-
name
|
|
125
|
+
name,
|
|
112
126
|
extname: ".ts"
|
|
113
127
|
}, {
|
|
114
128
|
root,
|
|
115
129
|
output,
|
|
116
|
-
group
|
|
130
|
+
group: group ?? void 0
|
|
117
131
|
});
|
|
118
132
|
const hookOptionsFile = {
|
|
119
133
|
...resolvedFile,
|
|
120
|
-
baseName:
|
|
121
|
-
path: resolvedFile.path.replace(/
|
|
134
|
+
baseName: `${name}.ts`,
|
|
135
|
+
path: resolvedFile.path.replace(/[^/\\]+\.ts$/, `${name}.ts`)
|
|
122
136
|
};
|
|
123
|
-
const capitalize = (s) => s.charAt(0).toUpperCase() + s.slice(1);
|
|
124
137
|
const imports = [];
|
|
125
138
|
const hookOptions = {};
|
|
126
139
|
for (const node of nodes) {
|
|
127
|
-
|
|
140
|
+
if (!ast.isHttpOperationNode(node)) continue;
|
|
128
141
|
const opOverrides = resolveOperationOverrides(node, override);
|
|
129
142
|
const nodeQuery = "query" in opOverrides ? opOverrides.query : query;
|
|
130
143
|
const nodeMutation = "mutation" in opOverrides ? opOverrides.mutation : mutation;
|
|
131
144
|
const nodeInfinite = "infinite" in opOverrides ? opOverrides.infinite : infinite;
|
|
132
|
-
const nodeInfiniteOptions = nodeInfinite && typeof nodeInfinite === "object" ? nodeInfinite :
|
|
145
|
+
const nodeInfiniteOptions = nodeInfinite && typeof nodeInfinite === "object" ? nodeInfinite : null;
|
|
133
146
|
const isQueryOp = nodeQuery === false ? !!query && query.methods.some((m) => node.method.toLowerCase() === m.toLowerCase()) : !!nodeQuery && nodeQuery.methods.some((m) => node.method.toLowerCase() === m.toLowerCase());
|
|
134
147
|
const isMutationOp = nodeMutation !== false && !isQueryOp && difference(nodeMutation ? nodeMutation.methods : [], nodeQuery ? nodeQuery.methods : []).some((m) => node.method.toLowerCase() === m.toLowerCase());
|
|
135
148
|
const isSuspenseOp = !!suspense;
|
|
136
149
|
const isInfiniteOp = !!nodeInfiniteOptions;
|
|
137
150
|
if (isQueryOp) {
|
|
138
|
-
const queryOptionsName =
|
|
139
|
-
const queryHookName =
|
|
140
|
-
const queryHookFile = resolver.resolveFile({
|
|
141
|
-
name: queryHookName,
|
|
142
|
-
extname: ".ts",
|
|
143
|
-
tag: node.tags[0] ?? "default",
|
|
144
|
-
path: node.path
|
|
145
|
-
}, {
|
|
151
|
+
const queryOptionsName = resolver.resolveQueryOptionsName(node);
|
|
152
|
+
const queryHookName = resolver.resolveQueryName(node);
|
|
153
|
+
const queryHookFile = resolver.resolveFile(operationFileEntry(node, queryHookName), {
|
|
146
154
|
root,
|
|
147
155
|
output,
|
|
148
|
-
group
|
|
156
|
+
group: group ?? void 0
|
|
149
157
|
});
|
|
150
158
|
imports.push(/* @__PURE__ */ jsx(File.Import, {
|
|
151
159
|
name: [queryOptionsName],
|
|
@@ -154,17 +162,12 @@ const hookOptionsGenerator = defineGenerator({
|
|
|
154
162
|
}));
|
|
155
163
|
hookOptions[queryHookName] = `Partial<ReturnType<typeof ${queryOptionsName}>>`;
|
|
156
164
|
if (isSuspenseOp) {
|
|
157
|
-
const suspenseOptionsName =
|
|
158
|
-
const suspenseHookName =
|
|
159
|
-
const suspenseHookFile = resolver.resolveFile({
|
|
160
|
-
name: suspenseHookName,
|
|
161
|
-
extname: ".ts",
|
|
162
|
-
tag: node.tags[0] ?? "default",
|
|
163
|
-
path: node.path
|
|
164
|
-
}, {
|
|
165
|
+
const suspenseOptionsName = resolver.resolveSuspenseQueryOptionsName(node);
|
|
166
|
+
const suspenseHookName = resolver.resolveSuspenseQueryName(node);
|
|
167
|
+
const suspenseHookFile = resolver.resolveFile(operationFileEntry(node, suspenseHookName), {
|
|
165
168
|
root,
|
|
166
169
|
output,
|
|
167
|
-
group
|
|
170
|
+
group: group ?? void 0
|
|
168
171
|
});
|
|
169
172
|
imports.push(/* @__PURE__ */ jsx(File.Import, {
|
|
170
173
|
name: [suspenseOptionsName],
|
|
@@ -175,19 +178,14 @@ const hookOptionsGenerator = defineGenerator({
|
|
|
175
178
|
}
|
|
176
179
|
if (isInfiniteOp) {
|
|
177
180
|
const normalizeKey = (key) => key.replace(/\?$/, "");
|
|
178
|
-
const queryParamKeys = node
|
|
181
|
+
const queryParamKeys = getOperationParameters(node).query.map((p) => p.name);
|
|
179
182
|
if (nodeInfiniteOptions.queryParam ? queryParamKeys.some((k) => normalizeKey(k) === nodeInfiniteOptions.queryParam) : false) {
|
|
180
|
-
const infiniteOptionsName =
|
|
181
|
-
const infiniteHookName =
|
|
182
|
-
const infiniteHookFile = resolver.resolveFile({
|
|
183
|
-
name: infiniteHookName,
|
|
184
|
-
extname: ".ts",
|
|
185
|
-
tag: node.tags[0] ?? "default",
|
|
186
|
-
path: node.path
|
|
187
|
-
}, {
|
|
183
|
+
const infiniteOptionsName = resolver.resolveInfiniteQueryOptionsName(node);
|
|
184
|
+
const infiniteHookName = resolver.resolveInfiniteQueryName(node);
|
|
185
|
+
const infiniteHookFile = resolver.resolveFile(operationFileEntry(node, infiniteHookName), {
|
|
188
186
|
root,
|
|
189
187
|
output,
|
|
190
|
-
group
|
|
188
|
+
group: group ?? void 0
|
|
191
189
|
});
|
|
192
190
|
imports.push(/* @__PURE__ */ jsx(File.Import, {
|
|
193
191
|
name: [infiniteOptionsName],
|
|
@@ -196,17 +194,12 @@ const hookOptionsGenerator = defineGenerator({
|
|
|
196
194
|
}));
|
|
197
195
|
hookOptions[infiniteHookName] = `Partial<ReturnType<typeof ${infiniteOptionsName}>>`;
|
|
198
196
|
if (isSuspenseOp) {
|
|
199
|
-
const suspenseInfiniteOptionsName =
|
|
200
|
-
const suspenseInfiniteHookName =
|
|
201
|
-
const suspenseInfiniteHookFile = resolver.resolveFile({
|
|
202
|
-
name: suspenseInfiniteHookName,
|
|
203
|
-
extname: ".ts",
|
|
204
|
-
tag: node.tags[0] ?? "default",
|
|
205
|
-
path: node.path
|
|
206
|
-
}, {
|
|
197
|
+
const suspenseInfiniteOptionsName = resolver.resolveSuspenseInfiniteQueryOptionsName(node);
|
|
198
|
+
const suspenseInfiniteHookName = resolver.resolveSuspenseInfiniteQueryName(node);
|
|
199
|
+
const suspenseInfiniteHookFile = resolver.resolveFile(operationFileEntry(node, suspenseInfiniteHookName), {
|
|
207
200
|
root,
|
|
208
201
|
output,
|
|
209
|
-
group
|
|
202
|
+
group: group ?? void 0
|
|
210
203
|
});
|
|
211
204
|
imports.push(/* @__PURE__ */ jsx(File.Import, {
|
|
212
205
|
name: [suspenseInfiniteOptionsName],
|
|
@@ -219,17 +212,12 @@ const hookOptionsGenerator = defineGenerator({
|
|
|
219
212
|
}
|
|
220
213
|
}
|
|
221
214
|
if (isMutationOp) {
|
|
222
|
-
const mutationOptionsName =
|
|
223
|
-
const mutationHookName =
|
|
224
|
-
const mutationHookFile = resolver.resolveFile({
|
|
225
|
-
name: mutationHookName,
|
|
226
|
-
extname: ".ts",
|
|
227
|
-
tag: node.tags[0] ?? "default",
|
|
228
|
-
path: node.path
|
|
229
|
-
}, {
|
|
215
|
+
const mutationOptionsName = resolver.resolveMutationOptionsName(node);
|
|
216
|
+
const mutationHookName = resolver.resolveMutationName(node);
|
|
217
|
+
const mutationHookFile = resolver.resolveFile(operationFileEntry(node, mutationHookName), {
|
|
230
218
|
root,
|
|
231
219
|
output,
|
|
232
|
-
group
|
|
220
|
+
group: group ?? void 0
|
|
233
221
|
});
|
|
234
222
|
imports.push(/* @__PURE__ */ jsx(File.Import, {
|
|
235
223
|
name: [mutationOptionsName],
|
|
@@ -239,18 +227,25 @@ const hookOptionsGenerator = defineGenerator({
|
|
|
239
227
|
hookOptions[mutationHookName] = `Partial<ReturnType<typeof ${mutationOptionsName}>>`;
|
|
240
228
|
}
|
|
241
229
|
}
|
|
242
|
-
const name = "HookOptions";
|
|
243
230
|
return /* @__PURE__ */ jsxs(File, {
|
|
244
231
|
baseName: hookOptionsFile.baseName,
|
|
245
232
|
path: hookOptionsFile.path,
|
|
246
233
|
meta: hookOptionsFile.meta,
|
|
247
|
-
banner: resolver.resolveBanner(
|
|
234
|
+
banner: resolver.resolveBanner(ctx.meta, {
|
|
248
235
|
output,
|
|
249
|
-
config
|
|
236
|
+
config,
|
|
237
|
+
file: {
|
|
238
|
+
path: hookOptionsFile.path,
|
|
239
|
+
baseName: hookOptionsFile.baseName
|
|
240
|
+
}
|
|
250
241
|
}),
|
|
251
|
-
footer: resolver.resolveFooter(
|
|
242
|
+
footer: resolver.resolveFooter(ctx.meta, {
|
|
252
243
|
output,
|
|
253
|
-
config
|
|
244
|
+
config,
|
|
245
|
+
file: {
|
|
246
|
+
path: hookOptionsFile.path,
|
|
247
|
+
baseName: hookOptionsFile.baseName
|
|
248
|
+
}
|
|
254
249
|
}),
|
|
255
250
|
children: [imports, /* @__PURE__ */ jsx(File.Source, {
|
|
256
251
|
name,
|
|
@@ -268,114 +263,100 @@ const hookOptionsGenerator = defineGenerator({
|
|
|
268
263
|
});
|
|
269
264
|
//#endregion
|
|
270
265
|
//#region src/generators/infiniteQueryGenerator.tsx
|
|
266
|
+
/**
|
|
267
|
+
* Built-in generator for `useInfiniteQuery` hooks. Enabled when
|
|
268
|
+
* `pluginReactQuery({ infinite: { ... } })`. Emits one `useFooInfiniteQuery`
|
|
269
|
+
* hook per query operation, wiring the configured `nextParam` /
|
|
270
|
+
* `previousParam` paths into TanStack Query's cursor-based pagination.
|
|
271
|
+
*/
|
|
271
272
|
const infiniteQueryGenerator = defineGenerator({
|
|
272
273
|
name: "react-infinite-query",
|
|
273
|
-
renderer:
|
|
274
|
+
renderer: jsxRendererSync,
|
|
274
275
|
operation(node, ctx) {
|
|
275
|
-
|
|
276
|
-
const {
|
|
276
|
+
if (!ast.isHttpOperationNode(node)) return null;
|
|
277
|
+
const { config, driver, resolver, root } = ctx;
|
|
278
|
+
const { output, query, mutation, infinite, paramsCasing, paramsType, pathParamsType, parser, client: clientOptions, group, customOptions } = ctx.options;
|
|
277
279
|
const pluginTs = driver.getPlugin(pluginTsName);
|
|
278
280
|
if (!pluginTs) return null;
|
|
279
281
|
const tsResolver = driver.getResolver(pluginTsName);
|
|
280
282
|
const isQuery = query === false || !!query && query.methods.some((method) => node.method.toLowerCase() === method.toLowerCase());
|
|
281
283
|
const isMutation = mutation !== false && !isQuery && difference(mutation ? mutation.methods : [], query ? query.methods : []).some((method) => node.method.toLowerCase() === method.toLowerCase());
|
|
282
|
-
const infiniteOptions = infinite && typeof infinite === "object" ? infinite :
|
|
284
|
+
const infiniteOptions = infinite && typeof infinite === "object" ? infinite : null;
|
|
283
285
|
if (!isQuery || isMutation || !infiniteOptions) return null;
|
|
284
286
|
const normalizeKey = (key) => key.replace(/\?$/, "");
|
|
285
|
-
const queryParamKeys = node
|
|
287
|
+
const queryParamKeys = getOperationParameters(node).query.map((p) => p.name);
|
|
286
288
|
const hasQueryParam = infiniteOptions.queryParam ? queryParamKeys.some((k) => normalizeKey(k) === infiniteOptions.queryParam) : false;
|
|
287
289
|
const hasCursorParam = !infiniteOptions.cursorParam || true;
|
|
288
290
|
if (!hasQueryParam || !hasCursorParam) return null;
|
|
289
291
|
const importPath = query ? query.importPath : "@tanstack/react-query";
|
|
290
|
-
const
|
|
291
|
-
const
|
|
292
|
-
const
|
|
293
|
-
const
|
|
294
|
-
const
|
|
295
|
-
const queryKeyTypeName = transformName(`${capitalize(baseName)}InfiniteQueryKey`, "type", transformers);
|
|
296
|
-
const clientBaseName = transformName(`${baseName}Infinite`, "function", transformers);
|
|
292
|
+
const queryName = resolver.resolveInfiniteQueryName(node);
|
|
293
|
+
const queryOptionsName = resolver.resolveInfiniteQueryOptionsName(node);
|
|
294
|
+
const queryKeyName = resolver.resolveInfiniteQueryKeyName(node);
|
|
295
|
+
const queryKeyTypeName = resolver.resolveInfiniteQueryKeyTypeName(node);
|
|
296
|
+
const clientBaseName = resolver.resolveInfiniteClientName(node);
|
|
297
297
|
const meta = {
|
|
298
|
-
file: resolver.resolveFile({
|
|
299
|
-
name: queryName,
|
|
300
|
-
extname: ".ts",
|
|
301
|
-
tag: node.tags[0] ?? "default",
|
|
302
|
-
path: node.path
|
|
303
|
-
}, {
|
|
298
|
+
file: resolver.resolveFile(operationFileEntry(node, queryName), {
|
|
304
299
|
root,
|
|
305
300
|
output,
|
|
306
|
-
group
|
|
301
|
+
group: group ?? void 0
|
|
307
302
|
}),
|
|
308
|
-
fileTs: tsResolver.resolveFile({
|
|
309
|
-
name: node.operationId,
|
|
310
|
-
extname: ".ts",
|
|
311
|
-
tag: node.tags[0] ?? "default",
|
|
312
|
-
path: node.path
|
|
313
|
-
}, {
|
|
303
|
+
fileTs: tsResolver.resolveFile(operationFileEntry(node, node.operationId), {
|
|
314
304
|
root,
|
|
315
305
|
output: pluginTs.options?.output ?? output,
|
|
316
|
-
group: pluginTs.options?.group
|
|
306
|
+
group: pluginTs.options?.group ?? void 0
|
|
317
307
|
})
|
|
318
308
|
};
|
|
319
|
-
const
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
...queryParams.map((p) => tsResolver.resolveQueryParamsName(node, p)),
|
|
328
|
-
...headerParams.map((p) => tsResolver.resolveHeaderParamsName(node, p)),
|
|
329
|
-
...node.responses.map((res) => tsResolver.resolveResponseStatusName(node, res.statusCode))
|
|
330
|
-
].filter((name) => !!name && name !== queryKeyTypeName);
|
|
331
|
-
const pluginZod = parser === "zod" ? driver.getPlugin(pluginZodName) : void 0;
|
|
332
|
-
const zodResolver = pluginZod ? driver.getResolver(pluginZodName) : void 0;
|
|
333
|
-
const fileZod = zodResolver ? zodResolver.resolveFile({
|
|
334
|
-
name: node.operationId,
|
|
335
|
-
extname: ".ts",
|
|
336
|
-
tag: node.tags[0] ?? "default",
|
|
337
|
-
path: node.path
|
|
338
|
-
}, {
|
|
309
|
+
const importedTypeNames = resolveOperationTypeNames(node, tsResolver, {
|
|
310
|
+
paramsCasing,
|
|
311
|
+
exclude: [queryKeyTypeName],
|
|
312
|
+
order: "body-response-first"
|
|
313
|
+
});
|
|
314
|
+
const pluginZod = parser === "zod" ? driver.getPlugin(pluginZodName) : null;
|
|
315
|
+
const zodResolver = pluginZod ? driver.getResolver(pluginZodName) : null;
|
|
316
|
+
const fileZod = zodResolver ? zodResolver.resolveFile(operationFileEntry(node, node.operationId), {
|
|
339
317
|
root,
|
|
340
318
|
output: pluginZod?.options?.output ?? output,
|
|
341
|
-
group: pluginZod?.options?.group
|
|
342
|
-
}) :
|
|
343
|
-
const zodSchemaNames =
|
|
319
|
+
group: pluginZod?.options?.group ?? void 0
|
|
320
|
+
}) : null;
|
|
321
|
+
const zodSchemaNames = resolveZodSchemaNames(node, zodResolver);
|
|
344
322
|
const clientPlugin = driver.getPlugin(pluginClientName);
|
|
345
323
|
const shouldUseClientPlugin = clientPlugin?.name === pluginClientName && clientOptions.clientType !== "class";
|
|
346
|
-
const clientResolver = shouldUseClientPlugin ? driver.getResolver(pluginClientName) :
|
|
347
|
-
const clientFile = shouldUseClientPlugin ? clientResolver?.resolveFile({
|
|
348
|
-
name: node.operationId,
|
|
349
|
-
extname: ".ts",
|
|
350
|
-
tag: node.tags[0] ?? "default",
|
|
351
|
-
path: node.path
|
|
352
|
-
}, {
|
|
324
|
+
const clientResolver = shouldUseClientPlugin ? driver.getResolver(pluginClientName) : null;
|
|
325
|
+
const clientFile = shouldUseClientPlugin ? clientResolver?.resolveFile(operationFileEntry(node, node.operationId), {
|
|
353
326
|
root,
|
|
354
327
|
output: clientPlugin?.options?.output ?? output,
|
|
355
|
-
group: clientPlugin?.options?.group
|
|
356
|
-
}) :
|
|
328
|
+
group: clientPlugin?.options?.group ?? void 0
|
|
329
|
+
}) : null;
|
|
357
330
|
const resolvedClientName = shouldUseClientPlugin ? clientResolver?.resolveName(node.operationId) ?? clientBaseName : clientBaseName;
|
|
358
331
|
return /* @__PURE__ */ jsxs(File, {
|
|
359
332
|
baseName: meta.file.baseName,
|
|
360
333
|
path: meta.file.path,
|
|
361
334
|
meta: meta.file.meta,
|
|
362
|
-
banner: resolver.resolveBanner(
|
|
335
|
+
banner: resolver.resolveBanner(ctx.meta, {
|
|
363
336
|
output,
|
|
364
|
-
config
|
|
337
|
+
config,
|
|
338
|
+
file: {
|
|
339
|
+
path: meta.file.path,
|
|
340
|
+
baseName: meta.file.baseName
|
|
341
|
+
}
|
|
365
342
|
}),
|
|
366
|
-
footer: resolver.resolveFooter(
|
|
343
|
+
footer: resolver.resolveFooter(ctx.meta, {
|
|
367
344
|
output,
|
|
368
|
-
config
|
|
345
|
+
config,
|
|
346
|
+
file: {
|
|
347
|
+
path: meta.file.path,
|
|
348
|
+
baseName: meta.file.baseName
|
|
349
|
+
}
|
|
369
350
|
}),
|
|
370
351
|
children: [
|
|
371
|
-
|
|
352
|
+
fileZod && zodSchemaNames.length > 0 && /* @__PURE__ */ jsx(File.Import, {
|
|
372
353
|
name: zodSchemaNames,
|
|
373
354
|
root: meta.file.path,
|
|
374
355
|
path: fileZod.path
|
|
375
356
|
}),
|
|
376
357
|
clientOptions.importPath ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
377
358
|
!shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
|
|
378
|
-
name: "
|
|
359
|
+
name: "client",
|
|
379
360
|
path: clientOptions.importPath
|
|
380
361
|
}),
|
|
381
362
|
/* @__PURE__ */ jsx(File.Import, {
|
|
@@ -394,9 +375,9 @@ const infiniteQueryGenerator = defineGenerator({
|
|
|
394
375
|
})
|
|
395
376
|
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
396
377
|
!shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
|
|
397
|
-
name: ["
|
|
378
|
+
name: ["client"],
|
|
398
379
|
root: meta.file.path,
|
|
399
|
-
path: path.resolve(root, ".kubb/
|
|
380
|
+
path: path.resolve(root, ".kubb/client.ts")
|
|
400
381
|
}),
|
|
401
382
|
/* @__PURE__ */ jsx(File.Import, {
|
|
402
383
|
name: [
|
|
@@ -405,13 +386,13 @@ const infiniteQueryGenerator = defineGenerator({
|
|
|
405
386
|
"ResponseErrorConfig"
|
|
406
387
|
],
|
|
407
388
|
root: meta.file.path,
|
|
408
|
-
path: path.resolve(root, ".kubb/
|
|
389
|
+
path: path.resolve(root, ".kubb/client.ts"),
|
|
409
390
|
isTypeOnly: true
|
|
410
391
|
}),
|
|
411
392
|
clientOptions.dataReturnType === "full" && /* @__PURE__ */ jsx(File.Import, {
|
|
412
393
|
name: ["ResponseConfig"],
|
|
413
394
|
root: meta.file.path,
|
|
414
|
-
path: path.resolve(root, ".kubb/
|
|
395
|
+
path: path.resolve(root, ".kubb/client.ts"),
|
|
415
396
|
isTypeOnly: true
|
|
416
397
|
})
|
|
417
398
|
] }),
|
|
@@ -516,107 +497,91 @@ const infiniteQueryGenerator = defineGenerator({
|
|
|
516
497
|
});
|
|
517
498
|
//#endregion
|
|
518
499
|
//#region src/generators/mutationGenerator.tsx
|
|
500
|
+
/**
|
|
501
|
+
* Built-in generator for `useMutation` hooks. Emits one `useFooMutation` hook
|
|
502
|
+
* per POST/PUT/DELETE operation (configurable via `mutation.methods`) plus
|
|
503
|
+
* the matching `fooMutationKey` / `fooMutationOptions` helpers.
|
|
504
|
+
*/
|
|
519
505
|
const mutationGenerator = defineGenerator({
|
|
520
506
|
name: "react-query-mutation",
|
|
521
|
-
renderer:
|
|
507
|
+
renderer: jsxRendererSync,
|
|
522
508
|
operation(node, ctx) {
|
|
523
|
-
|
|
524
|
-
const {
|
|
509
|
+
if (!ast.isHttpOperationNode(node)) return null;
|
|
510
|
+
const { config, driver, resolver, root } = ctx;
|
|
511
|
+
const { output, query, mutation, paramsCasing, paramsType, pathParamsType, parser, client: clientOptions, group, customOptions } = ctx.options;
|
|
525
512
|
const pluginTs = driver.getPlugin(pluginTsName);
|
|
526
513
|
if (!pluginTs) return null;
|
|
527
514
|
const tsResolver = driver.getResolver(pluginTsName);
|
|
528
515
|
const isQuery = query === false || !!query && query.methods.some((method) => node.method.toLowerCase() === method.toLowerCase());
|
|
529
516
|
if (!(mutation !== false && !isQuery && difference(mutation ? mutation.methods : [], query ? query.methods : []).some((method) => node.method.toLowerCase() === method.toLowerCase()))) return null;
|
|
530
517
|
const importPath = mutation ? mutation.importPath : "@tanstack/react-query";
|
|
531
|
-
const
|
|
532
|
-
const
|
|
533
|
-
const
|
|
534
|
-
const
|
|
535
|
-
const
|
|
536
|
-
const mutationKeyName = transformName(`${baseName}MutationKey`, "const", transformers);
|
|
537
|
-
const clientName = transformName(baseName, "function", transformers);
|
|
518
|
+
const mutationHookName = resolver.resolveMutationName(node);
|
|
519
|
+
const mutationTypeName = resolver.resolveMutationTypeName(node);
|
|
520
|
+
const mutationOptionsName = resolver.resolveMutationOptionsName(node);
|
|
521
|
+
const mutationKeyName = resolver.resolveMutationKeyName(node);
|
|
522
|
+
const clientName = resolver.resolveClientName(node);
|
|
538
523
|
const meta = {
|
|
539
|
-
file: resolver.resolveFile({
|
|
540
|
-
name: mutationHookName,
|
|
541
|
-
extname: ".ts",
|
|
542
|
-
tag: node.tags[0] ?? "default",
|
|
543
|
-
path: node.path
|
|
544
|
-
}, {
|
|
524
|
+
file: resolver.resolveFile(operationFileEntry(node, mutationHookName), {
|
|
545
525
|
root,
|
|
546
526
|
output,
|
|
547
|
-
group
|
|
527
|
+
group: group ?? void 0
|
|
548
528
|
}),
|
|
549
|
-
fileTs: tsResolver.resolveFile({
|
|
550
|
-
name: node.operationId,
|
|
551
|
-
extname: ".ts",
|
|
552
|
-
tag: node.tags[0] ?? "default",
|
|
553
|
-
path: node.path
|
|
554
|
-
}, {
|
|
529
|
+
fileTs: tsResolver.resolveFile(operationFileEntry(node, node.operationId), {
|
|
555
530
|
root,
|
|
556
531
|
output: pluginTs.options?.output ?? output,
|
|
557
|
-
group: pluginTs.options?.group
|
|
532
|
+
group: pluginTs.options?.group ?? void 0
|
|
558
533
|
})
|
|
559
534
|
};
|
|
560
|
-
const
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
const
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
...pathParams.map((p) => tsResolver.resolvePathParamsName(node, p)),
|
|
568
|
-
...queryParams.map((p) => tsResolver.resolveQueryParamsName(node, p)),
|
|
569
|
-
...headerParams.map((p) => tsResolver.resolveHeaderParamsName(node, p)),
|
|
570
|
-
...node.responses.map((res) => tsResolver.resolveResponseStatusName(node, res.statusCode))
|
|
571
|
-
].filter((name) => !!name);
|
|
572
|
-
const pluginZod = parser === "zod" ? driver.getPlugin(pluginZodName) : void 0;
|
|
573
|
-
const zodResolver = pluginZod ? driver.getResolver(pluginZodName) : void 0;
|
|
574
|
-
const fileZod = zodResolver ? zodResolver.resolveFile({
|
|
575
|
-
name: node.operationId,
|
|
576
|
-
extname: ".ts",
|
|
577
|
-
tag: node.tags[0] ?? "default",
|
|
578
|
-
path: node.path
|
|
579
|
-
}, {
|
|
535
|
+
const importedTypeNames = resolveOperationTypeNames(node, tsResolver, {
|
|
536
|
+
paramsCasing,
|
|
537
|
+
order: "body-response-first"
|
|
538
|
+
});
|
|
539
|
+
const pluginZod = parser === "zod" ? driver.getPlugin(pluginZodName) : null;
|
|
540
|
+
const zodResolver = pluginZod ? driver.getResolver(pluginZodName) : null;
|
|
541
|
+
const fileZod = zodResolver ? zodResolver.resolveFile(operationFileEntry(node, node.operationId), {
|
|
580
542
|
root,
|
|
581
543
|
output: pluginZod?.options?.output ?? output,
|
|
582
|
-
group: pluginZod?.options?.group
|
|
583
|
-
}) :
|
|
584
|
-
const zodSchemaNames =
|
|
544
|
+
group: pluginZod?.options?.group ?? void 0
|
|
545
|
+
}) : null;
|
|
546
|
+
const zodSchemaNames = resolveZodSchemaNames(node, zodResolver);
|
|
585
547
|
const clientPlugin = driver.getPlugin(pluginClientName);
|
|
586
548
|
const shouldUseClientPlugin = clientPlugin?.name === pluginClientName && clientOptions.clientType !== "class";
|
|
587
|
-
const clientResolver = shouldUseClientPlugin ? driver.getResolver(pluginClientName) :
|
|
588
|
-
const clientFile = shouldUseClientPlugin ? clientResolver?.resolveFile({
|
|
589
|
-
name: node.operationId,
|
|
590
|
-
extname: ".ts",
|
|
591
|
-
tag: node.tags[0] ?? "default",
|
|
592
|
-
path: node.path
|
|
593
|
-
}, {
|
|
549
|
+
const clientResolver = shouldUseClientPlugin ? driver.getResolver(pluginClientName) : null;
|
|
550
|
+
const clientFile = shouldUseClientPlugin ? clientResolver?.resolveFile(operationFileEntry(node, node.operationId), {
|
|
594
551
|
root,
|
|
595
552
|
output: clientPlugin?.options?.output ?? output,
|
|
596
|
-
group: clientPlugin?.options?.group
|
|
597
|
-
}) :
|
|
553
|
+
group: clientPlugin?.options?.group ?? void 0
|
|
554
|
+
}) : null;
|
|
598
555
|
const resolvedClientName = shouldUseClientPlugin ? clientResolver?.resolveName(node.operationId) ?? clientName : clientName;
|
|
599
556
|
return /* @__PURE__ */ jsxs(File, {
|
|
600
557
|
baseName: meta.file.baseName,
|
|
601
558
|
path: meta.file.path,
|
|
602
559
|
meta: meta.file.meta,
|
|
603
|
-
banner: resolver.resolveBanner(
|
|
560
|
+
banner: resolver.resolveBanner(ctx.meta, {
|
|
604
561
|
output,
|
|
605
|
-
config
|
|
562
|
+
config,
|
|
563
|
+
file: {
|
|
564
|
+
path: meta.file.path,
|
|
565
|
+
baseName: meta.file.baseName
|
|
566
|
+
}
|
|
606
567
|
}),
|
|
607
|
-
footer: resolver.resolveFooter(
|
|
568
|
+
footer: resolver.resolveFooter(ctx.meta, {
|
|
608
569
|
output,
|
|
609
|
-
config
|
|
570
|
+
config,
|
|
571
|
+
file: {
|
|
572
|
+
path: meta.file.path,
|
|
573
|
+
baseName: meta.file.baseName
|
|
574
|
+
}
|
|
610
575
|
}),
|
|
611
576
|
children: [
|
|
612
|
-
|
|
577
|
+
fileZod && zodSchemaNames.length > 0 && /* @__PURE__ */ jsx(File.Import, {
|
|
613
578
|
name: zodSchemaNames,
|
|
614
579
|
root: meta.file.path,
|
|
615
580
|
path: fileZod.path
|
|
616
581
|
}),
|
|
617
582
|
clientOptions.importPath ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
618
583
|
!shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
|
|
619
|
-
name: "
|
|
584
|
+
name: "client",
|
|
620
585
|
path: clientOptions.importPath
|
|
621
586
|
}),
|
|
622
587
|
/* @__PURE__ */ jsx(File.Import, {
|
|
@@ -635,9 +600,9 @@ const mutationGenerator = defineGenerator({
|
|
|
635
600
|
})
|
|
636
601
|
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
637
602
|
!shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
|
|
638
|
-
name: ["
|
|
603
|
+
name: ["client"],
|
|
639
604
|
root: meta.file.path,
|
|
640
|
-
path: path.resolve(root, ".kubb/
|
|
605
|
+
path: path.resolve(root, ".kubb/client.ts")
|
|
641
606
|
}),
|
|
642
607
|
/* @__PURE__ */ jsx(File.Import, {
|
|
643
608
|
name: [
|
|
@@ -646,13 +611,13 @@ const mutationGenerator = defineGenerator({
|
|
|
646
611
|
"ResponseErrorConfig"
|
|
647
612
|
],
|
|
648
613
|
root: meta.file.path,
|
|
649
|
-
path: path.resolve(root, ".kubb/
|
|
614
|
+
path: path.resolve(root, ".kubb/client.ts"),
|
|
650
615
|
isTypeOnly: true
|
|
651
616
|
}),
|
|
652
617
|
clientOptions.dataReturnType === "full" && /* @__PURE__ */ jsx(File.Import, {
|
|
653
618
|
name: ["ResponseConfig"],
|
|
654
619
|
root: meta.file.path,
|
|
655
|
-
path: path.resolve(root, ".kubb/
|
|
620
|
+
path: path.resolve(root, ".kubb/client.ts"),
|
|
656
621
|
isTypeOnly: true
|
|
657
622
|
})
|
|
658
623
|
] }),
|
|
@@ -661,7 +626,7 @@ const mutationGenerator = defineGenerator({
|
|
|
661
626
|
root: meta.file.path,
|
|
662
627
|
path: clientFile.path
|
|
663
628
|
}),
|
|
664
|
-
!shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
|
|
629
|
+
!shouldUseClientPlugin && node.requestBody?.content?.some((e) => e.contentType === "multipart/form-data") && /* @__PURE__ */ jsx(File.Import, {
|
|
665
630
|
name: ["buildFormData"],
|
|
666
631
|
root: meta.file.path,
|
|
667
632
|
path: path.resolve(root, ".kubb/config.ts")
|
|
@@ -743,12 +708,18 @@ const mutationGenerator = defineGenerator({
|
|
|
743
708
|
});
|
|
744
709
|
//#endregion
|
|
745
710
|
//#region src/generators/queryGenerator.tsx
|
|
711
|
+
/**
|
|
712
|
+
* Built-in generator for `useQuery` hooks. Emits one `useFooQuery` hook per
|
|
713
|
+
* GET operation (configurable via `query.methods`) plus the matching
|
|
714
|
+
* `fooQueryKey` / `fooQueryOptions` helpers.
|
|
715
|
+
*/
|
|
746
716
|
const queryGenerator = defineGenerator({
|
|
747
717
|
name: "react-query",
|
|
748
|
-
renderer:
|
|
718
|
+
renderer: jsxRendererSync,
|
|
749
719
|
operation(node, ctx) {
|
|
750
|
-
|
|
751
|
-
const {
|
|
720
|
+
if (!ast.isHttpOperationNode(node)) return null;
|
|
721
|
+
const { config, driver, resolver, root } = ctx;
|
|
722
|
+
const { output, query, mutation, paramsCasing, paramsType, pathParamsType, parser, client: clientOptions, group, customOptions } = ctx.options;
|
|
752
723
|
const pluginTs = driver.getPlugin(pluginTsName);
|
|
753
724
|
if (!pluginTs) return null;
|
|
754
725
|
const tsResolver = driver.getResolver(pluginTsName);
|
|
@@ -756,95 +727,74 @@ const queryGenerator = defineGenerator({
|
|
|
756
727
|
const isMutation = mutation !== false && !isQuery && difference(mutation ? mutation.methods : [], query ? query.methods : []).some((method) => node.method.toLowerCase() === method.toLowerCase());
|
|
757
728
|
if (!isQuery || isMutation) return null;
|
|
758
729
|
const importPath = query ? query.importPath : "@tanstack/react-query";
|
|
759
|
-
const
|
|
760
|
-
const
|
|
761
|
-
const
|
|
762
|
-
const
|
|
763
|
-
const
|
|
764
|
-
const queryKeyTypeName = transformName(`${capitalize(baseName)}QueryKey`, "type", transformers);
|
|
765
|
-
const clientName = transformName(baseName, "function", transformers);
|
|
730
|
+
const queryName = resolver.resolveQueryName(node);
|
|
731
|
+
const queryOptionsName = resolver.resolveQueryOptionsName(node);
|
|
732
|
+
const queryKeyName = resolver.resolveQueryKeyName(node);
|
|
733
|
+
const queryKeyTypeName = resolver.resolveQueryKeyTypeName(node);
|
|
734
|
+
const clientName = resolver.resolveClientName(node);
|
|
766
735
|
const meta = {
|
|
767
|
-
file: resolver.resolveFile({
|
|
768
|
-
name: queryName,
|
|
769
|
-
extname: ".ts",
|
|
770
|
-
tag: node.tags[0] ?? "default",
|
|
771
|
-
path: node.path
|
|
772
|
-
}, {
|
|
736
|
+
file: resolver.resolveFile(operationFileEntry(node, queryName), {
|
|
773
737
|
root,
|
|
774
738
|
output,
|
|
775
|
-
group
|
|
739
|
+
group: group ?? void 0
|
|
776
740
|
}),
|
|
777
|
-
fileTs: tsResolver.resolveFile({
|
|
778
|
-
name: node.operationId,
|
|
779
|
-
extname: ".ts",
|
|
780
|
-
tag: node.tags[0] ?? "default",
|
|
781
|
-
path: node.path
|
|
782
|
-
}, {
|
|
741
|
+
fileTs: tsResolver.resolveFile(operationFileEntry(node, node.operationId), {
|
|
783
742
|
root,
|
|
784
743
|
output: pluginTs.options?.output ?? output,
|
|
785
|
-
group: pluginTs.options?.group
|
|
744
|
+
group: pluginTs.options?.group ?? void 0
|
|
786
745
|
})
|
|
787
746
|
};
|
|
788
|
-
const
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
...queryParams.map((p) => tsResolver.resolveQueryParamsName(node, p)),
|
|
797
|
-
...headerParams.map((p) => tsResolver.resolveHeaderParamsName(node, p)),
|
|
798
|
-
...node.responses.map((res) => tsResolver.resolveResponseStatusName(node, res.statusCode))
|
|
799
|
-
].filter((name) => !!name && name !== queryKeyTypeName);
|
|
800
|
-
const pluginZod = parser === "zod" ? driver.getPlugin(pluginZodName) : void 0;
|
|
801
|
-
const zodResolver = pluginZod ? driver.getResolver(pluginZodName) : void 0;
|
|
802
|
-
const fileZod = zodResolver ? zodResolver.resolveFile({
|
|
803
|
-
name: node.operationId,
|
|
804
|
-
extname: ".ts",
|
|
805
|
-
tag: node.tags[0] ?? "default",
|
|
806
|
-
path: node.path
|
|
807
|
-
}, {
|
|
747
|
+
const importedTypeNames = resolveOperationTypeNames(node, tsResolver, {
|
|
748
|
+
paramsCasing,
|
|
749
|
+
exclude: [queryKeyTypeName],
|
|
750
|
+
order: "body-response-first"
|
|
751
|
+
});
|
|
752
|
+
const pluginZod = parser === "zod" ? driver.getPlugin(pluginZodName) : null;
|
|
753
|
+
const zodResolver = pluginZod ? driver.getResolver(pluginZodName) : null;
|
|
754
|
+
const fileZod = zodResolver ? zodResolver.resolveFile(operationFileEntry(node, node.operationId), {
|
|
808
755
|
root,
|
|
809
756
|
output: pluginZod?.options?.output ?? output,
|
|
810
|
-
group: pluginZod?.options?.group
|
|
811
|
-
}) :
|
|
812
|
-
const zodSchemaNames =
|
|
757
|
+
group: pluginZod?.options?.group ?? void 0
|
|
758
|
+
}) : null;
|
|
759
|
+
const zodSchemaNames = resolveZodSchemaNames(node, zodResolver);
|
|
813
760
|
const clientPlugin = driver.getPlugin(pluginClientName);
|
|
814
761
|
const shouldUseClientPlugin = clientPlugin?.name === pluginClientName && clientOptions.clientType !== "class";
|
|
815
|
-
const clientResolver = shouldUseClientPlugin ? driver.getResolver(pluginClientName) :
|
|
816
|
-
const clientFile = shouldUseClientPlugin ? clientResolver?.resolveFile({
|
|
817
|
-
name: node.operationId,
|
|
818
|
-
extname: ".ts",
|
|
819
|
-
tag: node.tags[0] ?? "default",
|
|
820
|
-
path: node.path
|
|
821
|
-
}, {
|
|
762
|
+
const clientResolver = shouldUseClientPlugin ? driver.getResolver(pluginClientName) : null;
|
|
763
|
+
const clientFile = shouldUseClientPlugin ? clientResolver?.resolveFile(operationFileEntry(node, node.operationId), {
|
|
822
764
|
root,
|
|
823
765
|
output: clientPlugin?.options?.output ?? output,
|
|
824
|
-
group: clientPlugin?.options?.group
|
|
825
|
-
}) :
|
|
766
|
+
group: clientPlugin?.options?.group ?? void 0
|
|
767
|
+
}) : null;
|
|
826
768
|
const resolvedClientName = shouldUseClientPlugin ? clientResolver?.resolveName(node.operationId) ?? clientName : clientName;
|
|
827
769
|
return /* @__PURE__ */ jsxs(File, {
|
|
828
770
|
baseName: meta.file.baseName,
|
|
829
771
|
path: meta.file.path,
|
|
830
772
|
meta: meta.file.meta,
|
|
831
|
-
banner: resolver.resolveBanner(
|
|
773
|
+
banner: resolver.resolveBanner(ctx.meta, {
|
|
832
774
|
output,
|
|
833
|
-
config
|
|
775
|
+
config,
|
|
776
|
+
file: {
|
|
777
|
+
path: meta.file.path,
|
|
778
|
+
baseName: meta.file.baseName
|
|
779
|
+
}
|
|
834
780
|
}),
|
|
835
|
-
footer: resolver.resolveFooter(
|
|
781
|
+
footer: resolver.resolveFooter(ctx.meta, {
|
|
836
782
|
output,
|
|
837
|
-
config
|
|
783
|
+
config,
|
|
784
|
+
file: {
|
|
785
|
+
path: meta.file.path,
|
|
786
|
+
baseName: meta.file.baseName
|
|
787
|
+
}
|
|
838
788
|
}),
|
|
839
789
|
children: [
|
|
840
|
-
|
|
790
|
+
fileZod && zodSchemaNames.length > 0 && /* @__PURE__ */ jsx(File.Import, {
|
|
841
791
|
name: zodSchemaNames,
|
|
842
792
|
root: meta.file.path,
|
|
843
793
|
path: fileZod.path
|
|
844
794
|
}),
|
|
845
795
|
clientOptions.importPath ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
846
796
|
!shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
|
|
847
|
-
name: "
|
|
797
|
+
name: "client",
|
|
848
798
|
path: clientOptions.importPath
|
|
849
799
|
}),
|
|
850
800
|
/* @__PURE__ */ jsx(File.Import, {
|
|
@@ -863,9 +813,9 @@ const queryGenerator = defineGenerator({
|
|
|
863
813
|
})
|
|
864
814
|
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
865
815
|
!shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
|
|
866
|
-
name: ["
|
|
816
|
+
name: ["client"],
|
|
867
817
|
root: meta.file.path,
|
|
868
|
-
path: path.resolve(root, ".kubb/
|
|
818
|
+
path: path.resolve(root, ".kubb/client.ts")
|
|
869
819
|
}),
|
|
870
820
|
/* @__PURE__ */ jsx(File.Import, {
|
|
871
821
|
name: [
|
|
@@ -874,13 +824,13 @@ const queryGenerator = defineGenerator({
|
|
|
874
824
|
"ResponseErrorConfig"
|
|
875
825
|
],
|
|
876
826
|
root: meta.file.path,
|
|
877
|
-
path: path.resolve(root, ".kubb/
|
|
827
|
+
path: path.resolve(root, ".kubb/client.ts"),
|
|
878
828
|
isTypeOnly: true
|
|
879
829
|
}),
|
|
880
830
|
clientOptions.dataReturnType === "full" && /* @__PURE__ */ jsx(File.Import, {
|
|
881
831
|
name: ["ResponseConfig"],
|
|
882
832
|
root: meta.file.path,
|
|
883
|
-
path: path.resolve(root, ".kubb/
|
|
833
|
+
path: path.resolve(root, ".kubb/client.ts"),
|
|
884
834
|
isTypeOnly: true
|
|
885
835
|
})
|
|
886
836
|
] }),
|
|
@@ -975,115 +925,100 @@ const queryGenerator = defineGenerator({
|
|
|
975
925
|
});
|
|
976
926
|
//#endregion
|
|
977
927
|
//#region src/generators/suspenseInfiniteQueryGenerator.tsx
|
|
928
|
+
/**
|
|
929
|
+
* Built-in generator for `useSuspenseInfiniteQuery` hooks. Enabled when both
|
|
930
|
+
* `suspense` and `infinite` are configured. Combines suspense semantics with
|
|
931
|
+
* cursor-based pagination — handlers throw promises while loading and pull
|
|
932
|
+
* additional pages on demand.
|
|
933
|
+
*/
|
|
978
934
|
const suspenseInfiniteQueryGenerator = defineGenerator({
|
|
979
935
|
name: "react-suspense-infinite-query",
|
|
980
|
-
renderer:
|
|
936
|
+
renderer: jsxRendererSync,
|
|
981
937
|
operation(node, ctx) {
|
|
982
|
-
|
|
983
|
-
const {
|
|
938
|
+
if (!ast.isHttpOperationNode(node)) return null;
|
|
939
|
+
const { config, driver, resolver, root } = ctx;
|
|
940
|
+
const { output, query, mutation, infinite, suspense, paramsCasing, paramsType, pathParamsType, parser, client: clientOptions, group, customOptions } = ctx.options;
|
|
984
941
|
const pluginTs = driver.getPlugin(pluginTsName);
|
|
985
942
|
if (!pluginTs) return null;
|
|
986
943
|
const tsResolver = driver.getResolver(pluginTsName);
|
|
987
944
|
const isQuery = query === false || !!query && query.methods.some((method) => node.method.toLowerCase() === method.toLowerCase());
|
|
988
945
|
const isMutation = mutation !== false && !isQuery && difference(mutation ? mutation.methods : [], query ? query.methods : []).some((method) => node.method.toLowerCase() === method.toLowerCase());
|
|
989
946
|
const isSuspense = !!suspense;
|
|
990
|
-
const infiniteOptions = infinite && typeof infinite === "object" ? infinite :
|
|
947
|
+
const infiniteOptions = infinite && typeof infinite === "object" ? infinite : null;
|
|
991
948
|
if (!isQuery || isMutation || !isSuspense || !infiniteOptions) return null;
|
|
992
949
|
const normalizeKey = (key) => key.replace(/\?$/, "");
|
|
993
|
-
const queryParamKeys = node
|
|
950
|
+
const queryParamKeys = getOperationParameters(node).query.map((p) => p.name);
|
|
994
951
|
const hasQueryParam = infiniteOptions.queryParam ? queryParamKeys.some((k) => normalizeKey(k) === infiniteOptions.queryParam) : false;
|
|
995
952
|
const hasCursorParam = !infiniteOptions.cursorParam || true;
|
|
996
953
|
if (!hasQueryParam || !hasCursorParam) return null;
|
|
997
954
|
const importPath = query ? query.importPath : "@tanstack/react-query";
|
|
998
|
-
const
|
|
999
|
-
const
|
|
1000
|
-
const
|
|
1001
|
-
const
|
|
1002
|
-
const
|
|
1003
|
-
const queryKeyTypeName = transformName(`${capitalize(baseName)}SuspenseInfiniteQueryKey`, "type", transformers);
|
|
1004
|
-
const clientBaseName = transformName(`${baseName}SuspenseInfinite`, "function", transformers);
|
|
955
|
+
const queryName = resolver.resolveSuspenseInfiniteQueryName(node);
|
|
956
|
+
const queryOptionsName = resolver.resolveSuspenseInfiniteQueryOptionsName(node);
|
|
957
|
+
const queryKeyName = resolver.resolveSuspenseInfiniteQueryKeyName(node);
|
|
958
|
+
const queryKeyTypeName = resolver.resolveSuspenseInfiniteQueryKeyTypeName(node);
|
|
959
|
+
const clientBaseName = resolver.resolveSuspenseInfiniteClientName(node);
|
|
1005
960
|
const meta = {
|
|
1006
|
-
file: resolver.resolveFile({
|
|
1007
|
-
name: queryName,
|
|
1008
|
-
extname: ".ts",
|
|
1009
|
-
tag: node.tags[0] ?? "default",
|
|
1010
|
-
path: node.path
|
|
1011
|
-
}, {
|
|
961
|
+
file: resolver.resolveFile(operationFileEntry(node, queryName), {
|
|
1012
962
|
root,
|
|
1013
963
|
output,
|
|
1014
|
-
group
|
|
964
|
+
group: group ?? void 0
|
|
1015
965
|
}),
|
|
1016
|
-
fileTs: tsResolver.resolveFile({
|
|
1017
|
-
name: node.operationId,
|
|
1018
|
-
extname: ".ts",
|
|
1019
|
-
tag: node.tags[0] ?? "default",
|
|
1020
|
-
path: node.path
|
|
1021
|
-
}, {
|
|
966
|
+
fileTs: tsResolver.resolveFile(operationFileEntry(node, node.operationId), {
|
|
1022
967
|
root,
|
|
1023
968
|
output: pluginTs.options?.output ?? output,
|
|
1024
|
-
group: pluginTs.options?.group
|
|
969
|
+
group: pluginTs.options?.group ?? void 0
|
|
1025
970
|
})
|
|
1026
971
|
};
|
|
1027
|
-
const
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
const
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
...pathParams.map((p) => tsResolver.resolvePathParamsName(node, p)),
|
|
1035
|
-
...queryParams.map((p) => tsResolver.resolveQueryParamsName(node, p)),
|
|
1036
|
-
...headerParams.map((p) => tsResolver.resolveHeaderParamsName(node, p)),
|
|
1037
|
-
...node.responses.map((res) => tsResolver.resolveResponseStatusName(node, res.statusCode))
|
|
1038
|
-
].filter(Boolean);
|
|
1039
|
-
const pluginZod = parser === "zod" ? driver.getPlugin(pluginZodName) : void 0;
|
|
1040
|
-
const zodResolver = pluginZod ? driver.getResolver(pluginZodName) : void 0;
|
|
1041
|
-
const fileZod = zodResolver ? zodResolver.resolveFile({
|
|
1042
|
-
name: node.operationId,
|
|
1043
|
-
extname: ".ts",
|
|
1044
|
-
tag: node.tags[0] ?? "default",
|
|
1045
|
-
path: node.path
|
|
1046
|
-
}, {
|
|
972
|
+
const importedTypeNames = resolveOperationTypeNames(node, tsResolver, {
|
|
973
|
+
paramsCasing,
|
|
974
|
+
order: "body-response-first"
|
|
975
|
+
});
|
|
976
|
+
const pluginZod = parser === "zod" ? driver.getPlugin(pluginZodName) : null;
|
|
977
|
+
const zodResolver = pluginZod ? driver.getResolver(pluginZodName) : null;
|
|
978
|
+
const fileZod = zodResolver ? zodResolver.resolveFile(operationFileEntry(node, node.operationId), {
|
|
1047
979
|
root,
|
|
1048
980
|
output: pluginZod?.options?.output ?? output,
|
|
1049
|
-
group: pluginZod?.options?.group
|
|
1050
|
-
}) :
|
|
1051
|
-
const zodSchemaNames =
|
|
981
|
+
group: pluginZod?.options?.group ?? void 0
|
|
982
|
+
}) : null;
|
|
983
|
+
const zodSchemaNames = resolveZodSchemaNames(node, zodResolver);
|
|
1052
984
|
const clientPlugin = driver.getPlugin(pluginClientName);
|
|
1053
985
|
const shouldUseClientPlugin = clientPlugin?.name === pluginClientName && clientOptions.clientType !== "class";
|
|
1054
|
-
const clientResolver = shouldUseClientPlugin ? driver.getResolver(pluginClientName) :
|
|
1055
|
-
const clientFile = shouldUseClientPlugin ? clientResolver?.resolveFile({
|
|
1056
|
-
name: node.operationId,
|
|
1057
|
-
extname: ".ts",
|
|
1058
|
-
tag: node.tags[0] ?? "default",
|
|
1059
|
-
path: node.path
|
|
1060
|
-
}, {
|
|
986
|
+
const clientResolver = shouldUseClientPlugin ? driver.getResolver(pluginClientName) : null;
|
|
987
|
+
const clientFile = shouldUseClientPlugin ? clientResolver?.resolveFile(operationFileEntry(node, node.operationId), {
|
|
1061
988
|
root,
|
|
1062
989
|
output: clientPlugin?.options?.output ?? output,
|
|
1063
|
-
group: clientPlugin?.options?.group
|
|
1064
|
-
}) :
|
|
990
|
+
group: clientPlugin?.options?.group ?? void 0
|
|
991
|
+
}) : null;
|
|
1065
992
|
const resolvedClientName = shouldUseClientPlugin ? clientResolver?.resolveName(node.operationId) ?? clientBaseName : clientBaseName;
|
|
1066
993
|
return /* @__PURE__ */ jsxs(File, {
|
|
1067
994
|
baseName: meta.file.baseName,
|
|
1068
995
|
path: meta.file.path,
|
|
1069
996
|
meta: meta.file.meta,
|
|
1070
|
-
banner: resolver.resolveBanner(
|
|
997
|
+
banner: resolver.resolveBanner(ctx.meta, {
|
|
1071
998
|
output,
|
|
1072
|
-
config
|
|
999
|
+
config,
|
|
1000
|
+
file: {
|
|
1001
|
+
path: meta.file.path,
|
|
1002
|
+
baseName: meta.file.baseName
|
|
1003
|
+
}
|
|
1073
1004
|
}),
|
|
1074
|
-
footer: resolver.resolveFooter(
|
|
1005
|
+
footer: resolver.resolveFooter(ctx.meta, {
|
|
1075
1006
|
output,
|
|
1076
|
-
config
|
|
1007
|
+
config,
|
|
1008
|
+
file: {
|
|
1009
|
+
path: meta.file.path,
|
|
1010
|
+
baseName: meta.file.baseName
|
|
1011
|
+
}
|
|
1077
1012
|
}),
|
|
1078
1013
|
children: [
|
|
1079
|
-
|
|
1014
|
+
fileZod && zodSchemaNames.length > 0 && /* @__PURE__ */ jsx(File.Import, {
|
|
1080
1015
|
name: zodSchemaNames,
|
|
1081
1016
|
root: meta.file.path,
|
|
1082
1017
|
path: fileZod.path
|
|
1083
1018
|
}),
|
|
1084
1019
|
clientOptions.importPath ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1085
1020
|
!shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
|
|
1086
|
-
name: "
|
|
1021
|
+
name: "client",
|
|
1087
1022
|
path: clientOptions.importPath
|
|
1088
1023
|
}),
|
|
1089
1024
|
/* @__PURE__ */ jsx(File.Import, {
|
|
@@ -1102,9 +1037,9 @@ const suspenseInfiniteQueryGenerator = defineGenerator({
|
|
|
1102
1037
|
})
|
|
1103
1038
|
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1104
1039
|
!shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
|
|
1105
|
-
name: ["
|
|
1040
|
+
name: ["client"],
|
|
1106
1041
|
root: meta.file.path,
|
|
1107
|
-
path: path.resolve(root, ".kubb/
|
|
1042
|
+
path: path.resolve(root, ".kubb/client.ts")
|
|
1108
1043
|
}),
|
|
1109
1044
|
/* @__PURE__ */ jsx(File.Import, {
|
|
1110
1045
|
name: [
|
|
@@ -1113,13 +1048,13 @@ const suspenseInfiniteQueryGenerator = defineGenerator({
|
|
|
1113
1048
|
"ResponseErrorConfig"
|
|
1114
1049
|
],
|
|
1115
1050
|
root: meta.file.path,
|
|
1116
|
-
path: path.resolve(root, ".kubb/
|
|
1051
|
+
path: path.resolve(root, ".kubb/client.ts"),
|
|
1117
1052
|
isTypeOnly: true
|
|
1118
1053
|
}),
|
|
1119
1054
|
clientOptions.dataReturnType === "full" && /* @__PURE__ */ jsx(File.Import, {
|
|
1120
1055
|
name: ["ResponseConfig"],
|
|
1121
1056
|
root: meta.file.path,
|
|
1122
|
-
path: path.resolve(root, ".kubb/
|
|
1057
|
+
path: path.resolve(root, ".kubb/client.ts"),
|
|
1123
1058
|
isTypeOnly: true
|
|
1124
1059
|
})
|
|
1125
1060
|
] }),
|
|
@@ -1224,12 +1159,19 @@ const suspenseInfiniteQueryGenerator = defineGenerator({
|
|
|
1224
1159
|
});
|
|
1225
1160
|
//#endregion
|
|
1226
1161
|
//#region src/generators/suspenseQueryGenerator.tsx
|
|
1162
|
+
/**
|
|
1163
|
+
* Built-in generator for `useSuspenseQuery` hooks. Enabled when
|
|
1164
|
+
* `pluginReactQuery({ suspense: {} })`. Emits one `useFooSuspenseQuery` hook
|
|
1165
|
+
* per query operation. Suspense queries throw promises while loading and
|
|
1166
|
+
* require a `<Suspense>` boundary in the React tree. TanStack Query v5+ only.
|
|
1167
|
+
*/
|
|
1227
1168
|
const suspenseQueryGenerator = defineGenerator({
|
|
1228
1169
|
name: "react-suspense-query",
|
|
1229
|
-
renderer:
|
|
1170
|
+
renderer: jsxRendererSync,
|
|
1230
1171
|
operation(node, ctx) {
|
|
1231
|
-
|
|
1232
|
-
const {
|
|
1172
|
+
if (!ast.isHttpOperationNode(node)) return null;
|
|
1173
|
+
const { config, driver, resolver, root } = ctx;
|
|
1174
|
+
const { output, query, mutation, suspense, paramsCasing, paramsType, pathParamsType, parser, client: clientOptions, group, customOptions } = ctx.options;
|
|
1233
1175
|
const pluginTs = driver.getPlugin(pluginTsName);
|
|
1234
1176
|
if (!pluginTs) return null;
|
|
1235
1177
|
const tsResolver = driver.getResolver(pluginTsName);
|
|
@@ -1237,95 +1179,74 @@ const suspenseQueryGenerator = defineGenerator({
|
|
|
1237
1179
|
const isMutation = mutation !== false && !isQuery && difference(mutation ? mutation.methods : [], query ? query.methods : []).some((method) => node.method.toLowerCase() === method.toLowerCase());
|
|
1238
1180
|
if (!isQuery || isMutation || !!!suspense) return null;
|
|
1239
1181
|
const importPath = query ? query.importPath : "@tanstack/react-query";
|
|
1240
|
-
const
|
|
1241
|
-
const
|
|
1242
|
-
const
|
|
1243
|
-
const
|
|
1244
|
-
const
|
|
1245
|
-
const queryKeyTypeName = transformName(`${capitalize(baseName)}SuspenseQueryKey`, "type", transformers);
|
|
1246
|
-
const clientName = transformName(`${baseName}Suspense`, "function", transformers);
|
|
1182
|
+
const queryName = resolver.resolveSuspenseQueryName(node);
|
|
1183
|
+
const queryOptionsName = resolver.resolveSuspenseQueryOptionsName(node);
|
|
1184
|
+
const queryKeyName = resolver.resolveSuspenseQueryKeyName(node);
|
|
1185
|
+
const queryKeyTypeName = resolver.resolveSuspenseQueryKeyTypeName(node);
|
|
1186
|
+
const clientName = resolver.resolveSuspenseClientName(node);
|
|
1247
1187
|
const meta = {
|
|
1248
|
-
file: resolver.resolveFile({
|
|
1249
|
-
name: queryName,
|
|
1250
|
-
extname: ".ts",
|
|
1251
|
-
tag: node.tags[0] ?? "default",
|
|
1252
|
-
path: node.path
|
|
1253
|
-
}, {
|
|
1188
|
+
file: resolver.resolveFile(operationFileEntry(node, queryName), {
|
|
1254
1189
|
root,
|
|
1255
1190
|
output,
|
|
1256
|
-
group
|
|
1191
|
+
group: group ?? void 0
|
|
1257
1192
|
}),
|
|
1258
|
-
fileTs: tsResolver.resolveFile({
|
|
1259
|
-
name: node.operationId,
|
|
1260
|
-
extname: ".ts",
|
|
1261
|
-
tag: node.tags[0] ?? "default",
|
|
1262
|
-
path: node.path
|
|
1263
|
-
}, {
|
|
1193
|
+
fileTs: tsResolver.resolveFile(operationFileEntry(node, node.operationId), {
|
|
1264
1194
|
root,
|
|
1265
1195
|
output: pluginTs.options?.output ?? output,
|
|
1266
|
-
group: pluginTs.options?.group
|
|
1196
|
+
group: pluginTs.options?.group ?? void 0
|
|
1267
1197
|
})
|
|
1268
1198
|
};
|
|
1269
|
-
const
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
...queryParams.map((p) => tsResolver.resolveQueryParamsName(node, p)),
|
|
1278
|
-
...headerParams.map((p) => tsResolver.resolveHeaderParamsName(node, p)),
|
|
1279
|
-
...node.responses.map((res) => tsResolver.resolveResponseStatusName(node, res.statusCode))
|
|
1280
|
-
].filter((name) => !!name && name !== queryKeyTypeName);
|
|
1281
|
-
const pluginZod = parser === "zod" ? driver.getPlugin(pluginZodName) : void 0;
|
|
1282
|
-
const zodResolver = pluginZod ? driver.getResolver(pluginZodName) : void 0;
|
|
1283
|
-
const fileZod = zodResolver ? zodResolver.resolveFile({
|
|
1284
|
-
name: node.operationId,
|
|
1285
|
-
extname: ".ts",
|
|
1286
|
-
tag: node.tags[0] ?? "default",
|
|
1287
|
-
path: node.path
|
|
1288
|
-
}, {
|
|
1199
|
+
const importedTypeNames = resolveOperationTypeNames(node, tsResolver, {
|
|
1200
|
+
paramsCasing,
|
|
1201
|
+
exclude: [queryKeyTypeName],
|
|
1202
|
+
order: "body-response-first"
|
|
1203
|
+
});
|
|
1204
|
+
const pluginZod = parser === "zod" ? driver.getPlugin(pluginZodName) : null;
|
|
1205
|
+
const zodResolver = pluginZod ? driver.getResolver(pluginZodName) : null;
|
|
1206
|
+
const fileZod = zodResolver ? zodResolver.resolveFile(operationFileEntry(node, node.operationId), {
|
|
1289
1207
|
root,
|
|
1290
1208
|
output: pluginZod?.options?.output ?? output,
|
|
1291
|
-
group: pluginZod?.options?.group
|
|
1292
|
-
}) :
|
|
1293
|
-
const zodSchemaNames =
|
|
1209
|
+
group: pluginZod?.options?.group ?? void 0
|
|
1210
|
+
}) : null;
|
|
1211
|
+
const zodSchemaNames = resolveZodSchemaNames(node, zodResolver);
|
|
1294
1212
|
const clientPlugin = driver.getPlugin(pluginClientName);
|
|
1295
1213
|
const shouldUseClientPlugin = clientPlugin?.name === pluginClientName && clientOptions.clientType !== "class";
|
|
1296
|
-
const clientResolver = shouldUseClientPlugin ? driver.getResolver(pluginClientName) :
|
|
1297
|
-
const clientFile = shouldUseClientPlugin ? clientResolver?.resolveFile({
|
|
1298
|
-
name: node.operationId,
|
|
1299
|
-
extname: ".ts",
|
|
1300
|
-
tag: node.tags[0] ?? "default",
|
|
1301
|
-
path: node.path
|
|
1302
|
-
}, {
|
|
1214
|
+
const clientResolver = shouldUseClientPlugin ? driver.getResolver(pluginClientName) : null;
|
|
1215
|
+
const clientFile = shouldUseClientPlugin ? clientResolver?.resolveFile(operationFileEntry(node, node.operationId), {
|
|
1303
1216
|
root,
|
|
1304
1217
|
output: clientPlugin?.options?.output ?? output,
|
|
1305
|
-
group: clientPlugin?.options?.group
|
|
1306
|
-
}) :
|
|
1218
|
+
group: clientPlugin?.options?.group ?? void 0
|
|
1219
|
+
}) : null;
|
|
1307
1220
|
const resolvedClientName = shouldUseClientPlugin ? clientResolver?.resolveName(node.operationId) ?? clientName : clientName;
|
|
1308
1221
|
return /* @__PURE__ */ jsxs(File, {
|
|
1309
1222
|
baseName: meta.file.baseName,
|
|
1310
1223
|
path: meta.file.path,
|
|
1311
1224
|
meta: meta.file.meta,
|
|
1312
|
-
banner: resolver.resolveBanner(
|
|
1225
|
+
banner: resolver.resolveBanner(ctx.meta, {
|
|
1313
1226
|
output,
|
|
1314
|
-
config
|
|
1227
|
+
config,
|
|
1228
|
+
file: {
|
|
1229
|
+
path: meta.file.path,
|
|
1230
|
+
baseName: meta.file.baseName
|
|
1231
|
+
}
|
|
1315
1232
|
}),
|
|
1316
|
-
footer: resolver.resolveFooter(
|
|
1233
|
+
footer: resolver.resolveFooter(ctx.meta, {
|
|
1317
1234
|
output,
|
|
1318
|
-
config
|
|
1235
|
+
config,
|
|
1236
|
+
file: {
|
|
1237
|
+
path: meta.file.path,
|
|
1238
|
+
baseName: meta.file.baseName
|
|
1239
|
+
}
|
|
1319
1240
|
}),
|
|
1320
1241
|
children: [
|
|
1321
|
-
|
|
1242
|
+
fileZod && zodSchemaNames.length > 0 && /* @__PURE__ */ jsx(File.Import, {
|
|
1322
1243
|
name: zodSchemaNames,
|
|
1323
1244
|
root: meta.file.path,
|
|
1324
1245
|
path: fileZod.path
|
|
1325
1246
|
}),
|
|
1326
1247
|
clientOptions.importPath ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1327
1248
|
!shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
|
|
1328
|
-
name: "
|
|
1249
|
+
name: "client",
|
|
1329
1250
|
path: clientOptions.importPath
|
|
1330
1251
|
}),
|
|
1331
1252
|
/* @__PURE__ */ jsx(File.Import, {
|
|
@@ -1344,9 +1265,9 @@ const suspenseQueryGenerator = defineGenerator({
|
|
|
1344
1265
|
})
|
|
1345
1266
|
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1346
1267
|
!shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
|
|
1347
|
-
name: ["
|
|
1268
|
+
name: ["client"],
|
|
1348
1269
|
root: meta.file.path,
|
|
1349
|
-
path: path.resolve(root, ".kubb/
|
|
1270
|
+
path: path.resolve(root, ".kubb/client.ts")
|
|
1350
1271
|
}),
|
|
1351
1272
|
/* @__PURE__ */ jsx(File.Import, {
|
|
1352
1273
|
name: [
|
|
@@ -1355,13 +1276,13 @@ const suspenseQueryGenerator = defineGenerator({
|
|
|
1355
1276
|
"ResponseErrorConfig"
|
|
1356
1277
|
],
|
|
1357
1278
|
root: meta.file.path,
|
|
1358
|
-
path: path.resolve(root, ".kubb/
|
|
1279
|
+
path: path.resolve(root, ".kubb/client.ts"),
|
|
1359
1280
|
isTypeOnly: true
|
|
1360
1281
|
}),
|
|
1361
1282
|
clientOptions.dataReturnType === "full" && /* @__PURE__ */ jsx(File.Import, {
|
|
1362
1283
|
name: ["ResponseConfig"],
|
|
1363
1284
|
root: meta.file.path,
|
|
1364
|
-
path: path.resolve(root, ".kubb/
|
|
1285
|
+
path: path.resolve(root, ".kubb/client.ts"),
|
|
1365
1286
|
isTypeOnly: true
|
|
1366
1287
|
})
|
|
1367
1288
|
] }),
|
|
@@ -1419,7 +1340,8 @@ const suspenseQueryGenerator = defineGenerator({
|
|
|
1419
1340
|
paramsCasing,
|
|
1420
1341
|
paramsType,
|
|
1421
1342
|
pathParamsType,
|
|
1422
|
-
dataReturnType: clientOptions.dataReturnType || "data"
|
|
1343
|
+
dataReturnType: clientOptions.dataReturnType || "data",
|
|
1344
|
+
suspense: true
|
|
1423
1345
|
}),
|
|
1424
1346
|
suspense && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1425
1347
|
/* @__PURE__ */ jsx(File.Import, {
|
|
@@ -1457,4 +1379,4 @@ const suspenseQueryGenerator = defineGenerator({
|
|
|
1457
1379
|
//#endregion
|
|
1458
1380
|
export { infiniteQueryGenerator as a, mutationGenerator as i, suspenseInfiniteQueryGenerator as n, hookOptionsGenerator as o, queryGenerator as r, customHookOptionsFileGenerator as s, suspenseQueryGenerator as t };
|
|
1459
1381
|
|
|
1460
|
-
//# sourceMappingURL=generators-
|
|
1382
|
+
//# sourceMappingURL=generators-BFn9CLBS.js.map
|