@kubb/plugin-vue-query 5.0.0-beta.10 → 5.0.0-beta.101

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.
Files changed (41) hide show
  1. package/README.md +22 -26
  2. package/dist/index.cjs +1649 -147
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.ts +358 -6
  5. package/dist/index.js +1620 -145
  6. package/dist/index.js.map +1 -1
  7. package/package.json +9 -32
  8. package/dist/components-B6jAb2as.js +0 -1150
  9. package/dist/components-B6jAb2as.js.map +0 -1
  10. package/dist/components-X0P-3W2G.cjs +0 -1264
  11. package/dist/components-X0P-3W2G.cjs.map +0 -1
  12. package/dist/components.cjs +0 -9
  13. package/dist/components.d.ts +0 -187
  14. package/dist/components.js +0 -2
  15. package/dist/generators-B33PbKzu.js +0 -681
  16. package/dist/generators-B33PbKzu.js.map +0 -1
  17. package/dist/generators-BE3KD0IR.cjs +0 -698
  18. package/dist/generators-BE3KD0IR.cjs.map +0 -1
  19. package/dist/generators.cjs +0 -5
  20. package/dist/generators.d.ts +0 -15
  21. package/dist/generators.js +0 -2
  22. package/dist/types-Bkm7bWT3.d.ts +0 -243
  23. package/extension.yaml +0 -732
  24. package/src/components/InfiniteQuery.tsx +0 -120
  25. package/src/components/InfiniteQueryOptions.tsx +0 -201
  26. package/src/components/Mutation.tsx +0 -148
  27. package/src/components/MutationKey.tsx +0 -1
  28. package/src/components/Query.tsx +0 -119
  29. package/src/components/QueryKey.tsx +0 -51
  30. package/src/components/QueryOptions.tsx +0 -134
  31. package/src/components/index.ts +0 -7
  32. package/src/generators/index.ts +0 -3
  33. package/src/generators/infiniteQueryGenerator.tsx +0 -194
  34. package/src/generators/mutationGenerator.tsx +0 -153
  35. package/src/generators/queryGenerator.tsx +0 -179
  36. package/src/index.ts +0 -2
  37. package/src/plugin.ts +0 -167
  38. package/src/resolvers/resolverVueQuery.ts +0 -65
  39. package/src/types.ts +0 -245
  40. package/src/utils.ts +0 -49
  41. /package/dist/{chunk--u3MIqq1.js → rolldown-runtime-C0LytTxp.js} +0 -0
package/dist/index.cjs CHANGED
@@ -2,149 +2,1673 @@ Object.defineProperties(exports, {
2
2
  __esModule: { value: true },
3
3
  [Symbol.toStringTag]: { value: "Module" }
4
4
  });
5
- const require_components = require("./components-X0P-3W2G.cjs");
6
- const require_generators = require("./generators-BE3KD0IR.cjs");
5
+ //#region \0rolldown/runtime.js
6
+ var __create = Object.create;
7
+ var __defProp = Object.defineProperty;
8
+ var __name = (target, value) => __defProp(target, "name", {
9
+ value,
10
+ configurable: true
11
+ });
12
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
+ var __getOwnPropNames = Object.getOwnPropertyNames;
14
+ var __getProtoOf = Object.getPrototypeOf;
15
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
16
+ var __copyProps = (to, from, except, desc) => {
17
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
18
+ key = keys[i];
19
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
20
+ get: ((k) => from[k]).bind(null, key),
21
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
22
+ });
23
+ }
24
+ return to;
25
+ };
26
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
27
+ value: mod,
28
+ enumerable: true
29
+ }) : target, mod));
30
+ //#endregion
31
+ let kubb_kit = require("kubb/kit");
7
32
  let node_path = require("node:path");
8
- node_path = require_components.__toESM(node_path, 1);
9
- let _kubb_core = require("@kubb/core");
10
- let _kubb_plugin_client = require("@kubb/plugin-client");
11
- let _kubb_plugin_client_templates_clients_axios_source = require("@kubb/plugin-client/templates/clients/axios.source");
12
- let _kubb_plugin_client_templates_clients_fetch_source = require("@kubb/plugin-client/templates/clients/fetch.source");
13
- let _kubb_plugin_client_templates_config_source = require("@kubb/plugin-client/templates/config.source");
33
+ node_path = __toESM(node_path, 1);
14
34
  let _kubb_plugin_ts = require("@kubb/plugin-ts");
