@kubb/plugin-vue-query 5.10.0-canary.20261109T201601 → 5.10.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,9 +1,292 @@
1
- import { Diagnostics, Resolver, Url, addGenerator, ast, camelCase, createResolver, defineExtension, defineGenerator, setMacros, setResolver, useConfig } from "@kubb/kit";
2
- import path from "node:path";
1
+ import { Diagnostics, Resolver, Url, addGenerator, ast, casing, createResolver, defineExtension, defineGenerator, setMacros, setResolver, useConfig } from "@kubb/kit";
3
2
  import { createFunctionParameter, createFunctionParameters, createObjectBindingPattern, createTypeLiteral, functionPrinter, pluginTsName } from "@kubb/plugin-ts";
4
- import { pluginZodName } from "@kubb/plugin-zod";
3
+ import path from "node:path";
5
4
  import { File, Function, Type, jsxRenderer } from "@kubb/renderer-jsx";
6
5
  import { Fragment, jsx, jsxs } from "@kubb/renderer-jsx/jsx-runtime";
6
+ // kubb-extension.json
7
+ var compatibility = {
8
+ "kubb": ">=5.18.4",
9
+ "node": ">=22.22"
10
+ };
11
+ // package.json
12
+ var version = "5.10.1";
13
+ // ../../internals/client/src/resolveClient.ts
14
+ /**
15
+ * Resolves which client plugin a consumer (react-query, vue-query, swr, mcp) should call for an
16
+ * operation, shared so the selection rules and diagnostics stay in one place.
17
+ *
18
+ * Every client runtime lives in a dedicated client plugin, so a consumer always calls a registered
19
+ * contract client plugin (plugin-fetch, plugin-axios, or plugin-client) and never emits its own
20
+ * inline client:
21
+ *
22
+ * - `contract` — a registered contract client plugin owns the `<op>` functions and the consumer
23
+ * imports and calls them.
24
+ * - `error` — no client plugin is registered, several are registered without a selector, the
25
+ * requested one is missing, or `client` is not a known selector.
26
+ *
27
+ * The `client` string selects explicitly (`'fetch'` / `'axios'` / `'client'`); when it is unset a
28
+ * lone registered contract client plugin is picked up automatically.
29
+ */
30
+ const pluginFetchName = "plugin-fetch";
31
+ const pluginAxiosName = "plugin-axios";
32
+ const pluginClientName = "plugin-client";
33
+ const selectorToPlugin = {
34
+ fetch: pluginFetchName,
35
+ axios: pluginAxiosName,
36
+ client: pluginClientName
37
+ };
38
+ const contractPlugins = [
39
+ pluginFetchName,
40
+ pluginAxiosName,
41
+ pluginClientName
42
+ ];
43
+ /**
44
+ * Applies the `client` resolution rules. See the module comment for the strategy shape.
45
+ *
46
+ * @example
47
+ * ```ts
48
+ * resolveClient({ client: 'fetch', pluginNames: ['plugin-ts', 'plugin-fetch'] })
49
+ * // { kind: 'contract', pluginName: 'plugin-fetch' }
50
+ * ```
51
+ *
52
+ * @example
53
+ * ```ts
54
+ * resolveClient({ client: undefined, pluginNames: ['plugin-ts'] })
55
+ * // { kind: 'error', code: 'KUBB_MISSING_DEPENDENCY', message: 'No client plugin is registered.', help: 'Add …' }
56
+ * ```
57
+ */
58
+ function resolveClient(options) {
59
+ const { client, pluginNames } = options;
60
+ const has = (name) => pluginNames.includes(name);
61
+ if (client === "fetch" || client === "axios" || client === "client") {
62
+ const pluginName = selectorToPlugin[client];
63
+ if (!has(pluginName)) return {
64
+ kind: "error",
65
+ code: Diagnostics.code.missingDependency,
66
+ message: `\`client: '${client}'\` is set but \`@kubb/plugin-${client}\` is not registered in \`plugins\`.`,
67
+ help: `Add \`@kubb/plugin-${client}\` to \`plugins\`, or drop \`client\` to use a different client plugin.`
68
+ };
69
+ return {
70
+ kind: "contract",
71
+ pluginName
72
+ };
73
+ }
74
+ if (client !== void 0) return {
75
+ kind: "error",
76
+ code: Diagnostics.code.invalidPluginOptions,
77
+ message: `Option \`client\` is ${typeof client === "string" ? `'${client}'` : String(client)}, but it must be one of 'fetch', 'axios', 'client'.`,
78
+ help: "Set `client` to one of those values, or drop it to use the registered client plugin."
79
+ };
80
+ const registered = contractPlugins.filter(has);
81
+ if (registered.length === 1) return {
82
+ kind: "contract",
83
+ pluginName: registered[0]
84
+ };
85
+ if (registered.length > 1) return {
86
+ kind: "error",
87
+ code: Diagnostics.code.invalidPluginOptions,
88
+ message: `Multiple client plugins are registered (${registered.map((name) => `\`@kubb/${name}\``).join(", ")}) and \`client\` is not set.`,
89
+ help: "Set `client: 'fetch' | 'axios' | 'client'` to choose which client the hooks call, or register a single client plugin."
90
+ };
91
+ return {
92
+ kind: "error",
93
+ code: Diagnostics.code.missingDependency,
94
+ message: "No client plugin is registered.",
95
+ help: "Add `@kubb/plugin-fetch`, `@kubb/plugin-axios`, or `@kubb/plugin-client` to `plugins` so the generated code has an HTTP client to call."
96
+ };
97
+ }
98
+ /**
99
+ * Resolves the contract client during a consumer plugin's setup hook.
100
+ * It extracts the plugin names from the raw `plugins` config and applies {@link resolveClient}.
101
+ * On a misconfiguration it throws a config diagnostic tagged with `plugin`, so every consumer
102
+ * fails fast with the same message.
103
+ */
104
+ function resolveContractClient(options) {
105
+ const { plugin, client, plugins = [] } = options;
106
+ const resolved = resolveClient({
107
+ client,
108
+ pluginNames: plugins.map((plugin) => plugin.name).filter((name) => Boolean(name))
109
+ });
110
+ if (resolved.kind === "error") {
111
+ const { code, message, help } = resolved;
112
+ throw new Diagnostics.Error({
113
+ code,
114
+ severity: "error",
115
+ message,
116
+ help,
117
+ location: { kind: "config" },
118
+ plugin
119
+ });
120
+ }
121
+ return resolved;
122
+ }
123
+ // ../../internals/utils/src/reserved.ts
124
+ /**
125
+ * JavaScript and Java reserved words.
126
+ * @link https://github.com/jonschlinkert/reserved/blob/master/index.js
127
+ */
128
+ const reservedWords = /* @__PURE__ */ new Set([
129
+ "abstract",
130
+ "arguments",
131
+ "await",
132
+ "boolean",
133
+ "break",
134
+ "byte",
135
+ "case",
136
+ "catch",
137
+ "char",
138
+ "class",
139
+ "const",
140
+ "continue",
141
+ "debugger",
142
+ "default",
143
+ "delete",
144
+ "do",
145
+ "double",
146
+ "else",
147
+ "enum",
148
+ "eval",
149
+ "export",
150
+ "extends",
151
+ "false",
152
+ "final",
153
+ "finally",
154
+ "float",
155
+ "for",
156
+ "function",
157
+ "goto",
158
+ "if",
159
+ "implements",
160
+ "import",
161
+ "in",
162
+ "instanceof",
163
+ "int",
164
+ "interface",
165
+ "let",
166
+ "long",
167
+ "native",
168
+ "new",
169
+ "null",
170
+ "package",
171
+ "private",
172
+ "protected",
173
+ "public",
174
+ "return",
175
+ "short",
176
+ "static",
177
+ "super",
178
+ "switch",
179
+ "synchronized",
180
+ "this",
181
+ "throw",
182
+ "throws",
183
+ "transient",
184
+ "true",
185
+ "try",
186
+ "typeof",
187
+ "var",
188
+ "void",
189
+ "volatile",
190
+ "while",
191
+ "with",
192
+ "yield",
193
+ "Array",
194
+ "Date",
195
+ "hasOwnProperty",
196
+ "Infinity",
197
+ "isFinite",
198
+ "isNaN",
199
+ "isPrototypeOf",
200
+ "length",
201
+ "Math",
202
+ "name",
203
+ "NaN",
204
+ "Number",
205
+ "Object",
206
+ "prototype",
207
+ "String",
208
+ "toString",
209
+ "undefined",
210
+ "valueOf"
211
+ ]);
212
+ /**
213
+ * Returns `true` when `name` is a syntactically valid JavaScript variable name.
214
+ *
215
+ * @example
216
+ * ```ts
217
+ * isValidVarName('status') // true
218
+ * isValidVarName('class') // false (reserved word)
219
+ * isValidVarName('42foo') // false (starts with digit)
220
+ * ```
221
+ */
222
+ function isValidVarName(name) {
223
+ if (!name || reservedWords.has(name)) return false;
224
+ return isIdentifier(name);
225
+ }
226
+ /**
227
+ * Returns `name` when it's a syntactically valid JavaScript variable name,
228
+ * otherwise prefixes it with `_` so the result is a valid identifier.
229
+ *
230
+ * Useful for sanitizing OpenAPI schema names or operation IDs that start with
231
+ * a digit (e.g. `409`, `504AccountCancel`) before using them as exported
232
+ * variable, type, or function names.
233
+ *
234
+ * @example
235
+ * ```ts
236
+ * ensureValidVarName('409') // '_409'
237
+ * ensureValidVarName('504AccountCancel') // '_504AccountCancel'
238
+ * ensureValidVarName('Pet') // 'Pet'
239
+ * ensureValidVarName('class') // '_class'
240
+ * ```
241
+ */
242
+ function ensureValidVarName(name) {
243
+ if (!name || isValidVarName(name)) return name;
244
+ return `_${name}`;
245
+ }
246
+ /**
247
+ * Returns `true` when `name` is syntactically a valid identifier, ignoring reserved words.
248
+ *
249
+ * Reserved words and globals (`class`, `name`, `Date`, …) are valid as bare object-literal keys
250
+ * even though they are not valid variable names, so use this (not {@link isValidVarName}) when
251
+ * deciding whether an object key needs quoting.
252
+ *
253
+ * @example
254
+ * ```ts
255
+ * isIdentifier('name') // true
256
+ * isIdentifier('x-total')// false
257
+ * ```
258
+ */
259
+ function isIdentifier(name) {
260
+ return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);
261
+ }
262
+ // ../../internals/utils/src/strings.ts
263
+ /**
264
+ * Renders a dotted path or string array as an optional-chaining accessor expression rooted at
265
+ * `accessor`. Returns `null` for an empty path.
266
+ *
267
+ * @example
268
+ * ```ts
269
+ * getNestedAccessor('pagination.next.id', 'lastPage')
270
+ * // "lastPage?.['pagination']?.['next']?.['id']"
271
+ * ```
272
+ */
273
+ function getNestedAccessor(param, accessor) {
274
+ const parts = Array.isArray(param) ? param : param.split(".");
275
+ if (parts.length === 0 || parts.length === 1 && parts[0] === "") return null;
276
+ return `${accessor}?.['${`${parts.join("']?.['")}']`}`;
277
+ }
278
+ /**
279
+ * Escapes an `@` at the start of a line, so a multi-line description can't start a new JSDoc tag.
280
+ * Editors render `\@` as `@` in hovers.
281
+ *
282
+ * @example
283
+ * ```ts
284
+ * jsDocEscape('intro\n@example value') // 'intro\n\\@example value'
285
+ * ```
286
+ */
287
+ function jsDocEscape(input) {
288
+ return `${input}`.replace(/^(\s*)@/gm, "$1\\@");
289
+ }
7
290
  // ../../internals/shared/src/operation.ts
