@kubb/plugin-vue-query 5.0.0-beta.3 → 5.0.0-beta.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -5
- package/dist/{components-qfOFRSoM.cjs → components-B6lPYyOP.cjs} +367 -381
- package/dist/components-B6lPYyOP.cjs.map +1 -0
- package/dist/{components-D1UhYFgY.js → components-BZqujNQv.js} +336 -380
- package/dist/components-BZqujNQv.js.map +1 -0
- package/dist/components.cjs +1 -1
- package/dist/components.d.ts +3 -67
- package/dist/components.js +1 -1
- package/dist/{generators-CbnIVBgY.js → generators-C-3isXzW.js} +158 -203
- package/dist/generators-C-3isXzW.js.map +1 -0
- package/dist/{generators-C4gs_P1i.cjs → generators-QHQkbNnm.cjs} +157 -202
- package/dist/generators-QHQkbNnm.cjs.map +1 -0
- package/dist/generators.cjs +1 -1
- package/dist/generators.d.ts +17 -1
- package/dist/generators.js +1 -1
- package/dist/index.cjs +136 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +29 -1
- package/dist/index.js +136 -23
- package/dist/index.js.map +1 -1
- package/dist/types-D-LjzI_Q.d.ts +270 -0
- package/extension.yaml +1273 -0
- package/package.json +16 -18
- package/src/components/InfiniteQuery.tsx +16 -48
- package/src/components/InfiniteQueryOptions.tsx +43 -58
- package/src/components/Mutation.tsx +33 -42
- package/src/components/Query.tsx +16 -49
- package/src/components/QueryKey.tsx +9 -61
- package/src/components/QueryOptions.tsx +20 -76
- package/src/generators/infiniteQueryGenerator.tsx +55 -63
- package/src/generators/mutationGenerator.tsx +50 -61
- package/src/generators/queryGenerator.tsx +52 -61
- package/src/plugin.ts +46 -30
- package/src/resolvers/resolverVueQuery.ts +61 -4
- package/src/types.ts +129 -53
- package/src/utils.ts +44 -25
- package/dist/components-D1UhYFgY.js.map +0 -1
- package/dist/components-qfOFRSoM.cjs.map +0 -1
- package/dist/generators-C4gs_P1i.cjs.map +0 -1
- package/dist/generators-CbnIVBgY.js.map +0 -1
- package/dist/types-nVDTfuS1.d.ts +0 -194
|
@@ -1,122 +1,108 @@
|
|
|
1
1
|
import "./chunk--u3MIqq1.js";
|
|
2
|
-
import { a as QueryOptions, c as
|
|
2
|
+
import { a as QueryOptions, c as resolveZodSchemaNames, d as getOperationParameters, f as operationFileEntry, i as InfiniteQuery, l as MutationKey, n as Mutation, o as QueryKey, p as resolveOperationTypeNames, r as InfiniteQueryOptions, t as Query } from "./components-BZqujNQv.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,
|
|
8
|
+
import { File, jsxRendererSync } from "@kubb/renderer-jsx";
|
|
9
9
|
import { Fragment, jsx, jsxs } from "@kubb/renderer-jsx/jsx-runtime";
|
|
10
10
|
import { difference } from "remeda";
|
|
11
11
|
//#region src/generators/infiniteQueryGenerator.tsx
|
|
12
|
+
/**
|
|
13
|
+
* Built-in generator for `useInfiniteQuery` composables. Enabled when
|
|
14
|
+
* `pluginVueQuery({ infinite: { ... } })`. Emits one `useFooInfiniteQuery`
|
|
15
|
+
* composable per query operation, wiring the configured cursor path into
|
|
16
|
+
* TanStack Query's cursor-based pagination.
|
|
17
|
+
*/
|
|
12
18
|
const infiniteQueryGenerator = defineGenerator({
|
|
13
19
|
name: "vue-query-infinite",
|
|
14
|
-
renderer:
|
|
20
|
+
renderer: jsxRendererSync,
|
|
15
21
|
operation(node, ctx) {
|
|
16
|
-
|
|
17
|
-
const {
|
|
22
|
+
if (!ast.isHttpOperationNode(node)) return null;
|
|
23
|
+
const { config, driver, resolver, root } = ctx;
|
|
24
|
+
const { output, query, mutation, infinite, paramsCasing, paramsType, pathParamsType, parser, client: clientOptions, group } = ctx.options;
|
|
18
25
|
const pluginTs = driver.getPlugin(pluginTsName);
|
|
19
26
|
if (!pluginTs) return null;
|
|
20
27
|
const tsResolver = driver.getResolver(pluginTsName);
|
|
21
28
|
const isQuery = query === false || !!query && query.methods.some((method) => node.method.toLowerCase() === method.toLowerCase());
|
|
22
29
|
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 :
|
|
30
|
+
const infiniteOptions = infinite && typeof infinite === "object" ? infinite : null;
|
|
24
31
|
if (!isQuery || isMutation || !infiniteOptions) return null;
|
|
25
32
|
const normalizeKey = (key) => key.replace(/\?$/, "");
|
|
26
|
-
const queryParamKeys = node
|
|
33
|
+
const queryParamKeys = getOperationParameters(node).query.map((p) => p.name);
|
|
27
34
|
const hasQueryParam = infiniteOptions.queryParam ? queryParamKeys.some((k) => normalizeKey(k) === infiniteOptions.queryParam) : false;
|
|
28
35
|
const hasCursorParam = !infiniteOptions.cursorParam || true;
|
|
29
36
|
if (!hasQueryParam || !hasCursorParam) return null;
|
|
30
37
|
const importPath = query ? query.importPath : "@tanstack/vue-query";
|
|
31
|
-
const
|
|
32
|
-
const
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
const
|
|
36
|
-
const queryKeyTypeName = transformName(`${capitalize(baseName)}InfiniteQueryKey`, "type", transformers);
|
|
37
|
-
const clientBaseName = transformName(`${baseName}Infinite`, "function", transformers);
|
|
38
|
+
const queryName = resolver.resolveInfiniteQueryName(node);
|
|
39
|
+
const queryOptionsName = resolver.resolveInfiniteQueryOptionsName(node);
|
|
40
|
+
const queryKeyName = resolver.resolveInfiniteQueryKeyName(node);
|
|
41
|
+
const queryKeyTypeName = resolver.resolveInfiniteQueryKeyTypeName(node);
|
|
42
|
+
const clientBaseName = resolver.resolveInfiniteClientName(node);
|
|
38
43
|
const meta = {
|
|
39
|
-
file: resolver.resolveFile({
|
|
40
|
-
name: queryName,
|
|
41
|
-
extname: ".ts",
|
|
42
|
-
tag: node.tags[0] ?? "default",
|
|
43
|
-
path: node.path
|
|
44
|
-
}, {
|
|
44
|
+
file: resolver.resolveFile(operationFileEntry(node, queryName), {
|
|
45
45
|
root,
|
|
46
46
|
output,
|
|
47
|
-
group
|
|
47
|
+
group: group ?? void 0
|
|
48
48
|
}),
|
|
49
|
-
fileTs: tsResolver.resolveFile({
|
|
50
|
-
name: node.operationId,
|
|
51
|
-
extname: ".ts",
|
|
52
|
-
tag: node.tags[0] ?? "default",
|
|
53
|
-
path: node.path
|
|
54
|
-
}, {
|
|
49
|
+
fileTs: tsResolver.resolveFile(operationFileEntry(node, node.operationId), {
|
|
55
50
|
root,
|
|
56
51
|
output: pluginTs.options?.output ?? output,
|
|
57
|
-
group: pluginTs.options?.group
|
|
52
|
+
group: pluginTs.options?.group ?? void 0
|
|
58
53
|
})
|
|
59
54
|
};
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|
-
}, {
|
|
55
|
+
const importedTypeNames = resolveOperationTypeNames(node, tsResolver, {
|
|
56
|
+
paramsCasing,
|
|
57
|
+
exclude: [queryKeyTypeName],
|
|
58
|
+
order: "body-response-first"
|
|
59
|
+
});
|
|
60
|
+
const pluginZod = parser === "zod" ? driver.getPlugin(pluginZodName) : null;
|
|
61
|
+
const zodResolver = pluginZod ? driver.getResolver(pluginZodName) : null;
|
|
62
|
+
const fileZod = zodResolver ? zodResolver.resolveFile(operationFileEntry(node, node.operationId), {
|
|
80
63
|
root,
|
|
81
64
|
output: pluginZod?.options?.output ?? output,
|
|
82
|
-
group: pluginZod?.options?.group
|
|
83
|
-
}) :
|
|
84
|
-
const zodSchemaNames =
|
|
65
|
+
group: pluginZod?.options?.group ?? void 0
|
|
66
|
+
}) : null;
|
|
67
|
+
const zodSchemaNames = resolveZodSchemaNames(node, zodResolver);
|
|
85
68
|
const clientPlugin = driver.getPlugin(pluginClientName);
|
|
86
69
|
const shouldUseClientPlugin = clientPlugin?.name === pluginClientName && clientOptions.clientType !== "class";
|
|
87
|
-
const clientResolver = shouldUseClientPlugin ? driver.getResolver(pluginClientName) :
|
|
88
|
-
const clientFile = shouldUseClientPlugin ? clientResolver?.resolveFile({
|
|
89
|
-
name: node.operationId,
|
|
90
|
-
extname: ".ts",
|
|
91
|
-
tag: node.tags[0] ?? "default",
|
|
92
|
-
path: node.path
|
|
93
|
-
}, {
|
|
70
|
+
const clientResolver = shouldUseClientPlugin ? driver.getResolver(pluginClientName) : null;
|
|
71
|
+
const clientFile = shouldUseClientPlugin ? clientResolver?.resolveFile(operationFileEntry(node, node.operationId), {
|
|
94
72
|
root,
|
|
95
73
|
output: clientPlugin?.options?.output ?? output,
|
|
96
|
-
group: clientPlugin?.options?.group
|
|
97
|
-
}) :
|
|
74
|
+
group: clientPlugin?.options?.group ?? void 0
|
|
75
|
+
}) : null;
|
|
98
76
|
const resolvedClientName = shouldUseClientPlugin ? clientResolver?.resolveName(node.operationId) ?? clientBaseName : clientBaseName;
|
|
99
77
|
return /* @__PURE__ */ jsxs(File, {
|
|
100
78
|
baseName: meta.file.baseName,
|
|
101
79
|
path: meta.file.path,
|
|
102
80
|
meta: meta.file.meta,
|
|
103
|
-
banner: resolver.resolveBanner(
|
|
81
|
+
banner: resolver.resolveBanner(ctx.meta, {
|
|
104
82
|
output,
|
|
105
|
-
config
|
|
83
|
+
config,
|
|
84
|
+
file: {
|
|
85
|
+
path: meta.file.path,
|
|
86
|
+
baseName: meta.file.baseName
|
|
87
|
+
}
|
|
106
88
|
}),
|
|
107
|
-
footer: resolver.resolveFooter(
|
|
89
|
+
footer: resolver.resolveFooter(ctx.meta, {
|
|
108
90
|
output,
|
|
109
|
-
config
|
|
91
|
+
config,
|
|
92
|
+
file: {
|
|
93
|
+
path: meta.file.path,
|
|
94
|
+
baseName: meta.file.baseName
|
|
95
|
+
}
|
|
110
96
|
}),
|
|
111
97
|
children: [
|
|
112
|
-
|
|
98
|
+
fileZod && zodSchemaNames.length > 0 && /* @__PURE__ */ jsx(File.Import, {
|
|
113
99
|
name: zodSchemaNames,
|
|
114
100
|
root: meta.file.path,
|
|
115
101
|
path: fileZod.path
|
|
116
102
|
}),
|
|
117
103
|
clientOptions.importPath ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
118
104
|
!shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
|
|
119
|
-
name: "
|
|
105
|
+
name: "client",
|
|
120
106
|
path: clientOptions.importPath
|
|
121
107
|
}),
|
|
122
108
|
/* @__PURE__ */ jsx(File.Import, {
|
|
@@ -135,9 +121,9 @@ const infiniteQueryGenerator = defineGenerator({
|
|
|
135
121
|
})
|
|
136
122
|
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
137
123
|
!shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
|
|
138
|
-
name: ["
|
|
124
|
+
name: ["client"],
|
|
139
125
|
root: meta.file.path,
|
|
140
|
-
path: path.resolve(root, ".kubb/
|
|
126
|
+
path: path.resolve(root, ".kubb/client.ts")
|
|
141
127
|
}),
|
|
142
128
|
/* @__PURE__ */ jsx(File.Import, {
|
|
143
129
|
name: [
|
|
@@ -146,13 +132,13 @@ const infiniteQueryGenerator = defineGenerator({
|
|
|
146
132
|
"ResponseErrorConfig"
|
|
147
133
|
],
|
|
148
134
|
root: meta.file.path,
|
|
149
|
-
path: path.resolve(root, ".kubb/
|
|
135
|
+
path: path.resolve(root, ".kubb/client.ts"),
|
|
150
136
|
isTypeOnly: true
|
|
151
137
|
}),
|
|
152
138
|
clientOptions.dataReturnType === "full" && /* @__PURE__ */ jsx(File.Import, {
|
|
153
139
|
name: ["ResponseConfig"],
|
|
154
140
|
root: meta.file.path,
|
|
155
|
-
path: path.resolve(root, ".kubb/
|
|
141
|
+
path: path.resolve(root, ".kubb/client.ts"),
|
|
156
142
|
isTypeOnly: true
|
|
157
143
|
})
|
|
158
144
|
] }),
|
|
@@ -261,106 +247,90 @@ const infiniteQueryGenerator = defineGenerator({
|
|
|
261
247
|
});
|
|
262
248
|
//#endregion
|
|
263
249
|
//#region src/generators/mutationGenerator.tsx
|
|
250
|
+
/**
|
|
251
|
+
* Built-in generator for `useMutation` composables. Emits one
|
|
252
|
+
* `useFooMutation` composable per POST/PUT/DELETE operation (configurable
|
|
253
|
+
* via `mutation.methods`) plus the matching `fooMutationKey` helper.
|
|
254
|
+
*/
|
|
264
255
|
const mutationGenerator = defineGenerator({
|
|
265
256
|
name: "vue-query-mutation",
|
|
266
|
-
renderer:
|
|
257
|
+
renderer: jsxRendererSync,
|
|
267
258
|
operation(node, ctx) {
|
|
268
|
-
|
|
269
|
-
const {
|
|
259
|
+
if (!ast.isHttpOperationNode(node)) return null;
|
|
260
|
+
const { config, driver, resolver, root } = ctx;
|
|
261
|
+
const { output, query, mutation, paramsCasing, paramsType, pathParamsType, parser, client: clientOptions, group } = ctx.options;
|
|
270
262
|
const pluginTs = driver.getPlugin(pluginTsName);
|
|
271
263
|
if (!pluginTs) return null;
|
|
272
264
|
const tsResolver = driver.getResolver(pluginTsName);
|
|
273
265
|
const isQuery = query === false || !!query && query.methods.some((method) => node.method.toLowerCase() === method.toLowerCase());
|
|
274
266
|
if (!(mutation !== false && !isQuery && difference(mutation ? mutation.methods : [], query ? query.methods : []).some((method) => node.method.toLowerCase() === method.toLowerCase()))) return null;
|
|
275
267
|
const importPath = mutation ? mutation.importPath : "@tanstack/vue-query";
|
|
276
|
-
const
|
|
277
|
-
const
|
|
278
|
-
const
|
|
279
|
-
const
|
|
280
|
-
const mutationKeyName = transformName(`${baseName}MutationKey`, "const", transformers);
|
|
281
|
-
const clientName = transformName(baseName, "function", transformers);
|
|
268
|
+
const mutationHookName = resolver.resolveMutationName(node);
|
|
269
|
+
const mutationTypeName = resolver.resolveMutationTypeName(node);
|
|
270
|
+
const mutationKeyName = resolver.resolveMutationKeyName(node);
|
|
271
|
+
const clientName = resolver.resolveClientName(node);
|
|
282
272
|
const meta = {
|
|
283
|
-
file: resolver.resolveFile({
|
|
284
|
-
name: mutationHookName,
|
|
285
|
-
extname: ".ts",
|
|
286
|
-
tag: node.tags[0] ?? "default",
|
|
287
|
-
path: node.path
|
|
288
|
-
}, {
|
|
273
|
+
file: resolver.resolveFile(operationFileEntry(node, mutationHookName), {
|
|
289
274
|
root,
|
|
290
275
|
output,
|
|
291
|
-
group
|
|
276
|
+
group: group ?? void 0
|
|
292
277
|
}),
|
|
293
|
-
fileTs: tsResolver.resolveFile({
|
|
294
|
-
name: node.operationId,
|
|
295
|
-
extname: ".ts",
|
|
296
|
-
tag: node.tags[0] ?? "default",
|
|
297
|
-
path: node.path
|
|
298
|
-
}, {
|
|
278
|
+
fileTs: tsResolver.resolveFile(operationFileEntry(node, node.operationId), {
|
|
299
279
|
root,
|
|
300
280
|
output: pluginTs.options?.output ?? output,
|
|
301
|
-
group: pluginTs.options?.group
|
|
281
|
+
group: pluginTs.options?.group ?? void 0
|
|
302
282
|
})
|
|
303
283
|
};
|
|
304
|
-
const
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
const
|
|
309
|
-
|
|
310
|
-
|
|
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
|
-
}, {
|
|
284
|
+
const importedTypeNames = resolveOperationTypeNames(node, tsResolver, {
|
|
285
|
+
paramsCasing,
|
|
286
|
+
order: "body-response-first"
|
|
287
|
+
});
|
|
288
|
+
const pluginZod = parser === "zod" ? driver.getPlugin(pluginZodName) : null;
|
|
289
|
+
const zodResolver = pluginZod ? driver.getResolver(pluginZodName) : null;
|
|
290
|
+
const fileZod = zodResolver ? zodResolver.resolveFile(operationFileEntry(node, node.operationId), {
|
|
324
291
|
root,
|
|
325
292
|
output: pluginZod?.options?.output ?? output,
|
|
326
|
-
group: pluginZod?.options?.group
|
|
327
|
-
}) :
|
|
328
|
-
const zodSchemaNames =
|
|
293
|
+
group: pluginZod?.options?.group ?? void 0
|
|
294
|
+
}) : null;
|
|
295
|
+
const zodSchemaNames = resolveZodSchemaNames(node, zodResolver);
|
|
329
296
|
const clientPlugin = driver.getPlugin(pluginClientName);
|
|
330
297
|
const shouldUseClientPlugin = clientPlugin?.name === pluginClientName && clientOptions.clientType !== "class";
|
|
331
|
-
const clientResolver = shouldUseClientPlugin ? driver.getResolver(pluginClientName) :
|
|
332
|
-
const clientFile = shouldUseClientPlugin ? clientResolver?.resolveFile({
|
|
333
|
-
name: node.operationId,
|
|
334
|
-
extname: ".ts",
|
|
335
|
-
tag: node.tags[0] ?? "default",
|
|
336
|
-
path: node.path
|
|
337
|
-
}, {
|
|
298
|
+
const clientResolver = shouldUseClientPlugin ? driver.getResolver(pluginClientName) : null;
|
|
299
|
+
const clientFile = shouldUseClientPlugin ? clientResolver?.resolveFile(operationFileEntry(node, node.operationId), {
|
|
338
300
|
root,
|
|
339
301
|
output: clientPlugin?.options?.output ?? output,
|
|
340
|
-
group: clientPlugin?.options?.group
|
|
341
|
-
}) :
|
|
302
|
+
group: clientPlugin?.options?.group ?? void 0
|
|
303
|
+
}) : null;
|
|
342
304
|
const resolvedClientName = shouldUseClientPlugin ? clientResolver?.resolveName(node.operationId) ?? clientName : clientName;
|
|
343
305
|
return /* @__PURE__ */ jsxs(File, {
|
|
344
306
|
baseName: meta.file.baseName,
|
|
345
307
|
path: meta.file.path,
|
|
346
308
|
meta: meta.file.meta,
|
|
347
|
-
banner: resolver.resolveBanner(
|
|
309
|
+
banner: resolver.resolveBanner(ctx.meta, {
|
|
348
310
|
output,
|
|
349
|
-
config
|
|
311
|
+
config,
|
|
312
|
+
file: {
|
|
313
|
+
path: meta.file.path,
|
|
314
|
+
baseName: meta.file.baseName
|
|
315
|
+
}
|
|
350
316
|
}),
|
|
351
|
-
footer: resolver.resolveFooter(
|
|
317
|
+
footer: resolver.resolveFooter(ctx.meta, {
|
|
352
318
|
output,
|
|
353
|
-
config
|
|
319
|
+
config,
|
|
320
|
+
file: {
|
|
321
|
+
path: meta.file.path,
|
|
322
|
+
baseName: meta.file.baseName
|
|
323
|
+
}
|
|
354
324
|
}),
|
|
355
325
|
children: [
|
|
356
|
-
|
|
326
|
+
fileZod && zodSchemaNames.length > 0 && /* @__PURE__ */ jsx(File.Import, {
|
|
357
327
|
name: zodSchemaNames,
|
|
358
328
|
root: meta.file.path,
|
|
359
329
|
path: fileZod.path
|
|
360
330
|
}),
|
|
361
331
|
clientOptions.importPath ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
362
332
|
!shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
|
|
363
|
-
name: "
|
|
333
|
+
name: "client",
|
|
364
334
|
path: clientOptions.importPath
|
|
365
335
|
}),
|
|
366
336
|
/* @__PURE__ */ jsx(File.Import, {
|
|
@@ -379,9 +349,9 @@ const mutationGenerator = defineGenerator({
|
|
|
379
349
|
})
|
|
380
350
|
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
381
351
|
!shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
|
|
382
|
-
name: ["
|
|
352
|
+
name: ["client"],
|
|
383
353
|
root: meta.file.path,
|
|
384
|
-
path: path.resolve(root, ".kubb/
|
|
354
|
+
path: path.resolve(root, ".kubb/client.ts")
|
|
385
355
|
}),
|
|
386
356
|
/* @__PURE__ */ jsx(File.Import, {
|
|
387
357
|
name: [
|
|
@@ -390,13 +360,13 @@ const mutationGenerator = defineGenerator({
|
|
|
390
360
|
"ResponseErrorConfig"
|
|
391
361
|
],
|
|
392
362
|
root: meta.file.path,
|
|
393
|
-
path: path.resolve(root, ".kubb/
|
|
363
|
+
path: path.resolve(root, ".kubb/client.ts"),
|
|
394
364
|
isTypeOnly: true
|
|
395
365
|
}),
|
|
396
366
|
clientOptions.dataReturnType === "full" && /* @__PURE__ */ jsx(File.Import, {
|
|
397
367
|
name: ["ResponseConfig"],
|
|
398
368
|
root: meta.file.path,
|
|
399
|
-
path: path.resolve(root, ".kubb/
|
|
369
|
+
path: path.resolve(root, ".kubb/client.ts"),
|
|
400
370
|
isTypeOnly: true
|
|
401
371
|
})
|
|
402
372
|
] }),
|
|
@@ -410,7 +380,7 @@ const mutationGenerator = defineGenerator({
|
|
|
410
380
|
root: meta.file.path,
|
|
411
381
|
path: clientFile.path
|
|
412
382
|
}),
|
|
413
|
-
!shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
|
|
383
|
+
!shouldUseClientPlugin && node.requestBody?.content?.some((e) => e.contentType === "multipart/form-data") && /* @__PURE__ */ jsx(File.Import, {
|
|
414
384
|
name: ["buildFormData"],
|
|
415
385
|
root: meta.file.path,
|
|
416
386
|
path: path.resolve(root, ".kubb/config.ts")
|
|
@@ -469,12 +439,18 @@ const mutationGenerator = defineGenerator({
|
|
|
469
439
|
});
|
|
470
440
|
//#endregion
|
|
471
441
|
//#region src/generators/queryGenerator.tsx
|
|
442
|
+
/**
|
|
443
|
+
* Built-in generator for `useQuery` composables. Emits one `useFooQuery`
|
|
444
|
+
* composable per GET operation (configurable via `query.methods`) plus the
|
|
445
|
+
* matching `fooQueryKey` / `fooQueryOptions` helpers.
|
|
446
|
+
*/
|
|
472
447
|
const queryGenerator = defineGenerator({
|
|
473
448
|
name: "vue-query",
|
|
474
|
-
renderer:
|
|
449
|
+
renderer: jsxRendererSync,
|
|
475
450
|
operation(node, ctx) {
|
|
476
|
-
|
|
477
|
-
const {
|
|
451
|
+
if (!ast.isHttpOperationNode(node)) return null;
|
|
452
|
+
const { config, driver, resolver, root } = ctx;
|
|
453
|
+
const { output, query, mutation, paramsCasing, paramsType, pathParamsType, parser, client: clientOptions, group } = ctx.options;
|
|
478
454
|
const pluginTs = driver.getPlugin(pluginTsName);
|
|
479
455
|
if (!pluginTs) return null;
|
|
480
456
|
const tsResolver = driver.getResolver(pluginTsName);
|
|
@@ -482,95 +458,74 @@ const queryGenerator = defineGenerator({
|
|
|
482
458
|
const isMutation = mutation !== false && !isQuery && difference(mutation ? mutation.methods : [], query ? query.methods : []).some((method) => node.method.toLowerCase() === method.toLowerCase());
|
|
483
459
|
if (!isQuery || isMutation) return null;
|
|
484
460
|
const importPath = query ? query.importPath : "@tanstack/vue-query";
|
|
485
|
-
const
|
|
486
|
-
const
|
|
487
|
-
const
|
|
488
|
-
const
|
|
489
|
-
const
|
|
490
|
-
const queryKeyTypeName = transformName(`${capitalize(baseName)}QueryKey`, "type", transformers);
|
|
491
|
-
const clientName = transformName(baseName, "function", transformers);
|
|
461
|
+
const queryName = resolver.resolveQueryName(node);
|
|
462
|
+
const queryOptionsName = resolver.resolveQueryOptionsName(node);
|
|
463
|
+
const queryKeyName = resolver.resolveQueryKeyName(node);
|
|
464
|
+
const queryKeyTypeName = resolver.resolveQueryKeyTypeName(node);
|
|
465
|
+
const clientName = resolver.resolveClientName(node);
|
|
492
466
|
const meta = {
|
|
493
|
-
file: resolver.resolveFile({
|
|
494
|
-
name: queryName,
|
|
495
|
-
extname: ".ts",
|
|
496
|
-
tag: node.tags[0] ?? "default",
|
|
497
|
-
path: node.path
|
|
498
|
-
}, {
|
|
467
|
+
file: resolver.resolveFile(operationFileEntry(node, queryName), {
|
|
499
468
|
root,
|
|
500
469
|
output,
|
|
501
|
-
group
|
|
470
|
+
group: group ?? void 0
|
|
502
471
|
}),
|
|
503
|
-
fileTs: tsResolver.resolveFile({
|
|
504
|
-
name: node.operationId,
|
|
505
|
-
extname: ".ts",
|
|
506
|
-
tag: node.tags[0] ?? "default",
|
|
507
|
-
path: node.path
|
|
508
|
-
}, {
|
|
472
|
+
fileTs: tsResolver.resolveFile(operationFileEntry(node, node.operationId), {
|
|
509
473
|
root,
|
|
510
474
|
output: pluginTs.options?.output ?? output,
|
|
511
|
-
group: pluginTs.options?.group
|
|
475
|
+
group: pluginTs.options?.group ?? void 0
|
|
512
476
|
})
|
|
513
477
|
};
|
|
514
|
-
const
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
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
|
-
}, {
|
|
478
|
+
const importedTypeNames = resolveOperationTypeNames(node, tsResolver, {
|
|
479
|
+
paramsCasing,
|
|
480
|
+
exclude: [queryKeyTypeName],
|
|
481
|
+
order: "body-response-first"
|
|
482
|
+
});
|
|
483
|
+
const pluginZod = parser === "zod" ? driver.getPlugin(pluginZodName) : null;
|
|
484
|
+
const zodResolver = pluginZod ? driver.getResolver(pluginZodName) : null;
|
|
485
|
+
const fileZod = zodResolver ? zodResolver.resolveFile(operationFileEntry(node, node.operationId), {
|
|
534
486
|
root,
|
|
535
487
|
output: pluginZod?.options?.output ?? output,
|
|
536
|
-
group: pluginZod?.options?.group
|
|
537
|
-
}) :
|
|
538
|
-
const zodSchemaNames =
|
|
488
|
+
group: pluginZod?.options?.group ?? void 0
|
|
489
|
+
}) : null;
|
|
490
|
+
const zodSchemaNames = resolveZodSchemaNames(node, zodResolver);
|
|
539
491
|
const clientPlugin = driver.getPlugin(pluginClientName);
|
|
540
492
|
const shouldUseClientPlugin = clientPlugin?.name === pluginClientName && clientOptions.clientType !== "class";
|
|
541
|
-
const clientResolver = shouldUseClientPlugin ? driver.getResolver(pluginClientName) :
|
|
542
|
-
const clientFile = shouldUseClientPlugin ? clientResolver?.resolveFile({
|
|
543
|
-
name: node.operationId,
|
|
544
|
-
extname: ".ts",
|
|
545
|
-
tag: node.tags[0] ?? "default",
|
|
546
|
-
path: node.path
|
|
547
|
-
}, {
|
|
493
|
+
const clientResolver = shouldUseClientPlugin ? driver.getResolver(pluginClientName) : null;
|
|
494
|
+
const clientFile = shouldUseClientPlugin ? clientResolver?.resolveFile(operationFileEntry(node, node.operationId), {
|
|
548
495
|
root,
|
|
549
496
|
output: clientPlugin?.options?.output ?? output,
|
|
550
|
-
group: clientPlugin?.options?.group
|
|
551
|
-
}) :
|
|
497
|
+
group: clientPlugin?.options?.group ?? void 0
|
|
498
|
+
}) : null;
|
|
552
499
|
const resolvedClientName = shouldUseClientPlugin ? clientResolver?.resolveName(node.operationId) ?? clientName : clientName;
|
|
553
500
|
return /* @__PURE__ */ jsxs(File, {
|
|
554
501
|
baseName: meta.file.baseName,
|
|
555
502
|
path: meta.file.path,
|
|
556
503
|
meta: meta.file.meta,
|
|
557
|
-
banner: resolver.resolveBanner(
|
|
504
|
+
banner: resolver.resolveBanner(ctx.meta, {
|
|
558
505
|
output,
|
|
559
|
-
config
|
|
506
|
+
config,
|
|
507
|
+
file: {
|
|
508
|
+
path: meta.file.path,
|
|
509
|
+
baseName: meta.file.baseName
|
|
510
|
+
}
|
|
560
511
|
}),
|
|
561
|
-
footer: resolver.resolveFooter(
|
|
512
|
+
footer: resolver.resolveFooter(ctx.meta, {
|
|
562
513
|
output,
|
|
563
|
-
config
|
|
514
|
+
config,
|
|
515
|
+
file: {
|
|
516
|
+
path: meta.file.path,
|
|
517
|
+
baseName: meta.file.baseName
|
|
518
|
+
}
|
|
564
519
|
}),
|
|
565
520
|
children: [
|
|
566
|
-
|
|
521
|
+
fileZod && zodSchemaNames.length > 0 && /* @__PURE__ */ jsx(File.Import, {
|
|
567
522
|
name: zodSchemaNames,
|
|
568
523
|
root: meta.file.path,
|
|
569
524
|
path: fileZod.path
|
|
570
525
|
}),
|
|
571
526
|
clientOptions.importPath ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
572
527
|
!shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
|
|
573
|
-
name: "
|
|
528
|
+
name: "client",
|
|
574
529
|
path: clientOptions.importPath
|
|
575
530
|
}),
|
|
576
531
|
/* @__PURE__ */ jsx(File.Import, {
|
|
@@ -589,9 +544,9 @@ const queryGenerator = defineGenerator({
|
|
|
589
544
|
})
|
|
590
545
|
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
591
546
|
!shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
|
|
592
|
-
name: ["
|
|
547
|
+
name: ["client"],
|
|
593
548
|
root: meta.file.path,
|
|
594
|
-
path: path.resolve(root, ".kubb/
|
|
549
|
+
path: path.resolve(root, ".kubb/client.ts")
|
|
595
550
|
}),
|
|
596
551
|
/* @__PURE__ */ jsx(File.Import, {
|
|
597
552
|
name: [
|
|
@@ -600,13 +555,13 @@ const queryGenerator = defineGenerator({
|
|
|
600
555
|
"ResponseErrorConfig"
|
|
601
556
|
],
|
|
602
557
|
root: meta.file.path,
|
|
603
|
-
path: path.resolve(root, ".kubb/
|
|
558
|
+
path: path.resolve(root, ".kubb/client.ts"),
|
|
604
559
|
isTypeOnly: true
|
|
605
560
|
}),
|
|
606
561
|
clientOptions.dataReturnType === "full" && /* @__PURE__ */ jsx(File.Import, {
|
|
607
562
|
name: ["ResponseConfig"],
|
|
608
563
|
root: meta.file.path,
|
|
609
|
-
path: path.resolve(root, ".kubb/
|
|
564
|
+
path: path.resolve(root, ".kubb/client.ts"),
|
|
610
565
|
isTypeOnly: true
|
|
611
566
|
})
|
|
612
567
|
] }),
|
|
@@ -706,4 +661,4 @@ const queryGenerator = defineGenerator({
|
|
|
706
661
|
//#endregion
|
|
707
662
|
export { mutationGenerator as n, infiniteQueryGenerator as r, queryGenerator as t };
|
|
708
663
|
|
|
709
|
-
//# sourceMappingURL=generators-
|
|
664
|
+
//# sourceMappingURL=generators-C-3isXzW.js.map
|