@kubb/plugin-vue-query 5.0.0-alpha.9 → 5.0.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +17 -10
- package/README.md +1 -3
- package/dist/components-D1UhYFgY.js +1277 -0
- package/dist/components-D1UhYFgY.js.map +1 -0
- package/dist/components-qfOFRSoM.cjs +1367 -0
- package/dist/components-qfOFRSoM.cjs.map +1 -0
- package/dist/components.cjs +1 -1
- package/dist/components.d.ts +118 -109
- package/dist/components.js +1 -1
- package/dist/generators-C4gs_P1i.cjs +726 -0
- package/dist/generators-C4gs_P1i.cjs.map +1 -0
- package/dist/generators-CbnIVBgY.js +709 -0
- package/dist/generators-CbnIVBgY.js.map +1 -0
- package/dist/generators.cjs +1 -1
- package/dist/generators.d.ts +5 -501
- package/dist/generators.js +1 -1
- package/dist/index.cjs +106 -121
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +102 -121
- package/dist/index.js.map +1 -1
- package/dist/types-nVDTfuS1.d.ts +194 -0
- package/package.json +61 -64
- package/src/components/InfiniteQuery.tsx +104 -153
- package/src/components/InfiniteQueryOptions.tsx +122 -162
- package/src/components/Mutation.tsx +110 -136
- package/src/components/Query.tsx +102 -151
- package/src/components/QueryKey.tsx +68 -58
- package/src/components/QueryOptions.tsx +147 -139
- package/src/generators/infiniteQueryGenerator.tsx +165 -170
- package/src/generators/mutationGenerator.tsx +117 -124
- package/src/generators/queryGenerator.tsx +138 -136
- package/src/index.ts +1 -1
- package/src/plugin.ts +124 -175
- package/src/resolvers/resolverVueQuery.ts +19 -0
- package/src/types.ts +68 -48
- package/src/utils.ts +37 -0
- package/dist/components-Yjoe78Y7.cjs +0 -1119
- package/dist/components-Yjoe78Y7.cjs.map +0 -1
- package/dist/components-_AMBl0g-.js +0 -1029
- package/dist/components-_AMBl0g-.js.map +0 -1
- package/dist/generators-CR34GjVu.js +0 -661
- package/dist/generators-CR34GjVu.js.map +0 -1
- package/dist/generators-DH8VkK1q.cjs +0 -678
- package/dist/generators-DH8VkK1q.cjs.map +0 -1
- package/dist/types-CgDFUvfZ.d.ts +0 -211
|
@@ -0,0 +1,709 @@
|
|
|
1
|
+
import "./chunk--u3MIqq1.js";
|
|
2
|
+
import { a as QueryOptions, c as MutationKey, i as InfiniteQuery, n as Mutation, o as QueryKey, r as InfiniteQueryOptions, s as transformName, t as Query } from "./components-D1UhYFgY.js";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { ast, defineGenerator } from "@kubb/core";
|
|
5
|
+
import { Client, pluginClientName } from "@kubb/plugin-client";
|
|
6
|
+
import { pluginTsName } from "@kubb/plugin-ts";
|
|
7
|
+
import { pluginZodName } from "@kubb/plugin-zod";
|
|
8
|
+
import { File, jsxRenderer } from "@kubb/renderer-jsx";
|
|
9
|
+
import { Fragment, jsx, jsxs } from "@kubb/renderer-jsx/jsx-runtime";
|
|
10
|
+
import { difference } from "remeda";
|
|
11
|
+
//#region src/generators/infiniteQueryGenerator.tsx
|
|
12
|
+
const infiniteQueryGenerator = defineGenerator({
|
|
13
|
+
name: "vue-query-infinite",
|
|
14
|
+
renderer: jsxRenderer,
|
|
15
|
+
operation(node, ctx) {
|
|
16
|
+
const { adapter, config, driver, resolver, root } = ctx;
|
|
17
|
+
const { output, query, mutation, infinite, paramsCasing, paramsType, pathParamsType, parser, client: clientOptions, group, transformers } = ctx.options;
|
|
18
|
+
const pluginTs = driver.getPlugin(pluginTsName);
|
|
19
|
+
if (!pluginTs) return null;
|
|
20
|
+
const tsResolver = driver.getResolver(pluginTsName);
|
|
21
|
+
const isQuery = query === false || !!query && query.methods.some((method) => node.method.toLowerCase() === method.toLowerCase());
|
|
22
|
+
const isMutation = mutation !== false && !isQuery && difference(mutation ? mutation.methods : [], query ? query.methods : []).some((method) => node.method.toLowerCase() === method.toLowerCase());
|
|
23
|
+
const infiniteOptions = infinite && typeof infinite === "object" ? infinite : void 0;
|
|
24
|
+
if (!isQuery || isMutation || !infiniteOptions) return null;
|
|
25
|
+
const normalizeKey = (key) => key.replace(/\?$/, "");
|
|
26
|
+
const queryParamKeys = node.parameters.filter((p) => p.in === "query").map((p) => p.name);
|
|
27
|
+
const hasQueryParam = infiniteOptions.queryParam ? queryParamKeys.some((k) => normalizeKey(k) === infiniteOptions.queryParam) : false;
|
|
28
|
+
const hasCursorParam = !infiniteOptions.cursorParam || true;
|
|
29
|
+
if (!hasQueryParam || !hasCursorParam) return null;
|
|
30
|
+
const importPath = query ? query.importPath : "@tanstack/vue-query";
|
|
31
|
+
const baseName = resolver.resolveName(node.operationId);
|
|
32
|
+
const capitalize = (s) => s.charAt(0).toUpperCase() + s.slice(1);
|
|
33
|
+
const queryName = transformName(`use${capitalize(baseName)}Infinite`, "function", transformers);
|
|
34
|
+
const queryOptionsName = transformName(`${baseName}InfiniteQueryOptions`, "function", transformers);
|
|
35
|
+
const queryKeyName = transformName(`${baseName}InfiniteQueryKey`, "const", transformers);
|
|
36
|
+
const queryKeyTypeName = transformName(`${capitalize(baseName)}InfiniteQueryKey`, "type", transformers);
|
|
37
|
+
const clientBaseName = transformName(`${baseName}Infinite`, "function", transformers);
|
|
38
|
+
const meta = {
|
|
39
|
+
file: resolver.resolveFile({
|
|
40
|
+
name: queryName,
|
|
41
|
+
extname: ".ts",
|
|
42
|
+
tag: node.tags[0] ?? "default",
|
|
43
|
+
path: node.path
|
|
44
|
+
}, {
|
|
45
|
+
root,
|
|
46
|
+
output,
|
|
47
|
+
group
|
|
48
|
+
}),
|
|
49
|
+
fileTs: tsResolver.resolveFile({
|
|
50
|
+
name: node.operationId,
|
|
51
|
+
extname: ".ts",
|
|
52
|
+
tag: node.tags[0] ?? "default",
|
|
53
|
+
path: node.path
|
|
54
|
+
}, {
|
|
55
|
+
root,
|
|
56
|
+
output: pluginTs.options?.output ?? output,
|
|
57
|
+
group: pluginTs.options?.group
|
|
58
|
+
})
|
|
59
|
+
};
|
|
60
|
+
const casedParams = ast.caseParams(node.parameters, paramsCasing);
|
|
61
|
+
const pathParams = casedParams.filter((p) => p.in === "path");
|
|
62
|
+
const queryParams = casedParams.filter((p) => p.in === "query");
|
|
63
|
+
const headerParams = casedParams.filter((p) => p.in === "header");
|
|
64
|
+
const importedTypeNames = [
|
|
65
|
+
node.requestBody?.content?.[0]?.schema ? tsResolver.resolveDataName(node) : void 0,
|
|
66
|
+
tsResolver.resolveResponseName(node),
|
|
67
|
+
...pathParams.map((p) => tsResolver.resolvePathParamsName(node, p)),
|
|
68
|
+
...queryParams.map((p) => tsResolver.resolveQueryParamsName(node, p)),
|
|
69
|
+
...headerParams.map((p) => tsResolver.resolveHeaderParamsName(node, p)),
|
|
70
|
+
...node.responses.map((res) => tsResolver.resolveResponseStatusName(node, res.statusCode))
|
|
71
|
+
].filter((name) => !!name && name !== queryKeyTypeName);
|
|
72
|
+
const pluginZod = parser === "zod" ? driver.getPlugin(pluginZodName) : void 0;
|
|
73
|
+
const zodResolver = pluginZod ? driver.getResolver(pluginZodName) : void 0;
|
|
74
|
+
const fileZod = zodResolver ? zodResolver.resolveFile({
|
|
75
|
+
name: node.operationId,
|
|
76
|
+
extname: ".ts",
|
|
77
|
+
tag: node.tags[0] ?? "default",
|
|
78
|
+
path: node.path
|
|
79
|
+
}, {
|
|
80
|
+
root,
|
|
81
|
+
output: pluginZod?.options?.output ?? output,
|
|
82
|
+
group: pluginZod?.options?.group
|
|
83
|
+
}) : void 0;
|
|
84
|
+
const zodSchemaNames = zodResolver && parser === "zod" ? [zodResolver.resolveResponseName?.(node), node.requestBody?.content?.[0]?.schema ? zodResolver.resolveDataName?.(node) : void 0].filter(Boolean) : [];
|
|
85
|
+
const clientPlugin = driver.getPlugin(pluginClientName);
|
|
86
|
+
const shouldUseClientPlugin = clientPlugin?.name === pluginClientName && clientOptions.clientType !== "class";
|
|
87
|
+
const clientResolver = shouldUseClientPlugin ? driver.getResolver(pluginClientName) : void 0;
|
|
88
|
+
const clientFile = shouldUseClientPlugin ? clientResolver?.resolveFile({
|
|
89
|
+
name: node.operationId,
|
|
90
|
+
extname: ".ts",
|
|
91
|
+
tag: node.tags[0] ?? "default",
|
|
92
|
+
path: node.path
|
|
93
|
+
}, {
|
|
94
|
+
root,
|
|
95
|
+
output: clientPlugin?.options?.output ?? output,
|
|
96
|
+
group: clientPlugin?.options?.group
|
|
97
|
+
}) : void 0;
|
|
98
|
+
const resolvedClientName = shouldUseClientPlugin ? clientResolver?.resolveName(node.operationId) ?? clientBaseName : clientBaseName;
|
|
99
|
+
return /* @__PURE__ */ jsxs(File, {
|
|
100
|
+
baseName: meta.file.baseName,
|
|
101
|
+
path: meta.file.path,
|
|
102
|
+
meta: meta.file.meta,
|
|
103
|
+
banner: resolver.resolveBanner(adapter.inputNode, {
|
|
104
|
+
output,
|
|
105
|
+
config
|
|
106
|
+
}),
|
|
107
|
+
footer: resolver.resolveFooter(adapter.inputNode, {
|
|
108
|
+
output,
|
|
109
|
+
config
|
|
110
|
+
}),
|
|
111
|
+
children: [
|
|
112
|
+
parser === "zod" && fileZod && zodSchemaNames.length > 0 && /* @__PURE__ */ jsx(File.Import, {
|
|
113
|
+
name: zodSchemaNames,
|
|
114
|
+
root: meta.file.path,
|
|
115
|
+
path: fileZod.path
|
|
116
|
+
}),
|
|
117
|
+
clientOptions.importPath ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
118
|
+
!shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
|
|
119
|
+
name: "fetch",
|
|
120
|
+
path: clientOptions.importPath
|
|
121
|
+
}),
|
|
122
|
+
/* @__PURE__ */ jsx(File.Import, {
|
|
123
|
+
name: [
|
|
124
|
+
"Client",
|
|
125
|
+
"RequestConfig",
|
|
126
|
+
"ResponseErrorConfig"
|
|
127
|
+
],
|
|
128
|
+
path: clientOptions.importPath,
|
|
129
|
+
isTypeOnly: true
|
|
130
|
+
}),
|
|
131
|
+
clientOptions.dataReturnType === "full" && /* @__PURE__ */ jsx(File.Import, {
|
|
132
|
+
name: ["ResponseConfig"],
|
|
133
|
+
path: clientOptions.importPath,
|
|
134
|
+
isTypeOnly: true
|
|
135
|
+
})
|
|
136
|
+
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
137
|
+
!shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
|
|
138
|
+
name: ["fetch"],
|
|
139
|
+
root: meta.file.path,
|
|
140
|
+
path: path.resolve(root, ".kubb/fetch.ts")
|
|
141
|
+
}),
|
|
142
|
+
/* @__PURE__ */ jsx(File.Import, {
|
|
143
|
+
name: [
|
|
144
|
+
"Client",
|
|
145
|
+
"RequestConfig",
|
|
146
|
+
"ResponseErrorConfig"
|
|
147
|
+
],
|
|
148
|
+
root: meta.file.path,
|
|
149
|
+
path: path.resolve(root, ".kubb/fetch.ts"),
|
|
150
|
+
isTypeOnly: true
|
|
151
|
+
}),
|
|
152
|
+
clientOptions.dataReturnType === "full" && /* @__PURE__ */ jsx(File.Import, {
|
|
153
|
+
name: ["ResponseConfig"],
|
|
154
|
+
root: meta.file.path,
|
|
155
|
+
path: path.resolve(root, ".kubb/fetch.ts"),
|
|
156
|
+
isTypeOnly: true
|
|
157
|
+
})
|
|
158
|
+
] }),
|
|
159
|
+
/* @__PURE__ */ jsx(File.Import, {
|
|
160
|
+
name: ["toValue"],
|
|
161
|
+
path: "vue"
|
|
162
|
+
}),
|
|
163
|
+
/* @__PURE__ */ jsx(File.Import, {
|
|
164
|
+
name: ["MaybeRefOrGetter"],
|
|
165
|
+
path: "vue",
|
|
166
|
+
isTypeOnly: true
|
|
167
|
+
}),
|
|
168
|
+
shouldUseClientPlugin && clientFile && /* @__PURE__ */ jsx(File.Import, {
|
|
169
|
+
name: [resolvedClientName],
|
|
170
|
+
root: meta.file.path,
|
|
171
|
+
path: clientFile.path
|
|
172
|
+
}),
|
|
173
|
+
!shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
|
|
174
|
+
name: ["buildFormData"],
|
|
175
|
+
root: meta.file.path,
|
|
176
|
+
path: path.resolve(root, ".kubb/config.ts")
|
|
177
|
+
}),
|
|
178
|
+
meta.fileTs && importedTypeNames.length > 0 && /* @__PURE__ */ jsx(File.Import, {
|
|
179
|
+
name: Array.from(new Set(importedTypeNames)),
|
|
180
|
+
root: meta.file.path,
|
|
181
|
+
path: meta.fileTs.path,
|
|
182
|
+
isTypeOnly: true
|
|
183
|
+
}),
|
|
184
|
+
/* @__PURE__ */ jsx(QueryKey, {
|
|
185
|
+
name: queryKeyName,
|
|
186
|
+
typeName: queryKeyTypeName,
|
|
187
|
+
node,
|
|
188
|
+
tsResolver,
|
|
189
|
+
pathParamsType,
|
|
190
|
+
paramsCasing,
|
|
191
|
+
transformer: ctx.options.queryKey
|
|
192
|
+
}),
|
|
193
|
+
!shouldUseClientPlugin && /* @__PURE__ */ jsx(Client, {
|
|
194
|
+
name: resolvedClientName,
|
|
195
|
+
baseURL: clientOptions.baseURL,
|
|
196
|
+
dataReturnType: clientOptions.dataReturnType || "data",
|
|
197
|
+
paramsCasing: clientOptions.paramsCasing || paramsCasing,
|
|
198
|
+
paramsType,
|
|
199
|
+
pathParamsType,
|
|
200
|
+
parser,
|
|
201
|
+
node,
|
|
202
|
+
tsResolver,
|
|
203
|
+
zodResolver
|
|
204
|
+
}),
|
|
205
|
+
/* @__PURE__ */ jsx(File.Import, {
|
|
206
|
+
name: ["InfiniteData"],
|
|
207
|
+
isTypeOnly: true,
|
|
208
|
+
path: importPath
|
|
209
|
+
}),
|
|
210
|
+
/* @__PURE__ */ jsx(File.Import, {
|
|
211
|
+
name: ["infiniteQueryOptions"],
|
|
212
|
+
path: importPath
|
|
213
|
+
}),
|
|
214
|
+
/* @__PURE__ */ jsx(InfiniteQueryOptions, {
|
|
215
|
+
name: queryOptionsName,
|
|
216
|
+
clientName: resolvedClientName,
|
|
217
|
+
queryKeyName,
|
|
218
|
+
node,
|
|
219
|
+
tsResolver,
|
|
220
|
+
paramsCasing,
|
|
221
|
+
paramsType,
|
|
222
|
+
pathParamsType,
|
|
223
|
+
dataReturnType: clientOptions.dataReturnType || "data",
|
|
224
|
+
cursorParam: infiniteOptions.cursorParam,
|
|
225
|
+
nextParam: infiniteOptions.nextParam,
|
|
226
|
+
previousParam: infiniteOptions.previousParam,
|
|
227
|
+
initialPageParam: infiniteOptions.initialPageParam,
|
|
228
|
+
queryParam: infiniteOptions.queryParam
|
|
229
|
+
}),
|
|
230
|
+
/* @__PURE__ */ jsx(File.Import, {
|
|
231
|
+
name: ["useInfiniteQuery"],
|
|
232
|
+
path: importPath
|
|
233
|
+
}),
|
|
234
|
+
/* @__PURE__ */ jsx(File.Import, {
|
|
235
|
+
name: [
|
|
236
|
+
"QueryKey",
|
|
237
|
+
"QueryClient",
|
|
238
|
+
"UseInfiniteQueryOptions",
|
|
239
|
+
"UseInfiniteQueryReturnType"
|
|
240
|
+
],
|
|
241
|
+
path: importPath,
|
|
242
|
+
isTypeOnly: true
|
|
243
|
+
}),
|
|
244
|
+
/* @__PURE__ */ jsx(InfiniteQuery, {
|
|
245
|
+
name: queryName,
|
|
246
|
+
queryOptionsName,
|
|
247
|
+
queryKeyName,
|
|
248
|
+
queryKeyTypeName,
|
|
249
|
+
node,
|
|
250
|
+
tsResolver,
|
|
251
|
+
paramsCasing,
|
|
252
|
+
paramsType,
|
|
253
|
+
pathParamsType,
|
|
254
|
+
dataReturnType: clientOptions.dataReturnType || "data",
|
|
255
|
+
initialPageParam: infiniteOptions.initialPageParam,
|
|
256
|
+
queryParam: infiniteOptions.queryParam
|
|
257
|
+
})
|
|
258
|
+
]
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
//#endregion
|
|
263
|
+
//#region src/generators/mutationGenerator.tsx
|
|
264
|
+
const mutationGenerator = defineGenerator({
|
|
265
|
+
name: "vue-query-mutation",
|
|
266
|
+
renderer: jsxRenderer,
|
|
267
|
+
operation(node, ctx) {
|
|
268
|
+
const { adapter, config, driver, resolver, root } = ctx;
|
|
269
|
+
const { output, query, mutation, paramsCasing, paramsType, pathParamsType, parser, client: clientOptions, group, transformers } = ctx.options;
|
|
270
|
+
const pluginTs = driver.getPlugin(pluginTsName);
|
|
271
|
+
if (!pluginTs) return null;
|
|
272
|
+
const tsResolver = driver.getResolver(pluginTsName);
|
|
273
|
+
const isQuery = query === false || !!query && query.methods.some((method) => node.method.toLowerCase() === method.toLowerCase());
|
|
274
|
+
if (!(mutation !== false && !isQuery && difference(mutation ? mutation.methods : [], query ? query.methods : []).some((method) => node.method.toLowerCase() === method.toLowerCase()))) return null;
|
|
275
|
+
const importPath = mutation ? mutation.importPath : "@tanstack/vue-query";
|
|
276
|
+
const baseName = resolver.resolveName(node.operationId);
|
|
277
|
+
const capitalize = (s) => s.charAt(0).toUpperCase() + s.slice(1);
|
|
278
|
+
const mutationHookName = transformName(`use${capitalize(baseName)}`, "function", transformers);
|
|
279
|
+
const mutationTypeName = transformName(`${capitalize(baseName)}`, "type", transformers);
|
|
280
|
+
const mutationKeyName = transformName(`${baseName}MutationKey`, "const", transformers);
|
|
281
|
+
const clientName = transformName(baseName, "function", transformers);
|
|
282
|
+
const meta = {
|
|
283
|
+
file: resolver.resolveFile({
|
|
284
|
+
name: mutationHookName,
|
|
285
|
+
extname: ".ts",
|
|
286
|
+
tag: node.tags[0] ?? "default",
|
|
287
|
+
path: node.path
|
|
288
|
+
}, {
|
|
289
|
+
root,
|
|
290
|
+
output,
|
|
291
|
+
group
|
|
292
|
+
}),
|
|
293
|
+
fileTs: tsResolver.resolveFile({
|
|
294
|
+
name: node.operationId,
|
|
295
|
+
extname: ".ts",
|
|
296
|
+
tag: node.tags[0] ?? "default",
|
|
297
|
+
path: node.path
|
|
298
|
+
}, {
|
|
299
|
+
root,
|
|
300
|
+
output: pluginTs.options?.output ?? output,
|
|
301
|
+
group: pluginTs.options?.group
|
|
302
|
+
})
|
|
303
|
+
};
|
|
304
|
+
const casedParams = ast.caseParams(node.parameters, paramsCasing);
|
|
305
|
+
const pathParams = casedParams.filter((p) => p.in === "path");
|
|
306
|
+
const queryParams = casedParams.filter((p) => p.in === "query");
|
|
307
|
+
const headerParams = casedParams.filter((p) => p.in === "header");
|
|
308
|
+
const importedTypeNames = [
|
|
309
|
+
node.requestBody?.content?.[0]?.schema ? tsResolver.resolveDataName(node) : void 0,
|
|
310
|
+
tsResolver.resolveResponseName(node),
|
|
311
|
+
...pathParams.map((p) => tsResolver.resolvePathParamsName(node, p)),
|
|
312
|
+
...queryParams.map((p) => tsResolver.resolveQueryParamsName(node, p)),
|
|
313
|
+
...headerParams.map((p) => tsResolver.resolveHeaderParamsName(node, p)),
|
|
314
|
+
...node.responses.map((res) => tsResolver.resolveResponseStatusName(node, res.statusCode))
|
|
315
|
+
].filter((name) => !!name);
|
|
316
|
+
const pluginZod = parser === "zod" ? driver.getPlugin(pluginZodName) : void 0;
|
|
317
|
+
const zodResolver = pluginZod ? driver.getResolver(pluginZodName) : void 0;
|
|
318
|
+
const fileZod = zodResolver ? zodResolver.resolveFile({
|
|
319
|
+
name: node.operationId,
|
|
320
|
+
extname: ".ts",
|
|
321
|
+
tag: node.tags[0] ?? "default",
|
|
322
|
+
path: node.path
|
|
323
|
+
}, {
|
|
324
|
+
root,
|
|
325
|
+
output: pluginZod?.options?.output ?? output,
|
|
326
|
+
group: pluginZod?.options?.group
|
|
327
|
+
}) : void 0;
|
|
328
|
+
const zodSchemaNames = zodResolver && parser === "zod" ? [zodResolver.resolveResponseName?.(node), node.requestBody?.content?.[0]?.schema ? zodResolver.resolveDataName?.(node) : void 0].filter(Boolean) : [];
|
|
329
|
+
const clientPlugin = driver.getPlugin(pluginClientName);
|
|
330
|
+
const shouldUseClientPlugin = clientPlugin?.name === pluginClientName && clientOptions.clientType !== "class";
|
|
331
|
+
const clientResolver = shouldUseClientPlugin ? driver.getResolver(pluginClientName) : void 0;
|
|
332
|
+
const clientFile = shouldUseClientPlugin ? clientResolver?.resolveFile({
|
|
333
|
+
name: node.operationId,
|
|
334
|
+
extname: ".ts",
|
|
335
|
+
tag: node.tags[0] ?? "default",
|
|
336
|
+
path: node.path
|
|
337
|
+
}, {
|
|
338
|
+
root,
|
|
339
|
+
output: clientPlugin?.options?.output ?? output,
|
|
340
|
+
group: clientPlugin?.options?.group
|
|
341
|
+
}) : void 0;
|
|
342
|
+
const resolvedClientName = shouldUseClientPlugin ? clientResolver?.resolveName(node.operationId) ?? clientName : clientName;
|
|
343
|
+
return /* @__PURE__ */ jsxs(File, {
|
|
344
|
+
baseName: meta.file.baseName,
|
|
345
|
+
path: meta.file.path,
|
|
346
|
+
meta: meta.file.meta,
|
|
347
|
+
banner: resolver.resolveBanner(adapter.inputNode, {
|
|
348
|
+
output,
|
|
349
|
+
config
|
|
350
|
+
}),
|
|
351
|
+
footer: resolver.resolveFooter(adapter.inputNode, {
|
|
352
|
+
output,
|
|
353
|
+
config
|
|
354
|
+
}),
|
|
355
|
+
children: [
|
|
356
|
+
parser === "zod" && fileZod && zodSchemaNames.length > 0 && /* @__PURE__ */ jsx(File.Import, {
|
|
357
|
+
name: zodSchemaNames,
|
|
358
|
+
root: meta.file.path,
|
|
359
|
+
path: fileZod.path
|
|
360
|
+
}),
|
|
361
|
+
clientOptions.importPath ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
362
|
+
!shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
|
|
363
|
+
name: "fetch",
|
|
364
|
+
path: clientOptions.importPath
|
|
365
|
+
}),
|
|
366
|
+
/* @__PURE__ */ jsx(File.Import, {
|
|
367
|
+
name: [
|
|
368
|
+
"Client",
|
|
369
|
+
"RequestConfig",
|
|
370
|
+
"ResponseErrorConfig"
|
|
371
|
+
],
|
|
372
|
+
path: clientOptions.importPath,
|
|
373
|
+
isTypeOnly: true
|
|
374
|
+
}),
|
|
375
|
+
clientOptions.dataReturnType === "full" && /* @__PURE__ */ jsx(File.Import, {
|
|
376
|
+
name: ["ResponseConfig"],
|
|
377
|
+
path: clientOptions.importPath,
|
|
378
|
+
isTypeOnly: true
|
|
379
|
+
})
|
|
380
|
+
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
381
|
+
!shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
|
|
382
|
+
name: ["fetch"],
|
|
383
|
+
root: meta.file.path,
|
|
384
|
+
path: path.resolve(root, ".kubb/fetch.ts")
|
|
385
|
+
}),
|
|
386
|
+
/* @__PURE__ */ jsx(File.Import, {
|
|
387
|
+
name: [
|
|
388
|
+
"Client",
|
|
389
|
+
"RequestConfig",
|
|
390
|
+
"ResponseErrorConfig"
|
|
391
|
+
],
|
|
392
|
+
root: meta.file.path,
|
|
393
|
+
path: path.resolve(root, ".kubb/fetch.ts"),
|
|
394
|
+
isTypeOnly: true
|
|
395
|
+
}),
|
|
396
|
+
clientOptions.dataReturnType === "full" && /* @__PURE__ */ jsx(File.Import, {
|
|
397
|
+
name: ["ResponseConfig"],
|
|
398
|
+
root: meta.file.path,
|
|
399
|
+
path: path.resolve(root, ".kubb/fetch.ts"),
|
|
400
|
+
isTypeOnly: true
|
|
401
|
+
})
|
|
402
|
+
] }),
|
|
403
|
+
/* @__PURE__ */ jsx(File.Import, {
|
|
404
|
+
name: ["MaybeRefOrGetter"],
|
|
405
|
+
path: "vue",
|
|
406
|
+
isTypeOnly: true
|
|
407
|
+
}),
|
|
408
|
+
shouldUseClientPlugin && clientFile && /* @__PURE__ */ jsx(File.Import, {
|
|
409
|
+
name: [resolvedClientName],
|
|
410
|
+
root: meta.file.path,
|
|
411
|
+
path: clientFile.path
|
|
412
|
+
}),
|
|
413
|
+
!shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
|
|
414
|
+
name: ["buildFormData"],
|
|
415
|
+
root: meta.file.path,
|
|
416
|
+
path: path.resolve(root, ".kubb/config.ts")
|
|
417
|
+
}),
|
|
418
|
+
meta.fileTs && importedTypeNames.length > 0 && /* @__PURE__ */ jsx(File.Import, {
|
|
419
|
+
name: Array.from(new Set(importedTypeNames)),
|
|
420
|
+
root: meta.file.path,
|
|
421
|
+
path: meta.fileTs.path,
|
|
422
|
+
isTypeOnly: true
|
|
423
|
+
}),
|
|
424
|
+
/* @__PURE__ */ jsx(MutationKey, {
|
|
425
|
+
name: mutationKeyName,
|
|
426
|
+
node,
|
|
427
|
+
pathParamsType,
|
|
428
|
+
paramsCasing,
|
|
429
|
+
transformer: ctx.options.mutationKey
|
|
430
|
+
}),
|
|
431
|
+
!shouldUseClientPlugin && /* @__PURE__ */ jsx(Client, {
|
|
432
|
+
name: resolvedClientName,
|
|
433
|
+
baseURL: clientOptions.baseURL,
|
|
434
|
+
dataReturnType: clientOptions.dataReturnType || "data",
|
|
435
|
+
paramsCasing: clientOptions.paramsCasing || paramsCasing,
|
|
436
|
+
paramsType,
|
|
437
|
+
pathParamsType,
|
|
438
|
+
parser,
|
|
439
|
+
node,
|
|
440
|
+
tsResolver,
|
|
441
|
+
zodResolver
|
|
442
|
+
}),
|
|
443
|
+
mutation && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
444
|
+
/* @__PURE__ */ jsx(File.Import, {
|
|
445
|
+
name: ["useMutation"],
|
|
446
|
+
path: importPath
|
|
447
|
+
}),
|
|
448
|
+
/* @__PURE__ */ jsx(File.Import, {
|
|
449
|
+
name: ["MutationObserverOptions", "QueryClient"],
|
|
450
|
+
path: importPath,
|
|
451
|
+
isTypeOnly: true
|
|
452
|
+
}),
|
|
453
|
+
/* @__PURE__ */ jsx(Mutation, {
|
|
454
|
+
name: mutationHookName,
|
|
455
|
+
clientName: resolvedClientName,
|
|
456
|
+
typeName: mutationTypeName,
|
|
457
|
+
node,
|
|
458
|
+
tsResolver,
|
|
459
|
+
paramsCasing,
|
|
460
|
+
dataReturnType: clientOptions.dataReturnType || "data",
|
|
461
|
+
paramsType,
|
|
462
|
+
pathParamsType,
|
|
463
|
+
mutationKeyName
|
|
464
|
+
})
|
|
465
|
+
] })
|
|
466
|
+
]
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
});
|
|
470
|
+
//#endregion
|
|
471
|
+
//#region src/generators/queryGenerator.tsx
|
|
472
|
+
const queryGenerator = defineGenerator({
|
|
473
|
+
name: "vue-query",
|
|
474
|
+
renderer: jsxRenderer,
|
|
475
|
+
operation(node, ctx) {
|
|
476
|
+
const { adapter, config, driver, resolver, root } = ctx;
|
|
477
|
+
const { output, query, mutation, paramsCasing, paramsType, pathParamsType, parser, client: clientOptions, group, transformers } = ctx.options;
|
|
478
|
+
const pluginTs = driver.getPlugin(pluginTsName);
|
|
479
|
+
if (!pluginTs) return null;
|
|
480
|
+
const tsResolver = driver.getResolver(pluginTsName);
|
|
481
|
+
const isQuery = query === false || !!query && query.methods.some((method) => node.method.toLowerCase() === method.toLowerCase());
|
|
482
|
+
const isMutation = mutation !== false && !isQuery && difference(mutation ? mutation.methods : [], query ? query.methods : []).some((method) => node.method.toLowerCase() === method.toLowerCase());
|
|
483
|
+
if (!isQuery || isMutation) return null;
|
|
484
|
+
const importPath = query ? query.importPath : "@tanstack/vue-query";
|
|
485
|
+
const baseName = resolver.resolveName(node.operationId);
|
|
486
|
+
const capitalize = (s) => s.charAt(0).toUpperCase() + s.slice(1);
|
|
487
|
+
const queryName = transformName(`use${capitalize(baseName)}`, "function", transformers);
|
|
488
|
+
const queryOptionsName = transformName(`${baseName}QueryOptions`, "function", transformers);
|
|
489
|
+
const queryKeyName = transformName(`${baseName}QueryKey`, "const", transformers);
|
|
490
|
+
const queryKeyTypeName = transformName(`${capitalize(baseName)}QueryKey`, "type", transformers);
|
|
491
|
+
const clientName = transformName(baseName, "function", transformers);
|
|
492
|
+
const meta = {
|
|
493
|
+
file: resolver.resolveFile({
|
|
494
|
+
name: queryName,
|
|
495
|
+
extname: ".ts",
|
|
496
|
+
tag: node.tags[0] ?? "default",
|
|
497
|
+
path: node.path
|
|
498
|
+
}, {
|
|
499
|
+
root,
|
|
500
|
+
output,
|
|
501
|
+
group
|
|
502
|
+
}),
|
|
503
|
+
fileTs: tsResolver.resolveFile({
|
|
504
|
+
name: node.operationId,
|
|
505
|
+
extname: ".ts",
|
|
506
|
+
tag: node.tags[0] ?? "default",
|
|
507
|
+
path: node.path
|
|
508
|
+
}, {
|
|
509
|
+
root,
|
|
510
|
+
output: pluginTs.options?.output ?? output,
|
|
511
|
+
group: pluginTs.options?.group
|
|
512
|
+
})
|
|
513
|
+
};
|
|
514
|
+
const casedParams = ast.caseParams(node.parameters, paramsCasing);
|
|
515
|
+
const pathParams = casedParams.filter((p) => p.in === "path");
|
|
516
|
+
const queryParams = casedParams.filter((p) => p.in === "query");
|
|
517
|
+
const headerParams = casedParams.filter((p) => p.in === "header");
|
|
518
|
+
const importedTypeNames = [
|
|
519
|
+
node.requestBody?.content?.[0]?.schema ? tsResolver.resolveDataName(node) : void 0,
|
|
520
|
+
tsResolver.resolveResponseName(node),
|
|
521
|
+
...pathParams.map((p) => tsResolver.resolvePathParamsName(node, p)),
|
|
522
|
+
...queryParams.map((p) => tsResolver.resolveQueryParamsName(node, p)),
|
|
523
|
+
...headerParams.map((p) => tsResolver.resolveHeaderParamsName(node, p)),
|
|
524
|
+
...node.responses.map((res) => tsResolver.resolveResponseStatusName(node, res.statusCode))
|
|
525
|
+
].filter((name) => !!name && name !== queryKeyTypeName);
|
|
526
|
+
const pluginZod = parser === "zod" ? driver.getPlugin(pluginZodName) : void 0;
|
|
527
|
+
const zodResolver = pluginZod ? driver.getResolver(pluginZodName) : void 0;
|
|
528
|
+
const fileZod = zodResolver ? zodResolver.resolveFile({
|
|
529
|
+
name: node.operationId,
|
|
530
|
+
extname: ".ts",
|
|
531
|
+
tag: node.tags[0] ?? "default",
|
|
532
|
+
path: node.path
|
|
533
|
+
}, {
|
|
534
|
+
root,
|
|
535
|
+
output: pluginZod?.options?.output ?? output,
|
|
536
|
+
group: pluginZod?.options?.group
|
|
537
|
+
}) : void 0;
|
|
538
|
+
const zodSchemaNames = zodResolver && parser === "zod" ? [zodResolver.resolveResponseName?.(node), node.requestBody?.content?.[0]?.schema ? zodResolver.resolveDataName?.(node) : void 0].filter(Boolean) : [];
|
|
539
|
+
const clientPlugin = driver.getPlugin(pluginClientName);
|
|
540
|
+
const shouldUseClientPlugin = clientPlugin?.name === pluginClientName && clientOptions.clientType !== "class";
|
|
541
|
+
const clientResolver = shouldUseClientPlugin ? driver.getResolver(pluginClientName) : void 0;
|
|
542
|
+
const clientFile = shouldUseClientPlugin ? clientResolver?.resolveFile({
|
|
543
|
+
name: node.operationId,
|
|
544
|
+
extname: ".ts",
|
|
545
|
+
tag: node.tags[0] ?? "default",
|
|
546
|
+
path: node.path
|
|
547
|
+
}, {
|
|
548
|
+
root,
|
|
549
|
+
output: clientPlugin?.options?.output ?? output,
|
|
550
|
+
group: clientPlugin?.options?.group
|
|
551
|
+
}) : void 0;
|
|
552
|
+
const resolvedClientName = shouldUseClientPlugin ? clientResolver?.resolveName(node.operationId) ?? clientName : clientName;
|
|
553
|
+
return /* @__PURE__ */ jsxs(File, {
|
|
554
|
+
baseName: meta.file.baseName,
|
|
555
|
+
path: meta.file.path,
|
|
556
|
+
meta: meta.file.meta,
|
|
557
|
+
banner: resolver.resolveBanner(adapter.inputNode, {
|
|
558
|
+
output,
|
|
559
|
+
config
|
|
560
|
+
}),
|
|
561
|
+
footer: resolver.resolveFooter(adapter.inputNode, {
|
|
562
|
+
output,
|
|
563
|
+
config
|
|
564
|
+
}),
|
|
565
|
+
children: [
|
|
566
|
+
parser === "zod" && fileZod && zodSchemaNames.length > 0 && /* @__PURE__ */ jsx(File.Import, {
|
|
567
|
+
name: zodSchemaNames,
|
|
568
|
+
root: meta.file.path,
|
|
569
|
+
path: fileZod.path
|
|
570
|
+
}),
|
|
571
|
+
clientOptions.importPath ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
572
|
+
!shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
|
|
573
|
+
name: "fetch",
|
|
574
|
+
path: clientOptions.importPath
|
|
575
|
+
}),
|
|
576
|
+
/* @__PURE__ */ jsx(File.Import, {
|
|
577
|
+
name: [
|
|
578
|
+
"Client",
|
|
579
|
+
"RequestConfig",
|
|
580
|
+
"ResponseErrorConfig"
|
|
581
|
+
],
|
|
582
|
+
path: clientOptions.importPath,
|
|
583
|
+
isTypeOnly: true
|
|
584
|
+
}),
|
|
585
|
+
clientOptions.dataReturnType === "full" && /* @__PURE__ */ jsx(File.Import, {
|
|
586
|
+
name: ["ResponseConfig"],
|
|
587
|
+
path: clientOptions.importPath,
|
|
588
|
+
isTypeOnly: true
|
|
589
|
+
})
|
|
590
|
+
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
591
|
+
!shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
|
|
592
|
+
name: ["fetch"],
|
|
593
|
+
root: meta.file.path,
|
|
594
|
+
path: path.resolve(root, ".kubb/fetch.ts")
|
|
595
|
+
}),
|
|
596
|
+
/* @__PURE__ */ jsx(File.Import, {
|
|
597
|
+
name: [
|
|
598
|
+
"Client",
|
|
599
|
+
"RequestConfig",
|
|
600
|
+
"ResponseErrorConfig"
|
|
601
|
+
],
|
|
602
|
+
root: meta.file.path,
|
|
603
|
+
path: path.resolve(root, ".kubb/fetch.ts"),
|
|
604
|
+
isTypeOnly: true
|
|
605
|
+
}),
|
|
606
|
+
clientOptions.dataReturnType === "full" && /* @__PURE__ */ jsx(File.Import, {
|
|
607
|
+
name: ["ResponseConfig"],
|
|
608
|
+
root: meta.file.path,
|
|
609
|
+
path: path.resolve(root, ".kubb/fetch.ts"),
|
|
610
|
+
isTypeOnly: true
|
|
611
|
+
})
|
|
612
|
+
] }),
|
|
613
|
+
/* @__PURE__ */ jsx(File.Import, {
|
|
614
|
+
name: ["toValue"],
|
|
615
|
+
path: "vue"
|
|
616
|
+
}),
|
|
617
|
+
/* @__PURE__ */ jsx(File.Import, {
|
|
618
|
+
name: ["MaybeRefOrGetter"],
|
|
619
|
+
path: "vue",
|
|
620
|
+
isTypeOnly: true
|
|
621
|
+
}),
|
|
622
|
+
shouldUseClientPlugin && clientFile && /* @__PURE__ */ jsx(File.Import, {
|
|
623
|
+
name: [resolvedClientName],
|
|
624
|
+
root: meta.file.path,
|
|
625
|
+
path: clientFile.path
|
|
626
|
+
}),
|
|
627
|
+
!shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
|
|
628
|
+
name: ["buildFormData"],
|
|
629
|
+
root: meta.file.path,
|
|
630
|
+
path: path.resolve(root, ".kubb/config.ts")
|
|
631
|
+
}),
|
|
632
|
+
meta.fileTs && importedTypeNames.length > 0 && /* @__PURE__ */ jsx(File.Import, {
|
|
633
|
+
name: Array.from(new Set(importedTypeNames)),
|
|
634
|
+
root: meta.file.path,
|
|
635
|
+
path: meta.fileTs.path,
|
|
636
|
+
isTypeOnly: true
|
|
637
|
+
}),
|
|
638
|
+
/* @__PURE__ */ jsx(QueryKey, {
|
|
639
|
+
name: queryKeyName,
|
|
640
|
+
typeName: queryKeyTypeName,
|
|
641
|
+
node,
|
|
642
|
+
tsResolver,
|
|
643
|
+
pathParamsType,
|
|
644
|
+
paramsCasing,
|
|
645
|
+
transformer: ctx.options.queryKey
|
|
646
|
+
}),
|
|
647
|
+
!shouldUseClientPlugin && /* @__PURE__ */ jsx(Client, {
|
|
648
|
+
name: resolvedClientName,
|
|
649
|
+
baseURL: clientOptions.baseURL,
|
|
650
|
+
dataReturnType: clientOptions.dataReturnType || "data",
|
|
651
|
+
paramsCasing: clientOptions.paramsCasing || paramsCasing,
|
|
652
|
+
paramsType,
|
|
653
|
+
pathParamsType,
|
|
654
|
+
parser,
|
|
655
|
+
node,
|
|
656
|
+
tsResolver,
|
|
657
|
+
zodResolver
|
|
658
|
+
}),
|
|
659
|
+
/* @__PURE__ */ jsx(File.Import, {
|
|
660
|
+
name: ["queryOptions"],
|
|
661
|
+
path: importPath
|
|
662
|
+
}),
|
|
663
|
+
/* @__PURE__ */ jsx(QueryOptions, {
|
|
664
|
+
name: queryOptionsName,
|
|
665
|
+
clientName: resolvedClientName,
|
|
666
|
+
queryKeyName,
|
|
667
|
+
node,
|
|
668
|
+
tsResolver,
|
|
669
|
+
paramsCasing,
|
|
670
|
+
paramsType,
|
|
671
|
+
pathParamsType,
|
|
672
|
+
dataReturnType: clientOptions.dataReturnType || "data"
|
|
673
|
+
}),
|
|
674
|
+
query && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
675
|
+
/* @__PURE__ */ jsx(File.Import, {
|
|
676
|
+
name: ["useQuery"],
|
|
677
|
+
path: importPath
|
|
678
|
+
}),
|
|
679
|
+
/* @__PURE__ */ jsx(File.Import, {
|
|
680
|
+
name: [
|
|
681
|
+
"QueryKey",
|
|
682
|
+
"QueryClient",
|
|
683
|
+
"UseQueryOptions",
|
|
684
|
+
"UseQueryReturnType"
|
|
685
|
+
],
|
|
686
|
+
path: importPath,
|
|
687
|
+
isTypeOnly: true
|
|
688
|
+
}),
|
|
689
|
+
/* @__PURE__ */ jsx(Query, {
|
|
690
|
+
name: queryName,
|
|
691
|
+
queryOptionsName,
|
|
692
|
+
queryKeyName,
|
|
693
|
+
queryKeyTypeName,
|
|
694
|
+
node,
|
|
695
|
+
tsResolver,
|
|
696
|
+
paramsCasing,
|
|
697
|
+
paramsType,
|
|
698
|
+
pathParamsType,
|
|
699
|
+
dataReturnType: clientOptions.dataReturnType || "data"
|
|
700
|
+
})
|
|
701
|
+
] })
|
|
702
|
+
]
|
|
703
|
+
});
|
|
704
|
+
}
|
|
705
|
+
});
|
|
706
|
+
//#endregion
|
|
707
|
+
export { mutationGenerator as n, infiniteQueryGenerator as r, queryGenerator as t };
|
|
708
|
+
|
|
709
|
+
//# sourceMappingURL=generators-CbnIVBgY.js.map
|