@orval/query 8.14.0 → 8.16.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 +49 -11
- package/dist/index.mjs.map +1 -1
- package/package.json +12 -32
package/dist/index.mjs
CHANGED
|
@@ -24,6 +24,7 @@ const normalizeQueryOptions = (queryOptions = {}, outputWorkspace) => {
|
|
|
24
24
|
...queryOptions.shouldExportMutatorHooks ? { shouldExportMutatorHooks: true } : {},
|
|
25
25
|
...queryOptions.shouldExportQueryKey ? { shouldExportQueryKey: true } : {},
|
|
26
26
|
...queryOptions.shouldFilterQueryKey ? { shouldFilterQueryKey: true } : {},
|
|
27
|
+
...queryOptions.queryKeyFilter ? { queryKeyFilter: queryOptions.queryKeyFilter } : {},
|
|
27
28
|
...queryOptions.shouldExportHttpClient ? { shouldExportHttpClient: true } : {},
|
|
28
29
|
...queryOptions.shouldSplitQueryKey ? { shouldSplitQueryKey: true } : {},
|
|
29
30
|
...queryOptions.useOperationIdAsQueryKey ? { useOperationIdAsQueryKey: true } : {}
|
|
@@ -129,7 +130,9 @@ const ANGULAR_HTTP_DEPENDENCIES = [
|
|
|
129
130
|
dependency: "rxjs/operators"
|
|
130
131
|
}
|
|
131
132
|
];
|
|
132
|
-
const generateAngularHttpRequestFunction = ({ headers, queryParams, operationName, response, mutator, body, props, verb, formData, formUrlEncoded, override }, { route, context }) => {
|
|
133
|
+
const generateAngularHttpRequestFunction = ({ headers, queryParams, operationName, response, mutator, body, props, verb, formData, formUrlEncoded, override }, { route: _route, context }) => {
|
|
134
|
+
let route = _route;
|
|
135
|
+
if (context.output.urlEncodeParameters) route = makeRouteSafe(route);
|
|
133
136
|
const isRequestOptions = override.requestOptions !== false;
|
|
134
137
|
const isFormData = !override.formData.disabled;
|
|
135
138
|
const isFormUrlEncoded = override.formUrlEncoded !== false;
|
|
@@ -143,6 +146,7 @@ const generateAngularHttpRequestFunction = ({ headers, queryParams, operationNam
|
|
|
143
146
|
isFormUrlEncoded
|
|
144
147
|
});
|
|
145
148
|
if (mutator) {
|
|
149
|
+
const isExactOptionalPropertyTypes = !!context.output.tsconfig?.compilerOptions?.exactOptionalPropertyTypes;
|
|
146
150
|
const mutatorConfig = generateMutatorConfig({
|
|
147
151
|
route,
|
|
148
152
|
body,
|
|
@@ -154,7 +158,7 @@ const generateAngularHttpRequestFunction = ({ headers, queryParams, operationNam
|
|
|
154
158
|
isFormUrlEncoded,
|
|
155
159
|
hasSignal,
|
|
156
160
|
hasSignalParam,
|
|
157
|
-
isExactOptionalPropertyTypes
|
|
161
|
+
isExactOptionalPropertyTypes,
|
|
158
162
|
isVue: false,
|
|
159
163
|
isAngular: context.output.httpClient === OutputHttpClient.ANGULAR
|
|
160
164
|
});
|
|
@@ -391,10 +395,12 @@ const dedupeUnionTypes = (types) => {
|
|
|
391
395
|
if (!types) return types;
|
|
392
396
|
return [...new Set(types.split("|").map((t) => t.trim()).filter(Boolean))].join(" | ");
|
|
393
397
|
};
|
|
394
|
-
const getQueryErrorType = (operationName, response, httpClient, mutator) => {
|
|
398
|
+
const getQueryErrorType = (operationName, response, httpClient, mutator, forceSuccessResponse) => {
|
|
395
399
|
const errorsType = dedupeUnionTypes(response.definition.errors || "unknown");
|
|
396
400
|
if (mutator) return mutator.hasErrorType ? `${mutator.default ? pascal(operationName) : ""}ErrorType<${errorsType}>` : errorsType;
|
|
397
|
-
|
|
401
|
+
if (httpClient === OutputHttpClient.AXIOS) return `AxiosError<${errorsType}>`;
|
|
402
|
+
if (forceSuccessResponse) return `globalThis.Error & { info?: ${errorsType}; status?: number }`;
|
|
403
|
+
return errorsType;
|
|
398
404
|
};
|
|
399
405
|
const getHooksOptionImplementation = (isRequestOptions, httpClient, operationName, mutator, useRuntimeFetcher) => {
|
|
400
406
|
const fetcherOption = httpClient === OutputHttpClient.FETCH && useRuntimeFetcher ? ", fetcher: fetcherFn" : "";
|
|
@@ -739,6 +745,12 @@ const getSolidQueryImports = (prefix, hasRenamedOptionsTypes) => {
|
|
|
739
745
|
{ name: "InvalidateOptions" }
|
|
740
746
|
],
|
|
741
747
|
dependency: "@tanstack/solid-query"
|
|
748
|
+
}, {
|
|
749
|
+
exports: [{
|
|
750
|
+
name: "mergeProps",
|
|
751
|
+
values: true
|
|
752
|
+
}],
|
|
753
|
+
dependency: "solid-js"
|
|
742
754
|
}];
|
|
743
755
|
};
|
|
744
756
|
const ANGULAR_QUERY_DEPENDENCIES = [{
|
|
@@ -1173,7 +1185,7 @@ const createSolidAdapter = ({ hasQueryV5, hasQueryV5WithDataTagError, hasQueryV5
|
|
|
1173
1185
|
>`;
|
|
1174
1186
|
},
|
|
1175
1187
|
getQueryReturnStatement({ queryResultVarName, queryOptionsVarName }) {
|
|
1176
|
-
return `return
|
|
1188
|
+
return `return mergeProps(${queryResultVarName}, { queryKey: ${queryOptionsVarName}.queryKey }) as any;`;
|
|
1177
1189
|
},
|
|
1178
1190
|
generateQueryInvocationArgs({ queryOptionsFnName, queryProperties, isRequestOptions, optionalQueryClientArgument }) {
|
|
1179
1191
|
const optionsArg = isRequestOptions ? "options" : "queryOptions";
|
|
@@ -1597,6 +1609,31 @@ const getStaticRoutePrefix = (route) => {
|
|
|
1597
1609
|
const prefix = route.slice(0, idx);
|
|
1598
1610
|
return prefix.split("/").some((segment) => segment.length > 0) ? prefix : void 0;
|
|
1599
1611
|
};
|
|
1612
|
+
const getMutationOptionsUrl = (route, pathParamNames, pathRoute) => {
|
|
1613
|
+
const pathParams = new Set(pathParamNames);
|
|
1614
|
+
if (pathParams.size === 0) return route;
|
|
1615
|
+
const formatPathRoute = (value) => value.replace(/\$\{([^}]+)\}/g, (match, expression) => pathParams.has(expression) ? `{${expression}}` : match);
|
|
1616
|
+
if (pathRoute) {
|
|
1617
|
+
if (route.endsWith(pathRoute)) return `${route.slice(0, -pathRoute.length)}${formatPathRoute(pathRoute)}`;
|
|
1618
|
+
const routeWithoutLeadingSlash = pathRoute.startsWith("/") ? pathRoute.slice(1) : void 0;
|
|
1619
|
+
if (routeWithoutLeadingSlash && route.endsWith(routeWithoutLeadingSlash)) return `${route.slice(0, -routeWithoutLeadingSlash.length)}${formatPathRoute(routeWithoutLeadingSlash)}`;
|
|
1620
|
+
}
|
|
1621
|
+
return pathRoute ? route : formatPathRoute(route);
|
|
1622
|
+
};
|
|
1623
|
+
const getMutationOptionsNamedPathParamName = (param) => {
|
|
1624
|
+
const trimmedParam = param.trim();
|
|
1625
|
+
if (!trimmedParam || trimmedParam.startsWith("...")) return void 0;
|
|
1626
|
+
const [name] = trimmedParam.split(/[=:]/);
|
|
1627
|
+
return name?.trim() || void 0;
|
|
1628
|
+
};
|
|
1629
|
+
const getMutationOptionsPathParamNames = (props) => props.flatMap((prop) => {
|
|
1630
|
+
if (prop.type === GetterPropType.PARAM) return [prop.name];
|
|
1631
|
+
if (prop.type === GetterPropType.NAMED_PATH_PARAMS) return prop.destructured.replace(/^\{\s*|\s*\}$/g, "").split(",").flatMap((param) => {
|
|
1632
|
+
const name = getMutationOptionsNamedPathParamName(param);
|
|
1633
|
+
return name ? [name] : [];
|
|
1634
|
+
});
|
|
1635
|
+
return [];
|
|
1636
|
+
});
|
|
1600
1637
|
/**
|
|
1601
1638
|
* Check whether the target invalidation needs to call the query key function.
|
|
1602
1639
|
* Returns false when no params are specified and the route has required path
|
|
@@ -1652,7 +1689,7 @@ const createGenerateInvalidateCall = (spec, shouldSplitQueryKey, useOperationIdA
|
|
|
1652
1689
|
};
|
|
1653
1690
|
};
|
|
1654
1691
|
const generateMutationHook = async ({ verbOptions, options, isRequestOptions, httpClient, doc, adapter }) => {
|
|
1655
|
-
const { operationName, body, props, mutator, response, operationId, override } = verbOptions;
|
|
1692
|
+
const { operationName, body, props, mutator, response, operationId, route: pathRoute, override } = verbOptions;
|
|
1656
1693
|
const { route, context, output } = options;
|
|
1657
1694
|
const query = override.query;
|
|
1658
1695
|
const mutationOptionsMutator = query.mutationOptions ? await generateMutator({
|
|
@@ -1665,7 +1702,7 @@ const generateMutationHook = async ({ verbOptions, options, isRequestOptions, ht
|
|
|
1665
1702
|
const bodyOptionalMark = body.isOptional ? "?" : "";
|
|
1666
1703
|
const definitions = props.map(({ definition, type }) => type === GetterPropType.BODY ? mutator?.bodyTypeName ? `data${bodyOptionalMark}: ${mutator.bodyTypeName}<${body.definition}>` : `data${bodyOptionalMark}: ${body.definition}` : definition).join(";");
|
|
1667
1704
|
const properties = props.map(({ name, type }) => type === GetterPropType.BODY ? "data" : name).join(",");
|
|
1668
|
-
const errorType = getQueryErrorType(operationName, response, httpClient, mutator);
|
|
1705
|
+
const errorType = getQueryErrorType(operationName, response, httpClient, mutator, override.fetch.forceSuccessResponse);
|
|
1669
1706
|
const dataType = mutator?.isHook ? `ReturnType<typeof use${pascal(operationName)}Hook>` : `typeof ${operationName}`;
|
|
1670
1707
|
const mutationOptionFnReturnType = getQueryOptionsDefinition({
|
|
1671
1708
|
operationName,
|
|
@@ -1730,7 +1767,7 @@ ${hasInvalidation ? adapter.generateMutationOnSuccess({
|
|
|
1730
1767
|
uniqueInvalidates
|
|
1731
1768
|
}) : ""}
|
|
1732
1769
|
|
|
1733
|
-
${mutationOptionsMutator ? `const customOptions = ${mutationOptionsMutator.name}({...mutationOptions, mutationFn}${mutationOptionsMutator.hasSecondArg ? `, { url: \`${route
|
|
1770
|
+
${mutationOptionsMutator ? `const customOptions = ${mutationOptionsMutator.name}({...mutationOptions, mutationFn}${mutationOptionsMutator.hasSecondArg ? `, { url: \`${getMutationOptionsUrl(route, getMutationOptionsPathParamNames(props), pathRoute)}\` }` : ""}${mutationOptionsMutator.hasThirdArg ? `, { operationId: '${operationId}', operationName: '${operationName}' }` : ""});` : ""}
|
|
1734
1771
|
|
|
1735
1772
|
|
|
1736
1773
|
return ${mutationOptionsMutator ? "customOptions" : hasInvalidation ? "{ ...mutationOptions, mutationFn, onSuccess }" : "{ mutationFn, ...mutationOptions }"}}`;
|
|
@@ -1933,7 +1970,7 @@ const generatePrefetch = ({ usePrefetch, type, useQuery, useInfinite, operationN
|
|
|
1933
1970
|
return queryClient;
|
|
1934
1971
|
}\n`;
|
|
1935
1972
|
};
|
|
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 }) => {
|
|
1973
|
+
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 }) => {
|
|
1937
1974
|
const { hasQueryV5, hasQueryV5WithDataTagError, hasQueryV5WithInfiniteQueryOptionsError } = adapter;
|
|
1938
1975
|
const hasSignalParam = props.some((prop) => prop.name === "signal");
|
|
1939
1976
|
const queryPropDefinitions = wrapPropsBodyWithMutatorBodyType({
|
|
@@ -1977,7 +2014,7 @@ const generateQueryImplementation = ({ queryOption: { name, queryParam, options,
|
|
|
1977
2014
|
hasQueryV5,
|
|
1978
2015
|
hasQueryV5WithDataTagError
|
|
1979
2016
|
});
|
|
1980
|
-
const errorType = getQueryErrorType(operationName, response, httpClient, mutator);
|
|
2017
|
+
const errorType = getQueryErrorType(operationName, response, httpClient, mutator, forceSuccessResponse);
|
|
1981
2018
|
const dataType = mutator?.isHook ? `ReturnType<typeof use${pascal(operationName)}Hook>` : `typeof ${operationName}`;
|
|
1982
2019
|
const definedInitialDataQueryArguments = adapter.generateQueryArguments({
|
|
1983
2020
|
operationName,
|
|
@@ -2310,7 +2347,7 @@ ${override.query.shouldExportQueryKey ? "export " : ""}const ${queryOption.query
|
|
|
2310
2347
|
queryKeyParams,
|
|
2311
2348
|
body.implementation
|
|
2312
2349
|
].filter((x) => !!x).join(", ")}
|
|
2313
|
-
]${override.query.shouldFilterQueryKey ?
|
|
2350
|
+
]${override.query.shouldFilterQueryKey ? `.filter(${override.query.queryKeyFilter ?? "q => q !== undefined"})` : " as const"};
|
|
2314
2351
|
}
|
|
2315
2352
|
`;
|
|
2316
2353
|
}
|
|
@@ -2334,6 +2371,7 @@ ${queryKeyFns}`;
|
|
|
2334
2371
|
isExactOptionalPropertyTypes,
|
|
2335
2372
|
hasSignal: getHasSignal({ overrideQuerySignal: override.query.signal }),
|
|
2336
2373
|
useRuntimeFetcher: override.fetch.useRuntimeFetcher,
|
|
2374
|
+
forceSuccessResponse: override.fetch.forceSuccessResponse,
|
|
2337
2375
|
queryOptionsMutator,
|
|
2338
2376
|
queryKeyMutator,
|
|
2339
2377
|
route,
|