@kubb/plugin-vue-query 5.13.0-canary.20261122T213936 → 5.13.1

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/dist/index.cjs CHANGED
@@ -25,9 +25,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
25
25
  }) : target, mod));
26
26
  let _kubb_kit = require("@kubb/kit");
27
27
  let _kubb_plugin_ts = require("@kubb/plugin-ts");
28
+ let _kubb_ast = require("@kubb/ast");
28
29
  let node_path = require("node:path");
29
30
  node_path = __toESM(node_path, 1);
30
- let _kubb_ast = require("@kubb/ast");
31
31
  let _kubb_renderer_jsx = require("@kubb/renderer-jsx");
32
32
  let _kubb_renderer_jsx_jsx_runtime = require("@kubb/renderer-jsx/jsx-runtime");
33
33
  // kubb-extension.json
@@ -36,7 +36,159 @@ var compatibility = {
36
36
  "node": ">=22.22"
37
37
  };
38
38
  // package.json
39
- var version = "5.13.0-canary.20261122T213936";
39
+ var version = "5.13.1";
40
+ // ../../internals/ast/src/http/requestBody.ts
41
+ /** The schema of the first request body entry, else `undefined` when the operation takes no body. */
42
+ function getSchema(node) {
43
+ return node.requestBody?.content?.[0]?.schema;
44
+ }
45
+ // ../../internals/ast/src/http/status.ts
46
+ const classByRange = /* @__PURE__ */ new Map([
47
+ ["1xx", 1],
48
+ ["2xx", 2],
49
+ ["3xx", 3],
50
+ ["4xx", 4],
51
+ ["5xx", 5]
52
+ ]);
53
+ /** The class digit of a status code or range: `2` for `201` and `2xx`, `null` for `default`. */
54
+ function statusClass(input) {
55
+ const statusCode = typeof input === "object" ? input.statusCode : input;
56
+ const rangeClass = classByRange.get(String(statusCode));
57
+ if (rangeClass) return rangeClass;
58
+ const code = Number(statusCode);
59
+ return Number.isNaN(code) ? null : Math.floor(code / 100);
60
+ }
61
+ function isSuccess(statusCode) {
62
+ return statusClass(statusCode) === 2;
63
+ }
64
+ function isError(statusCode) {
65
+ const code = statusClass(statusCode);
66
+ return code !== null && code >= 4;
67
+ }
68
+ // ../../internals/ast/src/http/responses.ts
69
+ /** The `4xx` and `5xx` responses, ranges included. */
70
+ function filterError(node) {
71
+ return node.responses.filter((response) => isError(response.statusCode));
72
+ }
73
+ function filterSuccess(node) {
74
+ return node.responses.filter((response) => isSuccess(response.statusCode));
75
+ }
76
+ /** The success response a client returns: one with a body first, then an exact code over a `2xx` range. */
77
+ function findPrimary(node) {
78
+ const responses = filterSuccess(node);
79
+ const withBody = responses.filter((response) => response.content?.some((entry) => entry.contentType));
80
+ const candidates = withBody.length ? withBody : responses;
81
+ return candidates.find((response) => !Number.isNaN(Number(response.statusCode))) ?? candidates[0] ?? null;
82
+ }
83
+ // ../../internals/ast/src/http/index.ts
84
+ const isOperation = _kubb_ast.ast.http.isOperation;
85
+ /** Computes once per key; generators visit the same node many times. */
86
+ function cached(store, key, compute) {
87
+ if (!store.has(key)) store.set(key, compute());
88
+ return store.get(key);
89
+ }
90
+ const parametersByNode = /* @__PURE__ */ new WeakMap();
91
+ /** The operation's parameters by location, with a `querystring` parameter in `query`. A repeated name keeps its first parameter. */
92
+ function groupParameters(node) {
93
+ return cached(parametersByNode, node, () => {
94
+ const group = (...locations) => {
95
+ const seen = /* @__PURE__ */ new Set();
96
+ return locations.flatMap((location) => node.parameters.filter((param) => {
97
+ if (param.in !== location || seen.has(param.name)) return false;
98
+ seen.add(param.name);
99
+ return true;
100
+ }));
101
+ };
102
+ return {
103
+ path: group("path"),
104
+ query: group("query", "querystring"),
105
+ header: group("header"),
106
+ cookie: group("cookie")
107
+ };
108
+ });
109
+ }
110
+ const requestGroupsByNode = /* @__PURE__ */ new WeakMap();
111
+ /** Which request groups are present, which hold a required member, and the body's media types. Built once per operation. */
112
+ function getRequestGroups(node) {
113
+ return cached(requestGroupsByNode, node, () => {
114
+ const { path, query, header, cookie } = groupParameters(node);
115
+ const content = node.requestBody?.content ?? [];
116
+ const body = Boolean(content[0]?.schema);
117
+ const required = {
118
+ path: path.some((param) => param.required),
119
+ query: query.some((param) => param.required),
120
+ headers: header.some((param) => param.required),
121
+ body: body && node.requestBody?.required === true
122
+ };
123
+ return {
124
+ path: path.length > 0,
125
+ query: query.length > 0,
126
+ body,
127
+ headers: header.length > 0,
128
+ cookies: cookie.length > 0,
129
+ required,
130
+ isOptional: !required.path && !required.query && !required.headers && !required.body,
131
+ contentTypes: content.map((entry) => entry.contentType),
132
+ hasContentTypeChoice: content.filter((entry) => entry.schema).length > 1
133
+ };
134
+ });
135
+ }
136
+ // ../../internals/ast/src/imports.ts
137
+ /**
138
+ * Returns the names of `imp`, each marked as a type, for an import that only types use.
139
+ *
140
+ * @example
141
+ * ```tsx
142
+ * <File.Import names={ast.imports.asType(imp)} path={imp.path} root={file.path} />
143
+ * ```
144
+ */
145
+ function asType(imp) {
146
+ return _kubb_ast.file.getNames(imp).map((item) => ({
147
+ ...item,
148
+ space: "type"
149
+ }));
150
+ }
151
+ // ../../internals/ast/src/mediaType.ts
152
+ const streamMediaTypes = /* @__PURE__ */ new Set([
153
+ "application/jsonl",
154
+ "application/x-ndjson",
155
+ "application/json-seq",
156
+ "text/event-stream"
157
+ ]);
158
+ const getBase = _kubb_ast.ast.mediaType.getBase;
159
+ const isJson = _kubb_ast.ast.mediaType.isJson;
160
+ /** Whether the media type is a stream of items: SSE, JSON Lines, or a `+json-seq` sequence. */
161
+ function isStream(mediaType) {
162
+ const baseType = getBase(mediaType);
163
+ return streamMediaTypes.has(baseType) || baseType.startsWith("application/") && baseType.endsWith("+json-seq");
164
+ }
165
+ const formKinds = {
166
+ "multipart/form-data": "form",
167
+ "application/x-www-form-urlencoded": "urlencoded"
168
+ };
169
+ /** How a client reads or sends a content entry, or `null` for another media type. A `blob` schema is `binary`. */
170
+ function getKind(entry) {
171
+ const content = typeof entry === "string" ? { contentType: entry } : entry;
172
+ const baseType = getBase(content);
173
+ if (!baseType) return null;
174
+ if (baseType === "text/event-stream") return "eventStream";
175
+ if (content.stream && isStream(content)) return "lineStream";
176
+ if (isJson(baseType)) return "json";
177
+ if (formKinds[baseType]) return formKinds[baseType];
178
+ if (content.schema?.type === "blob") return "binary";
179
+ if (baseType.startsWith("text/")) return "text";
180
+ if (baseType === "application/octet-stream" || baseType === "application/pdf" || /^(image|audio|video)\//.test(baseType)) return "binary";
181
+ return null;
182
+ }
183
+ _kubb_ast.ast.schema.applyOptionality;
184
+ _kubb_ast.ast.schema.types;
185
+ const narrow = _kubb_ast.ast.schema.narrow;
186
+ _kubb_ast.ast.schema.find;
187
+ _kubb_ast.ast.schema.getEmbeddedJson;
188
+ const is = _kubb_ast.ast.schema.is;
189
+ const getLiterals = _kubb_ast.ast.schema.getLiterals;
190
+ _kubb_ast.ast.schema.inferDiscriminator;
191
+ const findProperties = _kubb_ast.ast.schema.findProperties;
40
192
  // ../../internals/client/src/resolveClient.ts
41
193
  /**
42
194
  * Resolves which client plugin a consumer (react-query, vue-query, swr, mcp) should call for an
@@ -198,7 +350,7 @@ function resolveClientOperation({ node, pluginName }) {
198
350
  }),
199
351
  clientPathIsFile: importPath === void 0 || isRelativeImport(importPath),
200
352
  returnType: operationOptions.returnType ?? "full",
201
- typedHeaders: importPath === void 0
353
+ typedHeaders: importPath === void 0 || pluginName !== "plugin-client"
202
354
  };
203
355
  });
204
356
  }
@@ -276,143 +428,6 @@ function resolveOperationTypes() {
276
428
  };
277
429
  });
278
430
  }
279
- // ../../internals/ast/src/http/requestBody.ts
280
- /** The schema of the first request body entry, else `undefined` when the operation takes no body. */
281
- function getSchema(node) {
282
- return node.requestBody?.content?.[0]?.schema;
283
- }
284
- // ../../internals/ast/src/http/status.ts
285
- const classByRange = /* @__PURE__ */ new Map([
286
- ["1xx", 1],
287
- ["2xx", 2],
288
- ["3xx", 3],
289
- ["4xx", 4],
290
- ["5xx", 5]
291
- ]);
292
- /** The class digit of a status code or range: `2` for `201` and `2xx`, `null` for `default`. */
293
- function statusClass(input) {
294
- const statusCode = typeof input === "object" ? input.statusCode : input;
295
- const rangeClass = classByRange.get(String(statusCode));
296
- if (rangeClass) return rangeClass;
297
- const code = Number(statusCode);
298
- return Number.isNaN(code) ? null : Math.floor(code / 100);
299
- }
300
- function isSuccess(statusCode) {
301
- return statusClass(statusCode) === 2;
302
- }
303
- function isError(statusCode) {
304
- const code = statusClass(statusCode);
305
- return code !== null && code >= 4;
306
- }
307
- // ../../internals/ast/src/http/responses.ts
308
- /** The `4xx` and `5xx` responses, ranges included. */
309
- function filterError(node) {
310
- return node.responses.filter((response) => isError(response.statusCode));
311
- }
312
- function filterSuccess(node) {
313
- return node.responses.filter((response) => isSuccess(response.statusCode));
314
- }
315
- /** The success response a client returns: one with a body first, then an exact code over a `2xx` range. */
316
- function findPrimary(node) {
317
- const responses = filterSuccess(node);
318
- const withBody = responses.filter((response) => response.content?.some((entry) => entry.contentType));
319
- const candidates = withBody.length ? withBody : responses;
320
- return candidates.find((response) => !Number.isNaN(Number(response.statusCode))) ?? candidates[0] ?? null;
321
- }
322
- // ../../internals/ast/src/http/index.ts
323
- const isOperation = _kubb_ast.ast.http.isOperation;
324
- /** Computes once per key; generators visit the same node many times. */
325
- function cached(store, key, compute) {
326
- if (!store.has(key)) store.set(key, compute());
327
- return store.get(key);
328
- }
329
- const parametersByNode = /* @__PURE__ */ new WeakMap();
330
- /** The operation's parameters by location, with a `querystring` parameter in `query`. A repeated name keeps its first parameter. */
331
- function groupParameters(node) {
332
- return cached(parametersByNode, node, () => {
333
- const group = (...locations) => {
334
- const seen = /* @__PURE__ */ new Set();
335
- return locations.flatMap((location) => node.parameters.filter((param) => {
336
- if (param.in !== location || seen.has(param.name)) return false;
337
- seen.add(param.name);
338
- return true;
339
- }));
340
- };
341
- return {
342
- path: group("path"),
343
- query: group("query", "querystring"),
344
- header: group("header"),
345
- cookie: group("cookie")
346
- };
347
- });
348
- }
349
- const requestGroupsByNode = /* @__PURE__ */ new WeakMap();
350
- /** Which request groups are present, which hold a required member, and the body's media types. Built once per operation. */
351
- function getRequestGroups(node) {
352
- return cached(requestGroupsByNode, node, () => {
353
- const { path, query, header, cookie } = groupParameters(node);
354
- const content = node.requestBody?.content ?? [];
355
- const body = Boolean(content[0]?.schema);
356
- const required = {
357
- path: path.some((param) => param.required),
358
- query: query.some((param) => param.required),
359
- headers: header.some((param) => param.required),
360
- body: body && node.requestBody?.required === true
361
- };
362
- return {
363
- path: path.length > 0,
364
- query: query.length > 0,
365
- body,
366
- headers: header.length > 0,
367
- cookies: cookie.length > 0,
368
- required,
369
- isOptional: !required.path && !required.query && !required.headers && !required.body,
370
- contentTypes: content.map((entry) => entry.contentType),
371
- hasContentTypeChoice: content.filter((entry) => entry.schema).length > 1
372
- };
373
- });
374
- }
375
- // ../../internals/ast/src/mediaType.ts
376
- const streamMediaTypes = /* @__PURE__ */ new Set([
377
- "application/jsonl",
378
- "application/x-ndjson",
379
- "application/json-seq",
380
- "text/event-stream"
381
- ]);
382
- const getBase = _kubb_ast.ast.mediaType.getBase;
383
- const isJson = _kubb_ast.ast.mediaType.isJson;
384
- /** Whether the media type is a stream of items: SSE, JSON Lines, or a `+json-seq` sequence. */
385
- function isStream(mediaType) {
386
- const baseType = getBase(mediaType);
387
- return streamMediaTypes.has(baseType) || baseType.startsWith("application/") && baseType.endsWith("+json-seq");
388
- }
389
- const formKinds = {
390
- "multipart/form-data": "form",
391
- "application/x-www-form-urlencoded": "urlencoded"
392
- };
393
- /** How a client reads or sends a content entry, or `null` for another media type. A `blob` schema is `binary`. */
394
- function getKind(entry) {
395
- const content = typeof entry === "string" ? { contentType: entry } : entry;
396
- const baseType = getBase(content);
397
- if (!baseType) return null;
398
- if (baseType === "text/event-stream") return "eventStream";
399
- if (content.stream && isStream(content)) return "lineStream";
400
- if (isJson(baseType)) return "json";
401
- if (formKinds[baseType]) return formKinds[baseType];
402
- if (content.schema?.type === "blob") return "binary";
403
- if (baseType.startsWith("text/")) return "text";
404
- if (baseType === "application/octet-stream" || baseType === "application/pdf" || /^(image|audio|video)\//.test(baseType)) return "binary";
405
- return null;
406
- }
407
- _kubb_ast.ast.schema.applyOptionality;
408
- _kubb_ast.ast.schema.types;
409
- const narrow = _kubb_ast.ast.schema.narrow;
410
- _kubb_ast.ast.schema.find;
411
- _kubb_ast.ast.schema.getEmbeddedJson;
412
- const is = _kubb_ast.ast.schema.is;
413
- const getLiterals = _kubb_ast.ast.schema.getLiterals;
414
- _kubb_ast.ast.schema.inferDiscriminator;
415
- const findProperties = _kubb_ast.ast.schema.findProperties;
416
431
  // ../../internals/utils/src/reserved.ts
417
432
  /**
418
433
  * JavaScript and Java reserved words.
@@ -885,25 +900,30 @@ function HookFile({ hook, imports, children }) {
885
900
  ...file,
886
901
  children: [
887
902
  /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
888
- name: [contractOp.name],
903
+ names: [{
904
+ name: contractOp.name,
905
+ space: "value"
906
+ }],
889
907
  root: file.path,
890
908
  path: contractOp.path
891
909
  }),
892
910
  /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
893
- name: [
911
+ names: [
894
912
  "RequestConfig",
895
913
  "ResponseErrorConfig",
896
914
  resultTypeName
897
- ],
915
+ ].map((name) => ({
916
+ name,
917
+ space: "type"
918
+ })),
898
919
  root: contractOp.clientPathIsFile ? file.path : void 0,
899
- path: contractOp.clientPath,
900
- isTypeOnly: true
920
+ path: contractOp.clientPath
901
921
  }),
902
922
  imports,
903
923
  typeImports.map((imp) => /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
904
- ...imp,
924
+ names: asType(imp),
905
925
  root: file.path,
906
- isTypeOnly: true
926
+ path: imp.path
907
927
  }, imp.path)),
908
928
  children
909
929
  ]
@@ -926,8 +946,7 @@ function maybeRefOrGetter(type) {
926
946
  /**
927
947
  * Builds the grouped `{ path, query, body, headers, cookies }` parameter that mirrors the client
928
948
  * function signature. Only the groups the operation carries are emitted, typed from the
929
- * operation's `Options`. `keys` narrows the emitted groups, used by the query key which
930
- * never carries `headers`.
949
+ * operation's `Options`. `keys` narrows the emitted groups.
931
950
  *
932
951
  * By default the whole group is typed as the single `Options` reference. When
933
952
  * `memberTypeWrapper` is set, each group is emitted as its own member typed from the matching
@@ -935,7 +954,7 @@ function maybeRefOrGetter(type) {
935
954
  * `MaybeRefOrGetter` per group.
936
955
  */
937
956
  function buildGroupedRequestParam(node, options) {
938
- const { resolver, keys = requestGroupOrder, memberTypeWrapper, withContentType = false } = options;
957
+ const { resolver, keys = requestGroupOrder, memberTypeWrapper, optionalHeaders = false, withContentType = false } = options;
939
958
  const groups = getRequestGroups(node);
940
959
  const names = keys.filter((key) => groups[key]);
941
960
  if (names.length === 0) return null;
@@ -943,7 +962,7 @@ function buildGroupedRequestParam(node, options) {
943
962
  path: groups.required.path,
944
963
  query: groups.required.query,
945
964
  body: groups.body,
946
- headers: groups.required.headers,
965
+ headers: !optionalHeaders && groups.required.headers,
947
966
  cookies: false
948
967
  };
949
968
  const isOptional = names.every((name) => !requiredByGroup[name]);
@@ -953,8 +972,9 @@ function buildGroupedRequestParam(node, options) {
953
972
  type: optionsName,
954
973
  optional: false
955
974
  });
956
- const omittedKeys = requestGroupOrder.filter((key) => !keys.includes(key) && (key !== "cookies" || groups.cookies));
975
+ const omittedKeys = requestGroupOrder.filter((key) => (!keys.includes(key) || optionalHeaders && key === "headers" && !groups.headers) && (key !== "cookies" || groups.cookies));
957
976
  const optionsType = omittedKeys.length > 0 ? `Omit<${optionsName}, ${omittedKeys.map((key) => `'${key}'`).join(" | ")}>` : optionsName;
977
+ const paramType = optionalHeaders && names.includes("headers") ? `Omit<${optionsType}, 'headers'> & { headers?: ${optionsType}['headers'] }` : optionsType;
958
978
  if (memberTypeWrapper) {
959
979
  const members = names.map((name) => ({
960
980
  name,
@@ -970,7 +990,7 @@ function buildGroupedRequestParam(node, options) {
970
990
  }
971
991
  return (0, _kubb_plugin_ts.createFunctionParameter)({
972
992
  name: (0, _kubb_plugin_ts.createObjectBindingPattern)({ elements: names.map((name) => ({ name })) }),
973
- type: optionsType,
993
+ type: paramType,
974
994
  optional: false,
975
995
  ...isOptional ? { default: "{}" } : {}
976
996
  });
@@ -1205,27 +1225,26 @@ function getDefaultPageParamsWarning(node, infinite) {
1205
1225
  return `${node.operationId}: the default infinite page params expect an array response and never end for this one. Set \`infinite.getNextPageParam\` (or \`nextParam\`) to read the next page from the response.`;
1206
1226
  }
1207
1227
  /**
1208
- * The request groups a query key is built from, matching `buildQueryKeyParams`. Headers are
1209
- * deliberately absent: they do not identify a cache entry, so the key factory takes no parameter
1210
- * for an operation that only carries headers. Cookies are left out too: they often hold a session token, and a query key
1211
- * is stored in SSR payloads, persisted caches, and devtools.
1228
+ * The request groups available to a query key transformer. Headers are available for custom keys
1229
+ * but excluded from the default key. Cookies stay excluded.
1212
1230
  */
1213
1231
  const queryKeyGroupOrder = [
1214
1232
  "path",
1215
1233
  "query",
1216
- "body"
1234
+ "body",
1235
+ "headers"
1217
1236
  ];
1218
1237
  /**
1219
- * Build QueryKey params as the grouped `{ path, query, body }` object (NO headers, NO cookies, NO config),
1220
- * typed from the operation's `Options` minus `url`. The query key transformer reads the
1221
- * grouped `path`/`query`/`body` bindings.
1238
+ * Builds query key bindings for path, query, body, and optional headers. Custom transformers
1239
+ * can reference `headers` in returned code without changing the default key.
1222
1240
  */
1223
1241
  function buildQueryKeyParams(node, options) {
1224
1242
  const { resolver, memberTypeWrapper } = options;
1225
1243
  const groupedParam = buildGroupedRequestParam(node, {
1226
1244
  resolver,
1227
1245
  keys: queryKeyGroupOrder,
1228
- memberTypeWrapper
1246
+ memberTypeWrapper,
1247
+ optionalHeaders: true
1229
1248
  });
1230
1249
  return (0, _kubb_plugin_ts.createFunctionParameters)({ params: groupedParam ? [groupedParam] : [] });
1231
1250
  }
@@ -1539,29 +1558,28 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, t
1539
1558
  `
1540
1559
  });
1541
1560
  }
1542
- // src/generators/infiniteQueryGenerator.tsx
1561
+ // src/templates/infiniteQuery.tsx
1562
+ function matchesInfiniteQuery(node, ctx) {
1563
+ if (!isOperation(node)) return false;
1564
+ const { query, mutation, infinite, hooks } = ctx.options;
1565
+ const { isQuery, isMutation } = classifyOperation(node, {
1566
+ query,
1567
+ mutation
1568
+ });
1569
+ const infiniteOptions = infinite && typeof infinite === "object" ? infinite : null;
1570
+ if (!isQuery || isMutation || !infiniteOptions || !hooks) return false;
1571
+ return matchesInfinite(node, infiniteOptions);
1572
+ }
1543
1573
  /**
1544
- * Built-in generator for `useInfiniteQuery` composables. Enabled when
1574
+ * Built-in template for `useInfiniteQuery` composables. Enabled when
1545
1575
  * `pluginVueQuery({ infinite: { ... }, hooks: true })`. Emits one
1546
1576
  * `useFooInfiniteQuery` composable per query operation, wiring the
1547
1577
  * configured cursor path into TanStack Query's cursor-based pagination.
1548
1578
  */
1549
- const infiniteQueryGenerator = (0, _kubb_kit.defineGenerator)({
1550
- name: "vue-query-infinite",
1551
- renderer: _kubb_renderer_jsx.jsxRenderer,
1552
- match(node, ctx) {
1553
- const operationNode = node;
1554
- if (!isOperation(operationNode)) return false;
1555
- const { query, mutation, infinite, hooks } = ctx.options;
1556
- const { isQuery, isMutation } = classifyOperation(operationNode, {
1557
- query,
1558
- mutation
1559
- });
1560
- const infiniteOptions = infinite && typeof infinite === "object" ? infinite : null;
1561
- if (!isQuery || isMutation || !infiniteOptions || !hooks) return false;
1562
- return matchesInfinite(operationNode, infiniteOptions);
1563
- },
1564
- operation(node, ctx) {
1579
+ const infiniteQueryOperation = (0, _kubb_kit.defineTemplate)({
1580
+ kind: _kubb_ast.node.kinds.operation,
1581
+ render(node, ctx) {
1582
+ if (!matchesInfiniteQuery(node, ctx)) return null;
1565
1583
  if (!isOperation(node)) return null;
1566
1584
  const { query, infinite, client } = ctx.options;
1567
1585
  const infiniteOptions = infinite && typeof infinite === "object" ? infinite : null;
@@ -1592,14 +1610,16 @@ const infiniteQueryGenerator = (0, _kubb_kit.defineGenerator)({
1592
1610
  const { tsResolver } = hook;
1593
1611
  return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(HookFile, {
1594
1612
  hook,
1595
- imports: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
1596
- name: ["toValue"],
1613
+ imports: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx_jsx_runtime.Fragment, { children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
1614
+ names: [{
1615
+ name: "toValue",
1616
+ space: "value"
1617
+ }, {
1618
+ name: "MaybeRefOrGetter",
1619
+ space: "type"
1620
+ }],
1597
1621
  path: "vue"
1598
- }), /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
1599
- name: ["MaybeRefOrGetter"],
1600
- path: "vue",
1601
- isTypeOnly: true
1602
- })] }),
1622
+ }) }),
1603
1623
  children: [
1604
1624
  /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(QueryKey, {
1605
1625
  name: queryKeyName,
@@ -1612,12 +1632,13 @@ const infiniteQueryGenerator = (0, _kubb_kit.defineGenerator)({
1612
1632
  exportType: true
1613
1633
  }),
1614
1634
  /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
1615
- name: ["InfiniteData"],
1616
- isTypeOnly: true,
1617
- path: importPath
1618
- }),
1619
- /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
1620
- name: ["infiniteQueryOptions"],
1635
+ names: [{
1636
+ name: "infiniteQueryOptions",
1637
+ space: "value"
1638
+ }, {
1639
+ name: "InfiniteData",
1640
+ space: "type"
1641
+ }],
1621
1642
  path: importPath
1622
1643
  }),
1623
1644
  /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(InfiniteQueryOptions, {
@@ -1642,18 +1663,29 @@ const infiniteQueryGenerator = (0, _kubb_kit.defineGenerator)({
1642
1663
  unwrapName: (name) => `toValue(${name})`
1643
1664
  }),
1644
1665
  /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
1645
- name: ["useInfiniteQuery"],
1646
- path: importPath
1647
- }),
1648
- /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
1649
- name: [
1650
- "QueryKey",
1651
- "QueryClient",
1652
- "UseInfiniteQueryOptions",
1653
- "UseInfiniteQueryReturnType"
1666
+ names: [
1667
+ {
1668
+ name: "useInfiniteQuery",
1669
+ space: "value"
1670
+ },
1671
+ {
1672
+ name: "QueryKey",
1673
+ space: "type"
1674
+ },
1675
+ {
1676
+ name: "QueryClient",
1677
+ space: "type"
1678
+ },
1679
+ {
1680
+ name: "UseInfiniteQueryOptions",
1681
+ space: "type"
1682
+ },
1683
+ {
1684
+ name: "UseInfiniteQueryReturnType",
1685
+ space: "type"
1686
+ }
1654
1687
  ],
1655
- path: importPath,
1656
- isTypeOnly: true
1688
+ path: importPath
1657
1689
  }),
1658
1690
  /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(Query, {
1659
1691
  name: queryName,
@@ -1748,16 +1780,15 @@ function Mutation({ name, clientName, node, tsResolver, mutationKeyName, clientR
1748
1780
  `
1749
1781
  });
1750
1782
  }
1751
- // src/generators/mutationGenerator.tsx
1783
+ // src/templates/mutation.tsx
1752
1784
  /**
1753
- * Built-in generator for `useMutation` composables. Emits one
1785
+ * Built-in template for `useMutation` composables. Emits one
1754
1786
  * `useFooMutation` composable per POST/PUT/DELETE operation (configurable
1755
1787
  * via `mutation.methods`) plus the matching `fooMutationKey` helper.
1756
1788
  */
1757
- const mutationGenerator = (0, _kubb_kit.defineGenerator)({
1758
- name: "vue-query-mutation",
1759
- renderer: _kubb_renderer_jsx.jsxRenderer,
1760
- operation(node, ctx) {
1789
+ const mutationOperation = (0, _kubb_kit.defineTemplate)({
1790
+ kind: _kubb_ast.node.kinds.operation,
1791
+ render(node, ctx) {
1761
1792
  if (!isOperation(node)) return null;
1762
1793
  const { query, mutation, client, hooks } = ctx.options;
1763
1794
  const { isMutation } = classifyOperation(node, {
@@ -1782,52 +1813,58 @@ const mutationGenerator = (0, _kubb_kit.defineGenerator)({
1782
1813
  const hasRequestGroups = requestGroupOrder.some((key) => groups[key]);
1783
1814
  return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(HookFile, {
1784
1815
  hook,
1785
- imports: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx_jsx_runtime.Fragment, { children: [hasRequestGroups && /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
1786
- name: ["toValue"],
1816
+ imports: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx_jsx_runtime.Fragment, { children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
1817
+ names: [...hasRequestGroups ? [{
1818
+ name: "toValue",
1819
+ space: "value"
1820
+ }] : [], {
1821
+ name: "MaybeRefOrGetter",
1822
+ space: "type"
1823
+ }],
1787
1824
  path: "vue"
1788
- }), /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
1789
- name: ["MaybeRefOrGetter"],
1790
- path: "vue",
1791
- isTypeOnly: true
1792
- })] }),
1825
+ }) }),
1793
1826
  children: [/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(MutationKey, {
1794
1827
  name: mutationKeyName,
1795
1828
  node,
1796
1829
  transformer: ctx.options.mutationKey
1797
- }), mutation && hooks && /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx_jsx_runtime.Fragment, { children: [
1798
- /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
1799
- name: ["useMutation"],
1800
- path: importPath
1801
- }),
1802
- /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
1803
- name: ["MutationObserverOptions", "QueryClient"],
1804
- path: importPath,
1805
- isTypeOnly: true
1806
- }),
1807
- /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(Mutation, {
1808
- name: mutationHookName,
1809
- clientName: contractOp.name,
1810
- node,
1811
- tsResolver: hook.tsResolver,
1812
- mutationKeyName,
1813
- clientReturnType: contractOp.returnType,
1814
- returnType: hook.returnType,
1815
- typedHeaders: hook.contractOp.typedHeaders
1816
- })
1817
- ] })]
1830
+ }), mutation && hooks && /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
1831
+ names: [
1832
+ {
1833
+ name: "useMutation",
1834
+ space: "value"
1835
+ },
1836
+ {
1837
+ name: "MutationObserverOptions",
1838
+ space: "type"
1839
+ },
1840
+ {
1841
+ name: "QueryClient",
1842
+ space: "type"
1843
+ }
1844
+ ],
1845
+ path: importPath
1846
+ }), /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(Mutation, {
1847
+ name: mutationHookName,
1848
+ clientName: contractOp.name,
1849
+ node,
1850
+ tsResolver: hook.tsResolver,
1851
+ mutationKeyName,
1852
+ clientReturnType: contractOp.returnType,
1853
+ returnType: hook.returnType,
1854
+ typedHeaders: hook.contractOp.typedHeaders
1855
+ })] })]
1818
1856
  });
