@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.cjs CHANGED
@@ -24,12 +24,295 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
24
24
  enumerable: true
25
25
  }) : target, mod));
26
26
  let _kubb_kit = require("@kubb/kit");
27
+ let _kubb_plugin_ts = require("@kubb/plugin-ts");
27
28
  let node_path = require("node:path");
28
29
  node_path = __toESM(node_path, 1);
29
- let _kubb_plugin_ts = require("@kubb/plugin-ts");
30
- let _kubb_plugin_zod = require("@kubb/plugin-zod");
31
30
  let _kubb_renderer_jsx = require("@kubb/renderer-jsx");
32
31
  let _kubb_renderer_jsx_jsx_runtime = require("@kubb/renderer-jsx/jsx-runtime");
32
+ // kubb-extension.json
33
+ var compatibility = {
34
+ "kubb": ">=5.18.4",
35
+ "node": ">=22.22"
36
+ };
37
+ // package.json
38
+ var version = "5.10.1";
39
+ // ../../internals/client/src/resolveClient.ts
40
+ /**
41
+ * Resolves which client plugin a consumer (react-query, vue-query, swr, mcp) should call for an
42
+ * operation, shared so the selection rules and diagnostics stay in one place.
43
+ *
44
+ * Every client runtime lives in a dedicated client plugin, so a consumer always calls a registered
45
+ * contract client plugin (plugin-fetch, plugin-axios, or plugin-client) and never emits its own
46
+ * inline client:
47
+ *
48
+ * - `contract` — a registered contract client plugin owns the `<op>` functions and the consumer
49
+ * imports and calls them.
50
+ * - `error` — no client plugin is registered, several are registered without a selector, the
51
+ * requested one is missing, or `client` is not a known selector.
52
+ *
53
+ * The `client` string selects explicitly (`'fetch'` / `'axios'` / `'client'`); when it is unset a
54
+ * lone registered contract client plugin is picked up automatically.
55
+ */
56
+ const pluginFetchName = "plugin-fetch";
57
+ const pluginAxiosName = "plugin-axios";
58
+ const pluginClientName = "plugin-client";
59
+ const selectorToPlugin = {
60
+ fetch: pluginFetchName,
61
+ axios: pluginAxiosName,
62
+ client: pluginClientName
63
+ };
64
+ const contractPlugins = [
65
+ pluginFetchName,
66
+ pluginAxiosName,
67
+ pluginClientName
68
+ ];
69
+ /**
70
+ * Applies the `client` resolution rules. See the module comment for the strategy shape.
71
+ *
72
+ * @example
73
+ * ```ts
74
+ * resolveClient({ client: 'fetch', pluginNames: ['plugin-ts', 'plugin-fetch'] })
75
+ * // { kind: 'contract', pluginName: 'plugin-fetch' }
76
+ * ```
77
+ *
78
+ * @example
79
+ * ```ts
80
+ * resolveClient({ client: undefined, pluginNames: ['plugin-ts'] })
81
+ * // { kind: 'error', code: 'KUBB_MISSING_DEPENDENCY', message: 'No client plugin is registered.', help: 'Add …' }
82
+ * ```
83
+ */
84
+ function resolveClient(options) {
85
+ const { client, pluginNames } = options;
86
+ const has = (name) => pluginNames.includes(name);
87
+ if (client === "fetch" || client === "axios" || client === "client") {
88
+ const pluginName = selectorToPlugin[client];
89
+ if (!has(pluginName)) return {
90
+ kind: "error",
91
+ code: _kubb_kit.Diagnostics.code.missingDependency,
92
+ message: `\`client: '${client}'\` is set but \`@kubb/plugin-${client}\` is not registered in \`plugins\`.`,
93
+ help: `Add \`@kubb/plugin-${client}\` to \`plugins\`, or drop \`client\` to use a different client plugin.`
94
+ };
95
+ return {
96
+ kind: "contract",
97
+ pluginName
98
+ };
99
+ }
100
+ if (client !== void 0) return {
101
+ kind: "error",
102
+ code: _kubb_kit.Diagnostics.code.invalidPluginOptions,
103
+ message: `Option \`client\` is ${typeof client === "string" ? `'${client}'` : String(client)}, but it must be one of 'fetch', 'axios', 'client'.`,
104
+ help: "Set `client` to one of those values, or drop it to use the registered client plugin."
105
+ };
106
+ const registered = contractPlugins.filter(has);
107
+ if (registered.length === 1) return {
108
+ kind: "contract",
109
+ pluginName: registered[0]
110
+ };
111
+ if (registered.length > 1) return {
112
+ kind: "error",
113
+ code: _kubb_kit.Diagnostics.code.invalidPluginOptions,
114
+ message: `Multiple client plugins are registered (${registered.map((name) => `\`@kubb/${name}\``).join(", ")}) and \`client\` is not set.`,
115
+ help: "Set `client: 'fetch' | 'axios' | 'client'` to choose which client the hooks call, or register a single client plugin."
116
+ };
117
+ return {
118
+ kind: "error",
119
+ code: _kubb_kit.Diagnostics.code.missingDependency,
120
+ message: "No client plugin is registered.",
121
+ help: "Add `@kubb/plugin-fetch`, `@kubb/plugin-axios`, or `@kubb/plugin-client` to `plugins` so the generated code has an HTTP client to call."
122
+ };
123
+ }
124
+ /**
125
+ * Resolves the contract client during a consumer plugin's setup hook.
126
+ * It extracts the plugin names from the raw `plugins` config and applies {@link resolveClient}.
127
+ * On a misconfiguration it throws a config diagnostic tagged with `plugin`, so every consumer
128
+ * fails fast with the same message.
129
+ */
130
+ function resolveContractClient(options) {
131
+ const { plugin, client, plugins = [] } = options;
132
+ const resolved = resolveClient({
133
+ client,
134
+ pluginNames: plugins.map((plugin) => plugin.name).filter((name) => Boolean(name))
135
+ });
136
+ if (resolved.kind === "error") {
137
+ const { code, message, help } = resolved;
138
+ throw new _kubb_kit.Diagnostics.Error({
139
+ code,
140
+ severity: "error",
141
+ message,
142
+ help,
143
+ location: { kind: "config" },
144
+ plugin
145
+ });
146
+ }
147
+ return resolved;
148
+ }
149
+ // ../../internals/utils/src/reserved.ts
150
+ /**
151
+ * JavaScript and Java reserved words.
152
+ * @link https://github.com/jonschlinkert/reserved/blob/master/index.js
153
+ */
154
+ const reservedWords = /* @__PURE__ */ new Set([
155
+ "abstract",
156
+ "arguments",
157
+ "await",
158
+ "boolean",
159
+ "break",
160
+ "byte",
161
+ "case",
162
+ "catch",
163
+ "char",
164
+ "class",
165
+ "const",
166
+ "continue",
167
+ "debugger",
168
+ "default",
169
+ "delete",
170
+ "do",
171
+ "double",
172
+ "else",
173
+ "enum",
174
+ "eval",
175
+ "export",
176
+ "extends",
177
+ "false",
178
+ "final",
179
+ "finally",
180
+ "float",
181
+ "for",
182
+ "function",
183
+ "goto",
184
+ "if",
185
+ "implements",
186
+ "import",
187
+ "in",
188
+ "instanceof",
189
+ "int",
190
+ "interface",
191
+ "let",
192
+ "long",
193
+ "native",
194
+ "new",
195
+ "null",
196
+ "package",
197
+ "private",
198
+ "protected",
199
+ "public",
200
+ "return",
201
+ "short",
202
+ "static",
203
+ "super",
204
+ "switch",
205
+ "synchronized",
206
+ "this",
207
+ "throw",
208
+ "throws",
209
+ "transient",
210
+ "true",
211
+ "try",
212
+ "typeof",
213
+ "var",
214
+ "void",
215
+ "volatile",
216
+ "while",
217
+ "with",
218
+ "yield",
219
+ "Array",
220
+ "Date",
221
+ "hasOwnProperty",
222
+ "Infinity",
223
+ "isFinite",
224
+ "isNaN",
225
+ "isPrototypeOf",
226
+ "length",
227
+ "Math",
228
+ "name",
229
+ "NaN",
230
+ "Number",
231
+ "Object",
232
+ "prototype",
233
+ "String",
234
+ "toString",
235
+ "undefined",
236
+ "valueOf"
237
+ ]);
238
+ /**
239
+ * Returns `true` when `name` is a syntactically valid JavaScript variable name.
240
+ *
241
+ * @example
242
+ * ```ts
243
+ * isValidVarName('status') // true
244
+ * isValidVarName('class') // false (reserved word)
245
+ * isValidVarName('42foo') // false (starts with digit)
246
+ * ```
247
+ */
248
+ function isValidVarName(name) {
249
+ if (!name || reservedWords.has(name)) return false;
250
+ return isIdentifier(name);
251
+ }
252
+ /**
253
+ * Returns `name` when it's a syntactically valid JavaScript variable name,
254
+ * otherwise prefixes it with `_` so the result is a valid identifier.
255
+ *
256
+ * Useful for sanitizing OpenAPI schema names or operation IDs that start with
257
+ * a digit (e.g. `409`, `504AccountCancel`) before using them as exported
258
+ * variable, type, or function names.
259
+ *
260
+ * @example
261
+ * ```ts
262
+ * ensureValidVarName('409') // '_409'
263
+ * ensureValidVarName('504AccountCancel') // '_504AccountCancel'
264
+ * ensureValidVarName('Pet') // 'Pet'
265
+ * ensureValidVarName('class') // '_class'
266
+ * ```
267
+ */
268
+ function ensureValidVarName(name) {
269
+ if (!name || isValidVarName(name)) return name;
270
+ return `_${name}`;
271
+ }
272
+ /**
273
+ * Returns `true` when `name` is syntactically a valid identifier, ignoring reserved words.
274
+ *
275
+ * Reserved words and globals (`class`, `name`, `Date`, …) are valid as bare object-literal keys
276
+ * even though they are not valid variable names, so use this (not {@link isValidVarName}) when
277
+ * deciding whether an object key needs quoting.
278
+ *
279
+ * @example
280
+ * ```ts
281
+ * isIdentifier('name') // true
282
+ * isIdentifier('x-total')// false
283
+ * ```
284
+ */
285
+ function isIdentifier(name) {
286
+ return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);
287
+ }
288
+ // ../../internals/utils/src/strings.ts
289
+ /**
290
+ * Renders a dotted path or string array as an optional-chaining accessor expression rooted at
291
+ * `accessor`. Returns `null` for an empty path.
292
+ *
293
+ * @example
294
+ * ```ts
295
+ * getNestedAccessor('pagination.next.id', 'lastPage')
296
+ * // "lastPage?.['pagination']?.['next']?.['id']"
297
+ * ```
298
+ */
299
+ function getNestedAccessor(param, accessor) {
300
+ const parts = Array.isArray(param) ? param : param.split(".");
301
+ if (parts.length === 0 || parts.length === 1 && parts[0] === "") return null;
302
+ return `${accessor}?.['${`${parts.join("']?.['")}']`}`;
303
+ }
304
+ /**
305
+ * Escapes an `@` at the start of a line, so a multi-line description can't start a new JSDoc tag.
306
+ * Editors render `\@` as `@` in hovers.
307
+ *
308
+ * @example
309
+ * ```ts
310
+ * jsDocEscape('intro\n@example value') // 'intro\n\\@example value'
311
+ * ```
312
+ */
313
+ function jsDocEscape(input) {
314
+ return `${input}`.replace(/^(\s*)@/gm, "$1\\@");
315
+ }
33
316
  // ../../internals/shared/src/operation.ts
