@orval/query 8.25.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
@@ -968,7 +968,7 @@ const resolveUserQueryOptionsConstraint = (adapter, type, options) => {
968
968
  * constraint reshapes the type without requiring anything, so it does not count.
969
969
  */
970
970
  const requiresUserSuppliedQueryOptions = (adapter, type, options) => !!type && !!resolveUserQueryOptionsConstraint(adapter, type, options)?.require?.length;
971
- const getQueryOptionsDefinition = ({ operationName, mutator, definitions, type, prefix, hasQueryV5, hasQueryV5WithInfiniteQueryOptionsError, queryParams, queryParam, isReturnType, initialData, adapter, options }) => {
971
+ const getQueryOptionsDefinition = ({ operationName, mutator, definitions, mutationVariablesType, type, prefix, hasQueryV5, hasQueryV5WithInfiniteQueryOptionsError, queryParams, queryParam, isReturnType, initialData, adapter, options }) => {
972
972
  const isMutatorHook = mutator?.isHook;
973
973
  const partialOptions = !isReturnType && hasQueryV5;
974
974
  if (type) {
@@ -1001,7 +1001,8 @@ const getQueryOptionsDefinition = ({ operationName, mutator, definitions, type,
1001
1001
  return `${partialOptions ? "Partial<" : ""}${optionType}${partialOptions ? ">" : ""}${optionTypeInitialDataPostfix}`;
1002
1002
  }
1003
1003
  const mutationOptionsTypeName = adapter?.getOptionsReturnTypeName ? adapter.getOptionsReturnTypeName("mutation") : void 0;
1004
- 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>`;
1005
1006
  };
1006
1007
  //#endregion
1007
1008
  //#region src/frameworks/angular.ts
@@ -1082,11 +1083,12 @@ const createAngularAdapter = ({ hasQueryV5, hasQueryV5WithDataTagError, hasQuery
1082
1083
  getQueryOptionsDefinitionPrefix() {
1083
1084
  return prefix;
1084
1085
  },
1085
- 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 }) {
1086
1087
  const definition = getQueryOptionsDefinition({
1087
1088
  operationName,
1088
1089
  mutator,
1089
1090
  definitions,
1091
+ mutationVariablesType,
1090
1092
  type,
1091
1093
  prefix,
1092
1094
  hasQueryV5,
@@ -1326,11 +1328,12 @@ const createSvelteAdapter = ({ hasSvelteQueryV4, hasSvelteQueryV6, hasQueryV5, h
1326
1328
  getQueryOptionsDefinitionPrefix() {
1327
1329
  return prefix;
1328
1330
  },
1329
- 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 }) {
1330
1332
  const definition = getQueryOptionsDefinition({
1331
1333
  operationName,
1332
1334
  mutator,
1333
1335
  definitions,
1336
+ mutationVariablesType,
1334
1337
  type,
1335
1338
  prefix,
1336
1339
  hasQueryV5,
@@ -1470,27 +1473,28 @@ const createVueAdapter = ({ hasVueQueryV4, hasQueryV5, hasQueryV5WithDataTagErro
1470
1473
  supportsMutationInvalidation() {
1471
1474
  return hasQueryV5;
1472
1475
  },
1473
- generateMutationOnSuccess({ operationName, definitions, isRequestOptions, generateInvalidateCall, uniqueInvalidates }) {
1476
+ generateMutationOnSuccess({ operationName, definitions, mutationVariablesType, isRequestOptions, generateInvalidateCall, uniqueInvalidates }) {
1474
1477
  const invalidateCalls = uniqueInvalidates.map((t) => generateInvalidateCall(t)).join("\n");
1478
+ const variablesType = mutationVariablesType ?? (definitions ? `{${definitions}}` : "void");
1475
1479
  if (hasQueryV5WithMutationContextOnSuccess) {
1476
- 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) => {
1477
1481
  if (!options?.skipInvalidation) {
1478
1482
  ${invalidateCalls}
1479
1483
  }
1480
1484
  unref(unref(typeof mutationOptions === 'function' ? mutationOptions() : mutationOptions)?.onSuccess)?.(data, variables, onMutateResult, context);
1481
1485
  };`;
1482
- 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) => {
1483
1487
  ${invalidateCalls}
1484
1488
  unref(unref(typeof mutationOptions === 'function' ? mutationOptions() : mutationOptions)?.onSuccess)?.(data, variables, onMutateResult, context);
1485
1489
  };`;
1486
1490
  }
1487
- 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"}) => {
1488
1492
  if (!options?.skipInvalidation) {
1489
1493
  ${invalidateCalls}
1490
1494
  }
1491
1495
  unref(unref(typeof mutationOptions === 'function' ? mutationOptions() : mutationOptions)?.onSuccess)?.(data, variables, context);
1492
1496
  };`;
1493
- 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"}) => {
1494
1498
  ${invalidateCalls}
1495
1499
  unref(unref(typeof mutationOptions === 'function' ? mutationOptions() : mutationOptions)?.onSuccess)?.(data, variables, context);
1496
1500
  };`;
@@ -1556,12 +1560,13 @@ const withDefaults = (adapter) => {
1556
1560
  getOptionalQueryClientArgument() {
1557
1561
  return composed.hasQueryV5 ? ", queryClient?: QueryClient" : "";
1558
1562
  },
1559
- generateQueryArguments({ operationName, definitions, mutator, isRequestOptions, type, queryParams, queryParam, initialData, httpClient, hasInvalidation, useRuntimeFetcher, options }) {
1563
+ generateQueryArguments({ operationName, definitions, mutationVariablesType, mutator, isRequestOptions, type, queryParams, queryParam, initialData, httpClient, hasInvalidation, useRuntimeFetcher, options }) {
1560
1564
  const prefix = composed.getQueryOptionsDefinitionPrefix();
1561
1565
  const definition = getQueryOptionsDefinition({
1562
1566
  operationName,
1563
1567
  mutator,
1564
1568
  definitions,
1569
+ mutationVariablesType,
1565
1570
  type,
1566
1571
  prefix,
1567
1572
  hasQueryV5: composed.hasQueryV5,
@@ -1580,27 +1585,28 @@ const withDefaults = (adapter) => {
1580
1585
  const optionsType = `{ ${type ? "query" : "mutation"}${isQueryRequired ? "" : "?"}:${definition}, ${!type && hasInvalidation ? "skipInvalidation?: boolean, " : ""}${requestType}}`;
1581
1586
  return `options${isQueryRequired ? "" : "?"}: ${optionsType}\n`;
1582
1587
  },
1583
- generateMutationOnSuccess({ operationName, definitions, isRequestOptions, generateInvalidateCall, uniqueInvalidates }) {
1588
+ generateMutationOnSuccess({ operationName, definitions, mutationVariablesType, isRequestOptions, generateInvalidateCall, uniqueInvalidates }) {
1584
1589
  const invalidateCalls = uniqueInvalidates.map((t) => generateInvalidateCall(t)).join("\n");
1590
+ const variablesType = mutationVariablesType ?? (definitions ? `{${definitions}}` : "void");
1585
1591
  if (composed.hasQueryV5WithMutationContextOnSuccess) {
1586
- 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) => {
1587
1593
  if (!options?.skipInvalidation) {
1588
1594
  ${invalidateCalls}
1589
1595
  }
1590
1596
  mutationOptions?.onSuccess?.(data, variables, onMutateResult, context);
1591
1597
  };`;
1592
- 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) => {
1593
1599
  ${invalidateCalls}
1594
1600
  mutationOptions?.onSuccess?.(data, variables, onMutateResult, context);
1595
1601
  };`;
1596
1602
  } else {
1597
- 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"}) => {
1598
1604
  if (!options?.skipInvalidation) {
1599
1605
  ${invalidateCalls}
1600
1606
  }
1601
1607
  mutationOptions?.onSuccess?.(data, variables, context);
1602
1608
  };`;
1603
- 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"}) => {
1604
1610
  ${invalidateCalls}
1605
1611
  mutationOptions?.onSuccess?.(data, variables, context);
1606
1612
  };`;
@@ -1872,6 +1878,8 @@ const generateMutationHook = async ({ verbOptions, options, isRequestOptions, ht
1872
1878
  }) : void 0;
1873
1879
  const bodyOptionalMark = body.isOptional ? "?" : "";
1874
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";
1875
1883
  const properties = props.map(({ name, type }) => type === GetterPropType.BODY ? "data" : name).join(",");
1876
1884
  const operationLocalNames = new Set(MUTATION_OPERATION_LOCAL_NAMES);
1877
1885
  for (const { name, type } of props) operationLocalNames.add(type === GetterPropType.BODY ? "data" : name);
@@ -1883,6 +1891,7 @@ const generateMutationHook = async ({ verbOptions, options, isRequestOptions, ht
1883
1891
  operationName: operationTypeReferenceName,
1884
1892
  mutator,
1885
1893
  definitions,
1894
+ mutationVariablesType,
1886
1895
  prefix: adapter.getQueryOptionsDefinitionPrefix(),
1887
1896
  hasQueryV5: adapter.hasQueryV5,
1888
1897
  hasQueryV5WithInfiniteQueryOptionsError: adapter.hasQueryV5WithInfiniteQueryOptionsError,
@@ -1902,6 +1911,7 @@ const generateMutationHook = async ({ verbOptions, options, isRequestOptions, ht
1902
1911
  const mutationArguments = adapter.generateQueryArguments({
1903
1912
  operationName: operationTypeReferenceName,
1904
1913
  definitions,
1914
+ mutationVariablesType,
1905
1915
  mutator,
1906
1916
  isRequestOptions,
1907
1917
  httpClient,
@@ -1911,6 +1921,7 @@ const generateMutationHook = async ({ verbOptions, options, isRequestOptions, ht
1911
1921
  const mutationArgumentsForOptions = adapter.generateQueryArguments({
1912
1922
  operationName: operationTypeReferenceName,
1913
1923
  definitions,
1924
+ mutationVariablesType,
1914
1925
  mutator,
1915
1926
  isRequestOptions,
1916
1927
  httpClient,
@@ -1928,7 +1939,7 @@ ${hooksOptionImplementation}
1928
1939
  ${mutator?.isHook ? `const ${operationReferenceName} = use${pascal(operationName)}Hook()` : ""}
1929
1940
 
1930
1941
 
1931
- const mutationFn: MutationFunction<Awaited<ReturnType<${dataType}>>, ${definitions ? `{${definitions}}` : "void"}> = (${properties ? "props" : ""}) => {
1942
+ const mutationFn: MutationFunction<Awaited<ReturnType<${dataType}>>, ${mutationVariablesType}> = (${properties ? "props" : ""}) => {
1932
1943
  ${properties ? `const {${properties}} = props ?? {};` : ""}
1933
1944
 
1934
1945
  return ${operationReferenceName}(${adapter.getMutationHttpPrefix(mutator)}${properties}${properties ? "," : ""}${getMutationRequestArgs(isRequestOptions, httpClient, mutator, useRuntimeFetcher)})
@@ -1937,6 +1948,7 @@ ${hooksOptionImplementation}
1937
1948
  ${hasInvalidation ? adapter.generateMutationOnSuccess({
1938
1949
  operationName,
1939
1950
  definitions,
1951
+ mutationVariablesType,
1940
1952
  isRequestOptions,
1941
1953
  generateInvalidateCall: createGenerateInvalidateCall(context.spec, !!query.shouldSplitQueryKey, !!query.useOperationIdAsQueryKey, context.output.baseUrl, context.spec.servers),
1942
1954
  uniqueInvalidates
@@ -1956,7 +1968,7 @@ ${hasInvalidation ? adapter.generateMutationOnSuccess({
1956
1968
  const mutationOptionsVarName = camel(`${operationName}-mutation-options`);
1957
1969
  const mutationReturnType = adapter.getMutationReturnType({
1958
1970
  dataType,
1959
- variableType: definitions ? `{${definitions}}` : "void"
1971
+ variableType: mutationVariablesType
1960
1972
  });
1961
1973
  const mutationHookBody = adapter.generateMutationHookBody({
1962
1974
  operationPrefix,
@@ -1976,6 +1988,7 @@ ${mutationOptionsFn}
1976
1988
  export type ${pascal(typeName)}MutationResult = NonNullable<Awaited<ReturnType<${dataType}>>>
1977
1989
  ${body.definition ? `export type ${pascal(typeName)}MutationBody = ${mutator?.bodyTypeName ? `${mutator.bodyTypeName}<${body.definition}>` : body.definition}${body.isOptional ? " | undefined" : ""}` : ""}
1978
1990
  export type ${pascal(typeName)}MutationError = ${errorType}
1991
+ ${variablesTypeName ? `export type ${variablesTypeName} = {${definitions}}` : ""}
1979
1992
 
1980
1993
  ${doc}export const ${camel(`${operationPrefix}-${operationName}`)} = <TError = ${errorType},
1981
1994
  TContext = unknown>(${mutationArguments} ${optionalQueryClientArgument})${mutationReturnType} => {