@orval/query 8.10.0 → 8.12.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.mjs +129 -52
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GetterPropType, OutputClient, OutputHttpClient,
|
|
1
|
+
import { GetterPropType, OutputClient, OutputHttpClient, Verbs, camel, compareVersions, generateFormDataAndUrlEncodedFunction, generateMutator, generateMutatorConfig, generateMutatorRequestOptions, generateOptions, generateVerbImports, getAngularFilteredParamsCallExpression, getAngularFilteredParamsHelperBody, getRouteAsArray, getSuccessResponseType, isObject, isString, isSyntheticDefaultImportsAllow, jsDoc, kebab, 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";
|
|
@@ -64,8 +64,6 @@ const vueUnRefParams = (props) => {
|
|
|
64
64
|
return `${prop.name} = unref(${prop.name});`;
|
|
65
65
|
}).join("\n");
|
|
66
66
|
};
|
|
67
|
-
const wrapRouteParameters = (route, prepend, append) => route.replaceAll(TEMPLATE_TAG_REGEX, `\${${prepend}$1${append}}`);
|
|
68
|
-
const makeRouteSafe = (route) => wrapRouteParameters(route, "encodeURIComponent(String(", "))");
|
|
69
67
|
const getQueryTypeForFramework = (type) => {
|
|
70
68
|
switch (type) {
|
|
71
69
|
case "suspenseQuery": return "query";
|
|
@@ -704,8 +702,11 @@ const VUE_QUERY_DEPENDENCIES = [{
|
|
|
704
702
|
],
|
|
705
703
|
dependency: "vue"
|
|
706
704
|
}];
|
|
707
|
-
const getSolidQueryImports = (prefix) => {
|
|
705
|
+
const getSolidQueryImports = (prefix, hasRenamedOptionsTypes) => {
|
|
708
706
|
const capitalized = prefix === "use" ? "Use" : "Create";
|
|
707
|
+
const queryOptionsTypeName = hasRenamedOptionsTypes ? "QueryOptions" : "SolidQueryOptions";
|
|
708
|
+
const infiniteQueryOptionsTypeName = hasRenamedOptionsTypes ? "InfiniteQueryOptions" : "SolidInfiniteQueryOptions";
|
|
709
|
+
const mutationOptionsTypeName = hasRenamedOptionsTypes ? "MutationOptions" : "SolidMutationOptions";
|
|
709
710
|
return [{
|
|
710
711
|
exports: [
|
|
711
712
|
{
|
|
@@ -722,10 +723,9 @@ const getSolidQueryImports = (prefix) => {
|
|
|
722
723
|
},
|
|
723
724
|
{ name: `${capitalized}QueryOptions` },
|
|
724
725
|
{ name: `${capitalized}InfiniteQueryOptions` },
|
|
725
|
-
{ name:
|
|
726
|
-
{ name:
|
|
727
|
-
{ name:
|
|
728
|
-
{ name: "SolidMutationOptions" },
|
|
726
|
+
{ name: queryOptionsTypeName },
|
|
727
|
+
{ name: infiniteQueryOptionsTypeName },
|
|
728
|
+
{ name: mutationOptionsTypeName },
|
|
729
729
|
{ name: "QueryFunction" },
|
|
730
730
|
{ name: "MutationFunction" },
|
|
731
731
|
{ name: `${capitalized}QueryResult` },
|
|
@@ -806,7 +806,7 @@ const getSolidQueryDependencies = (hasGlobalMutator, hasParamsSerializerOptions,
|
|
|
806
806
|
return [
|
|
807
807
|
...!hasGlobalMutator && httpClient === OutputHttpClient.AXIOS ? AXIOS_DEPENDENCIES : [],
|
|
808
808
|
...hasParamsSerializerOptions ? PARAMS_SERIALIZER_DEPENDENCIES : [],
|
|
809
|
-
...getSolidQueryImports(isSolidQueryWithUsePrefix(packageJson) ? "use" : "create")
|
|
809
|
+
...getSolidQueryImports(isSolidQueryWithUsePrefix(packageJson) ? "use" : "create", isSolidQueryWithRenamedOptionsTypes(packageJson))
|
|
810
810
|
];
|
|
811
811
|
};
|
|
812
812
|
const getAngularQueryDependencies = (hasGlobalMutator, hasParamsSerializerOptions, packageJson, httpClient) => {
|
|
@@ -864,6 +864,25 @@ const isSolidQueryWithUsePrefix = (packageJson) => {
|
|
|
864
864
|
const withoutRc = version.split("-")[0];
|
|
865
865
|
return compareVersions(withoutRc, "5.71.5");
|
|
866
866
|
};
|
|
867
|
+
/**
|
|
868
|
+
* Solid Query renamed its plain options interfaces in v5.100.6, dropping the
|
|
869
|
+
* `Solid` prefix:
|
|
870
|
+
* - `SolidQueryOptions` → `QueryOptions`
|
|
871
|
+
* - `SolidInfiniteQueryOptions` → `InfiniteQueryOptions`
|
|
872
|
+
* - `SolidMutationOptions` → `MutationOptions`
|
|
873
|
+
*
|
|
874
|
+
* The Accessor wrappers `UseQueryOptions` / `UseInfiniteQueryOptions` /
|
|
875
|
+
* `UseMutationOptions` keep the same names but reference the renamed
|
|
876
|
+
* interfaces internally.
|
|
877
|
+
*
|
|
878
|
+
* https://github.com/TanStack/query/commit/<rename-commit>
|
|
879
|
+
*/
|
|
880
|
+
const isSolidQueryWithRenamedOptionsTypes = (packageJson) => {
|
|
881
|
+
const version = getPackageByQueryClient(packageJson, "solid-query");
|
|
882
|
+
if (!version) return false;
|
|
883
|
+
const withoutRc = version.split("-")[0];
|
|
884
|
+
return compareVersions(withoutRc, "5.100.6");
|
|
885
|
+
};
|
|
867
886
|
const getPackageByQueryClient = (packageJson, queryClient) => {
|
|
868
887
|
switch (queryClient) {
|
|
869
888
|
case "react-query": {
|
|
@@ -925,7 +944,7 @@ const getQueryOptionsDefinition = ({ operationName, mutator, definitions, type,
|
|
|
925
944
|
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}']` : ""}>`;
|
|
926
945
|
return `${partialOptions ? "Partial<" : ""}${optionType}${partialOptions ? ">" : ""}${optionTypeInitialDataPostfix}`;
|
|
927
946
|
}
|
|
928
|
-
const mutationOptionsTypeName =
|
|
947
|
+
const mutationOptionsTypeName = adapter?.getOptionsReturnTypeName ? adapter.getOptionsReturnTypeName("mutation") : void 0;
|
|
929
948
|
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>`;
|
|
930
949
|
};
|
|
931
950
|
//#endregion
|
|
@@ -954,10 +973,10 @@ const createAngularAdapter = ({ hasQueryV5, hasQueryV5WithDataTagError, hasQuery
|
|
|
954
973
|
if (!hasMutator) return queryProperties ? `http, ${queryProperties}` : "http";
|
|
955
974
|
return queryProperties;
|
|
956
975
|
},
|
|
957
|
-
getInfiniteQueryHttpProps(props, queryParam, hasMutator) {
|
|
976
|
+
getInfiniteQueryHttpProps(props, queryParam, _httpClient, hasMutator) {
|
|
958
977
|
let result = props.map((param) => {
|
|
959
978
|
if (param.type === GetterPropType.NAMED_PATH_PARAMS) return param.destructured;
|
|
960
|
-
return param.name === "params" ? `{...params, '${queryParam}': pageParam
|
|
979
|
+
return param.name === "params" ? `{...params, '${queryParam}': pageParam ?? params?.['${queryParam}']}` : param.name;
|
|
961
980
|
}).join(",");
|
|
962
981
|
if (!hasMutator) result = result ? `http, ${result}` : "http";
|
|
963
982
|
return result;
|
|
@@ -1110,7 +1129,7 @@ const createReactAdapter = ({ hasQueryV5, hasQueryV5WithDataTagError, hasQueryV5
|
|
|
1110
1129
|
});
|
|
1111
1130
|
//#endregion
|
|
1112
1131
|
//#region src/frameworks/solid.ts
|
|
1113
|
-
const createSolidAdapter = ({ hasQueryV5, hasQueryV5WithDataTagError, hasQueryV5WithInfiniteQueryOptionsError, hasQueryV5WithMutationContextOnSuccess, hasQueryV5WithRequiredContextOnSuccess, hasSolidQueryUsePrefix }) => ({
|
|
1132
|
+
const createSolidAdapter = ({ hasQueryV5, hasQueryV5WithDataTagError, hasQueryV5WithInfiniteQueryOptionsError, hasQueryV5WithMutationContextOnSuccess, hasQueryV5WithRequiredContextOnSuccess, hasSolidQueryUsePrefix, hasSolidQueryRenamedOptionsTypes }) => ({
|
|
1114
1133
|
outputClient: OutputClient.SOLID_QUERY,
|
|
1115
1134
|
hookPrefix: hasSolidQueryUsePrefix ? "use" : "create",
|
|
1116
1135
|
hasQueryV5,
|
|
@@ -1122,9 +1141,9 @@ const createSolidAdapter = ({ hasQueryV5, hasQueryV5WithDataTagError, hasQueryV5
|
|
|
1122
1141
|
return hasSolidQueryUsePrefix ? "Use" : "Create";
|
|
1123
1142
|
},
|
|
1124
1143
|
getOptionsReturnTypeName(type) {
|
|
1125
|
-
if (type === "mutation") return "SolidMutationOptions";
|
|
1126
|
-
if (type === "infiniteQuery") return "SolidInfiniteQueryOptions";
|
|
1127
|
-
return "SolidQueryOptions";
|
|
1144
|
+
if (type === "mutation") return hasSolidQueryRenamedOptionsTypes ? "MutationOptions" : "SolidMutationOptions";
|
|
1145
|
+
if (type === "infiniteQuery") return hasSolidQueryRenamedOptionsTypes ? "InfiniteQueryOptions" : "SolidInfiniteQueryOptions";
|
|
1146
|
+
return hasSolidQueryRenamedOptionsTypes ? "QueryOptions" : "SolidQueryOptions";
|
|
1128
1147
|
},
|
|
1129
1148
|
getQueryKeyPrefix() {
|
|
1130
1149
|
return "";
|
|
@@ -1298,9 +1317,10 @@ const createVueAdapter = ({ hasVueQueryV4, hasQueryV5, hasQueryV5WithDataTagErro
|
|
|
1298
1317
|
if (httpClient === OutputHttpClient.FETCH && queryProperties) return queryProperties.split(",").map((prop) => `unref(${prop})`).join(",");
|
|
1299
1318
|
return queryProperties;
|
|
1300
1319
|
},
|
|
1301
|
-
getInfiniteQueryHttpProps(props, queryParam) {
|
|
1320
|
+
getInfiniteQueryHttpProps(props, queryParam, httpClient) {
|
|
1302
1321
|
return props.map((param) => {
|
|
1303
|
-
|
|
1322
|
+
if (param.name === "params") return `{...unref(params), '${queryParam}': pageParam ?? unref(params)?.['${queryParam}']}`;
|
|
1323
|
+
return httpClient === OutputHttpClient.FETCH ? `unref(${param.name})` : param.name;
|
|
1304
1324
|
}).join(",");
|
|
1305
1325
|
},
|
|
1306
1326
|
getQueryReturnType({ type }) {
|
|
@@ -1393,7 +1413,7 @@ const withDefaults = (adapter) => ({
|
|
|
1393
1413
|
getInfiniteQueryHttpProps(props, queryParam) {
|
|
1394
1414
|
return props.map((param) => {
|
|
1395
1415
|
if (param.type === GetterPropType.NAMED_PATH_PARAMS) return param.destructured;
|
|
1396
|
-
return param.name === "params" ? `{...params, '${queryParam}': pageParam
|
|
1416
|
+
return param.name === "params" ? `{...params, '${queryParam}': pageParam ?? params?.['${queryParam}']}` : param.name;
|
|
1397
1417
|
}).join(",");
|
|
1398
1418
|
},
|
|
1399
1419
|
generateQueryInit({ queryOptionsFnName, queryProperties, isRequestOptions }) {
|
|
@@ -1417,7 +1437,8 @@ const withDefaults = (adapter) => ({
|
|
|
1417
1437
|
queryParams,
|
|
1418
1438
|
queryParam,
|
|
1419
1439
|
isReturnType: false,
|
|
1420
|
-
initialData
|
|
1440
|
+
initialData,
|
|
1441
|
+
adapter
|
|
1421
1442
|
});
|
|
1422
1443
|
if (!isRequestOptions) return `${type ? "queryOptions" : "mutationOptions"}${initialData === "defined" ? "" : "?"}: ${definition}`;
|
|
1423
1444
|
const requestType = getQueryArgumentsRequestType(httpClient, mutator, useRuntimeFetcher);
|
|
@@ -1495,7 +1516,8 @@ const createFrameworkAdapter = ({ outputClient, packageJson, queryVersion }) =>
|
|
|
1495
1516
|
hasQueryV5WithInfiniteQueryOptionsError: _hasQueryV5WithInfiniteQueryOptionsError,
|
|
1496
1517
|
hasQueryV5WithMutationContextOnSuccess: _hasQueryV5WithMutationContextOnSuccess,
|
|
1497
1518
|
hasQueryV5WithRequiredContextOnSuccess: _hasQueryV5WithRequiredContextOnSuccess,
|
|
1498
|
-
hasSolidQueryUsePrefix: isSolidQueryWithUsePrefix(packageJson)
|
|
1519
|
+
hasSolidQueryUsePrefix: isSolidQueryWithUsePrefix(packageJson),
|
|
1520
|
+
hasSolidQueryRenamedOptionsTypes: isSolidQueryWithRenamedOptionsTypes(packageJson)
|
|
1499
1521
|
}));
|
|
1500
1522
|
default: return withDefaults(createReactAdapter({
|
|
1501
1523
|
hasQueryV5: _hasQueryV5,
|
|
@@ -1802,6 +1824,62 @@ const wrapPropsBodyWithMutatorBodyType = ({ propsString, body, mutator }) => {
|
|
|
1802
1824
|
return propsString.replace(new RegExp(String.raw`(\w+\??:\s*(?:undefined\s*\|\s*)?)${bodyDefinitionPattern}`), `$1${mutator.bodyTypeName}<${body.definition}>`);
|
|
1803
1825
|
};
|
|
1804
1826
|
/**
|
|
1827
|
+
* Widens a parameter signature to be optional. Skips params that already
|
|
1828
|
+
* carry a default value (`= ...`), since those are syntactically optional
|
|
1829
|
+
* and adding `?` on top would be a TypeScript error.
|
|
1830
|
+
*/
|
|
1831
|
+
const makeOptionalParam = (impl) => {
|
|
1832
|
+
if (impl.includes("=")) return impl;
|
|
1833
|
+
return impl.replace(/^(\w+):\s*/, "$1?: ");
|
|
1834
|
+
};
|
|
1835
|
+
/**
|
|
1836
|
+
* Widens a parameter type to also accept `undefined`. Already-optional
|
|
1837
|
+
* (`?:`) signatures are normalized to required-with-undefined, and params
|
|
1838
|
+
* with a default value pass through unchanged.
|
|
1839
|
+
*/
|
|
1840
|
+
const allowUndefinedParam = (impl) => {
|
|
1841
|
+
if (impl.includes("=")) return impl;
|
|
1842
|
+
const optional = /^(\w+)\?:\s*(.+)$/.exec(impl);
|
|
1843
|
+
if (optional) return `${optional[1]}: ${optional[2]} | undefined`;
|
|
1844
|
+
return impl.replace(/^(\w+):\s*(.+)$/, "$1: $2 | undefined");
|
|
1845
|
+
};
|
|
1846
|
+
/**
|
|
1847
|
+
* Renders the `setXxxQueryData` helper as either a React hook (returns a
|
|
1848
|
+
* setter) or a plain function taking `queryClient`. Both shapes share the
|
|
1849
|
+
* same body and signature, so this collapses what would otherwise be two
|
|
1850
|
+
* near-identical template literals.
|
|
1851
|
+
*/
|
|
1852
|
+
const renderSetQueryDataHelper = ({ doc, isReactQuery, fnName, propsSig, body }) => {
|
|
1853
|
+
const docPrefix = doc ?? "";
|
|
1854
|
+
if (isReactQuery) return `${docPrefix}export const ${fnName} = () => {
|
|
1855
|
+
const queryClient = useQueryClient();
|
|
1856
|
+
return (${propsSig}) => {
|
|
1857
|
+
${body}
|
|
1858
|
+
};
|
|
1859
|
+
}\n`;
|
|
1860
|
+
return `${docPrefix}export const ${fnName} = (queryClient: QueryClient, ${propsSig}) => {
|
|
1861
|
+
${body}
|
|
1862
|
+
}\n`;
|
|
1863
|
+
};
|
|
1864
|
+
/**
|
|
1865
|
+
* Renders the prop list shared by `getXxxQueryKey`, `setXxxQueryData` and
|
|
1866
|
+
* `getXxxQueryData` helpers: headers are dropped, path params stay required,
|
|
1867
|
+
* non-path params (query params, body) are passed through `widenNonPath`
|
|
1868
|
+
* (defaults to identity — pass `makeOptionalParam` or `allowUndefinedParam`
|
|
1869
|
+
* to relax the signature).
|
|
1870
|
+
*
|
|
1871
|
+
* Centralising this prevents the three call sites from drifting apart on
|
|
1872
|
+
* how they treat the same props.
|
|
1873
|
+
*/
|
|
1874
|
+
const buildKeyShapedProps = ({ props, body, mutator, widenNonPath = (impl) => impl }) => wrapPropsBodyWithMutatorBodyType({
|
|
1875
|
+
propsString: toObjectString(props.filter((prop) => prop.type !== GetterPropType.HEADER).map((prop) => ({
|
|
1876
|
+
...prop,
|
|
1877
|
+
implementation: prop.type === GetterPropType.PARAM || prop.type === GetterPropType.NAMED_PATH_PARAMS ? prop.implementation : widenNonPath(prop.implementation)
|
|
1878
|
+
})), "implementation"),
|
|
1879
|
+
body,
|
|
1880
|
+
mutator
|
|
1881
|
+
});
|
|
1882
|
+
/**
|
|
1805
1883
|
* Computes a verb prefix segment for query keys when a non-GET operation is
|
|
1806
1884
|
* routed to a Query hook. Without this prefix, two operations sharing a path
|
|
1807
1885
|
* (e.g. `GET /pets` and `POST /pets`) would generate cache keys that both
|
|
@@ -1877,7 +1955,7 @@ const generateQueryImplementation = ({ queryOption: { name, queryParam, options,
|
|
|
1877
1955
|
mutator
|
|
1878
1956
|
});
|
|
1879
1957
|
const hasInfiniteQueryParam = queryParam && queryParams?.schema.name;
|
|
1880
|
-
const httpFunctionProps = queryParam ? adapter.getInfiniteQueryHttpProps(props, queryParam, !!mutator) : adapter.getHttpFunctionQueryProps(queryProperties, httpClient, !!mutator);
|
|
1958
|
+
const httpFunctionProps = queryParam ? adapter.getInfiniteQueryHttpProps(props, queryParam, httpClient, !!mutator) : adapter.getHttpFunctionQueryProps(queryProperties, httpClient, !!mutator);
|
|
1881
1959
|
const definedInitialDataReturnType = adapter.getQueryReturnType({
|
|
1882
1960
|
type,
|
|
1883
1961
|
isMutatorHook: mutator?.isHook,
|
|
@@ -1998,7 +2076,7 @@ ${hookOptions}
|
|
|
1998
2076
|
|
|
1999
2077
|
${adapter.getUnrefStatements(props)}
|
|
2000
2078
|
|
|
2001
|
-
${queryOptionsMutator ? `const customOptions = ${queryOptionsMutator.name}({
|
|
2079
|
+
${queryOptionsMutator ? `const customOptions = ${queryOptionsMutator.name}({ queryKey, queryFn, ${queryOptionsImp}}${queryOptionsMutator.hasSecondArg ? `, { ${queryProperties} }` : ""}${queryOptionsMutator.hasThirdArg ? `, { url: \`${route}\` }` : ""});` : ""}
|
|
2002
2080
|
|
|
2003
2081
|
return ${queryOptionsMutator ? "customOptions" : `{ queryKey, queryFn, ${queryOptionsImp}}`}${adapter.shouldCastQueryOptions?.() === false ? "" : ` as ${queryOptionFnReturnType} ${adapter.shouldAnnotateQueryKey() ? `& { queryKey: ${hasQueryV5 ? `DataTag<QueryKey, TData${hasQueryV5WithDataTagError ? ", TError" : ""}>` : "QueryKey"} }` : ""}`}
|
|
2004
2082
|
}`;
|
|
@@ -2030,22 +2108,28 @@ export function ${queryHookName}<TData = ${TData}, TError = ${errorType}>(\n ${q
|
|
|
2030
2108
|
const isPrimaryQueryType = type === QueryType.QUERY || type === QueryType.INFINITE || type === QueryType.SUSPENSE_QUERY && !useQuery || type === QueryType.SUSPENSE_INFINITE && !useInfinite;
|
|
2031
2109
|
const buildBaseQueryKeyExpr = () => queryKeyMutator ? `${queryKeyMutator.name}({ ${queryProperties} }${queryKeyMutator.hasSecondArg ? `, { url: \`${route}\` }` : ""})` : `${queryKeyFnName}(${queryKeyProperties})`;
|
|
2032
2110
|
const applyQueryOptionsMutator = (baseExpr) => queryOptionsMutator && !queryOptionsMutator.isHook ? `${queryOptionsMutator.name}({ queryKey: ${baseExpr} }${queryOptionsMutator.hasSecondArg ? `, { ${queryProperties} }` : ""}${queryOptionsMutator.hasThirdArg ? `, { url: \`${route}\` }` : ""}).queryKey` : baseExpr;
|
|
2111
|
+
const hasHookMutator = !!queryOptionsMutator?.isHook;
|
|
2112
|
+
if (hasHookMutator && (useSetQueryData || useGetQueryData)) logWarning(`'${name}' has a hook-based queryOptions mutator, so the requested set/get-query-data helpers were skipped to avoid a cache-key mismatch with the query hook.`);
|
|
2033
2113
|
const shouldGenerateInvalidate = useInvalidate && isPrimaryQueryType;
|
|
2034
2114
|
const invalidateFnName = camel(`invalidate-${name}`);
|
|
2035
2115
|
const invalidateQueryKeyExpr = applyQueryOptionsMutator(buildBaseQueryKeyExpr());
|
|
2036
|
-
const shouldGenerateSetQueryData = useSetQueryData && isPrimaryQueryType;
|
|
2116
|
+
const shouldGenerateSetQueryData = useSetQueryData && isPrimaryQueryType && !hasHookMutator;
|
|
2037
2117
|
const isReactQuery = adapter.outputClient === OutputClient.REACT_QUERY;
|
|
2038
2118
|
const setQueryDataFnName = isReactQuery ? camel(`use-set-${name}-query-data`) : camel(`set-${name}-query-data`);
|
|
2039
|
-
const setQueryDataKeyExpr = buildBaseQueryKeyExpr();
|
|
2040
|
-
const setQueryDataProps =
|
|
2041
|
-
|
|
2119
|
+
const setQueryDataKeyExpr = applyQueryOptionsMutator(buildBaseQueryKeyExpr());
|
|
2120
|
+
const setQueryDataProps = buildKeyShapedProps({
|
|
2121
|
+
props,
|
|
2042
2122
|
body,
|
|
2043
|
-
mutator
|
|
2123
|
+
mutator,
|
|
2124
|
+
widenNonPath: allowUndefinedParam
|
|
2044
2125
|
});
|
|
2045
|
-
const shouldGenerateGetQueryData = useGetQueryData && isPrimaryQueryType;
|
|
2126
|
+
const shouldGenerateGetQueryData = useGetQueryData && isPrimaryQueryType && !hasHookMutator;
|
|
2046
2127
|
const getQueryDataFnName = isReactQuery ? camel(`use-get-${name}-query-data`) : camel(`get-${name}-query-data`);
|
|
2047
|
-
const
|
|
2048
|
-
|
|
2128
|
+
const getQueryDataProps = buildKeyShapedProps({
|
|
2129
|
+
props,
|
|
2130
|
+
body,
|
|
2131
|
+
mutator
|
|
2132
|
+
});
|
|
2049
2133
|
const queryInit = adapter.generateQueryInit({
|
|
2050
2134
|
queryOptionsFnName,
|
|
2051
2135
|
queryProperties,
|
|
@@ -2096,20 +2180,19 @@ ${shouldGenerateInvalidate ? `${doc}export const ${invalidateFnName} = async (\n
|
|
|
2096
2180
|
|
|
2097
2181
|
return queryClient;
|
|
2098
2182
|
}\n` : ""}
|
|
2099
|
-
${shouldGenerateSetQueryData ?
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
}\n` : ""}
|
|
2183
|
+
${shouldGenerateSetQueryData ? renderSetQueryDataHelper({
|
|
2184
|
+
doc,
|
|
2185
|
+
isReactQuery,
|
|
2186
|
+
fnName: setQueryDataFnName,
|
|
2187
|
+
propsSig: `${setQueryDataProps}updater: ${TData} | undefined | ((old: ${TData} | undefined) => ${TData} | undefined)`,
|
|
2188
|
+
body: `queryClient.setQueriesData<${TData}>({ queryKey: ${setQueryDataKeyExpr} }, updater);`
|
|
2189
|
+
}) : ""}
|
|
2107
2190
|
${shouldGenerateGetQueryData ? isReactQuery ? `${doc}export const ${getQueryDataFnName} = () => {
|
|
2108
2191
|
const queryClient = useQueryClient();
|
|
2109
2192
|
return (${getQueryDataProps}) =>
|
|
2110
|
-
queryClient.getQueryData<${TData}>(${
|
|
2193
|
+
queryClient.getQueryData<${TData}>(${setQueryDataKeyExpr});
|
|
2111
2194
|
}\n` : `${doc}export const ${getQueryDataFnName} = (queryClient: QueryClient, ${getQueryDataProps}) =>
|
|
2112
|
-
queryClient.getQueryData<${TData}>(${
|
|
2195
|
+
queryClient.getQueryData<${TData}>(${setQueryDataKeyExpr});\n` : ""}
|
|
2113
2196
|
`;
|
|
2114
2197
|
};
|
|
2115
2198
|
const generateQueryHook = async (verbOptions, options, outputClient, adapter) => {
|
|
@@ -2135,7 +2218,7 @@ const generateQueryHook = async (verbOptions, options, outputClient, adapter) =>
|
|
|
2135
2218
|
const effectiveUseInfinite = operationQueryOptions?.useInfinite ?? globalSuspenseOrInfiniteOnlyForGet(override.query.useInfinite);
|
|
2136
2219
|
const effectiveUseSuspenseInfiniteQuery = operationQueryOptions?.useSuspenseInfiniteQuery ?? globalSuspenseOrInfiniteOnlyForGet(override.query.useSuspenseInfiniteQuery);
|
|
2137
2220
|
let isQuery = effectiveUseQuery || effectiveUseSuspenseQuery || effectiveUseInfinite || effectiveUseSuspenseInfiniteQuery;
|
|
2138
|
-
let isMutation = effectiveUseMutation
|
|
2221
|
+
let isMutation = effectiveUseMutation;
|
|
2139
2222
|
if (verb !== Verbs.GET && isQuery) isMutation = false;
|
|
2140
2223
|
if (verb === Verbs.GET && isMutation) isQuery = false;
|
|
2141
2224
|
const conflictWarning = getMutationInvalidatesConflictWarning({
|
|
@@ -2197,17 +2280,11 @@ const generateQueryHook = async (verbOptions, options, outputClient, adapter) =>
|
|
|
2197
2280
|
const uniqueQueryOptionsByKeys = queries.filter((obj, index, self) => index === self.findIndex((t) => t.queryKeyFnName === obj.queryKeyFnName));
|
|
2198
2281
|
let queryKeyFns = "";
|
|
2199
2282
|
if (!queryKeyMutator) for (const queryOption of uniqueQueryOptionsByKeys) {
|
|
2200
|
-
const
|
|
2201
|
-
|
|
2202
|
-
return impl.replace(/^(\w+):\s*/, "$1?: ");
|
|
2203
|
-
};
|
|
2204
|
-
const queryKeyProps = wrapPropsBodyWithMutatorBodyType({
|
|
2205
|
-
propsString: toObjectString(props.filter((prop) => prop.type !== GetterPropType.HEADER).map((prop) => ({
|
|
2206
|
-
...prop,
|
|
2207
|
-
implementation: prop.type === GetterPropType.PARAM || prop.type === GetterPropType.NAMED_PATH_PARAMS ? prop.implementation : makeOptionalParam(prop.implementation)
|
|
2208
|
-
})), "implementation"),
|
|
2283
|
+
const queryKeyProps = buildKeyShapedProps({
|
|
2284
|
+
props,
|
|
2209
2285
|
body,
|
|
2210
|
-
mutator
|
|
2286
|
+
mutator,
|
|
2287
|
+
widenNonPath: makeOptionalParam
|
|
2211
2288
|
});
|
|
2212
2289
|
const routeString = adapter.getQueryKeyRouteString(route, !!override.query.shouldSplitQueryKey);
|
|
2213
2290
|
const queryKeyIdentifier = override.query.useOperationIdAsQueryKey ? `"${operationName}"` : routeString;
|