34
317
  /**
35
318
  * Builds the `ResolverFileParams` every operation generator passes to
@@ -51,29 +334,55 @@ function operationFileEntry(node, name, extname = ".ts") {
51
334
  };
52
335
  }
53
336
  /**
54
- * Resolves a dependency plugin's generated file for `node.operationId`, cached in `memo` (the
55
- * build's `ctx.memo`) under the resolver's own plugin name and the operation. Several dependents reading the
56
- * same dependency for the same operation in one pass (a query plugin's several hook generators, the
57
- * MCP handler, ...) share one computed name and path instead of each calling `resolver.file` again.
337
+ * Resolves the file a schema-emitting plugin (`plugin-ts`, `plugin-zod`, `plugin-faker`) writes
338
+ * `node` to, cached in `ctx.memo` under the resolver's plugin name and the
339
+ * operation. The plugin itself and every plugin that imports from it call this, so they all get
340
+ * the same path.
341
+ *
342
+ * When that path matches the file of a component schema in `ctx.driver.inputNode`, ignoring case, the file name
343
+ * gets an `Operation` suffix: operation `point` goes to `PointOperation.ts` next to schema `Point.ts`.
344
+ * Otherwise the two merge into one file, or overwrite each other on a case-insensitive file system.
345
+ * Only the file name changes. The declarations keep their names.
58
346
  *
59
- * @example Cache `plugin-ts`'s file for the current operation
347
+ * @example Resolve `plugin-ts`'s file for the current operation
60
348
  * ```ts
61
- * const fileTs = resolveDependencyOperationFile({ memo: ctx.memo, node, resolver: tsResolver, root, output })
349
+ * const fileTs = resolveOperationFile({ ctx, node, resolver: tsResolver, root, output })
62
350
  * ```
63
351
  */