15
- let _kubb_plugin_zod = require("@kubb/plugin-zod");
16
- //#region src/resolvers/resolverVueQuery.ts
17
- function capitalize(name) {
18
- return `${name.charAt(0).toUpperCase()}${name.slice(1)}`;
35
+ let kubb_jsx = require("kubb/jsx");
36
+ let kubb_jsx_jsx_runtime = require("kubb/jsx/jsx-runtime");
37
+ //#region ../../internals/shared/src/params.ts
38
+ /**
39
+ * Drops parameters that share the same name, keeping the first.
40
+ *
41
+ * A malformed spec can declare the same parameter name twice within one `in` location. Both would
42
+ * resolve to the same output property, so emitting both would yield an object type with a duplicate
43
+ * member, which TypeScript rejects. This is a defensive guard against that case, not a casing guard:
44
+ * parameter names flow through unchanged, so no two distinct names ever collide here anymore.
45
+ */
46
+ function dedupeParams(params) {
47
+ const seen = /* @__PURE__ */ new Set();
48
+ return params.filter((param) => {
49
+ if (seen.has(param.name)) return false;
50
+ seen.add(param.name);
51
+ return true;
52
+ });
53
+ }
54
+ //#endregion
55
+ //#region ../../internals/shared/src/operation.ts
56
+ /**
57
+ * Builds the `ResolverFileParams` every operation generator passes to
58
+ * `resolver.file`: a file named `name`, tagged by the operation's first
59
+ * tag (or `'default'`), at the operation's path. Centralizes the entry object
60
+ * that was repeated at dozens of call sites across the client and query plugins.
61
+ *
62
+ * @example
63
+ * ```ts
64
+ * resolver.file(operationFileEntry(node, node.operationId), { root, output, group })
65
+ * ```
66
+ */
67
+ function operationFileEntry(node, name, extname = ".ts") {
68
+ return {
69
+ name,
70
+ extname,
71
+ tag: node.tags[0] ?? "default",
72
+ path: node.path
73
+ };
74
+ }
75
+ function getOperationLink(node, link) {
76
+ if (!link) return null;
77
+ if (typeof link === "function") return link(node) ?? null;
78
+ return node.path ? `{@link ${kubb_kit.Url.toPath(node.path)}}` : null;
79
+ }
80
+ /**
81
+ * Derives the shared `ContentTypeInfo` shape from a list of content types, tracking whether several
82
+ * are present and the union, default, and form-data flags the client uses to pick one.
83
+ */
84
+ function buildContentTypeInfo(contentTypes) {
85
+ const isMultipleContentTypes = contentTypes.length > 1;
86
+ return {
87
+ contentTypes,
88
+ isMultipleContentTypes,
89
+ contentTypeUnion: isMultipleContentTypes ? contentTypes.map((ct) => JSON.stringify(ct)).join(" | ") : "",
90
+ defaultContentType: contentTypes[0] ?? "application/json",
91
+ hasFormData: contentTypes.some((ct) => ct === "multipart/form-data")
92
+ };
93
+ }
94
+ function getContentTypeInfo(node) {
95
+ return buildContentTypeInfo(node.requestBody?.content?.map((e) => e.contentType) ?? []);
96
+ }
97
+ /**
98
+ * The request-body counterpart for the primary success response: the content types it documents and
99
+ * whether several are present, so the client can let a caller pick which one to accept.
100
+ */
101
+ function getResponseContentTypeInfo(node) {
102
+ return buildContentTypeInfo(getPrimarySuccessResponse(node)?.content?.map((e) => e.contentType) ?? []);
103
+ }
104
+ function buildRequestConfigType(node) {
105
+ const request = getContentTypeInfo(node);
106
+ const response = getResponseContentTypeInfo(node);
107
+ const configType = `Partial<Omit<RequestConfig, 'path' | 'query' | 'body' | 'headers' | 'url'>>`;
108
+ const members = [request.isMultipleContentTypes ? `request?: ${request.contentTypeUnion}` : null, response.isMultipleContentTypes ? `response?: ${response.contentTypeUnion}` : null].filter(Boolean);
109
+ return members.length ? `${configType} & { contentType?: { ${members.join("; ")} } }` : configType;
110
+ }
111
+ /**
112
+ * Builds the `client?:` option type shared by the generated query hooks (`useQuery`,
113
+ * `useInfiniteQuery`, `useSWR`, ...). Unlike {@link buildRequestConfigType}, it never adds a
114
+ * `contentType?:` member: query hooks wrap GET operations, which carry no request body to select a
115
+ * content type for.
116
+ */
117
+ function buildClientOptionType() {
118
+ return `Partial<Omit<RequestConfig, 'path' | 'query' | 'body' | 'headers' | 'url'>>`;
119
+ }
120
+ /**
121
+ * Which of the grouped request options an operation carries.
122
+ */
123
+ function getRequestGroups(node) {
124
+ const { path, query, header } = getOperationParameters(node);
125
+ return {
126
+ path: path.length > 0,
127
+ query: query.length > 0,
128
+ body: Boolean(node.requestBody?.content?.[0]?.schema),
129
+ headers: header.length > 0
130
+ };
131
+ }
132
+ /**
133
+ * Resolves which grouped request options an operation carries together with whether each group
134
+ * holds a required member. The grouped parameter stays optional only when nothing inside it is
135
+ * required, matching the generated `RequestConfig` type.
136
+ */
137
+ function getRequestGroupOptionality(node) {
138
+ const groups = getRequestGroups(node);
139
+ const { path, query, header } = getOperationParameters(node);
140
+ const hasRequiredPath = path.some((param) => param.required);
141
+ const hasRequiredQuery = query.some((param) => param.required);
142
+ const hasRequiredHeader = header.some((param) => param.required);
143
+ return {
144
+ groups,
145
+ hasRequiredPath,
146
+ hasRequiredQuery,
147
+ hasRequiredHeader,
148
+ isOptional: !hasRequiredPath && !hasRequiredQuery && !hasRequiredHeader && !groups.body
149
+ };
150
+ }
151
+ function buildOperationComments(node, options = {}) {
152
+ const { link = "pathTemplate", linkPosition = "afterDeprecated", splitLines = false } = options;
153
+ const linkComment = getOperationLink(node, link);
154
+ const filteredComments = (linkPosition === "beforeDeprecated" ? [
155
+ node.description && `@description ${node.description}`,
156
+ node.summary && `@summary ${node.summary}`,
157
+ linkComment,
158
+ node.deprecated && "@deprecated"
159
+ ] : [
160
+ node.description && `@description ${node.description}`,
161
+ node.summary && `@summary ${node.summary}`,
162
+ node.deprecated && "@deprecated",
163
+ linkComment
164
+ ]).filter((comment) => Boolean(comment));
165
+ if (!splitLines) return filteredComments;
166
+ return filteredComments.flatMap((text) => text.split(/\r?\n/).map((line) => line.trim())).filter((comment) => Boolean(comment));
167
+ }
168
+ function getOperationParameters(node) {
169
+ return {
170
+ path: dedupeParams(node.parameters.filter((param) => param.in === "path")),
171
+ query: dedupeParams(node.parameters.filter((param) => param.in === "query")),
172
+ header: dedupeParams(node.parameters.filter((param) => param.in === "header")),
173
+ cookie: dedupeParams(node.parameters.filter((param) => param.in === "cookie"))
174
+ };
175
+ }
176
+ function getStatusCodeNumber(statusCode) {
177
+ const code = Number(statusCode);
178
+ return Number.isNaN(code) ? null : code;
179
+ }
180
+ function isSuccessStatusCode(statusCode) {
181
+ const code = getStatusCodeNumber(statusCode);
182
+ return code !== null && code >= 200 && code < 300;
183
+ }
184
+ function isErrorStatusCode(statusCode) {
185
+ const code = getStatusCodeNumber(statusCode);
186
+ return code !== null && code >= 400;
187
+ }
188
+ function getSuccessResponses(responses) {
189
+ return responses.filter((response) => isSuccessStatusCode(response.statusCode));
190
+ }
191
+ function getOperationSuccessResponses(node) {
192
+ return getSuccessResponses(node.responses);
193
+ }
194
+ function getPrimarySuccessResponse(node) {
195
+ return getOperationSuccessResponses(node)[0] ?? null;
196
+ }
197
+ function resolveErrorNames(node, resolver) {
198
+ return node.responses.filter((response) => isErrorStatusCode(response.statusCode)).map((response) => resolver.response.status(node, response.statusCode));
199
+ }
200
+ function resolveSuccessNames(node, resolver) {
201
+ return node.responses.filter((response) => isSuccessStatusCode(response.statusCode)).map((response) => resolver.response.status(node, response.statusCode));
202
+ }
203
+ function resolveStatusCodeNames(node, resolver) {
204
+ return node.responses.map((response) => resolver.response.status(node, response.statusCode));
205
+ }
206
+ const typeNamesByResolver = /* @__PURE__ */ new WeakMap();
207
+ function resolveOperationTypeNames(node, resolver, options = {}) {
208
+ const cacheKey = `${node.operationId}\0${options.order ?? ""}\0${options.responseStatusNames ?? ""}\0${options.includeParams === false ? "noparams" : ""}\0${(options.exclude ?? []).join(",")}`;
209
+ let byResolver = typeNamesByResolver.get(resolver);
210
+ if (byResolver) {
211
+ const cached = byResolver.get(cacheKey);
212
+ if (cached) return cached;
213
+ } else {
214
+ byResolver = /* @__PURE__ */ new Map();
215
+ typeNamesByResolver.set(resolver, byResolver);
216
+ }
217
+ const { path, query, header } = getOperationParameters(node);
218
+ const responseStatusNames = options.responseStatusNames === "error" ? resolveErrorNames(node, resolver) : options.responseStatusNames === false ? [] : resolveStatusCodeNames(node, resolver);
219
+ const exclude = new Set(options.exclude ?? []);
220
+ const paramNames = options.includeParams === false ? [] : [
221
+ ...path.map((param) => resolver.param.path(node, param)),
222
+ ...query.map((param) => resolver.param.query(node, param)),
223
+ ...header.map((param) => resolver.param.headers(node, param))
224
+ ];
225
+ const bodyAndResponseNames = [node.requestBody?.content?.[0]?.schema ? resolver.response.body(node) : null, resolver.response.response(node)];
226
+ const result = (options.order === "body-response-first" ? [
227
+ ...bodyAndResponseNames,
228
+ ...paramNames,
229
+ ...responseStatusNames
230
+ ] : [
231
+ ...paramNames,
232
+ ...bodyAndResponseNames,
233
+ ...responseStatusNames
234
+ ]).filter((name) => Boolean(name) && !exclude.has(name));
235
+ byResolver.set(cacheKey, result);
236
+ return result;
237
+ }
238
+ //#endregion
239
+ //#region ../../internals/utils/src/casing.ts
240
+ /**
241
+ * Shared implementation for camelCase and PascalCase conversion.
242
+ * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)
243
+ * and capitalizes each word according to `pascal`.
244
+ *
245
+ * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.
246
+ */
247
+ function toCamelOrPascal(text, pascal) {
248
+ return text.trim().replace(/([a-z\d])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").replace(/(\d)([a-z])/g, "$1 $2").split(/[\s\-_./\\:]+/).filter(Boolean).map((word, i) => {
249
+ if (word.length > 1 && word === word.toUpperCase()) return word;
250
+ return (i === 0 && !pascal ? word.charAt(0).toLowerCase() : word.charAt(0).toUpperCase()) + word.slice(1);
251
+ }).join("").replace(/[^a-zA-Z0-9]/g, "");
252
+ }
253
+ /**
254
+ * Converts `text` to camelCase.
255
+ *
256
+ * @example Word boundaries
257
+ * `camelCase('hello-world') // 'helloWorld'`
258
+ *
259
+ * @example With a prefix
260
+ * `camelCase('tag', { prefix: 'create' }) // 'createTag'`
261
+ */
262
+ function camelCase(text, { prefix = "", suffix = "" } = {}) {
263
+ return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false);
264
+ }
265
+ /**
266
+ * Uppercases only the first character of `text`, leaving the rest untouched.
267
+ * Unlike {@link pascalCase} it never re-splits word boundaries or strips characters.
268
+ *
269
+ * @example
270
+ * `capitalize('getPetById') // 'GetPetById'`
271
+ */
272
+ function capitalize(text) {
273
+ return `${text.charAt(0).toUpperCase()}${text.slice(1)}`;
274
+ }
275
+ //#endregion
276
+ //#region ../../internals/utils/src/strings.ts
277
+ /**
278
+ * Renders a dotted path or string array as an optional-chaining accessor expression rooted at
279
+ * `accessor`. Returns `null` for an empty path.
280
+ *
281
+ * @example
282
+ * ```ts
283
+ * getNestedAccessor('pagination.next.id', 'lastPage')
284
+ * // "lastPage?.['pagination']?.['next']?.['id']"
285
+ * ```
286
+ */
287
+ function getNestedAccessor(param, accessor) {
288
+ const parts = Array.isArray(param) ? param : param.split(".");
289
+ if (parts.length === 0 || parts.length === 1 && parts[0] === "") return null;
290
+ return `${accessor}?.['${`${parts.join("']?.['")}']`}`;
291
+ }
292
+ //#endregion
293
+ //#region ../../internals/shared/src/group.ts
294
+ /**
295
+ * Builds the `group` config a Kubb plugin passes to `ctx.setOptions`, applying the
296
+ * shared default naming so every plugin groups output consistently:
297
+ *
298
+ * - `path` groups use the second path segment (`/pet/findByStatus` → `pet`).
299
+ * - other groups use the camelCased group (`pet store` → `petStore`).
300
+ *
301
+ * A user-provided `group.name` always wins over the default namer, so callers stay in
302
+ * control of their output folders. Returns `null` when grouping is disabled, matching the
303
+ * per-plugin convention.
304
+ *
305
+ * @param group - The user-supplied group option, or `undefined` to disable grouping.
306
+ *
307
+ * @example
308
+ * ```ts
309
+ * createGroupConfig(group) // shared across every plugin
310
+ * ```
311
+ */
312
+ function createGroupConfig(group) {
313
+ if (!group) return null;
314
+ const defaultName = (ctx) => {
315
+ if (group.type === "path") return `${ctx.group.split("/")[1]}`;
316
+ return camelCase(ctx.group);
317
+ };
318
+ return {
319
+ ...group,
320
+ name: group.name ? group.name : defaultName
321
+ };
322
+ }
323
+ //#endregion
324
+ //#region ../../internals/tanstack-query/src/utils.ts
325
+ /**
326
+ * The grouped request options, ordered for both the destructured signature and the
327
+ * call passed to the underlying client.
328
+ */
329
+ const requestGroupOrder = [
330
+ "path",
331
+ "query",
332
+ "body",
333
+ "headers"
334
+ ];
335
+ /**
336
+ * Widens a request-group member type so a generated TanStack hook accepts either the value or a
337
+ * deferred value. Both plugins apply this through the `memberTypeWrapper` of `buildGroupedRequestParam`;
338
+ * they only differ in how the deferred form is later resolved.
339
+ *
340
+ * `maybeRefOrGetter` is used by vue-query, which keeps the ref/getter live and unwraps it lazily with
341
+ * `toValue` because vue-query keys are reactive. `maybeValueOrGetter` is used by react-query, which
342
+ * resolves the getter once at the hook boundary and forwards a plain value because React Query hashes
343
+ * keys structurally and cannot hold a function.
344
+ */
345
+ function maybeRefOrGetter(type) {
346
+ return `MaybeRefOrGetter<${type}>`;
347
+ }
348
+ /**
349
+ * Builds the grouped `{ path, query, body, headers }` parameter that mirrors the client
350
+ * function signature. Only the groups the operation carries are emitted, typed from the
351
+ * operation's `Options`. `keys` narrows the emitted groups, used by the query key which
352
+ * never carries `headers`.
353
+ *
354
+ * By default the whole group is typed as the single `Options` reference. When
355
+ * `memberTypeWrapper` is set, each group is emitted as its own member typed from the matching
356
+ * `Options['<group>']` slice and wrapped, used by vue-query to apply
357
+ * `MaybeRefOrGetter` per group.
358
+ */
359
+ function buildGroupedRequestParam(node, options) {
360
+ const { resolver, keys = requestGroupOrder, memberTypeWrapper } = options;
361
+ const { groups, hasRequiredPath, hasRequiredQuery, hasRequiredHeader } = getRequestGroupOptionality(node);
362
+ const names = keys.filter((key) => groups[key]);
363
+ if (names.length === 0) return null;
364
+ const requiredByGroup = {
365
+ path: hasRequiredPath,
366
+ query: hasRequiredQuery,
367
+ body: groups.body,
368
+ headers: hasRequiredHeader
369
+ };
370
+ const isOptional = names.every((name) => !requiredByGroup[name]);
371
+ const optionsName = resolver.response.options(node);
372
+ const omittedKeys = requestGroupOrder.filter((key) => !keys.includes(key));
373
+ const optionsType = omittedKeys.length > 0 ? `Omit<${optionsName}, ${omittedKeys.map((key) => `'${key}'`).join(" | ")}>` : optionsName;
374
+ if (memberTypeWrapper) {
375
+ const members = names.map((name) => ({
376
+ name,
377
+ type: memberTypeWrapper(`${optionsType}['${name}']`),
378
+ optional: !requiredByGroup[name]
379
+ }));
380
+ return (0, _kubb_plugin_ts.createFunctionParameter)({
381
+ name: (0, _kubb_plugin_ts.createObjectBindingPattern)({ elements: names.map((name) => ({ name })) }),
382
+ type: (0, _kubb_plugin_ts.createTypeLiteral)({ members }),
383
+ optional: false,
384
+ ...isOptional ? { default: "{}" } : {}
385
+ });
386
+ }
387
+ return (0, _kubb_plugin_ts.createFunctionParameter)({
388
+ name: (0, _kubb_plugin_ts.createObjectBindingPattern)({ elements: names.map((name) => ({ name })) }),
389
+ type: optionsType,
390
+ optional: false,
391
+ ...isOptional ? { default: "{}" } : {}
392
+ });
393
+ }
394
+ /**
395
+ * Builds the shared `({ path, query, body, headers }, config = {})` parameter list for a
396
+ * TanStack query-options function. The leading parameter mirrors the client signature, and the
397
+ * trailing `config` is a partial `RequestConfig` minus the grouped data-shape keys, which are passed
398
+ * explicitly. Framework plugins wrap the result when needed, for example vue-query applies `MaybeRefOrGetter`.
399
+ */
400
+ function buildQueryOptionsParams(node, options) {
401
+ const { resolver, memberTypeWrapper } = options;
402
+ return (0, _kubb_plugin_ts.createFunctionParameters)({ params: [buildGroupedRequestParam(node, {
403
+ resolver,
404
+ memberTypeWrapper
405
+ }), (0, _kubb_plugin_ts.createFunctionParameter)({
406
+ name: "config",
407
+ type: `Partial<Omit<RequestConfig, 'path' | 'query' | 'body' | 'headers' | 'url'>>`,
408
+ default: "{}"
409
+ })].filter((param) => param !== null) });
19
410
  }
