@kubb/plugin-vue-query 5.13.0 → 5.13.2

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, memo, operationKey, setResolver, text, 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,154 @@ var compatibility = {
10
10
  "node": ">=22.22"
11
11
  };
12
12
  // package.json
13
- var version = "5.13.0";
13
+ var version = "5.13.2";
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
+ const parametersByNode = /* @__PURE__ */ new WeakMap();
60
+ /** The operation's parameters by location, with a `querystring` parameter in `query`. A repeated name keeps its first parameter. */
61
+ function groupParameters(node) {
62
+ return memo(parametersByNode, node, () => {
63
+ const group = (...locations) => {
64
+ const seen = /* @__PURE__ */ new Set();
65
+ return locations.flatMap((location) => node.parameters.filter((param) => {
66
+ if (param.in !== location || seen.has(param.name)) return false;
67
+ seen.add(param.name);
68
+ return true;
69
+ }));
70
+ };
71
+ return {
72
+ path: group("path"),
73
+ query: group("query", "querystring"),
74
+ header: group("header"),
75
+ cookie: group("cookie")
76
+ };
77
+ });
78
+ }
79
+ const requestGroupsByNode = /* @__PURE__ */ new WeakMap();
80
+ /** Which request groups are present, which hold a required member, and the body's media types. Built once per operation. */
81
+ function getRequestGroups(node) {
82
+ return memo(requestGroupsByNode, node, () => {
83
+ const { path, query, header, cookie } = groupParameters(node);
84
+ const content = node.requestBody?.content ?? [];
85
+ const body = Boolean(content[0]?.schema);
86
+ const required = {
87
+ path: path.some((param) => param.required),
88
+ query: query.some((param) => param.required),
89
+ headers: header.some((param) => param.required),
90
+ body: body && node.requestBody?.required === true
91
+ };
92
+ return {
93
+ path: path.length > 0,
94
+ query: query.length > 0,
95
+ body,
96
+ headers: header.length > 0,
97
+ cookies: cookie.length > 0,
98
+ required,
99
+ isOptional: !required.path && !required.query && !required.headers && !required.body,
100
+ contentTypes: content.map((entry) => entry.contentType),
101
+ hasContentTypeChoice: content.filter((entry) => entry.schema).length > 1
102
+ };
103
+ });
104
+ }
105
+ // ../../internals/ast/src/imports.ts
106
+ /**
107
+ * Returns the names of `imp`, each marked as a type, for an import that only types use.
108
+ *
109
+ * @example
110
+ * ```tsx
111
+ * <File.Import names={ast.imports.asType(imp)} path={imp.path} root={file.path} />
112
+ * ```
113
+ */
114
+ function asType(imp) {
115
+ return file$1.getNames(imp).map((item) => ({
116
+ ...item,
117
+ space: "type"
118
+ }));
119
+ }
120
+ // ../../internals/ast/src/mediaType.ts
121
+ const streamMediaTypes = /* @__PURE__ */ new Set([
122
+ "application/jsonl",
123
+ "application/x-ndjson",
124
+ "application/json-seq",
125
+ "text/event-stream"
126
+ ]);
127
+ const getBase = ast.mediaType.getBase;
128
+ const isJson = ast.mediaType.isJson;
129
+ /** Whether the media type is a stream of items: SSE, JSON Lines, or a `+json-seq` sequence. */
130
+ function isStream(mediaType) {
131
+ const baseType = getBase(mediaType);
132
+ return streamMediaTypes.has(baseType) || baseType.startsWith("application/") && baseType.endsWith("+json-seq");
133
+ }
134
+ const formKinds = {
135
+ "multipart/form-data": "form",
136
+ "application/x-www-form-urlencoded": "urlencoded"
137
+ };
138
+ /** How a client reads or sends a content entry, or `null` for another media type. A `blob` schema is `binary`. */
139
+ function getKind(entry) {
140
+ const content = typeof entry === "string" ? { contentType: entry } : entry;
141
+ const baseType = getBase(content);
142
+ if (!baseType) return null;
143
+ if (baseType === "text/event-stream") return "eventStream";
144
+ if (content.stream && isStream(content)) return "lineStream";
145
+ if (isJson(baseType)) return "json";
146
+ if (formKinds[baseType]) return formKinds[baseType];
147
+ if (content.schema?.type === "blob") return "binary";
148
+ if (baseType.startsWith("text/")) return "text";
149
+ if (baseType === "application/octet-stream" || baseType === "application/pdf" || /^(image|audio|video)\//.test(baseType)) return "binary";
150
+ return null;
151
+ }
152
+ ast.schema.applyOptionality;
153
+ ast.schema.types;
154
+ const narrow = ast.schema.narrow;
155
+ ast.schema.find;
156
+ ast.schema.getEmbeddedJson;
157
+ const is = ast.schema.is;
158
+ const getLiterals = ast.schema.getLiterals;
159
+ ast.schema.inferDiscriminator;
160
+ const findProperties = ast.schema.findProperties;
14
161
  // ../../internals/client/src/resolveClient.ts
15
162
  /**
16
163
  * Resolves which client plugin a consumer (react-query, vue-query, swr, mcp) should call for an
@@ -172,7 +319,7 @@ function resolveClientOperation({ node, pluginName }) {
172
319
  }),
173
320
  clientPathIsFile: importPath === void 0 || isRelativeImport(importPath),
174
321
  returnType: operationOptions.returnType ?? "full",
175
- typedHeaders: importPath === void 0
322
+ typedHeaders: importPath === void 0 || pluginName !== "plugin-client"
176
323
  };
177
324
  });
178
325
  }
@@ -250,143 +397,6 @@ function resolveOperationTypes() {
250
397
  };
251
398
  });
252
399
  }
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
400
  // ../../internals/utils/src/reserved.ts
391
401
  /**
392
402
  * JavaScript and Java reserved words.
@@ -859,25 +869,30 @@ function HookFile({ hook, imports, children }) {
859
869
  ...file,
860
870
  children: [
861
871
  /* @__PURE__ */ jsx(File.Import, {
862
- name: [contractOp.name],
872
+ names: [{
873
+ name: contractOp.name,
874
+ space: "value"
875
+ }],
863
876
  root: file.path,
864
877
  path: contractOp.path
865
878
  }),
866
879
  /* @__PURE__ */ jsx(File.Import, {
867
- name: [
880
+ names: [
868
881
  "RequestConfig",
869
882
  "ResponseErrorConfig",
870
883
  resultTypeName
871
- ],
884
+ ].map((name) => ({
885
+ name,
886
+ space: "type"
887
+ })),
872
888
  root: contractOp.clientPathIsFile ? file.path : void 0,
873
- path: contractOp.clientPath,
874
- isTypeOnly: true
889
+ path: contractOp.clientPath
875
890
  }),
876
891
  imports,
877
892
  typeImports.map((imp) => /* @__PURE__ */ jsx(File.Import, {
878
- ...imp,
893
+ names: asType(imp),
879
894
  root: file.path,
880
- isTypeOnly: true
895
+ path: imp.path
881
896
  }, imp.path)),
882
897
  children
883
898
  ]
