@orval/query 8.24.0 → 8.26.0

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.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { GetterPropType, OutputClient, OutputHttpClient, Verbs, camel, compareVersions, generateFormDataAndUrlEncodedFunction, generateMutator, generateMutatorConfig, generateMutatorRequestOptions, generateOptions, generateVerbImports, getAngularFilteredParamsCallExpression, getAngularFilteredParamsHelperBody, getFullRoute, getRoute, getRouteAsArray, getSuccessResponseType, isObject, isOperationInTagBucket, isString, isSyntheticDefaultImportsAllow, jsDoc, logWarning, makeRouteSafe, mergeDeep, pascal, stringify, toObjectString } from "@orval/core";
1
+ import { GetterPropType, OutputClient, OutputHttpClient, Verbs, camel, compareVersions, generateFormDataAndUrlEncodedFunction, generateMutator, generateMutatorConfig, generateMutatorRequestOptions, generateOptions, generateResponseDateDeserializer, generateVerbImports, getAngularFilteredParamsCallExpression, getAngularFilteredParamsHelperBody, getFullRoute, getRoute, getRouteAsArray, getSuccessResponseType, isObject, isOperationInTagBucket, isString, isSyntheticDefaultImportsAllow, jsDoc, logWarning, makeRouteSafe, mergeDeep, pascal, stringify, toObjectString } from "@orval/core";
2
2
  import { generateFetchHeader, generateRequestFunction } from "@orval/fetch";
3
3
  import nodePath from "node:path";
4
4
  import { styleText } from "node:util";