20
411
  /**
21
- * Naming convention resolver for Vue Query plugin.
412
+ * Builds the call to a client `<op>` function inside a query/mutation hook body. The function takes
413
+ * a single grouped options object, so the operation's request groups are passed as
414
+ * shorthand alongside the spread `config`, with `throwOnError: true` pinned last so a caller's config
415
+ * can't flip the query's error semantics. Queries thread the TanStack `signal`; mutations omit it.
22
416
  *
23
- * Provides default naming helpers using camelCase for functions and file paths.
417
+ * When `unwrapName` is set, each request group is passed as an explicit member unwrapped through it,
418
+ * used by vue-query to resolve refs and getters with `toValue(...)` at call time.
419
+ *
420
+ * @example
421
+ * ```ts
422
+ * buildClientCall(node, { clientName: 'getPetById', signal: true })
423
+ * // getPetById({ path, ...config, signal: config.signal ?? signal, throwOnError: true })
424
+ * ```
425
+ */
426
+ function buildClientCall(node, options) {
427
+ const { clientName, signal = false, unwrapName } = options;
428
+ const { groups } = getRequestGroupOptionality(node);
429
+ return `${clientName}({ ${[
430
+ "...config",
431
+ ...requestGroupOrder.filter((key) => groups[key]).map((name) => unwrapName ? `${name}: ${unwrapName(name)}` : name),
432
+ signal ? "signal: config.signal ?? signal" : null,
433
+ "throwOnError: true"
434
+ ].filter((part) => part !== null).join(", ")} })`;
435
+ }
436
+ /**
437
+ * Builds the `TData` / `TError` type expressions shared by every generated hook, joining the resolved
438
+ * success responses into `TData` and wrapping the error responses in `ResponseErrorConfig<...>`.
439
+ */
440
+ function buildResponseTypes(node, resolver) {
441
+ const successNames = resolveSuccessNames(node, resolver);
442
+ const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.response.response(node);
443
+ const errorNames = resolveErrorNames(node, resolver);
444
+ return {
445
+ TData: responseName,
446
+ TError: `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`
447
+ };
448
+ }
449
+ function resolveFallbackPageParamType(initialPageParam) {
450
+ if (typeof initialPageParam === "number") return "number";
451
+ if (typeof initialPageParam === "boolean") return "boolean";
452
+ if (typeof initialPageParam !== "string") return "unknown";
453
+ if (!initialPageParam.includes(" as ")) return "string";
454
+ return initialPageParam.split(" as ").at(-1) ?? "unknown";
455
+ }
456
+ /**
457
+ * Resolves the `TPageParam` generic for the infinite-query hooks. Prefers the type read from the
458
+ * configured `queryParam` on the operation's query object, and falls back to the type inferred from
459
+ * `initialPageParam` when that parameter type is unavailable. Also returns the query params type name
460
+ * so callers can reuse it when rewriting the paginated request.
461
+ */
462
+ function resolvePageParamType(node, { resolver, initialPageParam, queryParam }) {
463
+ const firstQueryParam = getOperationParameters(node).query[0];
464
+ const groupName = firstQueryParam ? resolver.param.query(node, firstQueryParam) : null;
465
+ const queryParamsTypeName = groupName !== (firstQueryParam ? resolver.param.name(node, firstQueryParam) : null) ? groupName : null;
466
+ const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : null;
467
+ if (!queryParamType) return {
468
+ queryParamsTypeName,
469
+ pageParamType: resolveFallbackPageParamType(initialPageParam)
470
+ };
471
+ return {
472
+ queryParamsTypeName,
473
+ pageParamType: initialPageParam !== void 0 && initialPageParam !== null ? `NonNullable<${queryParamType}>` : queryParamType
474
+ };
475
+ }
476
+ /**
477
+ * Applies the shared query defaults during plugin setup: `false` disables query generation, and an
478
+ * object merges over `methods: ['GET']` and the plugin's runtime `importPath`.
479
+ */
480
+ function resolveQueryConfig(query, options) {
481
+ if (query === false) return false;
482
+ return {
483
+ importPath: options.importPath,
484
+ methods: ["GET"],
485
+ ...query
486
+ };
487
+ }
488
+ /**
489
+ * Applies the shared mutation defaults during plugin setup: `false` disables mutation generation,
490
+ * and an object merges over `methods: ['POST', 'PUT', 'PATCH', 'DELETE']` and the plugin's runtime
491
+ * `importPath`.
492
+ */
493
+ function resolveMutationConfig(mutation, options) {
494
+ if (mutation === false) return false;
495
+ return {
496
+ importPath: options.importPath,
497
+ methods: [
498
+ "POST",
499
+ "PUT",
500
+ "PATCH",
501
+ "DELETE"
502
+ ],
503
+ ...mutation
504
+ };
505
+ }
506
+ /**
507
+ * Classifies an operation as a query or a mutation from the resolved `query` / `mutation` method lists.
508
+ * `query: false` still marks the operation as a query so the query-family generators keep matching it,
509
+ * and a method already claimed by `query` never counts as a mutation.
24
510
  */