@@ -1318,7 +1333,7 @@ const declarationPrinter$4 = functionPrinter({ mode: "declaration" });
1318
1333
  */
1319
1334
  const mutationKeyTransformer = ({ node }) => {
1320
1335
  if (!node.path) return [];
1321
- return [`{ url: '${Url.toPath(node.path)}' }`];
1336
+ return [`{ url: ${text.quote(Url.toPath(node.path))} }`];
1322
1337
  };
1323
1338
  function MutationKey({ name, node, transformer, typeName }) {
1324
1339
  const paramsNode = createFunctionParameters({ params: [] });
@@ -1356,7 +1371,7 @@ const queryKeyTransformer = ({ node, variant }) => {
1356
1371
  if (!node.path) return [];
1357
1372
  const { path, query } = groupParameters(node);
1358
1373
  const isInfinite = variant === "infiniteQuery" || variant === "suspenseInfiniteQuery";
1359
- const urlFields = [`url: '${Url.toPath(node.path)}'`];
1374
+ const urlFields = [`url: ${text.quote(Url.toPath(node.path))}`];
1360
1375
  if (path.length > 0) urlFields.push("params: path");
1361
1376
  if (isInfinite) urlFields.push("infinite: true");
1362
1377
  const result = [`{ ${urlFields.join(", ")} }`];
@@ -1512,29 +1527,28 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, t
1512
1527
  `
1513
1528
  });
1514
1529
  }
1515
- // src/generators/infiniteQueryGenerator.tsx
1530
+ // src/templates/infiniteQuery.tsx
1531
+ function matchesInfiniteQuery(node, ctx) {
1532
+ if (!isOperation(node)) return false;
1533
+ const { query, mutation, infinite, hooks } = ctx.options;
1534
+ const { isQuery, isMutation } = classifyOperation(node, {
1535
+ query,
1536
+ mutation
1537
+ });
1538
+ const infiniteOptions = infinite && typeof infinite === "object" ? infinite : null;
1539
+ if (!isQuery || isMutation || !infiniteOptions || !hooks) return false;
1540
+ return matchesInfinite(node, infiniteOptions);
1541
+ }
1516
1542
  /**
1517
- * Built-in generator for `useInfiniteQuery` composables. Enabled when
1543
+ * Built-in template for `useInfiniteQuery` composables. Enabled when
1518
1544
  * `pluginVueQuery({ infinite: { ... }, hooks: true })`. Emits one
1519
1545
  * `useFooInfiniteQuery` composable per query operation, wiring the
1520
1546
  * configured cursor path into TanStack Query's cursor-based pagination.
1521
1547
  */
1522
- const infiniteQueryGenerator = defineGenerator({
1523
- name: "vue-query-infinite",
1524
- renderer: jsxRenderer,
1525
- match(node, ctx) {
1526
- const operationNode = node;
1527
- if (!isOperation(operationNode)) return false;
1528
- const { query, mutation, infinite, hooks } = ctx.options;
1529
- const { isQuery, isMutation } = classifyOperation(operationNode, {
1530
- query,
1531
- mutation
1532
- });
1533
- const infiniteOptions = infinite && typeof infinite === "object" ? infinite : null;
1534
- if (!isQuery || isMutation || !infiniteOptions || !hooks) return false;
1535
- return matchesInfinite(operationNode, infiniteOptions);
1536
- },
1537
- operation(node, ctx) {
1548
+ const infiniteQueryOperation = defineTemplate({
1549
+ kind: node.kinds.operation,
1550
+ render(node, ctx) {
1551
+ if (!matchesInfiniteQuery(node, ctx)) return null;
1538
1552
  if (!isOperation(node)) return null;
1539
1553
  const { query, infinite, client } = ctx.options;
1540
1554
  const infiniteOptions = infinite && typeof infinite === "object" ? infinite : null;
@@ -1565,14 +1579,16 @@ const infiniteQueryGenerator = defineGenerator({
1565
1579
  const { tsResolver } = hook;
1566
1580
  return /* @__PURE__ */ jsxs(HookFile, {
1567
1581
  hook,
1568
- imports: /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(File.Import, {
1569
- name: ["toValue"],
1582
+ imports: /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(File.Import, {
1583
+ names: [{
1584
+ name: "toValue",
1585
+ space: "value"
1586
+ }, {
1587
+ name: "MaybeRefOrGetter",
1588
+ space: "type"
1589
+ }],
1570
1590
  path: "vue"
1571
- }), /* @__PURE__ */ jsx(File.Import, {
1572
- name: ["MaybeRefOrGetter"],
1573
- path: "vue",
1574
- isTypeOnly: true
1575
- })] }),
1591
+ }) }),
1576
1592
  children: [
1577
1593
  /* @__PURE__ */ jsx(QueryKey, {
1578
1594
  name: queryKeyName,
@@ -1585,12 +1601,13 @@ const infiniteQueryGenerator = defineGenerator({
1585
1601
  exportType: true
1586
1602
  }),
1587
1603
  /* @__PURE__ */ jsx(File.Import, {
1588
- name: ["InfiniteData"],
1589
- isTypeOnly: true,
1590
- path: importPath
1591
- }),
1592
- /* @__PURE__ */ jsx(File.Import, {
1593
- name: ["infiniteQueryOptions"],
1604
+ names: [{
1605
+ name: "infiniteQueryOptions",
1606
+ space: "value"
1607
+ }, {
1608
+ name: "InfiniteData",
1609
+ space: "type"
1610
+ }],
1594
1611
  path: importPath
1595
1612
  }),
1596
1613
  /* @__PURE__ */ jsx(InfiniteQueryOptions, {
@@ -1615,18 +1632,29 @@ const infiniteQueryGenerator = defineGenerator({
1615
1632
  unwrapName: (name) => `toValue(${name})`
1616
1633
  }),
1617
1634
  /* @__PURE__ */ jsx(File.Import, {
1618
- name: ["useInfiniteQuery"],
1619
- path: importPath
1620
- }),
1621
- /* @__PURE__ */ jsx(File.Import, {
1622
- name: [
1623
- "QueryKey",
1624
- "QueryClient",
1625
- "UseInfiniteQueryOptions",
1626
- "UseInfiniteQueryReturnType"
1635
+ names: [
1636
+ {
1637
+ name: "useInfiniteQuery",
1638
+ space: "value"
1639
+ },
1640
+ {
1641
+ name: "QueryKey",
1642
+ space: "type"
1643
+ },
1644
+ {
1645
+ name: "QueryClient",
1646
+ space: "type"
1647
+ },
1648
+ {
1649
+ name: "UseInfiniteQueryOptions",
1650
+ space: "type"
1651
+ },
1652
+ {
1653
+ name: "UseInfiniteQueryReturnType",
1654
+ space: "type"
1655
+ }
1627
1656
  ],
1628
- path: importPath,
1629
- isTypeOnly: true
1657
+ path: importPath
1630
1658
  }),
1631
1659
  /* @__PURE__ */ jsx(Query, {
1632
1660
  name: queryName,
@@ -1721,16 +1749,15 @@ function Mutation({ name, clientName, node, tsResolver, mutationKeyName, clientR
1721
1749
  `
1722
1750
  });
