@orval/query 8.12.3 → 8.14.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 +17 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -23,6 +23,7 @@ const normalizeQueryOptions = (queryOptions = {}, outputWorkspace) => {
|
|
|
23
23
|
...queryOptions.signal ? { signal: true } : {},
|
|
24
24
|
...queryOptions.shouldExportMutatorHooks ? { shouldExportMutatorHooks: true } : {},
|
|
25
25
|
...queryOptions.shouldExportQueryKey ? { shouldExportQueryKey: true } : {},
|
|
26
|
+
...queryOptions.shouldFilterQueryKey ? { shouldFilterQueryKey: true } : {},
|
|
26
27
|
...queryOptions.shouldExportHttpClient ? { shouldExportHttpClient: true } : {},
|
|
27
28
|
...queryOptions.shouldSplitQueryKey ? { shouldSplitQueryKey: true } : {},
|
|
28
29
|
...queryOptions.useOperationIdAsQueryKey ? { useOperationIdAsQueryKey: true } : {}
|
|
@@ -1794,6 +1795,10 @@ const getMutationInvalidatesConflictWarning = ({ operationName, isMutation, isQu
|
|
|
1794
1795
|
if (!mutationInvalidates.find((rule) => rule.onMutations.includes(operationName))) return void 0;
|
|
1795
1796
|
return `mutationInvalidates rule references '${operationName}', but that operation is generated as a ${isQuery ? "Query hook" : "plain function (no hook)"}, not a Mutation. The invalidation will not fire. Either remove '${operationName}' from the rule's onMutations list, or configure '${operationName}' so that it is generated as a Mutation hook.`;
|
|
1796
1797
|
};
|
|
1798
|
+
const hasQueryParam = (queryParams, queryParam) => {
|
|
1799
|
+
if (!queryParam || !queryParams) return false;
|
|
1800
|
+
return queryParams.paramNames?.includes(queryParam) ?? true;
|
|
1801
|
+
};
|
|
1797
1802
|
const escapeRegExpMetaChars = (value) => value.replaceAll(/[.*+?^${}()|[\]\\]/g, String.raw`\$&`);
|
|
1798
1803
|
/**
|
|
1799
1804
|
* Wraps the body parameter's type in a property string with the mutator's
|
|
@@ -1928,7 +1933,7 @@ const generatePrefetch = ({ usePrefetch, type, useQuery, useInfinite, operationN
|
|
|
1928
1933
|
return queryClient;
|
|
1929
1934
|
}\n`;
|
|
1930
1935
|
};
|
|
1931
|
-
const generateQueryImplementation = ({ queryOption: { name, queryParam, options, type, queryKeyFnName }, operationName, queryProperties, queryKeyProperties, queryParams, params, props, body, mutator, queryOptionsMutator, queryKeyMutator, isRequestOptions, response, httpClient, isExactOptionalPropertyTypes, hasSignal, useRuntimeFetcher, route, doc, usePrefetch, useQuery, useInfinite, useInvalidate, useSetQueryData, useGetQueryData, adapter }) => {
|
|
1936
|
+
const generateQueryImplementation = ({ queryOption: { name, queryParam, options, type, queryKeyFnName }, operationId, operationName, queryProperties, queryKeyProperties, queryParams, params, props, body, mutator, queryOptionsMutator, queryKeyMutator, isRequestOptions, response, httpClient, isExactOptionalPropertyTypes, hasSignal, useRuntimeFetcher, route, doc, usePrefetch, useQuery, useInfinite, useInvalidate, useSetQueryData, useGetQueryData, adapter }) => {
|
|
1932
1937
|
const { hasQueryV5, hasQueryV5WithDataTagError, hasQueryV5WithInfiniteQueryOptionsError } = adapter;
|
|
1933
1938
|
const hasSignalParam = props.some((prop) => prop.name === "signal");
|
|
1934
1939
|
const queryPropDefinitions = wrapPropsBodyWithMutatorBodyType({
|
|
@@ -1954,7 +1959,8 @@ const generateQueryImplementation = ({ queryOption: { name, queryParam, options,
|
|
|
1954
1959
|
body,
|
|
1955
1960
|
mutator
|
|
1956
1961
|
});
|
|
1957
|
-
const
|
|
1962
|
+
const infiniteQueryParamType = hasQueryParam(queryParams, queryParam) && queryParams && queryParam ? `${queryParams.schema.name}['${queryParam}']` : "";
|
|
1963
|
+
const hasInfiniteQueryParam = !!infiniteQueryParamType;
|
|
1958
1964
|
const httpFunctionProps = queryParam ? adapter.getInfiniteQueryHttpProps(props, queryParam, httpClient, !!mutator) : adapter.getHttpFunctionQueryProps(queryProperties, httpClient, !!mutator);
|
|
1959
1965
|
const definedInitialDataReturnType = adapter.getQueryReturnType({
|
|
1960
1966
|
type,
|
|
@@ -2062,7 +2068,7 @@ const generateQueryImplementation = ({ queryOption: { name, queryParam, options,
|
|
|
2062
2068
|
const queryOptionsFnName = camel(queryKeyMutator || queryOptionsMutator || mutator?.isHook ? `use-${name}-queryOptions` : `get-${name}-queryOptions`);
|
|
2063
2069
|
const queryOptionsVarName = isRequestOptions ? "queryOptions" : "options";
|
|
2064
2070
|
const queryResultVarName = props.some((prop) => prop.name === "query") ? "_query" : "query";
|
|
2065
|
-
const infiniteParam =
|
|
2071
|
+
const infiniteParam = infiniteQueryParamType ? `, ${infiniteQueryParamType}` : "";
|
|
2066
2072
|
const TData = hasQueryV5 && (type === QueryType.INFINITE || type === QueryType.SUSPENSE_INFINITE) ? `InfiniteData<Awaited<ReturnType<${dataType}>>${infiniteParam}>` : `Awaited<ReturnType<${dataType}>>`;
|
|
2067
2073
|
const queryOptionsFn = `export const ${queryOptionsFnName} = <TData = ${TData}, TError = ${errorType}>(${adapter.getHttpFirstParam(mutator)}${queryProps} ${queryArgumentsForOptions}) => {
|
|
2068
2074
|
|
|
@@ -2072,11 +2078,11 @@ ${hookOptions}
|
|
|
2072
2078
|
|
|
2073
2079
|
${mutator?.isHook ? `const ${operationName} = use${pascal(operationName)}Hook();` : ""}
|
|
2074
2080
|
|
|
2075
|
-
const queryFn: QueryFunction<Awaited<ReturnType<${mutator?.isHook ? `ReturnType<typeof use${pascal(operationName)}Hook>` : `typeof ${operationName}`}>>${hasQueryV5 && hasInfiniteQueryParam ? `, QueryKey, ${
|
|
2081
|
+
const queryFn: QueryFunction<Awaited<ReturnType<${mutator?.isHook ? `ReturnType<typeof use${pascal(operationName)}Hook>` : `typeof ${operationName}`}>>${hasQueryV5 && hasInfiniteQueryParam ? `, QueryKey, ${infiniteQueryParamType}` : ""}> = (${queryFnArguments}) => ${operationName}(${httpFunctionProps}${httpFunctionProps ? ", " : ""}${queryOptions});
|
|
2076
2082
|
|
|
2077
2083
|
${adapter.getUnrefStatements(props)}
|
|
2078
2084
|
|
|
2079
|
-
${queryOptionsMutator ? `const customOptions = ${queryOptionsMutator.name}({ queryKey, queryFn, ${queryOptionsImp}}${queryOptionsMutator.hasSecondArg ? `, { ${queryProperties} }` : ""}${queryOptionsMutator.hasThirdArg ? `, { url: \`${route}
|
|
2085
|
+
${queryOptionsMutator ? `const customOptions = ${queryOptionsMutator.name}({ queryKey, queryFn, ${queryOptionsImp}}${queryOptionsMutator.hasSecondArg ? `, { ${queryProperties} }` : ""}${queryOptionsMutator.hasThirdArg ? `, { url: \`${route}\`, operationId: '${operationId}', operationName: '${operationName}' }` : ""});` : ""}
|
|
2080
2086
|
|
|
2081
2087
|
return ${queryOptionsMutator ? "customOptions" : `{ queryKey, queryFn, ${queryOptionsImp}}`}${adapter.shouldCastQueryOptions?.() === false ? "" : ` as ${queryOptionFnReturnType} ${adapter.shouldAnnotateQueryKey() ? `& { queryKey: ${hasQueryV5 ? `DataTag<QueryKey, TData${hasQueryV5WithDataTagError ? ", TError" : ""}>` : "QueryKey"} }` : ""}`}
|
|
2082
2088
|
}`;
|
|
@@ -2107,7 +2113,7 @@ export function ${queryHookName}<TData = ${TData}, TError = ${errorType}>(\n ${q
|
|
|
2107
2113
|
const prefetch = adapter.generatePrefetch ? adapter.generatePrefetch(prefetchContext) : generatePrefetch(prefetchContext);
|
|
2108
2114
|
const isPrimaryQueryType = type === QueryType.QUERY || type === QueryType.INFINITE || type === QueryType.SUSPENSE_QUERY && !useQuery || type === QueryType.SUSPENSE_INFINITE && !useInfinite;
|
|
2109
2115
|
const buildBaseQueryKeyExpr = () => queryKeyMutator ? `${queryKeyMutator.name}({ ${queryProperties} }${queryKeyMutator.hasSecondArg ? `, { url: \`${route}\` }` : ""})` : `${queryKeyFnName}(${queryKeyProperties})`;
|
|
2110
|
-
const applyQueryOptionsMutator = (baseExpr) => queryOptionsMutator && !queryOptionsMutator.isHook ? `${queryOptionsMutator.name}({ queryKey: ${baseExpr} }${queryOptionsMutator.hasSecondArg ? `, { ${queryProperties} }` : ""}${queryOptionsMutator.hasThirdArg ? `, { url: \`${route}
|
|
2116
|
+
const applyQueryOptionsMutator = (baseExpr) => queryOptionsMutator && !queryOptionsMutator.isHook ? `${queryOptionsMutator.name}({ queryKey: ${baseExpr} }${queryOptionsMutator.hasSecondArg ? `, { ${queryProperties} }` : ""}${queryOptionsMutator.hasThirdArg ? `, { url: \`${route}\`, operationId: '${operationId}', operationName: '${operationName}' }` : ""}).queryKey` : baseExpr;
|
|
2111
2117
|
const hasHookMutator = !!queryOptionsMutator?.isHook;
|
|
2112
2118
|
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.`);
|
|
2113
2119
|
const shouldGenerateInvalidate = useInvalidate && isPrimaryQueryType;
|
|
@@ -2215,8 +2221,9 @@ const generateQueryHook = async (verbOptions, options, outputClient, adapter) =>
|
|
|
2215
2221
|
const effectiveUseMutation = operationQueryOptions?.useMutation ?? override.query.useMutation ?? verb !== Verbs.GET;
|
|
2216
2222
|
const globalSuspenseOrInfiniteOnlyForGet = (flag) => flag === true && verb === Verbs.GET;
|
|
2217
2223
|
const effectiveUseSuspenseQuery = operationQueryOptions?.useSuspenseQuery ?? globalSuspenseOrInfiniteOnlyForGet(override.query.useSuspenseQuery);
|
|
2218
|
-
const
|
|
2219
|
-
const
|
|
2224
|
+
const hasConfiguredInfiniteQueryParam = !query.useInfiniteQueryParam || hasQueryParam(queryParams, query.useInfiniteQueryParam);
|
|
2225
|
+
const effectiveUseInfinite = (operationQueryOptions?.useInfinite ?? globalSuspenseOrInfiniteOnlyForGet(override.query.useInfinite)) && hasConfiguredInfiniteQueryParam;
|
|
2226
|
+
const effectiveUseSuspenseInfiniteQuery = (operationQueryOptions?.useSuspenseInfiniteQuery ?? globalSuspenseOrInfiniteOnlyForGet(override.query.useSuspenseInfiniteQuery)) && hasConfiguredInfiniteQueryParam;
|
|
2220
2227
|
let isQuery = effectiveUseQuery || effectiveUseSuspenseQuery || effectiveUseInfinite || effectiveUseSuspenseInfiniteQuery;
|
|
2221
2228
|
let isMutation = effectiveUseMutation;
|
|
2222
2229
|
if (verb !== Verbs.GET && isQuery) isMutation = false;
|
|
@@ -2303,7 +2310,7 @@ ${override.query.shouldExportQueryKey ? "export " : ""}const ${queryOption.query
|
|
|
2303
2310
|
queryKeyParams,
|
|
2304
2311
|
body.implementation
|
|
2305
2312
|
].filter((x) => !!x).join(", ")}
|
|
2306
|
-
] as const;
|
|
2313
|
+
]${override.query.shouldFilterQueryKey ? ".filter(Boolean)" : " as const"};
|
|
2307
2314
|
}
|
|
2308
2315
|
`;
|
|
2309
2316
|
}
|
|
@@ -2312,6 +2319,7 @@ ${queryKeyFns}`;
|
|
|
2312
2319
|
let queryImplementations = "";
|
|
2313
2320
|
for (const queryOption of queries) queryImplementations += generateQueryImplementation({
|
|
2314
2321
|
queryOption,
|
|
2322
|
+
operationId,
|
|
2315
2323
|
operationName,
|
|
2316
2324
|
queryProperties,
|
|
2317
2325
|
queryKeyProperties,
|