@@ -180,9 +180,7 @@ const generateAngularHttpRequestFunction = ({ headers, queryParams, operationNam
180
180
  case "delete":
181
181
  httpCall = bodyArg ? `http.${verb}${httpGeneric}(url, { ${httpOptions.length > 0 ? httpOptions.join(", ") + ", " : ""}body: ${bodyArg} })` : `http.${verb}${httpGeneric}(url${optionsStr})`;
182
182
  break;
183
- default:
184
- httpCall = `http.${verb}${httpGeneric}(url, ${bodyArg || "undefined"}${optionsStr})`;
185
- break;
183
+ default: httpCall = `http.${verb}${httpGeneric}(url, ${bodyArg || "undefined"}${optionsStr})`;
186
184
  }
187
185
  const responseType = response.definition.success;
188
186
  const isPrimitiveType = [
@@ -227,6 +225,13 @@ const generateAxiosRequestFunction = ({ headers, queryParams, operationName, res
227
225
  isFormData,
228
226
  isFormUrlEncoded
229
227
  });
228
+ const dateDeserializer = override.useDatesTransform ? generateResponseDateDeserializer({
229
+ operationName,
230
+ response,
231
+ context
232
+ }) : void 0;
233
+ const dateDeserializerImplementation = dateDeserializer ? `\n${dateDeserializer.implementation}` : "";
234
+ const thenDateDeserializer = dateDeserializer ? `.then(${dateDeserializer.name})` : "";
230
235
  if (mutator) {
231
236
  const mutatorConfig = generateMutatorConfig({
232
237
  route,
@@ -253,14 +258,14 @@ const generateAxiosRequestFunction = ({ headers, queryParams, operationName, res
253
258
  ${bodyForm}
254
259
  return ${operationName}(
255
260
  ${mutatorConfig},
256
- ${requestOptions});
261
+ ${requestOptions})${thenDateDeserializer};
257
262
  }`;
258
263
  return `${override.query.shouldExportMutatorHooks ? "export " : ""}const use${pascal(operationName)}Hook = () => {
259
264
  const ${operationName} = ${mutator.name}<${response.definition.success || "unknown"}>();
260
265
 
261
266
  return ${adapter.wrapHookMutatorCallback(callback, operationName)}
262
267
  }
263
- `;
268
+ ${dateDeserializerImplementation}`;
264
269
  }
265
270
  return `${override.query.shouldExportHttpClient ? "export " : ""}const ${operationName} = (\n ${propsImplementation}\n ${isRequestOptions && mutator.hasSecondArg ? `options${context.output.optionsParamRequired ? "" : "?"}: SecondParameter<typeof ${mutator.name}>,` : ""}${getSignalDefinition({
266
271
  hasSignal,
@@ -270,9 +275,9 @@ const generateAxiosRequestFunction = ({ headers, queryParams, operationName, res
270
275
  ${bodyForm}
271
276
  return ${mutator.name}<${response.definition.success || "unknown"}>(
272
277
  ${mutatorConfig},
273
- ${requestOptions});
278
+ ${requestOptions})${thenDateDeserializer};
274
279
  }
275
- `;
280
+ ${dateDeserializerImplementation}`;
276
281
  }
277
282
  const isSyntheticDefaultImportsAllowed = isSyntheticDefaultImportsAllow(context.output.tsconfig);
278
283
  const options = generateOptions({
@@ -300,9 +305,9 @@ const generateAxiosRequestFunction = ({ headers, queryParams, operationName, res
300
305
  return `${override.query.shouldExportHttpClient ? "export " : ""}const ${operationName} = (\n ${queryProps} ${optionsArgs} ): Promise<AxiosResponse<${response.definition.success || "unknown"}>> => {
301
306
  ${unrefStatements}
302
307
  ${bodyForm}
303
- return axios${isSyntheticDefaultImportsAllowed ? "" : ".default"}.${verb}(${options});
308
+ return axios${isSyntheticDefaultImportsAllowed ? "" : ".default"}.${verb}(${options})${dateDeserializer ? `.then((res) => { res.data = ${dateDeserializer.name}(res.data); return res; })` : ""};
304
309
  }
305
- `;
310
+ ${dateDeserializerImplementation}`;
306
311
  };
307
312
  const generateRequestOptionsArguments = ({ isRequestOptions, hasSignal, hasSignalParam = false }) => {
308
313
  if (isRequestOptions) return "options?: AxiosRequestConfig\n";
@@ -352,9 +357,11 @@ const getQueryOptions = ({ isRequestOptions, mutator, isExactOptionalPropertyTyp
352
357
  const getHookOptions = ({ isRequestOptions, httpClient, mutator, useRuntimeFetcher = false }) => {
353
358
  if (!isRequestOptions) return "";
354
359
  let value = "const {query: queryOptions";
355
- if (!mutator) if (httpClient === OutputHttpClient.AXIOS) value += ", axios: axiosOptions";
356
- else if (httpClient === OutputHttpClient.FETCH && useRuntimeFetcher) value += ", fetch: fetchOptions, fetcher: fetcherFn";
357
- else value += ", fetch: fetchOptions";
360
+ if (!mutator) {
361
+ if (httpClient === OutputHttpClient.AXIOS) value += ", axios: axiosOptions";
362
+ else if (httpClient === OutputHttpClient.FETCH && useRuntimeFetcher) value += ", fetch: fetchOptions, fetcher: fetcherFn";
363
+ else value += ", fetch: fetchOptions";
364
+ }
358
365
  if (mutator?.hasSecondArg) value += ", request: requestOptions";
359
366
  value += "} = options ?? {};";
360
367
  return value;
@@ -715,6 +722,12 @@ const getSolidQueryImports = (prefix, hasRenamedOptionsTypes) => {
715
722
  { name: "MutationFunction" },
716
723
  { name: `${capitalized}QueryResult` },
717
724
  { name: `${capitalized}InfiniteQueryResult` },
725
+ { name: `Defined${capitalized}QueryResult` },
726
+ { name: `Defined${capitalized}InfiniteQueryResult` },
727
+ { name: "DefinedInitialDataOptions" },
728
+ { name: "UndefinedInitialDataOptions" },
729
+ { name: "DefinedInitialDataInfiniteOptions" },
730
+ { name: "UndefinedInitialDataInfiniteOptions" },
718
731
  { name: "QueryKey" },
719
732
  { name: "InfiniteData" },
720
733
  { name: `${capitalized}MutationResult` },
@@ -906,10 +919,16 @@ const QueryType = {
906
919
  SUSPENSE_QUERY: "suspenseQuery",
907
920
  SUSPENSE_INFINITE: "suspenseInfiniteQuery"
908
921
  };
909
- const INFINITE_QUERY_PROPERTIES = new Set(["getNextPageParam", "getPreviousPageParam"]);
922
+ const INFINITE_QUERY_PROPERTIES = /* @__PURE__ */ new Set(["getNextPageParam", "getPreviousPageParam"]);
923
+ /**
924
+ * Whether a key from `override.query.options` reaches the emitted options
925
+ * literal for this query type. Page-param callbacks are meaningless on a plain
926
+ * query, so they are dropped there.
927
+ */
928
+ const isConfiguredOptionEmitted = (key, type) => isInfiniteQuery(type) || !INFINITE_QUERY_PROPERTIES.has(key);
910
929
  const generateQueryOptions = ({ params, options, type, adapter }) => {
911
930
  if (options === false) return "";
912
- const queryConfig = isObject(options) ? ` ${stringify(omitBy(options, (_, key) => type !== QueryType.INFINITE && type !== QueryType.SUSPENSE_INFINITE && INFINITE_QUERY_PROPERTIES.has(key)))?.slice(1, -1)}` : "";
931
+ const queryConfig = isObject(options) ? ` ${stringify(omitBy(options, (_, key) => !isConfiguredOptionEmitted(key, type)))?.slice(1, -1)}` : "";
913
932
  if (params.length === 0 || isSuspenseQuery(type)) {
914
933
  if (options) return `${queryConfig} ...queryOptions`;
915
934
  return "...queryOptions";
@@ -919,24 +938,71 @@ const generateQueryOptions = ({ params, options, type, adapter }) => {
919
938
  const isSuspenseQuery = (type) => {
920
939
  return [QueryType.SUSPENSE_INFINITE, QueryType.SUSPENSE_QUERY].includes(type);
921
940
  };
922
- const getQueryOptionsDefinition = ({ operationName, mutator, definitions, type, prefix, hasQueryV5, hasQueryV5WithInfiniteQueryOptionsError, queryParams, queryParam, isReturnType, initialData, adapter }) => {
941
+ const isInfiniteQuery = (type) => {
942
+ return [QueryType.INFINITE, QueryType.SUSPENSE_INFINITE].includes(type);
943
+ };
944
+ const getOptionsKind = (type) => isInfiniteQuery(type) ? "infiniteQuery" : "query";
945
+ /**
946
+ * Resolves the adapter's constraint together with the plain options type it has
947
+ * to be rendered against. Both are optional on `FrameworkAdapter` and neither is
948
+ * useful alone: without a type name there is nothing to `Pick` from, and without
949
+ * required keys the caller has nothing to supply. Returning them as one value is
950
+ * what stops the signature and the type disagreeing about whether `options` is
951
+ * mandatory.
952
+ */
953
+ const resolveUserQueryOptionsConstraint = (adapter, type, options) => {
954
+ const constraint = adapter?.getUserQueryOptionsConstraint?.(type);
955
+ if (!constraint) return;
956
+ const optionsTypeName = adapter?.getOptionsReturnTypeName?.(getOptionsKind(type));
957
+ if (!optionsTypeName) return;
958
+ const require = isObject(options) ? constraint.require?.filter((key) => !(isConfiguredOptionEmitted(key, type) && Object.hasOwn(options, key))) : constraint.require;
959
+ return {
960
+ ...constraint,
961
+ require,
962
+ optionsTypeName
963
+ };
964
+ };
965
+ /**
966
+ * Whether the caller must supply options the generator cannot infer, which is
967
+ * what makes the whole `options` parameter mandatory. An `exclude`-only
968
+ * constraint reshapes the type without requiring anything, so it does not count.
969
+ */
970
+ const requiresUserSuppliedQueryOptions = (adapter, type, options) => !!type && !!resolveUserQueryOptionsConstraint(adapter, type, options)?.require?.length;
971
+ const getQueryOptionsDefinition = ({ operationName, mutator, definitions, mutationVariablesType, type, prefix, hasQueryV5, hasQueryV5WithInfiniteQueryOptionsError, queryParams, queryParam, isReturnType, initialData, adapter, options }) => {
923
972
  const isMutatorHook = mutator?.isHook;
924
973
  const partialOptions = !isReturnType && hasQueryV5;
925
974
  if (type) {
926
975
  const funcReturnType = `Awaited<ReturnType<${isMutatorHook ? `ReturnType<typeof use${pascal(operationName)}Hook>` : `typeof ${operationName}`}>>`;
927
- const optionTypeInitialDataPostfix = initialData && !isSuspenseQuery(type) ? ` & Pick<
928
- ${pascal(initialData)}InitialDataOptions<
976
+ const isInfiniteType = isInfiniteQuery(type);
977
+ const infiniteTypeArgs = hasQueryV5 && isInfiniteType && queryParam && queryParams ? `, QueryKey, ${queryParams.schema.name}['${queryParam}']` : "";
978
+ const initialDataOptionsType = initialData && adapter?.getInitialDataOptionsType ? adapter.getInitialDataOptionsType({
979
+ initialData,
980
+ isInfinite: isInfiniteType,
981
+ funcReturnType,
982
+ infiniteTypeArgs
983
+ }) : `${pascal(initialData ?? "")}InitialDataOptions<
929
984
  ${funcReturnType},
930
985
  TError,
931
- ${funcReturnType}${hasQueryV5 && (type === QueryType.INFINITE || type === QueryType.SUSPENSE_INFINITE) && queryParam && queryParams ? `, QueryKey` : ""}
932
- > , 'initialData'
986
+ ${funcReturnType}${hasQueryV5 && isInfiniteType && queryParam && queryParams ? `, QueryKey` : ""}
987
+ >`;
988
+ const optionTypeInitialDataPostfix = initialData && !isSuspenseQuery(type) ? ` & Pick<
989
+ ${initialDataOptionsType} , 'initialData'
933
990
  >` : "";
934
- const optionsTypeName = isReturnType && adapter?.getOptionsReturnTypeName ? adapter.getOptionsReturnTypeName(type === QueryType.INFINITE || type === QueryType.SUSPENSE_INFINITE ? "infiniteQuery" : "query") : void 0;
935
- const optionType = optionsTypeName ? `${optionsTypeName}<${funcReturnType}, TError, TData${hasQueryV5 && (type === QueryType.INFINITE || type === QueryType.SUSPENSE_INFINITE) && queryParam && queryParams ? `, QueryKey, ${queryParams.schema.name}['${queryParam}']` : ""}>` : `${prefix}${pascal(type)}Options<${funcReturnType}, TError, TData${hasQueryV5 && (type === QueryType.INFINITE || type === QueryType.SUSPENSE_INFINITE) && queryParam && queryParams ? hasQueryV5WithInfiniteQueryOptionsError ? `, QueryKey, ${queryParams.schema.name}['${queryParam}']` : `, ${funcReturnType}, QueryKey, ${queryParams.schema.name}['${queryParam}']` : ""}>`;
991
+ const userOptionsConstraint = isReturnType ? void 0 : resolveUserQueryOptionsConstraint(adapter, type, options);
992
+ if (userOptionsConstraint) {
993
+ const { optionsTypeName, require = [], exclude = [] } = userOptionsConstraint;
994
+ const plainOptionsType = `${optionsTypeName}<${funcReturnType}, TError, TData${infiniteTypeArgs}>`;
995
+ const quoteKeys = (keys) => keys.map((key) => `'${key}'`).join(" | ");
996
+ const omitted = [...require, ...exclude];
997
+ return `${omitted.length ? `Omit<Partial<${plainOptionsType}>, ${quoteKeys(omitted)}>` : `Partial<${plainOptionsType}>`}${require.length ? ` & Pick<${plainOptionsType}, ${quoteKeys(require)}>` : ""}${optionTypeInitialDataPostfix}`;
998
+ }
999
+ const optionsTypeName = isReturnType ? adapter?.getOptionsReturnTypeName?.(getOptionsKind(type)) : void 0;
1000
+ const optionType = optionsTypeName ? `${optionsTypeName}<${funcReturnType}, TError, TData${infiniteTypeArgs}>` : `${prefix}${pascal(type)}Options<${funcReturnType}, TError, TData${hasQueryV5 && isInfiniteType && queryParam && queryParams ? hasQueryV5WithInfiniteQueryOptionsError ? `, QueryKey, ${queryParams.schema.name}['${queryParam}']` : `, ${funcReturnType}, QueryKey, ${queryParams.schema.name}['${queryParam}']` : ""}>`;
936
1001
  return `${partialOptions ? "Partial<" : ""}${optionType}${partialOptions ? ">" : ""}${optionTypeInitialDataPostfix}`;
937
1002
  }
938
1003
  const mutationOptionsTypeName = adapter?.getOptionsReturnTypeName ? adapter.getOptionsReturnTypeName("mutation") : void 0;
939
- return mutationOptionsTypeName ? `${mutationOptionsTypeName}<Awaited<ReturnType<${isMutatorHook ? `ReturnType<typeof use${pascal(operationName)}Hook>` : `typeof ${operationName}`}>>, TError,${definitions ? `{${definitions}}` : "void"}, TContext>` : `${prefix}MutationOptions<Awaited<ReturnType<${isMutatorHook ? `ReturnType<typeof use${pascal(operationName)}Hook>` : `typeof ${operationName}`}>>, TError,${definitions ? `{${definitions}}` : "void"}, TContext>`;
1004
+ const variablesType = mutationVariablesType ?? (definitions ? `{${definitions}}` : "void");
1005
+ return mutationOptionsTypeName ? `${mutationOptionsTypeName}<Awaited<ReturnType<${isMutatorHook ? `ReturnType<typeof use${pascal(operationName)}Hook>` : `typeof ${operationName}`}>>, TError,${variablesType}, TContext>` : `${prefix}MutationOptions<Awaited<ReturnType<${isMutatorHook ? `ReturnType<typeof use${pascal(operationName)}Hook>` : `typeof ${operationName}`}>>, TError,${variablesType}, TContext>`;
940
1006
  };
941
1007
  //#endregion
942
1008
  //#region src/frameworks/angular.ts
@@ -1017,11 +1083,12 @@ const createAngularAdapter = ({ hasQueryV5, hasQueryV5WithDataTagError, hasQuery
1017
1083
  getQueryOptionsDefinitionPrefix() {
1018
1084
  return prefix;
1019
1085
  },
1020
- generateQueryArguments({ operationName, definitions, mutator, isRequestOptions, type, queryParams, queryParam, initialData, httpClient, forQueryOptions = false, hasInvalidation, useRuntimeFetcher }) {
1086
+ generateQueryArguments({ operationName, definitions, mutationVariablesType, mutator, isRequestOptions, type, queryParams, queryParam, initialData, httpClient, forQueryOptions = false, hasInvalidation, useRuntimeFetcher }) {
1021
1087
  const definition = getQueryOptionsDefinition({
1022
1088
  operationName,
1023
1089
  mutator,
1024
1090
  definitions,
1091
+ mutationVariablesType,
1025
1092
  type,
1026
1093
  prefix,
1027
1094
  hasQueryV5,
@@ -1117,6 +1184,11 @@ const createReactAdapter = ({ hasQueryV5, hasQueryV5WithDataTagError, hasQueryV5
1117
1184
  });
1118
1185
  //#endregion
1119
1186
  //#region src/frameworks/solid.ts
1187
+ const QUERY_OPTIONS_CONSTRAINT = { exclude: ["initialData"] };
1188
+ const INFINITE_QUERY_OPTIONS_CONSTRAINT = {
1189
+ require: ["initialPageParam", "getNextPageParam"],
1190
+ exclude: ["initialData"]
1191
+ };
1120
1192
  const createSolidAdapter = ({ hasQueryV5, hasQueryV5WithDataTagError, hasQueryV5WithInfiniteQueryOptionsError, hasQueryV5WithMutationContextOnSuccess, hasQueryV5WithRequiredContextOnSuccess, hasSolidQueryUsePrefix, hasSolidQueryRenamedOptionsTypes }) => ({
1121
1193
  outputClient: OutputClient.SOLID_QUERY,
1122
1194
  hookPrefix: hasSolidQueryUsePrefix ? "use" : "create",
@@ -1145,11 +1217,25 @@ const createSolidAdapter = ({ hasQueryV5, hasQueryV5WithDataTagError, hasQueryV5
1145
1217
  shouldCastQueryOptions() {
1146
1218
  return false;
1147
1219
  },
1148
- getQueryReturnType({ type }) {
1220
+ getUserQueryOptionsConstraint(type) {
1221
+ if (!hasQueryV5) return;
1222
+ if (isInfiniteQuery(type)) return INFINITE_QUERY_OPTIONS_CONSTRAINT;
1223
+ return hasSolidQueryUsePrefix ? QUERY_OPTIONS_CONSTRAINT : void 0;
1224
+ },
1225
+ getQueryType(type) {
1226
+ return getQueryTypeForFramework(type);
1227
+ },
1228
+ shouldGenerateOverrideTypes() {
1229
+ return hasQueryV5 && hasSolidQueryUsePrefix;
1230
+ },
1231
+ getInitialDataOptionsType({ initialData, isInfinite, funcReturnType, infiniteTypeArgs }) {
1232
+ return `ReturnType<${`${pascal(initialData)}InitialData${isInfinite ? "Infinite" : ""}Options`}<${funcReturnType}, TError, TData${infiniteTypeArgs}>>`;
1233
+ },
1234
+ getQueryReturnType({ type, isInitialDataDefined }) {
1149
1235
  const prefix = hasSolidQueryUsePrefix ? "Use" : "Create";
1150
1236
  const queryKeyType = hasQueryV5 ? `DataTag<QueryKey, TData${hasQueryV5WithDataTagError ? ", TError" : ""}>` : "QueryKey";
1151
- if (type !== QueryType.INFINITE && type !== QueryType.SUSPENSE_INFINITE) return `${prefix}QueryResult<TData, TError> & { queryKey: ${queryKeyType} }`;
1152
- return `${prefix}InfiniteQueryResult<TData, TError> & { queryKey: ${queryKeyType} }`;
1237
+ const resultName = isInfiniteQuery(type) ? "InfiniteQueryResult" : "QueryResult";
1238
+ return `${isInitialDataDefined ? "Defined" : ""}${prefix}${resultName}<TData, TError> & { queryKey: ${queryKeyType} }`;
1153
1239
  },
1154
1240
  getMutationReturnType({ dataType, variableType }) {
1155
1241
  return `: ${hasSolidQueryUsePrefix ? "Use" : "Create"}MutationResult<
@@ -1242,11 +1328,12 @@ const createSvelteAdapter = ({ hasSvelteQueryV4, hasSvelteQueryV6, hasQueryV5, h
1242
1328
  getQueryOptionsDefinitionPrefix() {
1243
1329
  return prefix;
1244
1330
  },
1245
- generateQueryArguments({ operationName, definitions, mutator, isRequestOptions, type, queryParams, queryParam, initialData, httpClient, forQueryOptions = false, hasInvalidation, useRuntimeFetcher }) {
1331
+ generateQueryArguments({ operationName, definitions, mutationVariablesType, mutator, isRequestOptions, type, queryParams, queryParam, initialData, httpClient, forQueryOptions = false, hasInvalidation, useRuntimeFetcher }) {
1246
1332
  const definition = getQueryOptionsDefinition({
1247
1333
  operationName,
1248
1334
  mutator,
1249
1335
  definitions,
1336
+ mutationVariablesType,
1250
1337
  type,
1251
1338
  prefix,
1252
1339
  hasQueryV5,
@@ -1386,27 +1473,28 @@ const createVueAdapter = ({ hasVueQueryV4, hasQueryV5, hasQueryV5WithDataTagErro
1386
1473
  supportsMutationInvalidation() {
1387
1474
  return hasQueryV5;
1388
1475
  },
1389
- generateMutationOnSuccess({ operationName, definitions, isRequestOptions, generateInvalidateCall, uniqueInvalidates }) {
1476
+ generateMutationOnSuccess({ operationName, definitions, mutationVariablesType, isRequestOptions, generateInvalidateCall, uniqueInvalidates }) {
1390
1477
  const invalidateCalls = uniqueInvalidates.map((t) => generateInvalidateCall(t)).join("\n");
1478
+ const variablesType = mutationVariablesType ?? (definitions ? `{${definitions}}` : "void");
1391
1479
  if (hasQueryV5WithMutationContextOnSuccess) {
1392
- if (isRequestOptions) return ` const onSuccess = (data: Awaited<ReturnType<typeof ${operationName}>>, variables: ${definitions ? `{${definitions}}` : "void"}, onMutateResult: TContext, context: MutationFunctionContext) => {
1480
+ if (isRequestOptions) return ` const onSuccess = (data: Awaited<ReturnType<typeof ${operationName}>>, variables: ${variablesType}, onMutateResult: TContext, context: MutationFunctionContext) => {
1393
1481
  if (!options?.skipInvalidation) {
1394
1482
  ${invalidateCalls}
1395
1483
  }
1396
1484
  unref(unref(typeof mutationOptions === 'function' ? mutationOptions() : mutationOptions)?.onSuccess)?.(data, variables, onMutateResult, context);
1397
1485
  };`;
1398
- return ` const onSuccess = (data: Awaited<ReturnType<typeof ${operationName}>>, variables: ${definitions ? `{${definitions}}` : "void"}, onMutateResult: TContext, context: MutationFunctionContext) => {
1486
+ return ` const onSuccess = (data: Awaited<ReturnType<typeof ${operationName}>>, variables: ${variablesType}, onMutateResult: TContext, context: MutationFunctionContext) => {
1399
1487
  ${invalidateCalls}
1400
1488
  unref(unref(typeof mutationOptions === 'function' ? mutationOptions() : mutationOptions)?.onSuccess)?.(data, variables, onMutateResult, context);
1401
1489
  };`;
1402
1490
  }
1403
- if (isRequestOptions) return ` const onSuccess = (data: Awaited<ReturnType<typeof ${operationName}>>, variables: ${definitions ? `{${definitions}}` : "void"}, context: TContext${hasQueryV5WithRequiredContextOnSuccess ? "" : " | undefined"}) => {
1491
+ if (isRequestOptions) return ` const onSuccess = (data: Awaited<ReturnType<typeof ${operationName}>>, variables: ${variablesType}, context: TContext${hasQueryV5WithRequiredContextOnSuccess ? "" : " | undefined"}) => {
1404
1492
  if (!options?.skipInvalidation) {
1405
1493
  ${invalidateCalls}
1406
1494
  }
1407
1495
  unref(unref(typeof mutationOptions === 'function' ? mutationOptions() : mutationOptions)?.onSuccess)?.(data, variables, context);
1408
1496
  };`;
1409
- return ` const onSuccess = (data: Awaited<ReturnType<typeof ${operationName}>>, variables: ${definitions ? `{${definitions}}` : "void"}, context: TContext${hasQueryV5WithRequiredContextOnSuccess ? "" : " | undefined"}) => {
1497
+ return ` const onSuccess = (data: Awaited<ReturnType<typeof ${operationName}>>, variables: ${variablesType}, context: TContext${hasQueryV5WithRequiredContextOnSuccess ? "" : " | undefined"}) => {
1410
1498
  ${invalidateCalls}
1411
1499
  unref(unref(typeof mutationOptions === 'function' ? mutationOptions() : mutationOptions)?.onSuccess)?.(data, variables, context);
1412
1500
  };`;
@@ -1472,48 +1560,53 @@ const withDefaults = (adapter) => {
1472
1560
  getOptionalQueryClientArgument() {
1473
1561
  return composed.hasQueryV5 ? ", queryClient?: QueryClient" : "";
1474
1562
  },
1475
- generateQueryArguments({ operationName, definitions, mutator, isRequestOptions, type, queryParams, queryParam, initialData, httpClient, hasInvalidation, useRuntimeFetcher }) {
1563
+ generateQueryArguments({ operationName, definitions, mutationVariablesType, mutator, isRequestOptions, type, queryParams, queryParam, initialData, httpClient, hasInvalidation, useRuntimeFetcher, options }) {
1564
+ const prefix = composed.getQueryOptionsDefinitionPrefix();
1476
1565
  const definition = getQueryOptionsDefinition({
1477
1566
  operationName,
1478
1567
  mutator,
1479
1568
  definitions,
1569
+ mutationVariablesType,
1480
1570
  type,
1481
- prefix: composed.getQueryOptionsDefinitionPrefix(),
1571
+ prefix,
1482
1572
  hasQueryV5: composed.hasQueryV5,
1483
1573
  hasQueryV5WithInfiniteQueryOptionsError: composed.hasQueryV5WithInfiniteQueryOptionsError,
1484
1574
  queryParams,
1485
1575
  queryParam,
1486
1576
  isReturnType: false,
1487
1577
  initialData,
1488
- adapter: composed
1578
+ adapter: composed,
1579
+ options
1489
1580
  });
1490
- if (!isRequestOptions) return `${type ? "queryOptions" : "mutationOptions"}${initialData === "defined" ? "" : "?"}: ${definition}`;
1581
+ const requiresUserQueryOptions = requiresUserSuppliedQueryOptions(composed, type, options);
1582
+ if (!isRequestOptions) return `${type ? "queryOptions" : "mutationOptions"}${initialData === "defined" || requiresUserQueryOptions ? "" : "?"}: ${definition}`;
1491
1583
  const requestType = getQueryArgumentsRequestType(httpClient, mutator, useRuntimeFetcher);
1492
- const isQueryRequired = initialData === "defined";
1584
+ const isQueryRequired = initialData === "defined" || requiresUserQueryOptions;
1493
1585
  const optionsType = `{ ${type ? "query" : "mutation"}${isQueryRequired ? "" : "?"}:${definition}, ${!type && hasInvalidation ? "skipInvalidation?: boolean, " : ""}${requestType}}`;
1494
1586
  return `options${isQueryRequired ? "" : "?"}: ${optionsType}\n`;
1495
1587
  },
1496
- generateMutationOnSuccess({ operationName, definitions, isRequestOptions, generateInvalidateCall, uniqueInvalidates }) {
1588
+ generateMutationOnSuccess({ operationName, definitions, mutationVariablesType, isRequestOptions, generateInvalidateCall, uniqueInvalidates }) {
1497
1589
  const invalidateCalls = uniqueInvalidates.map((t) => generateInvalidateCall(t)).join("\n");
1590
+ const variablesType = mutationVariablesType ?? (definitions ? `{${definitions}}` : "void");
1498
1591
  if (composed.hasQueryV5WithMutationContextOnSuccess) {
1499
- if (isRequestOptions) return ` const onSuccess = (data: Awaited<ReturnType<typeof ${operationName}>>, variables: ${definitions ? `{${definitions}}` : "void"}, onMutateResult: TContext, context: MutationFunctionContext) => {
1592
+ if (isRequestOptions) return ` const onSuccess = (data: Awaited<ReturnType<typeof ${operationName}>>, variables: ${variablesType}, onMutateResult: TContext, context: MutationFunctionContext) => {
1500
1593
  if (!options?.skipInvalidation) {
1501
1594
  ${invalidateCalls}
1502
1595
  }
1503
1596
  mutationOptions?.onSuccess?.(data, variables, onMutateResult, context);
1504
1597
  };`;
1505
- return ` const onSuccess = (data: Awaited<ReturnType<typeof ${operationName}>>, variables: ${definitions ? `{${definitions}}` : "void"}, onMutateResult: TContext, context: MutationFunctionContext) => {
1598
+ return ` const onSuccess = (data: Awaited<ReturnType<typeof ${operationName}>>, variables: ${variablesType}, onMutateResult: TContext, context: MutationFunctionContext) => {
1506
1599
  ${invalidateCalls}
1507
1600
  mutationOptions?.onSuccess?.(data, variables, onMutateResult, context);
1508
1601
  };`;
1509
1602
  } else {
1510
- if (isRequestOptions) return ` const onSuccess = (data: Awaited<ReturnType<typeof ${operationName}>>, variables: ${definitions ? `{${definitions}}` : "void"}, context: TContext${composed.hasQueryV5WithRequiredContextOnSuccess ? "" : " | undefined"}) => {
1603
+ if (isRequestOptions) return ` const onSuccess = (data: Awaited<ReturnType<typeof ${operationName}>>, variables: ${variablesType}, context: TContext${composed.hasQueryV5WithRequiredContextOnSuccess ? "" : " | undefined"}) => {
1511
1604
  if (!options?.skipInvalidation) {
1512
1605
  ${invalidateCalls}
1513
1606
  }
1514
1607
  mutationOptions?.onSuccess?.(data, variables, context);
1515
1608
  };`;
1516
- return ` const onSuccess = (data: Awaited<ReturnType<typeof ${operationName}>>, variables: ${definitions ? `{${definitions}}` : "void"}, context: TContext${composed.hasQueryV5WithRequiredContextOnSuccess ? "" : " | undefined"}) => {
1609
+ return ` const onSuccess = (data: Awaited<ReturnType<typeof ${operationName}>>, variables: ${variablesType}, context: TContext${composed.hasQueryV5WithRequiredContextOnSuccess ? "" : " | undefined"}) => {
1517
1610
  ${invalidateCalls}
1518
1611
  mutationOptions?.onSuccess?.(data, variables, context);
1519
1612
  };`;
@@ -1535,23 +1628,30 @@ const createFrameworkAdapter = ({ outputClient, packageJson, queryVersion }) =>
1535
1628
  const _hasQueryV5WithMutationContextOnSuccess = isQueryV5WithMutationContextOnSuccess(packageJson, clientType);
1536
1629
  const _hasQueryV5WithRequiredContextOnSuccess = isQueryV5WithRequiredContextOnSuccess(packageJson, clientType);
1537
1630
  switch (outputClient) {
1538
- case OutputClient.VUE_QUERY: return withDefaults(createVueAdapter({
1539
- hasVueQueryV4: !isVueQueryV3(packageJson) || queryVersion === 4,
1540
- hasQueryV5: _hasQueryV5,
1541
- hasQueryV5WithDataTagError: _hasQueryV5WithDataTagError,
1542
- hasQueryV5WithInfiniteQueryOptionsError: _hasQueryV5WithInfiniteQueryOptionsError,
1543
- hasQueryV5WithMutationContextOnSuccess: _hasQueryV5WithMutationContextOnSuccess,
1544
- hasQueryV5WithRequiredContextOnSuccess: _hasQueryV5WithRequiredContextOnSuccess
1545
- }));
1546
- case OutputClient.SVELTE_QUERY: return withDefaults(createSvelteAdapter({
1547
- hasSvelteQueryV4: !isSvelteQueryV3(packageJson) || queryVersion === 4,
1548
- hasSvelteQueryV6: isSvelteQueryV6(packageJson),
1549
- hasQueryV5: _hasQueryV5,
1550
- hasQueryV5WithDataTagError: _hasQueryV5WithDataTagError,
1551
- hasQueryV5WithInfiniteQueryOptionsError: _hasQueryV5WithInfiniteQueryOptionsError,
1552
- hasQueryV5WithMutationContextOnSuccess: _hasQueryV5WithMutationContextOnSuccess,
1553
- hasQueryV5WithRequiredContextOnSuccess: _hasQueryV5WithRequiredContextOnSuccess
1554
- }));
1631
+ case OutputClient.VUE_QUERY: {
1632
+ const hasVueQueryV4 = !isVueQueryV3(packageJson) || queryVersion === 4;
1633
+ return withDefaults(createVueAdapter({
1634
+ hasVueQueryV4,
1635
+ hasQueryV5: _hasQueryV5,
1636
+ hasQueryV5WithDataTagError: _hasQueryV5WithDataTagError,
1637
+ hasQueryV5WithInfiniteQueryOptionsError: _hasQueryV5WithInfiniteQueryOptionsError,
1638
+ hasQueryV5WithMutationContextOnSuccess: _hasQueryV5WithMutationContextOnSuccess,
1639
+ hasQueryV5WithRequiredContextOnSuccess: _hasQueryV5WithRequiredContextOnSuccess
1640
+ }));
1641
+ }
1642
+ case OutputClient.SVELTE_QUERY: {
1643
+ const hasSvelteQueryV4 = !isSvelteQueryV3(packageJson) || queryVersion === 4;
1644
+ const _hasSvelteQueryV6 = isSvelteQueryV6(packageJson);
1645
+ return withDefaults(createSvelteAdapter({
1646
+ hasSvelteQueryV4,
1647
+ hasSvelteQueryV6: _hasSvelteQueryV6,
1648
+ hasQueryV5: _hasQueryV5,
1649
+ hasQueryV5WithDataTagError: _hasQueryV5WithDataTagError,
1650
+ hasQueryV5WithInfiniteQueryOptionsError: _hasQueryV5WithInfiniteQueryOptionsError,
1651
+ hasQueryV5WithMutationContextOnSuccess: _hasQueryV5WithMutationContextOnSuccess,
1652
+ hasQueryV5WithRequiredContextOnSuccess: _hasQueryV5WithRequiredContextOnSuccess
1653
+ }));
1654
+ }
1555
1655
  case OutputClient.ANGULAR_QUERY: return withDefaults(createAngularAdapter({
1556
1656
  hasQueryV5: _hasQueryV5,
1557
1657
  hasQueryV5WithDataTagError: _hasQueryV5WithDataTagError,
@@ -1559,15 +1659,19 @@ const createFrameworkAdapter = ({ outputClient, packageJson, queryVersion }) =>
1559
1659
  hasQueryV5WithMutationContextOnSuccess: _hasQueryV5WithMutationContextOnSuccess,
1560
1660
  hasQueryV5WithRequiredContextOnSuccess: _hasQueryV5WithRequiredContextOnSuccess
1561
1661
  }));
1562
- case OutputClient.SOLID_QUERY: return withDefaults(createSolidAdapter({
1563
- hasQueryV5: _hasQueryV5,
1564
- hasQueryV5WithDataTagError: _hasQueryV5WithDataTagError,
1565
- hasQueryV5WithInfiniteQueryOptionsError: _hasQueryV5WithInfiniteQueryOptionsError,
1566
- hasQueryV5WithMutationContextOnSuccess: _hasQueryV5WithMutationContextOnSuccess,
1567
- hasQueryV5WithRequiredContextOnSuccess: _hasQueryV5WithRequiredContextOnSuccess,
1568
- hasSolidQueryUsePrefix: isSolidQueryWithUsePrefix(packageJson),
1569
- hasSolidQueryRenamedOptionsTypes: isSolidQueryWithRenamedOptionsTypes(packageJson)
1570
- }));
1662
+ case OutputClient.SOLID_QUERY: {
1663
+ const hasSolidQueryWithUsePrefix = isSolidQueryWithUsePrefix(packageJson);
1664
+ const hasSolidQueryWithRenamedOptionsTypes = isSolidQueryWithRenamedOptionsTypes(packageJson);
1665
+ return withDefaults(createSolidAdapter({
1666
+ hasQueryV5: _hasQueryV5,
1667
+ hasQueryV5WithDataTagError: _hasQueryV5WithDataTagError,
1668
+ hasQueryV5WithInfiniteQueryOptionsError: _hasQueryV5WithInfiniteQueryOptionsError,
1669
+ hasQueryV5WithMutationContextOnSuccess: _hasQueryV5WithMutationContextOnSuccess,
1670
+ hasQueryV5WithRequiredContextOnSuccess: _hasQueryV5WithRequiredContextOnSuccess,
1671
+ hasSolidQueryUsePrefix: hasSolidQueryWithUsePrefix,
1672
+ hasSolidQueryRenamedOptionsTypes: hasSolidQueryWithRenamedOptionsTypes
1673
+ }));
1674
+ }
1571
1675
  default: return withDefaults(createReactAdapter({
1572
1676
  hasQueryV5: _hasQueryV5,
1573
1677
  hasQueryV5WithDataTagError: _hasQueryV5WithDataTagError,
@@ -1603,7 +1707,7 @@ const HTTP_METHODS = [
1603
1707
  "head",
1604
1708
  "trace"
1605
1709
  ];
1606
- const MUTATION_OPERATION_LOCAL_NAMES = new Set([
1710
+ const MUTATION_OPERATION_LOCAL_NAMES = /* @__PURE__ */ new Set([
1607
1711
  "backupQueryClient",
1608
1712
  "context",
1609
1713
  "customOptions",
@@ -1774,6 +1878,8 @@ const generateMutationHook = async ({ verbOptions, options, isRequestOptions, ht
1774
1878
  }) : void 0;
1775
1879
  const bodyOptionalMark = body.isOptional ? "?" : "";
1776
1880
  const definitions = props.map(({ definition, type }) => type === GetterPropType.BODY ? mutator?.bodyTypeName ? `data${bodyOptionalMark}: ${mutator.bodyTypeName}<${body.definition}>` : `data${bodyOptionalMark}: ${body.definition}` : definition).join(";");
1881
+ const variablesTypeName = definitions ? `${pascal(typeName)}MutationVariables` : void 0;
1882
+ const mutationVariablesType = variablesTypeName ?? "void";
1777
1883
  const properties = props.map(({ name, type }) => type === GetterPropType.BODY ? "data" : name).join(",");
1778
1884
  const operationLocalNames = new Set(MUTATION_OPERATION_LOCAL_NAMES);
1779
1885
  for (const { name, type } of props) operationLocalNames.add(type === GetterPropType.BODY ? "data" : name);
@@ -1785,6 +1891,7 @@ const generateMutationHook = async ({ verbOptions, options, isRequestOptions, ht
1785
1891
  operationName: operationTypeReferenceName,
1786
1892
  mutator,
1787
1893
  definitions,
1894
+ mutationVariablesType,
1788
1895
  prefix: adapter.getQueryOptionsDefinitionPrefix(),
1789
1896
  hasQueryV5: adapter.hasQueryV5,
1790
1897
  hasQueryV5WithInfiniteQueryOptionsError: adapter.hasQueryV5WithInfiniteQueryOptionsError,
@@ -1804,6 +1911,7 @@ const generateMutationHook = async ({ verbOptions, options, isRequestOptions, ht
1804
1911
  const mutationArguments = adapter.generateQueryArguments({
1805
1912
  operationName: operationTypeReferenceName,
1806
1913
  definitions,
1914
+ mutationVariablesType,
1807
1915
  mutator,
1808
1916
  isRequestOptions,
1809
1917
  httpClient,
@@ -1813,6 +1921,7 @@ const generateMutationHook = async ({ verbOptions, options, isRequestOptions, ht
1813
1921
  const mutationArgumentsForOptions = adapter.generateQueryArguments({
1814
1922
  operationName: operationTypeReferenceName,
1815
1923
  definitions,
1924
+ mutationVariablesType,
1816
1925
  mutator,
1817
1926
  isRequestOptions,
1818
1927
  httpClient,
@@ -1830,7 +1939,7 @@ ${hooksOptionImplementation}
1830
1939
  ${mutator?.isHook ? `const ${operationReferenceName} = use${pascal(operationName)}Hook()` : ""}
1831
1940
 
1832
1941
 
1833
- const mutationFn: MutationFunction<Awaited<ReturnType<${dataType}>>, ${definitions ? `{${definitions}}` : "void"}> = (${properties ? "props" : ""}) => {
1942
+ const mutationFn: MutationFunction<Awaited<ReturnType<${dataType}>>, ${mutationVariablesType}> = (${properties ? "props" : ""}) => {
1834
1943
  ${properties ? `const {${properties}} = props ?? {};` : ""}
1835
1944
 
1836
1945
  return ${operationReferenceName}(${adapter.getMutationHttpPrefix(mutator)}${properties}${properties ? "," : ""}${getMutationRequestArgs(isRequestOptions, httpClient, mutator, useRuntimeFetcher)})
@@ -1839,6 +1948,7 @@ ${hooksOptionImplementation}
1839
1948
  ${hasInvalidation ? adapter.generateMutationOnSuccess({
1840
1949
  operationName,
1841
1950
  definitions,
1951
+ mutationVariablesType,
1842
1952
  isRequestOptions,
1843
1953
  generateInvalidateCall: createGenerateInvalidateCall(context.spec, !!query.shouldSplitQueryKey, !!query.useOperationIdAsQueryKey, context.output.baseUrl, context.spec.servers),
1844
1954
  uniqueInvalidates
@@ -1858,7 +1968,7 @@ ${hasInvalidation ? adapter.generateMutationOnSuccess({
1858
1968
  const mutationOptionsVarName = camel(`${operationName}-mutation-options`);
1859
1969
  const mutationReturnType = adapter.getMutationReturnType({
1860
1970
  dataType,
1861
- variableType: definitions ? `{${definitions}}` : "void"
1971
+ variableType: mutationVariablesType
1862
1972
  });
1863
1973
  const mutationHookBody = adapter.generateMutationHookBody({
1864
1974
  operationPrefix,
@@ -1878,6 +1988,7 @@ ${mutationOptionsFn}
1878
1988
  export type ${pascal(typeName)}MutationResult = NonNullable<Awaited<ReturnType<${dataType}>>>
1879
1989
  ${body.definition ? `export type ${pascal(typeName)}MutationBody = ${mutator?.bodyTypeName ? `${mutator.bodyTypeName}<${body.definition}>` : body.definition}${body.isOptional ? " | undefined" : ""}` : ""}
1880
1990
  export type ${pascal(typeName)}MutationError = ${errorType}
1991
+ ${variablesTypeName ? `export type ${variablesTypeName} = {${definitions}}` : ""}
1881
1992
 
1882
1993
  ${doc}export const ${camel(`${operationPrefix}-${operationName}`)} = <TError = ${errorType},
1883
1994
  TContext = unknown>(${mutationArguments} ${optionalQueryClientArgument})${mutationReturnType} => {
@@ -2000,6 +2111,26 @@ const renderSetQueryDataHelper = ({ doc, isReactQuery, fnName, propsSig, body })
2000
2111
  }\n`;
2001
2112
  };
2002
2113
  /**
2114
+ * Rewrites `name?: T` to `name: undefined | T` so a required parameter can follow
2115
+ * it (TS1016).
2116
+ *
2117
+ * Keep `undefined` first. `wrapPropsBodyWithMutatorBodyType` matches an optional
2118
+ * `undefined\s*\|\s*` prefix when it swaps in a mutator body type, and misses the
2119
+ * `T | undefined` form that `allowUndefinedParam` emits.
2120
+ */
2121
+ const widenOptionalPropsToUndefined = (props, field) => props.map((prop) => {
2122
+ const regex = new RegExp(String.raw`^${escapeRegExpMetaChars(prop.name)}\s*\?:`);
2123
+ if (!regex.test(prop[field])) return prop;
2124
+ const widened = prop[field].replace(regex, `${prop.name}: undefined | `);
2125
+ return field === "definition" ? {
2126
+ ...prop,
2127
+ definition: widened
2128
+ } : {
2129
+ ...prop,
2130
+ implementation: widened
2131
+ };
2132
+ });
2133
+ /**
2003
2134
  * Renders the prop list shared by `getXxxQueryKey`, `setXxxQueryData` and
2004
2135
  * `getXxxQueryData` helpers: headers are dropped (unless `includeHeaders`
2005
2136
  * is set — key-mutator factories need them), path params stay required,
@@ -2070,21 +2201,15 @@ const generatePrefetch = ({ usePrefetch, type, useQuery, useInfinite, operationN
2070
2201
  const generateQueryImplementation = ({ queryOption: { name, typeName: optionTypeName, queryParam, options, type, queryKeyFnName }, operationId, operationName, typeName, queryProperties, queryKeyProperties, queryParams, params, props, body, mutator, queryOptionsMutator, queryKeyMutator, isRequestOptions, response, httpClient, isExactOptionalPropertyTypes, hasSignal, useRuntimeFetcher, forceSuccessResponse, route, doc, usePrefetch, useQuery, useInfinite, useInvalidate, useSetQueryData, useGetQueryData, adapter }) => {
2071
2202
  const { hasQueryV5, hasQueryV5WithDataTagError, hasQueryV5WithInfiniteQueryOptionsError } = adapter;
2072
2203
  const hasSignalParam = props.some((prop) => prop.name === "signal");
2204
+ const requiresUserQueryOptions = requiresUserSuppliedQueryOptions(adapter, type, options);
2205
+ const signatureProps = requiresUserQueryOptions ? widenOptionalPropsToUndefined(props, "implementation") : props;
2073
2206
  const queryPropDefinitions = wrapPropsBodyWithMutatorBodyType({
2074
- propsString: toObjectString(props, "definition"),
2207
+ propsString: toObjectString(requiresUserQueryOptions ? widenOptionalPropsToUndefined(props, "definition") : props, "definition"),
2075
2208
  body,
2076
2209
  mutator
2077
2210
  });
2078
2211
  const definedInitialDataQueryPropsDefinitions = wrapPropsBodyWithMutatorBodyType({
2079
- propsString: toObjectString(props.map((prop) => {
2080
- const regex = new RegExp(String.raw`^${prop.name}\s*\?:`);
2081
- if (!regex.test(prop.definition)) return prop;
2082
- const definitionWithUndefined = prop.definition.replace(regex, `${prop.name}: undefined | `);
2083
- return {
2084
- ...prop,
2085
- definition: definitionWithUndefined
2086
- };
2087
- }), "definition"),
2212
+ propsString: toObjectString(widenOptionalPropsToUndefined(props, "definition"), "definition"),
2088
2213
  body,
2089
2214
  mutator
2090
2215
  });
@@ -2093,6 +2218,11 @@ const generateQueryImplementation = ({ queryOption: { name, typeName: optionType
2093
2218
  body,
2094
2219
  mutator
2095
2220
  });
2221
+ const queryPropsBeforeRequiredOptions = requiresUserQueryOptions ? wrapPropsBodyWithMutatorBodyType({
2222
+ propsString: toObjectString(signatureProps, "implementation"),
2223
+ body,
2224
+ mutator
2225
+ }) : queryProps;
2096
2226
  const infiniteQueryParamType = hasQueryParam(queryParams, queryParam) && queryParams && queryParam ? `${queryParams.schema.name}['${queryParam}']` : "";
2097
2227
  const hasInfiniteQueryParam = !!infiniteQueryParamType;
2098
2228
  const httpFunctionProps = queryParam ? adapter.getInfiniteQueryHttpProps(props, queryParam, httpClient, !!mutator) : adapter.getHttpFunctionQueryProps(queryProperties, httpClient, !!mutator);
@@ -2123,7 +2253,8 @@ const generateQueryImplementation = ({ queryOption: { name, typeName: optionType
2123
2253
  queryParam,
2124
2254
  initialData: "defined",
2125
2255
  httpClient,
2126
- useRuntimeFetcher
2256
+ useRuntimeFetcher,
2257
+ options
2127
2258
  });
2128
2259
  const undefinedInitialDataQueryArguments = adapter.generateQueryArguments({
2129
2260
  operationName,
@@ -2135,7 +2266,8 @@ const generateQueryImplementation = ({ queryOption: { name, typeName: optionType
2135
2266
  queryParam,
2136
2267
  initialData: "undefined",
2137
2268
  httpClient,
2138
- useRuntimeFetcher
2269
+ useRuntimeFetcher,
2270
+ options
2139
2271
  });
2140
2272
  const queryArguments = adapter.generateQueryArguments({
2141
2273
  operationName,
@@ -2146,7 +2278,8 @@ const generateQueryImplementation = ({ queryOption: { name, typeName: optionType
2146
2278
  queryParams,
2147
2279
  queryParam,
2148
2280
  httpClient,
2149
- useRuntimeFetcher
2281
+ useRuntimeFetcher,
2282
+ options
2150
2283
  });
2151
2284
  const queryArgumentsForOptions = adapter.generateQueryArguments({
2152
2285
  operationName,
@@ -2158,7 +2291,8 @@ const generateQueryImplementation = ({ queryOption: { name, typeName: optionType
2158
2291
  queryParam,
2159
2292
  httpClient,
2160
2293
  forQueryOptions: true,
2161
- useRuntimeFetcher
2294
+ useRuntimeFetcher,
2295
+ options
2162
2296
  });
2163
2297
  const queryOptions = getQueryOptions({
2164
2298
  isRequestOptions,
@@ -2204,7 +2338,7 @@ const generateQueryImplementation = ({ queryOption: { name, typeName: optionType
2204
2338
  const queryResultVarName = props.some((prop) => prop.name === "query") ? "_query" : "query";
2205
2339
  const infiniteParam = infiniteQueryParamType ? `, ${infiniteQueryParamType}` : "";
2206
2340
  const TData = hasQueryV5 && (type === QueryType.INFINITE || type === QueryType.SUSPENSE_INFINITE) ? `InfiniteData<Awaited<ReturnType<${dataType}>>${infiniteParam}>` : `Awaited<ReturnType<${dataType}>>`;
2207
- const queryOptionsFn = `export const ${queryOptionsFnName} = <TData = ${TData}, TError = ${errorType}>(${adapter.getHttpFirstParam(mutator)}${queryProps} ${queryArgumentsForOptions}) => {
2341
+ const queryOptionsFn = `export const ${queryOptionsFnName} = <TData = ${TData}, TError = ${errorType}>(${adapter.getHttpFirstParam(mutator)}${queryPropsBeforeRequiredOptions} ${queryArgumentsForOptions}) => {
2208
2342
 
2209
2343
  ${hookOptions}
2210
2344
 
@@ -2212,7 +2346,7 @@ ${hookOptions}
2212
2346
 
2213
2347
  ${mutator?.isHook ? `const ${operationName} = use${pascal(operationName)}Hook();` : ""}
2214
2348
 
2215
- const queryFn: QueryFunction<Awaited<ReturnType<${mutator?.isHook ? `ReturnType<typeof use${pascal(operationName)}Hook>` : `typeof ${operationName}`}>>${hasQueryV5 && hasInfiniteQueryParam ? `, QueryKey, ${infiniteQueryParamType}` : ""}> = (${queryFnArguments}) => ${operationName}(${httpFunctionProps}${httpFunctionProps ? ", " : ""}${queryOptions});
2349
+ const queryFn: QueryFunction<Awaited<ReturnType<${mutator?.isHook ? `ReturnType<typeof use${pascal(operationName)}Hook>` : `typeof ${operationName}`}>>${hasQueryV5 && hasInfiniteQueryParam ? `, QueryKey, ${infiniteQueryParamType}` : hasQueryV5 && isInfiniteQuery(type) && adapter.shouldCastQueryOptions?.() === false ? `, QueryKey, unknown` : ""}> = (${queryFnArguments}) => ${operationName}(${httpFunctionProps}${httpFunctionProps ? ", " : ""}${queryOptions});
2216
2350
 
2217
2351
  ${adapter.getQueryOptionsUnrefStatements(props)}
2218
2352
 
@@ -2234,7 +2368,7 @@ export function ${queryHookName}<TData = ${TData}, TError = ${errorType}>(\n ${q
2234
2368
  useInfinite,
2235
2369
  operationName,
2236
2370
  mutator,
2237
- queryProps,
2371
+ queryProps: queryPropsBeforeRequiredOptions,
2238
2372
  dataType,
2239
2373
  errorType,
2240
2374
  queryArguments: queryArgumentsForOptions,
@@ -2297,7 +2431,7 @@ export type ${pascal(optionTypeName)}QueryError = ${errorType}
2297
2431
  ${adapter.shouldGenerateOverrideTypes() ? overrideTypes : ""}
2298
2432
  ${doc}
2299
2433
  export function ${queryHookName}<TData = ${TData}, TError = ${errorType}>(\n ${wrapPropsBodyWithMutatorBodyType({
2300
- propsString: adapter.getHookPropsDefinitions(props),
2434
+ propsString: adapter.getHookPropsDefinitions(signatureProps),
2301
2435
  body,
2302
2436
  mutator
2303
2437
  })} ${queryArguments} ${optionalQueryClientArgument} \n ): ${returnType} {
@@ -2355,7 +2489,8 @@ const generateQueryHook = async (verbOptions, options, outputClient, adapter) =>
2355
2489
  const effectiveUseMutation = operationQueryOptions?.useMutation ?? override.query.useMutation ?? verb !== Verbs.GET;
2356
2490
  const globalSuspenseOrInfiniteOnlyForGet = (flag) => flag === true && verb === Verbs.GET;
2357
2491
  const effectiveUseSuspenseQuery = operationQueryOptions?.useSuspenseQuery ?? globalSuspenseOrInfiniteOnlyForGet(override.query.useSuspenseQuery);
2358
- const { queryParam: infiniteQueryParam, infiniteHookAllowed } = resolveInfiniteQueryParam(queryParams, operationQueryOptions?.useInfiniteQueryParam ?? query.useInfiniteQueryParam);
2492
+ const configuredInfiniteQueryParam = operationQueryOptions?.useInfiniteQueryParam ?? query.useInfiniteQueryParam;
2493
+ const { queryParam: infiniteQueryParam, infiniteHookAllowed } = resolveInfiniteQueryParam(queryParams, configuredInfiniteQueryParam);
2359
2494
  const effectiveUseInfinite = (operationQueryOptions?.useInfinite ?? globalSuspenseOrInfiniteOnlyForGet(override.query.useInfinite)) && infiniteHookAllowed;
2360
2495
  const effectiveUseSuspenseInfiniteQuery = (operationQueryOptions?.useSuspenseInfiniteQuery ?? globalSuspenseOrInfiniteOnlyForGet(override.query.useSuspenseInfiniteQuery)) && infiniteHookAllowed;
2361
2496
  let isQuery = effectiveUseQuery || effectiveUseSuspenseQuery || effectiveUseInfinite || effectiveUseSuspenseInfiniteQuery;