25
- const resolverVueQuery = (0, _kubb_core.defineResolver)(() => ({
26
- name: "default",
511
+ function classifyOperation(node, { query, mutation }) {
512
+ const isQuery = query === false || !!query && query.methods.some((method) => node.method.toLowerCase() === method.toLowerCase());
513
+ const queryMethods = new Set(query ? query.methods : []);
514
+ return {
515
+ isQuery,
516
+ isMutation: mutation !== false && !isQuery && (mutation ? mutation.methods : []).some((method) => !queryMethods.has(method) && node.method.toLowerCase() === method.toLowerCase())
517
+ };
518
+ }
519
+ /**
520
+ * Applies the shared infinite-query defaults during plugin setup: a falsy value disables infinite
521
+ * queries, and an object merges over `queryParam: 'id'` and `initialPageParam: 0` with the cursor
522
+ * paths cleared.
523
+ */
524
+ function resolveInfiniteConfig(infinite) {
525
+ if (!infinite) return false;
526
+ return {
527
+ queryParam: "id",
528
+ initialPageParam: 0,
529
+ cursorParam: null,
530
+ nextParam: null,
531
+ previousParam: null,
532
+ ...infinite
533
+ };
534
+ }
535
+ //#endregion
536
+ //#region ../../internals/tanstack-query/src/components/InfiniteQueryOptions.tsx
537
+ const declarationPrinter$7 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
538
+ const callPrinter$4 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
539
+ function InfiniteQueryOptions$1({ name, clientName, initialPageParam, cursorParam, nextParam, previousParam, node, tsResolver, queryParam, queryKeyName, queryKeyType = "typeof queryKey", memberTypeWrapper, unwrapName }) {
540
+ const { TData: queryFnDataType, TError: errorType } = buildResponseTypes(node, tsResolver);
541
+ const { queryParamsTypeName, pageParamType } = resolvePageParamType(node, {
542
+ resolver: tsResolver,
543
+ initialPageParam,
544
+ queryParam
545
+ });
546
+ const groupedKeyParam = buildGroupedRequestParam(node, {
547
+ resolver: tsResolver,
548
+ keys: [
549
+ "path",
550
+ "query",
551
+ "body"
552
+ ],
553
+ memberTypeWrapper
554
+ });
555
+ const queryKeyParamsNode = (0, _kubb_plugin_ts.createFunctionParameters)({ params: groupedKeyParam ? [groupedKeyParam] : [] });
556
+ const queryKeyParamsCall = callPrinter$4.print(queryKeyParamsNode) ?? "";
557
+ const paramsNode = buildQueryOptionsParams(node, {
558
+ resolver: tsResolver,
559
+ memberTypeWrapper
560
+ });
561
+ const paramsSignature = declarationPrinter$7.print(paramsNode) ?? "";
562
+ const queryFnBody = `const { data } = await ${buildClientCall(node, {
563
+ clientName,
564
+ signal: true,
565
+ unwrapName
566
+ })}
567
+ return data`;
568
+ const hasNewParams = nextParam != null || previousParam != null;
569
+ const [getNextPageParamExpr, getPreviousPageParamExpr] = (() => {
570
+ if (hasNewParams) {
571
+ const nextAccessor = nextParam ? getNestedAccessor(nextParam, "lastPage") : null;
572
+ const prevAccessor = previousParam ? getNestedAccessor(previousParam, "firstPage") : null;
573
+ return [nextAccessor ? `getNextPageParam: (lastPage) => ${nextAccessor}` : null, prevAccessor ? `getPreviousPageParam: (firstPage) => ${prevAccessor}` : null];
574
+ }
575
+ if (cursorParam) return [`getNextPageParam: (lastPage) => lastPage['${cursorParam}']`, `getPreviousPageParam: (firstPage) => firstPage['${cursorParam}']`];
576
+ return ["getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage) && lastPage.length === 0 ? undefined : lastPageParam + 1", "getPreviousPageParam: (_firstPage, _allPages, firstPageParam) => firstPageParam <= 1 ? undefined : firstPageParam - 1"];
577
+ })();
578
+ const queryOptionsArr = [
579
+ `initialPageParam: ${typeof initialPageParam === "string" ? JSON.stringify(initialPageParam) : initialPageParam}`,
580
+ getNextPageParamExpr,
581
+ getPreviousPageParamExpr
582
+ ].filter(Boolean);
583
+ const infiniteOverrideParams = queryParam && queryParamsTypeName ? `query = {
584
+ ...(query ?? {}),
585
+ ['${queryParam}']: pageParam as unknown as ${queryParamsTypeName}['${queryParam}'],
586
+ } as ${queryParamsTypeName}` : "";
587
+ const queryFnArgs = infiniteOverrideParams ? "{ signal, pageParam }" : "{ signal }";
588
+ const queryFnStatements = infiniteOverrideParams ? `${infiniteOverrideParams}\n ${queryFnBody}` : queryFnBody;
589
+ return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
590
+ name,
591
+ isExportable: true,
592
+ isIndexable: true,
593
+ children: /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.Function, {
594
+ name,
595
+ export: true,
596
+ params: paramsSignature,
597
+ children: `
598
+ const queryKey = ${queryKeyName}(${queryKeyParamsCall})
599
+ return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, ${queryKeyType}, ${pageParamType}>({
600
+ queryKey,
601
+ queryFn: async (${queryFnArgs}) => {
602
+ ${queryFnStatements}
603
+ },
604
+ ${queryOptionsArr.join(",\n ")}
605
+ })
606
+ `
607
+ })
608
+ });
609
+ }
610
+ __name(InfiniteQueryOptions$1, "InfiniteQueryOptions");
611
+ //#endregion
612
+ //#region ../../internals/tanstack-query/src/components/MutationKey.tsx
613
+ const declarationPrinter$6 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
614
+ const mutationKeyTransformer = ({ node }) => {
615
+ if (!node.path) return [];
616
+ return [`{ url: '${kubb_kit.Url.toPath(node.path)}' }`];
617
+ };
618
+ function MutationKey({ name, node, transformer }) {
619
+ const paramsNode = (0, _kubb_plugin_ts.createFunctionParameters)({ params: [] });
620
+ const paramsSignature = declarationPrinter$6.print(paramsNode) ?? "";
621
+ const keys = (transformer ?? mutationKeyTransformer)({
622
+ node,
623
+ casing: "camelcase"
624
+ });
625
+ return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
626
+ name,
627
+ isExportable: true,
628
+ isIndexable: true,
629
+ children: /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.Function.Arrow, {
630
+ name,
631
+ export: true,
632
+ params: paramsSignature,
633
+ singleLine: true,
634
+ children: `[${keys.join(", ")}] as const`
635
+ })
636
+ });
637
+ }
638
+ //#endregion
639
+ //#region ../../internals/tanstack-query/src/resolver.ts
640
+ /**
641
+ * Builds the shared query namespace for a variant. Spread the result into
642
+ * `createResolver` once per variant the plugin supports.
643
+ *
644
+ * @example
645
+ * ```ts
646
+ * createResolver<PluginReactQuery>({
647
+ * query: createQueryResolver(),
648
+ * suspenseQuery: createQueryResolver('Suspense'),
649
+ * })
650
+ * ```
651
+ */
652
+ function createQueryResolver(variant = "") {
653
+ return {
654
+ name(node) {
655
+ return `use${capitalize(this.name(node.operationId))}${variant}`;
656
+ },
657
+ optionsName(node) {
658
+ return `${this.name(node.operationId)}${variant}QueryOptions`;
659
+ },
660
+ keyName(node) {
661
+ return `${this.name(node.operationId)}${variant}QueryKey`;
662
+ },
663
+ keyTypeName(node) {
664
+ return `${capitalize(this.name(node.operationId))}${variant}QueryKey`;
665
+ },
666
+ clientName(node) {
667
+ return `${this.name(node.operationId)}${variant}`;
668
+ }
669
+ };
670
+ }
671
+ /**
672
+ * Builds the shared mutation namespace. Spread the result into
673
+ * `createResolver` and add plugin-specific methods (`optionsName`,
674
+ * `typeName`, `argTypeName`) next to it.
675
+ *
676
+ * @example
677
+ * ```ts
678
+ * createResolver<PluginSwr>({ mutation: { ...createMutationResolver(), argTypeName(node) {...} } })
679
+ * ```
680
+ */
681
+ function createMutationResolver() {
682
+ return {
683
+ name(node) {
684
+ return `use${capitalize(this.name(node.operationId))}`;
685
+ },
686
+ keyName(node) {
687
+ return `${this.name(node.operationId)}MutationKey`;
688
+ }
689
+ };
690
+ }
691
+ (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
692
+ const queryKeyTransformer = ({ node }) => {
693
+ if (!node.path) return [];
694
+ const hasPathParams = getOperationParameters(node).path.length > 0;
695
+ const hasQueryParams = getOperationParameters(node).query.length > 0;
696
+ const hasRequestBody = !!node.requestBody?.content?.[0]?.schema;
697
+ return [
698
+ hasPathParams ? `{ url: '${kubb_kit.Url.toPath(node.path)}', params: path }` : `{ url: '${kubb_kit.Url.toPath(node.path)}' }`,
699
+ hasQueryParams ? "...(query ? [query] : [])" : null,
700
+ hasRequestBody ? "...(body ? [body] : [])" : null
701
+ ].filter(Boolean);
702
+ };
703
+ //#endregion
704
+ //#region ../../internals/client/src/resolveClient.ts
705
+ /**
706
+ * Resolves which client plugin a consumer (react-query, vue-query, swr, mcp) should call for an
707
+ * operation, shared so the selection rules and diagnostics stay in one place.
708
+ *
709
+ * Every client runtime lives in a dedicated client plugin, so a consumer always calls a registered
710
+ * contract client plugin (plugin-fetch or plugin-axios) and never emits its own inline client:
711
+ *
712
+ * - `contract` — a registered contract client plugin owns the `<op>` functions and the consumer
713
+ * imports and calls them.
714
+ * - `error` — no client plugin is registered, several are registered without a selector, or the
715
+ * requested one is missing.
716
+ *
717
+ * The `client` string selects explicitly (`'fetch'` / `'axios'`); when it is unset a lone registered
718
+ * contract client plugin is picked up automatically.
719
+ */
720
+ const pluginFetchName = "plugin-fetch";
721
+ const pluginAxiosName = "plugin-axios";
722
+ const selectorToPlugin = {
723
+ fetch: pluginFetchName,
724
+ axios: pluginAxiosName
725
+ };
726
+ const contractPlugins = [pluginFetchName, pluginAxiosName];
727
+ /**
728
+ * Applies the `client` resolution rules. See the module comment for the strategy shape.
729
+ *
730
+ * @example
731
+ * ```ts
732
+ * resolveClient({ client: 'fetch', pluginNames: ['plugin-ts', 'plugin-fetch'] })
733
+ * // { kind: 'contract', pluginName: 'plugin-fetch' }
734
+ * ```
735
+ *
736
+ * @example
737
+ * ```ts
738
+ * resolveClient({ client: undefined, pluginNames: ['plugin-ts'] })
739
+ * // { kind: 'error', message: 'No client plugin is registered…' }
740
+ * ```
741
+ */
742
+ function resolveClient(options) {
743
+ const { client, pluginNames } = options;
744
+ const has = (name) => pluginNames.includes(name);
745
+ if (client === "fetch" || client === "axios") {
746
+ const pluginName = selectorToPlugin[client];
747
+ if (!has(pluginName)) return {
748
+ kind: "error",
749
+ message: `\`client: '${client}'\` is set but \`@kubb/plugin-${client}\` is not registered in \`plugins\`. Add it, or drop \`client\` to use a different client plugin.`
750
+ };
751
+ return {
752
+ kind: "contract",
753
+ pluginName
754
+ };
755
+ }
756
+ const registered = contractPlugins.filter(has);
757
+ if (registered.length === 1) return {
758
+ kind: "contract",
759
+ pluginName: registered[0]
760
+ };
761
+ if (registered.length > 1) return {
762
+ kind: "error",
763
+ message: `Multiple client plugins are registered (${registered.map((name) => `\`@kubb/${name}\``).join(", ")}). Set \`client: 'fetch' | 'axios'\` to choose which client the hooks call, or register a single client plugin.`
764
+ };
765
+ return {
766
+ kind: "error",
767
+ message: "No client plugin is registered. Add `@kubb/plugin-axios` or `@kubb/plugin-fetch` to `plugins` so the generated code has an HTTP client to call."
768
+ };
769
+ }
770
+ /**
771
+ * Resolves the contract client during a consumer plugin's setup hook. Extracts the plugin names
772
+ * from the raw `plugins` config, applies {@link resolveClient}, and throws the diagnostic on a
773
+ * misconfiguration so every consumer fails fast with the same message.
774
+ */
775
+ function resolveContractClient(options) {
776
+ const { client, plugins = [] } = options;
777
+ const resolved = resolveClient({
778
+ client,
779
+ pluginNames: plugins.map((plugin) => plugin.name).filter((name) => Boolean(name))
780
+ });
781
+ if (resolved.kind === "error") throw new Error(resolved.message);
782
+ return resolved;
783
+ }
784
+ //#endregion
785
+ //#region ../../internals/client/src/resolveClientOperation.ts
786
+ /**
787
+ * Resolves the contract client `<op>` a consumer (query hook, MCP handler) imports, by looking up
788
+ * the registered contract client plugin's resolver and output. Works for any contract client plugin
789
+ * (plugin-fetch or plugin-axios). Returns `null` when no contract plugin is in play (the inline
790
+ * path). The plugin injects `.kubb/client.ts` at the global output root, the same path consumers
791
+ * read `RequestConfig` / `ResponseErrorConfig` from.
792
+ */
793
+ function resolveClientOperation(options) {
794
+ const { clientPlugin, driver, node, root, output } = options;
795
+ if (!clientPlugin) return null;
796
+ const resolver = driver.getResolver(clientPlugin.pluginName);
797
+ const plugin = driver.getPlugin(clientPlugin.pluginName);
798
+ const file = resolver.file({
799
+ ...operationFileEntry(node, node.operationId),
800
+ root,
801
+ output: plugin?.options?.output ?? output,
802
+ group: plugin?.options?.group ?? void 0
803
+ });
804
+ return {
805
+ name: resolver.name(node.operationId),
806
+ path: file.path,
807
+ clientPath: node_path.default.resolve(root, ".kubb/client.ts")
808
+ };
809
+ }
810
+ //#endregion
811
+ //#region src/utils.ts
812
+ /**
813
+ * Builds the call to a contract client `<op>` function inside a vue-query composable body. The
814
+ * function takes a single grouped options object, so `config` is spread first, then the operation's
815
+ * request groups are unwrapped with `toValue()`, then the abort `signal` for queries, with
816
+ * `throwOnError: true` pinned last so a caller's config can't flip the query's error semantics.
817
+ * Mutations omit the `signal`.
818
+ */
819
+ function buildVueClientCall(node, options) {
820
+ return buildClientCall(node, {
821
+ ...options,
822
+ unwrapName: (name) => `toValue(${name})`
823
+ });
824
+ }
825
+ //#endregion
826
+ //#region src/components/QueryKey.tsx
827
+ const declarationPrinter$4 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
828
+ function buildQueryKeyParamsNode(node, options) {
829
+ const groupedParam = buildGroupedRequestParam(node, {
830
+ resolver: options.resolver,
831
+ keys: [
832
+ "path",
833
+ "query",
834
+ "body"
835
+ ],
836
+ memberTypeWrapper: maybeRefOrGetter
837
+ });
838
+ return (0, _kubb_plugin_ts.createFunctionParameters)({ params: groupedParam ? [groupedParam] : [] });
839
+ }
840
+ function QueryKey({ name, node, tsResolver, typeName, transformer }) {
841
+ const paramsNode = buildQueryKeyParamsNode(node, { resolver: tsResolver });
842
+ const paramsSignature = declarationPrinter$4.print(paramsNode) ?? "";
843
+ const keys = (transformer ?? queryKeyTransformer)({
844
+ node,
845
+ casing: "camelcase"
846
+ });
847
+ return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(kubb_jsx_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
848
+ name,
849
+ isExportable: true,
850
+ isIndexable: true,
851
+ children: /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.Function.Arrow, {
852
+ name,
853
+ export: true,
854
+ params: paramsSignature,
855
+ singleLine: true,
856
+ children: `[${keys.join(", ")}] as const`
857
+ })
858
+ }), /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
859
+ name: typeName,
860
+ isExportable: true,
861
+ isIndexable: true,
862
+ isTypeOnly: true,
863
+ children: /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.Type, {
864
+ name: typeName,
865
+ export: true,
866
+ children: `ReturnType<typeof ${name}>`
867
+ })
868
+ })] });
869
+ }
870
+ //#endregion
871
+ //#region src/components/QueryOptions.tsx
872
+ const declarationPrinter$3 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
873
+ const callPrinter$3 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
874
+ function getQueryOptionsParams(node, options) {
875
+ return buildQueryOptionsParams(node, {
876
+ resolver: options.resolver,
877
+ memberTypeWrapper: maybeRefOrGetter
878
+ });
879
+ }
880
+ function QueryOptions({ name, clientName, node, tsResolver, queryKeyName }) {
881
+ const { TData, TError } = buildResponseTypes(node, tsResolver);
882
+ const queryKeyParamsNode = buildQueryKeyParamsNode(node, { resolver: tsResolver });
883
+ const queryKeyParamsCall = callPrinter$3.print(queryKeyParamsNode) ?? "";
884
+ const paramsNode = getQueryOptionsParams(node, { resolver: tsResolver });
885
+ const paramsSignature = declarationPrinter$3.print(paramsNode) ?? "";
886
+ const queryFnBody = `const { data } = await ${buildVueClientCall(node, {
887
+ clientName,
888
+ signal: true
889
+ })}
890
+ return data`;
891
+ return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
892
+ name,
893
+ isExportable: true,
894
+ isIndexable: true,
895
+ children: /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.Function, {
896
+ name,
897
+ export: true,
898
+ params: paramsSignature,
899
+ children: `
900
+ const queryKey = ${queryKeyName}(${queryKeyParamsCall})
901
+ return queryOptions<${TData}, ${TError}, ${TData}>({
902
+ queryKey,
903
+ queryFn: async ({ signal }) => {
904
+ ${queryFnBody}
905
+ },
906
+ })
907
+ `
908
+ })
909
+ });
910
+ }
911
+ //#endregion
912
+ //#region src/components/InfiniteQuery.tsx
913
+ const declarationPrinter$2 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
914
+ const callPrinter$2 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
915
+ function buildInfiniteQueryParamsNode(node, options) {
916
+ const { resolver } = options;
917
+ const { TData, TError } = buildResponseTypes(node, resolver);
918
+ const optionsParam = (0, _kubb_plugin_ts.createFunctionParameter)({
919
+ name: "options",
920
+ type: `{
921
+ query?: Partial<UseInfiniteQueryOptions<${[
922
+ TData,
923
+ TError,
924
+ "TQueryData",
925
+ "TQueryKey",
926
+ "TQueryData"
927
+ ].join(", ")}>> & { client?: QueryClient },
928
+ client?: ${buildClientOptionType()}
929
+ }`,
930
+ default: "{}"
931
+ });
932
+ return (0, _kubb_plugin_ts.createFunctionParameters)({ params: [buildGroupedRequestParam(node, {
933
+ resolver,
934
+ memberTypeWrapper: maybeRefOrGetter
935
+ }), optionsParam].filter((param) => param !== null) });
936
+ }
937
+ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, tsResolver }) {
938
+ const { TData, TError } = buildResponseTypes(node, tsResolver);
939
+ const returnType = `UseInfiniteQueryReturnType<${["TData", TError].join(", ")}> & { queryKey: TQueryKey }`;
940
+ const generics = [
941
+ `TData = InfiniteData<${TData}>`,
942
+ `TQueryData = ${TData}`,
943
+ `TQueryKey extends QueryKey = ${queryKeyTypeName}`
944
+ ];
945
+ const queryKeyParamsNode = buildQueryKeyParamsNode(node, { resolver: tsResolver });
946
+ const queryKeyParamsCall = callPrinter$2.print(queryKeyParamsNode) ?? "";
947
+ const queryOptionsParamsNode = getQueryOptionsParams(node, { resolver: tsResolver });
948
+ const queryOptionsParamsCall = callPrinter$2.print(queryOptionsParamsNode) ?? "";
949
+ const paramsNode = buildInfiniteQueryParamsNode(node, { resolver: tsResolver });
950
+ const paramsSignature = declarationPrinter$2.print(paramsNode) ?? "";
951
+ return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
952
+ name,
953
+ isExportable: true,
954
+ isIndexable: true,
955
+ children: /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.Function, {
956
+ name,
957
+ export: true,
958
+ generics: generics.join(", "),
959
+ params: paramsSignature,
960
+ JSDoc: { comments: buildOperationComments(node) },
961
+ children: `
962
+ const { query: queryConfig = {}, client: config = {} } = options ?? {}
963
+ const { client: queryClient, ...resolvedOptions } = queryConfig
964
+ const queryKey = (resolvedOptions && 'queryKey' in resolvedOptions ? toValue(resolvedOptions.queryKey) : undefined) ?? ${queryKeyName}(${queryKeyParamsCall})
965
+
966
+ const queryResult = useInfiniteQuery({
967
+ ...${queryOptionsName}(${queryOptionsParamsCall}),
968
+ ...resolvedOptions,
969
+ queryKey
970
+ } as unknown as UseInfiniteQueryOptions<${TData}, ${TError}, ${TData}, TQueryKey, ${TData}>, toValue(queryClient)) as ${returnType}
971
+
972
+ queryResult.queryKey = queryKey as TQueryKey
973
+
974
+ return queryResult
975
+ `
976
+ })
977
+ });
978
+ }
979
+ //#endregion
980
+ //#region src/components/InfiniteQueryOptions.tsx
981
+ /**
982
+ * The vue-query flavor of the shared `infiniteQueryOptions` component: request groups accept
983
+ * `MaybeRefOrGetter` values, are unwrapped with `toValue(...)` in the client call, and the emitted
984
+ * `TQueryKey` generic is the imported `QueryKey` type instead of `typeof queryKey`.
985
+ */
986
+ function InfiniteQueryOptions(props) {
987
+ return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(InfiniteQueryOptions$1, {
988
+ ...props,
989
+ queryKeyType: "QueryKey",
990
+ memberTypeWrapper: maybeRefOrGetter,
991
+ unwrapName: (name) => `toValue(${name})`
992
+ });
993
+ }
994
+ //#endregion
995
+ //#region src/components/Mutation.tsx
996
+ const declarationPrinter$1 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
997
+ const callPrinter$1 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
998
+ function resolveMutationRequestType(node, resolver) {
999
+ return buildGroupedRequestParam(node, { resolver }) ? resolver.response.options(node) : "undefined";
1000
+ }
1001
+ function buildMutationParamsNode(node, options) {
1002
+ const { resolver } = options;
1003
+ const { TData, TError } = buildResponseTypes(node, resolver);
1004
+ return (0, _kubb_plugin_ts.createFunctionParameters)({ params: [(0, _kubb_plugin_ts.createFunctionParameter)({
1005
+ name: "options",
1006
+ type: `{
1007
+ mutation?: MutationObserverOptions<${[
1008
+ TData,
1009
+ TError,
1010
+ resolveMutationRequestType(node, resolver),
1011
+ "TContext"
1012
+ ].join(", ")}> & { client?: QueryClient },
1013
+ client?: ${buildRequestConfigType(node)},
1014
+ }`,
1015
+ default: "{}"
1016
+ })] });
1017
+ }
1018
+ function Mutation({ name, clientName, node, tsResolver, mutationKeyName }) {
1019
+ const { TData, TError } = buildResponseTypes(node, tsResolver);
1020
+ const groupedParam = buildGroupedRequestParam(node, { resolver: tsResolver });
1021
+ const hasMutationParams = groupedParam !== null;
1022
+ const groupedParamsNode = (0, _kubb_plugin_ts.createFunctionParameters)({ params: groupedParam ? [groupedParam] : [] });
1023
+ const argBindingStr = hasMutationParams ? callPrinter$1.print(groupedParamsNode) ?? "" : "";
1024
+ const mutationFnBody = `const { data } = await ${buildVueClientCall(node, {
1025
+ clientName,
1026
+ signal: false
1027
+ })}
1028
+ return data`;
1029
+ const generics = [
1030
+ TData,
1031
+ TError,
1032
+ resolveMutationRequestType(node, tsResolver),
1033
+ "TContext"
1034
+ ].join(", ");
1035
+ const paramsNode = buildMutationParamsNode(node, { resolver: tsResolver });
1036
+ const paramsSignature = declarationPrinter$1.print(paramsNode) ?? "";
1037
+ return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
1038
+ name,
1039
+ isExportable: true,
1040
+ isIndexable: true,
1041
+ children: /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.Function, {
1042
+ name,
1043
+ export: true,
1044
+ params: paramsSignature,
1045
+ JSDoc: { comments: buildOperationComments(node) },
1046
+ generics: ["TContext"],
1047
+ children: `
1048
+ const { mutation = {}, client: config = {} } = options ?? {}
1049
+ const { client: queryClient, ...mutationOptions } = mutation;
1050
+ const mutationKey = mutationOptions?.mutationKey ?? ${mutationKeyName}()
1051
+
1052
+ return useMutation<${generics}>({
1053
+ mutationFn: async(${argBindingStr}) => {
1054
+ ${mutationFnBody}
1055
+ },
1056
+ mutationKey,
1057
+ ...mutationOptions
1058
+ }, queryClient)
1059
+ `
1060
+ })
1061
+ });
1062
+ }
1063
+ //#endregion
1064
+ //#region src/components/Query.tsx
1065
+ const declarationPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
1066
+ const callPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
1067
+ function buildQueryParamsNode(node, options) {
1068
+ const { resolver } = options;
1069
+ const { TData, TError } = buildResponseTypes(node, resolver);
1070
+ const optionsParam = (0, _kubb_plugin_ts.createFunctionParameter)({
1071
+ name: "options",
1072
+ type: `{
1073
+ query?: Partial<UseQueryOptions<${[
1074
+ TData,
1075
+ TError,
1076
+ "TData",
1077
+ "TQueryData",
1078
+ "TQueryKey"
1079
+ ].join(", ")}>> & { client?: QueryClient },
1080
+ client?: ${buildClientOptionType()}
1081
+ }`,
1082
+ default: "{}"
1083
+ });
1084
+ return (0, _kubb_plugin_ts.createFunctionParameters)({ params: [buildGroupedRequestParam(node, {
1085
+ resolver,
1086
+ memberTypeWrapper: maybeRefOrGetter
1087
+ }), optionsParam].filter((param) => param !== null) });
1088
+ }
1089
+ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, tsResolver }) {
1090
+ const { TData, TError } = buildResponseTypes(node, tsResolver);
1091
+ const returnType = `UseQueryReturnType<${["TData", TError].join(", ")}> & { queryKey: TQueryKey }`;
1092
+ const generics = [
1093
+ `TData = ${TData}`,
1094
+ `TQueryData = ${TData}`,
1095
+ `TQueryKey extends QueryKey = ${queryKeyTypeName}`
1096
+ ];
1097
+ const queryKeyParamsNode = buildQueryKeyParamsNode(node, { resolver: tsResolver });
1098
+ const queryKeyParamsCall = callPrinter.print(queryKeyParamsNode) ?? "";
1099
+ const queryOptionsParamsNode = getQueryOptionsParams(node, { resolver: tsResolver });
1100
+ const queryOptionsParamsCall = callPrinter.print(queryOptionsParamsNode) ?? "";
1101
+ const paramsNode = buildQueryParamsNode(node, { resolver: tsResolver });
1102
+ const paramsSignature = declarationPrinter.print(paramsNode) ?? "";
1103
+ return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
1104
+ name,
1105
+ isExportable: true,
1106
+ isIndexable: true,
1107
+ children: /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.Function, {
1108
+ name,
1109
+ export: true,
1110
+ generics: generics.join(", "),
1111
+ params: paramsSignature,
1112
+ JSDoc: { comments: buildOperationComments(node) },
1113
+ children: `
1114
+ const { query: queryConfig = {}, client: config = {} } = options ?? {}
1115
+ const { client: queryClient, ...resolvedOptions } = queryConfig
1116
+ const queryKey = (resolvedOptions && 'queryKey' in resolvedOptions ? toValue(resolvedOptions.queryKey) : undefined) ?? ${queryKeyName}(${queryKeyParamsCall})
1117
+
1118
+ const queryResult = useQuery({
1119
+ ...${queryOptionsName}(${queryOptionsParamsCall}),
1120
+ ...resolvedOptions,
1121
+ queryKey
1122
+ } as unknown as UseQueryOptions<${TData}, ${TError}, TData, ${TData}, TQueryKey>, toValue(queryClient)) as ${returnType}
1123
+
1124
+ queryResult.queryKey = queryKey as TQueryKey
1125
+
1126
+ return queryResult
1127
+ `
1128
+ })
1129
+ });
1130
+ }
1131
+ //#endregion
1132
+ //#region src/generators/infiniteQueryGenerator.tsx
1133
+ /**
1134
+ * Built-in generator for `useInfiniteQuery` composables. Enabled when
1135
+ * `pluginVueQuery({ infinite: { ... }, hooks: true })`. Emits one
1136
+ * `useFooInfiniteQuery` composable per query operation, wiring the
1137
+ * configured cursor path into TanStack Query's cursor-based pagination.
1138
+ */
1139
+ const infiniteQueryGenerator = (0, kubb_kit.defineGenerator)({
1140
+ name: "vue-query-infinite",
1141
+ renderer: kubb_jsx.jsxRenderer,
1142
+ operation(node, ctx) {
1143
+ if (!kubb_kit.ast.isHttpOperationNode(node)) return null;
1144
+ const { config, driver, resolver, root } = ctx;
1145
+ const { output, query, mutation, infinite, client, group, hooks } = ctx.options;
1146
+ const pluginTs = driver.getPlugin(_kubb_plugin_ts.pluginTsName);
1147
+ if (!pluginTs) return null;
1148
+ const tsResolver = driver.getResolver(_kubb_plugin_ts.pluginTsName);
1149
+ const { isQuery, isMutation } = classifyOperation(node, {
1150
+ query,
1151
+ mutation
1152
+ });
1153
+ const infiniteOptions = infinite && typeof infinite === "object" ? infinite : null;
1154
+ if (!isQuery || isMutation || !infiniteOptions || !hooks) return null;
1155
+ const normalizeKey = (key) => key.replace(/\?$/, "");
1156
+ const queryParamKeys = getOperationParameters(node).query.map((p) => p.name);
1157
+ if (!(infiniteOptions.queryParam ? queryParamKeys.some((k) => normalizeKey(k) === infiniteOptions.queryParam) : false)) return null;
1158
+ const importPath = query ? query.importPath : "@tanstack/vue-query";
1159
+ const contractOp = resolveClientOperation({
1160
+ clientPlugin: { pluginName: client.pluginName },
1161
+ driver,
1162
+ node,
1163
+ root,
1164
+ output
1165
+ });
1166
+ if (!contractOp) return null;
1167
+ const queryName = resolver.infiniteQuery.name(node);
1168
+ const queryOptionsName = resolver.infiniteQuery.optionsName(node);
1169
+ const queryKeyName = resolver.infiniteQuery.keyName(node);
1170
+ const queryKeyTypeName = resolver.infiniteQuery.keyTypeName(node);
1171
+ const meta = {
1172
+ file: resolver.file({
1173
+ ...operationFileEntry(node, queryName),
1174
+ root,
1175
+ output,
1176
+ group: group ?? void 0
1177
+ }),
1178
+ fileTs: tsResolver.file({
1179
+ ...operationFileEntry(node, node.operationId),
1180
+ root,
1181
+ output: pluginTs.options?.output ?? output,
1182
+ group: pluginTs.options?.group ?? void 0
1183
+ })
1184
+ };
1185
+ const { queryParamsTypeName } = resolvePageParamType(node, {
1186
+ resolver: tsResolver,
1187
+ initialPageParam: infiniteOptions.initialPageParam,
1188
+ queryParam: infiniteOptions.queryParam
1189
+ });
1190
+ const importedTypeNames = [
1191
+ tsResolver.response.options(node),
1192
+ queryParamsTypeName,
1193
+ ...resolveOperationTypeNames(node, tsResolver, {
1194
+ exclude: [queryKeyTypeName],
1195
+ order: "body-response-first",
1196
+ includeParams: false
1197
+ })
1198
+ ].filter((name) => Boolean(name));
1199
+ const calledClientName = contractOp.name;
1200
+ return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(kubb_jsx.File, {
1201
+ baseName: meta.file.baseName,
1202
+ path: meta.file.path,
1203
+ meta: meta.file.meta,
1204
+ banner: resolver.default.banner(ctx.meta, {
1205
+ output,
1206
+ config,
1207
+ file: {
1208
+ path: meta.file.path,
1209
+ baseName: meta.file.baseName
1210
+ }
1211
+ }),
1212
+ footer: resolver.default.footer(ctx.meta, {
1213
+ output,
1214
+ config,
1215
+ file: {
1216
+ path: meta.file.path,
1217
+ baseName: meta.file.baseName
1218
+ }
1219
+ }),
1220
+ children: [
1221
+ /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
1222
+ name: [contractOp.name],
1223
+ root: meta.file.path,
1224
+ path: contractOp.path
1225
+ }),
1226
+ /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
1227
+ name: ["RequestConfig", "ResponseErrorConfig"],
1228
+ root: meta.file.path,
1229
+ path: contractOp.clientPath,
1230
+ isTypeOnly: true
1231
+ }),
1232
+ /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
1233
+ name: ["toValue"],
1234
+ path: "vue"
1235
+ }),
1236
+ /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
1237
+ name: ["MaybeRefOrGetter"],
1238
+ path: "vue",
1239
+ isTypeOnly: true
1240
+ }),
1241
+ meta.fileTs && importedTypeNames.length > 0 && /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
1242
+ name: Array.from(new Set(importedTypeNames)),
1243
+ root: meta.file.path,
1244
+ path: meta.fileTs.path,
1245
+ isTypeOnly: true
1246
+ }),
1247
+ /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(QueryKey, {
1248
+ name: queryKeyName,
1249
+ typeName: queryKeyTypeName,
1250
+ node,
1251
+ tsResolver,
1252
+ transformer: ctx.options.queryKey
1253
+ }),
1254
+ /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
1255
+ name: ["InfiniteData"],
1256
+ isTypeOnly: true,
1257
+ path: importPath
1258
+ }),
1259
+ /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
1260
+ name: ["infiniteQueryOptions"],
1261
+ path: importPath
1262
+ }),
1263
+ /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(InfiniteQueryOptions, {
1264
+ name: queryOptionsName,
1265
+ clientName: calledClientName,
1266
+ queryKeyName,
1267
+ node,
1268
+ tsResolver,
1269
+ cursorParam: infiniteOptions.cursorParam,
1270
+ nextParam: infiniteOptions.nextParam,
1271
+ previousParam: infiniteOptions.previousParam,
1272
+ initialPageParam: infiniteOptions.initialPageParam,
1273
+ queryParam: infiniteOptions.queryParam
1274
+ }),
1275
+ /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
1276
+ name: ["useInfiniteQuery"],
1277
+ path: importPath
1278
+ }),
1279
+ /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
1280
+ name: [
1281
+ "QueryKey",
1282
+ "QueryClient",
1283
+ "UseInfiniteQueryOptions",
1284
+ "UseInfiniteQueryReturnType"
1285
+ ],
1286
+ path: importPath,
1287
+ isTypeOnly: true
1288
+ }),
1289
+ /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(InfiniteQuery, {
1290
+ name: queryName,
1291
+ queryOptionsName,
1292
+ queryKeyName,
1293
+ queryKeyTypeName,
1294
+ node,
1295
+ tsResolver,
1296
+ initialPageParam: infiniteOptions.initialPageParam,
1297
+ queryParam: infiniteOptions.queryParam
1298
+ })
1299
+ ]
1300
+ });
1301
+ }
1302
+ });
1303
+ //#endregion
1304
+ //#region src/generators/mutationGenerator.tsx
1305
+ /**
1306
+ * Built-in generator for `useMutation` composables. Emits one
1307
+ * `useFooMutation` composable per POST/PUT/DELETE operation (configurable
1308
+ * via `mutation.methods`) plus the matching `fooMutationKey` helper.
1309
+ */
1310
+ const mutationGenerator = (0, kubb_kit.defineGenerator)({
1311
+ name: "vue-query-mutation",
1312
+ renderer: kubb_jsx.jsxRenderer,
1313
+ operation(node, ctx) {
1314
+ if (!kubb_kit.ast.isHttpOperationNode(node)) return null;
1315
+ const { config, driver, resolver, root } = ctx;
1316
+ const { output, query, mutation, client, group, hooks } = ctx.options;
1317
+ const pluginTs = driver.getPlugin(_kubb_plugin_ts.pluginTsName);
1318
+ if (!pluginTs) return null;
1319
+ const tsResolver = driver.getResolver(_kubb_plugin_ts.pluginTsName);
1320
+ const { isMutation } = classifyOperation(node, {
1321
+ query,
1322
+ mutation
1323
+ });
1324
+ if (!isMutation) return null;
1325
+ const importPath = mutation ? mutation.importPath : "@tanstack/vue-query";
1326
+ const contractOp = resolveClientOperation({
1327
+ clientPlugin: { pluginName: client.pluginName },
1328
+ driver,
1329
+ node,
1330
+ root,
1331
+ output
1332
+ });
1333
+ if (!contractOp) return null;
1334
+ const mutationHookName = resolver.mutation.name(node);
1335
+ const mutationTypeName = resolver.mutation.typeName(node);
1336
+ const mutationKeyName = resolver.mutation.keyName(node);
1337
+ const meta = {
1338
+ file: resolver.file({
1339
+ ...operationFileEntry(node, mutationHookName),
1340
+ root,
1341
+ output,
1342
+ group: group ?? void 0
1343
+ }),
1344
+ fileTs: tsResolver.file({
1345
+ ...operationFileEntry(node, node.operationId),
1346
+ root,
1347
+ output: pluginTs.options?.output ?? output,
1348
+ group: pluginTs.options?.group ?? void 0
1349
+ })
1350
+ };
1351
+ const importedTypeNames = [tsResolver.response.options(node), ...resolveOperationTypeNames(node, tsResolver, {
1352
+ order: "body-response-first",
1353
+ includeParams: false
1354
+ })].filter((name) => Boolean(name));
1355
+ const calledClientName = contractOp.name;
1356
+ const groups = getRequestGroups(node);
1357
+ const hasRequestGroups = groups.path || groups.query || groups.body || groups.headers;
1358
+ return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(kubb_jsx.File, {
1359
+ baseName: meta.file.baseName,
1360
+ path: meta.file.path,
1361
+ meta: meta.file.meta,
1362
+ banner: resolver.default.banner(ctx.meta, {
1363
+ output,
1364
+ config,
1365
+ file: {
1366
+ path: meta.file.path,
1367
+ baseName: meta.file.baseName
1368
+ }
1369
+ }),
1370
+ footer: resolver.default.footer(ctx.meta, {
1371
+ output,
1372
+ config,
1373
+ file: {
1374
+ path: meta.file.path,
1375
+ baseName: meta.file.baseName
1376
+ }
1377
+ }),
1378
+ children: [
1379
+ /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
1380
+ name: [contractOp.name],
1381
+ root: meta.file.path,
1382
+ path: contractOp.path
1383
+ }),
1384
+ /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
1385
+ name: ["RequestConfig", "ResponseErrorConfig"],
1386
+ root: meta.file.path,
1387
+ path: contractOp.clientPath,
1388
+ isTypeOnly: true
1389
+ }),
1390
+ hasRequestGroups && /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
1391
+ name: ["toValue"],
1392
+ path: "vue"
1393
+ }),
1394
+ /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
1395
+ name: ["MaybeRefOrGetter"],
1396
+ path: "vue",
1397
+ isTypeOnly: true
1398
+ }),
1399
+ meta.fileTs && importedTypeNames.length > 0 && /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
1400
+ name: Array.from(new Set(importedTypeNames)),
1401
+ root: meta.file.path,
1402
+ path: meta.fileTs.path,
1403
+ isTypeOnly: true
1404
+ }),
1405
+ /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(MutationKey, {
1406
+ name: mutationKeyName,
1407
+ node,
1408
+ transformer: ctx.options.mutationKey
1409
+ }),
1410
+ mutation && hooks && /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(kubb_jsx_jsx_runtime.Fragment, { children: [
1411
+ /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
1412
+ name: ["useMutation"],
1413
+ path: importPath
1414
+ }),
1415
+ /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
1416
+ name: ["MutationObserverOptions", "QueryClient"],
1417
+ path: importPath,
1418
+ isTypeOnly: true
1419
+ }),
1420
+ /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(Mutation, {
1421
+ name: mutationHookName,
1422
+ clientName: calledClientName,
1423
+ typeName: mutationTypeName,
1424
+ node,
1425
+ tsResolver,
1426
+ mutationKeyName
1427
+ })
1428
+ ] })
1429
+ ]
1430
+ });
1431
+ }
1432
+ });
1433
+ //#endregion
1434
+ //#region src/generators/queryGenerator.tsx
1435
+ /**
1436
+ * Built-in generator for `useQuery` composables. Emits one `useFooQuery`
1437
+ * composable per GET operation (configurable via `query.methods`) plus the
1438
+ * matching `fooQueryKey` / `fooQueryOptions` helpers.
1439
+ */
1440
+ const queryGenerator = (0, kubb_kit.defineGenerator)({
1441
+ name: "vue-query",
1442
+ renderer: kubb_jsx.jsxRenderer,
1443
+ operation(node, ctx) {
1444
+ if (!kubb_kit.ast.isHttpOperationNode(node)) return null;
1445
+ const { config, driver, resolver, root } = ctx;
1446
+ const { output, query, mutation, client, group, hooks } = ctx.options;
1447
+ const pluginTs = driver.getPlugin(_kubb_plugin_ts.pluginTsName);
1448
+ if (!pluginTs) return null;
1449
+ const tsResolver = driver.getResolver(_kubb_plugin_ts.pluginTsName);
1450
+ const { isQuery, isMutation } = classifyOperation(node, {
1451
+ query,
1452
+ mutation
1453
+ });
1454
+ if (!isQuery || isMutation) return null;
1455
+ const importPath = query ? query.importPath : "@tanstack/vue-query";
1456
+ const contractOp = resolveClientOperation({
1457
+ clientPlugin: { pluginName: client.pluginName },
1458
+ driver,
1459
+ node,
1460
+ root,
1461
+ output
1462
+ });
1463
+ if (!contractOp) return null;
1464
+ const queryName = resolver.query.name(node);
1465
+ const queryOptionsName = resolver.query.optionsName(node);
1466
+ const queryKeyName = resolver.query.keyName(node);
1467
+ const queryKeyTypeName = resolver.query.keyTypeName(node);
1468
+ const meta = {
1469
+ file: resolver.file({
1470
+ ...operationFileEntry(node, queryName),
1471
+ root,
1472
+ output,
1473
+ group: group ?? void 0
1474
+ }),
1475
+ fileTs: tsResolver.file({
1476
+ ...operationFileEntry(node, node.operationId),
1477
+ root,
1478
+ output: pluginTs.options?.output ?? output,
1479
+ group: pluginTs.options?.group ?? void 0
1480
+ })
1481
+ };
1482
+ const importedTypeNames = [tsResolver.response.options(node), ...resolveOperationTypeNames(node, tsResolver, {
1483
+ exclude: [queryKeyTypeName],
1484
+ order: "body-response-first",
1485
+ includeParams: false
1486
+ })].filter((name) => Boolean(name));
1487
+ const calledClientName = contractOp.name;
1488
+ return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(kubb_jsx.File, {
1489
+ baseName: meta.file.baseName,
1490
+ path: meta.file.path,
1491
+ meta: meta.file.meta,
1492
+ banner: resolver.default.banner(ctx.meta, {
1493
+ output,
1494
+ config,
1495
+ file: {
1496
+ path: meta.file.path,
1497
+ baseName: meta.file.baseName
1498
+ }
1499
+ }),
1500
+ footer: resolver.default.footer(ctx.meta, {
1501
+ output,
1502
+ config,
1503
+ file: {
1504
+ path: meta.file.path,
1505
+ baseName: meta.file.baseName
1506
+ }
1507
+ }),
1508
+ children: [
1509
+ /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
1510
+ name: [contractOp.name],
1511
+ root: meta.file.path,
1512
+ path: contractOp.path
1513
+ }),
1514
+ /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
1515
+ name: ["RequestConfig", "ResponseErrorConfig"],
1516
+ root: meta.file.path,
1517
+ path: contractOp.clientPath,
1518
+ isTypeOnly: true
1519
+ }),
1520
+ /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
1521
+ name: ["toValue"],
1522
+ path: "vue"
1523
+ }),
1524
+ /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
1525
+ name: ["MaybeRefOrGetter"],
1526
+ path: "vue",
1527
+ isTypeOnly: true
1528
+ }),
1529
+ meta.fileTs && importedTypeNames.length > 0 && /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
1530
+ name: Array.from(new Set(importedTypeNames)),
1531
+ root: meta.file.path,
1532
+ path: meta.fileTs.path,
1533
+ isTypeOnly: true
1534
+ }),
1535
+ /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(QueryKey, {
1536
+ name: queryKeyName,
1537
+ typeName: queryKeyTypeName,
1538
+ node,
1539
+ tsResolver,
1540
+ transformer: ctx.options.queryKey
1541
+ }),
1542
+ /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
1543
+ name: ["queryOptions"],
1544
+ path: importPath
1545
+ }),
1546
+ /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(QueryOptions, {
1547
+ name: queryOptionsName,
1548
+ clientName: calledClientName,
1549
+ queryKeyName,
1550
+ node,
1551
+ tsResolver
1552
+ }),
1553
+ query && hooks && /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(kubb_jsx_jsx_runtime.Fragment, { children: [
1554
+ /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
1555
+ name: ["useQuery"],
1556
+ path: importPath
1557
+ }),
1558
+ /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
1559
+ name: [
1560
+ "QueryKey",
1561
+ "QueryClient",
1562
+ "UseQueryOptions",
1563
+ "UseQueryReturnType"
1564
+ ],
1565
+ path: importPath,
1566
+ isTypeOnly: true
1567
+ }),
1568
+ /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(Query, {
1569
+ name: queryName,
1570
+ queryOptionsName,
1571
+ queryKeyName,
1572
+ queryKeyTypeName,
1573
+ node,
1574
+ tsResolver
1575
+ })
1576
+ ] })
1577
+ ]
1578
+ });
1579
+ }
1580
+ });
1581
+ //#endregion
1582
+ //#region src/resolvers/resolverVueQuery.ts
1583
+ /**
1584
+ * Default resolver used by `@kubb/plugin-vue-query`. Decides the names and
1585
+ * file paths for every generated TanStack Query composable (`useFoo`,
1586
+ * `useFooInfinite`) and its companion helpers.
1587
+ *
1588
+ * The `default` helpers are supplied by `createResolver`. Functions and files use camelCase;
1589
+ * composables get the `use` prefix. Operation-specific naming is grouped under the `query`,
1590
+ * `infiniteQuery`, and `mutation` namespaces.
1591
+ *
1592
+ * @example Resolve composable and helper names
1593
+ * ```ts
1594
+ * import { resolverVueQuery } from '@kubb/plugin-vue-query'
1595
+ *
1596
+ * resolverVueQuery.query.name(operationNode) // 'useGetPetById'
1597
+ * resolverVueQuery.query.keyName(operationNode) // 'getPetByIdQueryKey'
1598
+ * resolverVueQuery.query.optionsName(operationNode) // 'getPetByIdQueryOptions'
1599
+ * ```
1600
+ */
1601
+ const resolverVueQuery = (0, kubb_kit.createResolver)({
27
1602
  pluginName: "plugin-vue-query",
28
- default(name, type) {
29
- return require_components.camelCase(name, { isFile: type === "file" });
30
- },
31
- resolveName(name) {
32
- return this.default(name, "function");
33
- },
34
- resolvePathName(name, type) {
35
- return this.default(name, type);
36
- },
37
- resolveQueryName(node) {
38
- return `use${capitalize(this.resolveName(node.operationId))}`;
39
- },
40
- resolveInfiniteQueryName(node) {
41
- return `use${capitalize(this.resolveName(node.operationId))}Infinite`;
42
- },
43
- resolveMutationName(node) {
44
- return `use${capitalize(this.resolveName(node.operationId))}`;
45
- },
46
- resolveQueryOptionsName(node) {
47
- return `${this.resolveName(node.operationId)}QueryOptions`;
48
- },
49
- resolveInfiniteQueryOptionsName(node) {
50
- return `${this.resolveName(node.operationId)}InfiniteQueryOptions`;
51
- },
52
- resolveQueryKeyName(node) {
53
- return `${this.resolveName(node.operationId)}QueryKey`;
54
- },
55
- resolveInfiniteQueryKeyName(node) {
56
- return `${this.resolveName(node.operationId)}InfiniteQueryKey`;
57
- },
58
- resolveMutationKeyName(node) {
59
- return `${this.resolveName(node.operationId)}MutationKey`;
60
- },
61
- resolveQueryKeyTypeName(node) {
62
- return `${capitalize(this.resolveName(node.operationId))}QueryKey`;
63
- },
64
- resolveInfiniteQueryKeyTypeName(node) {
65
- return `${capitalize(this.resolveName(node.operationId))}InfiniteQueryKey`;
66
- },
67
- resolveMutationTypeName(node) {
68
- return capitalize(this.resolveName(node.operationId));
69
- },
70
- resolveClientName(node) {
71
- return this.resolveName(node.operationId);
72
- },
73
- resolveInfiniteClientName(node) {
74
- return `${this.resolveName(node.operationId)}Infinite`;
1603
+ query: createQueryResolver(),
1604
+ infiniteQuery: createQueryResolver("Infinite"),
1605
+ mutation: {
1606
+ ...createMutationResolver(),
1607
+ typeName(node) {
1608
+ return capitalize(this.name(node.operationId));
1609
+ }
75
1610
  }
76
- }));
1611
+ });
77
1612
  //#endregion
