@kubb/plugin-vue-query 5.11.0 → 5.11.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,6 +1,7 @@
1
- import { Diagnostics, Resolver, Url, addGenerator, ast, casing, createResolver, defineExtension, defineGenerator, setMacros, setResolver, useConfig } from "@kubb/kit";
1
+ import { Diagnostics, Resolver, Url, addGenerator, casing, createResolver, defineExtension, defineGenerator, setMacros, setResolver, useConfig } from "@kubb/kit";
2
2
  import { createFunctionParameter, createFunctionParameters, createObjectBindingPattern, createTypeLiteral, functionPrinter, pluginTsName } from "@kubb/plugin-ts";
3
3
  import path from "node:path";
4
+ import { ast, ref } from "@kubb/ast";
4
5
  import { File, Function, Type, jsxRenderer } from "@kubb/renderer-jsx";
5
6
  import { Fragment, jsx, jsxs } from "@kubb/renderer-jsx/jsx-runtime";
6
7
  // kubb-extension.json
@@ -9,7 +10,7 @@ var compatibility = {
9
10
  "node": ">=22.22"
10
11
  };
11
12
  // package.json
12
- var version = "5.11.0";
13
+ var version = "5.11.1";
13
14
  // ../../internals/client/src/resolveClient.ts
14
15
  /**
15
16
  * Resolves which client plugin a consumer (react-query, vue-query, swr, mcp) should call for an
@@ -123,6 +124,143 @@ function resolveContractClient(options) {
123
124
  }
124
125
  return resolved;
125
126
  }
127
+ // ../../internals/ast/src/http/requestBody.ts
128
+ /** The schema of the first request body entry, else `undefined` when the operation takes no body. */
129
+ function getSchema(node) {
130
+ return node.requestBody?.content?.[0]?.schema;
131
+ }
132
+ // ../../internals/ast/src/http/status.ts
133
+ const classByRange = /* @__PURE__ */ new Map([
134
+ ["1xx", 1],
135
+ ["2xx", 2],
136
+ ["3xx", 3],
137
+ ["4xx", 4],
138
+ ["5xx", 5]
139
+ ]);
140
+ /** The class digit of a status code or range: `2` for `201` and `2xx`, `null` for `default`. */
141
+ function statusClass(input) {
142
+ const statusCode = typeof input === "object" ? input.statusCode : input;
143
+ const rangeClass = classByRange.get(String(statusCode));
144
+ if (rangeClass) return rangeClass;
145
+ const code = Number(statusCode);
146
+ return Number.isNaN(code) ? null : Math.floor(code / 100);
147
+ }
148
+ function isSuccess(statusCode) {
149
+ return statusClass(statusCode) === 2;
150
+ }
151
+ function isError(statusCode) {
152
+ const code = statusClass(statusCode);
153
+ return code !== null && code >= 4;
154
+ }
155
+ // ../../internals/ast/src/http/responses.ts
156
+ /** The `4xx` and `5xx` responses, ranges included. */
157
+ function filterError(node) {
158
+ return node.responses.filter((response) => isError(response.statusCode));
159
+ }
160
+ function filterSuccess(node) {
161
+ return node.responses.filter((response) => isSuccess(response.statusCode));
162
+ }
163
+ /** The success response a client returns: one with a body first, then an exact code over a `2xx` range. */
164
+ function findPrimary(node) {
165
+ const responses = filterSuccess(node);
166
+ const withBody = responses.filter((response) => response.content?.some((entry) => entry.contentType));
167
+ const candidates = withBody.length ? withBody : responses;
168
+ return candidates.find((response) => !Number.isNaN(Number(response.statusCode))) ?? candidates[0] ?? null;
169
+ }
170
+ // ../../internals/ast/src/http/index.ts
171
+ const isOperation = ast.http.isOperation;
172
+ /** Computes once per key; generators visit the same node many times. */
173
+ function cached(store, key, compute) {
174
+ if (!store.has(key)) store.set(key, compute());
175
+ return store.get(key);
176
+ }
177
+ const parametersByNode = /* @__PURE__ */ new WeakMap();
178
+ /** The operation's parameters by location, with a `querystring` parameter in `query`. A repeated name keeps its first parameter. */
179
+ function groupParameters(node) {
180
+ return cached(parametersByNode, node, () => {
181
+ const group = (...locations) => {
182
+ const seen = /* @__PURE__ */ new Set();
183
+ return locations.flatMap((location) => node.parameters.filter((param) => {
184
+ if (param.in !== location || seen.has(param.name)) return false;
185
+ seen.add(param.name);
186
+ return true;
187
+ }));
188
+ };
189
+ return {
190
+ path: group("path"),
191
+ query: group("query", "querystring"),
192
+ header: group("header"),
193
+ cookie: group("cookie")
194
+ };
195
+ });
196
+ }
197
+ const requestGroupsByNode = /* @__PURE__ */ new WeakMap();
198
+ /** Which request groups are present, which hold a required member, and the body's media types. Built once per operation. */
199
+ function getRequestGroups(node) {
200
+ return cached(requestGroupsByNode, node, () => {
201
+ const { path, query, header, cookie } = groupParameters(node);
202
+ const content = node.requestBody?.content ?? [];
203
+ const body = Boolean(content[0]?.schema);
204
+ const required = {
205
+ path: path.some((param) => param.required),
206
+ query: query.some((param) => param.required),
207
+ headers: header.some((param) => param.required),
208
+ body: body && node.requestBody?.required === true
209
+ };
210
+ return {
211
+ path: path.length > 0,
212
+ query: query.length > 0,
213
+ body,
214
+ headers: header.length > 0,
215
+ cookies: cookie.length > 0,
216
+ required,
217
+ isOptional: !required.path && !required.query && !required.headers && !required.body,
218
+ contentTypes: content.map((entry) => entry.contentType),
219
+ hasContentTypeChoice: content.filter((entry) => entry.schema).length > 1
220
+ };
221
+ });
222
+ }
223
+ // ../../internals/ast/src/mediaType.ts
224
+ const streamMediaTypes = /* @__PURE__ */ new Set([
225
+ "application/jsonl",
226
+ "application/x-ndjson",
227
+ "application/json-seq",
228
+ "text/event-stream"
229
+ ]);
230
+ const getBase = ast.mediaType.getBase;
231
+ const isJson = ast.mediaType.isJson;
232
+ /** Whether the media type is a stream of items: SSE, JSON Lines, or a `+json-seq` sequence. */
233
+ function isStream(mediaType) {
234
+ const baseType = getBase(mediaType);
235
+ return streamMediaTypes.has(baseType) || baseType.startsWith("application/") && baseType.endsWith("+json-seq");
236
+ }
237
+ const formKinds = {
238
+ "multipart/form-data": "form",
239
+ "application/x-www-form-urlencoded": "urlencoded"
240
+ };
241
+ /** How a client reads or sends a content entry, or `null` for another media type. A `blob` schema is `binary`. */
242
+ function getKind(entry) {
243
+ const content = typeof entry === "string" ? { contentType: entry } : entry;
244
+ const baseType = getBase(content);
245
+ if (!baseType) return null;
246
+ if (baseType === "text/event-stream") return "eventStream";
247
+ if (content.stream && isStream(content)) return "lineStream";
248
+ if (isJson(baseType)) return "json";
249
+ if (formKinds[baseType]) return formKinds[baseType];
250
+ if (content.schema?.type === "blob") return "binary";
251
+ if (baseType.startsWith("text/")) return "text";
252
+ if (baseType === "application/octet-stream" || baseType === "application/pdf" || /^(image|audio|video)\//.test(baseType)) return "binary";
253
+ return null;
254
+ }
255
+ ast.schema.applyOptionality;
256
+ ast.schema.types;
257
+ const narrow = ast.schema.narrow;
258
+ ast.schema.find;
259
+ ast.schema.getEmbeddedJson;
260
+ const is = ast.schema.is;
261
+ const getLiterals = ast.schema.getLiterals;
262
+ ast.schema.inferDiscriminator;
263
+ const findProperties = ast.schema.findProperties;
126
264
  // ../../internals/utils/src/reserved.ts
127
265
  /**
128
266
  * JavaScript and Java reserved words.
@@ -359,7 +497,7 @@ function resolveOperationFile(options) {
359
497
  * The operation's method and path as plain text, such as `` `GET /pet/{petId}` ``. A path is not a valid `{@link}` target.
360
498
  */
361
499
  function getOperationRequestLine(node) {
362
- return ast.http.isOperation(node) && node.path ? `\`${node.method.toUpperCase()} ${node.path}\`` : null;
500
+ return isOperation(node) && node.path ? `\`${node.method.toUpperCase()} ${node.path}\`` : null;
363
501
  }
364
502
  /**
365
503
  * Derives the shared `ContentTypeInfo` shape from a list of content types, tracking whether several
@@ -376,55 +514,52 @@ function buildContentTypeInfo(contentTypes) {
376
514
  };
377
515
  }
378
516
  function getContentTypeInfo(node) {
379
- return buildContentTypeInfo(node.requestBody?.content?.map((e) => e.contentType) ?? []);
517
+ return buildContentTypeInfo(getRequestGroups(node).contentTypes);
380
518
  }
381
519
  /**
382
520
  * The request-body counterpart for the primary success response: the content types it documents and
383
521
  * whether several are present, so the client can let a caller pick which one to accept.
384
522
  */
385
523
  function getResponseContentTypeInfo(node) {
386
- return buildContentTypeInfo(ast.http.responses.findPrimary(node)?.content?.map((e) => e.contentType) ?? []);
387
- }
388
- /**
389
- * How an operation streams its primary success response item by item, when that response declares one content type:
390
- * - `'event'` for `text/event-stream` whose `itemSchema` types the whole event with its own `event` and `data`
391
- * - `'data'` for `text/event-stream` typed by its payload only
392
- * - `'line'` for JSON Lines, one parsed JSON value per line
393
- *
394
- * Returns `null` for any other response, and for a response that also declares another content type, which stays a normal
395
- * call with its query hooks.
396
- */
397
- function getEventStream(node) {
398
- const content = ast.http.responses.findPrimary(node)?.content ?? [];
399
- if (content.length !== 1) return null;
400
- const entry = content[0];
401
- const framing = getStreamFraming(entry);
402
- if (framing === "events") return entry.stream?.shape ?? "data";
403
- return framing === "lines" ? "line" : null;
404
- }
405
- /**
406
- * How a content entry is framed as a stream: `'events'` for Server-Sent Events, `'lines'` for JSON Lines.
407
- */
408
- function getStreamFraming(entry) {
409
- if (ast.mediaType.getBase(entry) === "text/event-stream") return "events";
410
- return entry.stream && ast.mediaType.isStream(entry) ? "lines" : void 0;
411
- }
412
- /**
413
- * Whether an operation streams its primary success response, as Server-Sent Events or JSON Lines. The client generator uses
414
- * this to return a typed stream of items instead of a one-shot `RequestResult`.
415
- */
416
- function isEventStream(node) {
417
- return getEventStream(node) !== null;
418
- }
419
- /**
420
- * Whether a success response offers a stream media type next to other content types. The client returns that variant's
421
- * body as a `ReadableStream`, so the stream runtime is registered and a hook's data type includes the stream.
422
- */
423
- function hasStreamVariant(node) {
424
- return ast.http.responses.filterSuccess(node).some((response) => {
425
- const variants = (response.content ?? []).filter((entry) => entry.schema);
426
- return variants.length > 1 && variants.some((entry) => ast.mediaType.isStream(entry));
524
+ return buildContentTypeInfo(findPrimary(node)?.content?.map((e) => e.contentType) ?? []);
525
+ }
526
+ const isText = (schema) => !!schema && is(schema, "text", { follow: ["ref"] });
527
+ function getTextEvents(entry, shape) {
528
+ if (shape === "data") return isText(entry.stream?.schema ?? entry.schema);
529
+ if (shape !== "event" || !entry.stream?.schema) return false;
530
+ const item = ref.getSchema(entry.stream.schema);
531
+ const events = narrow(item, "union")?.members ?? [item];
532
+ const propertySchemas = (event, propertyName) => findProperties({
533
+ node: event,
534
+ propertyName
535
+ }).map(({ schema }) => schema);
536
+ const textEvents = events.filter((event) => {
537
+ const dataSchemas = propertySchemas(event, "data");
538
+ return dataSchemas.length > 0 && dataSchemas.every(isText);
539
+ });
540
+ if (textEvents.length === events.length) return events.length > 0;
541
+ const eventNames = textEvents.map((event) => propertySchemas(event, "event").flatMap((schema) => getLiterals(ref.getSchema(schema))));
542
+ if (!eventNames.length || eventNames.some((values) => !values.length)) return false;
543
+ return [...new Set(eventNames.flat().map(String))];
544
+ }
545
+ /** How an operation streams its success responses, or `null` when none offers a stream. */
546
+ function getStream(node) {
547
+ const entries = findPrimary(node)?.content ?? [];
548
+ const entry = entries.length === 1 ? entries[0] : void 0;
549
+ const kind = entry ? getKind(entry) : null;
550
+ const shape = kind === "eventStream" ? entry?.stream?.shape ?? "data" : kind === "lineStream" ? "line" : null;
551
+ const hasEventStream = entries.some((item) => getKind(item) === "eventStream" && (entries.length === 1 || !!item.schema));
552
+ const hasVariant = filterSuccess(node).some((response) => {
553
+ const variants = (response.content ?? []).filter((item) => item.schema);
554
+ return variants.length > 1 && variants.some(isStream);
427
555
  });
556
+ if (!shape && !hasEventStream && !hasVariant) return null;
557
+ return {
558
+ shape,
559
+ textEvents: entry ? getTextEvents(entry, shape) : false,
560
+ hasEventStream,
561
+ hasVariant
562
+ };
428
563
  }
429
564
  /**
430
565
  * Builds the `client?:` option type shared by the generated query hooks (`useQuery`,
@@ -448,7 +583,7 @@ function buildClientOptionType(options = {}) {
448
583
  * generated call.
449
584
  */
450
585
  function buildRequestConfigType(node) {
451
- if (hasRequestContentTypeChoice(node)) return buildClientOptionType({ omit: ["contentType"] });
586
+ if (getRequestGroups(node).hasContentTypeChoice) return buildClientOptionType({ omit: ["contentType"] });
452
587
  const request = getContentTypeInfo(node);
453
588
  const response = getResponseContentTypeInfo(node);
454
589
  const members = [request.isMultipleContentTypes ? `request?: ${request.contentTypeUnion}` : null, response.isMultipleContentTypes ? `response?: ${response.contentTypeUnion}` : null].filter(Boolean);
@@ -463,38 +598,6 @@ const requestGroupOrder = [
463
598
  "headers",
464
599
  "cookies"
465
600
  ];
466
- /**
467
- * Which of the grouped request options an operation carries.
468
- */
469
- function getRequestGroups(node) {
470
- const { path, query, header, cookie } = ast.http.groupParameters(node);
471
- return {
472
- path: path.length > 0,
473
- query: query.length > 0,
474
- body: Boolean(ast.http.requestBody.getSchema(node)),
475
- headers: header.length > 0,
476
- cookies: cookie.length > 0
477
- };
478
- }
479
- /**
480
- * Resolves which grouped request options an operation carries together with whether each group
481
- * holds a required member. The grouped parameter stays optional only when nothing inside it is
482
- * required, matching the generated `RequestConfig` type.
483
- */
484
- function getRequestGroupOptionality(node) {
485
- const groups = getRequestGroups(node);
486
- const { path, query, header } = ast.http.groupParameters(node);
487
- const hasRequiredPath = path.some((param) => param.required);
488
- const hasRequiredQuery = query.some((param) => param.required);
489
- const hasRequiredHeader = header.some((param) => param.required);
490
- return {
491
- groups,
492
- hasRequiredPath,
493
- hasRequiredQuery,
494
- hasRequiredHeader,
495
- isOptional: !hasRequiredPath && !hasRequiredQuery && !hasRequiredHeader && !(groups.body && node.requestBody?.required === true)
496
- };
497
- }
498
601
  function buildOperationComments(node, options = {}) {
499
602
  const { splitLines = false } = options;
500
603
  const filteredComments = [
@@ -507,17 +610,11 @@ function buildOperationComments(node, options = {}) {
507
610
  if (!splitLines) return filteredComments;
508
611
  return filteredComments.flatMap((text) => text.split(/\r?\n/).map((line) => line.trim())).filter((comment) => Boolean(comment));
509
612
  }
510
- /**
511
- * Whether the operation declares more than one request media type with a schema, so a caller must pick one on `contentType`.
512
- */
513
- function hasRequestContentTypeChoice(node) {
514
- return (node.requestBody?.content ?? []).filter((entry) => entry.schema).length > 1;
515
- }
516
613
  function resolveErrorNames(node, resolver) {
517
- return ast.http.responses.filterError(node).map((response) => resolver.response.status(node, response.statusCode));
614
+ return filterError(node).map((response) => resolver.response.status(node, response.statusCode));
518
615
  }
519
616
  function resolveSuccessNames(node, resolver) {
520
- return ast.http.responses.filterSuccess(node).map((response) => resolver.response.status(node, response.statusCode));
617
+ return filterSuccess(node).map((response) => resolver.response.status(node, response.statusCode));
521
618
  }
522
619
  function resolveStatusCodeNames(node, resolver) {
523
620
  return node.responses.map((response) => resolver.response.status(node, response.statusCode));
@@ -529,7 +626,7 @@ function resolveStatusCodeNames(node, resolver) {
529
626
  function resolveOperationTypeNames(node, resolver, options = {}) {
530
627
  const key = `${node.operationId}\0${options.order ?? ""}\0${options.responseStatusNames ?? ""}\0${options.includeParams === false ? "noparams" : ""}\0${(options.exclude ?? []).join(",")}`;
531
628
  return resolver.memo(`operationTypeNames:${key}`, () => {
532
- const { path, query, header, cookie } = ast.http.groupParameters(node);
629
+ const { path, query, header, cookie } = groupParameters(node);
533
630
  const responseStatusNames = options.responseStatusNames === "error" ? resolveErrorNames(node, resolver) : options.responseStatusNames === false ? [] : resolveStatusCodeNames(node, resolver);
534
631
  const exclude = new Set(options.exclude ?? []);
535
632
  const paramNames = options.includeParams === false ? [] : [
@@ -538,7 +635,7 @@ function resolveOperationTypeNames(node, resolver, options = {}) {
538
635
  ...header.map((param) => resolver.param.headers(node, param)),
539
636
  ...cookie.map((param) => resolver.param.cookies(node, param))
540
637
  ];
541
- const bodyAndResponseNames = [ast.http.requestBody.getSchema(node) ? resolver.response.body(node) : null, resolver.response.response(node)];
638
+ const bodyAndResponseNames = [getSchema(node) ? resolver.response.body(node) : null, resolver.response.response(node)];
542
639
  return (options.order === "body-response-first" ? [
543
640
  ...bodyAndResponseNames,
544
641
  ...paramNames,
@@ -890,19 +987,19 @@ function maybeRefOrGetter(type) {
890
987
  */
891
988
  function buildGroupedRequestParam(node, options) {
892
989
  const { resolver, keys = requestGroupOrder, memberTypeWrapper, withContentType = false } = options;
893
- const { groups, hasRequiredPath, hasRequiredQuery, hasRequiredHeader } = getRequestGroupOptionality(node);
990
+ const groups = getRequestGroups(node);
894
991
  const names = keys.filter((key) => groups[key]);
895
992
  if (names.length === 0) return null;
896
993
  const requiredByGroup = {
897
- path: hasRequiredPath,
898
- query: hasRequiredQuery,
994
+ path: groups.required.path,
995
+ query: groups.required.query,
899
996
  body: groups.body,
900
- headers: hasRequiredHeader,
997
+ headers: groups.required.headers,
901
998
  cookies: false
902
999
  };
903
1000
  const isOptional = names.every((name) => !requiredByGroup[name]);
904
1001
  const optionsName = resolver.response.options(node);
905
- if (withContentType && hasRequestContentTypeChoice(node)) return createFunctionParameter({
1002
+ if (withContentType && groups.hasContentTypeChoice) return createFunctionParameter({
906
1003
  name: "variables",
907
1004
  type: optionsName,
908
1005
  optional: false
@@ -966,7 +1063,7 @@ function buildQueryOptionsParams(node, options) {
966
1063
  */
967
1064
  function buildClientCall(node, options) {
968
1065
  const { clientName, signal = false, unwrapName, withContentType = false, pageParam } = options;
969
- const { groups } = getRequestGroupOptionality(node);
1066
+ const groups = getRequestGroups(node);
970
1067
  const names = requestGroupOrder.filter((key) => groups[key]);
971
1068
  const member = (name) => {
972
1069
  const value = unwrapName ? unwrapName(name) : name;
@@ -975,7 +1072,7 @@ function buildClientCall(node, options) {
975
1072
  };
976
1073
  return `${clientName}({ ${[
977
1074
  "...config",
978
- ...withContentType && hasRequestContentTypeChoice(node) ? ["...variables"] : names.map(member),
1075
+ ...withContentType && groups.hasContentTypeChoice ? ["...variables"] : names.map(member),
979
1076
  signal ? "signal: config.signal ?? signal" : null,
980
1077
  "throwOnError: true"
981
1078
  ].filter((part) => part !== null).join(", ")} })`;
@@ -1019,7 +1116,7 @@ function buildResponseTypes(node, resolver, options = {}) {
1019
1116
  return resolver.memo(`responseTypes:${returnType}:${typedHeaders}:${node.method}\0${node.path}`, () => {
1020
1117
  const successNames = resolveSuccessNames(node, resolver);
1021
1118
  const bodyName = successNames.length > 0 ? successNames.join(" | ") : resolver.response.response(node);
1022
- const responseName = hasStreamVariant(node) ? `${bodyName} | ReadableStream<Uint8Array>` : bodyName;
1119
+ const responseName = getStream(node)?.hasVariant ? `${bodyName} | ReadableStream<Uint8Array>` : bodyName;
1023
1120
  const errorNames = resolveErrorNames(node, resolver);
1024
1121
  return {
1025
1122
  TData: returnType === "data" ? responseName : buildResultType(node, resolver, typedHeaders),
@@ -1041,7 +1138,7 @@ function resolveFallbackPageParamType(initialPageParam) {
1041
1138
  * so callers can reuse it when rewriting the paginated request.
1042
1139
  */
1043
1140
  function resolvePageParamType(node, { resolver, initialPageParam, queryParam }) {
1044
- const firstQueryParam = ast.http.groupParameters(node).query[0];
1141
+ const firstQueryParam = groupParameters(node).query[0];
1045
1142
  const groupName = firstQueryParam ? resolver.param.query(node, firstQueryParam) : null;
1046
1143
  const queryParamsTypeName = groupName !== (firstQueryParam ? resolver.param.name(node, firstQueryParam) : null) ? groupName : null;
1047
1144
  const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : null;
@@ -1092,7 +1189,7 @@ function resolveMutationConfig(mutation, options) {
1092
1189
  * directly, so they do not generate query or mutation hooks.
1093
1190
  */
1094
1191
  function classifyOperation(node, { query, mutation }) {
1095
- if (isEventStream(node)) return {
1192
+ if (getStream(node)?.shape) return {
1096
1193
  isQuery: false,
1097
1194
  isMutation: false
1098
1195
  };
@@ -1144,7 +1241,7 @@ function resolveInfiniteConfig(infinite) {
1144
1241
  */
1145
1242
  function matchesInfinite(node, infinite) {
1146
1243
  if (!infinite.queryParam) return false;
1147
- return ast.http.groupParameters(node).query.some((param) => param.name.replace(/\?$/, "") === infinite.queryParam);
1244
+ return groupParameters(node).query.some((param) => param.name.replace(/\?$/, "") === infinite.queryParam);
1148
1245
  }
1149
1246
  /**
1150
1247
  * Warning for an infinite hook that falls back to the built-in page params on a response that
@@ -1152,8 +1249,8 @@ function matchesInfinite(node, infinite) {
1152
1249
  */
1153
1250
  function getDefaultPageParamsWarning(node, infinite) {
1154
1251
  if (!(infinite.getNextPageParam == null && infinite.getPreviousPageParam == null && infinite.nextParam == null && infinite.previousParam == null && !infinite.cursorParam)) return null;
1155
- const content = ast.http.responses.findPrimary(node)?.content;
1156
- let resolved = (content?.find((item) => ast.mediaType.isJson(item)) ?? content?.[0])?.schema;
1252
+ const content = findPrimary(node)?.content;
1253
+ let resolved = (content?.find((item) => isJson(item)) ?? content?.[0])?.schema;
1157
1254
  while (resolved?.type === "ref" || resolved?.type === "intersection" && resolved.members?.length === 1) resolved = resolved.type === "ref" ? resolved.schema : resolved.members?.[0];
1158
1255
  if (!resolved || resolved.type === "array") return null;
1159
1256
  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.`;
@@ -1208,7 +1305,7 @@ function resolveMutationRequestType(node, resolver) {
1208
1305
  if (!buildGroupedRequestParam(node, { resolver })) return "undefined";
1209
1306
  const optionsName = resolver.response.options(node);
1210
1307
  const response = getResponseContentTypeInfo(node);
1211
- if (!hasRequestContentTypeChoice(node) || !response.isMultipleContentTypes) return optionsName;
1308
+ if (!getRequestGroups(node).hasContentTypeChoice || !response.isMultipleContentTypes) return optionsName;
1212
1309
  return `${/^[\w$]+$/.test(optionsName) ? optionsName : `(${optionsName})`} & { contentType?: string | { response?: ${response.contentTypeUnion} } }`;
1213
1310
  }
1214
1311
  // ../../internals/tanstack-query/src/components/InfiniteQueryOptions.tsx
@@ -1269,26 +1366,20 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, hasExplicitI
1269
1366
  getNextPageParamExpr,
1270
1367
  getPreviousPageParamExpr
1271
1368
  ].filter(Boolean);
1272
- const queryFnArgs = pageParam ? "{ signal, pageParam }" : "{ signal }";
1273
- return /* @__PURE__ */ jsx(File.Source, {
1369
+ return /* @__PURE__ */ jsx(Function, {
1274
1370
  name,
1275
- isExportable: true,
1276
- isIndexable: true,
1277
- children: /* @__PURE__ */ jsx(Function, {
1278
- name,
1279
- export: true,
1280
- params: paramsSignature,
1281
- children: `
1371
+ export: true,
1372
+ params: paramsSignature,
1373
+ children: `
1282
1374
  const queryKey = ${queryKeyName}(${queryKeyParamsCall})
1283
1375
  return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, ${queryKeyType}, ${pageParamType}>({
1284
1376
  queryKey,
1285
- queryFn: async (${queryFnArgs}) => {
1377
+ queryFn: async (${pageParam ? "{ signal, pageParam }" : "{ signal }"}) => {
1286
1378
  ${queryFnBody}
1287
1379
  },
1288
1380
  ${queryOptionsArr.join(",\n ")}
1289
1381
  })
1290
1382
  `
1291
- })
1292
1383
  });
1293
1384
  }
1294
1385
  // ../../internals/tanstack-query/src/components/MutationKey.tsx
@@ -1315,27 +1406,16 @@ function MutationKey({ name, node, transformer, typeName }) {
1315
1406
  casing: "camelcase",
1316
1407
  variant: "mutation"
1317
1408
  });
1318
- return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(File.Source, {
1409
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Function.Arrow, {
1319
1410
  name,
1320
- isExportable: true,
1321
- isIndexable: true,
1322
- children: /* @__PURE__ */ jsx(Function.Arrow, {
1323
- name,
1324
- export: true,
1325
- params: paramsSignature,
1326
- singleLine: true,
1327
- children: `[${keys.join(", ")}] as const`
1328
- })
1329
- }), typeName && /* @__PURE__ */ jsx(File.Source, {
1411
+ export: true,
1412
+ params: paramsSignature,
1413
+ singleLine: true,
1414
+ children: `[${keys.join(", ")}] as const`
1415
+ }), typeName && /* @__PURE__ */ jsx(Type, {
1416
+ export: true,
1330
1417
  name: typeName,
1331
- isExportable: true,
1332
- isIndexable: true,
1333
- isTypeOnly: true,
1334
- children: /* @__PURE__ */ jsx(Type, {
1335
- export: true,
1336
- name: typeName,
1337
- children: `ReturnType<typeof ${name}>`
1338
- })
1418
+ children: `ReturnType<typeof ${name}>`
1339
1419
  })] });
1340
1420
  }
1341
1421
  // ../../internals/tanstack-query/src/resolver.ts
@@ -1425,14 +1505,14 @@ const declarationPrinter$3 = functionPrinter({ mode: "declaration" });
1425
1505
  */
1426
1506
  const queryKeyTransformer = ({ node, variant }) => {
1427
1507
  if (!node.path) return [];
1428
- const { path, query } = ast.http.groupParameters(node);
1508
+ const { path, query } = groupParameters(node);
1429
1509
  const isInfinite = variant === "infiniteQuery" || variant === "suspenseInfiniteQuery";
1430
1510
  const urlFields = [`url: '${Url.toPath(node.path)}'`];
1431
1511
  if (path.length > 0) urlFields.push("params: path");
1432
1512
  if (isInfinite) urlFields.push("infinite: true");
1433
1513
  const result = [`{ ${urlFields.join(", ")} }`];
1434
1514
  if (query.length > 0) result.push("...(query ? [query] : [])");
1435
- if (ast.http.requestBody.getSchema(node)) result.push("...(body !== undefined ? [body] : [])");
1515
+ if (getSchema(node)) result.push("...(body !== undefined ? [body] : [])");
1436
1516
  return result;
1437
1517
  };
1438
1518
  function QueryKey({ name, node, tsResolver, typeName, transformer, variant = "query", memberTypeWrapper, exportType }) {
@@ -1446,27 +1526,16 @@ function QueryKey({ name, node, tsResolver, typeName, transformer, variant = "qu
1446
1526
  casing: "camelcase",
1447
1527
  variant
1448
1528
  });
1449
- return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(File.Source, {
1529
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Function.Arrow, {
1450
1530
  name,
1451
- isExportable: true,
1452
- isIndexable: true,
1453
- children: /* @__PURE__ */ jsx(Function.Arrow, {
1454
- name,
1455
- export: true,
1456
- params: paramsSignature,
1457
- singleLine: true,
1458
- children: `[${keys.join(", ")}] as const`
1459
- })
1460
- }), /* @__PURE__ */ jsx(File.Source, {
1531
+ export: true,
1532
+ params: paramsSignature,
1533
+ singleLine: true,
1534
+ children: `[${keys.join(", ")}] as const`
1535
+ }), /* @__PURE__ */ jsx(Type, {
1461
1536
  name: typeName,
1462
- isExportable: exportType,
1463
- isIndexable: exportType,
1464
- isTypeOnly: true,
1465
- children: /* @__PURE__ */ jsx(Type, {
1466
- name: typeName,
1467
- export: exportType,
1468
- children: `ReturnType<typeof ${name}>`
1469
- })
1537
+ export: exportType,
1538
+ children: `ReturnType<typeof ${name}>`
1470
1539
  })] });
1471
1540
  }
1472
1541
  // src/components/QueryOptions.tsx
@@ -1498,15 +1567,11 @@ function QueryOptions({ name, clientName, node, tsResolver, queryKeyName, client
1498
1567
  clientReturnType,
1499
1568
  returnType
1500
1569
  });
1501
- return /* @__PURE__ */ jsx(File.Source, {
1570
+ return /* @__PURE__ */ jsx(Function, {
1502
1571
  name,
1503
- isExportable: true,
1504
- isIndexable: true,
1505
- children: /* @__PURE__ */ jsx(Function, {
1506
- name,
1507
- export: true,
1508
- params: paramsSignature,
1509
- children: `
1572
+ export: true,
1573
+ params: paramsSignature,
1574
+ children: `
1510
1575
  const queryKey = ${queryKeyName}(${queryKeyParamsCall})
1511
1576
  return queryOptions<${TData}, ${TError}, ${TData}>({
1512
1577
  queryKey,
@@ -1515,7 +1580,6 @@ function QueryOptions({ name, clientName, node, tsResolver, queryKeyName, client
1515
1580
  },
1516
1581
  })
1517
1582
  `
1518
- })
1519
1583
  });
1520
1584
  }
1521
1585
  // src/components/Query.tsx
@@ -1576,17 +1640,13 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, t
1576
1640
  }`
1577
1641
  });
1578
1642
  const paramsSignature = declarationPrinter$1.print(paramsNode) ?? "";
1579
- return /* @__PURE__ */ jsx(File.Source, {
1643
+ return /* @__PURE__ */ jsx(Function, {
1580
1644
  name,
1581
- isExportable: true,
1582
- isIndexable: true,
1583
- children: /* @__PURE__ */ jsx(Function, {
1584
- name,
1585
- export: true,
1586
- generics: generics.join(", "),
1587
- params: paramsSignature,
1588
- JSDoc: { comments: buildOperationComments(node) },
1589
- children: `
1645
+ export: true,
1646
+ generics: generics.join(", "),
1647
+ params: paramsSignature,
1648
+ JSDoc: { comments: buildOperationComments(node) },
1649
+ children: `
1590
1650
  const { query: queryConfig = {}, client: config = {} } = options ?? {}
1591
1651
  const { client: queryClient, ...resolvedOptions } = queryConfig
1592
1652
  const queryKey = (resolvedOptions && 'queryKey' in resolvedOptions ? toValue(resolvedOptions.queryKey) : undefined) ?? ${queryKeyName}(${queryKeyParamsCall})
@@ -1601,7 +1661,6 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, t
1601
1661
 
1602
1662
  return queryResult
1603
1663
  `
1604
- })
1605
1664
  });
1606
1665
  }
1607
1666
  // src/generators/infiniteQueryGenerator.tsx
@@ -1616,7 +1675,7 @@ const infiniteQueryGenerator = defineGenerator({
1616
1675
  renderer: jsxRenderer,
1617
1676
  match(node, ctx) {
1618
1677
  const operationNode = node;
1619
- if (!ast.http.isOperation(operationNode)) return false;
1678
+ if (!isOperation(operationNode)) return false;
1620
1679
  const { query, mutation, infinite, hooks } = ctx.options;
1621
1680
  const { isQuery, isMutation } = classifyOperation(operationNode, {
1622
1681
  query,
@@ -1627,7 +1686,7 @@ const infiniteQueryGenerator = defineGenerator({
1627
1686
  return matchesInfinite(operationNode, infiniteOptions);
1628
1687
  },
1629
1688
  operation(node, ctx) {
1630
- if (!ast.http.isOperation(node)) return null;
1689
+ if (!isOperation(node)) return null;
1631
1690
  const { resolver, root } = ctx;
1632
1691
  const { output, query, infinite, client, group } = ctx.options;
1633
1692
  const infiniteOptions = infinite && typeof infinite === "object" ? infinite : null;
@@ -1798,17 +1857,13 @@ function Mutation({ name, clientName, node, tsResolver, mutationKeyName, clientR
1798
1857
  typedHeaders
1799
1858
  });
1800
1859
  const paramsSignature = declarationPrinter.print(paramsNode) ?? "";
1801
- return /* @__PURE__ */ jsx(File.Source, {
1860
+ return /* @__PURE__ */ jsx(Function, {
1802
1861
  name,
1803
- isExportable: true,
1804
- isIndexable: true,
1805
- children: /* @__PURE__ */ jsx(Function, {
1806
- name,
1807
- export: true,
1808
- params: paramsSignature,
1809
- JSDoc: { comments: buildOperationComments(node) },
1810
- generics: ["TContext"],
1811
- children: `
1862
+ export: true,
1863
+ params: paramsSignature,
1864
+ JSDoc: { comments: buildOperationComments(node) },
1865
+ generics: ["TContext"],
1866
+ children: `
1812
1867
  const { mutation = {}, client: config = {} } = options ?? {}
1813
1868
  const { client: queryClient, ...mutationOptions } = mutation;
1814
1869
  const mutationKey = mutationOptions?.mutationKey ?? ${mutationKeyName}()
@@ -1821,7 +1876,6 @@ function Mutation({ name, clientName, node, tsResolver, mutationKeyName, clientR
1821
1876
  ...mutationOptions
1822
1877
  }, queryClient)
1823
1878
  `
1824
- })
1825
1879
  });
1826
1880
  }
1827
1881
  // src/generators/mutationGenerator.tsx
@@ -1834,7 +1888,7 @@ const mutationGenerator = defineGenerator({
1834
1888
  name: "vue-query-mutation",
1835
1889
  renderer: jsxRenderer,
1836
1890
  operation(node, ctx) {
1837
- if (!ast.http.isOperation(node)) return null;
1891
+ if (!isOperation(node)) return null;
1838
1892
  const { resolver, root } = ctx;
1839
1893
  const { output, query, mutation, client, group, hooks } = ctx.options;
1840
1894
  const { isMutation } = classifyOperation(node, {
@@ -1860,7 +1914,8 @@ const mutationGenerator = defineGenerator({
1860
1914
  contractOp,
1861
1915
  returnType: ctx.options.returnType
1862
1916
  });
1863
- const hasRequestGroups = Object.values(getRequestGroups(node)).some(Boolean);
1917
+ const groups = getRequestGroups(node);
1918
+ const hasRequestGroups = requestGroupOrder.some((key) => groups[key]);
1864
1919
  return /* @__PURE__ */ jsxs(HookFile, {
1865
1920
  hook,
1866
1921
  imports: /* @__PURE__ */ jsxs(Fragment, { children: [hasRequestGroups && /* @__PURE__ */ jsx(File.Import, {
@@ -1909,7 +1964,7 @@ const queryGenerator = defineGenerator({
1909
1964
  name: "vue-query",
1910
1965
  renderer: jsxRenderer,
1911
1966
  operation(node, ctx) {
1912
- if (!ast.http.isOperation(node)) return null;
1967
+ if (!isOperation(node)) return null;
1913
1968
  const { resolver, root } = ctx;
1914
1969
  const { output, query, mutation, client, group, hooks } = ctx.options;
1915
1970
  const { isQuery, isMutation } = classifyOperation(node, {