@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.js CHANGED
@@ -1,8 +1,8 @@
1
- import { Diagnostics, Resolver, Url, addGenerator, casing, code, createResolver, defineExtension, defineGenerator, operationKey, setMacros, setResolver, useConfig, useKubb } from "@kubb/kit";
1
+ import { Diagnostics, Resolver, Url, addMacro, addTemplate, casing, code, createResolver, defineExtension, defineTemplate, operationKey, setResolver, useConfig, useKubb } from "@kubb/kit";
2
2
  import { createFunctionParameter, createFunctionParameters, createObjectBindingPattern, createTypeLiteral, functionPrinter, pluginTsName } from "@kubb/plugin-ts";
3
+ import { ast, file as file$1, node, ref } from "@kubb/ast";
3
4
  import path from "node:path";
4
- import { ast, ref } from "@kubb/ast";
5
- import { File, Function, Type, jsxRenderer } from "@kubb/renderer-jsx";
5
+ import { File, Function, Type } from "@kubb/renderer-jsx";
6
6
  import { Fragment, jsx, jsxs } from "@kubb/renderer-jsx/jsx-runtime";
7
7
  // kubb-extension.json
8
8
  var compatibility = {
@@ -10,7 +10,159 @@ var compatibility = {
10
10
  "node": ">=22.22"
11
11
  };
12
12
  // package.json
13
- var version = "5.13.0-canary.20261122T213936";
13
+ var version = "5.13.1";
14
+ // ../../internals/ast/src/http/requestBody.ts
15
+ /** The schema of the first request body entry, else `undefined` when the operation takes no body. */
16
+ function getSchema(node) {
17
+ return node.requestBody?.content?.[0]?.schema;
18
+ }
19
+ // ../../internals/ast/src/http/status.ts
20
+ const classByRange = /* @__PURE__ */ new Map([
21
+ ["1xx", 1],
22
+ ["2xx", 2],
23
+ ["3xx", 3],
24
+ ["4xx", 4],
25
+ ["5xx", 5]
26
+ ]);
27
+ /** The class digit of a status code or range: `2` for `201` and `2xx`, `null` for `default`. */
28
+ function statusClass(input) {
29
+ const statusCode = typeof input === "object" ? input.statusCode : input;
30
+ const rangeClass = classByRange.get(String(statusCode));
31
+ if (rangeClass) return rangeClass;
32
+ const code = Number(statusCode);
33
+ return Number.isNaN(code) ? null : Math.floor(code / 100);
34
+ }
35
+ function isSuccess(statusCode) {
36
+ return statusClass(statusCode) === 2;
37
+ }
38
+ function isError(statusCode) {
39
+ const code = statusClass(statusCode);
40
+ return code !== null && code >= 4;
41
+ }
42
+ // ../../internals/ast/src/http/responses.ts
43
+ /** The `4xx` and `5xx` responses, ranges included. */
44
+ function filterError(node) {
45
+ return node.responses.filter((response) => isError(response.statusCode));
46
+ }
47
+ function filterSuccess(node) {
48
+ return node.responses.filter((response) => isSuccess(response.statusCode));
49
+ }
50
+ /** The success response a client returns: one with a body first, then an exact code over a `2xx` range. */
51
+ function findPrimary(node) {
52
+ const responses = filterSuccess(node);
53
+ const withBody = responses.filter((response) => response.content?.some((entry) => entry.contentType));
54
+ const candidates = withBody.length ? withBody : responses;
55
+ return candidates.find((response) => !Number.isNaN(Number(response.statusCode))) ?? candidates[0] ?? null;
56
+ }
57
+ // ../../internals/ast/src/http/index.ts
58
+ const isOperation = ast.http.isOperation;
59
+ /** Computes once per key; generators visit the same node many times. */
60
+ function cached(store, key, compute) {
61
+ if (!store.has(key)) store.set(key, compute());
62
+ return store.get(key);
63
+ }
64
+ const parametersByNode = /* @__PURE__ */ new WeakMap();
65
+ /** The operation's parameters by location, with a `querystring` parameter in `query`. A repeated name keeps its first parameter. */
66
+ function groupParameters(node) {
67
+ return cached(parametersByNode, node, () => {
68
+ const group = (...locations) => {
69
+ const seen = /* @__PURE__ */ new Set();
70
+ return locations.flatMap((location) => node.parameters.filter((param) => {
71
+ if (param.in !== location || seen.has(param.name)) return false;
72
+ seen.add(param.name);
73
+ return true;
74
+ }));
75
+ };
76
+ return {
77
+ path: group("path"),
78
+ query: group("query", "querystring"),
79
+ header: group("header"),
80
+ cookie: group("cookie")
81
+ };
82
+ });
83
+ }
84
+ const requestGroupsByNode = /* @__PURE__ */ new WeakMap();
85
+ /** Which request groups are present, which hold a required member, and the body's media types. Built once per operation. */
86
+ function getRequestGroups(node) {
87
+ return cached(requestGroupsByNode, node, () => {
88
+ const { path, query, header, cookie } = groupParameters(node);
89
+ const content = node.requestBody?.content ?? [];
90
+ const body = Boolean(content[0]?.schema);
91
+ const required = {
92
+ path: path.some((param) => param.required),
93
+ query: query.some((param) => param.required),
94
+ headers: header.some((param) => param.required),
95
+ body: body && node.requestBody?.required === true
96
+ };
97
+ return {
98
+ path: path.length > 0,
99
+ query: query.length > 0,
100
+ body,
101
+ headers: header.length > 0,
102
+ cookies: cookie.length > 0,
103
+ required,
104
+ isOptional: !required.path && !required.query && !required.headers && !required.body,
105
+ contentTypes: content.map((entry) => entry.contentType),
106
+ hasContentTypeChoice: content.filter((entry) => entry.schema).length > 1
107
+ };
108
+ });
109
+ }
110
+ // ../../internals/ast/src/imports.ts
111
+ /**
112
+ * Returns the names of `imp`, each marked as a type, for an import that only types use.
113
+ *
114
+ * @example
115
+ * ```tsx
116
+ * <File.Import names={ast.imports.asType(imp)} path={imp.path} root={file.path} />
117
+ * ```
118
+ */
119
+ function asType(imp) {
120
+ return file$1.getNames(imp).map((item) => ({
121
+ ...item,
122
+ space: "type"
123
+ }));
124
+ }
125
+ // ../../internals/ast/src/mediaType.ts
126
+ const streamMediaTypes = /* @__PURE__ */ new Set([
127
+ "application/jsonl",
128
+ "application/x-ndjson",
129
+ "application/json-seq",
130
+ "text/event-stream"
131
+ ]);
132
+ const getBase = ast.mediaType.getBase;
133
+ const isJson = ast.mediaType.isJson;
134
+ /** Whether the media type is a stream of items: SSE, JSON Lines, or a `+json-seq` sequence. */
135
+ function isStream(mediaType) {
136
+ const baseType = getBase(mediaType);
137
+ return streamMediaTypes.has(baseType) || baseType.startsWith("application/") && baseType.endsWith("+json-seq");
138
+ }
139
+ const formKinds = {
140
+ "multipart/form-data": "form",
141
+ "application/x-www-form-urlencoded": "urlencoded"
142
+ };
143
+ /** How a client reads or sends a content entry, or `null` for another media type. A `blob` schema is `binary`. */
144
+ function getKind(entry) {
145
+ const content = typeof entry === "string" ? { contentType: entry } : entry;
146
+ const baseType = getBase(content);
147
+ if (!baseType) return null;
148
+ if (baseType === "text/event-stream") return "eventStream";
149
+ if (content.stream && isStream(content)) return "lineStream";
150
+ if (isJson(baseType)) return "json";
151
+ if (formKinds[baseType]) return formKinds[baseType];
152
+ if (content.schema?.type === "blob") return "binary";
153
+ if (baseType.startsWith("text/")) return "text";
154
+ if (baseType === "application/octet-stream" || baseType === "application/pdf" || /^(image|audio|video)\//.test(baseType)) return "binary";
155
+ return null;
156
+ }
157
+ ast.schema.applyOptionality;
158
+ ast.schema.types;
159
+ const narrow = ast.schema.narrow;
160
+ ast.schema.find;
161
+ ast.schema.getEmbeddedJson;
162
+ const is = ast.schema.is;
163
+ const getLiterals = ast.schema.getLiterals;
164
+ ast.schema.inferDiscriminator;
165
+ const findProperties = ast.schema.findProperties;
14
166
  // ../../internals/client/src/resolveClient.ts
15
167
  /**
16
168
  * Resolves which client plugin a consumer (react-query, vue-query, swr, mcp) should call for an
@@ -172,7 +324,7 @@ function resolveClientOperation({ node, pluginName }) {
172
324
  }),
173
325
  clientPathIsFile: importPath === void 0 || isRelativeImport(importPath),
174
326
  returnType: operationOptions.returnType ?? "full",
175
- typedHeaders: importPath === void 0
327
+ typedHeaders: importPath === void 0 || pluginName !== "plugin-client"
176
328
  };
177
329
  });
178
330
  }
@@ -250,143 +402,6 @@ function resolveOperationTypes() {
250
402
  };
251
403
  });
252
404
  }
253
- // ../../internals/ast/src/http/requestBody.ts
254
- /** The schema of the first request body entry, else `undefined` when the operation takes no body. */
255
- function getSchema(node) {
256
- return node.requestBody?.content?.[0]?.schema;
257
- }
258
- // ../../internals/ast/src/http/status.ts
259
- const classByRange = /* @__PURE__ */ new Map([
260
- ["1xx", 1],
261
- ["2xx", 2],
262
- ["3xx", 3],
263
- ["4xx", 4],
264
- ["5xx", 5]
265
- ]);
266
- /** The class digit of a status code or range: `2` for `201` and `2xx`, `null` for `default`. */
267
- function statusClass(input) {
268
- const statusCode = typeof input === "object" ? input.statusCode : input;
269
- const rangeClass = classByRange.get(String(statusCode));
270
- if (rangeClass) return rangeClass;
271
- const code = Number(statusCode);
272
- return Number.isNaN(code) ? null : Math.floor(code / 100);
273
- }
274
- function isSuccess(statusCode) {
275
- return statusClass(statusCode) === 2;
276
- }
277
- function isError(statusCode) {
278
- const code = statusClass(statusCode);
279
- return code !== null && code >= 4;
280
- }
281
- // ../../internals/ast/src/http/responses.ts
282
- /** The `4xx` and `5xx` responses, ranges included. */
283
- function filterError(node) {
284
- return node.responses.filter((response) => isError(response.statusCode));
285
- }
286
- function filterSuccess(node) {
287
- return node.responses.filter((response) => isSuccess(response.statusCode));
288
- }
289
- /** The success response a client returns: one with a body first, then an exact code over a `2xx` range. */
290
- function findPrimary(node) {
291
- const responses = filterSuccess(node);
292
- const withBody = responses.filter((response) => response.content?.some((entry) => entry.contentType));
293
- const candidates = withBody.length ? withBody : responses;
294
- return candidates.find((response) => !Number.isNaN(Number(response.statusCode))) ?? candidates[0] ?? null;
295
- }
296
- // ../../internals/ast/src/http/index.ts
297
- const isOperation = ast.http.isOperation;
298
- /** Computes once per key; generators visit the same node many times. */
299
- function cached(store, key, compute) {
300
- if (!store.has(key)) store.set(key, compute());
301
- return store.get(key);
302
- }
303
- const parametersByNode = /* @__PURE__ */ new WeakMap();
304
- /** The operation's parameters by location, with a `querystring` parameter in `query`. A repeated name keeps its first parameter. */
305
- function groupParameters(node) {
306
- return cached(parametersByNode, node, () => {
307
- const group = (...locations) => {
308
- const seen = /* @__PURE__ */ new Set();
309
- return locations.flatMap((location) => node.parameters.filter((param) => {
310
- if (param.in !== location || seen.has(param.name)) return false;
311
- seen.add(param.name);
312
- return true;
313
- }));
314
- };
315
- return {
316
- path: group("path"),
317
- query: group("query", "querystring"),
318
- header: group("header"),
319
- cookie: group("cookie")
320
- };
321
- });
322
- }
323
- const requestGroupsByNode = /* @__PURE__ */ new WeakMap();
324
- /** Which request groups are present, which hold a required member, and the body's media types. Built once per operation. */
325
- function getRequestGroups(node) {
326
- return cached(requestGroupsByNode, node, () => {
327
- const { path, query, header, cookie } = groupParameters(node);
328
- const content = node.requestBody?.content ?? [];
329
- const body = Boolean(content[0]?.schema);
330
- const required = {
331
- path: path.some((param) => param.required),
332
- query: query.some((param) => param.required),
333
- headers: header.some((param) => param.required),
334
- body: body && node.requestBody?.required === true
335
- };
336
- return {
337
- path: path.length > 0,
338
- query: query.length > 0,
339
- body,
340
- headers: header.length > 0,
341
- cookies: cookie.length > 0,
342
- required,
343
- isOptional: !required.path && !required.query && !required.headers && !required.body,
344
- contentTypes: content.map((entry) => entry.contentType),
345
- hasContentTypeChoice: content.filter((entry) => entry.schema).length > 1
346
- };
347
- });
348
- }
349
- // ../../internals/ast/src/mediaType.ts
350
- const streamMediaTypes = /* @__PURE__ */ new Set([
351
- "application/jsonl",
352
- "application/x-ndjson",
353
- "application/json-seq",
354
- "text/event-stream"
355
- ]);
356
- const getBase = ast.mediaType.getBase;
357
- const isJson = ast.mediaType.isJson;
358
- /** Whether the media type is a stream of items: SSE, JSON Lines, or a `+json-seq` sequence. */
359
- function isStream(mediaType) {
360
- const baseType = getBase(mediaType);
361
- return streamMediaTypes.has(baseType) || baseType.startsWith("application/") && baseType.endsWith("+json-seq");
362
- }
363
- const formKinds = {
364
- "multipart/form-data": "form",
365
- "application/x-www-form-urlencoded": "urlencoded"
366
- };
367
- /** How a client reads or sends a content entry, or `null` for another media type. A `blob` schema is `binary`. */
368
- function getKind(entry) {
369
- const content = typeof entry === "string" ? { contentType: entry } : entry;
370
- const baseType = getBase(content);
371
- if (!baseType) return null;
372
- if (baseType === "text/event-stream") return "eventStream";
373
- if (content.stream && isStream(content)) return "lineStream";
374
- if (isJson(baseType)) return "json";
375
- if (formKinds[baseType]) return formKinds[baseType];
376
- if (content.schema?.type === "blob") return "binary";
377
- if (baseType.startsWith("text/")) return "text";
378
- if (baseType === "application/octet-stream" || baseType === "application/pdf" || /^(image|audio|video)\//.test(baseType)) return "binary";
379
- return null;
380
- }
381
- ast.schema.applyOptionality;
382
- ast.schema.types;
383
- const narrow = ast.schema.narrow;
384
- ast.schema.find;
385
- ast.schema.getEmbeddedJson;
386
- const is = ast.schema.is;
387
- const getLiterals = ast.schema.getLiterals;
388
- ast.schema.inferDiscriminator;
389
- const findProperties = ast.schema.findProperties;
390
405
  // ../../internals/utils/src/reserved.ts
391
406
  /**
392
407
  * JavaScript and Java reserved words.
@@ -859,25 +874,30 @@ function HookFile({ hook, imports, children }) {
859
874
  ...file,
860
875
  children: [
861
876
  /* @__PURE__ */ jsx(File.Import, {
862
- name: [contractOp.name],
877
+ names: [{
878
+ name: contractOp.name,
879
+ space: "value"
880
+ }],
863
881
  root: file.path,
864
882
  path: contractOp.path
865
883
  }),
866
884
  /* @__PURE__ */ jsx(File.Import, {
867
- name: [
885
+ names: [
868
886
  "RequestConfig",
869
887
  "ResponseErrorConfig",
870
888
  resultTypeName
871
- ],
889
+ ].map((name) => ({
890
+ name,
891
+ space: "type"
892
+ })),
872
893
  root: contractOp.clientPathIsFile ? file.path : void 0,
873
- path: contractOp.clientPath,
874
- isTypeOnly: true
894
+ path: contractOp.clientPath
875
895
  }),
876
896
  imports,
877
897
  typeImports.map((imp) => /* @__PURE__ */ jsx(File.Import, {
878
- ...imp,
898
+ names: asType(imp),
879
899
  root: file.path,
880
- isTypeOnly: true
900
+ path: imp.path
881
901
  }, imp.path)),
882
902
  children
883
903
  ]
@@ -900,8 +920,7 @@ function maybeRefOrGetter(type) {
900
920
  /**
901
921
  * Builds the grouped `{ path, query, body, headers, cookies }` parameter that mirrors the client
902
922
  * function signature. Only the groups the operation carries are emitted, typed from the
903
- * operation's `Options`. `keys` narrows the emitted groups, used by the query key which
904
- * never carries `headers`.
923
+ * operation's `Options`. `keys` narrows the emitted groups.
905
924
  *
906
925
  * By default the whole group is typed as the single `Options` reference. When
907
926
  * `memberTypeWrapper` is set, each group is emitted as its own member typed from the matching
@@ -909,7 +928,7 @@ function maybeRefOrGetter(type) {
909
928
  * `MaybeRefOrGetter` per group.
910
929
  */
911
930
  function buildGroupedRequestParam(node, options) {
912
- const { resolver, keys = requestGroupOrder, memberTypeWrapper, withContentType = false } = options;
931
+ const { resolver, keys = requestGroupOrder, memberTypeWrapper, optionalHeaders = false, withContentType = false } = options;
913
932
  const groups = getRequestGroups(node);
914
933
  const names = keys.filter((key) => groups[key]);
915
934
  if (names.length === 0) return null;
@@ -917,7 +936,7 @@ function buildGroupedRequestParam(node, options) {
917
936
  path: groups.required.path,
918
937
  query: groups.required.query,
919
938
  body: groups.body,
920
- headers: groups.required.headers,
939
+ headers: !optionalHeaders && groups.required.headers,
921
940
  cookies: false
922
941
  };
923
942
  const isOptional = names.every((name) => !requiredByGroup[name]);
@@ -927,8 +946,9 @@ function buildGroupedRequestParam(node, options) {
927
946
  type: optionsName,
928
947
  optional: false
929
948
  });
930
- const omittedKeys = requestGroupOrder.filter((key) => !keys.includes(key) && (key !== "cookies" || groups.cookies));
949
+ const omittedKeys = requestGroupOrder.filter((key) => (!keys.includes(key) || optionalHeaders && key === "headers" && !groups.headers) && (key !== "cookies" || groups.cookies));
931
950
  const optionsType = omittedKeys.length > 0 ? `Omit<${optionsName}, ${omittedKeys.map((key) => `'${key}'`).join(" | ")}>` : optionsName;
951
+ const paramType = optionalHeaders && names.includes("headers") ? `Omit<${optionsType}, 'headers'> & { headers?: ${optionsType}['headers'] }` : optionsType;
932
952
  if (memberTypeWrapper) {
933
953
  const members = names.map((name) => ({
934
954
  name,
@@ -944,7 +964,7 @@ function buildGroupedRequestParam(node, options) {
944
964
  }
945
965
  return createFunctionParameter({
946
966
  name: createObjectBindingPattern({ elements: names.map((name) => ({ name })) }),
947
- type: optionsType,
967
+ type: paramType,
948
968
  optional: false,
949
969
  ...isOptional ? { default: "{}" } : {}
950
970
  });
@@ -1179,27 +1199,26 @@ function getDefaultPageParamsWarning(node, infinite) {
1179
1199
  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.`;
1180
1200
  }
1181
1201
  /**
1182
- * The request groups a query key is built from, matching `buildQueryKeyParams`. Headers are
1183
- * deliberately absent: they do not identify a cache entry, so the key factory takes no parameter
1184
- * for an operation that only carries headers. Cookies are left out too: they often hold a session token, and a query key
1185
- * is stored in SSR payloads, persisted caches, and devtools.
1202
+ * The request groups available to a query key transformer. Headers are available for custom keys
1203
+ * but excluded from the default key. Cookies stay excluded.
1186
1204
  */
1187
1205
  const queryKeyGroupOrder = [
1188
1206
  "path",
1189
1207
  "query",
1190
- "body"
1208
+ "body",
1209
+ "headers"
1191
1210
  ];
1192
1211
  /**
1193
- * Build QueryKey params as the grouped `{ path, query, body }` object (NO headers, NO cookies, NO config),
1194
- * typed from the operation's `Options` minus `url`. The query key transformer reads the
1195
- * grouped `path`/`query`/`body` bindings.
1212
+ * Builds query key bindings for path, query, body, and optional headers. Custom transformers
1213
+ * can reference `headers` in returned code without changing the default key.
1196
1214
  */
1197
1215
  function buildQueryKeyParams(node, options) {
1198
1216
  const { resolver, memberTypeWrapper } = options;
1199
1217
  const groupedParam = buildGroupedRequestParam(node, {
1200
1218
  resolver,
1201
1219
  keys: queryKeyGroupOrder,
1202
- memberTypeWrapper
1220
+ memberTypeWrapper,
1221
+ optionalHeaders: true
1203
1222
  });
1204
1223
  return createFunctionParameters({ params: groupedParam ? [groupedParam] : [] });
1205
1224
  }
@@ -1513,29 +1532,28 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, t
1513
1532
  `
1514
1533
  });
1515
1534
  }
1516
- // src/generators/infiniteQueryGenerator.tsx
1535
+ // src/templates/infiniteQuery.tsx
1536
+ function matchesInfiniteQuery(node, ctx) {
1537
+ if (!isOperation(node)) return false;
1538
+ const { query, mutation, infinite, hooks } = ctx.options;
1539
+ const { isQuery, isMutation } = classifyOperation(node, {
1540
+ query,
1541
+ mutation
1542
+ });
1543
+ const infiniteOptions = infinite && typeof infinite === "object" ? infinite : null;
1544
+ if (!isQuery || isMutation || !infiniteOptions || !hooks) return false;
1545
+ return matchesInfinite(node, infiniteOptions);
1546
+ }
1517
1547
  /**
1518
- * Built-in generator for `useInfiniteQuery` composables. Enabled when
1548
+ * Built-in template for `useInfiniteQuery` composables. Enabled when
1519
1549
  * `pluginVueQuery({ infinite: { ... }, hooks: true })`. Emits one
1520
1550
  * `useFooInfiniteQuery` composable per query operation, wiring the
1521
1551
  * configured cursor path into TanStack Query's cursor-based pagination.
1522
1552
  */
1523
- const infiniteQueryGenerator = defineGenerator({
1524
- name: "vue-query-infinite",
1525
- renderer: jsxRenderer,
1526
- match(node, ctx) {
1527
- const operationNode = node;
1528
- if (!isOperation(operationNode)) return false;
1529
- const { query, mutation, infinite, hooks } = ctx.options;
1530
- const { isQuery, isMutation } = classifyOperation(operationNode, {
1531
- query,
1532
- mutation
1533
- });
1534
- const infiniteOptions = infinite && typeof infinite === "object" ? infinite : null;
1535
- if (!isQuery || isMutation || !infiniteOptions || !hooks) return false;
1536
- return matchesInfinite(operationNode, infiniteOptions);
1537
- },
1538
- operation(node, ctx) {
1553
+ const infiniteQueryOperation = defineTemplate({
1554
+ kind: node.kinds.operation,
1555
+ render(node, ctx) {
1556
+ if (!matchesInfiniteQuery(node, ctx)) return null;
1539
1557
  if (!isOperation(node)) return null;
1540
1558
  const { query, infinite, client } = ctx.options;
1541
1559
  const infiniteOptions = infinite && typeof infinite === "object" ? infinite : null;
@@ -1566,14 +1584,16 @@ const infiniteQueryGenerator = defineGenerator({
1566
1584
  const { tsResolver } = hook;
1567
1585
  return /* @__PURE__ */ jsxs(HookFile, {
1568
1586
  hook,
1569
- imports: /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(File.Import, {
1570
- name: ["toValue"],
1587
+ imports: /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(File.Import, {
1588
+ names: [{
1589
+ name: "toValue",
1590
+ space: "value"
1591
+ }, {
1592
+ name: "MaybeRefOrGetter",
1593
+ space: "type"
1594
+ }],
1571
1595
  path: "vue"
1572
- }), /* @__PURE__ */ jsx(File.Import, {
1573
- name: ["MaybeRefOrGetter"],
1574
- path: "vue",
1575
- isTypeOnly: true
1576
- })] }),
1596
+ }) }),
1577
1597
  children: [
1578
1598
  /* @__PURE__ */ jsx(QueryKey, {
1579
1599
  name: queryKeyName,
@@ -1586,12 +1606,13 @@ const infiniteQueryGenerator = defineGenerator({
1586
1606
  exportType: true
1587
1607
  }),
1588
1608
  /* @__PURE__ */ jsx(File.Import, {
1589
- name: ["InfiniteData"],
1590
- isTypeOnly: true,
1591
- path: importPath
1592
- }),
1593
- /* @__PURE__ */ jsx(File.Import, {
1594
- name: ["infiniteQueryOptions"],
1609
+ names: [{
1610
+ name: "infiniteQueryOptions",
1611
+ space: "value"
1612
+ }, {
1613
+ name: "InfiniteData",
1614
+ space: "type"
1615
+ }],
1595
1616
  path: importPath
1596
1617
  }),
1597
1618
  /* @__PURE__ */ jsx(InfiniteQueryOptions, {
@@ -1616,18 +1637,29 @@ const infiniteQueryGenerator = defineGenerator({
1616
1637
  unwrapName: (name) => `toValue(${name})`
1617
1638
  }),
1618
1639
  /* @__PURE__ */ jsx(File.Import, {
1619
- name: ["useInfiniteQuery"],
1620
- path: importPath
1621
- }),
1622
- /* @__PURE__ */ jsx(File.Import, {
1623
- name: [
1624
- "QueryKey",
1625
- "QueryClient",
1626
- "UseInfiniteQueryOptions",
1627
- "UseInfiniteQueryReturnType"
1640
+ names: [
1641
+ {
1642
+ name: "useInfiniteQuery",
1643
+ space: "value"
1644
+ },
1645
+ {
1646
+ name: "QueryKey",
1647
+ space: "type"
1648
+ },
1649
+ {
1650
+ name: "QueryClient",
1651
+ space: "type"
1652
+ },
1653
+ {
1654
+ name: "UseInfiniteQueryOptions",
1655
+ space: "type"
1656
+ },
1657
+ {
1658
+ name: "UseInfiniteQueryReturnType",
1659
+ space: "type"
1660
+ }
1628
1661
  ],
1629
- path: importPath,
1630
- isTypeOnly: true
1662
+ path: importPath
1631
1663
  }),
1632
1664
  /* @__PURE__ */ jsx(Query, {
1633
1665
  name: queryName,
@@ -1722,16 +1754,15 @@ function Mutation({ name, clientName, node, tsResolver, mutationKeyName, clientR
1722
1754
  `
1723
1755
  });
1724
1756
  }
1725
- // src/generators/mutationGenerator.tsx
1757
+ // src/templates/mutation.tsx
1726
1758
  /**
1727
- * Built-in generator for `useMutation` composables. Emits one
1759
+ * Built-in template for `useMutation` composables. Emits one
1728
1760
  * `useFooMutation` composable per POST/PUT/DELETE operation (configurable
1729
1761
  * via `mutation.methods`) plus the matching `fooMutationKey` helper.
1730
1762
  */
1731
- const mutationGenerator = defineGenerator({
1732
- name: "vue-query-mutation",
1733
- renderer: jsxRenderer,
1734
- operation(node, ctx) {
1763
+ const mutationOperation = defineTemplate({
1764
+ kind: node.kinds.operation,
1765
+ render(node, ctx) {
1735
1766
  if (!isOperation(node)) return null;
1736
1767
  const { query, mutation, client, hooks } = ctx.options;
1737
1768
  const { isMutation } = classifyOperation(node, {
@@ -1756,52 +1787,58 @@ const mutationGenerator = defineGenerator({
1756
1787
  const hasRequestGroups = requestGroupOrder.some((key) => groups[key]);
1757
1788
  return /* @__PURE__ */ jsxs(HookFile, {
1758
1789
  hook,
1759
- imports: /* @__PURE__ */ jsxs(Fragment, { children: [hasRequestGroups && /* @__PURE__ */ jsx(File.Import, {
1760
- name: ["toValue"],
1790
+ imports: /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(File.Import, {
1791
+ names: [...hasRequestGroups ? [{
1792
+ name: "toValue",
1793
+ space: "value"
1794
+ }] : [], {
1795
+ name: "MaybeRefOrGetter",
1796
+ space: "type"
1797
+ }],
1761
1798
  path: "vue"
1762
- }), /* @__PURE__ */ jsx(File.Import, {
1763
- name: ["MaybeRefOrGetter"],
1764
- path: "vue",
1765
- isTypeOnly: true
1766
- })] }),
1799
+ }) }),
1767
1800
  children: [/* @__PURE__ */ jsx(MutationKey, {
1768
1801
  name: mutationKeyName,
1769
1802
  node,
1770
1803
  transformer: ctx.options.mutationKey
1771
- }), mutation && hooks && /* @__PURE__ */ jsxs(Fragment, { children: [
1772
- /* @__PURE__ */ jsx(File.Import, {
1773
- name: ["useMutation"],
1774
- path: importPath
1775
- }),
1776
- /* @__PURE__ */ jsx(File.Import, {
1777
- name: ["MutationObserverOptions", "QueryClient"],
1778
- path: importPath,
1779
- isTypeOnly: true
1780
- }),
1781
- /* @__PURE__ */ jsx(Mutation, {
1782
- name: mutationHookName,
1783
- clientName: contractOp.name,
1784
- node,
1785
- tsResolver: hook.tsResolver,
1786
- mutationKeyName,
1787
- clientReturnType: contractOp.returnType,
1788
- returnType: hook.returnType,
1789
- typedHeaders: hook.contractOp.typedHeaders
1790
- })
1791
- ] })]
1804
+ }), mutation && hooks && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(File.Import, {
1805
+ names: [
1806
+ {
1807
+ name: "useMutation",
1808
+ space: "value"
1809
+ },
1810
+ {
1811
+ name: "MutationObserverOptions",
1812
+ space: "type"
1813
+ },
1814
+ {
1815
+ name: "QueryClient",
1816
+ space: "type"
1817
+ }
1818
+ ],
1819
+ path: importPath
1820
+ }), /* @__PURE__ */ jsx(Mutation, {
1821
+ name: mutationHookName,
1822
+ clientName: contractOp.name,
1823
+ node,
1824
+ tsResolver: hook.tsResolver,
1825
+ mutationKeyName,
1826
+ clientReturnType: contractOp.returnType,
1827
+ returnType: hook.returnType,
1828
+ typedHeaders: hook.contractOp.typedHeaders
1829
+ })] })]
1792
1830
  });
1793
1831
  }
1794
1832
  });
1795
- // src/generators/queryGenerator.tsx
1833
+ // src/templates/query.tsx
1796
1834
  /**
1797
- * Built-in generator for `useQuery` composables. Emits one `useFooQuery`
1835
+ * Built-in template for `useQuery` composables. Emits one `useFooQuery`
1798
1836
  * composable per GET and QUERY operation (configurable via `query.methods`) plus the
1799
1837
  * matching `fooQueryKey` / `fooQueryOptions` helpers.
1800
1838
  */
1801
- const queryGenerator = defineGenerator({
1802
- name: "vue-query",
1803
- renderer: jsxRenderer,
1804
- operation(node, ctx) {
1839
+ const queryOperation = defineTemplate({
1840
+ kind: node.kinds.operation,
1841
+ render(node, ctx) {
1805
1842
  if (!isOperation(node)) return null;
1806
1843
  const { query, mutation, client, hooks } = ctx.options;
1807
1844
  const { isQuery, isMutation } = classifyOperation(node, {
@@ -1827,14 +1864,16 @@ const queryGenerator = defineGenerator({
1827
1864
  const { tsResolver } = hook;
1828
1865
  return /* @__PURE__ */ jsxs(HookFile, {
1829
1866
  hook,
1830
- imports: /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(File.Import, {
1831
- name: ["toValue"],
1867
+ imports: /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(File.Import, {
1868
+ names: [{
1869
+ name: "toValue",
1870
+ space: "value"
1871
+ }, {
1872
+ name: "MaybeRefOrGetter",
1873
+ space: "type"
1874
+ }],
1832
1875
  path: "vue"
1833
- }), /* @__PURE__ */ jsx(File.Import, {
1834
- name: ["MaybeRefOrGetter"],
1835
- path: "vue",
1836
- isTypeOnly: true
1837
- })] }),
1876
+ }) }),
1838
1877
  children: [
1839
1878
  /* @__PURE__ */ jsx(QueryKey, {
1840
1879
  name: queryKeyName,
@@ -1847,7 +1886,10 @@ const queryGenerator = defineGenerator({
1847
1886
  exportType: true
1848
1887
  }),
1849
1888
  /* @__PURE__ */ jsx(File.Import, {
1850
- name: ["queryOptions"],
1889
+ names: [{
1890
+ name: "queryOptions",
1891
+ space: "value"
1892
+ }],
1851
1893
  path: importPath
1852
1894
  }),
1853
1895
  /* @__PURE__ */ jsx(QueryOptions, {
@@ -1860,32 +1902,40 @@ const queryGenerator = defineGenerator({
1860
1902
  returnType: hook.returnType,
1861
1903
  typedHeaders: hook.contractOp.typedHeaders
1862
1904
  }),
1863
- query && hooks && /* @__PURE__ */ jsxs(Fragment, { children: [
1864
- /* @__PURE__ */ jsx(File.Import, {
1865
- name: ["useQuery"],
1866
- path: importPath
1867
- }),
1868
- /* @__PURE__ */ jsx(File.Import, {
1869
- name: [
1870
- "QueryKey",
1871
- "QueryClient",
1872
- "UseQueryOptions",
1873
- "UseQueryReturnType"
1874
- ],
1875
- path: importPath,
1876
- isTypeOnly: true
1877
- }),
1878
- /* @__PURE__ */ jsx(Query, {
1879
- name: queryName,
1880
- queryOptionsName,
1881
- queryKeyName,
1882
- queryKeyTypeName,
1883
- node,
1884
- tsResolver,
1885
- returnType: hook.returnType,
1886
- typedHeaders: hook.contractOp.typedHeaders
1887
- })
1888
- ] })
1905
+ query && hooks && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(File.Import, {
1906
+ names: [
1907
+ {
1908
+ name: "useQuery",
1909
+ space: "value"
1910
+ },
1911
+ {
1912
+ name: "QueryKey",
1913
+ space: "type"
1914
+ },
1915
+ {
1916
+ name: "QueryClient",
1917
+ space: "type"
1918
+ },
1919
+ {
1920
+ name: "UseQueryOptions",
1921
+ space: "type"
1922
+ },
1923
+ {
1924
+ name: "UseQueryReturnType",
1925
+ space: "type"
1926
+ }
1927
+ ],
1928
+ path: importPath
1929
+ }), /* @__PURE__ */ jsx(Query, {
1930
+ name: queryName,
1931
+ queryOptionsName,
1932
+ queryKeyName,
1933
+ queryKeyTypeName,
1934
+ node,
1935
+ tsResolver,
1936
+ returnType: hook.returnType,
1937
+ typedHeaders: hook.contractOp.typedHeaders
1938
+ })] })
1889
1939
  ]
1890
1940
  });
1891
1941
  }
@@ -1961,8 +2011,10 @@ const pluginVueQuery = defineExtension({
1961
2011
  }, group, exclude = [], include, override = [], infinite = false, mutation = {}, query = {}, mutationKey = mutationKeyTransformer, queryKey = queryKeyTransformer, hooks = false, client, returnType = "data", resolver: userResolver, macros: userMacros } = options;
1962
2012
  const resolver = userResolver ? Resolver.merge(resolverVueQuery, ...[userResolver].flat()) : resolverVueQuery;
1963
2013
  setResolver(resolver);
1964
- if (userMacros?.length) setMacros(userMacros);
1965
- addGenerator(queryGenerator, infiniteQueryGenerator, mutationGenerator);
2014
+ addMacro(...userMacros ?? []);
2015
+ addTemplate(queryOperation);
2016
+ addTemplate(infiniteQueryOperation);
2017
+ addTemplate(mutationOperation);
1966
2018
  return {
1967
2019
  output,
1968
2020
  client: resolveContractClient({