8
291
  /**
9
292
  * Builds the `ResolverFileParams` every operation generator passes to
@@ -25,29 +308,55 @@ function operationFileEntry(node, name, extname = ".ts") {
25
308
  };
26
309
  }
27
310
  /**
28
- * Resolves a dependency plugin's generated file for `node.operationId`, cached in `memo` (the
29
- * build's `ctx.memo`) under the resolver's own plugin name and the operation. Several dependents reading the
30
- * same dependency for the same operation in one pass (a query plugin's several hook generators, the
31
- * MCP handler, ...) share one computed name and path instead of each calling `resolver.file` again.
311
+ * Resolves the file a schema-emitting plugin (`plugin-ts`, `plugin-zod`, `plugin-faker`) writes
312
+ * `node` to, cached in `ctx.memo` under the resolver's plugin name and the
313
+ * operation. The plugin itself and every plugin that imports from it call this, so they all get
314
+ * the same path.
315
+ *
316
+ * When that path matches the file of a component schema in `ctx.driver.inputNode`, ignoring case, the file name
317
+ * gets an `Operation` suffix: operation `point` goes to `PointOperation.ts` next to schema `Point.ts`.
318
+ * Otherwise the two merge into one file, or overwrite each other on a case-insensitive file system.
319
+ * Only the file name changes. The declarations keep their names.
32
320
  *
33
- * @example Cache `plugin-ts`'s file for the current operation
321
+ * @example Resolve `plugin-ts`'s file for the current operation
34
322
  * ```ts
35
- * const fileTs = resolveDependencyOperationFile({ memo: ctx.memo, node, resolver: tsResolver, root, output })
323
+ * const fileTs = resolveOperationFile({ ctx, node, resolver: tsResolver, root, output })
36
324
  * ```
37
325
  */