1819
1857
  }
1820
1858
  });
1821
- // src/generators/queryGenerator.tsx
1859
+ // src/templates/query.tsx
1822
1860
  /**
1823
- * Built-in generator for `useQuery` composables. Emits one `useFooQuery`
1861
+ * Built-in template for `useQuery` composables. Emits one `useFooQuery`
1824
1862
  * composable per GET and QUERY operation (configurable via `query.methods`) plus the
1825
1863
  * matching `fooQueryKey` / `fooQueryOptions` helpers.
1826
1864
  */
1827
- const queryGenerator = (0, _kubb_kit.defineGenerator)({
1828
- name: "vue-query",
1829
- renderer: _kubb_renderer_jsx.jsxRenderer,
1830
- operation(node, ctx) {
1865
+ const queryOperation = (0, _kubb_kit.defineTemplate)({
1866
+ kind: _kubb_ast.node.kinds.operation,
1867
+ render(node, ctx) {
1831
1868
  if (!isOperation(node)) return null;
1832
1869
  const { query, mutation, client, hooks } = ctx.options;
1833
1870
  const { isQuery, isMutation } = classifyOperation(node, {
@@ -1853,14 +1890,16 @@ const queryGenerator = (0, _kubb_kit.defineGenerator)({
1853
1890
  const { tsResolver } = hook;
1854
1891
  return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(HookFile, {
1855
1892
  hook,
1856
- imports: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
1857
- name: ["toValue"],
1893
+ imports: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx_jsx_runtime.Fragment, { children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
1894
+ names: [{
1895
+ name: "toValue",
1896
+ space: "value"
1897
+ }, {
1898
+ name: "MaybeRefOrGetter",
1899
+ space: "type"
1900
+ }],
1858
1901
  path: "vue"
1859
- }), /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
1860
- name: ["MaybeRefOrGetter"],
1861
- path: "vue",
1862
- isTypeOnly: true
1863
- })] }),
1902
+ }) }),
1864
1903
  children: [
1865
1904
  /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(QueryKey, {
1866
1905
  name: queryKeyName,
@@ -1873,7 +1912,10 @@ const queryGenerator = (0, _kubb_kit.defineGenerator)({
1873
1912
  exportType: true
1874
1913
  }),
1875
1914
  /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
1876
- name: ["queryOptions"],
1915
+ names: [{
1916
+ name: "queryOptions",
1917
+ space: "value"
1918
+ }],
1877
1919
  path: importPath
1878
1920
  }),
1879
1921
  /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(QueryOptions, {
@@ -1886,32 +1928,40 @@ const queryGenerator = (0, _kubb_kit.defineGenerator)({
1886
1928
  returnType: hook.returnType,
1887
1929
  typedHeaders: hook.contractOp.typedHeaders
1888
1930
  }),
1889
- query && hooks && /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx_jsx_runtime.Fragment, { children: [
1890
- /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
1891
- name: ["useQuery"],
1892
- path: importPath
1893
- }),
1894
- /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
1895
- name: [
1896
- "QueryKey",
1897
- "QueryClient",
1898
- "UseQueryOptions",
1899
- "UseQueryReturnType"
1900
- ],
1901
- path: importPath,
1902
- isTypeOnly: true
1903
- }),
1904
- /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(Query, {
1905
- name: queryName,
1906
- queryOptionsName,
1907
- queryKeyName,
1908
- queryKeyTypeName,
1909
- node,
1910
- tsResolver,
1911
- returnType: hook.returnType,
1912
- typedHeaders: hook.contractOp.typedHeaders
1913
- })
1914
- ] })
1931
+ query && hooks && /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
1932
+ names: [
1933
+ {
1934
+ name: "useQuery",
1935
+ space: "value"
1936
+ },
1937
+ {
1938
+ name: "QueryKey",
1939
+ space: "type"
1940
+ },
1941
+ {
1942
+ name: "QueryClient",
1943
+ space: "type"
1944
+ },
1945
+ {
1946
+ name: "UseQueryOptions",
1947
+ space: "type"
1948
+ },
1949
+ {
1950
+ name: "UseQueryReturnType",
1951
+ space: "type"
1952
+ }
1953
+ ],
1954
+ path: importPath
1955
+ }), /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(Query, {
1956
+ name: queryName,
1957
+ queryOptionsName,
1958
+ queryKeyName,
1959
+ queryKeyTypeName,
1960
+ node,
1961
+ tsResolver,
1962
+ returnType: hook.returnType,
1963
+ typedHeaders: hook.contractOp.typedHeaders
1964
+ })] })
1915
1965
  ]
