@orval/query 8.10.0 → 8.11.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 +120 -42
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -704,8 +704,11 @@ const VUE_QUERY_DEPENDENCIES = [{
|
|
|
704
704
|
],
|
|
705
705
|
dependency: "vue"
|
|
706
706
|
}];
|
|
707
|
-
const getSolidQueryImports = (prefix) => {
|
|
707
|
+
const getSolidQueryImports = (prefix, hasRenamedOptionsTypes) => {
|
|
708
708
|
const capitalized = prefix === "use" ? "Use" : "Create";
|
|
709
|
+
const queryOptionsTypeName = hasRenamedOptionsTypes ? "QueryOptions" : "SolidQueryOptions";
|
|
710
|
+
const infiniteQueryOptionsTypeName = hasRenamedOptionsTypes ? "InfiniteQueryOptions" : "SolidInfiniteQueryOptions";
|
|
711
|
+
const mutationOptionsTypeName = hasRenamedOptionsTypes ? "MutationOptions" : "SolidMutationOptions";
|
|
709
712
|
return [{
|
|
710
713
|
exports: [
|
|
711
714
|
{
|
|
@@ -722,10 +725,9 @@ const getSolidQueryImports = (prefix) => {
|
|
|
722
725
|
},
|
|
723
726
|
{ name: `${capitalized}QueryOptions` },
|
|
724
727
|
{ name: `${capitalized}InfiniteQueryOptions` },
|
|
725
|
-
{ name:
|
|
726
|
-
{ name:
|
|
727
|
-
{ name:
|
|
728
|
-
{ name: "SolidMutationOptions" },
|
|
728
|
+
{ name: queryOptionsTypeName },
|
|
729
|
+
{ name: infiniteQueryOptionsTypeName },
|
|
730
|
+
{ name: mutationOptionsTypeName },
|
|
729
731
|
{ name: "QueryFunction" },
|
|
730
732
|
{ name: "MutationFunction" },
|
|
731
733
|
{ name: `${capitalized}QueryResult` },
|
|
@@ -806,7 +808,7 @@ const getSolidQueryDependencies = (hasGlobalMutator, hasParamsSerializerOptions,
|
|
|
806
808
|
return [
|
|
807
809
|
...!hasGlobalMutator && httpClient === OutputHttpClient.AXIOS ? AXIOS_DEPENDENCIES : [],
|
|
808
810
|
...hasParamsSerializerOptions ? PARAMS_SERIALIZER_DEPENDENCIES : [],
|
|
809
|
-
...getSolidQueryImports(isSolidQueryWithUsePrefix(packageJson) ? "use" : "create")
|
|
811
|
+
...getSolidQueryImports(isSolidQueryWithUsePrefix(packageJson) ? "use" : "create", isSolidQueryWithRenamedOptionsTypes(packageJson))
|
|
810
812
|
];
|
|
811
813
|
};
|
|
812
814
|
const getAngularQueryDependencies = (hasGlobalMutator, hasParamsSerializerOptions, packageJson, httpClient) => {
|
|
@@ -864,6 +866,25 @@ const isSolidQueryWithUsePrefix = (packageJson) => {
|
|
|
864
866
|
const withoutRc = version.split("-")[0];
|
|
865
867
|
return compareVersions(withoutRc, "5.71.5");
|
|
866
868
|
};
|
|
869
|
+
/**
|
|
870
|
+
* Solid Query renamed its plain options interfaces in v5.100.6, dropping the
|
|
871
|
+
* `Solid` prefix:
|
|
872
|
+
* - `SolidQueryOptions` → `QueryOptions`
|
|
873
|
+
* - `SolidInfiniteQueryOptions` → `InfiniteQueryOptions`
|
|
874
|
+
* - `SolidMutationOptions` → `MutationOptions`
|
|
875
|
+
*
|
|
876
|
+
* The Accessor wrappers `UseQueryOptions` / `UseInfiniteQueryOptions` /
|
|
877
|
+
* `UseMutationOptions` keep the same names but reference the renamed
|
|
878
|
+
* interfaces internally.
|
|
879
|
+
*
|
|
880
|
+
* https://github.com/TanStack/query/commit/<rename-commit>
|
|
881
|
+
*/
|
|
882
|
+
const isSolidQueryWithRenamedOptionsTypes = (packageJson) => {
|
|
883
|
+
const version = getPackageByQueryClient(packageJson, "solid-query");
|
|
884
|
+
if (!version) return false;
|
|
885
|
+
const withoutRc = version.split("-")[0];
|
|
886
|
+
return compareVersions(withoutRc, "5.100.6");
|
|
887
|
+
};
|
|
867
888
|
const getPackageByQueryClient = (packageJson, queryClient) => {
|
|
868
889
|
switch (queryClient) {
|
|
869
890
|
case "react-query": {
|
|
@@ -925,7 +946,7 @@ const getQueryOptionsDefinition = ({ operationName, mutator, definitions, type,
|
|
|
925
946
|
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
947
|
return `${partialOptions ? "Partial<" : ""}${optionType}${partialOptions ? ">" : ""}${optionTypeInitialDataPostfix}`;
|
|
927
948
|
}
|
|
928
|
-
const mutationOptionsTypeName =
|
|
949
|
+
const mutationOptionsTypeName = adapter?.getOptionsReturnTypeName ? adapter.getOptionsReturnTypeName("mutation") : void 0;
|
|
929
950
|
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
951
|
};
|
|
931
952
|
//#endregion
|
|
@@ -1110,7 +1131,7 @@ const createReactAdapter = ({ hasQueryV5, hasQueryV5WithDataTagError, hasQueryV5
|
|
|
1110
1131
|
});
|
|
1111
1132
|
//#endregion
|
|
1112
1133
|
//#region src/frameworks/solid.ts
|
|
1113
|
-
const createSolidAdapter = ({ hasQueryV5, hasQueryV5WithDataTagError, hasQueryV5WithInfiniteQueryOptionsError, hasQueryV5WithMutationContextOnSuccess, hasQueryV5WithRequiredContextOnSuccess, hasSolidQueryUsePrefix }) => ({
|
|
1134
|
+
const createSolidAdapter = ({ hasQueryV5, hasQueryV5WithDataTagError, hasQueryV5WithInfiniteQueryOptionsError, hasQueryV5WithMutationContextOnSuccess, hasQueryV5WithRequiredContextOnSuccess, hasSolidQueryUsePrefix, hasSolidQueryRenamedOptionsTypes }) => ({
|
|
1114
1135
|
outputClient: OutputClient.SOLID_QUERY,
|
|
1115
1136
|
hookPrefix: hasSolidQueryUsePrefix ? "use" : "create",
|
|
1116
1137
|
hasQueryV5,
|
|
@@ -1122,9 +1143,9 @@ const createSolidAdapter = ({ hasQueryV5, hasQueryV5WithDataTagError, hasQueryV5
|
|
|
1122
1143
|
return hasSolidQueryUsePrefix ? "Use" : "Create";
|
|
1123
1144
|
},
|
|
1124
1145
|
getOptionsReturnTypeName(type) {
|
|
1125
|
-
if (type === "mutation") return "SolidMutationOptions";
|
|
1126
|
-
if (type === "infiniteQuery") return "SolidInfiniteQueryOptions";
|
|
1127
|
-
return "SolidQueryOptions";
|
|
1146
|
+
if (type === "mutation") return hasSolidQueryRenamedOptionsTypes ? "MutationOptions" : "SolidMutationOptions";
|
|
1147
|
+
if (type === "infiniteQuery") return hasSolidQueryRenamedOptionsTypes ? "InfiniteQueryOptions" : "SolidInfiniteQueryOptions";
|
|
1148
|
+
return hasSolidQueryRenamedOptionsTypes ? "QueryOptions" : "SolidQueryOptions";
|
|
1128
1149
|
},
|
|
1129
1150
|
getQueryKeyPrefix() {
|
|
1130
1151
|
return "";
|
|
@@ -1417,7 +1438,8 @@ const withDefaults = (adapter) => ({
|
|
|
1417
1438
|
queryParams,
|
|
1418
1439
|
queryParam,
|
|
1419
1440
|
isReturnType: false,
|
|
1420
|
-
initialData
|
|
1441
|
+
initialData,
|
|
1442
|
+
adapter
|
|
1421
1443
|
});
|
|
1422
1444
|
if (!isRequestOptions) return `${type ? "queryOptions" : "mutationOptions"}${initialData === "defined" ? "" : "?"}: ${definition}`;
|
|
1423
1445
|
const requestType = getQueryArgumentsRequestType(httpClient, mutator, useRuntimeFetcher);
|
|
@@ -1495,7 +1517,8 @@ const createFrameworkAdapter = ({ outputClient, packageJson, queryVersion }) =>
|
|
|
1495
1517
|
hasQueryV5WithInfiniteQueryOptionsError: _hasQueryV5WithInfiniteQueryOptionsError,
|
|
1496
1518
|
hasQueryV5WithMutationContextOnSuccess: _hasQueryV5WithMutationContextOnSuccess,
|
|
1497
1519
|
hasQueryV5WithRequiredContextOnSuccess: _hasQueryV5WithRequiredContextOnSuccess,
|
|
1498
|
-
hasSolidQueryUsePrefix: isSolidQueryWithUsePrefix(packageJson)
|
|
1520
|
+
hasSolidQueryUsePrefix: isSolidQueryWithUsePrefix(packageJson),
|
|
1521
|
+
hasSolidQueryRenamedOptionsTypes: isSolidQueryWithRenamedOptionsTypes(packageJson)
|
|
1499
1522
|
}));
|
|
1500
1523
|
default: return withDefaults(createReactAdapter({
|
|
1501
1524
|
hasQueryV5: _hasQueryV5,
|
|
@@ -1802,6 +1825,62 @@ const wrapPropsBodyWithMutatorBodyType = ({ propsString, body, mutator }) => {
|
|
|
1802
1825
|
return propsString.replace(new RegExp(String.raw`(\w+\??:\s*(?:undefined\s*\|\s*)?)${bodyDefinitionPattern}`), `$1${mutator.bodyTypeName}<${body.definition}>`);
|
|
1803
1826
|
};
|
|
1804
1827
|
/**
|
|
1828
|
+
* Widens a parameter signature to be optional. Skips params that already
|
|
1829
|
+
* carry a default value (`= ...`), since those are syntactically optional
|
|
1830
|
+
* and adding `?` on top would be a TypeScript error.
|
|
1831
|
+
*/
|
|
1832
|
+
const makeOptionalParam = (impl) => {
|
|
1833
|
+
if (impl.includes("=")) return impl;
|
|
1834
|
+
return impl.replace(/^(\w+):\s*/, "$1?: ");
|
|
1835
|
+
};
|
|
1836
|
+
/**
|
|
1837
|
+
* Widens a parameter type to also accept `undefined`. Already-optional
|
|
1838
|
+
* (`?:`) signatures are normalized to required-with-undefined, and params
|
|
1839
|
+
* with a default value pass through unchanged.
|
|
1840
|
+
*/
|
|
1841
|
+
const allowUndefinedParam = (impl) => {
|
|
1842
|
+
if (impl.includes("=")) return impl;
|
|
1843
|
+
const optional = /^(\w+)\?:\s*(.+)$/.exec(impl);
|
|
1844
|
+
if (optional) return `${optional[1]}: ${optional[2]} | undefined`;
|
|
1845
|
+
return impl.replace(/^(\w+):\s*(.+)$/, "$1: $2 | undefined");
|
|
1846
|
+
};
|
|
1847
|
+
/**
|
|
1848
|
+
* Renders the `setXxxQueryData` helper as either a React hook (returns a
|
|
1849
|
+
* setter) or a plain function taking `queryClient`. Both shapes share the
|
|
1850
|
+
* same body and signature, so this collapses what would otherwise be two
|
|
1851
|
+
* near-identical template literals.
|
|
1852
|
+
*/
|
|
1853
|
+
const renderSetQueryDataHelper = ({ doc, isReactQuery, fnName, propsSig, body }) => {
|
|
1854
|
+
const docPrefix = doc ?? "";
|
|
1855
|
+
if (isReactQuery) return `${docPrefix}export const ${fnName} = () => {
|
|
1856
|
+
const queryClient = useQueryClient();
|
|
1857
|
+
return (${propsSig}) => {
|
|
1858
|
+
${body}
|
|
1859
|
+
};
|
|
1860
|
+
}\n`;
|
|
1861
|
+
return `${docPrefix}export const ${fnName} = (queryClient: QueryClient, ${propsSig}) => {
|
|
1862
|
+
${body}
|
|
1863
|
+
}\n`;
|
|
1864
|
+
};
|
|
1865
|
+
/**
|
|
1866
|
+
* Renders the prop list shared by `getXxxQueryKey`, `setXxxQueryData` and
|
|
1867
|
+
* `getXxxQueryData` helpers: headers are dropped, path params stay required,
|
|
1868
|
+
* non-path params (query params, body) are passed through `widenNonPath`
|
|
1869
|
+
* (defaults to identity — pass `makeOptionalParam` or `allowUndefinedParam`
|
|
1870
|
+
* to relax the signature).
|
|
1871
|
+
*
|
|
1872
|
+
* Centralising this prevents the three call sites from drifting apart on
|
|
1873
|
+
* how they treat the same props.
|
|
1874
|
+
*/
|
|
1875
|
+
const buildKeyShapedProps = ({ props, body, mutator, widenNonPath = (impl) => impl }) => wrapPropsBodyWithMutatorBodyType({
|
|
1876
|
+
propsString: toObjectString(props.filter((prop) => prop.type !== GetterPropType.HEADER).map((prop) => ({
|
|
1877
|
+
...prop,
|
|
1878
|
+
implementation: prop.type === GetterPropType.PARAM || prop.type === GetterPropType.NAMED_PATH_PARAMS ? prop.implementation : widenNonPath(prop.implementation)
|
|
1879
|
+
})), "implementation"),
|
|
1880
|
+
body,
|
|
1881
|
+
mutator
|
|
1882
|
+
});
|
|
1883
|
+
/**
|
|
1805
1884
|
* Computes a verb prefix segment for query keys when a non-GET operation is
|
|
1806
1885
|
* routed to a Query hook. Without this prefix, two operations sharing a path
|
|
1807
1886
|
* (e.g. `GET /pets` and `POST /pets`) would generate cache keys that both
|
|
@@ -2030,22 +2109,28 @@ export function ${queryHookName}<TData = ${TData}, TError = ${errorType}>(\n ${q
|
|
|
2030
2109
|
const isPrimaryQueryType = type === QueryType.QUERY || type === QueryType.INFINITE || type === QueryType.SUSPENSE_QUERY && !useQuery || type === QueryType.SUSPENSE_INFINITE && !useInfinite;
|
|
2031
2110
|
const buildBaseQueryKeyExpr = () => queryKeyMutator ? `${queryKeyMutator.name}({ ${queryProperties} }${queryKeyMutator.hasSecondArg ? `, { url: \`${route}\` }` : ""})` : `${queryKeyFnName}(${queryKeyProperties})`;
|
|
2032
2111
|
const applyQueryOptionsMutator = (baseExpr) => queryOptionsMutator && !queryOptionsMutator.isHook ? `${queryOptionsMutator.name}({ queryKey: ${baseExpr} }${queryOptionsMutator.hasSecondArg ? `, { ${queryProperties} }` : ""}${queryOptionsMutator.hasThirdArg ? `, { url: \`${route}\` }` : ""}).queryKey` : baseExpr;
|
|
2112
|
+
const hasHookMutator = !!queryOptionsMutator?.isHook;
|
|
2113
|
+
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
2114
|
const shouldGenerateInvalidate = useInvalidate && isPrimaryQueryType;
|
|
2034
2115
|
const invalidateFnName = camel(`invalidate-${name}`);
|
|
2035
2116
|
const invalidateQueryKeyExpr = applyQueryOptionsMutator(buildBaseQueryKeyExpr());
|
|
2036
|
-
const shouldGenerateSetQueryData = useSetQueryData && isPrimaryQueryType;
|
|
2117
|
+
const shouldGenerateSetQueryData = useSetQueryData && isPrimaryQueryType && !hasHookMutator;
|
|
2037
2118
|
const isReactQuery = adapter.outputClient === OutputClient.REACT_QUERY;
|
|
2038
2119
|
const setQueryDataFnName = isReactQuery ? camel(`use-set-${name}-query-data`) : camel(`set-${name}-query-data`);
|
|
2039
|
-
const setQueryDataKeyExpr = buildBaseQueryKeyExpr();
|
|
2040
|
-
const setQueryDataProps =
|
|
2041
|
-
|
|
2120
|
+
const setQueryDataKeyExpr = applyQueryOptionsMutator(buildBaseQueryKeyExpr());
|
|
2121
|
+
const setQueryDataProps = buildKeyShapedProps({
|
|
2122
|
+
props,
|
|
2042
2123
|
body,
|
|
2043
|
-
mutator
|
|
2124
|
+
mutator,
|
|
2125
|
+
widenNonPath: allowUndefinedParam
|
|
2044
2126
|
});
|
|
2045
|
-
const shouldGenerateGetQueryData = useGetQueryData && isPrimaryQueryType;
|
|
2127
|
+
const shouldGenerateGetQueryData = useGetQueryData && isPrimaryQueryType && !hasHookMutator;
|
|
2046
2128
|
const getQueryDataFnName = isReactQuery ? camel(`use-get-${name}-query-data`) : camel(`get-${name}-query-data`);
|
|
2047
|
-
const
|
|
2048
|
-
|
|
2129
|
+
const getQueryDataProps = buildKeyShapedProps({
|
|
2130
|
+
props,
|
|
2131
|
+
body,
|
|
2132
|
+
mutator
|
|
2133
|
+
});
|
|
2049
2134
|
const queryInit = adapter.generateQueryInit({
|
|
2050
2135
|
queryOptionsFnName,
|
|
2051
2136
|
queryProperties,
|
|
@@ -2096,20 +2181,19 @@ ${shouldGenerateInvalidate ? `${doc}export const ${invalidateFnName} = async (\n
|
|
|
2096
2181
|
|
|
2097
2182
|
return queryClient;
|
|
2098
2183
|
}\n` : ""}
|
|
2099
|
-
${shouldGenerateSetQueryData ?
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
}\n` : ""}
|
|
2184
|
+
${shouldGenerateSetQueryData ? renderSetQueryDataHelper({
|
|
2185
|
+
doc,
|
|
2186
|
+
isReactQuery,
|
|
2187
|
+
fnName: setQueryDataFnName,
|
|
2188
|
+
propsSig: `${setQueryDataProps}updater: ${TData} | undefined | ((old: ${TData} | undefined) => ${TData} | undefined)`,
|
|
2189
|
+
body: `queryClient.setQueriesData<${TData}>({ queryKey: ${setQueryDataKeyExpr} }, updater);`
|
|
2190
|
+
}) : ""}
|
|
2107
2191
|
${shouldGenerateGetQueryData ? isReactQuery ? `${doc}export const ${getQueryDataFnName} = () => {
|
|
2108
2192
|
const queryClient = useQueryClient();
|
|
2109
2193
|
return (${getQueryDataProps}) =>
|
|
2110
|
-
queryClient.getQueryData<${TData}>(${
|
|
2194
|
+
queryClient.getQueryData<${TData}>(${setQueryDataKeyExpr});
|
|
2111
2195
|
}\n` : `${doc}export const ${getQueryDataFnName} = (queryClient: QueryClient, ${getQueryDataProps}) =>
|
|
2112
|
-
queryClient.getQueryData<${TData}>(${
|
|
2196
|
+
queryClient.getQueryData<${TData}>(${setQueryDataKeyExpr});\n` : ""}
|
|
2113
2197
|
`;
|
|
2114
2198
|
};
|
|
2115
2199
|
const generateQueryHook = async (verbOptions, options, outputClient, adapter) => {
|
|
@@ -2135,7 +2219,7 @@ const generateQueryHook = async (verbOptions, options, outputClient, adapter) =>
|
|
|
2135
2219
|
const effectiveUseInfinite = operationQueryOptions?.useInfinite ?? globalSuspenseOrInfiniteOnlyForGet(override.query.useInfinite);
|
|
2136
2220
|
const effectiveUseSuspenseInfiniteQuery = operationQueryOptions?.useSuspenseInfiniteQuery ?? globalSuspenseOrInfiniteOnlyForGet(override.query.useSuspenseInfiniteQuery);
|
|
2137
2221
|
let isQuery = effectiveUseQuery || effectiveUseSuspenseQuery || effectiveUseInfinite || effectiveUseSuspenseInfiniteQuery;
|
|
2138
|
-
let isMutation = effectiveUseMutation
|
|
2222
|
+
let isMutation = effectiveUseMutation;
|
|
2139
2223
|
if (verb !== Verbs.GET && isQuery) isMutation = false;
|
|
2140
2224
|
if (verb === Verbs.GET && isMutation) isQuery = false;
|
|
2141
2225
|
const conflictWarning = getMutationInvalidatesConflictWarning({
|
|
@@ -2197,17 +2281,11 @@ const generateQueryHook = async (verbOptions, options, outputClient, adapter) =>
|
|
|
2197
2281
|
const uniqueQueryOptionsByKeys = queries.filter((obj, index, self) => index === self.findIndex((t) => t.queryKeyFnName === obj.queryKeyFnName));
|
|
2198
2282
|
let queryKeyFns = "";
|
|
2199
2283
|
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"),
|
|
2284
|
+
const queryKeyProps = buildKeyShapedProps({
|
|
2285
|
+
props,
|
|
2209
2286
|
body,
|
|
2210
|
-
mutator
|
|
2287
|
+
mutator,
|
|
2288
|
+
widenNonPath: makeOptionalParam
|
|
2211
2289
|
});
|
|
2212
2290
|
const routeString = adapter.getQueryKeyRouteString(route, !!override.query.shouldSplitQueryKey);
|
|
2213
2291
|
const queryKeyIdentifier = override.query.useOperationIdAsQueryKey ? `"${operationName}"` : routeString;
|