@kubb/plugin-vue-query 5.13.0 → 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";
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
  ]
@@ -1512,29 +1532,28 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, t
1512
1532
  `
1513
1533
  });
1514
1534
  }
1515
- // 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
+ }
1516
1547
  /**
1517
- * Built-in generator for `useInfiniteQuery` composables. Enabled when
1548
+ * Built-in template for `useInfiniteQuery` composables. Enabled when
1518
1549
  * `pluginVueQuery({ infinite: { ... }, hooks: true })`. Emits one
1519
1550
  * `useFooInfiniteQuery` composable per query operation, wiring the
1520
1551
  * configured cursor path into TanStack Query's cursor-based pagination.
1521
1552
  */
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) {
1553
+ const infiniteQueryOperation = defineTemplate({
1554
+ kind: node.kinds.operation,
1555
+ render(node, ctx) {
1556
+ if (!matchesInfiniteQuery(node, ctx)) return null;
1538
1557
  if (!isOperation(node)) return null;
1539
1558
  const { query, infinite, client } = ctx.options;
1540
1559
  const infiniteOptions = infinite && typeof infinite === "object" ? infinite : null;
@@ -1565,14 +1584,16 @@ const infiniteQueryGenerator = defineGenerator({
1565
1584
  const { tsResolver } = hook;
1566
1585
  return /* @__PURE__ */ jsxs(HookFile, {
1567
1586
  hook,
1568
- imports: /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(File.Import, {
1569
- 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
+ }],
1570
1595
  path: "vue"
1571
- }), /* @__PURE__ */ jsx(File.Import, {
1572
- name: ["MaybeRefOrGetter"],
1573
- path: "vue",
1574
- isTypeOnly: true
1575
- })] }),
1596
+ }) }),
1576
1597
  children: [
1577
1598
  /* @__PURE__ */ jsx(QueryKey, {
1578
1599
  name: queryKeyName,
@@ -1585,12 +1606,13 @@ const infiniteQueryGenerator = defineGenerator({
1585
1606
  exportType: true
1586
1607
  }),
1587
1608
  /* @__PURE__ */ jsx(File.Import, {
1588
- name: ["InfiniteData"],
1589
- isTypeOnly: true,
1590
- path: importPath
1591
- }),
1592
- /* @__PURE__ */ jsx(File.Import, {
1593
- name: ["infiniteQueryOptions"],
1609
+ names: [{
1610
+ name: "infiniteQueryOptions",
1611
+ space: "value"
1612
+ }, {
1613
+ name: "InfiniteData",
1614
+ space: "type"
1615
+ }],
1594
1616
  path: importPath
1595
1617
  }),
1596
1618
  /* @__PURE__ */ jsx(InfiniteQueryOptions, {
@@ -1615,18 +1637,29 @@ const infiniteQueryGenerator = defineGenerator({
1615
1637
  unwrapName: (name) => `toValue(${name})`
1616
1638
  }),
1617
1639
  /* @__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"
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
+ }
1627
1661
  ],
1628
- path: importPath,
1629
- isTypeOnly: true
1662
+ path: importPath
1630
1663
  }),
1631
1664
  /* @__PURE__ */ jsx(Query, {
1632
1665
  name: queryName,
@@ -1721,16 +1754,15 @@ function Mutation({ name, clientName, node, tsResolver, mutationKeyName, clientR
1721
1754
  `
1722
1755
  });
1723
1756
  }
1724
- // src/generators/mutationGenerator.tsx
1757
+ // src/templates/mutation.tsx
1725
1758
  /**
1726
- * Built-in generator for `useMutation` composables. Emits one
1759
+ * Built-in template for `useMutation` composables. Emits one
1727
1760
  * `useFooMutation` composable per POST/PUT/DELETE operation (configurable
1728
1761
  * via `mutation.methods`) plus the matching `fooMutationKey` helper.
1729
1762
  */