1916
1966
  });
1917
1967
  }
@@ -1987,8 +2037,10 @@ const pluginVueQuery = (0, _kubb_kit.defineExtension)({
1987
2037
  }, group, exclude = [], include, override = [], infinite = false, mutation = {}, query = {}, mutationKey = mutationKeyTransformer, queryKey = queryKeyTransformer, hooks = false, client, returnType = "data", resolver: userResolver, macros: userMacros } = options;
1988
2038
  const resolver = userResolver ? _kubb_kit.Resolver.merge(resolverVueQuery, ...[userResolver].flat()) : resolverVueQuery;
1989
2039
  (0, _kubb_kit.setResolver)(resolver);
1990
- if (userMacros?.length) (0, _kubb_kit.setMacros)(userMacros);
1991
- (0, _kubb_kit.addGenerator)(queryGenerator, infiniteQueryGenerator, mutationGenerator);
2040
+ (0, _kubb_kit.addMacro)(...userMacros ?? []);
2041
+ (0, _kubb_kit.addTemplate)(queryOperation);
2042
+ (0, _kubb_kit.addTemplate)(infiniteQueryOperation);
2043
+ (0, _kubb_kit.addTemplate)(mutationOperation);
1992
2044
  return {
1993
2045
  output,
1994
2046
  client: resolveContractClient({