1723
1751
  }
1724
- // src/generators/mutationGenerator.tsx
1752
+ // src/templates/mutation.tsx
1725
1753
  /**
1726
- * Built-in generator for `useMutation` composables. Emits one
1754
+ * Built-in template for `useMutation` composables. Emits one
1727
1755
  * `useFooMutation` composable per POST/PUT/DELETE operation (configurable
1728
1756
  * via `mutation.methods`) plus the matching `fooMutationKey` helper.
1729
1757
  */
1730
- const mutationGenerator = defineGenerator({
1731
- name: "vue-query-mutation",
1732
- renderer: jsxRenderer,
1733
- operation(node, ctx) {
1758
+ const mutationOperation = defineTemplate({
1759
+ kind: node.kinds.operation,
1760
+ render(node, ctx) {
1734
1761
  if (!isOperation(node)) return null;
1735
1762
  const { query, mutation, client, hooks } = ctx.options;
1736
1763
  const { isMutation } = classifyOperation(node, {
@@ -1755,52 +1782,58 @@ const mutationGenerator = defineGenerator({
1755
1782
  const hasRequestGroups = requestGroupOrder.some((key) => groups[key]);
1756
1783
  return /* @__PURE__ */ jsxs(HookFile, {
1757
1784
  hook,
1758
- imports: /* @__PURE__ */ jsxs(Fragment, { children: [hasRequestGroups && /* @__PURE__ */ jsx(File.Import, {
1759
- name: ["toValue"],
1785
+ imports: /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(File.Import, {
1786
+ names: [...hasRequestGroups ? [{
1787
+ name: "toValue",
1788
+ space: "value"
1789
+ }] : [], {
1790
+ name: "MaybeRefOrGetter",
1791
+ space: "type"
1792
+ }],
1760
1793
  path: "vue"
1761
- }), /* @__PURE__ */ jsx(File.Import, {
1762
- name: ["MaybeRefOrGetter"],
1763
- path: "vue",
1764
- isTypeOnly: true
1765
- })] }),
1794
+ }) }),
1766
1795
  children: [/* @__PURE__ */ jsx(MutationKey, {
1767
1796
  name: mutationKeyName,
1768
1797
  node,
1769
1798
  transformer: ctx.options.mutationKey
1770
- }), mutation && hooks && /* @__PURE__ */ jsxs(Fragment, { children: [
1771
- /* @__PURE__ */ jsx(File.Import, {
1772
- name: ["useMutation"],
1773
- path: importPath
1774
- }),
1775
- /* @__PURE__ */ jsx(File.Import, {
1776
- name: ["MutationObserverOptions", "QueryClient"],
1777
- path: importPath,
1778
- isTypeOnly: true
1779
- }),
1780
- /* @__PURE__ */ jsx(Mutation, {
1781
- name: mutationHookName,
1782
- clientName: contractOp.name,
1783
- node,
1784
- tsResolver: hook.tsResolver,
1785
- mutationKeyName,
1786
- clientReturnType: contractOp.returnType,
1787
- returnType: hook.returnType,
1788
- typedHeaders: hook.contractOp.typedHeaders
1789
- })
1790
- ] })]
1799
+ }), mutation && hooks && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(File.Import, {
1800
+ names: [
1801
+ {
1802
+ name: "useMutation",
1803
+ space: "value"
1804
+ },
1805
+ {
1806
+ name: "MutationObserverOptions",
1807
+ space: "type"
1808
+ },
1809
+ {
1810
+ name: "QueryClient",
1811
+ space: "type"
1812
+ }
1813
+ ],
1814
+ path: importPath
1815
+ }), /* @__PURE__ */ jsx(Mutation, {
1816
+ name: mutationHookName,
1817
+ clientName: contractOp.name,
1818
+ node,
1819
+ tsResolver: hook.tsResolver,
1820
+ mutationKeyName,
1821
+ clientReturnType: contractOp.returnType,
1822
+ returnType: hook.returnType,
1823
+ typedHeaders: hook.contractOp.typedHeaders
1824
+ })] })]
1791
1825
  });
1792
1826
  }
1793
1827
  });
