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