38
- function resolveDependencyOperationFile(options) {
39
- const { memo, node, resolver, root, output, group } = options;
40
- return memo(`${resolver.pluginName}:operationFile:${node.operationId}`, () => resolver.file({
41
- ...operationFileEntry(node, node.operationId),
326
+ function resolveOperationFile(options) {
327
+ const { ctx, node, resolver, root, output } = options;
328
+ const { memo } = ctx;
329
+ const location = {
42
330
  root,
43
331
  output,
44
- group: group ?? void 0
45
- }));
332
+ group: options.group ?? void 0
333
+ };
334
+ return memo(`${resolver.pluginName}:operationFile:${node.operationId}`, () => {
335
+ const schemaPaths = memo(`${resolver.pluginName}:schemaFilePaths`, () => new Set((ctx.driver.inputNode?.schemas ?? []).flatMap((schema) => schema.name ? [resolver.file({
336
+ name: schema.name,
337
+ extname: ".ts",
338
+ ...location
339
+ }).path.toLowerCase()] : [])));
340
+ let file = resolver.file({
341
+ ...operationFileEntry(node, node.operationId),
342
+ ...location
343
+ });
344
+ for (let name = `${node.operationId}Operation`; schemaPaths.has(file.path.toLowerCase()); name += "Operation") {
345
+ const next = resolver.file({
346
+ ...operationFileEntry(node, name),
347
+ ...location
348
+ });
349
+ if (next.path === file.path) break;
350
+ file = next;
351
+ }
352
+ return file;
353
+ });
46
354
  }
47
- function getOperationLink(node, link) {
48
- if (!link) return null;
49
- if (typeof link === "function") return link(node) ?? null;
50
- return node.path ? `{@link ${Url.toPath(node.path)}}` : null;
355
+ /**
356
+ * The operation's method and path as plain text, such as `` `GET /pet/{petId}` ``. A path is not a valid `{@link}` target.
357
+ */
358
+ function getOperationRequestLine(node) {
359
+ return ast.http.isOperation(node) && node.path ? `\`${node.method.toUpperCase()} ${node.path}\`` : null;
51
360
  }
52
361
  /**
53
362
  * Derives the shared `ContentTypeInfo` shape from a list of content types, tracking whether several
@@ -71,18 +380,7 @@ function getContentTypeInfo(node) {
71
380
  * whether several are present, so the client can let a caller pick which one to accept.
72
381
  */
73
382
  function getResponseContentTypeInfo(node) {
74
- return buildContentTypeInfo(getPrimarySuccessResponse(node)?.content?.map((e) => e.contentType) ?? []);
75
- }
76
- function baseContentType(contentType) {
77
- return contentType.split(";")[0].trim().toLowerCase();
78
- }
79
- /**
80
- * Whether a content entry is a sequence of JSON values the adapter marks as a stream, such as `application/jsonl`,
81
- * `application/x-ndjson`, `application/json-seq`, or any media type with an OpenAPI 3.2 `itemSchema`.
82
- */
83
- function isJsonLines(entry) {
84
- const baseType = baseContentType(entry.contentType);
85
- return Boolean(entry.stream) && baseType !== "text/event-stream" && !baseType.startsWith("multipart/");
383
+ return buildContentTypeInfo(ast.http.responses.findPrimary(node)?.content?.map((e) => e.contentType) ?? []);
86
384
  }
87
385
  /**
88
386
  * How an operation streams its primary success response item by item, when that response declares one content type:
@@ -94,11 +392,19 @@ function isJsonLines(entry) {
94
392
  * call with its query hooks.
95
393
  */
96
394
  function getEventStream(node) {
97
- const content = getPrimarySuccessResponse(node)?.content ?? [];
395
+ const content = ast.http.responses.findPrimary(node)?.content ?? [];
98
396
  if (content.length !== 1) return null;
99
397
  const entry = content[0];
100
- if (baseContentType(entry.contentType) === "text/event-stream") return entry.stream?.shape ?? "data";
101
- return isJsonLines(entry) ? "line" : null;
398
+ const framing = getStreamFraming(entry);
399
+ if (framing === "events") return entry.stream?.shape ?? "data";
400
+ return framing === "lines" ? "line" : null;
401
+ }
402
+ /**
403
+ * How a content entry is framed as a stream: `'events'` for Server-Sent Events, `'lines'` for JSON Lines.
404
+ */
405
+ function getStreamFraming(entry) {
406
+ if (ast.mediaType.getBase(entry) === "text/event-stream") return "events";
407
+ return entry.stream && ast.mediaType.isStream(entry) ? "lines" : void 0;
102
408
  }
103
409
  /**
104
410
  * Whether an operation streams its primary success response, as Server-Sent Events or JSON Lines. The client generator uses
@@ -108,20 +414,42 @@ function isEventStream(node) {
108
414
  return getEventStream(node) !== null;
109
415
  }
110
416
  /**
417
+ * Whether a success response offers a stream media type next to other content types. The client returns that variant's
418
+ * body as a `ReadableStream`, so the stream runtime is registered and a hook's data type includes the stream.
419
+ */
420
+ function hasStreamVariant(node) {
421
+ return ast.http.responses.filterSuccess(node).some((response) => {
422
+ const variants = (response.content ?? []).filter((entry) => entry.schema);
423
+ return variants.length > 1 && variants.some((entry) => ast.mediaType.isStream(entry));
424
+ });
425
+ }
426
+ /**
111
427
  * Builds the `client?:` option type shared by the generated query hooks (`useQuery`,
112
- * `useInfiniteQuery`, `useSWR`, ...). Unlike {@link buildRequestConfigType}, it never adds a
113
- * `contentType?:` member: query hooks wrap GET operations, which carry no request body to select a
114
- * content type for. It drops the data-shape keys to stay assignable to `Options`, which omits them
115
- * from `RequestConfig`. `cookies` is a group only on an operation that declares one.
428
+ * `useInfiniteQuery`, `useSWR`, ...): `RequestConfig` minus what the
429
+ * hook fills in, which is every request group and `throwOnError`. Unlike {@link buildRequestConfigType},
430
+ * it never narrows `contentType`: query hooks wrap GET operations, which carry no request body to select
431
+ * a content type for.
116
432
  */
117
- function buildClientOptionType(node) {
118
- return `Partial<Omit<RequestConfig, 'path' | 'query' | 'body' | 'headers'${getOperationParameters(node).cookie.length > 0 ? ` | 'cookies'` : ""} | 'url'>>`;
433
+ function buildClientOptionType(options = {}) {
434
+ return `Partial<Omit<RequestConfig, ${[
435
+ ...requestGroupOrder,
436
+ "url",
437
+ ...options.omit ?? [],
438
+ "throwOnError"
439
+ ].map((key) => `'${key}'`).join(" | ")}>>`;
119
440
  }
441
+ /**
442
+ * The `client?:` option type of a mutation hook. When the operation has a request content type choice,
443
+ * the mutation variables carry `contentType`, so the config leaves it out. Otherwise the ambiguous side is
444
+ * narrowed to the operation's media types; a single-type side has nothing to pick, so it stays baked in the
445
+ * generated call.
446
+ */
120
447
  function buildRequestConfigType(node) {
448
+ if (hasRequestContentTypeChoice(node)) return buildClientOptionType({ omit: ["contentType"] });
121
449
  const request = getContentTypeInfo(node);
122
450
  const response = getResponseContentTypeInfo(node);
123
451
  const members = [request.isMultipleContentTypes ? `request?: ${request.contentTypeUnion}` : null, response.isMultipleContentTypes ? `response?: ${response.contentTypeUnion}` : null].filter(Boolean);
124
- const base = buildClientOptionType(node);
452
+ const base = buildClientOptionType();
125
453
  return members.length ? `${base} & { contentType?: { ${members.join("; ")} } }` : base;
126
454
  }
127
455
  /** The grouped request options, in the order generated signatures and calls list them. */
@@ -136,11 +464,11 @@ const requestGroupOrder = [
136
464
  * Which of the grouped request options an operation carries.
137
465
  */
138
466
  function getRequestGroups(node) {
139
- const { path, query, header, cookie } = getOperationParameters(node);
467
+ const { path, query, header, cookie } = ast.http.groupParameters(node);
140
468
  return {
141
469
  path: path.length > 0,
142
470
  query: query.length > 0,
143
- body: Boolean(node.requestBody?.content?.[0]?.schema),
471
+ body: Boolean(ast.http.requestBody.getSchema(node)),
144
472
  headers: header.length > 0,
145
473
  cookies: cookie.length > 0
146
474
  };
@@ -152,7 +480,7 @@ function getRequestGroups(node) {
152
480
  */
153
481
  function getRequestGroupOptionality(node) {
154
482
  const groups = getRequestGroups(node);
155
- const { path, query, header } = getOperationParameters(node);
483
+ const { path, query, header } = ast.http.groupParameters(node);
156
484
  const hasRequiredPath = path.some((param) => param.required);
157
485
  const hasRequiredQuery = query.some((param) => param.required);
158
486
  const hasRequiredHeader = header.some((param) => param.required);
@@ -165,104 +493,28 @@ function getRequestGroupOptionality(node) {
165
493
  };
166
494
  }
167
495
  function buildOperationComments(node, options = {}) {
168
- const { link = "pathTemplate", linkPosition = "afterDeprecated", splitLines = false } = options;
169
- const linkComment = getOperationLink(node, link);
170
- const filteredComments = (linkPosition === "beforeDeprecated" ? [
171
- node.description && `@description ${node.description}`,
172
- node.summary && `@summary ${node.summary}`,
173
- linkComment,
174
- node.deprecated && "@deprecated"
175
- ] : [
496
+ const { splitLines = false } = options;
497
+ const filteredComments = [
498
+ getOperationRequestLine(node),
176
499
  node.description && `@description ${node.description}`,
177
500
  node.summary && `@summary ${node.summary}`,
178
501
  node.deprecated && "@deprecated",
179
- linkComment
180
- ]).filter((comment) => Boolean(comment));
502
+ node.externalDocs && `@see ${jsDocEscape([node.externalDocs.url, node.externalDocs.description].filter(Boolean).join(" "))}`
503
+ ].filter((comment) => Boolean(comment));
181
504
  if (!splitLines) return filteredComments;
182
505
  return filteredComments.flatMap((text) => text.split(/\r?\n/).map((line) => line.trim())).filter((comment) => Boolean(comment));
183
506
  }
184
- const operationParameterGroupsByNode = /* @__PURE__ */ new WeakMap();
185
- /**
186
- * An OpenAPI 3.2 `querystring` parameter is the whole query string, so a form-encoded object becomes one query parameter
187
- * per property, typed and serialized like any other.
188
- * Another content type, such as JSON, stays one parameter named after it, and the runtime sends its value as the whole query string.
189
- */
190
- function spreadQuerystring(param) {
191
- const schema = param.schema.type === "ref" ? param.schema.schema : param.schema;
192
- const formEncoded = !param.contentType || param.contentType.split(";")[0].trim().toLowerCase() === "application/x-www-form-urlencoded";
193
- if (schema?.type !== "object" || !formEncoded) return [param];
194
- return schema.properties.map((property) => ast.factory.createParameter({
195
- name: property.name,
196
- in: "query",
197
- schema: property.schema,
198
- required: param.required && property.required
199
- }));
200
- }
201
- /**
202
- * Groups an operation's parameters by location (`path`/`query`/`header`/`cookie`), deduping each
203
- * group by name. Every plugin generator visiting the same `OperationNode` shares one AST instance
204
- * (see `KubbDriver`), so the result is cached per node to avoid re-filtering and re-deduping the
205
- * same parameters once per plugin.
206
- */
207
- function getOperationParameters(node) {
208
- const cached = operationParameterGroupsByNode.get(node);
209
- if (cached) return cached;
210
- const dedupe = (params) => {
211
- const seen = /* @__PURE__ */ new Set();
212
- return params.filter((param) => {
213
- if (seen.has(param.name)) return false;
214
- seen.add(param.name);
215
- return true;
216
- });
217
- };
218
- const group = (location) => dedupe(node.parameters.filter((param) => param.in === location));
219
- const groups = {
220
- path: group("path"),
221
- query: dedupe([...group("query"), ...group("querystring").flatMap(spreadQuerystring)]),
222
- header: group("header"),
223
- cookie: group("cookie")
224
- };
225
- operationParameterGroupsByNode.set(node, groups);
226
- return groups;
227
- }
228
507
  /**
229
508
  * Whether the operation declares more than one request media type with a schema, so a caller must pick one on `contentType`.
230
509
  */
231
510
  function hasRequestContentTypeChoice(node) {
232
511
  return (node.requestBody?.content ?? []).filter((entry) => entry.schema).length > 1;
233
512
  }
234
- /**
235
- * Casts a call argument to the client's parameter type; a `'plain'` client is non-generic.
236
- */
237
- function castToClientOptions(callArg, clientName, returnType = "full") {
238
- return `${callArg} as Parameters<typeof ${clientName}${returnType === "plain" ? "" : "<true>"}>[0]`;
239
- }
240
- function getStatusCodeNumber(statusCode) {
241
- const code = Number(statusCode);
242
- return Number.isNaN(code) ? null : code;
243
- }
244
- function isSuccessStatusCode(statusCode) {
245
- const code = getStatusCodeNumber(statusCode);
246
- return code !== null && code >= 200 && code < 300;
247
- }
248
- function isErrorStatusCode(statusCode) {
249
- const code = getStatusCodeNumber(statusCode);
250
- return code !== null && code >= 400;
251
- }
252
- function getSuccessResponses(responses) {
253
- return responses.filter((response) => isSuccessStatusCode(response.statusCode));
254
- }
255
- function getOperationSuccessResponses(node) {
256
- return getSuccessResponses(node.responses);
257
- }
258
- function getPrimarySuccessResponse(node) {
259
- return getOperationSuccessResponses(node)[0] ?? null;
260
- }
261
513
  function resolveErrorNames(node, resolver) {
262
- return node.responses.filter((response) => isErrorStatusCode(response.statusCode)).map((response) => resolver.response.status(node, response.statusCode));
514
+ return ast.http.responses.filterError(node).map((response) => resolver.response.status(node, response.statusCode));
263
515
  }
264
516
  function resolveSuccessNames(node, resolver) {
265
- return node.responses.filter((response) => isSuccessStatusCode(response.statusCode)).map((response) => resolver.response.status(node, response.statusCode));
517
+ return ast.http.responses.filterSuccess(node).map((response) => resolver.response.status(node, response.statusCode));
266
518
  }
267
519
  function resolveStatusCodeNames(node, resolver) {
268
520
  return node.responses.map((response) => resolver.response.status(node, response.statusCode));
@@ -274,7 +526,7 @@ function resolveStatusCodeNames(node, resolver) {
274
526
  function resolveOperationTypeNames(node, resolver, options = {}) {
275
527
  const key = `${node.operationId}\0${options.order ?? ""}\0${options.responseStatusNames ?? ""}\0${options.includeParams === false ? "noparams" : ""}\0${(options.exclude ?? []).join(",")}`;
276
528
  return resolver.memo(`operationTypeNames:${key}`, () => {
277
- const { path, query, header, cookie } = getOperationParameters(node);
529
+ const { path, query, header, cookie } = ast.http.groupParameters(node);
278
530
  const responseStatusNames = options.responseStatusNames === "error" ? resolveErrorNames(node, resolver) : options.responseStatusNames === false ? [] : resolveStatusCodeNames(node, resolver);
279
531
  const exclude = new Set(options.exclude ?? []);
280
532
  const paramNames = options.includeParams === false ? [] : [
@@ -283,7 +535,7 @@ function resolveOperationTypeNames(node, resolver, options = {}) {
283
535
  ...header.map((param) => resolver.param.headers(node, param)),
284
536
  ...cookie.map((param) => resolver.param.cookies(node, param))
285
537
  ];
286
- const bodyAndResponseNames = [node.requestBody?.content?.[0]?.schema ? resolver.response.body(node) : null, resolver.response.response(node)];
538
+ const bodyAndResponseNames = [ast.http.requestBody.getSchema(node) ? resolver.response.body(node) : null, resolver.response.response(node)];
287
539
  return (options.order === "body-response-first" ? [
288
540
  ...bodyAndResponseNames,
289
541
  ...paramNames,
@@ -295,235 +547,139 @@ function resolveOperationTypeNames(node, resolver, options = {}) {
295
547
  ]).filter((name) => Boolean(name) && !exclude.has(name));
296
548
  });
297
549
  }
298
- // ../../internals/utils/src/casing.ts
299
- /**
300
- * Uppercases only the first character of `text`, leaving the rest untouched.
301
- * Unlike `pascalCase` it never re-splits word boundaries or strips characters.
302
- *
303
- * @example
304
- * `capitalize('getPetById') // 'GetPetById'`
305
- */
306
- function capitalize(text) {
307
- return `${text.charAt(0).toUpperCase()}${text.slice(1)}`;
308
- }
309
- // ../../internals/utils/src/reserved.ts
310
- /**
311
- * JavaScript and Java reserved words.
312
- * @link https://github.com/jonschlinkert/reserved/blob/master/index.js
313
- */
314
- const reservedWords = /* @__PURE__ */ new Set([
315
- "abstract",
316
- "arguments",
317
- "await",
318
- "boolean",
319
- "break",
320
- "byte",
321
- "case",
322
- "catch",
323
- "char",
324
- "class",
325
- "const",
326
- "continue",
327
- "debugger",
328
- "default",
329
- "delete",
330
- "do",
331
- "double",
332
- "else",
333
- "enum",
334
- "eval",
335
- "export",
336
- "extends",
337
- "false",
338
- "final",
339
- "finally",
340
- "float",
341
- "for",
342
- "function",
343
- "goto",
344
- "if",
345
- "implements",
346
- "import",
347
- "in",
348
- "instanceof",
349
- "int",
350
- "interface",
351
- "let",
352
- "long",
353
- "native",
354
- "new",
355
- "null",
356
- "package",
357
- "private",
358
- "protected",
359
- "public",
360
- "return",
361
- "short",
362
- "static",
363
- "super",
364
- "switch",
365
- "synchronized",
366
- "this",
367
- "throw",
368
- "throws",
369
- "transient",
370
- "true",
371
- "try",
372
- "typeof",
373
- "var",
374
- "void",
375
- "volatile",
376
- "while",
377
- "with",
378
- "yield",
379
- "Array",
380
- "Date",
381
- "hasOwnProperty",
382
- "Infinity",
383
- "isFinite",
384
- "isNaN",
385
- "isPrototypeOf",
386
- "length",
387
- "Math",
388
- "name",
389
- "NaN",
390
- "Number",
391
- "Object",
392
- "prototype",
393
- "String",
394
- "toString",
395
- "undefined",
396
- "valueOf"
397
- ]);
550
+ // ../../internals/shared/src/resolver.ts
398
551
  /**
399
- * Returns `true` when `name` is a syntactically valid JavaScript variable name.
400
- *
401
- * @example
402
- * ```ts
403
- * isValidVarName('status') // true
404
- * isValidVarName('class') // false (reserved word)
405
- * isValidVarName('42foo') // false (starts with digit)
406
- * ```
552
+ * The shared top-level `name` of the operation plugins, computed once per operation name and build.
407
553
  */
408
- function isValidVarName(name) {
409
- if (!name || reservedWords.has(name)) return false;
410
- return isIdentifier(name);
554
+ function resolveOperationName(name) {
555
+ return this.memo(`operation:${name}`, () => ensureValidVarName(casing.camel(name)));
411
556
  }
412
557
  /**
413
- * Returns `name` when it's a syntactically valid JavaScript variable name,
414
- * otherwise prefixes it with `_` so the result is a valid identifier.
558
+ * Builds the allocation key for a declaration an operation owns. `scope` names which declaration
559
+ * it is, so two of them never share an allocation even when a custom resolver gives both the same
560
+ * name. Leave `scope` empty for the operation's own declaration.
415
561
  *
416
- * Useful for sanitizing OpenAPI schema names or operation IDs that start with
417
- * a digit (e.g. `409`, `504AccountCancel`) before using them as exported
418
- * variable, type, or function names.
562
+ * The key starts from the operation's input `pointer`, which macros keep, so a plugin whose macro
563
+ * rewrites the method or path still resolves another plugin's names for the same operation.
419
564
  *
420
565
  * @example
421
566
  * ```ts
422
- * ensureValidVarName('409') // '_409'
423
- * ensureValidVarName('504AccountCancel') // '_504AccountCancel'
424
- * ensureValidVarName('Pet') // 'Pet'
425
- * ensureValidVarName('class') // '_class'
567
+ * resolver.resolveName({ key: operationKey(node, 'response', 'status', 404), name })
426
568
  * ```
427
569
  */
428
- function ensureValidVarName(name) {
429
- if (!name || isValidVarName(name)) return name;
430
- return `_${name}`;
570
+ function operationKey(node, ...scope) {
571
+ return [
572
+ "operation",
573
+ ...node.pointer ? [node.pointer] : [node.method, node.path],
574
+ ...scope.map(String)
575
+ ];
576
+ }
577
+ // ../../internals/client/src/resolveClientOperation.ts
578
+ function isRelativeImport(importPath) {
579
+ return importPath.startsWith(".");
580
+ }
581
+ function resolveImportPath(options) {
582
+ const { importPath, operationFile } = options;
583
+ return isRelativeImport(importPath) ? path.resolve(path.dirname(operationFile), importPath) : importPath;
431
584
  }
432
585
  /**
433
- * Returns `true` when `name` is syntactically a valid identifier, ignoring reserved words.
586
+ * Resolves the contract client `<op>` a consumer (query hook, MCP handler) imports, by looking up
587
+ * the registered contract client plugin's resolver and output. Works for any contract client plugin
588
+ * (plugin-fetch, plugin-axios, or plugin-client). Returns `null` when no contract plugin is in play (the inline
589
+ * path), or when the client plugin's `exclude` / `include` leaves this operation out, since it then
590
+ * emits no `<op>` to import. plugin-fetch / plugin-axios inject `.kubb/client.ts` at the global
591
+ * output root, the same path consumers read `RequestConfig` / `ResponseErrorConfig` from.
592
+ * With plugin-client they come from the user's `importPath` module instead.
434
593
  *
435
- * Reserved words and globals (`class`, `name`, `Date`, …) are valid as bare object-literal keys
436
- * even though they are not valid variable names, so use this (not {@link isValidVarName}) when
437
- * deciding whether an object key needs quoting.
594
+ * The result is cached in `memo` (the build's `ctx.memo`) under the client plugin's name and the operation,
595
+ * so several dependents reading the same client plugin for one operation in a single pass
596
+ * (react-query's query/mutation/infinite generators, vue-query, swr, the MCP handler, ...) share
597
+ * one computed result instead of each re-deriving the name and path.
438
598
  *
439
- * @example
440
- * ```ts
441
- * isIdentifier('name') // true
442
- * isIdentifier('x-total')// false
443
- * ```
599
+ * `returnType`, `output`, and `group` are the client plugin's options for this operation, after its
600
+ * `override` entries, the same resolution its own generator sees. A dependent's generated call body
601
+ * and import path therefore match the `<op>` actually emitted, even when an `override` changes it.
444
602
  */
445
- function isIdentifier(name) {
446
- return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);
603
+ function resolveClientOperation(options) {
604
+ const { clientPlugin, driver, node, root, output, memo } = options;
605
+ if (!clientPlugin) return null;
606
+ return memo(`${clientPlugin.pluginName}:clientOperation:${node.operationId}`, () => {
607
+ const resolver = driver.getResolver(clientPlugin.pluginName);
608
+ const pluginOptions = driver.getPlugin(clientPlugin.pluginName)?.options ?? {};
609
+ const { exclude, include, override } = pluginOptions;
610
+ const operationOptions = Boolean(exclude?.length || include?.length || override?.length) && resolver.default ? resolver.default.options(node, {
611
+ options: pluginOptions,
612
+ exclude,
613
+ include,
614
+ override
615
+ }) : pluginOptions;
616
+ if (!operationOptions) return null;
617
+ const file = resolver.file({
618
+ ...operationFileEntry(node, node.operationId),
619
+ root,
620
+ output: operationOptions.output ?? output,
621
+ group: operationOptions.group ?? void 0
622
+ });
623
+ const { importPath } = operationOptions;
624
+ const name = resolver.name(node.operationId);
625
+ return {
626
+ name: resolver.resolveName({
627
+ key: operationKey(node),
628
+ name
629
+ }),
630
+ path: file.path,
631
+ clientPath: importPath === void 0 ? path.resolve(root, ".kubb/client.ts") : resolveImportPath({
632
+ importPath,
633
+ operationFile: file.path
634
+ }),
635
+ clientPathIsFile: importPath === void 0 || isRelativeImport(importPath),
636
+ returnType: operationOptions.returnType ?? "full",
637
+ typedHeaders: importPath === void 0
638
+ };
639
+ });
640
+ }
641
+ // ../../internals/client/src/resolveOperationTypes.ts
642
+ const pluginZodName = "plugin-zod";
643
+ function getResponseHeadersEntries({ node, types }) {
644
+ const resolve = types.response.headers;
645
+ if (!resolve) return [];
646
+ return node.responses.filter((response) => response.headers?.length).map((response) => [response.statusCode, resolve.call(types.response, node, response.statusCode)]);
447
647
  }
448
- // ../../internals/utils/src/strings.ts
449
648
  /**
450
- * Renders a dotted path or string array as an optional-chaining accessor expression rooted at
451
- * `accessor`. Returns `null` for an empty path.
452
- *
453
- * @example
454
- * ```ts
455
- * getNestedAccessor('pagination.next.id', 'lastPage')
456
- * // "lastPage?.['pagination']?.['next']?.['id']"
457
- * ```
649
+ * The headers type argument of `RequestResult`, such as `{ '200': LoginUserStatus200Headers }`, or `null` when no response declares headers.
458
650
  */
459
- function getNestedAccessor(param, accessor) {
460
- const parts = Array.isArray(param) ? param : param.split(".");
461
- if (parts.length === 0 || parts.length === 1 && parts[0] === "") return null;
462
- return `${accessor}?.['${`${parts.join("']?.['")}']`}`;
651
+ function buildResponseHeadersType({ node, types }) {
652
+ const entries = getResponseHeadersEntries({
653
+ node,
654
+ types
655
+ }).map(([statusCode, name]) => `'${statusCode}': ${name}`);
656
+ return entries.length ? `{ ${entries.join("; ")} }` : null;
463
657
  }
464
- // ../../internals/shared/src/resolver.ts
465
658
  /**
466
- * The shared top-level `name` of the operation plugins, computed once per operation name and build.
659
+ * A runtime result type, such as `RequestResult`, in its `WithHeaders` form when `headers` is set.
467
660
  */
468
- function resolveOperationName(name) {
469
- return this.memo(`operation:${name}`, () => ensureValidVarName(camelCase(name)));
661
+ function resultTypeName(name, headers) {
662
+ return headers ? `${name}WithHeaders` : name;
470
663
  }
471
664
  /**
472
- * Builds the allocation key for a declaration an operation owns. `scope` names which declaration
473
- * it is, so two of them never share an allocation even when a custom resolver gives both the same
474
- * name. Leave `scope` empty for the operation's own declaration.
475
- *
476
- * @example
477
- * ```ts
478
- * resolver.resolveName({ key: operationKey(node, 'response', 'status', 404), name })
479
- * ```
665
+ * A runtime result type with its arguments, such as `RequestResultWithHeaders<Responses, Headers, ThrowOnError>`.
480
666
  */
481
- function operationKey(node, ...scope) {
482
- return [
483
- "operation",
484
- node.method,
485
- node.path,
486
- ...scope.map(String)
487
- ];
667
+ function buildResultTypeRef(name, responses, headers, rest = []) {
668
+ return `${resultTypeName(name, headers !== null)}<${[
669
+ responses,
670
+ headers,
671
+ ...rest
672
+ ].filter(Boolean).join(", ")}>`;
488
673
  }
489
- // ../../internals/shared/src/group.ts
490
674
  /**
491
- * Builds the `group` config a Kubb plugin passes to `ctx.setOptions`, applying the
492
- * shared default naming so every plugin groups output consistently:
493
- *
494
- * - `path` groups use the second path segment (`/pet/findByStatus` → `pet`).
495
- * - other groups use the camelCased group (`pet store` → `petStore`).
496
- *
497
- * A user-provided `group.name` always wins over the default namer, so callers stay in
498
- * control of their output folders. Returns `null` when grouping is disabled, matching the
499
- * per-plugin convention.
500
- *
501
- * @param group - The user-supplied group option, or `undefined` to disable grouping.
502
- *
503
- * @example
504
- * ```ts
505
- * createGroupConfig(group) // shared across every plugin
506
- * ```
675
+ * The names of the headers types `buildResponseHeadersType` references, for the file's imports.
507
676
  */
508
- function createGroupConfig(group) {
509
- if (!group) return null;
510
- const defaultName = (ctx) => {
511
- if (group.type === "path") return `${ctx.group.split("/")[1]}`;
512
- return camelCase(ctx.group);
513
- };
514
- return {
515
- ...group,
516
- name: group.name ? group.name : defaultName
517
- };
677
+ function getResponseHeadersTypeNames({ node, types }) {
678
+ return getResponseHeadersEntries({
679
+ node,
680
+ types
681
+ }).map(([, name]) => name);
518
682
  }
519
- // kubb-extension.json
520
- var compatibility = {
521
- "kubb": ">=5.16.0",
522
- "node": ">=22.22"
523
- };
524
- // package.json
525
- var version = "5.10.0-canary.20261109T201601";
526
- // ../../internals/client/src/resolveOperationTypes.ts
527
683
  /**
528
684
  * A `plugin-ts` shaped resolver whose operation type names point at the types `pluginZod({ inferred })`
529
685
  * exports next to each schema, so code written against `plugin-ts` names picks up the zod types.
@@ -546,6 +702,7 @@ function toZodTypeResolver(resolver) {
546
702
  status: (node, statusCode) => type(resolver.response.status(node, statusCode)),
547
703
  response: (node) => type(resolver.response.response(node)),
548
704
  responses: (node) => type(resolver.response.responses(node)),
705
+ headers: (node, statusCode) => type(resolver.response.headers(node, statusCode)),
549
706
  options: (node) => resolver.response.options(node)
550
707
  }
551
708
  };
@@ -593,179 +750,6 @@ function resolveOperationTypes(driver, pluginName) {
593
750
  };
594
751
  });
595
752
  }
596
- // ../../internals/client/src/resolveClient.ts
597
- /**
598
- * Resolves which client plugin a consumer (react-query, vue-query, swr, mcp) should call for an
599
- * operation, shared so the selection rules and diagnostics stay in one place.
600
- *
601
- * Every client runtime lives in a dedicated client plugin, so a consumer always calls a registered
602
- * contract client plugin (plugin-fetch, plugin-axios, or plugin-client) and never emits its own
603
- * inline client:
604
- *
605
- * - `contract` — a registered contract client plugin owns the `<op>` functions and the consumer
606
- * imports and calls them.
607
- * - `error` — no client plugin is registered, several are registered without a selector, the
608
- * requested one is missing, or `client` is not a known selector.
609
- *
610
- * The `client` string selects explicitly (`'fetch'` / `'axios'` / `'client'`); when it is unset a
611
- * lone registered contract client plugin is picked up automatically.
612
- */
613
- const pluginFetchName = "plugin-fetch";
614
- const pluginAxiosName = "plugin-axios";
615
- const pluginClientName = "plugin-client";
616
- const selectorToPlugin = {
617
- fetch: pluginFetchName,
618
- axios: pluginAxiosName,
619
- client: pluginClientName
620
- };
621
- const contractPlugins = [
622
- pluginFetchName,
623
- pluginAxiosName,
624
- pluginClientName
625
- ];
626
- /**
627
- * Applies the `client` resolution rules. See the module comment for the strategy shape.
628
- *
629
- * @example
630
- * ```ts
631
- * resolveClient({ client: 'fetch', pluginNames: ['plugin-ts', 'plugin-fetch'] })
632
- * // { kind: 'contract', pluginName: 'plugin-fetch' }
633
- * ```
634
- *
635
- * @example
636
- * ```ts
637
- * resolveClient({ client: undefined, pluginNames: ['plugin-ts'] })
638
- * // { kind: 'error', code: 'KUBB_MISSING_DEPENDENCY', message: 'No client plugin is registered.', help: 'Add …' }
639
- * ```
640
- */
641
- function resolveClient(options) {
642
- const { client, pluginNames } = options;
643
- const has = (name) => pluginNames.includes(name);
644
- if (client === "fetch" || client === "axios" || client === "client") {
645
- const pluginName = selectorToPlugin[client];
646
- if (!has(pluginName)) return {
647
- kind: "error",
648
- code: Diagnostics.code.missingDependency,
649
- message: `\`client: '${client}'\` is set but \`@kubb/plugin-${client}\` is not registered in \`plugins\`.`,
650
- help: `Add \`@kubb/plugin-${client}\` to \`plugins\`, or drop \`client\` to use a different client plugin.`
651
- };
652
- return {
653
- kind: "contract",
654
- pluginName
655
- };
656
- }
657
- if (client !== void 0) return {
658
- kind: "error",
659
- code: Diagnostics.code.invalidPluginOptions,
660
- message: `Option \`client\` is ${typeof client === "string" ? `'${client}'` : String(client)}, but it must be one of 'fetch', 'axios', 'client'.`,
661
- help: "Set `client` to one of those values, or drop it to use the registered client plugin."
662
- };
663
- const registered = contractPlugins.filter(has);
664
- if (registered.length === 1) return {
665
- kind: "contract",
666
- pluginName: registered[0]
667
- };
668
- if (registered.length > 1) return {
669
- kind: "error",
670
- code: Diagnostics.code.invalidPluginOptions,
671
- message: `Multiple client plugins are registered (${registered.map((name) => `\`@kubb/${name}\``).join(", ")}) and \`client\` is not set.`,
672
- help: "Set `client: 'fetch' | 'axios' | 'client'` to choose which client the hooks call, or register a single client plugin."
673
- };
674
- return {
675
- kind: "error",
676
- code: Diagnostics.code.missingDependency,
677
- message: "No client plugin is registered.",
678
- help: "Add `@kubb/plugin-fetch`, `@kubb/plugin-axios`, or `@kubb/plugin-client` to `plugins` so the generated code has an HTTP client to call."
679
- };
680
- }
681
- /**
682
- * Resolves the contract client during a consumer plugin's setup hook.
683
- * It extracts the plugin names from the raw `plugins` config and applies {@link resolveClient}.
684
- * On a misconfiguration it throws a config diagnostic tagged with `plugin`, so every consumer
685
- * fails fast with the same message.
686
- */
687
- function resolveContractClient(options) {
688
- const { plugin, client, plugins = [] } = options;
689
- const resolved = resolveClient({
690
- client,
691
- pluginNames: plugins.map((plugin) => plugin.name).filter((name) => Boolean(name))
692
- });
693
- if (resolved.kind === "error") {
694
- const { code, message, help } = resolved;
695
- throw new Diagnostics.Error({
696
- code,
697
- severity: "error",
698
- message,
699
- help,
700
- location: { kind: "config" },
701
- plugin
702
- });
703
- }
704
- return resolved;
705
- }
706
- // ../../internals/client/src/resolveClientOperation.ts
707
- function isRelativeImport(importPath) {
708
- return importPath.startsWith(".");
709
- }
710
- function resolveImportPath(options) {
711
- const { importPath, operationFile } = options;
712
- return isRelativeImport(importPath) ? path.resolve(path.dirname(operationFile), importPath) : importPath;
713
- }
714
- /**
715
- * Resolves the contract client `<op>` a consumer (query hook, MCP handler) imports, by looking up
716
- * the registered contract client plugin's resolver and output. Works for any contract client plugin
717
- * (plugin-fetch, plugin-axios, or plugin-client). Returns `null` when no contract plugin is in play (the inline
718
- * path), or when the client plugin's `exclude` / `include` leaves this operation out, since it then
719
- * emits no `<op>` to import. plugin-fetch / plugin-axios inject `.kubb/client.ts` at the global
720
- * output root, the same path consumers read `RequestConfig` / `ResponseErrorConfig` from.
721
- * With plugin-client they come from the user's `importPath` module instead.
722
- *
723
- * The result is cached in `memo` (the build's `ctx.memo`) under the client plugin's name and the operation,
724
- * so several dependents reading the same client plugin for one operation in a single pass
725
- * (react-query's query/mutation/infinite generators, vue-query, swr, the MCP handler, ...) share
726
- * one computed result instead of each re-deriving the name and path.
727
- *
728
- * `returnType`, `output`, and `group` are the client plugin's options for this operation, after its
729
- * `override` entries, the same resolution its own generator sees. A dependent's generated call body
730
- * and import path therefore match the `<op>` actually emitted, even when an `override` changes it.
731
- */
732
- function resolveClientOperation(options) {
733
- const { clientPlugin, driver, node, root, output, memo } = options;
734
- if (!clientPlugin) return null;
735
- return memo(`${clientPlugin.pluginName}:clientOperation:${node.operationId}`, () => {
736
- const resolver = driver.getResolver(clientPlugin.pluginName);
737
- const pluginOptions = driver.getPlugin(clientPlugin.pluginName)?.options ?? {};
738
- const { exclude, include, override } = pluginOptions;
739
- const operationOptions = Boolean(exclude?.length || include?.length || override?.length) && resolver.default ? resolver.default.options(node, {
740
- options: pluginOptions,
741
- exclude,
742
- include,
743
- override
744
- }) : pluginOptions;
745
- if (!operationOptions) return null;
746
- const file = resolver.file({
747
- ...operationFileEntry(node, node.operationId),
748
- root,
749
- output: operationOptions.output ?? output,
750
- group: operationOptions.group ?? void 0
751
- });
752
- const { importPath } = operationOptions;
753
- const name = resolver.name(node.operationId);
754
- return {
755
- name: resolver.resolveName({
756
- key: operationKey(node),
757
- name
758
- }),
759
- path: file.path,
760
- clientPath: importPath === void 0 ? path.resolve(root, ".kubb/client.ts") : resolveImportPath({
761
- importPath,
762
- operationFile: file.path
763
- }),
764
- clientPathIsFile: importPath === void 0 || isRelativeImport(importPath),
765
- returnType: operationOptions.returnType ?? "full"
766
- };
767
- });
768
- }
769
753
  // ../../internals/tanstack-query/src/components/HookFile.tsx
770
754
  /**
771
755
  * Resolves what every TanStack hook file shares: its file, the operation types file and names (`@kubb/plugin-ts`, or
@@ -784,14 +768,18 @@ function resolveHookFile(node, ctx, options) {
784
768
  });
785
769
  const types = resolveOperationTypes(ctx.driver, resolver.pluginName);
786
770
  const tsResolver = types.resolver;
771
+ const headerTypeNames = returnType === "data" || !contractOp.typedHeaders ? [] : getResponseHeadersTypeNames({
772
+ node,
773
+ types: tsResolver
774
+ });
787
775
  const file = resolver.file({
788
776
  ...operationFileEntry(node, name),
789
777
  root,
790
778
  output,
791
779
  group: group ?? void 0
792
780
  });
793
- const fileTs = resolveDependencyOperationFile({
794
- memo: ctx.memo,
781
+ const fileTs = resolveOperationFile({
782
+ ctx,
795
783
  node,
796
784
  resolver: tsResolver,
797
785
  root,
@@ -801,6 +789,7 @@ function resolveHookFile(node, ctx, options) {
801
789
  const importedTypeNames = [
802
790
  tsResolver.response.options(node),
803
791
  tsResolver.response.responses(node),
792
+ ...headerTypeNames,
804
793
  ...extraTypeNames,
805
794
  ...resolveOperationTypeNames(node, tsResolver, {
806
795
  exclude: [keyTypeName, returnType !== "data" ? tsResolver.response.response(node) : null].filter((name) => Boolean(name)),
@@ -818,6 +807,7 @@ function resolveHookFile(node, ctx, options) {
818
807
  tsResolver,
819
808
  contractOp,
820
809
  importedTypeNames,
810
+ resultTypeName: headerTypeNames.length ? "RequestResultWithHeaders" : "RequestResult",
821
811
  returnType,
822
812
  banner: resolver.default.banner(ctx.meta, {
823
813
  output,
@@ -835,7 +825,7 @@ function resolveHookFile(node, ctx, options) {
835
825
  * The `<File>` shell shared by the TanStack hook generators; renders `children` after the imports.
836
826
  */
837
827
  function HookFile({ hook, imports, children }) {
838
- const { file, fileTs, contractOp, importedTypeNames, banner, footer } = hook;
828
+ const { file, fileTs, contractOp, importedTypeNames, resultTypeName, banner, footer } = hook;
839
829
  return /* @__PURE__ */ jsxs(File, {
840
830
  baseName: file.baseName,
841
831
  path: file.path,
@@ -852,7 +842,7 @@ function HookFile({ hook, imports, children }) {
852
842
  name: [
853
843
  "RequestConfig",
854
844
  "ResponseErrorConfig",
855
- "RequestResult"
845
+ resultTypeName
856
846
  ],
857
847
  root: contractOp.clientPathIsFile ? file.path : void 0,
858
848
  path: contractOp.clientPath,
@@ -938,8 +928,8 @@ function buildGroupedRequestParam(node, options) {
938
928
  /**
939
929
  * Builds the shared `({ path, query, body, headers, cookies }, config = {})` parameter list for a
940
930
  * TanStack query-options function. The leading parameter mirrors the client signature, and the
941
- * trailing `config` is a partial `RequestConfig` minus the grouped data-shape keys, which are passed
942
- * explicitly. Framework plugins wrap the result when needed, for example vue-query applies `MaybeRefOrGetter`.
931
+ * trailing `config` is the client's `Options` minus the request groups and `throwOnError`, which the
932
+ * hook passes itself. Framework plugins wrap the result when needed, for example vue-query applies `MaybeRefOrGetter`.
943
933
  */
944
934
  function buildQueryOptionsParams(node, options) {
945
935
  const { resolver, memberTypeWrapper } = options;
@@ -949,7 +939,7 @@ function buildQueryOptionsParams(node, options) {
949
939
  });
950
940
  const configParam = createFunctionParameter({
951
941
  name: "config",
952
- type: buildClientOptionType(node),
942
+ type: buildClientOptionType(),
953
943
  default: "{}"
954
944
  });
955
945
  return createFunctionParameters({ params: [groupedParam, configParam].filter((param) => param !== null) });
@@ -961,26 +951,30 @@ function buildQueryOptionsParams(node, options) {
961
951
  * can't flip the query's error semantics. Queries thread the TanStack `signal`; mutations omit it.
962
952
  *
963
953
  * When `unwrapName` is set, each request group is passed as an explicit member unwrapped through it,
964
- * used by vue-query to resolve refs and getters with `toValue(...)` at call time.
954
+ * used by vue-query to resolve refs and getters with `toValue(...)` at call time. `pageParam` names the
955
+ * query parameter an infinite query sets from TanStack's `pageParam`.
965
956
  *
966
957
  * @example
967
958
  * ```ts
968
959
  * buildClientCall(node, { clientName: 'getPetById', signal: true })
969
- * // getPetById({ path, ...config, signal: config.signal ?? signal, throwOnError: true })
960
+ * // getPetById({ ...config, path, signal: config.signal ?? signal, throwOnError: true })
970
961
  * ```
971
962
  */
972
963
  function buildClientCall(node, options) {
973
- const { clientName, signal = false, unwrapName, withContentType = false, returnType = "full" } = options;
964
+ const { clientName, signal = false, unwrapName, withContentType = false, pageParam } = options;
974
965
  const { groups } = getRequestGroupOptionality(node);
975
966
  const names = requestGroupOrder.filter((key) => groups[key]);
976
- const args = [
967
+ const member = (name) => {
968
+ const value = unwrapName ? unwrapName(name) : name;
969
+ if (name === "query" && pageParam) return `query: { ...${value}, ${JSON.stringify(pageParam)}: pageParam }`;
970
+ return unwrapName ? `${name}: ${value}` : name;
971
+ };
972
+ return `${clientName}({ ${[
977
973
  "...config",
978
- ...withContentType && hasRequestContentTypeChoice(node) ? ["...variables"] : names.map((name) => unwrapName ? `${name}: ${unwrapName(name)}` : name),
974
+ ...withContentType && hasRequestContentTypeChoice(node) ? ["...variables"] : names.map(member),
979
975
  signal ? "signal: config.signal ?? signal" : null,
980
976
  "throwOnError: true"
981
- ].filter((part) => part !== null);
982
- if (withContentType && hasRequestContentTypeChoice(node)) return `${clientName}(${castToClientOptions(`{ ${args.join(", ")} }`, clientName, returnType)})`;
983
- return `${clientName}({ ${args.join(", ")} })`;
977
+ ].filter((part) => part !== null).join(", ")} })`;
984
978
  }
985
979
  /**
986
980
  * Builds the query/mutation body that resolves a `buildClientCall` expression down to the bare
@@ -1003,19 +997,28 @@ function buildCallResultBody(call, options = {}) {
1003
997
  if (clientReturnType === "plain") return `return (await ${call}).data`;
1004
998
  return `return ${call}.unwrap()`;
1005
999
  }
1000
+ function buildResultType(node, resolver, typedHeaders) {
1001
+ const headers = typedHeaders ? buildResponseHeadersType({
1002
+ node,
1003
+ types: resolver
1004
+ }) : null;
1005
+ return buildResultTypeRef("RequestResult", resolver.response.responses(node), headers, ["true"]);
1006
+ }
1006
1007
  /**
1007
1008
  * Builds the `TData` / `TError` type expressions shared by every generated hook, joining the resolved
1008
1009
  * success responses into `TData` and wrapping the error responses in `ResponseErrorConfig<...>`.
1009
- * With `returnType` `'full'`, `TData` is the client's `RequestResult` over the operation's responses record.
1010
+ * With `returnType` `'full'`, `TData` is the client's `RequestResult` over the operation's responses record, with the
1011
+ * response headers the operation declares.
1010
1012
  */
1011
1013
  function buildResponseTypes(node, resolver, options = {}) {
1012
- const { returnType = "data" } = options;
1013
- return resolver.memo(`responseTypes:${returnType}:${node.method}\0${node.path}`, () => {
1014
+ const { returnType = "data", typedHeaders = true } = options;
1015
+ return resolver.memo(`responseTypes:${returnType}:${typedHeaders}:${node.method}\0${node.path}`, () => {
1014
1016
  const successNames = resolveSuccessNames(node, resolver);
1015
- const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.response.response(node);
1017
+ const bodyName = successNames.length > 0 ? successNames.join(" | ") : resolver.response.response(node);
1018
+ const responseName = hasStreamVariant(node) ? `${bodyName} | ReadableStream<Uint8Array>` : bodyName;
1016
1019
  const errorNames = resolveErrorNames(node, resolver);
1017
1020
  return {
1018
- TData: returnType !== "data" ? `RequestResult<${resolver.response.responses(node)}, true>` : responseName,
1021
+ TData: returnType === "data" ? responseName : buildResultType(node, resolver, typedHeaders),
1019
1022
  TError: `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`
1020
1023
  };
1021
1024
  });
@@ -1034,7 +1037,7 @@ function resolveFallbackPageParamType(initialPageParam) {
1034
1037
  * so callers can reuse it when rewriting the paginated request.
1035
1038
  */
1036
1039
  function resolvePageParamType(node, { resolver, initialPageParam, queryParam }) {
1037
- const firstQueryParam = getOperationParameters(node).query[0];
1040
+ const firstQueryParam = ast.http.groupParameters(node).query[0];
1038
1041
  const groupName = firstQueryParam ? resolver.param.query(node, firstQueryParam) : null;
1039
1042
  const queryParamsTypeName = groupName !== (firstQueryParam ? resolver.param.name(node, firstQueryParam) : null) ? groupName : null;
1040
1043
  const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : null;
@@ -1137,7 +1140,7 @@ function resolveInfiniteConfig(infinite) {
1137
1140
  */
1138
1141
  function matchesInfinite(node, infinite) {
1139
1142
  if (!infinite.queryParam) return false;
1140
- return getOperationParameters(node).query.some((param) => param.name.replace(/\?$/, "") === infinite.queryParam);
1143
+ return ast.http.groupParameters(node).query.some((param) => param.name.replace(/\?$/, "") === infinite.queryParam);
1141
1144
  }
1142
1145
  /**
1143
1146
  * Warning for an infinite hook that falls back to the built-in page params on a response that
@@ -1145,8 +1148,8 @@ function matchesInfinite(node, infinite) {
1145
1148
  */
1146
1149
  function getDefaultPageParamsWarning(node, infinite) {
1147
1150
  if (!(infinite.getNextPageParam == null && infinite.getPreviousPageParam == null && infinite.nextParam == null && infinite.previousParam == null && !infinite.cursorParam)) return null;
1148
- const content = getPrimarySuccessResponse(node)?.content;
1149
- let resolved = (content?.find((item) => item.contentType?.includes("json")) ?? content?.[0])?.schema;
1151
+ const content = ast.http.responses.findPrimary(node)?.content;
1152
+ let resolved = (content?.find((item) => ast.mediaType.isJson(item)) ?? content?.[0])?.schema;
1150
1153
  while (resolved?.type === "ref" || resolved?.type === "intersection" && resolved.members?.length === 1) resolved = resolved.type === "ref" ? resolved.schema : resolved.members?.[0];
1151
1154
  if (!resolved || resolved.type === "array") return null;
1152
1155
  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.`;
@@ -1194,15 +1197,24 @@ function buildHookParams(node, options) {
1194
1197
  }
1195
1198
  /**
1196
1199
  * The `TRequest` type argument of a mutation hook: the options type when the operation takes a request, else `undefined`.
1200
+ * When the variables carry the request media type and the response has several, `contentType` can pick the
1201
+ * response one too, as `{ request, response }`.
1197
1202
  */
1198
1203
  function resolveMutationRequestType(node, resolver) {
1199
- return buildGroupedRequestParam(node, { resolver }) ? resolver.response.options(node) : "undefined";
1204
+ if (!buildGroupedRequestParam(node, { resolver })) return "undefined";
1205
+ const optionsName = resolver.response.options(node);
1206
+ const response = getResponseContentTypeInfo(node);
1207
+ if (!hasRequestContentTypeChoice(node) || !response.isMultipleContentTypes) return optionsName;
1208
+ return `${/^[\w$]+$/.test(optionsName) ? optionsName : `(${optionsName})`} & { contentType?: string | { response?: ${response.contentTypeUnion} } }`;
1200
1209
  }
1201
1210
  // ../../internals/tanstack-query/src/components/InfiniteQueryOptions.tsx
1202
1211
  const declarationPrinter$5 = functionPrinter({ mode: "declaration" });
1203
1212
  const callPrinter$3 = functionPrinter({ mode: "call" });
1204
- function InfiniteQueryOptions({ name, clientName, initialPageParam, hasExplicitInitialPageParam, cursorParam, nextParam, previousParam, getNextPageParam, getPreviousPageParam, node, tsResolver, queryParam, queryKeyName, queryKeyType = "typeof queryKey", memberTypeWrapper, unwrapName, clientReturnType, returnType }) {
1205
- const { TData: queryFnDataType, TError: errorType } = buildResponseTypes(node, tsResolver, { returnType });
1213
+ function InfiniteQueryOptions({ name, clientName, initialPageParam, hasExplicitInitialPageParam, cursorParam, nextParam, previousParam, getNextPageParam, getPreviousPageParam, node, tsResolver, queryParam, queryKeyName, queryKeyType = "typeof queryKey", memberTypeWrapper, unwrapName, clientReturnType, returnType, typedHeaders }) {
1214
+ const { TData: queryFnDataType, TError: errorType } = buildResponseTypes(node, tsResolver, {
1215
+ returnType,
1216
+ typedHeaders
1217
+ });
1206
1218
  const dataSuffix = returnType === "data" ? "" : ".data";
1207
1219
  const { queryParamsTypeName, pageParamType } = resolvePageParamType(node, {
1208
1220
  resolver: tsResolver,
@@ -1221,10 +1233,12 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, hasExplicitI
1221
1233
  memberTypeWrapper
1222
1234
  });
1223
1235
  const paramsSignature = declarationPrinter$5.print(paramsNode) ?? "";
1236
+ const pageParam = queryParam && queryParamsTypeName ? queryParam : void 0;
1224
1237
  const queryFnBody = buildCallResultBody(buildClientCall(node, {
1225
1238
  clientName,
1226
1239
  signal: true,
1227
- unwrapName
1240
+ unwrapName,
1241
+ pageParam
1228
1242
  }), {
1229
1243
  clientReturnType,
1230
1244
  returnType
@@ -1251,12 +1265,7 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, hasExplicitI
1251
1265
  getNextPageParamExpr,
1252
1266
  getPreviousPageParamExpr
1253
1267
  ].filter(Boolean);
1254
- const infiniteOverrideParams = queryParam && queryParamsTypeName ? `query = {
1255
- ...(query ?? {}),
1256
- ['${queryParam}']: pageParam as unknown as ${queryParamsTypeName}['${queryParam}'],
1257
- } as ${queryParamsTypeName}` : "";
1258
- const queryFnArgs = infiniteOverrideParams ? "{ signal, pageParam }" : "{ signal }";
1259
- const queryFnStatements = infiniteOverrideParams ? `${infiniteOverrideParams}\n ${queryFnBody}` : queryFnBody;
1268
+ const queryFnArgs = pageParam ? "{ signal, pageParam }" : "{ signal }";
1260
1269
  return /* @__PURE__ */ jsx(File.Source, {
1261
1270
  name,
1262
1271
  isExportable: true,
@@ -1270,7 +1279,7 @@ const queryKey = ${queryKeyName}(${queryKeyParamsCall})
1270
1279
  return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, ${queryKeyType}, ${pageParamType}>({
1271
1280
  queryKey,
1272
1281
  queryFn: async (${queryFnArgs}) => {
1273
- ${queryFnStatements}
1282
+ ${queryFnBody}
1274
1283
  },
1275
1284
  ${queryOptionsArr.join(",\n ")}
1276
1285
  })
@@ -1341,7 +1350,7 @@ function MutationKey({ name, node, transformer, typeName }) {
1341
1350
  function createQueryResolver(variant = "") {
1342
1351
  return {
1343
1352
  name(node) {
1344
- const name = `use${capitalize(this.name(node.operationId))}${variant}`;
1353
+ const name = `use${casing.capitalize(this.name(node.operationId))}${variant}`;
1345
1354
  return this.resolveName({
1346
1355
  key: operationKey(node, "query", variant, "name"),
1347
1356
  name
@@ -1362,7 +1371,7 @@ function createQueryResolver(variant = "") {
1362
1371
  });
1363
1372
  },
1364
1373
  keyTypeName(node) {
1365
- const name = `${capitalize(this.name(node.operationId))}${variant}QueryKey`;
1374
+ const name = `${casing.capitalize(this.name(node.operationId))}${variant}QueryKey`;
1366
1375
  return this.resolveName({
1367
1376
  key: operationKey(node, "query", variant, "keyTypeName"),
1368
1377
  name
@@ -1383,7 +1392,7 @@ function createQueryResolver(variant = "") {
1383
1392
  function createMutationResolver() {
1384
1393
  return {
1385
1394
  name(node) {
1386
- const name = `use${capitalize(this.name(node.operationId))}`;
1395
+ const name = `use${casing.capitalize(this.name(node.operationId))}`;
1387
1396
  return this.resolveName({
1388
1397
  key: operationKey(node, "mutation", "name"),
1389
1398
  name
@@ -1412,14 +1421,14 @@ const declarationPrinter$3 = functionPrinter({ mode: "declaration" });
1412
1421
  */
1413
1422
  const queryKeyTransformer = ({ node, variant }) => {
1414
1423
  if (!node.path) return [];
1415
- const { path, query } = getOperationParameters(node);
1424
+ const { path, query } = ast.http.groupParameters(node);
1416
1425
  const isInfinite = variant === "infiniteQuery" || variant === "suspenseInfiniteQuery";
1417
1426
  const urlFields = [`url: '${Url.toPath(node.path)}'`];
1418
1427
  if (path.length > 0) urlFields.push("params: path");
1419
1428
  if (isInfinite) urlFields.push("infinite: true");
1420
1429
  const result = [`{ ${urlFields.join(", ")} }`];
1421
1430
  if (query.length > 0) result.push("...(query ? [query] : [])");
1422
- if (node.requestBody?.content?.[0]?.schema) result.push("...(body !== undefined ? [body] : [])");
1431
+ if (ast.http.requestBody.getSchema(node)) result.push("...(body !== undefined ? [body] : [])");
1423
1432
  return result;
1424
1433
  };
1425
1434
  function QueryKey({ name, node, tsResolver, typeName, transformer, variant = "query", memberTypeWrapper, exportType }) {
@@ -1465,8 +1474,11 @@ function getQueryOptionsParams(node, options) {
1465
1474
  memberTypeWrapper: maybeRefOrGetter
1466
1475
  });
1467
1476
  }
1468
- function QueryOptions({ name, clientName, node, tsResolver, queryKeyName, clientReturnType, returnType }) {
1469
- const { TData, TError } = buildResponseTypes(node, tsResolver, { returnType });
1477
+ function QueryOptions({ name, clientName, node, tsResolver, queryKeyName, clientReturnType, returnType, typedHeaders }) {
1478
+ const { TData, TError } = buildResponseTypes(node, tsResolver, {
1479
+ returnType,
1480
+ typedHeaders
1481
+ });
1470
1482
  const queryKeyParamsNode = buildQueryKeyParams(node, {
1471
1483
  resolver: tsResolver,
1472
1484
  memberTypeWrapper: maybeRefOrGetter
@@ -1505,8 +1517,11 @@ function QueryOptions({ name, clientName, node, tsResolver, queryKeyName, client
1505
1517
  // src/components/Query.tsx
1506
1518
  const declarationPrinter$1 = functionPrinter({ mode: "declaration" });
1507
1519
  const callPrinter$1 = functionPrinter({ mode: "call" });
1508
- function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, tsResolver, infinite, returnType }) {
1509
- const { TData, TError } = buildResponseTypes(node, tsResolver, { returnType });
1520
+ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, tsResolver, infinite, returnType, typedHeaders }) {
1521
+ const { TData, TError } = buildResponseTypes(node, tsResolver, {
1522
+ returnType,
1523
+ typedHeaders
1524
+ });
1510
1525
  const optionsName = infinite ? "UseInfiniteQueryOptions" : "UseQueryOptions";
1511
1526
  const hookName = infinite ? "useInfiniteQuery" : "useQuery";
1512
1527
  const resultType = `${infinite ? "UseInfiniteQueryReturnType" : "UseQueryReturnType"}<${["TData", TError].join(", ")}> & { queryKey: TQueryKey }`;
@@ -1553,7 +1568,7 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, t
1553
1568
  memberTypeWrapper: maybeRefOrGetter,
1554
1569
  optionsType: `{
1555
1570
  query?: Partial<${optionsName}<${optionsGenerics.join(", ")}>> & { client?: QueryClient },
1556
- client?: ${buildClientOptionType(node)}
1571
+ client?: ${buildClientOptionType()}
1557
1572
  }`
1558
1573
  });
1559
1574
  const paramsSignature = declarationPrinter$1.print(paramsNode) ?? "";
@@ -1597,7 +1612,7 @@ const infiniteQueryGenerator = defineGenerator({
1597
1612
  renderer: jsxRenderer,
1598
1613
  match(node, ctx) {
1599
1614
  const operationNode = node;
1600
- if (!ast.isHttpOperationNode(operationNode)) return false;
1615
+ if (!ast.http.isOperation(operationNode)) return false;
1601
1616
  const { query, mutation, infinite, hooks } = ctx.options;
1602
1617
  const { isQuery, isMutation } = classifyOperation(operationNode, {
1603
1618
  query,
@@ -1608,7 +1623,7 @@ const infiniteQueryGenerator = defineGenerator({
1608
1623
  return matchesInfinite(operationNode, infiniteOptions);
1609
1624
  },
1610
1625
  operation(node, ctx) {
1611
- if (!ast.isHttpOperationNode(node)) return null;
1626
+ if (!ast.http.isOperation(node)) return null;
1612
1627
  const { driver, resolver, root } = ctx;
1613
1628
  const { output, query, infinite, client, group } = ctx.options;
1614
1629
  const infiniteOptions = infinite && typeof infinite === "object" ? infinite : null;
@@ -1689,6 +1704,7 @@ const infiniteQueryGenerator = defineGenerator({
1689
1704
  queryParam: infiniteOptions.queryParam,
1690
1705
  clientReturnType: contractOp.returnType,
1691
1706
  returnType: hook.returnType,
1707
+ typedHeaders: hook.contractOp.typedHeaders,
1692
1708
  queryKeyType: "QueryKey",
1693
1709
  memberTypeWrapper: maybeRefOrGetter,
1694
1710
  unwrapName: (name) => `toValue(${name})`
@@ -1715,7 +1731,8 @@ const infiniteQueryGenerator = defineGenerator({
1715
1731
  node,
1716
1732
  tsResolver,
1717
1733
  infinite: true,
1718
- returnType: hook.returnType
1734
+ returnType: hook.returnType,
1735
+ typedHeaders: hook.contractOp.typedHeaders
1719
1736
  })
1720
1737
  ]
1721
1738
  });
@@ -1725,8 +1742,11 @@ const infiniteQueryGenerator = defineGenerator({
1725
1742
  const declarationPrinter = functionPrinter({ mode: "declaration" });
1726
1743
  const callPrinter = functionPrinter({ mode: "call" });
1727
1744
  function buildMutationParamsNode(node, options) {
1728
- const { resolver, returnType } = options;
1729
- const { TData, TError } = buildResponseTypes(node, resolver, { returnType });
1745
+ const { resolver, returnType, typedHeaders } = options;
1746
+ const { TData, TError } = buildResponseTypes(node, resolver, {
1747
+ returnType,
1748
+ typedHeaders
1749
+ });
1730
1750
  return buildHookParams(node, {
1731
1751
  resolver,
1732
1752
  withRequest: false,
@@ -1741,8 +1761,11 @@ function buildMutationParamsNode(node, options) {
1741
1761
  }`
1742
1762
  });
1743
1763
  }
1744
- function Mutation({ name, clientName, node, tsResolver, mutationKeyName, clientReturnType, returnType }) {
1745
- const { TData, TError } = buildResponseTypes(node, tsResolver, { returnType });
1764
+ function Mutation({ name, clientName, node, tsResolver, mutationKeyName, clientReturnType, returnType, typedHeaders }) {
1765
+ const { TData, TError } = buildResponseTypes(node, tsResolver, {
1766
+ returnType,
1767
+ typedHeaders
1768
+ });
1746
1769
  const groupedParam = buildGroupedRequestParam(node, {
1747
1770
  resolver: tsResolver,
1748
1771
  withContentType: true
@@ -1755,7 +1778,6 @@ function Mutation({ name, clientName, node, tsResolver, mutationKeyName, clientR
1755
1778
  clientName,
1756
1779
  signal: false,
1757
1780
  withContentType: true,
1758
- returnType: clientReturnType,
1759
1781
  unwrapName: (name) => `toValue<${TRequest}['${name}']>(${name})`
1760
1782
  }), {
1761
1783
  clientReturnType,
@@ -1769,7 +1791,8 @@ function Mutation({ name, clientName, node, tsResolver, mutationKeyName, clientR
1769
1791
  ].join(", ");
1770
1792
  const paramsNode = buildMutationParamsNode(node, {
1771
1793
  resolver: tsResolver,
1772
- returnType
1794
+ returnType,
1795
+ typedHeaders
1773
1796
  });
1774
1797
  const paramsSignature = declarationPrinter.print(paramsNode) ?? "";
1775
1798
  return /* @__PURE__ */ jsx(File.Source, {
@@ -1808,7 +1831,7 @@ const mutationGenerator = defineGenerator({
1808
1831
  name: "vue-query-mutation",
1809
1832
  renderer: jsxRenderer,
1810
1833
  operation(node, ctx) {
1811
- if (!ast.isHttpOperationNode(node)) return null;
1834
+ if (!ast.http.isOperation(node)) return null;
1812
1835
  const { driver, resolver, root } = ctx;
1813
1836
  const { output, query, mutation, client, group, hooks } = ctx.options;
1814
1837
  const { isMutation } = classifyOperation(node, {
@@ -1867,7 +1890,8 @@ const mutationGenerator = defineGenerator({
1867
1890
  tsResolver: hook.tsResolver,
1868
1891
  mutationKeyName,
1869
1892
  clientReturnType: contractOp.returnType,
1870
- returnType: hook.returnType
1893
+ returnType: hook.returnType,
1894
+ typedHeaders: hook.contractOp.typedHeaders
1871
1895
  })
1872
1896
  ] })]
1873
1897
  });
@@ -1883,7 +1907,7 @@ const queryGenerator = defineGenerator({
1883
1907
  name: "vue-query",
1884
1908
  renderer: jsxRenderer,
1885
1909
  operation(node, ctx) {
1886
- if (!ast.isHttpOperationNode(node)) return null;
1910
+ if (!ast.http.isOperation(node)) return null;
1887
1911
  const { driver, resolver, root } = ctx;
1888
1912
  const { output, query, mutation, client, group, hooks } = ctx.options;
1889
1913
  const { isQuery, isMutation } = classifyOperation(node, {
@@ -1946,7 +1970,8 @@ const queryGenerator = defineGenerator({
1946
1970
  node,
1947
1971
  tsResolver,
1948
1972
  clientReturnType: contractOp.returnType,
1949
- returnType: hook.returnType
1973
+ returnType: hook.returnType,
1974
+ typedHeaders: hook.contractOp.typedHeaders
1950
1975
  }),
1951
1976
  query && hooks && /* @__PURE__ */ jsxs(Fragment, { children: [
1952
1977
  /* @__PURE__ */ jsx(File.Import, {
@@ -1970,7 +1995,8 @@ const queryGenerator = defineGenerator({
1970
1995
  queryKeyTypeName,
1971
1996
  node,
1972
1997
  tsResolver,
1973
- returnType: hook.returnType
1998
+ returnType: hook.returnType,
1999
+ typedHeaders: hook.contractOp.typedHeaders
1974
2000
  })
1975
2001
  ] })
1976
2002
  ]
@@ -2064,7 +2090,7 @@ const pluginVueQuery = defineExtension({
2064
2090
  mutation: resolveMutationConfig(mutation, { importPath: "@tanstack/vue-query" }),
2065
2091
  infinite: resolveInfiniteConfig(infinite),
2066
2092
  hooks,
2067
- group: createGroupConfig(group),
2093
+ group: group ?? null,
2068
2094
  exclude,
2069
2095
  include,
2070
2096
  override,