@orval/query 8.15.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 +39 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +12 -32
package/dist/index.mjs
CHANGED
|
@@ -130,7 +130,9 @@ const ANGULAR_HTTP_DEPENDENCIES = [
|
|
|
130
130
|
dependency: "rxjs/operators"
|
|
131
131
|
}
|
|
132
132
|
];
|
|
133
|
-
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);
|
|
134
136
|
const isRequestOptions = override.requestOptions !== false;
|
|
135
137
|
const isFormData = !override.formData.disabled;
|
|
136
138
|
const isFormUrlEncoded = override.formUrlEncoded !== false;
|
|
@@ -144,6 +146,7 @@ const generateAngularHttpRequestFunction = ({ headers, queryParams, operationNam
|
|
|
144
146
|
isFormUrlEncoded
|
|
145
147
|
});
|
|
146
148
|
if (mutator) {
|
|
149
|
+
const isExactOptionalPropertyTypes = !!context.output.tsconfig?.compilerOptions?.exactOptionalPropertyTypes;
|
|
147
150
|
const mutatorConfig = generateMutatorConfig({
|
|
148
151
|
route,
|
|
149
152
|
body,
|
|
@@ -155,7 +158,7 @@ const generateAngularHttpRequestFunction = ({ headers, queryParams, operationNam
|
|
|
155
158
|
isFormUrlEncoded,
|
|
156
159
|
hasSignal,
|
|
157
160
|
hasSignalParam,
|
|
158
|
-
isExactOptionalPropertyTypes
|
|
161
|
+
isExactOptionalPropertyTypes,
|
|
159
162
|
isVue: false,
|
|
160
163
|
isAngular: context.output.httpClient === OutputHttpClient.ANGULAR
|
|
161
164
|
});
|
|
@@ -742,6 +745,12 @@ const getSolidQueryImports = (prefix, hasRenamedOptionsTypes) => {
|
|
|
742
745
|
{ name: "InvalidateOptions" }
|
|
743
746
|
],
|
|
744
747
|
dependency: "@tanstack/solid-query"
|
|
748
|
+
}, {
|
|
749
|
+
exports: [{
|
|
750
|
+
name: "mergeProps",
|
|
751
|
+
values: true
|
|
752
|
+
}],
|
|
753
|
+
dependency: "solid-js"
|
|
745
754
|
}];
|
|
746
755
|
};
|
|
747
756
|
const ANGULAR_QUERY_DEPENDENCIES = [{
|
|
@@ -1176,7 +1185,7 @@ const createSolidAdapter = ({ hasQueryV5, hasQueryV5WithDataTagError, hasQueryV5
|
|
|
1176
1185
|
>`;
|
|
1177
1186
|
},
|
|
1178
1187
|
getQueryReturnStatement({ queryResultVarName, queryOptionsVarName }) {
|
|
1179
|
-
return `return
|
|
1188
|
+
return `return mergeProps(${queryResultVarName}, { queryKey: ${queryOptionsVarName}.queryKey }) as any;`;
|
|
1180
1189
|
},
|
|
1181
1190
|
generateQueryInvocationArgs({ queryOptionsFnName, queryProperties, isRequestOptions, optionalQueryClientArgument }) {
|
|
1182
1191
|
const optionsArg = isRequestOptions ? "options" : "queryOptions";
|
|
@@ -1600,6 +1609,31 @@ const getStaticRoutePrefix = (route) => {
|
|
|
1600
1609
|
const prefix = route.slice(0, idx);
|
|
1601
1610
|
return prefix.split("/").some((segment) => segment.length > 0) ? prefix : void 0;
|
|
1602
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
|
+
});
|
|
1603
1637
|
/**
|
|
1604
1638
|
* Check whether the target invalidation needs to call the query key function.
|
|
1605
1639
|
* Returns false when no params are specified and the route has required path
|
|
@@ -1655,7 +1689,7 @@ const createGenerateInvalidateCall = (spec, shouldSplitQueryKey, useOperationIdA
|
|
|
1655
1689
|
};
|
|
1656
1690
|
};
|
|
1657
1691
|
const generateMutationHook = async ({ verbOptions, options, isRequestOptions, httpClient, doc, adapter }) => {
|
|
1658
|
-
const { operationName, body, props, mutator, response, operationId, override } = verbOptions;
|
|
1692
|
+
const { operationName, body, props, mutator, response, operationId, route: pathRoute, override } = verbOptions;
|
|
1659
1693
|
const { route, context, output } = options;
|
|
1660
1694
|
const query = override.query;
|
|
1661
1695
|
const mutationOptionsMutator = query.mutationOptions ? await generateMutator({
|
|
@@ -1733,7 +1767,7 @@ ${hasInvalidation ? adapter.generateMutationOnSuccess({
|
|
|
1733
1767
|
uniqueInvalidates
|
|
1734
1768
|
}) : ""}
|
|
1735
1769
|
|
|
1736
|
-
${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}' }` : ""});` : ""}
|
|
1737
1771
|
|
|
1738
1772
|
|
|
1739
1773
|
return ${mutationOptionsMutator ? "customOptions" : hasInvalidation ? "{ ...mutationOptions, mutationFn, onSuccess }" : "{ mutationFn, ...mutationOptions }"}}`;
|