@orval/query 8.20.0 → 8.21.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 -12
- 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, Verbs, camel, compareVersions, generateFormDataAndUrlEncodedFunction, generateMutator, generateMutatorConfig, generateMutatorRequestOptions, generateOptions, generateVerbImports, getAngularFilteredParamsCallExpression, getAngularFilteredParamsHelperBody, getFullRoute, 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, 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";
|
|
@@ -1744,7 +1744,7 @@ const createGenerateInvalidateCall = (spec, shouldSplitQueryKey, useOperationIdA
|
|
|
1744
1744
|
if (info?.hasRequiredPathParams) {
|
|
1745
1745
|
const prefix = getStaticRoutePrefix(info.route);
|
|
1746
1746
|
if (prefix !== void 0) {
|
|
1747
|
-
const prefixWithBase = getFullRoute(prefix, servers, baseUrl);
|
|
1747
|
+
const prefixWithBase = getFullRoute(getRoute(prefix), servers, baseUrl);
|
|
1748
1748
|
const verbPrefix = getQueryKeyVerbPrefix({
|
|
1749
1749
|
verb: info.method,
|
|
1750
1750
|
useOperationIdAsQueryKey
|
|
@@ -1762,7 +1762,7 @@ const createGenerateInvalidateCall = (spec, shouldSplitQueryKey, useOperationIdA
|
|
|
1762
1762
|
};
|
|
1763
1763
|
};
|
|
1764
1764
|
const generateMutationHook = async ({ verbOptions, options, isRequestOptions, httpClient, doc, adapter }) => {
|
|
1765
|
-
const { operationName, body, props, mutator, response, operationId, route: pathRoute, override } = verbOptions;
|
|
1765
|
+
const { operationName, typeName, body, props, mutator, response, operationId, route: pathRoute, override } = verbOptions;
|
|
1766
1766
|
const { route, context, output } = options;
|
|
1767
1767
|
const query = override.query;
|
|
1768
1768
|
const mutationOptionsMutator = query.mutationOptions ? await generateMutator({
|
|
@@ -1777,7 +1777,7 @@ const generateMutationHook = async ({ verbOptions, options, isRequestOptions, ht
|
|
|
1777
1777
|
const properties = props.map(({ name, type }) => type === GetterPropType.BODY ? "data" : name).join(",");
|
|
1778
1778
|
const operationLocalNames = new Set(MUTATION_OPERATION_LOCAL_NAMES);
|
|
1779
1779
|
for (const { name, type } of props) operationLocalNames.add(type === GetterPropType.BODY ? "data" : name);
|
|
1780
|
-
const errorType = getQueryErrorType(
|
|
1780
|
+
const errorType = getQueryErrorType(typeName, response, httpClient, mutator, override.fetch.forceSuccessResponse);
|
|
1781
1781
|
const operationReferenceName = getMutationOperationReferenceName(operationName, operationLocalNames);
|
|
1782
1782
|
const dataType = mutator?.isHook ? `ReturnType<typeof use${pascal(operationName)}Hook>` : `typeof ${operationReferenceName}`;
|
|
1783
1783
|
const operationTypeReferenceName = mutator?.isHook ? operationName : operationReferenceName;
|
|
@@ -1875,9 +1875,9 @@ ${hasInvalidation ? adapter.generateMutationOnSuccess({
|
|
|
1875
1875
|
${!mutator?.isHook && operationReferenceName !== operationName ? `const ${operationReferenceName} = ${operationName};` : ""}
|
|
1876
1876
|
${mutationOptionsFn}
|
|
1877
1877
|
|
|
1878
|
-
export type ${pascal(
|
|
1879
|
-
${body.definition ? `export type ${pascal(
|
|
1880
|
-
export type ${pascal(
|
|
1878
|
+
export type ${pascal(typeName)}MutationResult = NonNullable<Awaited<ReturnType<${dataType}>>>
|
|
1879
|
+
${body.definition ? `export type ${pascal(typeName)}MutationBody = ${mutator?.bodyTypeName ? `${mutator.bodyTypeName}<${body.definition}>` : body.definition}${body.isOptional ? " | undefined" : ""}` : ""}
|
|
1880
|
+
export type ${pascal(typeName)}MutationError = ${errorType}
|
|
1881
1881
|
|
|
1882
1882
|
${doc}export const ${camel(`${operationPrefix}-${operationName}`)} = <TError = ${errorType},
|
|
1883
1883
|
TContext = unknown>(${mutationArguments} ${optionalQueryClientArgument})${mutationReturnType} => {
|
|
@@ -2048,7 +2048,7 @@ const generatePrefetch = ({ usePrefetch, type, useQuery, useInfinite, operationN
|
|
|
2048
2048
|
return queryClient;
|
|
2049
2049
|
}\n`;
|
|
2050
2050
|
};
|
|
2051
|
-
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, forceSuccessResponse, route, doc, usePrefetch, useQuery, useInfinite, useInvalidate, useSetQueryData, useGetQueryData, adapter }) => {
|
|
2051
|
+
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 }) => {
|
|
2052
2052
|
const { hasQueryV5, hasQueryV5WithDataTagError, hasQueryV5WithInfiniteQueryOptionsError } = adapter;
|
|
2053
2053
|
const hasSignalParam = props.some((prop) => prop.name === "signal");
|
|
2054
2054
|
const queryPropDefinitions = wrapPropsBodyWithMutatorBodyType({
|
|
@@ -2092,7 +2092,7 @@ const generateQueryImplementation = ({ queryOption: { name, queryParam, options,
|
|
|
2092
2092
|
hasQueryV5,
|
|
2093
2093
|
hasQueryV5WithDataTagError
|
|
2094
2094
|
});
|
|
2095
|
-
const errorType = getQueryErrorType(
|
|
2095
|
+
const errorType = getQueryErrorType(typeName, response, httpClient, mutator, forceSuccessResponse);
|
|
2096
2096
|
const dataType = mutator?.isHook ? `ReturnType<typeof use${pascal(operationName)}Hook>` : `typeof ${operationName}`;
|
|
2097
2097
|
const definedInitialDataQueryArguments = adapter.generateQueryArguments({
|
|
2098
2098
|
operationName,
|
|
@@ -2272,8 +2272,8 @@ export function ${queryHookName}<TData = ${TData}, TError = ${errorType}>(\n ${q
|
|
|
2272
2272
|
return `
|
|
2273
2273
|
${queryOptionsFn}
|
|
2274
2274
|
|
|
2275
|
-
export type ${pascal(
|
|
2276
|
-
export type ${pascal(
|
|
2275
|
+
export type ${pascal(optionTypeName)}QueryResult = NonNullable<Awaited<ReturnType<${dataType}>>>
|
|
2276
|
+
export type ${pascal(optionTypeName)}QueryError = ${errorType}
|
|
2277
2277
|
|
|
2278
2278
|
${adapter.shouldGenerateOverrideTypes() ? overrideTypes : ""}
|
|
2279
2279
|
${doc}
|
|
@@ -2318,7 +2318,7 @@ ${shouldGenerateGetQueryData ? isReactQuery ? `${doc}export const ${getQueryData
|
|
|
2318
2318
|
};
|
|
2319
2319
|
const generateQueryHook = async (verbOptions, options, outputClient, adapter) => {
|
|
2320
2320
|
if (!adapter) throw new Error("FrameworkAdapter is required for generateQueryHook");
|
|
2321
|
-
const { queryParams, operationName, body, props: _props, verb, params, override, mutator, response, operationId, summary, deprecated } = verbOptions;
|
|
2321
|
+
const { queryParams, operationName, typeName, body, props: _props, verb, params, override, mutator, response, operationId, summary, deprecated } = verbOptions;
|
|
2322
2322
|
const { route, override: { operations }, context, output } = options;
|
|
2323
2323
|
const props = adapter.transformProps(_props);
|
|
2324
2324
|
const query = override.query;
|
|
@@ -2374,6 +2374,7 @@ const generateQueryHook = async (verbOptions, options, outputClient, adapter) =>
|
|
|
2374
2374
|
const queries = [
|
|
2375
2375
|
...effectiveUseInfinite ? [{
|
|
2376
2376
|
name: camel(`${operationName}-infinite`),
|
|
2377
|
+
typeName: camel(`${typeName}-infinite`),
|
|
2377
2378
|
options: query.options,
|
|
2378
2379
|
type: QueryType.INFINITE,
|
|
2379
2380
|
queryParam: query.useInfiniteQueryParam,
|
|
@@ -2381,18 +2382,21 @@ const generateQueryHook = async (verbOptions, options, outputClient, adapter) =>
|
|
|
2381
2382
|
}] : [],
|
|
2382
2383
|
...effectiveUseQuery ? [{
|
|
2383
2384
|
name: operationName,
|
|
2385
|
+
typeName,
|
|
2384
2386
|
options: query.options,
|
|
2385
2387
|
type: QueryType.QUERY,
|
|
2386
2388
|
queryKeyFnName: camel(`get-${operationName}-query-key`)
|
|
2387
2389
|
}] : [],
|
|
2388
2390
|
...effectiveUseSuspenseQuery ? [{
|
|
2389
2391
|
name: camel(`${operationName}-suspense`),
|
|
2392
|
+
typeName: camel(`${typeName}-suspense`),
|
|
2390
2393
|
options: query.options,
|
|
2391
2394
|
type: QueryType.SUSPENSE_QUERY,
|
|
2392
2395
|
queryKeyFnName: camel(`get-${operationName}-query-key`)
|
|
2393
2396
|
}] : [],
|
|
2394
2397
|
...effectiveUseSuspenseInfiniteQuery ? [{
|
|
2395
2398
|
name: camel(`${operationName}-suspense-infinite`),
|
|
2399
|
+
typeName: camel(`${typeName}-suspense-infinite`),
|
|
2396
2400
|
options: query.options,
|
|
2397
2401
|
type: QueryType.SUSPENSE_INFINITE,
|
|
2398
2402
|
queryParam: query.useInfiniteQueryParam,
|
|
@@ -2436,6 +2440,7 @@ ${queryKeyFns}`;
|
|
|
2436
2440
|
queryOption,
|
|
2437
2441
|
operationId,
|
|
2438
2442
|
operationName,
|
|
2443
|
+
typeName,
|
|
2439
2444
|
queryProperties,
|
|
2440
2445
|
queryKeyProperties,
|
|
2441
2446
|
params,
|