64
- function resolveDependencyOperationFile(options) {
65
- const { memo, node, resolver, root, output, group } = options;
66
- return memo(`${resolver.pluginName}:operationFile:${node.operationId}`, () => resolver.file({
67
- ...operationFileEntry(node, node.operationId),
352
+ function resolveOperationFile(options) {
353
+ const { ctx, node, resolver, root, output } = options;
354
+ const { memo } = ctx;
355
+ const location = {
68
356
  root,
69
357
  output,
70
- group: group ?? void 0
71
- }));
358
+ group: options.group ?? void 0
359
+ };
360
+ return memo(`${resolver.pluginName}:operationFile:${node.operationId}`, () => {
361
+ const schemaPaths = memo(`${resolver.pluginName}:schemaFilePaths`, () => new Set((ctx.driver.inputNode?.schemas ?? []).flatMap((schema) => schema.name ? [resolver.file({
362
+ name: schema.name,
363
+ extname: ".ts",
364
+ ...location
365
+ }).path.toLowerCase()] : [])));
366
+ let file = resolver.file({
367
+ ...operationFileEntry(node, node.operationId),
368
+ ...location
369
+ });
370
+ for (let name = `${node.operationId}Operation`; schemaPaths.has(file.path.toLowerCase()); name += "Operation") {
371
+ const next = resolver.file({
372
+ ...operationFileEntry(node, name),
373
+ ...location
374
+ });
375
+ if (next.path === file.path) break;
376
+ file = next;
377
+ }
378
+ return file;
379
+ });
72
380
  }
73
- function getOperationLink(node, link) {
74
- if (!link) return null;
75
- if (typeof link === "function") return link(node) ?? null;
76
- return node.path ? `{@link ${_kubb_kit.Url.toPath(node.path)}}` : null;
381
+ /**
382
+ * The operation's method and path as plain text, such as `` `GET /pet/{petId}` ``. A path is not a valid `{@link}` target.
383
+ */
384
+ function getOperationRequestLine(node) {
385
+ return _kubb_kit.ast.http.isOperation(node) && node.path ? `\`${node.method.toUpperCase()} ${node.path}\`` : null;
77
386
  }
78
387
  /**
79
388
  * Derives the shared `ContentTypeInfo` shape from a list of content types, tracking whether several
@@ -97,18 +406,7 @@ function getContentTypeInfo(node) {
97
406
  * whether several are present, so the client can let a caller pick which one to accept.
98
407
  */
99
408
  function getResponseContentTypeInfo(node) {
100
- return buildContentTypeInfo(getPrimarySuccessResponse(node)?.content?.map((e) => e.contentType) ?? []);
101
- }
102
- function baseContentType(contentType) {
103
- return contentType.split(";")[0].trim().toLowerCase();
104
- }
105
- /**
106
- * Whether a content entry is a sequence of JSON values the adapter marks as a stream, such as `application/jsonl`,
107
- * `application/x-ndjson`, `application/json-seq`, or any media type with an OpenAPI 3.2 `itemSchema`.
108
- */
109
- function isJsonLines(entry) {
110
- const baseType = baseContentType(entry.contentType);
111
- return Boolean(entry.stream) && baseType !== "text/event-stream" && !baseType.startsWith("multipart/");
409
+ return buildContentTypeInfo(_kubb_kit.ast.http.responses.findPrimary(node)?.content?.map((e) => e.contentType) ?? []);
112
410
  }
113
411
  /**
114
412
  * How an operation streams its primary success response item by item, when that response declares one content type:
@@ -120,11 +418,19 @@ function isJsonLines(entry) {
120
418
  * call with its query hooks.
121
419
  */
122
420
  function getEventStream(node) {
123
- const content = getPrimarySuccessResponse(node)?.content ?? [];
421
+ const content = _kubb_kit.ast.http.responses.findPrimary(node)?.content ?? [];
124
422
  if (content.length !== 1) return null;
125
423
  const entry = content[0];
126
- if (baseContentType(entry.contentType) === "text/event-stream") return entry.stream?.shape ?? "data";
127
- return isJsonLines(entry) ? "line" : null;
424
+ const framing = getStreamFraming(entry);
425
+ if (framing === "events") return entry.stream?.shape ?? "data";
426
+ return framing === "lines" ? "line" : null;
427
+ }
428
+ /**
429
+ * How a content entry is framed as a stream: `'events'` for Server-Sent Events, `'lines'` for JSON Lines.
430
+ */
431
+ function getStreamFraming(entry) {
432
+ if (_kubb_kit.ast.mediaType.getBase(entry) === "text/event-stream") return "events";
433
+ return entry.stream && _kubb_kit.ast.mediaType.isStream(entry) ? "lines" : void 0;
128
434
  }
129
435
  /**
130
436
  * Whether an operation streams its primary success response, as Server-Sent Events or JSON Lines. The client generator uses
@@ -134,20 +440,42 @@ function isEventStream(node) {
134
440
  return getEventStream(node) !== null;
135
441
  }
136
442
  /**
443
+ * Whether a success response offers a stream media type next to other content types. The client returns that variant's
444
+ * body as a `ReadableStream`, so the stream runtime is registered and a hook's data type includes the stream.
445
+ */
446
+ function hasStreamVariant(node) {
447
+ return _kubb_kit.ast.http.responses.filterSuccess(node).some((response) => {
448
+ const variants = (response.content ?? []).filter((entry) => entry.schema);
449
+ return variants.length > 1 && variants.some((entry) => _kubb_kit.ast.mediaType.isStream(entry));
450
+ });
451
+ }
452
+ /**
137
453
  * Builds the `client?:` option type shared by the generated query hooks (`useQuery`,
138
- * `useInfiniteQuery`, `useSWR`, ...). Unlike {@link buildRequestConfigType}, it never adds a
139
- * `contentType?:` member: query hooks wrap GET operations, which carry no request body to select a
140
- * content type for. It drops the data-shape keys to stay assignable to `Options`, which omits them
141
- * from `RequestConfig`. `cookies` is a group only on an operation that declares one.
454
+ * `useInfiniteQuery`, `useSWR`, ...): `RequestConfig` minus what the
455
+ * hook fills in, which is every request group and `throwOnError`. Unlike {@link buildRequestConfigType},
456
+ * it never narrows `contentType`: query hooks wrap GET operations, which carry no request body to select
457
+ * a content type for.
142
458
  */
143
- function buildClientOptionType(node) {
144
- return `Partial<Omit<RequestConfig, 'path' | 'query' | 'body' | 'headers'${getOperationParameters(node).cookie.length > 0 ? ` | 'cookies'` : ""} | 'url'>>`;
459
+ function buildClientOptionType(options = {}) {
460
+ return `Partial<Omit<RequestConfig, ${[
461
+ ...requestGroupOrder,
462
+ "url",
463
+ ...options.omit ?? [],
464
+ "throwOnError"
465
+ ].map((key) => `'${key}'`).join(" | ")}>>`;
145
466
  }
467
+ /**
468
+ * The `client?:` option type of a mutation hook. When the operation has a request content type choice,
469
+ * the mutation variables carry `contentType`, so the config leaves it out. Otherwise the ambiguous side is
470
+ * narrowed to the operation's media types; a single-type side has nothing to pick, so it stays baked in the
471
+ * generated call.
472
+ */
146
473
  function buildRequestConfigType(node) {
474
+ if (hasRequestContentTypeChoice(node)) return buildClientOptionType({ omit: ["contentType"] });
147
475
  const request = getContentTypeInfo(node);
148
476
  const response = getResponseContentTypeInfo(node);
149
477
  const members = [request.isMultipleContentTypes ? `request?: ${request.contentTypeUnion}` : null, response.isMultipleContentTypes ? `response?: ${response.contentTypeUnion}` : null].filter(Boolean);
150
- const base = buildClientOptionType(node);
478
+ const base = buildClientOptionType();
151
479
  return members.length ? `${base} & { contentType?: { ${members.join("; ")} } }` : base;
152
480
  }
153
481
  /** The grouped request options, in the order generated signatures and calls list them. */
@@ -162,11 +490,11 @@ const requestGroupOrder = [
162
490
  * Which of the grouped request options an operation carries.
163
491
  */
164
492
  function getRequestGroups(node) {
165
- const { path, query, header, cookie } = getOperationParameters(node);
493
+ const { path, query, header, cookie } = _kubb_kit.ast.http.groupParameters(node);
166
494
  return {
167
495
  path: path.length > 0,
168
496
  query: query.length > 0,
169
- body: Boolean(node.requestBody?.content?.[0]?.schema),
497
+ body: Boolean(_kubb_kit.ast.http.requestBody.getSchema(node)),
170
498
  headers: header.length > 0,
171
499
  cookies: cookie.length > 0
172
500
  };
@@ -178,7 +506,7 @@ function getRequestGroups(node) {
178
506
  */
179
507
  function getRequestGroupOptionality(node) {
180
508
  const groups = getRequestGroups(node);
181
- const { path, query, header } = getOperationParameters(node);
509
+ const { path, query, header } = _kubb_kit.ast.http.groupParameters(node);
182
510
  const hasRequiredPath = path.some((param) => param.required);
183
511
  const hasRequiredQuery = query.some((param) => param.required);
184
512
  const hasRequiredHeader = header.some((param) => param.required);
@@ -191,104 +519,28 @@ function getRequestGroupOptionality(node) {
191
519
  };
192
520
  }
193
521
  function buildOperationComments(node, options = {}) {
194
- const { link = "pathTemplate", linkPosition = "afterDeprecated", splitLines = false } = options;
195
- const linkComment = getOperationLink(node, link);
196
- const filteredComments = (linkPosition === "beforeDeprecated" ? [
197
- node.description && `@description ${node.description}`,
198
- node.summary && `@summary ${node.summary}`,
199
- linkComment,
200
- node.deprecated && "@deprecated"
201
- ] : [
522
+ const { splitLines = false } = options;
523
+ const filteredComments = [
524
+ getOperationRequestLine(node),
202
525
  node.description && `@description ${node.description}`,
203
526
  node.summary && `@summary ${node.summary}`,
204
527
  node.deprecated && "@deprecated",
205
- linkComment
206
- ]).filter((comment) => Boolean(comment));
528
+ node.externalDocs && `@see ${jsDocEscape([node.externalDocs.url, node.externalDocs.description].filter(Boolean).join(" "))}`
529
+ ].filter((comment) => Boolean(comment));
207
530
  if (!splitLines) return filteredComments;
208
531
  return filteredComments.flatMap((text) => text.split(/\r?\n/).map((line) => line.trim())).filter((comment) => Boolean(comment));
209
532
  }
210
- const operationParameterGroupsByNode = /* @__PURE__ */ new WeakMap();
211
- /**
212
- * An OpenAPI 3.2 `querystring` parameter is the whole query string, so a form-encoded object becomes one query parameter
213
- * per property, typed and serialized like any other.
214
- * Another content type, such as JSON, stays one parameter named after it, and the runtime sends its value as the whole query string.
215
- */
216
- function spreadQuerystring(param) {
217
- const schema = param.schema.type === "ref" ? param.schema.schema : param.schema;
218
- const formEncoded = !param.contentType || param.contentType.split(";")[0].trim().toLowerCase() === "application/x-www-form-urlencoded";
219
- if (schema?.type !== "object" || !formEncoded) return [param];
220
- return schema.properties.map((property) => _kubb_kit.ast.factory.createParameter({
221
- name: property.name,
222
- in: "query",
223
- schema: property.schema,
224
- required: param.required && property.required
225
- }));
226
- }
227
- /**
228
- * Groups an operation's parameters by location (`path`/`query`/`header`/`cookie`), deduping each
229
- * group by name. Every plugin generator visiting the same `OperationNode` shares one AST instance
230
- * (see `KubbDriver`), so the result is cached per node to avoid re-filtering and re-deduping the
231
- * same parameters once per plugin.
232
- */
233
- function getOperationParameters(node) {
234
- const cached = operationParameterGroupsByNode.get(node);
235
- if (cached) return cached;
236
- const dedupe = (params) => {
237
- const seen = /* @__PURE__ */ new Set();
238
- return params.filter((param) => {
239
- if (seen.has(param.name)) return false;
240
- seen.add(param.name);
241
- return true;
242
- });
243
- };
244
- const group = (location) => dedupe(node.parameters.filter((param) => param.in === location));
245
- const groups = {
246
- path: group("path"),
247
- query: dedupe([...group("query"), ...group("querystring").flatMap(spreadQuerystring)]),
248
- header: group("header"),
249
- cookie: group("cookie")
250
- };
251
- operationParameterGroupsByNode.set(node, groups);
252
- return groups;
253
- }
254
533
  /**
255
534
  * Whether the operation declares more than one request media type with a schema, so a caller must pick one on `contentType`.
256
535
  */
257
536
  function hasRequestContentTypeChoice(node) {
258
537
  return (node.requestBody?.content ?? []).filter((entry) => entry.schema).length > 1;
259
538
  }
260
- /**
261
- * Casts a call argument to the client's parameter type; a `'plain'` client is non-generic.
262
- */
263
- function castToClientOptions(callArg, clientName, returnType = "full") {
264
- return `${callArg} as Parameters<typeof ${clientName}${returnType === "plain" ? "" : "<true>"}>[0]`;
265
- }
266
- function getStatusCodeNumber(statusCode) {
267
- const code = Number(statusCode);
268
- return Number.isNaN(code) ? null : code;
269
- }
270
- function isSuccessStatusCode(statusCode) {
271
- const code = getStatusCodeNumber(statusCode);
272
- return code !== null && code >= 200 && code < 300;
273
- }
274
- function isErrorStatusCode(statusCode) {
275
- const code = getStatusCodeNumber(statusCode);
276
- return code !== null && code >= 400;
277
- }
278
- function getSuccessResponses(responses) {
279
- return responses.filter((response) => isSuccessStatusCode(response.statusCode));
280
- }
281
- function getOperationSuccessResponses(node) {
282
- return getSuccessResponses(node.responses);
283
- }
284
- function getPrimarySuccessResponse(node) {
285
- return getOperationSuccessResponses(node)[0] ?? null;
286
- }
287
539
  function resolveErrorNames(node, resolver) {
288
- return node.responses.filter((response) => isErrorStatusCode(response.statusCode)).map((response) => resolver.response.status(node, response.statusCode));
540
+ return _kubb_kit.ast.http.responses.filterError(node).map((response) => resolver.response.status(node, response.statusCode));
289
541
  }
290
542
  function resolveSuccessNames(node, resolver) {
291
- return node.responses.filter((response) => isSuccessStatusCode(response.statusCode)).map((response) => resolver.response.status(node, response.statusCode));
543
+ return _kubb_kit.ast.http.responses.filterSuccess(node).map((response) => resolver.response.status(node, response.statusCode));
292
544
  }
293
545
  function resolveStatusCodeNames(node, resolver) {
294
546
  return node.responses.map((response) => resolver.response.status(node, response.statusCode));
@@ -300,7 +552,7 @@ function resolveStatusCodeNames(node, resolver) {
300
552
  function resolveOperationTypeNames(node, resolver, options = {}) {
301
553
  const key = `${node.operationId}\0${options.order ?? ""}\0${options.responseStatusNames ?? ""}\0${options.includeParams === false ? "noparams" : ""}\0${(options.exclude ?? []).join(",")}`;
302
554
  return resolver.memo(`operationTypeNames:${key}`, () => {
303
- const { path, query, header, cookie } = getOperationParameters(node);
555
+ const { path, query, header, cookie } = _kubb_kit.ast.http.groupParameters(node);
304
556
  const responseStatusNames = options.responseStatusNames === "error" ? resolveErrorNames(node, resolver) : options.responseStatusNames === false ? [] : resolveStatusCodeNames(node, resolver);
305
557
  const exclude = new Set(options.exclude ?? []);
306
558
  const paramNames = options.includeParams === false ? [] : [
@@ -309,7 +561,7 @@ function resolveOperationTypeNames(node, resolver, options = {}) {
309
561
  ...header.map((param) => resolver.param.headers(node, param)),
310
562
  ...cookie.map((param) => resolver.param.cookies(node, param))
311
563
  ];
312
- const bodyAndResponseNames = [node.requestBody?.content?.[0]?.schema ? resolver.response.body(node) : null, resolver.response.response(node)];
564
+ const bodyAndResponseNames = [_kubb_kit.ast.http.requestBody.getSchema(node) ? resolver.response.body(node) : null, resolver.response.response(node)];
313
565
  return (options.order === "body-response-first" ? [
314
566
  ...bodyAndResponseNames,
315
567
  ...paramNames,
@@ -321,235 +573,139 @@ function resolveOperationTypeNames(node, resolver, options = {}) {
321
573
  ]).filter((name) => Boolean(name) && !exclude.has(name));
322
574
  });
323
575
  }
324
- // ../../internals/utils/src/casing.ts
325
- /**
326
- * Uppercases only the first character of `text`, leaving the rest untouched.
327
- * Unlike `pascalCase` it never re-splits word boundaries or strips characters.
328
- *
329
- * @example
330
- * `capitalize('getPetById') // 'GetPetById'`
331
- */
332
- function capitalize(text) {
333
- return `${text.charAt(0).toUpperCase()}${text.slice(1)}`;
334
- }
335
- // ../../internals/utils/src/reserved.ts
336
- /**
337
- * JavaScript and Java reserved words.
338
- * @link https://github.com/jonschlinkert/reserved/blob/master/index.js
339
- */
340
- const reservedWords = /* @__PURE__ */ new Set([
341
- "abstract",
342
- "arguments",
343
- "await",
344
- "boolean",
345
- "break",
346
- "byte",
347
- "case",
348
- "catch",
349
- "char",
350
- "class",
351
- "const",
352
- "continue",
353
- "debugger",
354
- "default",
355
- "delete",
356
- "do",
357
- "double",
358
- "else",
359
- "enum",
360
- "eval",
361
- "export",
362
- "extends",
363
- "false",
364
- "final",
365
- "finally",
366
- "float",
367
- "for",
368
- "function",
369
- "goto",
370
- "if",
371
- "implements",
372
- "import",
373
- "in",
374
- "instanceof",
375
- "int",
376
- "interface",
377
- "let",
378
- "long",
379
- "native",
380
- "new",
381
- "null",
382
- "package",
383
- "private",
384
- "protected",
385
- "public",
386
- "return",
387
- "short",
388
- "static",
389
- "super",
390
- "switch",
391
- "synchronized",
392
- "this",
393
- "throw",
394
- "throws",
395
- "transient",
396
- "true",
397
- "try",
398
- "typeof",
399
- "var",
400
- "void",
401
- "volatile",
402
- "while",
403
- "with",
404
- "yield",
405
- "Array",
406
- "Date",
407
- "hasOwnProperty",
408
- "Infinity",
409
- "isFinite",
410
- "isNaN",
411
- "isPrototypeOf",
412
- "length",
413
- "Math",
414
- "name",
415
- "NaN",
416
- "Number",
417
- "Object",
418
- "prototype",
419
- "String",
420
- "toString",
421
- "undefined",
422
- "valueOf"
423
- ]);
576
+ // ../../internals/shared/src/resolver.ts
424
577
  /**
425
- * Returns `true` when `name` is a syntactically valid JavaScript variable name.
426
- *
427
- * @example
428
- * ```ts
429
- * isValidVarName('status') // true
430
- * isValidVarName('class') // false (reserved word)
431
- * isValidVarName('42foo') // false (starts with digit)
432
- * ```
578
+ * The shared top-level `name` of the operation plugins, computed once per operation name and build.
433
579
  */
434
- function isValidVarName(name) {
435
- if (!name || reservedWords.has(name)) return false;
436
- return isIdentifier(name);
580
+ function resolveOperationName(name) {
581
+ return this.memo(`operation:${name}`, () => ensureValidVarName(_kubb_kit.casing.camel(name)));
437
582
  }
438
583
  /**
439
- * Returns `name` when it's a syntactically valid JavaScript variable name,
440
- * otherwise prefixes it with `_` so the result is a valid identifier.
584
+ * Builds the allocation key for a declaration an operation owns. `scope` names which declaration
585
+ * it is, so two of them never share an allocation even when a custom resolver gives both the same
586
+ * name. Leave `scope` empty for the operation's own declaration.
441
587
  *
442
- * Useful for sanitizing OpenAPI schema names or operation IDs that start with
443
- * a digit (e.g. `409`, `504AccountCancel`) before using them as exported
444
- * variable, type, or function names.
588
+ * The key starts from the operation's input `pointer`, which macros keep, so a plugin whose macro
589
+ * rewrites the method or path still resolves another plugin's names for the same operation.
445
590
  *
446
591
  * @example
447
592
  * ```ts
448
- * ensureValidVarName('409') // '_409'
449
- * ensureValidVarName('504AccountCancel') // '_504AccountCancel'
450
- * ensureValidVarName('Pet') // 'Pet'
451
- * ensureValidVarName('class') // '_class'
593
+ * resolver.resolveName({ key: operationKey(node, 'response', 'status', 404), name })
452
594
  * ```
453
595
  */
454
- function ensureValidVarName(name) {
455
- if (!name || isValidVarName(name)) return name;
456
- return `_${name}`;
596
+ function operationKey(node, ...scope) {
597
+ return [
598
+ "operation",
599
+ ...node.pointer ? [node.pointer] : [node.method, node.path],
600
+ ...scope.map(String)
601
+ ];
602
+ }
603
+ // ../../internals/client/src/resolveClientOperation.ts
604
+ function isRelativeImport(importPath) {
605
+ return importPath.startsWith(".");
606
+ }
607
+ function resolveImportPath(options) {
608
+ const { importPath, operationFile } = options;
609
+ return isRelativeImport(importPath) ? node_path.default.resolve(node_path.default.dirname(operationFile), importPath) : importPath;
457
610
  }
458
611
  /**
459
- * Returns `true` when `name` is syntactically a valid identifier, ignoring reserved words.
612
+ * Resolves the contract client `<op>` a consumer (query hook, MCP handler) imports, by looking up
613
+ * the registered contract client plugin's resolver and output. Works for any contract client plugin
614
+ * (plugin-fetch, plugin-axios, or plugin-client). Returns `null` when no contract plugin is in play (the inline
615
+ * path), or when the client plugin's `exclude` / `include` leaves this operation out, since it then
616
+ * emits no `<op>` to import. plugin-fetch / plugin-axios inject `.kubb/client.ts` at the global
617
+ * output root, the same path consumers read `RequestConfig` / `ResponseErrorConfig` from.
618
+ * With plugin-client they come from the user's `importPath` module instead.
460
619
  *
461
- * Reserved words and globals (`class`, `name`, `Date`, …) are valid as bare object-literal keys
462
- * even though they are not valid variable names, so use this (not {@link isValidVarName}) when
463
- * deciding whether an object key needs quoting.
620
+ * The result is cached in `memo` (the build's `ctx.memo`) under the client plugin's name and the operation,
621
+ * so several dependents reading the same client plugin for one operation in a single pass
622
+ * (react-query's query/mutation/infinite generators, vue-query, swr, the MCP handler, ...) share
623
+ * one computed result instead of each re-deriving the name and path.
464
624
  *
465
- * @example
466
- * ```ts
467
- * isIdentifier('name') // true
468
- * isIdentifier('x-total')// false
469
- * ```
625
+ * `returnType`, `output`, and `group` are the client plugin's options for this operation, after its
626
+ * `override` entries, the same resolution its own generator sees. A dependent's generated call body
627
+ * and import path therefore match the `<op>` actually emitted, even when an `override` changes it.
470
628
  */
471
- function isIdentifier(name) {
472
- return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);
629
+ function resolveClientOperation(options) {
630
+ const { clientPlugin, driver, node, root, output, memo } = options;
631
+ if (!clientPlugin) return null;
632
+ return memo(`${clientPlugin.pluginName}:clientOperation:${node.operationId}`, () => {
633
+ const resolver = driver.getResolver(clientPlugin.pluginName);
634
+ const pluginOptions = driver.getPlugin(clientPlugin.pluginName)?.options ?? {};
635
+ const { exclude, include, override } = pluginOptions;
636
+ const operationOptions = Boolean(exclude?.length || include?.length || override?.length) && resolver.default ? resolver.default.options(node, {
637
+ options: pluginOptions,
638
+ exclude,
639
+ include,
640
+ override
641
+ }) : pluginOptions;
642
+ if (!operationOptions) return null;
643
+ const file = resolver.file({
644
+ ...operationFileEntry(node, node.operationId),
645
+ root,
646
+ output: operationOptions.output ?? output,
647
+ group: operationOptions.group ?? void 0
648
+ });
649
+ const { importPath } = operationOptions;
650
+ const name = resolver.name(node.operationId);
651
+ return {
652
+ name: resolver.resolveName({
653
+ key: operationKey(node),
654
+ name
655
+ }),
656
+ path: file.path,
657
+ clientPath: importPath === void 0 ? node_path.default.resolve(root, ".kubb/client.ts") : resolveImportPath({
658
+ importPath,
659
+ operationFile: file.path
660
+ }),
661
+ clientPathIsFile: importPath === void 0 || isRelativeImport(importPath),
662
+ returnType: operationOptions.returnType ?? "full",
663
+ typedHeaders: importPath === void 0
664
+ };
665
+ });
666
+ }
667
+ // ../../internals/client/src/resolveOperationTypes.ts
668
+ const pluginZodName = "plugin-zod";
669
+ function getResponseHeadersEntries({ node, types }) {
670
+ const resolve = types.response.headers;
671
+ if (!resolve) return [];
672
+ return node.responses.filter((response) => response.headers?.length).map((response) => [response.statusCode, resolve.call(types.response, node, response.statusCode)]);
473
673
  }
474
- // ../../internals/utils/src/strings.ts
475
674
  /**
476
- * Renders a dotted path or string array as an optional-chaining accessor expression rooted at
477
- * `accessor`. Returns `null` for an empty path.
478
- *
479
- * @example
480
- * ```ts
481
- * getNestedAccessor('pagination.next.id', 'lastPage')
482
- * // "lastPage?.['pagination']?.['next']?.['id']"
483
- * ```
675
+ * The headers type argument of `RequestResult`, such as `{ '200': LoginUserStatus200Headers }`, or `null` when no response declares headers.
484
676
  */
485
- function getNestedAccessor(param, accessor) {
486
- const parts = Array.isArray(param) ? param : param.split(".");
487
- if (parts.length === 0 || parts.length === 1 && parts[0] === "") return null;
488
- return `${accessor}?.['${`${parts.join("']?.['")}']`}`;
677
+ function buildResponseHeadersType({ node, types }) {
678
+ const entries = getResponseHeadersEntries({
679
+ node,
680
+ types
681
+ }).map(([statusCode, name]) => `'${statusCode}': ${name}`);
682
+ return entries.length ? `{ ${entries.join("; ")} }` : null;
489
683
  }
490
- // ../../internals/shared/src/resolver.ts
491
684
  /**
492
- * The shared top-level `name` of the operation plugins, computed once per operation name and build.
685
+ * A runtime result type, such as `RequestResult`, in its `WithHeaders` form when `headers` is set.
493
686
  */
494
- function resolveOperationName(name) {
495
- return this.memo(`operation:${name}`, () => ensureValidVarName((0, _kubb_kit.camelCase)(name)));
687
+ function resultTypeName(name, headers) {
688
+ return headers ? `${name}WithHeaders` : name;
496
689
  }
497
690
  /**
498
- * Builds the allocation key for a declaration an operation owns. `scope` names which declaration
499
- * it is, so two of them never share an allocation even when a custom resolver gives both the same
500
- * name. Leave `scope` empty for the operation's own declaration.
501
- *
502
- * @example
503
- * ```ts
504
- * resolver.resolveName({ key: operationKey(node, 'response', 'status', 404), name })
505
- * ```
691
+ * A runtime result type with its arguments, such as `RequestResultWithHeaders<Responses, Headers, ThrowOnError>`.
506
692
  */
507
- function operationKey(node, ...scope) {
508
- return [
509
- "operation",
510
- node.method,
511
- node.path,
512
- ...scope.map(String)
513
- ];
693
+ function buildResultTypeRef(name, responses, headers, rest = []) {
694
+ return `${resultTypeName(name, headers !== null)}<${[
695
+ responses,
696
+ headers,
697
+ ...rest
698
+ ].filter(Boolean).join(", ")}>`;
514
699
  }
515
- // ../../internals/shared/src/group.ts
516
700
  /**
517
- * Builds the `group` config a Kubb plugin passes to `ctx.setOptions`, applying the
518
- * shared default naming so every plugin groups output consistently:
519
- *
520
- * - `path` groups use the second path segment (`/pet/findByStatus` → `pet`).
521
- * - other groups use the camelCased group (`pet store` → `petStore`).
522
- *
523
- * A user-provided `group.name` always wins over the default namer, so callers stay in
524
- * control of their output folders. Returns `null` when grouping is disabled, matching the
525
- * per-plugin convention.
526
- *
527
- * @param group - The user-supplied group option, or `undefined` to disable grouping.
528
- *
529
- * @example
530
- * ```ts
531
- * createGroupConfig(group) // shared across every plugin
532
- * ```
701
+ * The names of the headers types `buildResponseHeadersType` references, for the file's imports.
533
702
  */
534
- function createGroupConfig(group) {
535
- if (!group) return null;
536
- const defaultName = (ctx) => {
537
- if (group.type === "path") return `${ctx.group.split("/")[1]}`;
538
- return (0, _kubb_kit.camelCase)(ctx.group);
539
- };
540
- return {
541
- ...group,
542
- name: group.name ? group.name : defaultName
543
- };
703
+ function getResponseHeadersTypeNames({ node, types }) {
704
+ return getResponseHeadersEntries({
705
+ node,
706
+ types
707
+ }).map(([, name]) => name);
544
708
  }
545
- // kubb-extension.json
546
- var compatibility = {
547
- "kubb": ">=5.16.0",
548
- "node": ">=22.22"
549
- };
550
- // package.json
551
- var version = "5.10.0-canary.20261109T201601";
552
- // ../../internals/client/src/resolveOperationTypes.ts
553
709
  /**
554
710
  * A `plugin-ts` shaped resolver whose operation type names point at the types `pluginZod({ inferred })`
555
711
  * exports next to each schema, so code written against `plugin-ts` names picks up the zod types.
@@ -572,6 +728,7 @@ function toZodTypeResolver(resolver) {
572
728
  status: (node, statusCode) => type(resolver.response.status(node, statusCode)),
573
729
  response: (node) => type(resolver.response.response(node)),
574
730
  responses: (node) => type(resolver.response.responses(node)),
731
+ headers: (node, statusCode) => type(resolver.response.headers(node, statusCode)),
575
732
  options: (node) => resolver.response.options(node)
576
733
  }
577
734
  };
@@ -592,7 +749,7 @@ function toZodTypeResolver(resolver) {
592
749
  function resolveOperationTypes(driver, pluginName) {
593
750
  return driver.memo(`operationTypes:${pluginName}`, () => {
594
751
  const pluginTs = driver.getPlugin(_kubb_plugin_ts.pluginTsName);
595
- const pluginZod = driver.getPlugin(_kubb_plugin_zod.pluginZodName);
752
+ const pluginZod = driver.getPlugin(pluginZodName);
596
753
  if (pluginTs && pluginZod?.options?.inferred !== "codec") {
597
754
  const resolver = driver.getResolver(_kubb_plugin_ts.pluginTsName);
598
755
  return {
@@ -610,7 +767,7 @@ function resolveOperationTypes(driver, pluginName) {
610
767
  location: { kind: "config" },
611
768
  plugin: pluginName
612
769
  });
613
- const resolver = toZodTypeResolver(driver.getResolver(_kubb_plugin_zod.pluginZodName));
770
+ const resolver = toZodTypeResolver(driver.getResolver(pluginZodName));
614
771
  return {
615
772
  response: resolver.response,
616
773
  resolver,
@@ -619,179 +776,6 @@ function resolveOperationTypes(driver, pluginName) {
619
776
  };
620
777
  });
621
778
  }
622
- // ../../internals/client/src/resolveClient.ts
623
- /**
624
- * Resolves which client plugin a consumer (react-query, vue-query, swr, mcp) should call for an
625
- * operation, shared so the selection rules and diagnostics stay in one place.
626
- *
627
- * Every client runtime lives in a dedicated client plugin, so a consumer always calls a registered
628
- * contract client plugin (plugin-fetch, plugin-axios, or plugin-client) and never emits its own
629
- * inline client:
630
- *
631
- * - `contract` — a registered contract client plugin owns the `<op>` functions and the consumer
632
- * imports and calls them.
633
- * - `error` — no client plugin is registered, several are registered without a selector, the
634
- * requested one is missing, or `client` is not a known selector.
635
- *
636
- * The `client` string selects explicitly (`'fetch'` / `'axios'` / `'client'`); when it is unset a
637
- * lone registered contract client plugin is picked up automatically.
638
- */
639
- const pluginFetchName = "plugin-fetch";
640
- const pluginAxiosName = "plugin-axios";
641
- const pluginClientName = "plugin-client";
642
- const selectorToPlugin = {
643
- fetch: pluginFetchName,
644
- axios: pluginAxiosName,
645
- client: pluginClientName
646
- };
647
- const contractPlugins = [
648
- pluginFetchName,
649
- pluginAxiosName,
650
- pluginClientName
651
- ];
652
- /**
653
- * Applies the `client` resolution rules. See the module comment for the strategy shape.
654
- *
655
- * @example
656
- * ```ts
657
- * resolveClient({ client: 'fetch', pluginNames: ['plugin-ts', 'plugin-fetch'] })
658
- * // { kind: 'contract', pluginName: 'plugin-fetch' }
659
- * ```
660
- *
661
- * @example
662
- * ```ts
663
- * resolveClient({ client: undefined, pluginNames: ['plugin-ts'] })
664
- * // { kind: 'error', code: 'KUBB_MISSING_DEPENDENCY', message: 'No client plugin is registered.', help: 'Add …' }
665
- * ```
666
- */
667
- function resolveClient(options) {
668
- const { client, pluginNames } = options;
669
- const has = (name) => pluginNames.includes(name);
670
- if (client === "fetch" || client === "axios" || client === "client") {
671
- const pluginName = selectorToPlugin[client];
672
- if (!has(pluginName)) return {
673
- kind: "error",
674
- code: _kubb_kit.Diagnostics.code.missingDependency,
675
- message: `\`client: '${client}'\` is set but \`@kubb/plugin-${client}\` is not registered in \`plugins\`.`,
676
- help: `Add \`@kubb/plugin-${client}\` to \`plugins\`, or drop \`client\` to use a different client plugin.`
677
- };
678
- return {
679
- kind: "contract",
680
- pluginName
681
- };
682
- }
683
- if (client !== void 0) return {
684
- kind: "error",
685
- code: _kubb_kit.Diagnostics.code.invalidPluginOptions,
686
- message: `Option \`client\` is ${typeof client === "string" ? `'${client}'` : String(client)}, but it must be one of 'fetch', 'axios', 'client'.`,
687
- help: "Set `client` to one of those values, or drop it to use the registered client plugin."
688
- };
689
- const registered = contractPlugins.filter(has);
690
- if (registered.length === 1) return {
691
- kind: "contract",
692
- pluginName: registered[0]
693
- };
694
- if (registered.length > 1) return {
695
- kind: "error",
696
- code: _kubb_kit.Diagnostics.code.invalidPluginOptions,
697
- message: `Multiple client plugins are registered (${registered.map((name) => `\`@kubb/${name}\``).join(", ")}) and \`client\` is not set.`,
698
- help: "Set `client: 'fetch' | 'axios' | 'client'` to choose which client the hooks call, or register a single client plugin."
699
- };
700
- return {
701
- kind: "error",
702
- code: _kubb_kit.Diagnostics.code.missingDependency,
703
- message: "No client plugin is registered.",
704
- help: "Add `@kubb/plugin-fetch`, `@kubb/plugin-axios`, or `@kubb/plugin-client` to `plugins` so the generated code has an HTTP client to call."
705
- };
706
- }
707
- /**
708
- * Resolves the contract client during a consumer plugin's setup hook.
709
- * It extracts the plugin names from the raw `plugins` config and applies {@link resolveClient}.
710
- * On a misconfiguration it throws a config diagnostic tagged with `plugin`, so every consumer
711
- * fails fast with the same message.
712
- */
713
- function resolveContractClient(options) {
714
- const { plugin, client, plugins = [] } = options;
715
- const resolved = resolveClient({
716
- client,
717
- pluginNames: plugins.map((plugin) => plugin.name).filter((name) => Boolean(name))
718
- });
719
- if (resolved.kind === "error") {
720
- const { code, message, help } = resolved;
721
- throw new _kubb_kit.Diagnostics.Error({
722
- code,
723
- severity: "error",
724
- message,
725
- help,
726
- location: { kind: "config" },
727
- plugin
728
- });
729
- }
730
- return resolved;
731
- }
732
- // ../../internals/client/src/resolveClientOperation.ts
733
- function isRelativeImport(importPath) {
734
- return importPath.startsWith(".");
735
- }
736
- function resolveImportPath(options) {
737
- const { importPath, operationFile } = options;
738
- return isRelativeImport(importPath) ? node_path.default.resolve(node_path.default.dirname(operationFile), importPath) : importPath;
739
- }
740
- /**
741
- * Resolves the contract client `<op>` a consumer (query hook, MCP handler) imports, by looking up
742
- * the registered contract client plugin's resolver and output. Works for any contract client plugin
743
- * (plugin-fetch, plugin-axios, or plugin-client). Returns `null` when no contract plugin is in play (the inline
744
- * path), or when the client plugin's `exclude` / `include` leaves this operation out, since it then
745
- * emits no `<op>` to import. plugin-fetch / plugin-axios inject `.kubb/client.ts` at the global
746
- * output root, the same path consumers read `RequestConfig` / `ResponseErrorConfig` from.
747
- * With plugin-client they come from the user's `importPath` module instead.
748
- *
749
- * The result is cached in `memo` (the build's `ctx.memo`) under the client plugin's name and the operation,
750
- * so several dependents reading the same client plugin for one operation in a single pass
751
- * (react-query's query/mutation/infinite generators, vue-query, swr, the MCP handler, ...) share
752
- * one computed result instead of each re-deriving the name and path.
753
- *
754
- * `returnType`, `output`, and `group` are the client plugin's options for this operation, after its
755
- * `override` entries, the same resolution its own generator sees. A dependent's generated call body
756
- * and import path therefore match the `<op>` actually emitted, even when an `override` changes it.
757
- */
758
- function resolveClientOperation(options) {
759
- const { clientPlugin, driver, node, root, output, memo } = options;
760
- if (!clientPlugin) return null;
761
- return memo(`${clientPlugin.pluginName}:clientOperation:${node.operationId}`, () => {
762
- const resolver = driver.getResolver(clientPlugin.pluginName);
763
- const pluginOptions = driver.getPlugin(clientPlugin.pluginName)?.options ?? {};
764
- const { exclude, include, override } = pluginOptions;
765
- const operationOptions = Boolean(exclude?.length || include?.length || override?.length) && resolver.default ? resolver.default.options(node, {
766
- options: pluginOptions,
767
- exclude,
768
- include,
769
- override
770
- }) : pluginOptions;
771
- if (!operationOptions) return null;
772
- const file = resolver.file({
773
- ...operationFileEntry(node, node.operationId),
774
- root,
775
- output: operationOptions.output ?? output,
776
- group: operationOptions.group ?? void 0
777
- });
778
- const { importPath } = operationOptions;
779
- const name = resolver.name(node.operationId);
780
- return {
781
- name: resolver.resolveName({
782
- key: operationKey(node),
783
- name
784
- }),
785
- path: file.path,
786
- clientPath: importPath === void 0 ? node_path.default.resolve(root, ".kubb/client.ts") : resolveImportPath({
787
- importPath,
788
- operationFile: file.path
789
- }),
790
- clientPathIsFile: importPath === void 0 || isRelativeImport(importPath),
791
- returnType: operationOptions.returnType ?? "full"
792
- };
793
- });
794
- }
795
779
  // ../../internals/tanstack-query/src/components/HookFile.tsx
796
780
  /**
797
781
  * Resolves what every TanStack hook file shares: its file, the operation types file and names (`@kubb/plugin-ts`, or
@@ -810,14 +794,18 @@ function resolveHookFile(node, ctx, options) {
810
794
  });
811
795
  const types = resolveOperationTypes(ctx.driver, resolver.pluginName);
812
796
  const tsResolver = types.resolver;
797
+ const headerTypeNames = returnType === "data" || !contractOp.typedHeaders ? [] : getResponseHeadersTypeNames({
798
+ node,
799
+ types: tsResolver
800
+ });
813
801
  const file = resolver.file({
814
802
  ...operationFileEntry(node, name),
815
803
  root,
816
804
  output,
817
805
  group: group ?? void 0
818
806
  });
819
- const fileTs = resolveDependencyOperationFile({
820
- memo: ctx.memo,
807
+ const fileTs = resolveOperationFile({
808
+ ctx,
821
809
  node,
822
810
  resolver: tsResolver,
823
811
  root,
@@ -827,6 +815,7 @@ function resolveHookFile(node, ctx, options) {
827
815
  const importedTypeNames = [
828
816
  tsResolver.response.options(node),
829
817
  tsResolver.response.responses(node),
818
+ ...headerTypeNames,
830
819
  ...extraTypeNames,
831
820
  ...resolveOperationTypeNames(node, tsResolver, {
832
821
  exclude: [keyTypeName, returnType !== "data" ? tsResolver.response.response(node) : null].filter((name) => Boolean(name)),
@@ -844,6 +833,7 @@ function resolveHookFile(node, ctx, options) {
844
833
  tsResolver,
845
834
  contractOp,
846
835
  importedTypeNames,
836
+ resultTypeName: headerTypeNames.length ? "RequestResultWithHeaders" : "RequestResult",
847
837
  returnType,
848
838
  banner: resolver.default.banner(ctx.meta, {
849
839
  output,
@@ -861,7 +851,7 @@ function resolveHookFile(node, ctx, options) {
861
851
  * The `<File>` shell shared by the TanStack hook generators; renders `children` after the imports.
862
852
  */
863
853
  function HookFile({ hook, imports, children }) {
864
- const { file, fileTs, contractOp, importedTypeNames, banner, footer } = hook;
854
+ const { file, fileTs, contractOp, importedTypeNames, resultTypeName, banner, footer } = hook;
865
855
  return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx.File, {
866
856
  baseName: file.baseName,
867
857
  path: file.path,
@@ -878,7 +868,7 @@ function HookFile({ hook, imports, children }) {
878
868
  name: [
879
869
  "RequestConfig",
880
870
  "ResponseErrorConfig",
881
- "RequestResult"
871
+ resultTypeName
882
872
  ],
883
873
  root: contractOp.clientPathIsFile ? file.path : void 0,
884
874
  path: contractOp.clientPath,
@@ -964,8 +954,8 @@ function buildGroupedRequestParam(node, options) {
964
954
  /**
965
955
  * Builds the shared `({ path, query, body, headers, cookies }, config = {})` parameter list for a
966
956
  * TanStack query-options function. The leading parameter mirrors the client signature, and the
967
- * trailing `config` is a partial `RequestConfig` minus the grouped data-shape keys, which are passed
968
- * explicitly. Framework plugins wrap the result when needed, for example vue-query applies `MaybeRefOrGetter`.
957
+ * trailing `config` is the client's `Options` minus the request groups and `throwOnError`, which the
958
+ * hook passes itself. Framework plugins wrap the result when needed, for example vue-query applies `MaybeRefOrGetter`.
969
959
  */
970
960
  function buildQueryOptionsParams(node, options) {
971
961
  const { resolver, memberTypeWrapper } = options;
@@ -975,7 +965,7 @@ function buildQueryOptionsParams(node, options) {
975
965
  });
976
966
  const configParam = (0, _kubb_plugin_ts.createFunctionParameter)({
977
967
  name: "config",
978
- type: buildClientOptionType(node),
968
+ type: buildClientOptionType(),
979
969
  default: "{}"
980
970
  });
981
971
  return (0, _kubb_plugin_ts.createFunctionParameters)({ params: [groupedParam, configParam].filter((param) => param !== null) });
@@ -987,26 +977,30 @@ function buildQueryOptionsParams(node, options) {
987
977
  * can't flip the query's error semantics. Queries thread the TanStack `signal`; mutations omit it.
988
978
  *
989
979
  * When `unwrapName` is set, each request group is passed as an explicit member unwrapped through it,
990
- * used by vue-query to resolve refs and getters with `toValue(...)` at call time.
980
+ * used by vue-query to resolve refs and getters with `toValue(...)` at call time. `pageParam` names the
981
+ * query parameter an infinite query sets from TanStack's `pageParam`.
991
982
  *
992
983
  * @example
993
984
  * ```ts
994
985
  * buildClientCall(node, { clientName: 'getPetById', signal: true })
995
- * // getPetById({ path, ...config, signal: config.signal ?? signal, throwOnError: true })
986
+ * // getPetById({ ...config, path, signal: config.signal ?? signal, throwOnError: true })
996
987
  * ```
997
988
  */
998
989
  function buildClientCall(node, options) {
999
- const { clientName, signal = false, unwrapName, withContentType = false, returnType = "full" } = options;
990
+ const { clientName, signal = false, unwrapName, withContentType = false, pageParam } = options;
1000
991
  const { groups } = getRequestGroupOptionality(node);
1001
992
  const names = requestGroupOrder.filter((key) => groups[key]);
1002
- const args = [
993
+ const member = (name) => {
994
+ const value = unwrapName ? unwrapName(name) : name;
995
+ if (name === "query" && pageParam) return `query: { ...${value}, ${JSON.stringify(pageParam)}: pageParam }`;
996
+ return unwrapName ? `${name}: ${value}` : name;
997
+ };
998
+ return `${clientName}({ ${[
1003
999
  "...config",
1004
- ...withContentType && hasRequestContentTypeChoice(node) ? ["...variables"] : names.map((name) => unwrapName ? `${name}: ${unwrapName(name)}` : name),
1000
+ ...withContentType && hasRequestContentTypeChoice(node) ? ["...variables"] : names.map(member),
1005
1001
  signal ? "signal: config.signal ?? signal" : null,
1006
1002
  "throwOnError: true"
1007
- ].filter((part) => part !== null);
1008
- if (withContentType && hasRequestContentTypeChoice(node)) return `${clientName}(${castToClientOptions(`{ ${args.join(", ")} }`, clientName, returnType)})`;
1009
- return `${clientName}({ ${args.join(", ")} })`;
1003
+ ].filter((part) => part !== null).join(", ")} })`;
1010
1004
  }
1011
1005
  /**
1012
1006
  * Builds the query/mutation body that resolves a `buildClientCall` expression down to the bare
@@ -1029,19 +1023,28 @@ function buildCallResultBody(call, options = {}) {
1029
1023
  if (clientReturnType === "plain") return `return (await ${call}).data`;
1030
1024
  return `return ${call}.unwrap()`;
1031
1025
  }
1026
+ function buildResultType(node, resolver, typedHeaders) {
1027
+ const headers = typedHeaders ? buildResponseHeadersType({
1028
+ node,
1029
+ types: resolver
1030
+ }) : null;
1031
+ return buildResultTypeRef("RequestResult", resolver.response.responses(node), headers, ["true"]);
1032
+ }
1032
1033
  /**
1033
1034
  * Builds the `TData` / `TError` type expressions shared by every generated hook, joining the resolved
1034
1035
  * success responses into `TData` and wrapping the error responses in `ResponseErrorConfig<...>`.
1035
- * With `returnType` `'full'`, `TData` is the client's `RequestResult` over the operation's responses record.
1036
+ * With `returnType` `'full'`, `TData` is the client's `RequestResult` over the operation's responses record, with the
1037
+ * response headers the operation declares.
1036
1038
  */
1037
1039
  function buildResponseTypes(node, resolver, options = {}) {
1038
- const { returnType = "data" } = options;
1039
- return resolver.memo(`responseTypes:${returnType}:${node.method}\0${node.path}`, () => {
1040
+ const { returnType = "data", typedHeaders = true } = options;
1041
+ return resolver.memo(`responseTypes:${returnType}:${typedHeaders}:${node.method}\0${node.path}`, () => {
1040
1042
  const successNames = resolveSuccessNames(node, resolver);
1041
- const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.response.response(node);
1043
+ const bodyName = successNames.length > 0 ? successNames.join(" | ") : resolver.response.response(node);
1044
+ const responseName = hasStreamVariant(node) ? `${bodyName} | ReadableStream<Uint8Array>` : bodyName;
1042
1045
  const errorNames = resolveErrorNames(node, resolver);
1043
1046
  return {
1044
- TData: returnType !== "data" ? `RequestResult<${resolver.response.responses(node)}, true>` : responseName,
1047
+ TData: returnType === "data" ? responseName : buildResultType(node, resolver, typedHeaders),
1045
1048
  TError: `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`
1046
1049
  };
1047
1050
  });
@@ -1060,7 +1063,7 @@ function resolveFallbackPageParamType(initialPageParam) {
1060
1063
  * so callers can reuse it when rewriting the paginated request.
1061
1064
  */
1062
1065
  function resolvePageParamType(node, { resolver, initialPageParam, queryParam }) {
1063
- const firstQueryParam = getOperationParameters(node).query[0];
1066
+ const firstQueryParam = _kubb_kit.ast.http.groupParameters(node).query[0];
1064
1067
  const groupName = firstQueryParam ? resolver.param.query(node, firstQueryParam) : null;
1065
1068
  const queryParamsTypeName = groupName !== (firstQueryParam ? resolver.param.name(node, firstQueryParam) : null) ? groupName : null;
1066
1069
  const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : null;
@@ -1163,7 +1166,7 @@ function resolveInfiniteConfig(infinite) {
1163
1166
  */
1164
1167
  function matchesInfinite(node, infinite) {
1165
1168
  if (!infinite.queryParam) return false;
1166
- return getOperationParameters(node).query.some((param) => param.name.replace(/\?$/, "") === infinite.queryParam);
1169
+ return _kubb_kit.ast.http.groupParameters(node).query.some((param) => param.name.replace(/\?$/, "") === infinite.queryParam);
1167
1170
  }
1168
1171
  /**
1169
1172
  * Warning for an infinite hook that falls back to the built-in page params on a response that
@@ -1171,8 +1174,8 @@ function matchesInfinite(node, infinite) {
1171
1174
  */
1172
1175
  function getDefaultPageParamsWarning(node, infinite) {
1173
1176
  if (!(infinite.getNextPageParam == null && infinite.getPreviousPageParam == null && infinite.nextParam == null && infinite.previousParam == null && !infinite.cursorParam)) return null;
1174
- const content = getPrimarySuccessResponse(node)?.content;
1175
- let resolved = (content?.find((item) => item.contentType?.includes("json")) ?? content?.[0])?.schema;
1177
+ const content = _kubb_kit.ast.http.responses.findPrimary(node)?.content;
1178
+ let resolved = (content?.find((item) => _kubb_kit.ast.mediaType.isJson(item)) ?? content?.[0])?.schema;
1176
1179
  while (resolved?.type === "ref" || resolved?.type === "intersection" && resolved.members?.length === 1) resolved = resolved.type === "ref" ? resolved.schema : resolved.members?.[0];
1177
1180
  if (!resolved || resolved.type === "array") return null;
1178
1181
  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.`;
@@ -1220,15 +1223,24 @@ function buildHookParams(node, options) {
1220
1223
  }
1221
1224
  /**
1222
1225
  * The `TRequest` type argument of a mutation hook: the options type when the operation takes a request, else `undefined`.
1226
+ * When the variables carry the request media type and the response has several, `contentType` can pick the
1227
+ * response one too, as `{ request, response }`.
1223
1228
  */
1224
1229
  function resolveMutationRequestType(node, resolver) {
1225
- return buildGroupedRequestParam(node, { resolver }) ? resolver.response.options(node) : "undefined";
1230
+ if (!buildGroupedRequestParam(node, { resolver })) return "undefined";
1231
+ const optionsName = resolver.response.options(node);
1232
+ const response = getResponseContentTypeInfo(node);
1233
+ if (!hasRequestContentTypeChoice(node) || !response.isMultipleContentTypes) return optionsName;
1234
+ return `${/^[\w$]+$/.test(optionsName) ? optionsName : `(${optionsName})`} & { contentType?: string | { response?: ${response.contentTypeUnion} } }`;
1226
1235
  }
1227
1236
  // ../../internals/tanstack-query/src/components/InfiniteQueryOptions.tsx
1228
1237
  const declarationPrinter$5 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
1229
1238
  const callPrinter$3 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
1230
- function InfiniteQueryOptions({ name, clientName, initialPageParam, hasExplicitInitialPageParam, cursorParam, nextParam, previousParam, getNextPageParam, getPreviousPageParam, node, tsResolver, queryParam, queryKeyName, queryKeyType = "typeof queryKey", memberTypeWrapper, unwrapName, clientReturnType, returnType }) {
1231
- const { TData: queryFnDataType, TError: errorType } = buildResponseTypes(node, tsResolver, { returnType });
1239
+ function InfiniteQueryOptions({ name, clientName, initialPageParam, hasExplicitInitialPageParam, cursorParam, nextParam, previousParam, getNextPageParam, getPreviousPageParam, node, tsResolver, queryParam, queryKeyName, queryKeyType = "typeof queryKey", memberTypeWrapper, unwrapName, clientReturnType, returnType, typedHeaders }) {
1240
+ const { TData: queryFnDataType, TError: errorType } = buildResponseTypes(node, tsResolver, {
1241
+ returnType,
1242
+ typedHeaders
1243
+ });
1232
1244
  const dataSuffix = returnType === "data" ? "" : ".data";
1233
1245
  const { queryParamsTypeName, pageParamType } = resolvePageParamType(node, {
1234
1246
  resolver: tsResolver,
@@ -1247,10 +1259,12 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, hasExplicitI
1247
1259
  memberTypeWrapper
1248
1260
  });
1249
1261
  const paramsSignature = declarationPrinter$5.print(paramsNode) ?? "";
1262
+ const pageParam = queryParam && queryParamsTypeName ? queryParam : void 0;
1250
1263
  const queryFnBody = buildCallResultBody(buildClientCall(node, {
1251
1264
  clientName,
1252
1265
  signal: true,
1253
- unwrapName
1266
+ unwrapName,
1267
+ pageParam
1254
1268
  }), {
1255
1269
  clientReturnType,
1256
1270
  returnType
@@ -1277,12 +1291,7 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, hasExplicitI
1277
1291
  getNextPageParamExpr,
1278
1292
  getPreviousPageParamExpr
1279
1293
  ].filter(Boolean);
1280
- const infiniteOverrideParams = queryParam && queryParamsTypeName ? `query = {
1281
- ...(query ?? {}),
1282
- ['${queryParam}']: pageParam as unknown as ${queryParamsTypeName}['${queryParam}'],
1283
- } as ${queryParamsTypeName}` : "";
1284
- const queryFnArgs = infiniteOverrideParams ? "{ signal, pageParam }" : "{ signal }";
1285
- const queryFnStatements = infiniteOverrideParams ? `${infiniteOverrideParams}\n ${queryFnBody}` : queryFnBody;
1294
+ const queryFnArgs = pageParam ? "{ signal, pageParam }" : "{ signal }";
1286
1295
  return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
1287
1296
  name,
1288
1297
  isExportable: true,
@@ -1296,7 +1305,7 @@ const queryKey = ${queryKeyName}(${queryKeyParamsCall})
1296
1305
  return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, ${queryKeyType}, ${pageParamType}>({
1297
1306
  queryKey,
1298
1307
  queryFn: async (${queryFnArgs}) => {
1299
- ${queryFnStatements}
1308
+ ${queryFnBody}
1300
1309
  },
1301
1310
  ${queryOptionsArr.join(",\n ")}
1302
1311
  })
@@ -1367,7 +1376,7 @@ function MutationKey({ name, node, transformer, typeName }) {
1367
1376
  function createQueryResolver(variant = "") {
1368
1377
  return {
1369
1378
  name(node) {
1370
- const name = `use${capitalize(this.name(node.operationId))}${variant}`;
1379
+ const name = `use${_kubb_kit.casing.capitalize(this.name(node.operationId))}${variant}`;
1371
1380
  return this.resolveName({
1372
1381
  key: operationKey(node, "query", variant, "name"),
1373
1382
  name
@@ -1388,7 +1397,7 @@ function createQueryResolver(variant = "") {
1388
1397
  });
1389
1398
  },
1390
1399
  keyTypeName(node) {
1391
- const name = `${capitalize(this.name(node.operationId))}${variant}QueryKey`;
1400
+ const name = `${_kubb_kit.casing.capitalize(this.name(node.operationId))}${variant}QueryKey`;
1392
1401
  return this.resolveName({
1393
1402
  key: operationKey(node, "query", variant, "keyTypeName"),
1394
1403
  name
@@ -1409,7 +1418,7 @@ function createQueryResolver(variant = "") {
1409
1418
  function createMutationResolver() {
1410
1419
  return {
1411
1420
  name(node) {
1412
- const name = `use${capitalize(this.name(node.operationId))}`;
1421
+ const name = `use${_kubb_kit.casing.capitalize(this.name(node.operationId))}`;
1413
1422
  return this.resolveName({
1414
1423
  key: operationKey(node, "mutation", "name"),
1415
1424
  name
@@ -1438,14 +1447,14 @@ const declarationPrinter$3 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "decla
1438
1447
  */
1439
1448
  const queryKeyTransformer = ({ node, variant }) => {
1440
1449
  if (!node.path) return [];
1441
- const { path, query } = getOperationParameters(node);
1450
+ const { path, query } = _kubb_kit.ast.http.groupParameters(node);
1442
1451
  const isInfinite = variant === "infiniteQuery" || variant === "suspenseInfiniteQuery";
1443
1452
  const urlFields = [`url: '${_kubb_kit.Url.toPath(node.path)}'`];
1444
1453
  if (path.length > 0) urlFields.push("params: path");
1445
1454
  if (isInfinite) urlFields.push("infinite: true");
1446
1455
  const result = [`{ ${urlFields.join(", ")} }`];
1447
1456
  if (query.length > 0) result.push("...(query ? [query] : [])");
1448
- if (node.requestBody?.content?.[0]?.schema) result.push("...(body !== undefined ? [body] : [])");
1457
+ if (_kubb_kit.ast.http.requestBody.getSchema(node)) result.push("...(body !== undefined ? [body] : [])");
1449
1458
  return result;
1450
1459
  };
1451
1460
  function QueryKey({ name, node, tsResolver, typeName, transformer, variant = "query", memberTypeWrapper, exportType }) {
@@ -1491,8 +1500,11 @@ function getQueryOptionsParams(node, options) {
1491
1500
  memberTypeWrapper: maybeRefOrGetter
1492
1501
  });
1493
1502
  }
1494
- function QueryOptions({ name, clientName, node, tsResolver, queryKeyName, clientReturnType, returnType }) {
1495
- const { TData, TError } = buildResponseTypes(node, tsResolver, { returnType });
1503
+ function QueryOptions({ name, clientName, node, tsResolver, queryKeyName, clientReturnType, returnType, typedHeaders }) {
1504
+ const { TData, TError } = buildResponseTypes(node, tsResolver, {
1505
+ returnType,
1506
+ typedHeaders
1507
+ });
1496
1508
  const queryKeyParamsNode = buildQueryKeyParams(node, {
1497
1509
  resolver: tsResolver,
1498
1510
  memberTypeWrapper: maybeRefOrGetter
@@ -1531,8 +1543,11 @@ function QueryOptions({ name, clientName, node, tsResolver, queryKeyName, client
1531
1543
  // src/components/Query.tsx
1532
1544
  const declarationPrinter$1 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
1533
1545
  const callPrinter$1 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
1534
- function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, tsResolver, infinite, returnType }) {
1535
- const { TData, TError } = buildResponseTypes(node, tsResolver, { returnType });
1546
+ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, tsResolver, infinite, returnType, typedHeaders }) {
1547
+ const { TData, TError } = buildResponseTypes(node, tsResolver, {
1548
+ returnType,
1549
+ typedHeaders
1550
+ });
1536
1551
  const optionsName = infinite ? "UseInfiniteQueryOptions" : "UseQueryOptions";
1537
1552
  const hookName = infinite ? "useInfiniteQuery" : "useQuery";
1538
1553
  const resultType = `${infinite ? "UseInfiniteQueryReturnType" : "UseQueryReturnType"}<${["TData", TError].join(", ")}> & { queryKey: TQueryKey }`;
@@ -1579,7 +1594,7 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, t
1579
1594
  memberTypeWrapper: maybeRefOrGetter,
1580
1595
  optionsType: `{
1581
1596
  query?: Partial<${optionsName}<${optionsGenerics.join(", ")}>> & { client?: QueryClient },
1582
- client?: ${buildClientOptionType(node)}
1597
+ client?: ${buildClientOptionType()}
1583
1598
  }`
1584
1599
  });
1585
1600
  const paramsSignature = declarationPrinter$1.print(paramsNode) ?? "";
@@ -1623,7 +1638,7 @@ const infiniteQueryGenerator = (0, _kubb_kit.defineGenerator)({
1623
1638
  renderer: _kubb_renderer_jsx.jsxRenderer,
1624
1639
  match(node, ctx) {
1625
1640
  const operationNode = node;
1626
- if (!_kubb_kit.ast.isHttpOperationNode(operationNode)) return false;
1641
+ if (!_kubb_kit.ast.http.isOperation(operationNode)) return false;
1627
1642
  const { query, mutation, infinite, hooks } = ctx.options;
1628
1643
  const { isQuery, isMutation } = classifyOperation(operationNode, {
1629
1644
  query,
@@ -1634,7 +1649,7 @@ const infiniteQueryGenerator = (0, _kubb_kit.defineGenerator)({
1634
1649
  return matchesInfinite(operationNode, infiniteOptions);
1635
1650
  },
1636
1651
  operation(node, ctx) {
1637
- if (!_kubb_kit.ast.isHttpOperationNode(node)) return null;
1652
+ if (!_kubb_kit.ast.http.isOperation(node)) return null;
1638
1653
  const { driver, resolver, root } = ctx;
1639
1654
  const { output, query, infinite, client, group } = ctx.options;
1640
1655
  const infiniteOptions = infinite && typeof infinite === "object" ? infinite : null;
@@ -1715,6 +1730,7 @@ const infiniteQueryGenerator = (0, _kubb_kit.defineGenerator)({
1715
1730
  queryParam: infiniteOptions.queryParam,
1716
1731
  clientReturnType: contractOp.returnType,
1717
1732
  returnType: hook.returnType,
1733
+ typedHeaders: hook.contractOp.typedHeaders,
1718
1734
  queryKeyType: "QueryKey",
1719
1735
  memberTypeWrapper: maybeRefOrGetter,
1720
1736
  unwrapName: (name) => `toValue(${name})`
@@ -1741,7 +1757,8 @@ const infiniteQueryGenerator = (0, _kubb_kit.defineGenerator)({
1741
1757
  node,
1742
1758
  tsResolver,
1743
1759
  infinite: true,
1744
- returnType: hook.returnType
1760
+ returnType: hook.returnType,
1761
+ typedHeaders: hook.contractOp.typedHeaders
1745
1762
  })
1746
1763
  ]
1747
1764
  });
@@ -1751,8 +1768,11 @@ const infiniteQueryGenerator = (0, _kubb_kit.defineGenerator)({
1751
1768
  const declarationPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
1752
1769
  const callPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
1753
1770
  function buildMutationParamsNode(node, options) {
1754
- const { resolver, returnType } = options;
1755
- const { TData, TError } = buildResponseTypes(node, resolver, { returnType });
1771
+ const { resolver, returnType, typedHeaders } = options;
1772
+ const { TData, TError } = buildResponseTypes(node, resolver, {
1773
+ returnType,
1774
+ typedHeaders
1775
+ });
1756
1776
  return buildHookParams(node, {
1757
1777
  resolver,
1758
1778
  withRequest: false,
@@ -1767,8 +1787,11 @@ function buildMutationParamsNode(node, options) {
1767
1787
  }`
1768
1788
  });
1769
1789
  }
1770
- function Mutation({ name, clientName, node, tsResolver, mutationKeyName, clientReturnType, returnType }) {
1771
- const { TData, TError } = buildResponseTypes(node, tsResolver, { returnType });
1790
+ function Mutation({ name, clientName, node, tsResolver, mutationKeyName, clientReturnType, returnType, typedHeaders }) {
1791
+ const { TData, TError } = buildResponseTypes(node, tsResolver, {
1792
+ returnType,
1793
+ typedHeaders
1794
+ });
1772
1795
  const groupedParam = buildGroupedRequestParam(node, {
1773
1796
  resolver: tsResolver,
1774
1797
  withContentType: true
@@ -1781,7 +1804,6 @@ function Mutation({ name, clientName, node, tsResolver, mutationKeyName, clientR
1781
1804
  clientName,
1782
1805
  signal: false,
1783
1806
  withContentType: true,
1784
- returnType: clientReturnType,
1785
1807
  unwrapName: (name) => `toValue<${TRequest}['${name}']>(${name})`
1786
1808
  }), {
1787
1809
  clientReturnType,
@@ -1795,7 +1817,8 @@ function Mutation({ name, clientName, node, tsResolver, mutationKeyName, clientR
1795
1817
  ].join(", ");
1796
1818
  const paramsNode = buildMutationParamsNode(node, {
1797
1819
  resolver: tsResolver,
1798
- returnType
1820
+ returnType,
1821
+ typedHeaders
1799
1822
  });
1800
1823
  const paramsSignature = declarationPrinter.print(paramsNode) ?? "";
1801
1824
  return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
@@ -1834,7 +1857,7 @@ const mutationGenerator = (0, _kubb_kit.defineGenerator)({
1834
1857
  name: "vue-query-mutation",
1835
1858
  renderer: _kubb_renderer_jsx.jsxRenderer,
1836
1859
  operation(node, ctx) {
1837
- if (!_kubb_kit.ast.isHttpOperationNode(node)) return null;
1860
+ if (!_kubb_kit.ast.http.isOperation(node)) return null;
1838
1861
  const { driver, resolver, root } = ctx;
1839
1862
  const { output, query, mutation, client, group, hooks } = ctx.options;
1840
1863
  const { isMutation } = classifyOperation(node, {
@@ -1893,7 +1916,8 @@ const mutationGenerator = (0, _kubb_kit.defineGenerator)({
1893
1916
  tsResolver: hook.tsResolver,
1894
1917
  mutationKeyName,
1895
1918
  clientReturnType: contractOp.returnType,
1896
- returnType: hook.returnType
1919
+ returnType: hook.returnType,
1920
+ typedHeaders: hook.contractOp.typedHeaders
1897
1921
  })
1898
1922
  ] })]
1899
1923
  });
@@ -1909,7 +1933,7 @@ const queryGenerator = (0, _kubb_kit.defineGenerator)({
1909
1933
  name: "vue-query",
1910
1934
  renderer: _kubb_renderer_jsx.jsxRenderer,
1911
1935
  operation(node, ctx) {
1912
- if (!_kubb_kit.ast.isHttpOperationNode(node)) return null;
1936
+ if (!_kubb_kit.ast.http.isOperation(node)) return null;
1913
1937
  const { driver, resolver, root } = ctx;
1914
1938
  const { output, query, mutation, client, group, hooks } = ctx.options;
1915
1939
  const { isQuery, isMutation } = classifyOperation(node, {
@@ -1972,7 +1996,8 @@ const queryGenerator = (0, _kubb_kit.defineGenerator)({
1972
1996
  node,
1973
1997
  tsResolver,
1974
1998
  clientReturnType: contractOp.returnType,
1975
- returnType: hook.returnType
1999
+ returnType: hook.returnType,
2000
+ typedHeaders: hook.contractOp.typedHeaders
1976
2001
  }),
1977
2002
  query && hooks && /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx_jsx_runtime.Fragment, { children: [
1978
2003
  /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
@@ -1996,7 +2021,8 @@ const queryGenerator = (0, _kubb_kit.defineGenerator)({
1996
2021
  queryKeyTypeName,
1997
2022
  node,
1998
2023
  tsResolver,
1999
- returnType: hook.returnType
2024
+ returnType: hook.returnType,
2025
+ typedHeaders: hook.contractOp.typedHeaders
2000
2026
  })
2001
2027
  ] })
2002
2028
  ]
@@ -2090,7 +2116,7 @@ const pluginVueQuery = (0, _kubb_kit.defineExtension)({
2090
2116
  mutation: resolveMutationConfig(mutation, { importPath: "@tanstack/vue-query" }),
2091
2117
  infinite: resolveInfiniteConfig(infinite),
2092
2118
  hooks,
2093
- group: createGroupConfig(group),
2119
+ group: group ?? null,
2094
2120
  exclude,
2095
2121
  include,
2096
2122
  override,