78
1613
  //#region src/plugin.ts
1614
+ /**
1615
+ * Canonical plugin name for `@kubb/plugin-vue-query`. Used for driver lookups
1616
+ * and cross-plugin dependency references.
1617
+ */
79
1618
  const pluginVueQueryName = "plugin-vue-query";
80
- const pluginVueQuery = (0, _kubb_core.definePlugin)((options) => {
1619
+ /**
1620
+ * Generates one TanStack Query composable per OpenAPI operation for Vue's
1621
+ * Composition API. Queries become `useFoo` (and optionally
1622
+ * `useFooInfinite`). Mutations become `useFoo` as well. Each composable
1623
+ * is fully typed end to end.
1624
+ *
1625
+ * @example
1626
+ * ```ts
1627
+ * import { defineConfig } from 'kubb/config'
1628
+ * import { pluginTs } from '@kubb/plugin-ts'
1629
+ * import { pluginVueQuery } from '@kubb/plugin-vue-query'
1630
+ *
1631
+ * export default defineConfig({
1632
+ * input: './petStore.yaml',
1633
+ * output: { path: './src/gen' },
1634
+ * plugins: [
1635
+ * pluginTs(),
1636
+ * pluginVueQuery({
1637
+ * output: { path: './hooks' },
1638
+ * }),
1639
+ * ],
1640
+ * })
1641
+ * ```
1642
+ */
1643
+ const pluginVueQuery = (0, kubb_kit.definePlugin)((options) => {
81
1644
  const { output = {
82
1645
  path: "hooks",
83
- barrelType: "named"
84
- }, group, exclude = [], include, override = [], parser = "client", infinite = false, paramsType = "inline", pathParamsType = paramsType === "object" ? "object" : options.pathParamsType || "inline", mutation = {}, query = {}, mutationKey = require_components.mutationKeyTransformer, queryKey = require_components.queryKeyTransformer, paramsCasing, client, resolver: userResolver, transformer: userTransformer, generators: userGenerators = [] } = options;
85
- const clientName = client?.client ?? "axios";
86
- const clientImportPath = client?.importPath ?? (!client?.bundle ? `@kubb/plugin-client/clients/${clientName}` : void 0);
87
- const selectedGenerators = options.generators ?? [
88
- require_generators.queryGenerator,
89
- require_generators.infiniteQueryGenerator,
90
- require_generators.mutationGenerator
91
- ].filter((generator) => Boolean(generator));
92
- const groupConfig = group ? {
93
- ...group,
94
- name: group.name ? group.name : (ctx) => {
95
- if (group.type === "path") return `${ctx.group.split("/")[1]}`;
96
- return `${require_components.camelCase(ctx.group)}Controller`;
97
- }
98
- } : void 0;
1646
+ barrel: { type: "named" }
1647
+ }, group, exclude = [], include, override = [], infinite = false, mutation = {}, query = {}, mutationKey = mutationKeyTransformer, queryKey = queryKeyTransformer, hooks = false, client, resolver: userResolver, macros: userMacros } = options;
1648
+ const selectedGenerators = [
1649
+ queryGenerator,
1650
+ infiniteQueryGenerator,
1651
+ mutationGenerator
1652
+ ];
1653
+ const groupConfig = createGroupConfig(group);
99
1654
  return {
100
1655
  name: pluginVueQueryName,
101
1656
  options,
102
- dependencies: [_kubb_plugin_ts.pluginTsName, parser === "zod" ? _kubb_plugin_zod.pluginZodName : void 0].filter((dependency) => Boolean(dependency)),
1657
+ dependencies: [_kubb_plugin_ts.pluginTsName],
103
1658
  hooks: { "kubb:plugin:setup"(ctx) {
104
- const resolver = userResolver ? {
105
- ...resolverVueQuery,
106
- ...userResolver
107
- } : resolverVueQuery;
1659
+ const resolver = userResolver ? kubb_kit.Resolver.merge(resolverVueQuery, userResolver) : resolverVueQuery;
108
1660
  ctx.setOptions({
109
1661
  output,
110
- client: {
111
- bundle: client?.bundle,
112
- baseURL: client?.baseURL,
113
- client: clientName,
114
- clientType: client?.clientType ?? "function",
115
- importPath: clientImportPath,
116
- dataReturnType: client?.dataReturnType ?? "data",
117
- paramsCasing
118
- },
1662
+ client: resolveContractClient({
1663
+ client,
1664
+ plugins: ctx.config.plugins
1665
+ }),
119
1666
  queryKey,
120
- query: query === false ? false : {
121
- importPath: "@tanstack/vue-query",
122
- methods: ["get"],
123
- ...query
124
- },
1667
+ query: resolveQueryConfig(query, { importPath: "@tanstack/vue-query" }),
125
1668
  mutationKey,
126
- mutation: mutation === false ? false : {
127
- importPath: "@tanstack/vue-query",
128
- methods: [
129
- "post",
130
- "put",
131
- "patch",
132
- "delete"
133
- ],
134
- ...mutation
135
- },
136
- infinite: infinite ? {
137
- queryParam: "id",
138
- initialPageParam: 0,
139
- cursorParam: void 0,
140
- nextParam: void 0,
141
- previousParam: void 0,
142
- ...infinite
143
- } : false,
144
- parser,
145
- paramsType,
146
- pathParamsType,
147
- paramsCasing,
1669
+ mutation: resolveMutationConfig(mutation, { importPath: "@tanstack/vue-query" }),
1670
+ infinite: resolveInfiniteConfig(infinite),
1671
+ hooks,
148
1672
  group: groupConfig,
149
1673
  exclude,
150
1674
  include,
@@ -152,31 +1676,8 @@ const pluginVueQuery = (0, _kubb_core.definePlugin)((options) => {
152
1676
  resolver
153
1677
  });
154
1678
  ctx.setResolver(resolver);
155
- if (userTransformer) ctx.setTransformer(userTransformer);
156
- for (const gen of selectedGenerators) ctx.addGenerator(gen);
157
- for (const gen of userGenerators) ctx.addGenerator(gen);
158
- const root = node_path.default.resolve(ctx.config.root, ctx.config.output.path);
159
- const hasClientPlugin = !!ctx.config.plugins?.some((p) => p.name === _kubb_plugin_client.pluginClientName);
160
- if (client?.bundle && !hasClientPlugin && !clientImportPath) ctx.injectFile({
161
- baseName: "fetch.ts",
162
- path: node_path.default.resolve(root, ".kubb/fetch.ts"),
163
- sources: [_kubb_core.ast.createSource({
164
- name: "fetch",
165
- nodes: [_kubb_core.ast.createText(clientName === "fetch" ? _kubb_plugin_client_templates_clients_fetch_source.source : _kubb_plugin_client_templates_clients_axios_source.source)],
166
- isExportable: true,
167
- isIndexable: true
168
- })]
169
- });
170
- if (!hasClientPlugin) ctx.injectFile({
171
- baseName: "config.ts",
172
- path: node_path.default.resolve(root, ".kubb/config.ts"),
173
- sources: [_kubb_core.ast.createSource({
174
- name: "config",
175
- nodes: [_kubb_core.ast.createText(_kubb_plugin_client_templates_config_source.source)],
176
- isExportable: false,
177
- isIndexable: false
178
- })]
179
- });
1679
+ if (userMacros?.length) ctx.setMacros(userMacros);
1680
+ ctx.addGenerator(...selectedGenerators);
180
1681
  } }
181
1682
  };
182
1683
  });
@@ -184,5 +1685,6 @@ const pluginVueQuery = (0, _kubb_core.definePlugin)((options) => {
184
1685
  exports.default = pluginVueQuery;
185
1686
  exports.pluginVueQuery = pluginVueQuery;
186
1687
  exports.pluginVueQueryName = pluginVueQueryName;
1688
+ exports.resolverVueQuery = resolverVueQuery;
187
1689
 
188
1690
  //# sourceMappingURL=index.cjs.map