@orval/query 7.2.0 → 7.4.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.js +69 -66
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1674,6 +1674,10 @@ var vueUnRefParams = (props) => {
|
|
|
1674
1674
|
var wrapRouteParameters = (route, prepend, append) => route.replaceAll(import_core.TEMPLATE_TAG_REGEX, `\${${prepend}$1${append}}`);
|
|
1675
1675
|
var makeRouteSafe = (route) => wrapRouteParameters(route, "encodeURIComponent(String(", "))");
|
|
1676
1676
|
var isVue = (client) => import_core.OutputClient.VUE_QUERY === client;
|
|
1677
|
+
var getHasSignal = ({
|
|
1678
|
+
overrideQuerySignal = false,
|
|
1679
|
+
verb
|
|
1680
|
+
}) => overrideQuerySignal && (!(0, import_core.getIsBodyVerb)(verb) || verb === import_core.Verbs.POST);
|
|
1677
1681
|
|
|
1678
1682
|
// src/client.ts
|
|
1679
1683
|
var AXIOS_DEPENDENCIES = [
|
|
@@ -1692,9 +1696,9 @@ var AXIOS_DEPENDENCIES = [
|
|
|
1692
1696
|
dependency: "axios"
|
|
1693
1697
|
}
|
|
1694
1698
|
];
|
|
1695
|
-
var generateQueryRequestFunction = (verbOptions, options,
|
|
1699
|
+
var generateQueryRequestFunction = (verbOptions, options, isVue2) => {
|
|
1696
1700
|
if (options.context.output.httpClient === import_core2.OutputHttpClient.AXIOS) {
|
|
1697
|
-
return generateAxiosRequestFunction(verbOptions, options,
|
|
1701
|
+
return generateAxiosRequestFunction(verbOptions, options, isVue2);
|
|
1698
1702
|
} else {
|
|
1699
1703
|
return (0, import_fetch.generateRequestFunction)(verbOptions, options);
|
|
1700
1704
|
}
|
|
@@ -1712,11 +1716,11 @@ var generateAxiosRequestFunction = ({
|
|
|
1712
1716
|
formUrlEncoded,
|
|
1713
1717
|
override,
|
|
1714
1718
|
paramsSerializer
|
|
1715
|
-
}, { route: _route, context },
|
|
1719
|
+
}, { route: _route, context }, isVue2) => {
|
|
1716
1720
|
var _a, _b, _c;
|
|
1717
1721
|
let props = _props;
|
|
1718
1722
|
let route = _route;
|
|
1719
|
-
if (
|
|
1723
|
+
if (isVue2) {
|
|
1720
1724
|
props = vueWrapTypeWithMaybeRef(_props);
|
|
1721
1725
|
}
|
|
1722
1726
|
if ((_a = context.output) == null ? void 0 : _a.urlEncodeParameters) {
|
|
@@ -1725,9 +1729,11 @@ var generateAxiosRequestFunction = ({
|
|
|
1725
1729
|
const isRequestOptions = override.requestOptions !== false;
|
|
1726
1730
|
const isFormData = override.formData !== false;
|
|
1727
1731
|
const isFormUrlEncoded = override.formUrlEncoded !== false;
|
|
1728
|
-
const hasSignal =
|
|
1732
|
+
const hasSignal = getHasSignal({
|
|
1733
|
+
overrideQuerySignal: override.query.signal,
|
|
1734
|
+
verb
|
|
1735
|
+
});
|
|
1729
1736
|
const isExactOptionalPropertyTypes = !!((_c = (_b = context.output.tsconfig) == null ? void 0 : _b.compilerOptions) == null ? void 0 : _c.exactOptionalPropertyTypes);
|
|
1730
|
-
const isBodyVerb = import_core2.VERBS_WITH_BODY.includes(verb);
|
|
1731
1737
|
const bodyForm = (0, import_core2.generateFormDataAndUrlEncodedFunction)({
|
|
1732
1738
|
formData,
|
|
1733
1739
|
formUrlEncoded,
|
|
@@ -1745,13 +1751,12 @@ var generateAxiosRequestFunction = ({
|
|
|
1745
1751
|
verb,
|
|
1746
1752
|
isFormData,
|
|
1747
1753
|
isFormUrlEncoded,
|
|
1748
|
-
isBodyVerb,
|
|
1749
1754
|
hasSignal,
|
|
1750
1755
|
isExactOptionalPropertyTypes,
|
|
1751
|
-
isVue:
|
|
1756
|
+
isVue: isVue2
|
|
1752
1757
|
});
|
|
1753
|
-
|
|
1754
|
-
|
|
1758
|
+
const bodyDefinition = body.definition.replace("[]", "\\[\\]");
|
|
1759
|
+
const propsImplementation = (mutator == null ? void 0 : mutator.bodyTypeName) && body.definition ? (0, import_core2.toObjectString)(props, "implementation").replace(
|
|
1755
1760
|
new RegExp(`(\\w*):\\s?${bodyDefinition}`),
|
|
1756
1761
|
`$1: ${mutator.bodyTypeName}<${body.definition}>`
|
|
1757
1762
|
) : (0, import_core2.toObjectString)(props, "implementation");
|
|
@@ -1765,7 +1770,7 @@ var generateAxiosRequestFunction = ({
|
|
|
1765
1770
|
|
|
1766
1771
|
return useCallback((
|
|
1767
1772
|
${propsImplementation}
|
|
1768
|
-
${isRequestOptions && mutator.hasSecondArg ? `options${context.output.optionsParamRequired ? "" : "?"}: SecondParameter<ReturnType<typeof ${mutator.name}>>,` : ""}${
|
|
1773
|
+
${isRequestOptions && mutator.hasSecondArg ? `options${context.output.optionsParamRequired ? "" : "?"}: SecondParameter<ReturnType<typeof ${mutator.name}>>,` : ""}${hasSignal ? "signal?: AbortSignal\n" : ""}) => {${bodyForm}
|
|
1769
1774
|
return ${operationName}(
|
|
1770
1775
|
${mutatorConfig},
|
|
1771
1776
|
${requestOptions});
|
|
@@ -1775,8 +1780,8 @@ var generateAxiosRequestFunction = ({
|
|
|
1775
1780
|
}
|
|
1776
1781
|
return `${override.query.shouldExportHttpClient ? "export " : ""}const ${operationName} = (
|
|
1777
1782
|
${propsImplementation}
|
|
1778
|
-
${isRequestOptions && mutator.hasSecondArg ? `options${context.output.optionsParamRequired ? "" : "?"}: SecondParameter<typeof ${mutator.name}>,` : ""}${
|
|
1779
|
-
${
|
|
1783
|
+
${isRequestOptions && mutator.hasSecondArg ? `options${context.output.optionsParamRequired ? "" : "?"}: SecondParameter<typeof ${mutator.name}>,` : ""}${hasSignal ? "signal?: AbortSignal\n" : ""}) => {
|
|
1784
|
+
${isVue2 ? vueUnRefParams(props) : ""}
|
|
1780
1785
|
${bodyForm}
|
|
1781
1786
|
return ${mutator.name}<${response.definition.success || "unknown"}>(
|
|
1782
1787
|
${mutatorConfig},
|
|
@@ -1801,7 +1806,7 @@ var generateAxiosRequestFunction = ({
|
|
|
1801
1806
|
paramsSerializerOptions: override == null ? void 0 : override.paramsSerializerOptions,
|
|
1802
1807
|
isExactOptionalPropertyTypes,
|
|
1803
1808
|
hasSignal,
|
|
1804
|
-
isVue:
|
|
1809
|
+
isVue: isVue2
|
|
1805
1810
|
});
|
|
1806
1811
|
const optionsArgs = generateRequestOptionsArguments({
|
|
1807
1812
|
isRequestOptions,
|
|
@@ -1809,8 +1814,9 @@ var generateAxiosRequestFunction = ({
|
|
|
1809
1814
|
});
|
|
1810
1815
|
const queryProps = (0, import_core2.toObjectString)(props, "implementation");
|
|
1811
1816
|
const httpRequestFunctionImplementation = `export const ${operationName} = (
|
|
1812
|
-
${queryProps} ${optionsArgs} ): Promise<AxiosResponse<${response.definition.success || "unknown"}>> => {
|
|
1813
|
-
${
|
|
1817
|
+
${queryProps} ${optionsArgs} ): Promise<AxiosResponse<${response.definition.success || "unknown"}>> => {
|
|
1818
|
+
${isVue2 ? vueUnRefParams(props) : ""}
|
|
1819
|
+
${bodyForm}
|
|
1814
1820
|
return axios${!isSyntheticDefaultImportsAllowed ? ".default" : ""}.${verb}(${options});
|
|
1815
1821
|
}
|
|
1816
1822
|
`;
|
|
@@ -1888,17 +1894,22 @@ var getQueryErrorType = (operationName, response, httpClient, mutator) => {
|
|
|
1888
1894
|
return httpClient === import_core2.OutputHttpClient.AXIOS ? `AxiosError<${response.definition.errors || "unknown"}>` : `${response.definition.errors || "unknown"}`;
|
|
1889
1895
|
}
|
|
1890
1896
|
};
|
|
1891
|
-
var getHooksOptionImplementation = (isRequestOptions, httpClient, mutator) => {
|
|
1897
|
+
var getHooksOptionImplementation = (isRequestOptions, httpClient, operationName, mutator) => {
|
|
1892
1898
|
const options = httpClient === import_core2.OutputHttpClient.AXIOS ? ", axios: axiosOptions" : ", fetch: fetchOptions";
|
|
1893
|
-
return isRequestOptions ? `const
|
|
1899
|
+
return isRequestOptions ? `const mutationKey = ['${operationName}'];
|
|
1900
|
+
const {mutation: mutationOptions${!mutator ? options : (mutator == null ? void 0 : mutator.hasSecondArg) ? ", request: requestOptions" : ""}} = options ?
|
|
1901
|
+
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
|
1902
|
+
options
|
|
1903
|
+
: {...options, mutation: {...options.mutation, mutationKey}}
|
|
1904
|
+
: {mutation: { mutationKey, }${(mutator == null ? void 0 : mutator.hasSecondArg) ? ", request: undefined" : ""}${!mutator ? httpClient === import_core2.OutputHttpClient.AXIOS ? ", axios: undefined" : ", fetch: undefined" : ""}};` : "";
|
|
1894
1905
|
};
|
|
1895
1906
|
var getMutationRequestArgs = (isRequestOptions, httpClient, mutator) => {
|
|
1896
1907
|
const options = httpClient === import_core2.OutputHttpClient.AXIOS ? "axiosOptions" : "fetchOptions";
|
|
1897
1908
|
return isRequestOptions ? !mutator ? options : (mutator == null ? void 0 : mutator.hasSecondArg) ? "requestOptions" : "" : "";
|
|
1898
1909
|
};
|
|
1899
|
-
var getHttpFunctionQueryProps = (
|
|
1900
|
-
if (
|
|
1901
|
-
return `unref(${
|
|
1910
|
+
var getHttpFunctionQueryProps = (isVue2, httpClient, queryProperties) => {
|
|
1911
|
+
if (isVue2 && httpClient === import_core2.OutputHttpClient.FETCH && queryProperties) {
|
|
1912
|
+
return queryProperties.split(",").map((prop) => `unref(${prop})`).join(",");
|
|
1902
1913
|
}
|
|
1903
1914
|
return queryProperties;
|
|
1904
1915
|
};
|
|
@@ -1966,7 +1977,8 @@ var SVELTE_QUERY_DEPENDENCIES = [
|
|
|
1966
1977
|
{ name: "CreateInfiniteQueryResult" },
|
|
1967
1978
|
{ name: "QueryKey" },
|
|
1968
1979
|
{ name: "InfiniteData" },
|
|
1969
|
-
{ name: "CreateMutationResult" }
|
|
1980
|
+
{ name: "CreateMutationResult" },
|
|
1981
|
+
{ name: "DataTag" }
|
|
1970
1982
|
],
|
|
1971
1983
|
dependency: "@tanstack/svelte-query"
|
|
1972
1984
|
}
|
|
@@ -2031,7 +2043,8 @@ var REACT_QUERY_DEPENDENCIES = [
|
|
|
2031
2043
|
{ name: "QueryKey" },
|
|
2032
2044
|
{ name: "QueryClient" },
|
|
2033
2045
|
{ name: "InfiniteData" },
|
|
2034
|
-
{ name: "UseMutationResult" }
|
|
2046
|
+
{ name: "UseMutationResult" },
|
|
2047
|
+
{ name: "DataTag" }
|
|
2035
2048
|
],
|
|
2036
2049
|
dependency: "@tanstack/react-query"
|
|
2037
2050
|
}
|
|
@@ -2097,7 +2110,8 @@ var VUE_QUERY_DEPENDENCIES = [
|
|
|
2097
2110
|
{ name: "UseQueryReturnType" },
|
|
2098
2111
|
{ name: "UseInfiniteQueryReturnType" },
|
|
2099
2112
|
{ name: "InfiniteData" },
|
|
2100
|
-
{ name: "UseMutationReturnType" }
|
|
2113
|
+
{ name: "UseMutationReturnType" },
|
|
2114
|
+
{ name: "DataTag" }
|
|
2101
2115
|
],
|
|
2102
2116
|
dependency: "@tanstack/vue-query"
|
|
2103
2117
|
},
|
|
@@ -2169,7 +2183,7 @@ var generateQueryOptions = ({
|
|
|
2169
2183
|
(_, key) => (type !== QueryType.INFINITE || type !== QueryType.SUSPENSE_INFINITE) && INFINITE_QUERY_PROPERTIES.includes(key)
|
|
2170
2184
|
)
|
|
2171
2185
|
)) == null ? void 0 : _a.slice(1, -1)}` : "";
|
|
2172
|
-
if (!params.length) {
|
|
2186
|
+
if (!params.length || isSuspenseQuery(type)) {
|
|
2173
2187
|
if (options) {
|
|
2174
2188
|
return `${queryConfig} ...queryOptions`;
|
|
2175
2189
|
}
|
|
@@ -2181,9 +2195,7 @@ var isSuspenseQuery = (type) => {
|
|
|
2181
2195
|
return [QueryType.SUSPENSE_INFINITE, QueryType.SUSPENSE_QUERY].includes(type);
|
|
2182
2196
|
};
|
|
2183
2197
|
var getQueryOptionsDefinition = ({
|
|
2184
|
-
operationName,
|
|
2185
2198
|
definitions,
|
|
2186
|
-
mutator,
|
|
2187
2199
|
type,
|
|
2188
2200
|
hasSvelteQueryV4,
|
|
2189
2201
|
hasQueryV5,
|
|
@@ -2192,27 +2204,22 @@ var getQueryOptionsDefinition = ({
|
|
|
2192
2204
|
isReturnType,
|
|
2193
2205
|
initialData
|
|
2194
2206
|
}) => {
|
|
2195
|
-
const isMutatorHook = mutator == null ? void 0 : mutator.isHook;
|
|
2196
2207
|
const prefix = !hasSvelteQueryV4 ? "Use" : "Create";
|
|
2197
2208
|
const partialOptions = !isReturnType && hasQueryV5;
|
|
2198
2209
|
if (type) {
|
|
2199
|
-
const funcReturnType = `Awaited<ReturnType<${isMutatorHook ? `ReturnType<typeof use${(0, import_core3.pascal)(operationName)}Hook>` : `typeof ${operationName}`}>>`;
|
|
2200
2210
|
const optionTypeInitialDataPostfix = initialData && !isSuspenseQuery(type) ? ` & Pick<
|
|
2201
2211
|
${(0, import_core3.pascal)(initialData)}InitialDataOptions<
|
|
2202
|
-
|
|
2212
|
+
TData,
|
|
2203
2213
|
TError,
|
|
2204
2214
|
TData${hasQueryV5 && (type === QueryType.INFINITE || type === QueryType.SUSPENSE_INFINITE) && queryParam && queryParams ? `, QueryKey` : ""}
|
|
2205
2215
|
> , 'initialData'
|
|
2206
2216
|
>` : "";
|
|
2207
|
-
const optionType = `${prefix}${(0, import_core3.pascal)(
|
|
2208
|
-
type
|
|
2209
|
-
)}Options<${funcReturnType}, TError, TData${hasQueryV5 && (type === QueryType.INFINITE || type === QueryType.SUSPENSE_INFINITE) && queryParam && queryParams ? `, ${funcReturnType}, QueryKey, ${queryParams == null ? void 0 : queryParams.schema.name}['${queryParam}']` : ""}>`;
|
|
2217
|
+
const optionType = `${prefix}${(0, import_core3.pascal)(type)}Options<TData, TError, TData${hasQueryV5 && (type === QueryType.INFINITE || type === QueryType.SUSPENSE_INFINITE) && queryParam && queryParams ? `, TData, QueryKey, ${queryParams == null ? void 0 : queryParams.schema.name}['${queryParam}']` : ""}>`;
|
|
2210
2218
|
return `${partialOptions ? "Partial<" : ""}${optionType}${partialOptions ? ">" : ""}${optionTypeInitialDataPostfix}`;
|
|
2211
2219
|
}
|
|
2212
|
-
return `${prefix}MutationOptions<
|
|
2220
|
+
return `${prefix}MutationOptions<TData, TError,${definitions ? `{${definitions}}` : "void"}, TContext>`;
|
|
2213
2221
|
};
|
|
2214
2222
|
var generateQueryArguments = ({
|
|
2215
|
-
operationName,
|
|
2216
2223
|
definitions,
|
|
2217
2224
|
mutator,
|
|
2218
2225
|
isRequestOptions,
|
|
@@ -2225,9 +2232,7 @@ var generateQueryArguments = ({
|
|
|
2225
2232
|
httpClient
|
|
2226
2233
|
}) => {
|
|
2227
2234
|
const definition = getQueryOptionsDefinition({
|
|
2228
|
-
operationName,
|
|
2229
2235
|
definitions,
|
|
2230
|
-
mutator,
|
|
2231
2236
|
type,
|
|
2232
2237
|
hasSvelteQueryV4,
|
|
2233
2238
|
hasQueryV5,
|
|
@@ -2251,42 +2256,42 @@ var generateQueryReturnType = ({
|
|
|
2251
2256
|
operationName,
|
|
2252
2257
|
hasVueQueryV4,
|
|
2253
2258
|
hasSvelteQueryV4,
|
|
2259
|
+
hasQueryV5,
|
|
2254
2260
|
isInitialDataDefined
|
|
2255
2261
|
}) => {
|
|
2256
2262
|
switch (outputClient) {
|
|
2257
2263
|
case import_core3.OutputClient.SVELTE_QUERY: {
|
|
2258
2264
|
if (!hasSvelteQueryV4) {
|
|
2259
|
-
return `Use${(0, import_core3.pascal)(type)}StoreResult<Awaited<ReturnType<${isMutatorHook ? `ReturnType<typeof use${(0, import_core3.pascal)(operationName)}Hook>` : `typeof ${operationName}`}>>, TError, TData, QueryKey> & { queryKey: QueryKey }`;
|
|
2265
|
+
return `Use${(0, import_core3.pascal)(type)}StoreResult<Awaited<ReturnType<${isMutatorHook ? `ReturnType<typeof use${(0, import_core3.pascal)(operationName)}Hook>` : `typeof ${operationName}`}>>, TError, TData, QueryKey> & { queryKey: QueryKey} }`;
|
|
2260
2266
|
}
|
|
2261
2267
|
return `Create${(0, import_core3.pascal)(
|
|
2262
2268
|
type
|
|
2263
|
-
)}Result<TData, TError> & { queryKey: QueryKey }`;
|
|
2269
|
+
)}Result<TData, TError> & { queryKey: ${hasQueryV5 ? "DataTag<QueryKey, TData>" : "QueryKey"} }`;
|
|
2264
2270
|
}
|
|
2265
2271
|
case import_core3.OutputClient.VUE_QUERY: {
|
|
2266
2272
|
if (!hasVueQueryV4) {
|
|
2267
2273
|
return ` UseQueryReturnType<TData, TError, Use${(0, import_core3.pascal)(
|
|
2268
2274
|
type
|
|
2269
|
-
)}Result<TData, TError>> & { queryKey: QueryKey }`;
|
|
2275
|
+
)}Result<TData, TError>> & { queryKey: QueryKey} }`;
|
|
2270
2276
|
}
|
|
2271
2277
|
if (type !== QueryType.INFINITE && type !== QueryType.SUSPENSE_INFINITE) {
|
|
2272
|
-
return `UseQueryReturnType<TData, TError> & { queryKey: QueryKey }`;
|
|
2278
|
+
return `UseQueryReturnType<TData, TError> & { queryKey: ${hasQueryV5 ? "DataTag<QueryKey, TData>" : "QueryKey"} }`;
|
|
2273
2279
|
}
|
|
2274
|
-
return `UseInfiniteQueryReturnType<TData, TError> & { queryKey: QueryKey }`;
|
|
2280
|
+
return `UseInfiniteQueryReturnType<TData, TError> & { queryKey: ${hasQueryV5 ? "DataTag<QueryKey, TData>" : "QueryKey"} }`;
|
|
2275
2281
|
}
|
|
2276
2282
|
case import_core3.OutputClient.REACT_QUERY:
|
|
2277
2283
|
default: {
|
|
2278
|
-
return ` ${isInitialDataDefined && !isSuspenseQuery(type) ? "Defined" : ""}Use${(0, import_core3.pascal)(type)}Result<TData, TError> & { queryKey: QueryKey }`;
|
|
2284
|
+
return ` ${isInitialDataDefined && !isSuspenseQuery(type) ? "Defined" : ""}Use${(0, import_core3.pascal)(type)}Result<TData, TError> & { queryKey: ${hasQueryV5 ? "DataTag<QueryKey, TData>" : "QueryKey"} }`;
|
|
2279
2285
|
}
|
|
2280
2286
|
}
|
|
2281
2287
|
};
|
|
2282
2288
|
var generateMutatorReturnType = ({
|
|
2283
2289
|
outputClient,
|
|
2284
|
-
dataType,
|
|
2285
2290
|
variableType
|
|
2286
2291
|
}) => {
|
|
2287
2292
|
if (outputClient === import_core3.OutputClient.REACT_QUERY) {
|
|
2288
2293
|
return `: UseMutationResult<
|
|
2289
|
-
|
|
2294
|
+
TData,
|
|
2290
2295
|
TError,
|
|
2291
2296
|
${variableType},
|
|
2292
2297
|
TContext
|
|
@@ -2294,7 +2299,7 @@ var generateMutatorReturnType = ({
|
|
|
2294
2299
|
}
|
|
2295
2300
|
if (outputClient === import_core3.OutputClient.SVELTE_QUERY) {
|
|
2296
2301
|
return `: CreateMutationResult<
|
|
2297
|
-
|
|
2302
|
+
TData,
|
|
2298
2303
|
TError,
|
|
2299
2304
|
${variableType},
|
|
2300
2305
|
TContext
|
|
@@ -2302,7 +2307,7 @@ var generateMutatorReturnType = ({
|
|
|
2302
2307
|
}
|
|
2303
2308
|
if (outputClient === import_core3.OutputClient.VUE_QUERY) {
|
|
2304
2309
|
return `: UseMutationReturnType<
|
|
2305
|
-
|
|
2310
|
+
TData,
|
|
2306
2311
|
TError,
|
|
2307
2312
|
${variableType},
|
|
2308
2313
|
TContext
|
|
@@ -2386,6 +2391,7 @@ var generateQueryImplementation = ({
|
|
|
2386
2391
|
operationName,
|
|
2387
2392
|
hasVueQueryV4,
|
|
2388
2393
|
hasSvelteQueryV4,
|
|
2394
|
+
hasQueryV5,
|
|
2389
2395
|
isInitialDataDefined: true
|
|
2390
2396
|
});
|
|
2391
2397
|
const returnType = generateQueryReturnType({
|
|
@@ -2394,7 +2400,8 @@ var generateQueryImplementation = ({
|
|
|
2394
2400
|
isMutatorHook: mutator == null ? void 0 : mutator.isHook,
|
|
2395
2401
|
operationName,
|
|
2396
2402
|
hasVueQueryV4,
|
|
2397
|
-
hasSvelteQueryV4
|
|
2403
|
+
hasSvelteQueryV4,
|
|
2404
|
+
hasQueryV5
|
|
2398
2405
|
});
|
|
2399
2406
|
const errorType = getQueryErrorType(
|
|
2400
2407
|
operationName,
|
|
@@ -2404,7 +2411,6 @@ var generateQueryImplementation = ({
|
|
|
2404
2411
|
);
|
|
2405
2412
|
const dataType = (mutator == null ? void 0 : mutator.isHook) ? `ReturnType<typeof use${(0, import_core3.pascal)(operationName)}Hook>` : `typeof ${operationName}`;
|
|
2406
2413
|
const definedInitialDataQueryArguments = generateQueryArguments({
|
|
2407
|
-
operationName,
|
|
2408
2414
|
definitions: "",
|
|
2409
2415
|
mutator,
|
|
2410
2416
|
isRequestOptions,
|
|
@@ -2417,7 +2423,6 @@ var generateQueryImplementation = ({
|
|
|
2417
2423
|
httpClient
|
|
2418
2424
|
});
|
|
2419
2425
|
const undefinedInitialDataQueryArguments = generateQueryArguments({
|
|
2420
|
-
operationName,
|
|
2421
2426
|
definitions: "",
|
|
2422
2427
|
mutator,
|
|
2423
2428
|
isRequestOptions,
|
|
@@ -2430,7 +2435,6 @@ var generateQueryImplementation = ({
|
|
|
2430
2435
|
httpClient
|
|
2431
2436
|
});
|
|
2432
2437
|
const queryArguments = generateQueryArguments({
|
|
2433
|
-
operationName,
|
|
2434
2438
|
definitions: "",
|
|
2435
2439
|
mutator,
|
|
2436
2440
|
isRequestOptions,
|
|
@@ -2458,9 +2462,7 @@ var generateQueryImplementation = ({
|
|
|
2458
2462
|
hasSignal
|
|
2459
2463
|
});
|
|
2460
2464
|
const queryOptionFnReturnType = getQueryOptionsDefinition({
|
|
2461
|
-
operationName,
|
|
2462
2465
|
definitions: "",
|
|
2463
|
-
mutator,
|
|
2464
2466
|
type,
|
|
2465
2467
|
hasSvelteQueryV4,
|
|
2466
2468
|
hasQueryV5,
|
|
@@ -2502,7 +2504,7 @@ ${hookOptions}
|
|
|
2502
2504
|
|
|
2503
2505
|
${queryOptionsMutator ? `const customOptions = ${queryOptionsMutator.name}({...queryOptions, queryKey, queryFn}${queryOptionsMutator.hasSecondArg ? `, { ${queryProperties} }` : ""}${queryOptionsMutator.hasThirdArg ? `, { url: \`${route}\` }` : ""});` : ""}
|
|
2504
2506
|
|
|
2505
|
-
return ${!queryOptionsMutator ? `{ queryKey, queryFn, ${queryOptionsImp}}` : "customOptions"} as ${queryOptionFnReturnType} ${isVue(outputClient) ? "" :
|
|
2507
|
+
return ${!queryOptionsMutator ? `{ queryKey, queryFn, ${queryOptionsImp}}` : "customOptions"} as ${queryOptionFnReturnType} ${isVue(outputClient) ? "" : `& { queryKey: ${hasQueryV5 ? "DataTag<QueryKey, TData>" : "QueryKey"} }`}
|
|
2506
2508
|
}`;
|
|
2507
2509
|
const operationPrefix = hasSvelteQueryV4 ? "create" : "use";
|
|
2508
2510
|
const queryHookName = (0, import_core3.camel)(`${operationPrefix}-${name}`);
|
|
@@ -2536,7 +2538,7 @@ export function ${queryHookName}<TData = ${TData}, TError = ${errorType}>(
|
|
|
2536
2538
|
`${operationPrefix}-${type}`
|
|
2537
2539
|
)}(${queryOptionsVarName}) as ${returnType};
|
|
2538
2540
|
|
|
2539
|
-
${queryResultVarName}.queryKey = ${isVue(outputClient) ? `unref(${queryOptionsVarName})` : queryOptionsVarName}.queryKey ${isVue(outputClient) ?
|
|
2541
|
+
${queryResultVarName}.queryKey = ${isVue(outputClient) ? `unref(${queryOptionsVarName})` : queryOptionsVarName}.queryKey ${isVue(outputClient) ? `as ${hasQueryV5 ? "DataTag<QueryKey, TData>" : "QueryKey"}` : ""};
|
|
2540
2542
|
|
|
2541
2543
|
return ${queryResultVarName};
|
|
2542
2544
|
}
|
|
@@ -2660,7 +2662,7 @@ var generateQueryHook = async ({
|
|
|
2660
2662
|
] : []
|
|
2661
2663
|
];
|
|
2662
2664
|
const queryKeyFnName = (0, import_core3.camel)(`get-${operationName}-queryKey`);
|
|
2663
|
-
|
|
2665
|
+
const queryKeyProps = (0, import_core3.toObjectString)(
|
|
2664
2666
|
props.filter((prop) => prop.type !== import_core3.GetterPropType.HEADER),
|
|
2665
2667
|
"implementation"
|
|
2666
2668
|
);
|
|
@@ -2686,7 +2688,10 @@ var generateQueryHook = async ({
|
|
|
2686
2688
|
outputClient,
|
|
2687
2689
|
httpClient,
|
|
2688
2690
|
isExactOptionalPropertyTypes,
|
|
2689
|
-
hasSignal:
|
|
2691
|
+
hasSignal: getHasSignal({
|
|
2692
|
+
overrideQuerySignal: override.query.signal,
|
|
2693
|
+
verb
|
|
2694
|
+
}),
|
|
2690
2695
|
queryOptionsMutator,
|
|
2691
2696
|
queryKeyMutator,
|
|
2692
2697
|
route,
|
|
@@ -2720,7 +2725,7 @@ var generateQueryHook = async ({
|
|
|
2720
2725
|
({ definition, type }) => type === import_core3.GetterPropType.BODY ? (mutator == null ? void 0 : mutator.bodyTypeName) ? `data: ${mutator.bodyTypeName}<${body.definition}>` : `data: ${body.definition}` : definition
|
|
2721
2726
|
).join(";");
|
|
2722
2727
|
const properties = props.map(({ name, type }) => type === import_core3.GetterPropType.BODY ? "data" : name).join(",");
|
|
2723
|
-
|
|
2728
|
+
const errorType = getQueryErrorType(
|
|
2724
2729
|
operationName,
|
|
2725
2730
|
response,
|
|
2726
2731
|
httpClient,
|
|
@@ -2728,15 +2733,12 @@ var generateQueryHook = async ({
|
|
|
2728
2733
|
);
|
|
2729
2734
|
const dataType = (mutator == null ? void 0 : mutator.isHook) ? `ReturnType<typeof use${(0, import_core3.pascal)(operationName)}Hook>` : `typeof ${operationName}`;
|
|
2730
2735
|
const mutationOptionFnReturnType = getQueryOptionsDefinition({
|
|
2731
|
-
operationName,
|
|
2732
2736
|
definitions,
|
|
2733
|
-
mutator,
|
|
2734
2737
|
hasSvelteQueryV4,
|
|
2735
2738
|
hasQueryV5,
|
|
2736
2739
|
isReturnType: true
|
|
2737
2740
|
});
|
|
2738
2741
|
const mutationArguments = generateQueryArguments({
|
|
2739
|
-
operationName,
|
|
2740
2742
|
definitions,
|
|
2741
2743
|
mutator,
|
|
2742
2744
|
isRequestOptions,
|
|
@@ -2751,10 +2753,12 @@ var generateQueryHook = async ({
|
|
|
2751
2753
|
const hooksOptionImplementation = getHooksOptionImplementation(
|
|
2752
2754
|
isRequestOptions,
|
|
2753
2755
|
httpClient,
|
|
2756
|
+
(0, import_core3.camel)(operationName),
|
|
2754
2757
|
mutator
|
|
2755
2758
|
);
|
|
2756
|
-
const
|
|
2757
|
-
|
|
2759
|
+
const TData = `Awaited<ReturnType<${(mutator == null ? void 0 : mutator.isHook) ? `ReturnType<typeof use${(0, import_core3.pascal)(operationName)}Hook>` : `typeof ${operationName}`}>>`;
|
|
2760
|
+
const mutationOptionsFn = `export const ${mutationOptionsFnName} = <TData = ${TData}, TError = ${errorType},
|
|
2761
|
+
TContext = unknown>(${mutationArguments}) => {
|
|
2758
2762
|
${hooksOptionImplementation}
|
|
2759
2763
|
|
|
2760
2764
|
${(mutator == null ? void 0 : mutator.isHook) ? `const ${operationName} = use${(0, import_core3.pascal)(operationName)}Hook()` : ""}
|
|
@@ -2769,7 +2773,7 @@ ${hooksOptionImplementation}
|
|
|
2769
2773
|
${mutationOptionsMutator ? `const customOptions = ${mutationOptionsMutator.name}({...mutationOptions, mutationFn}${mutationOptionsMutator.hasThirdArg ? `, { url: \`${route}\` }` : ""});` : ""}
|
|
2770
2774
|
|
|
2771
2775
|
|
|
2772
|
-
return ${!mutationOptionsMutator ? "{ mutationFn, ...mutationOptions }" : "customOptions"}}`;
|
|
2776
|
+
return ${!mutationOptionsMutator ? "{ mutationFn, ...mutationOptions }" : "customOptions"} as ${mutationOptionFnReturnType}}`;
|
|
2773
2777
|
const operationPrefix = hasSvelteQueryV4 ? "create" : "use";
|
|
2774
2778
|
implementation += `
|
|
2775
2779
|
${mutationOptionsFn}
|
|
@@ -2782,10 +2786,9 @@ ${mutationOptionsFn}
|
|
|
2782
2786
|
|
|
2783
2787
|
${doc}export const ${(0, import_core3.camel)(
|
|
2784
2788
|
`${operationPrefix}-${operationName}`
|
|
2785
|
-
)} = <TError = ${errorType},
|
|
2789
|
+
)} = <TData = ${TData}, TError = ${errorType},
|
|
2786
2790
|
TContext = unknown>(${mutationArguments})${generateMutatorReturnType({
|
|
2787
2791
|
outputClient,
|
|
2788
|
-
dataType,
|
|
2789
2792
|
variableType: definitions ? `{${definitions}}` : "void"
|
|
2790
2793
|
})} => {
|
|
2791
2794
|
|