1794
- // src/generators/queryGenerator.tsx
1828
+ // src/templates/query.tsx
1795
1829
  /**
1796
- * Built-in generator for `useQuery` composables. Emits one `useFooQuery`
1830
+ * Built-in template for `useQuery` composables. Emits one `useFooQuery`
1797
1831
  * composable per GET and QUERY operation (configurable via `query.methods`) plus the
1798
1832
  * matching `fooQueryKey` / `fooQueryOptions` helpers.
1799
1833
  */
1800
- const queryGenerator = defineGenerator({
1801
- name: "vue-query",
1802
- renderer: jsxRenderer,
1803
- operation(node, ctx) {
1834
+ const queryOperation = defineTemplate({
1835
+ kind: node.kinds.operation,
1836
+ render(node, ctx) {
1804
1837
  if (!isOperation(node)) return null;
1805
1838
  const { query, mutation, client, hooks } = ctx.options;
1806
1839
  const { isQuery, isMutation } = classifyOperation(node, {
@@ -1826,14 +1859,16 @@ const queryGenerator = defineGenerator({
1826
1859
  const { tsResolver } = hook;
1827
1860
  return /* @__PURE__ */ jsxs(HookFile, {
1828
1861
  hook,
1829
- imports: /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(File.Import, {
1830
- name: ["toValue"],
1862
+ imports: /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(File.Import, {
1863
+ names: [{
1864
+ name: "toValue",
1865
+ space: "value"
1866
+ }, {
1867
+ name: "MaybeRefOrGetter",
1868
+ space: "type"
1869
+ }],
1831
1870
  path: "vue"
1832
- }), /* @__PURE__ */ jsx(File.Import, {
1833
- name: ["MaybeRefOrGetter"],
1834
- path: "vue",
1835
- isTypeOnly: true
1836
- })] }),
1871
+ }) }),
1837
1872
  children: [
1838
1873
  /* @__PURE__ */ jsx(QueryKey, {
1839
1874
  name: queryKeyName,
@@ -1846,7 +1881,10 @@ const queryGenerator = defineGenerator({
1846
1881
  exportType: true
1847
1882
  }),
1848
1883
  /* @__PURE__ */ jsx(File.Import, {
1849
- name: ["queryOptions"],
1884
+ names: [{
1885
+ name: "queryOptions",
1886
+ space: "value"
1887
+ }],
1850
1888
  path: importPath
1851
1889
  }),
1852
1890
  /* @__PURE__ */ jsx(QueryOptions, {
@@ -1859,32 +1897,40 @@ const queryGenerator = defineGenerator({
1859
1897
  returnType: hook.returnType,
1860
1898
  typedHeaders: hook.contractOp.typedHeaders
1861
1899
  }),
1862
- query && hooks && /* @__PURE__ */ jsxs(Fragment, { children: [
1863
- /* @__PURE__ */ jsx(File.Import, {
1864
- name: ["useQuery"],
1865
- path: importPath
1866
- }),
1867
- /* @__PURE__ */ jsx(File.Import, {
1868
- name: [
1869
- "QueryKey",
1870
- "QueryClient",
1871
- "UseQueryOptions",
1872
- "UseQueryReturnType"
1873
- ],
1874
- path: importPath,
1875
- isTypeOnly: true
1876
- }),
1877
- /* @__PURE__ */ jsx(Query, {
1878
- name: queryName,
1879
- queryOptionsName,
1880
- queryKeyName,
1881
- queryKeyTypeName,
1882
- node,
1883
- tsResolver,
1884
- returnType: hook.returnType,
1885
- typedHeaders: hook.contractOp.typedHeaders
1886
- })
1887
- ] })
1900
+ query && hooks && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(File.Import, {
1901
+ names: [
1902
+ {
1903
+ name: "useQuery",
1904
+ space: "value"
1905
+ },
1906
+ {
1907
+ name: "QueryKey",
1908
+ space: "type"
1909
+ },
1910
+ {
1911
+ name: "QueryClient",
1912
+ space: "type"
1913
+ },
1914
+ {
1915
+ name: "UseQueryOptions",
1916
+ space: "type"
1917
+ },
1918
+ {
1919
+ name: "UseQueryReturnType",
1920
+ space: "type"
1921
+ }
1922
+ ],
1923
+ path: importPath
1924
+ }), /* @__PURE__ */ jsx(Query, {
1925
+ name: queryName,
1926
+ queryOptionsName,
1927
+ queryKeyName,
1928
+ queryKeyTypeName,
1929
+ node,
1930
+ tsResolver,
1931
+ returnType: hook.returnType,
1932
+ typedHeaders: hook.contractOp.typedHeaders
1933
+ })] })
1888
1934
  ]
1889
1935
  });
1890
1936
  }
@@ -1960,8 +2006,10 @@ const pluginVueQuery = defineExtension({
1960
2006
  }, group, exclude = [], include, override = [], infinite = false, mutation = {}, query = {}, mutationKey = mutationKeyTransformer, queryKey = queryKeyTransformer, hooks = false, client, returnType = "data", resolver: userResolver, macros: userMacros } = options;
1961
2007
  const resolver = userResolver ? Resolver.merge(resolverVueQuery, ...[userResolver].flat()) : resolverVueQuery;
1962
2008
  setResolver(resolver);
1963
- if (userMacros?.length) setMacros(userMacros);
1964
- addGenerator(queryGenerator, infiniteQueryGenerator, mutationGenerator);
2009
+ addMacro(...userMacros ?? []);
2010
+ addTemplate(queryOperation);
2011
+ addTemplate(infiniteQueryOperation);
2012
+ addTemplate(mutationOperation);
1965
2013
  return {
1966
2014
  output,
1967
2015
  client: resolveContractClient({