1730
- const mutationGenerator = defineGenerator({
1731
- name: "vue-query-mutation",
1732
- renderer: jsxRenderer,
1733
- operation(node, ctx) {
1763
+ const mutationOperation = defineTemplate({
1764
+ kind: node.kinds.operation,
1765
+ render(node, ctx) {
1734
1766
  if (!isOperation(node)) return null;
1735
1767
  const { query, mutation, client, hooks } = ctx.options;
1736
1768
  const { isMutation } = classifyOperation(node, {
@@ -1755,52 +1787,58 @@ const mutationGenerator = defineGenerator({
1755
1787
  const hasRequestGroups = requestGroupOrder.some((key) => groups[key]);
1756
1788
  return /* @__PURE__ */ jsxs(HookFile, {
1757
1789
  hook,
1758
- imports: /* @__PURE__ */ jsxs(Fragment, { children: [hasRequestGroups && /* @__PURE__ */ jsx(File.Import, {
1759
- 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
+ }],
1760
1798
  path: "vue"
1761
- }), /* @__PURE__ */ jsx(File.Import, {
1762
- name: ["MaybeRefOrGetter"],
1763
- path: "vue",
1764
- isTypeOnly: true
1765
- })] }),
1799
+ }) }),
1766
1800
  children: [/* @__PURE__ */ jsx(MutationKey, {
1767
1801
  name: mutationKeyName,
1768
1802
  node,
1769
1803
  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
- ] })]
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
+ })] })]
1791
1830
  });
1792
1831
  }
1793
1832
  });
1794
- // src/generators/queryGenerator.tsx
1833
+ // src/templates/query.tsx
1795
1834
  /**
1796
- * Built-in generator for `useQuery` composables. Emits one `useFooQuery`
1835
+ * Built-in template for `useQuery` composables. Emits one `useFooQuery`
1797
1836
  * composable per GET and QUERY operation (configurable via `query.methods`) plus the
1798
1837
  * matching `fooQueryKey` / `fooQueryOptions` helpers.
1799
1838
  */
1800
- const queryGenerator = defineGenerator({
1801
- name: "vue-query",
1802
- renderer: jsxRenderer,
1803
- operation(node, ctx) {
1839
+ const queryOperation = defineTemplate({
1840
+ kind: node.kinds.operation,
1841
+ render(node, ctx) {
1804
1842
  if (!isOperation(node)) return null;
1805
1843
  const { query, mutation, client, hooks } = ctx.options;
1806
1844
  const { isQuery, isMutation } = classifyOperation(node, {
@@ -1826,14 +1864,16 @@ const queryGenerator = defineGenerator({
1826
1864
  const { tsResolver } = hook;
1827
1865
  return /* @__PURE__ */ jsxs(HookFile, {
1828
1866
  hook,
1829
- imports: /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(File.Import, {
1830
- 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
+ }],
1831
1875
  path: "vue"
1832
- }), /* @__PURE__ */ jsx(File.Import, {
1833
- name: ["MaybeRefOrGetter"],
1834
- path: "vue",
1835
- isTypeOnly: true
1836
- })] }),
1876
+ }) }),
1837
1877
  children: [
1838
1878
  /* @__PURE__ */ jsx(QueryKey, {
1839
1879
  name: queryKeyName,
@@ -1846,7 +1886,10 @@ const queryGenerator = defineGenerator({
1846
1886
  exportType: true
1847
1887
  }),
1848
1888
  /* @__PURE__ */ jsx(File.Import, {
1849
- name: ["queryOptions"],
1889
+ names: [{
1890
+ name: "queryOptions",
1891
+ space: "value"
1892
+ }],
1850
1893
  path: importPath
1851
1894
  }),
1852
1895
  /* @__PURE__ */ jsx(QueryOptions, {
@@ -1859,32 +1902,40 @@ const queryGenerator = defineGenerator({
1859
1902
  returnType: hook.returnType,
1860
1903
  typedHeaders: hook.contractOp.typedHeaders
1861
1904
  }),
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
- ] })
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
+ })] })
1888
1939
  ]
1889
1940
  });
1890
1941
  }
@@ -1960,8 +2011,10 @@ const pluginVueQuery = defineExtension({
1960
2011
  }, group, exclude = [], include, override = [], infinite = false, mutation = {}, query = {}, mutationKey = mutationKeyTransformer, queryKey = queryKeyTransformer, hooks = false, client, returnType = "data", resolver: userResolver, macros: userMacros } = options;
1961
2012
  const resolver = userResolver ? Resolver.merge(resolverVueQuery, ...[userResolver].flat()) : resolverVueQuery;
1962
2013
  setResolver(resolver);
1963
- if (userMacros?.length) setMacros(userMacros);
1964
- addGenerator(queryGenerator, infiniteQueryGenerator, mutationGenerator);
2014
+ addMacro(...userMacros ?? []);
2015
+ addTemplate(queryOperation);
2016
+ addTemplate(infiniteQueryOperation);
2017
+ addTemplate(mutationOperation);
1965
2018
  return {
1966
2019
  output,
1967
2020
  client: resolveContractClient({