@orval/query 6.31.0 → 7.0.1
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/README.md +9 -9
- package/dist/index.js +455 -308
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
package/dist/index.js
CHANGED
|
@@ -30,9 +30,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
30
30
|
));
|
|
31
31
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
32
32
|
|
|
33
|
-
// ../../node_modules/chalk/node_modules/color-name/index.js
|
|
33
|
+
// ../../node_modules/chalk/node_modules/ansi-styles/node_modules/color-convert/node_modules/color-name/index.js
|
|
34
34
|
var require_color_name = __commonJS({
|
|
35
|
-
"../../node_modules/chalk/node_modules/color-name/index.js"(exports2, module2) {
|
|
35
|
+
"../../node_modules/chalk/node_modules/ansi-styles/node_modules/color-convert/node_modules/color-name/index.js"(exports2, module2) {
|
|
36
36
|
"use strict";
|
|
37
37
|
module2.exports = {
|
|
38
38
|
"aliceblue": [240, 248, 255],
|
|
@@ -187,9 +187,9 @@ var require_color_name = __commonJS({
|
|
|
187
187
|
}
|
|
188
188
|
});
|
|
189
189
|
|
|
190
|
-
// ../../node_modules/chalk/node_modules/color-convert/conversions.js
|
|
190
|
+
// ../../node_modules/chalk/node_modules/ansi-styles/node_modules/color-convert/conversions.js
|
|
191
191
|
var require_conversions = __commonJS({
|
|
192
|
-
"../../node_modules/chalk/node_modules/color-convert/conversions.js"(exports2, module2) {
|
|
192
|
+
"../../node_modules/chalk/node_modules/ansi-styles/node_modules/color-convert/conversions.js"(exports2, module2) {
|
|
193
193
|
"use strict";
|
|
194
194
|
var cssKeywords = require_color_name();
|
|
195
195
|
var reverseKeywords = {};
|
|
@@ -859,9 +859,9 @@ var require_conversions = __commonJS({
|
|
|
859
859
|
}
|
|
860
860
|
});
|
|
861
861
|
|
|
862
|
-
// ../../node_modules/chalk/node_modules/color-convert/route.js
|
|
862
|
+
// ../../node_modules/chalk/node_modules/ansi-styles/node_modules/color-convert/route.js
|
|
863
863
|
var require_route = __commonJS({
|
|
864
|
-
"../../node_modules/chalk/node_modules/color-convert/route.js"(exports2, module2) {
|
|
864
|
+
"../../node_modules/chalk/node_modules/ansi-styles/node_modules/color-convert/route.js"(exports2, module2) {
|
|
865
865
|
"use strict";
|
|
866
866
|
var conversions = require_conversions();
|
|
867
867
|
function buildGraph() {
|
|
@@ -930,9 +930,9 @@ var require_route = __commonJS({
|
|
|
930
930
|
}
|
|
931
931
|
});
|
|
932
932
|
|
|
933
|
-
// ../../node_modules/chalk/node_modules/color-convert/index.js
|
|
933
|
+
// ../../node_modules/chalk/node_modules/ansi-styles/node_modules/color-convert/index.js
|
|
934
934
|
var require_color_convert = __commonJS({
|
|
935
|
-
"../../node_modules/chalk/node_modules/color-convert/index.js"(exports2, module2) {
|
|
935
|
+
"../../node_modules/chalk/node_modules/ansi-styles/node_modules/color-convert/index.js"(exports2, module2) {
|
|
936
936
|
"use strict";
|
|
937
937
|
var conversions = require_conversions();
|
|
938
938
|
var route = require_route();
|
|
@@ -1592,9 +1592,13 @@ __export(src_exports, {
|
|
|
1592
1592
|
getVueQueryDependencies: () => getVueQueryDependencies
|
|
1593
1593
|
});
|
|
1594
1594
|
module.exports = __toCommonJS(src_exports);
|
|
1595
|
-
var
|
|
1595
|
+
var import_core3 = require("@orval/core");
|
|
1596
1596
|
var import_lodash = __toESM(require("lodash.omitby"));
|
|
1597
1597
|
|
|
1598
|
+
// src/client.ts
|
|
1599
|
+
var import_core2 = require("@orval/core");
|
|
1600
|
+
var import_fetch = require("@orval/fetch");
|
|
1601
|
+
|
|
1598
1602
|
// src/utils.ts
|
|
1599
1603
|
var import_core = require("@orval/core");
|
|
1600
1604
|
var import_chalk = __toESM(require_source());
|
|
@@ -1650,8 +1654,7 @@ var normalizeMutator = (workspace, mutator) => {
|
|
|
1650
1654
|
function vueWrapTypeWithMaybeRef(props) {
|
|
1651
1655
|
return props.map((prop) => {
|
|
1652
1656
|
const [paramName, paramType] = prop.implementation.split(":");
|
|
1653
|
-
if (!paramType)
|
|
1654
|
-
return prop;
|
|
1657
|
+
if (!paramType) return prop;
|
|
1655
1658
|
const name = prop.type === import_core.GetterPropType.NAMED_PATH_PARAMS ? prop.name : `${paramName}`;
|
|
1656
1659
|
const [type, defaultValue] = paramType.split("=");
|
|
1657
1660
|
return {
|
|
@@ -1672,18 +1675,7 @@ var wrapRouteParameters = (route, prepend, append) => route.replaceAll(import_co
|
|
|
1672
1675
|
var makeRouteSafe = (route) => wrapRouteParameters(route, "encodeURIComponent(String(", "))");
|
|
1673
1676
|
var isVue = (client) => import_core.OutputClient.VUE_QUERY === client;
|
|
1674
1677
|
|
|
1675
|
-
// src/
|
|
1676
|
-
var REACT_DEPENDENCIES = [
|
|
1677
|
-
{
|
|
1678
|
-
exports: [
|
|
1679
|
-
{
|
|
1680
|
-
name: "useCallback",
|
|
1681
|
-
values: true
|
|
1682
|
-
}
|
|
1683
|
-
],
|
|
1684
|
-
dependency: "react"
|
|
1685
|
-
}
|
|
1686
|
-
];
|
|
1678
|
+
// src/client.ts
|
|
1687
1679
|
var AXIOS_DEPENDENCIES = [
|
|
1688
1680
|
{
|
|
1689
1681
|
exports: [
|
|
@@ -1700,6 +1692,230 @@ var AXIOS_DEPENDENCIES = [
|
|
|
1700
1692
|
dependency: "axios"
|
|
1701
1693
|
}
|
|
1702
1694
|
];
|
|
1695
|
+
var generateQueryRequestFunction = (verbOptions, options, isVue3) => {
|
|
1696
|
+
if (options.context.output.httpClient === import_core2.OutputHttpClient.AXIOS) {
|
|
1697
|
+
return generateAxiosRequestFunction(verbOptions, options, isVue3);
|
|
1698
|
+
} else {
|
|
1699
|
+
return (0, import_fetch.generateRequestFunction)(verbOptions, options);
|
|
1700
|
+
}
|
|
1701
|
+
};
|
|
1702
|
+
var generateAxiosRequestFunction = ({
|
|
1703
|
+
headers,
|
|
1704
|
+
queryParams,
|
|
1705
|
+
operationName,
|
|
1706
|
+
response,
|
|
1707
|
+
mutator,
|
|
1708
|
+
body,
|
|
1709
|
+
props: _props,
|
|
1710
|
+
verb,
|
|
1711
|
+
formData,
|
|
1712
|
+
formUrlEncoded,
|
|
1713
|
+
override,
|
|
1714
|
+
paramsSerializer
|
|
1715
|
+
}, { route: _route, context }, isVue3) => {
|
|
1716
|
+
var _a, _b, _c;
|
|
1717
|
+
let props = _props;
|
|
1718
|
+
let route = _route;
|
|
1719
|
+
if (isVue3) {
|
|
1720
|
+
props = vueWrapTypeWithMaybeRef(_props);
|
|
1721
|
+
}
|
|
1722
|
+
if ((_a = context.output) == null ? void 0 : _a.urlEncodeParameters) {
|
|
1723
|
+
route = makeRouteSafe(route);
|
|
1724
|
+
}
|
|
1725
|
+
const isRequestOptions = override.requestOptions !== false;
|
|
1726
|
+
const isFormData = override.formData !== false;
|
|
1727
|
+
const isFormUrlEncoded = override.formUrlEncoded !== false;
|
|
1728
|
+
const hasSignal = !!override.query.signal;
|
|
1729
|
+
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
|
+
const bodyForm = (0, import_core2.generateFormDataAndUrlEncodedFunction)({
|
|
1732
|
+
formData,
|
|
1733
|
+
formUrlEncoded,
|
|
1734
|
+
body,
|
|
1735
|
+
isFormData,
|
|
1736
|
+
isFormUrlEncoded
|
|
1737
|
+
});
|
|
1738
|
+
if (mutator) {
|
|
1739
|
+
const mutatorConfig = (0, import_core2.generateMutatorConfig)({
|
|
1740
|
+
route,
|
|
1741
|
+
body,
|
|
1742
|
+
headers,
|
|
1743
|
+
queryParams,
|
|
1744
|
+
response,
|
|
1745
|
+
verb,
|
|
1746
|
+
isFormData,
|
|
1747
|
+
isFormUrlEncoded,
|
|
1748
|
+
isBodyVerb,
|
|
1749
|
+
hasSignal,
|
|
1750
|
+
isExactOptionalPropertyTypes,
|
|
1751
|
+
isVue: isVue3
|
|
1752
|
+
});
|
|
1753
|
+
let bodyDefinition = body.definition.replace("[]", "\\[\\]");
|
|
1754
|
+
let propsImplementation = (mutator == null ? void 0 : mutator.bodyTypeName) && body.definition ? (0, import_core2.toObjectString)(props, "implementation").replace(
|
|
1755
|
+
new RegExp(`(\\w*):\\s?${bodyDefinition}`),
|
|
1756
|
+
`$1: ${mutator.bodyTypeName}<${body.definition}>`
|
|
1757
|
+
) : (0, import_core2.toObjectString)(props, "implementation");
|
|
1758
|
+
const requestOptions = isRequestOptions ? (0, import_core2.generateMutatorRequestOptions)(
|
|
1759
|
+
override.requestOptions,
|
|
1760
|
+
mutator.hasSecondArg
|
|
1761
|
+
) : "";
|
|
1762
|
+
if (mutator.isHook) {
|
|
1763
|
+
return `${override.query.shouldExportMutatorHooks ? "export " : ""}const use${(0, import_core2.pascal)(operationName)}Hook = () => {
|
|
1764
|
+
const ${operationName} = ${mutator.name}<${response.definition.success || "unknown"}>();
|
|
1765
|
+
|
|
1766
|
+
return useCallback((
|
|
1767
|
+
${propsImplementation}
|
|
1768
|
+
${isRequestOptions && mutator.hasSecondArg ? `options${context.output.optionsParamRequired ? "" : "?"}: SecondParameter<ReturnType<typeof ${mutator.name}>>,` : ""}${!isBodyVerb && hasSignal ? "signal?: AbortSignal\n" : ""}) => {${bodyForm}
|
|
1769
|
+
return ${operationName}(
|
|
1770
|
+
${mutatorConfig},
|
|
1771
|
+
${requestOptions});
|
|
1772
|
+
}, [${operationName}])
|
|
1773
|
+
}
|
|
1774
|
+
`;
|
|
1775
|
+
}
|
|
1776
|
+
return `${override.query.shouldExportHttpClient ? "export " : ""}const ${operationName} = (
|
|
1777
|
+
${propsImplementation}
|
|
1778
|
+
${isRequestOptions && mutator.hasSecondArg ? `options${context.output.optionsParamRequired ? "" : "?"}: SecondParameter<typeof ${mutator.name}>,` : ""}${!isBodyVerb && hasSignal ? "signal?: AbortSignal\n" : ""}) => {
|
|
1779
|
+
${isVue3 ? vueUnRefParams(props) : ""}
|
|
1780
|
+
${bodyForm}
|
|
1781
|
+
return ${mutator.name}<${response.definition.success || "unknown"}>(
|
|
1782
|
+
${mutatorConfig},
|
|
1783
|
+
${requestOptions});
|
|
1784
|
+
}
|
|
1785
|
+
`;
|
|
1786
|
+
}
|
|
1787
|
+
const isSyntheticDefaultImportsAllowed = (0, import_core2.isSyntheticDefaultImportsAllow)(
|
|
1788
|
+
context.output.tsconfig
|
|
1789
|
+
);
|
|
1790
|
+
const options = (0, import_core2.generateOptions)({
|
|
1791
|
+
route,
|
|
1792
|
+
body,
|
|
1793
|
+
headers,
|
|
1794
|
+
queryParams,
|
|
1795
|
+
response,
|
|
1796
|
+
verb,
|
|
1797
|
+
requestOptions: override == null ? void 0 : override.requestOptions,
|
|
1798
|
+
isFormData,
|
|
1799
|
+
isFormUrlEncoded,
|
|
1800
|
+
paramsSerializer,
|
|
1801
|
+
paramsSerializerOptions: override == null ? void 0 : override.paramsSerializerOptions,
|
|
1802
|
+
isExactOptionalPropertyTypes,
|
|
1803
|
+
hasSignal,
|
|
1804
|
+
isVue: isVue3
|
|
1805
|
+
});
|
|
1806
|
+
const optionsArgs = generateRequestOptionsArguments({
|
|
1807
|
+
isRequestOptions,
|
|
1808
|
+
hasSignal
|
|
1809
|
+
});
|
|
1810
|
+
const queryProps = (0, import_core2.toObjectString)(props, "implementation");
|
|
1811
|
+
const httpRequestFunctionImplementation = `export const ${operationName} = (
|
|
1812
|
+
${queryProps} ${optionsArgs} ): Promise<AxiosResponse<${response.definition.success || "unknown"}>> => {${bodyForm}
|
|
1813
|
+
${isVue3 ? vueUnRefParams(props) : ""}
|
|
1814
|
+
return axios${!isSyntheticDefaultImportsAllowed ? ".default" : ""}.${verb}(${options});
|
|
1815
|
+
}
|
|
1816
|
+
`;
|
|
1817
|
+
return httpRequestFunctionImplementation;
|
|
1818
|
+
};
|
|
1819
|
+
var generateRequestOptionsArguments = ({
|
|
1820
|
+
isRequestOptions,
|
|
1821
|
+
hasSignal
|
|
1822
|
+
}) => {
|
|
1823
|
+
if (isRequestOptions) {
|
|
1824
|
+
return "options?: AxiosRequestConfig\n";
|
|
1825
|
+
}
|
|
1826
|
+
return hasSignal ? "signal?: AbortSignal\n" : "";
|
|
1827
|
+
};
|
|
1828
|
+
var getQueryArgumentsRequestType = (httpClient, mutator) => {
|
|
1829
|
+
if (!mutator) {
|
|
1830
|
+
return httpClient === import_core2.OutputHttpClient.AXIOS ? `axios?: AxiosRequestConfig` : "fetch?: RequestInit";
|
|
1831
|
+
}
|
|
1832
|
+
if (mutator.hasSecondArg && !mutator.isHook) {
|
|
1833
|
+
return `request?: SecondParameter<typeof ${mutator.name}>`;
|
|
1834
|
+
}
|
|
1835
|
+
if (mutator.hasSecondArg && mutator.isHook) {
|
|
1836
|
+
return `request?: SecondParameter<ReturnType<typeof ${mutator.name}>>`;
|
|
1837
|
+
}
|
|
1838
|
+
return "";
|
|
1839
|
+
};
|
|
1840
|
+
var getQueryOptions = ({
|
|
1841
|
+
isRequestOptions,
|
|
1842
|
+
mutator,
|
|
1843
|
+
isExactOptionalPropertyTypes,
|
|
1844
|
+
hasSignal,
|
|
1845
|
+
httpClient
|
|
1846
|
+
}) => {
|
|
1847
|
+
if (!mutator && isRequestOptions) {
|
|
1848
|
+
const options = httpClient === import_core2.OutputHttpClient.AXIOS ? "axiosOptions" : "fetchOptions";
|
|
1849
|
+
if (!hasSignal) {
|
|
1850
|
+
return options;
|
|
1851
|
+
}
|
|
1852
|
+
return `{ ${isExactOptionalPropertyTypes ? "...(signal ? { signal } : {})" : "signal"}, ...${options} }`;
|
|
1853
|
+
}
|
|
1854
|
+
if ((mutator == null ? void 0 : mutator.hasSecondArg) && isRequestOptions) {
|
|
1855
|
+
if (!hasSignal) {
|
|
1856
|
+
return "requestOptions";
|
|
1857
|
+
}
|
|
1858
|
+
return httpClient === import_core2.OutputHttpClient.AXIOS ? "requestOptions, signal" : "{ signal, ...requestOptions }";
|
|
1859
|
+
}
|
|
1860
|
+
if (hasSignal) {
|
|
1861
|
+
return "signal";
|
|
1862
|
+
}
|
|
1863
|
+
return "";
|
|
1864
|
+
};
|
|
1865
|
+
var getHookOptions = ({
|
|
1866
|
+
isRequestOptions,
|
|
1867
|
+
httpClient,
|
|
1868
|
+
mutator
|
|
1869
|
+
}) => {
|
|
1870
|
+
if (!isRequestOptions) {
|
|
1871
|
+
return "";
|
|
1872
|
+
}
|
|
1873
|
+
let value = "const {query: queryOptions";
|
|
1874
|
+
if (!mutator) {
|
|
1875
|
+
const options = httpClient === import_core2.OutputHttpClient.AXIOS ? ", axios: axiosOptions" : ", fetch: fetchOptions";
|
|
1876
|
+
value += options;
|
|
1877
|
+
}
|
|
1878
|
+
if (mutator == null ? void 0 : mutator.hasSecondArg) {
|
|
1879
|
+
value += ", request: requestOptions";
|
|
1880
|
+
}
|
|
1881
|
+
value += "} = options ?? {};";
|
|
1882
|
+
return value;
|
|
1883
|
+
};
|
|
1884
|
+
var getQueryErrorType = (operationName, response, httpClient, mutator) => {
|
|
1885
|
+
if (mutator) {
|
|
1886
|
+
return mutator.hasErrorType ? `${mutator.default ? (0, import_core2.pascal)(operationName) : ""}ErrorType<${response.definition.errors || "unknown"}>` : response.definition.errors || "unknown";
|
|
1887
|
+
} else {
|
|
1888
|
+
const errorType = httpClient === import_core2.OutputHttpClient.AXIOS ? "AxiosError" : "Promise";
|
|
1889
|
+
return `${errorType}<${response.definition.errors || "unknown"}>`;
|
|
1890
|
+
}
|
|
1891
|
+
};
|
|
1892
|
+
var getHooksOptionImplementation = (isRequestOptions, httpClient, mutator) => {
|
|
1893
|
+
const options = httpClient === import_core2.OutputHttpClient.AXIOS ? ", axios: axiosOptions" : ", fetch: fetchOptions";
|
|
1894
|
+
return isRequestOptions ? `const {mutation: mutationOptions${!mutator ? options : (mutator == null ? void 0 : mutator.hasSecondArg) ? ", request: requestOptions" : ""}} = options ?? {};` : "";
|
|
1895
|
+
};
|
|
1896
|
+
var getMutationRequestArgs = (isRequestOptions, httpClient, mutator) => {
|
|
1897
|
+
const options = httpClient === import_core2.OutputHttpClient.AXIOS ? "axiosOptions" : "fetchOptions";
|
|
1898
|
+
return isRequestOptions ? !mutator ? options : (mutator == null ? void 0 : mutator.hasSecondArg) ? "requestOptions" : "" : "";
|
|
1899
|
+
};
|
|
1900
|
+
var getHttpFunctionQueryProps = (isVue3, httpClient, queryProperties) => {
|
|
1901
|
+
if (isVue3 && httpClient === import_core2.OutputHttpClient.FETCH && queryProperties) {
|
|
1902
|
+
return `unref(${queryProperties})`;
|
|
1903
|
+
}
|
|
1904
|
+
return queryProperties;
|
|
1905
|
+
};
|
|
1906
|
+
|
|
1907
|
+
// src/index.ts
|
|
1908
|
+
var REACT_DEPENDENCIES = [
|
|
1909
|
+
{
|
|
1910
|
+
exports: [
|
|
1911
|
+
{
|
|
1912
|
+
name: "useCallback",
|
|
1913
|
+
values: true
|
|
1914
|
+
}
|
|
1915
|
+
],
|
|
1916
|
+
dependency: "react"
|
|
1917
|
+
}
|
|
1918
|
+
];
|
|
1703
1919
|
var PARAMS_SERIALIZER_DEPENDENCIES = [
|
|
1704
1920
|
{
|
|
1705
1921
|
exports: [
|
|
@@ -1757,15 +1973,15 @@ var SVELTE_QUERY_DEPENDENCIES = [
|
|
|
1757
1973
|
}
|
|
1758
1974
|
];
|
|
1759
1975
|
var isSvelteQueryV3 = (packageJson) => {
|
|
1760
|
-
var _a, _b, _c, _d, _e, _f;
|
|
1761
|
-
const
|
|
1762
|
-
const
|
|
1763
|
-
return !!
|
|
1976
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
1977
|
+
const hasSvelteQuery = (_e = (_c = (_a = packageJson == null ? void 0 : packageJson.dependencies) == null ? void 0 : _a["@sveltestack/svelte-query"]) != null ? _c : (_b = packageJson == null ? void 0 : packageJson.devDependencies) == null ? void 0 : _b["@sveltestack/svelte-query"]) != null ? _e : (_d = packageJson == null ? void 0 : packageJson.peerDependencies) == null ? void 0 : _d["@sveltestack/svelte-query"];
|
|
1978
|
+
const hasSvelteQueryV4 = (_j = (_h = (_f = packageJson == null ? void 0 : packageJson.dependencies) == null ? void 0 : _f["@tanstack/svelte-query"]) != null ? _h : (_g = packageJson == null ? void 0 : packageJson.devDependencies) == null ? void 0 : _g["@tanstack/svelte-query"]) != null ? _j : (_i = packageJson == null ? void 0 : packageJson.peerDependencies) == null ? void 0 : _i["@tanstack/svelte-query"];
|
|
1979
|
+
return !!hasSvelteQuery && !hasSvelteQueryV4;
|
|
1764
1980
|
};
|
|
1765
|
-
var getSvelteQueryDependencies = (hasGlobalMutator, hasParamsSerializerOptions, packageJson) => {
|
|
1981
|
+
var getSvelteQueryDependencies = (hasGlobalMutator, hasParamsSerializerOptions, packageJson, httpClient) => {
|
|
1766
1982
|
const hasSvelteQueryV3 = isSvelteQueryV3(packageJson);
|
|
1767
1983
|
return [
|
|
1768
|
-
...!hasGlobalMutator ? AXIOS_DEPENDENCIES : [],
|
|
1984
|
+
...!hasGlobalMutator && httpClient === import_core3.OutputHttpClient.AXIOS ? AXIOS_DEPENDENCIES : [],
|
|
1769
1985
|
...hasParamsSerializerOptions ? PARAMS_SERIALIZER_DEPENDENCIES : [],
|
|
1770
1986
|
...hasSvelteQueryV3 ? SVELTE_QUERY_DEPENDENCIES_V3 : SVELTE_QUERY_DEPENDENCIES
|
|
1771
1987
|
];
|
|
@@ -1799,6 +2015,8 @@ var REACT_QUERY_DEPENDENCIES = [
|
|
|
1799
2015
|
{ name: "useSuspenseInfiniteQuery", values: true },
|
|
1800
2016
|
{ name: "useMutation", values: true },
|
|
1801
2017
|
{ name: "UseQueryOptions" },
|
|
2018
|
+
{ name: "DefinedInitialDataOptions" },
|
|
2019
|
+
{ name: "UndefinedInitialDataOptions" },
|
|
1802
2020
|
{ name: "UseSuspenseQueryOptions" },
|
|
1803
2021
|
{ name: "UseInfiniteQueryOptions" },
|
|
1804
2022
|
{ name: "UseSuspenseInfiniteQueryOptions" },
|
|
@@ -1806,8 +2024,10 @@ var REACT_QUERY_DEPENDENCIES = [
|
|
|
1806
2024
|
{ name: "QueryFunction" },
|
|
1807
2025
|
{ name: "MutationFunction" },
|
|
1808
2026
|
{ name: "UseQueryResult" },
|
|
2027
|
+
{ name: "DefinedUseQueryResult" },
|
|
1809
2028
|
{ name: "UseSuspenseQueryResult" },
|
|
1810
2029
|
{ name: "UseInfiniteQueryResult" },
|
|
2030
|
+
{ name: "DefinedUseInfiniteQueryResult" },
|
|
1811
2031
|
{ name: "UseSuspenseInfiniteQueryResult" },
|
|
1812
2032
|
{ name: "QueryKey" },
|
|
1813
2033
|
{ name: "QueryClient" },
|
|
@@ -1817,13 +2037,13 @@ var REACT_QUERY_DEPENDENCIES = [
|
|
|
1817
2037
|
dependency: "@tanstack/react-query"
|
|
1818
2038
|
}
|
|
1819
2039
|
];
|
|
1820
|
-
var getReactQueryDependencies = (hasGlobalMutator, hasParamsSerializerOptions, packageJson) => {
|
|
1821
|
-
var _a, _b, _c, _d, _e, _f;
|
|
1822
|
-
const hasReactQuery = (_c = (_a = packageJson == null ? void 0 : packageJson.dependencies) == null ? void 0 : _a["react-query"]) != null ? _c : (_b = packageJson == null ? void 0 : packageJson.devDependencies) == null ? void 0 : _b["react-query"];
|
|
1823
|
-
const hasReactQueryV4 = (
|
|
2040
|
+
var getReactQueryDependencies = (hasGlobalMutator, hasParamsSerializerOptions, packageJson, httpClient) => {
|
|
2041
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
2042
|
+
const hasReactQuery = (_e = (_c = (_a = packageJson == null ? void 0 : packageJson.dependencies) == null ? void 0 : _a["react-query"]) != null ? _c : (_b = packageJson == null ? void 0 : packageJson.devDependencies) == null ? void 0 : _b["react-query"]) != null ? _e : (_d = packageJson == null ? void 0 : packageJson.peerDependencies) == null ? void 0 : _d["react-query"];
|
|
2043
|
+
const hasReactQueryV4 = (_j = (_h = (_f = packageJson == null ? void 0 : packageJson.dependencies) == null ? void 0 : _f["@tanstack/react-query"]) != null ? _h : (_g = packageJson == null ? void 0 : packageJson.devDependencies) == null ? void 0 : _g["@tanstack/react-query"]) != null ? _j : (_i = packageJson == null ? void 0 : packageJson.peerDependencies) == null ? void 0 : _i["@tanstack/react-query"];
|
|
1824
2044
|
return [
|
|
1825
2045
|
...hasGlobalMutator ? REACT_DEPENDENCIES : [],
|
|
1826
|
-
...!hasGlobalMutator ? AXIOS_DEPENDENCIES : [],
|
|
2046
|
+
...!hasGlobalMutator && httpClient === import_core3.OutputHttpClient.AXIOS ? AXIOS_DEPENDENCIES : [],
|
|
1827
2047
|
...hasParamsSerializerOptions ? PARAMS_SERIALIZER_DEPENDENCIES : [],
|
|
1828
2048
|
...hasReactQuery && !hasReactQueryV4 ? REACT_QUERY_DEPENDENCIES_V3 : REACT_QUERY_DEPENDENCIES
|
|
1829
2049
|
];
|
|
@@ -1892,15 +2112,15 @@ var VUE_QUERY_DEPENDENCIES = [
|
|
|
1892
2112
|
}
|
|
1893
2113
|
];
|
|
1894
2114
|
var isVueQueryV3 = (packageJson) => {
|
|
1895
|
-
var _a, _b, _c, _d, _e, _f;
|
|
1896
|
-
const hasVueQuery = (_c = (_a = packageJson == null ? void 0 : packageJson.dependencies) == null ? void 0 : _a["vue-query"]) != null ? _c : (_b = packageJson == null ? void 0 : packageJson.devDependencies) == null ? void 0 : _b["vue-query"];
|
|
1897
|
-
const hasVueQueryV4 = (
|
|
2115
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
2116
|
+
const hasVueQuery = (_e = (_c = (_a = packageJson == null ? void 0 : packageJson.dependencies) == null ? void 0 : _a["vue-query"]) != null ? _c : (_b = packageJson == null ? void 0 : packageJson.devDependencies) == null ? void 0 : _b["vue-query"]) != null ? _e : (_d = packageJson == null ? void 0 : packageJson.peerDependencies) == null ? void 0 : _d["vue-query"];
|
|
2117
|
+
const hasVueQueryV4 = (_j = (_h = (_f = packageJson == null ? void 0 : packageJson.dependencies) == null ? void 0 : _f["@tanstack/vue-query"]) != null ? _h : (_g = packageJson == null ? void 0 : packageJson.devDependencies) == null ? void 0 : _g["@tanstack/vue-query"]) != null ? _j : (_i = packageJson == null ? void 0 : packageJson.peerDependencies) == null ? void 0 : _i["@tanstack/vue-query"];
|
|
1898
2118
|
return !!hasVueQuery && !hasVueQueryV4;
|
|
1899
2119
|
};
|
|
1900
|
-
var getVueQueryDependencies = (hasGlobalMutator, hasParamsSerializerOptions, packageJson) => {
|
|
2120
|
+
var getVueQueryDependencies = (hasGlobalMutator, hasParamsSerializerOptions, packageJson, httpClient) => {
|
|
1901
2121
|
const hasVueQueryV3 = isVueQueryV3(packageJson);
|
|
1902
2122
|
return [
|
|
1903
|
-
...!hasGlobalMutator ? AXIOS_DEPENDENCIES : [],
|
|
2123
|
+
...!hasGlobalMutator && httpClient === import_core3.OutputHttpClient.AXIOS ? AXIOS_DEPENDENCIES : [],
|
|
1904
2124
|
...hasParamsSerializerOptions ? PARAMS_SERIALIZER_DEPENDENCIES : [],
|
|
1905
2125
|
...hasVueQueryV3 ? VUE_QUERY_DEPENDENCIES_V3 : VUE_QUERY_DEPENDENCIES
|
|
1906
2126
|
];
|
|
@@ -1911,146 +2131,21 @@ var isQueryV5 = (packageJson, queryClient) => {
|
|
|
1911
2131
|
return false;
|
|
1912
2132
|
}
|
|
1913
2133
|
const withoutRc = version.split("-")[0];
|
|
1914
|
-
return (0,
|
|
2134
|
+
return (0, import_core3.compareVersions)(withoutRc, "5.0.0");
|
|
1915
2135
|
};
|
|
1916
2136
|
var getPackageByQueryClient = (packageJson, queryClient) => {
|
|
1917
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
2137
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
1918
2138
|
switch (queryClient) {
|
|
1919
2139
|
case "react-query": {
|
|
1920
|
-
return (_c = (_a = packageJson == null ? void 0 : packageJson.dependencies) == null ? void 0 : _a["@tanstack/react-query"]) != null ? _c : (_b = packageJson == null ? void 0 : packageJson.devDependencies) == null ? void 0 : _b["@tanstack/react-query"];
|
|
2140
|
+
return (_e = (_c = (_a = packageJson == null ? void 0 : packageJson.dependencies) == null ? void 0 : _a["@tanstack/react-query"]) != null ? _c : (_b = packageJson == null ? void 0 : packageJson.devDependencies) == null ? void 0 : _b["@tanstack/react-query"]) != null ? _e : (_d = packageJson == null ? void 0 : packageJson.peerDependencies) == null ? void 0 : _d["@tanstack/react-query"];
|
|
1921
2141
|
}
|
|
1922
2142
|
case "svelte-query": {
|
|
1923
|
-
return (
|
|
2143
|
+
return (_j = (_h = (_f = packageJson == null ? void 0 : packageJson.dependencies) == null ? void 0 : _f["@tanstack/svelte-query"]) != null ? _h : (_g = packageJson == null ? void 0 : packageJson.devDependencies) == null ? void 0 : _g["@tanstack/svelte-query"]) != null ? _j : (_i = packageJson == null ? void 0 : packageJson.peerDependencies) == null ? void 0 : _i["@tanstack/svelte-query"];
|
|
1924
2144
|
}
|
|
1925
2145
|
case "vue-query": {
|
|
1926
|
-
return (
|
|
1927
|
-
}
|
|
1928
|
-
}
|
|
1929
|
-
};
|
|
1930
|
-
var generateRequestOptionsArguments = ({
|
|
1931
|
-
isRequestOptions,
|
|
1932
|
-
hasSignal
|
|
1933
|
-
}) => {
|
|
1934
|
-
if (isRequestOptions) {
|
|
1935
|
-
return "options?: AxiosRequestConfig\n";
|
|
1936
|
-
}
|
|
1937
|
-
return hasSignal ? "signal?: AbortSignal\n" : "";
|
|
1938
|
-
};
|
|
1939
|
-
var generateQueryRequestFunction = ({
|
|
1940
|
-
headers,
|
|
1941
|
-
queryParams,
|
|
1942
|
-
operationName,
|
|
1943
|
-
response,
|
|
1944
|
-
mutator,
|
|
1945
|
-
body,
|
|
1946
|
-
props: _props,
|
|
1947
|
-
verb,
|
|
1948
|
-
formData,
|
|
1949
|
-
formUrlEncoded,
|
|
1950
|
-
paramsSerializer,
|
|
1951
|
-
override
|
|
1952
|
-
}, { route: _route, context }, outputClient, output) => {
|
|
1953
|
-
var _a, _b;
|
|
1954
|
-
let props = _props;
|
|
1955
|
-
let route = _route;
|
|
1956
|
-
if (isVue(outputClient)) {
|
|
1957
|
-
props = vueWrapTypeWithMaybeRef(_props);
|
|
1958
|
-
}
|
|
1959
|
-
if (output == null ? void 0 : output.urlEncodeParameters) {
|
|
1960
|
-
route = makeRouteSafe(route);
|
|
1961
|
-
}
|
|
1962
|
-
const isRequestOptions = override.requestOptions !== false;
|
|
1963
|
-
const isFormData = override.formData !== false;
|
|
1964
|
-
const isFormUrlEncoded = override.formUrlEncoded !== false;
|
|
1965
|
-
const hasSignal = !!override.query.signal;
|
|
1966
|
-
const isSyntheticDefaultImportsAllowed = (0, import_core2.isSyntheticDefaultImportsAllow)(
|
|
1967
|
-
context.output.tsconfig
|
|
1968
|
-
);
|
|
1969
|
-
const isExactOptionalPropertyTypes = !!((_b = (_a = context.output.tsconfig) == null ? void 0 : _a.compilerOptions) == null ? void 0 : _b.exactOptionalPropertyTypes);
|
|
1970
|
-
const isBodyVerb = import_core2.VERBS_WITH_BODY.includes(verb);
|
|
1971
|
-
const bodyForm = (0, import_core2.generateFormDataAndUrlEncodedFunction)({
|
|
1972
|
-
formData,
|
|
1973
|
-
formUrlEncoded,
|
|
1974
|
-
body,
|
|
1975
|
-
isFormData,
|
|
1976
|
-
isFormUrlEncoded
|
|
1977
|
-
});
|
|
1978
|
-
if (mutator) {
|
|
1979
|
-
const mutatorConfig = (0, import_core2.generateMutatorConfig)({
|
|
1980
|
-
route,
|
|
1981
|
-
body,
|
|
1982
|
-
headers,
|
|
1983
|
-
queryParams,
|
|
1984
|
-
response,
|
|
1985
|
-
verb,
|
|
1986
|
-
isFormData,
|
|
1987
|
-
isFormUrlEncoded,
|
|
1988
|
-
isBodyVerb,
|
|
1989
|
-
hasSignal,
|
|
1990
|
-
isExactOptionalPropertyTypes,
|
|
1991
|
-
isVue: isVue(outputClient)
|
|
1992
|
-
});
|
|
1993
|
-
let bodyDefinition = body.definition.replace("[]", "\\[\\]");
|
|
1994
|
-
let propsImplementation = (mutator == null ? void 0 : mutator.bodyTypeName) && body.definition ? (0, import_core2.toObjectString)(props, "implementation").replace(
|
|
1995
|
-
new RegExp(`(\\w*):\\s?${bodyDefinition}`),
|
|
1996
|
-
`$1: ${mutator.bodyTypeName}<${body.definition}>`
|
|
1997
|
-
) : (0, import_core2.toObjectString)(props, "implementation");
|
|
1998
|
-
const requestOptions = isRequestOptions ? (0, import_core2.generateMutatorRequestOptions)(
|
|
1999
|
-
override.requestOptions,
|
|
2000
|
-
mutator.hasSecondArg
|
|
2001
|
-
) : "";
|
|
2002
|
-
if (mutator.isHook) {
|
|
2003
|
-
return `${override.query.shouldExportMutatorHooks ? "export " : ""}const use${(0, import_core2.pascal)(operationName)}Hook = () => {
|
|
2004
|
-
const ${operationName} = ${mutator.name}<${response.definition.success || "unknown"}>();
|
|
2005
|
-
|
|
2006
|
-
return useCallback((
|
|
2007
|
-
${propsImplementation}
|
|
2008
|
-
${isRequestOptions && mutator.hasSecondArg ? `options${context.output.optionsParamRequired ? "" : "?"}: SecondParameter<ReturnType<typeof ${mutator.name}>>,` : ""}${!isBodyVerb && hasSignal ? "signal?: AbortSignal\n" : ""}) => {${bodyForm}
|
|
2009
|
-
return ${operationName}(
|
|
2010
|
-
${mutatorConfig},
|
|
2011
|
-
${requestOptions});
|
|
2012
|
-
}, [${operationName}])
|
|
2013
|
-
}
|
|
2014
|
-
`;
|
|
2146
|
+
return (_o = (_m = (_k = packageJson == null ? void 0 : packageJson.dependencies) == null ? void 0 : _k["@tanstack/vue-query"]) != null ? _m : (_l = packageJson == null ? void 0 : packageJson.devDependencies) == null ? void 0 : _l["@tanstack/vue-query"]) != null ? _o : (_n = packageJson == null ? void 0 : packageJson.peerDependencies) == null ? void 0 : _n["@tanstack/vue-query"];
|
|
2015
2147
|
}
|
|
2016
|
-
return `${override.query.shouldExportHttpClient ? "export " : ""}const ${operationName} = (
|
|
2017
|
-
${propsImplementation}
|
|
2018
|
-
${isRequestOptions && mutator.hasSecondArg ? `options${context.output.optionsParamRequired ? "" : "?"}: SecondParameter<typeof ${mutator.name}>,` : ""}${!isBodyVerb && hasSignal ? "signal?: AbortSignal\n" : ""}) => {
|
|
2019
|
-
${isVue(outputClient) ? vueUnRefParams(props) : ""}
|
|
2020
|
-
${bodyForm}
|
|
2021
|
-
return ${mutator.name}<${response.definition.success || "unknown"}>(
|
|
2022
|
-
${mutatorConfig},
|
|
2023
|
-
${requestOptions});
|
|
2024
|
-
}
|
|
2025
|
-
`;
|
|
2026
2148
|
}
|
|
2027
|
-
const options = (0, import_core2.generateOptions)({
|
|
2028
|
-
route,
|
|
2029
|
-
body,
|
|
2030
|
-
headers,
|
|
2031
|
-
queryParams,
|
|
2032
|
-
response,
|
|
2033
|
-
verb,
|
|
2034
|
-
requestOptions: override == null ? void 0 : override.requestOptions,
|
|
2035
|
-
isFormData,
|
|
2036
|
-
isFormUrlEncoded,
|
|
2037
|
-
paramsSerializer,
|
|
2038
|
-
paramsSerializerOptions: override == null ? void 0 : override.paramsSerializerOptions,
|
|
2039
|
-
isExactOptionalPropertyTypes,
|
|
2040
|
-
hasSignal,
|
|
2041
|
-
isVue: isVue(outputClient)
|
|
2042
|
-
});
|
|
2043
|
-
const optionsArgs = generateRequestOptionsArguments({
|
|
2044
|
-
isRequestOptions,
|
|
2045
|
-
hasSignal
|
|
2046
|
-
});
|
|
2047
|
-
const queryProps = (0, import_core2.toObjectString)(props, "implementation");
|
|
2048
|
-
return `export const ${operationName} = (
|
|
2049
|
-
${queryProps} ${optionsArgs} ): Promise<AxiosResponse<${response.definition.success || "unknown"}>> => {${bodyForm}
|
|
2050
|
-
${isVue(outputClient) ? vueUnRefParams(props) : ""}
|
|
2051
|
-
return axios${!isSyntheticDefaultImportsAllowed ? ".default" : ""}.${verb}(${options});
|
|
2052
|
-
}
|
|
2053
|
-
`;
|
|
2054
2149
|
};
|
|
2055
2150
|
var QueryType = {
|
|
2056
2151
|
INFINITE: "infiniteQuery",
|
|
@@ -2069,7 +2164,7 @@ var generateQueryOptions = ({
|
|
|
2069
2164
|
if (options === false) {
|
|
2070
2165
|
return "";
|
|
2071
2166
|
}
|
|
2072
|
-
const queryConfig = (0,
|
|
2167
|
+
const queryConfig = (0, import_core3.isObject)(options) ? ` ${(_a = (0, import_core3.stringify)(
|
|
2073
2168
|
(0, import_lodash.default)(
|
|
2074
2169
|
options,
|
|
2075
2170
|
(_, key) => (type !== QueryType.INFINITE || type !== QueryType.SUSPENSE_INFINITE) && INFINITE_QUERY_PROPERTIES.includes(key)
|
|
@@ -2081,19 +2176,10 @@ var generateQueryOptions = ({
|
|
|
2081
2176
|
}
|
|
2082
2177
|
return "...queryOptions";
|
|
2083
2178
|
}
|
|
2084
|
-
return `${!(0,
|
|
2179
|
+
return `${!(0, import_core3.isObject)(options) || !options.hasOwnProperty("enabled") ? isVue(outputClient) ? `enabled: computed(() => !!(${params.map(({ name }) => `unref(${name})`).join(" && ")})),` : `enabled: !!(${params.map(({ name }) => name).join(" && ")}),` : ""}${queryConfig} ...queryOptions`;
|
|
2085
2180
|
};
|
|
2086
|
-
var
|
|
2087
|
-
|
|
2088
|
-
return `axios?: AxiosRequestConfig`;
|
|
2089
|
-
}
|
|
2090
|
-
if (mutator.hasSecondArg && !mutator.isHook) {
|
|
2091
|
-
return `request?: SecondParameter<typeof ${mutator.name}>`;
|
|
2092
|
-
}
|
|
2093
|
-
if (mutator.hasSecondArg && mutator.isHook) {
|
|
2094
|
-
return `request?: SecondParameter<ReturnType<typeof ${mutator.name}>>`;
|
|
2095
|
-
}
|
|
2096
|
-
return "";
|
|
2181
|
+
var isSuspenseQuery = (type) => {
|
|
2182
|
+
return [QueryType.SUSPENSE_INFINITE, QueryType.SUSPENSE_QUERY].includes(type);
|
|
2097
2183
|
};
|
|
2098
2184
|
var getQueryOptionsDefinition = ({
|
|
2099
2185
|
operationName,
|
|
@@ -2104,18 +2190,27 @@ var getQueryOptionsDefinition = ({
|
|
|
2104
2190
|
hasQueryV5,
|
|
2105
2191
|
queryParams,
|
|
2106
2192
|
queryParam,
|
|
2107
|
-
isReturnType
|
|
2193
|
+
isReturnType,
|
|
2194
|
+
initialData
|
|
2108
2195
|
}) => {
|
|
2109
2196
|
const isMutatorHook = mutator == null ? void 0 : mutator.isHook;
|
|
2110
2197
|
const prefix = !hasSvelteQueryV4 ? "Use" : "Create";
|
|
2111
2198
|
const partialOptions = !isReturnType && hasQueryV5;
|
|
2112
2199
|
if (type) {
|
|
2113
|
-
const funcReturnType = `Awaited<ReturnType<${isMutatorHook ? `ReturnType<typeof use${(0,
|
|
2114
|
-
|
|
2200
|
+
const funcReturnType = `Awaited<ReturnType<${isMutatorHook ? `ReturnType<typeof use${(0, import_core3.pascal)(operationName)}Hook>` : `typeof ${operationName}`}>>`;
|
|
2201
|
+
const optionTypeInitialDataPostfix = initialData && !isSuspenseQuery(type) ? ` & Pick<
|
|
2202
|
+
${(0, import_core3.pascal)(initialData)}InitialDataOptions<
|
|
2203
|
+
${funcReturnType},
|
|
2204
|
+
TError,
|
|
2205
|
+
TData${hasQueryV5 && (type === QueryType.INFINITE || type === QueryType.SUSPENSE_INFINITE) && queryParam && queryParams ? `, QueryKey` : ""}
|
|
2206
|
+
> , 'initialData'
|
|
2207
|
+
>` : "";
|
|
2208
|
+
const optionType = `${prefix}${(0, import_core3.pascal)(
|
|
2115
2209
|
type
|
|
2116
|
-
)}Options<${funcReturnType}, TError, TData${hasQueryV5 && (type === QueryType.INFINITE || type === QueryType.SUSPENSE_INFINITE) && queryParam && queryParams ? `, ${funcReturnType}, QueryKey, ${queryParams == null ? void 0 : queryParams.schema.name}['${queryParam}']` : ""}
|
|
2210
|
+
)}Options<${funcReturnType}, TError, TData${hasQueryV5 && (type === QueryType.INFINITE || type === QueryType.SUSPENSE_INFINITE) && queryParam && queryParams ? `, ${funcReturnType}, QueryKey, ${queryParams == null ? void 0 : queryParams.schema.name}['${queryParam}']` : ""}>`;
|
|
2211
|
+
return `${partialOptions ? "Partial<" : ""}${optionType}${partialOptions ? ">" : ""}${optionTypeInitialDataPostfix}`;
|
|
2117
2212
|
}
|
|
2118
|
-
return `${prefix}MutationOptions<Awaited<ReturnType<${isMutatorHook ? `ReturnType<typeof use${(0,
|
|
2213
|
+
return `${prefix}MutationOptions<Awaited<ReturnType<${isMutatorHook ? `ReturnType<typeof use${(0, import_core3.pascal)(operationName)}Hook>` : `typeof ${operationName}`}>>, TError,${definitions ? `{${definitions}}` : "void"}, TContext>`;
|
|
2119
2214
|
};
|
|
2120
2215
|
var generateQueryArguments = ({
|
|
2121
2216
|
operationName,
|
|
@@ -2126,7 +2221,9 @@ var generateQueryArguments = ({
|
|
|
2126
2221
|
hasSvelteQueryV4,
|
|
2127
2222
|
hasQueryV5,
|
|
2128
2223
|
queryParams,
|
|
2129
|
-
queryParam
|
|
2224
|
+
queryParam,
|
|
2225
|
+
initialData,
|
|
2226
|
+
httpClient
|
|
2130
2227
|
}) => {
|
|
2131
2228
|
const definition = getQueryOptionsDefinition({
|
|
2132
2229
|
operationName,
|
|
@@ -2137,13 +2234,15 @@ var generateQueryArguments = ({
|
|
|
2137
2234
|
hasQueryV5,
|
|
2138
2235
|
queryParams,
|
|
2139
2236
|
queryParam,
|
|
2140
|
-
isReturnType: false
|
|
2237
|
+
isReturnType: false,
|
|
2238
|
+
initialData
|
|
2141
2239
|
});
|
|
2142
2240
|
if (!isRequestOptions) {
|
|
2143
2241
|
return `${type ? "queryOptions" : "mutationOptions"}?: ${definition}`;
|
|
2144
2242
|
}
|
|
2145
|
-
const requestType = getQueryArgumentsRequestType(mutator);
|
|
2146
|
-
|
|
2243
|
+
const requestType = getQueryArgumentsRequestType(httpClient, mutator);
|
|
2244
|
+
const isQueryRequired = initialData === "defined";
|
|
2245
|
+
return `options${isQueryRequired ? "" : "?"}: { ${type ? "query" : "mutation"}${isQueryRequired ? "" : "?"}:${definition}, ${requestType}}
|
|
2147
2246
|
`;
|
|
2148
2247
|
};
|
|
2149
2248
|
var generateQueryReturnType = ({
|
|
@@ -2152,20 +2251,21 @@ var generateQueryReturnType = ({
|
|
|
2152
2251
|
isMutatorHook,
|
|
2153
2252
|
operationName,
|
|
2154
2253
|
hasVueQueryV4,
|
|
2155
|
-
hasSvelteQueryV4
|
|
2254
|
+
hasSvelteQueryV4,
|
|
2255
|
+
isInitialDataDefined
|
|
2156
2256
|
}) => {
|
|
2157
2257
|
switch (outputClient) {
|
|
2158
|
-
case
|
|
2258
|
+
case import_core3.OutputClient.SVELTE_QUERY: {
|
|
2159
2259
|
if (!hasSvelteQueryV4) {
|
|
2160
|
-
return `Use${(0,
|
|
2260
|
+
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 }`;
|
|
2161
2261
|
}
|
|
2162
|
-
return `Create${(0,
|
|
2262
|
+
return `Create${(0, import_core3.pascal)(
|
|
2163
2263
|
type
|
|
2164
2264
|
)}Result<TData, TError> & { queryKey: QueryKey }`;
|
|
2165
2265
|
}
|
|
2166
|
-
case
|
|
2266
|
+
case import_core3.OutputClient.VUE_QUERY: {
|
|
2167
2267
|
if (!hasVueQueryV4) {
|
|
2168
|
-
return ` UseQueryReturnType<TData, TError, Use${(0,
|
|
2268
|
+
return ` UseQueryReturnType<TData, TError, Use${(0, import_core3.pascal)(
|
|
2169
2269
|
type
|
|
2170
2270
|
)}Result<TData, TError>> & { queryKey: QueryKey }`;
|
|
2171
2271
|
}
|
|
@@ -2174,9 +2274,9 @@ var generateQueryReturnType = ({
|
|
|
2174
2274
|
}
|
|
2175
2275
|
return `UseInfiniteQueryReturnType<TData, TError> & { queryKey: QueryKey }`;
|
|
2176
2276
|
}
|
|
2177
|
-
case
|
|
2277
|
+
case import_core3.OutputClient.REACT_QUERY:
|
|
2178
2278
|
default: {
|
|
2179
|
-
return ` Use${(0,
|
|
2279
|
+
return ` ${isInitialDataDefined && !isSuspenseQuery(type) ? "Defined" : ""}Use${(0, import_core3.pascal)(
|
|
2180
2280
|
type
|
|
2181
2281
|
)}Result<TData, TError> & { queryKey: QueryKey }`;
|
|
2182
2282
|
}
|
|
@@ -2187,7 +2287,7 @@ var generateMutatorReturnType = ({
|
|
|
2187
2287
|
dataType,
|
|
2188
2288
|
variableType
|
|
2189
2289
|
}) => {
|
|
2190
|
-
if (outputClient ===
|
|
2290
|
+
if (outputClient === import_core3.OutputClient.REACT_QUERY) {
|
|
2191
2291
|
return `: UseMutationResult<
|
|
2192
2292
|
Awaited<ReturnType<${dataType}>>,
|
|
2193
2293
|
TError,
|
|
@@ -2195,7 +2295,7 @@ var generateMutatorReturnType = ({
|
|
|
2195
2295
|
TContext
|
|
2196
2296
|
>`;
|
|
2197
2297
|
}
|
|
2198
|
-
if (outputClient ===
|
|
2298
|
+
if (outputClient === import_core3.OutputClient.SVELTE_QUERY) {
|
|
2199
2299
|
return `: CreateMutationResult<
|
|
2200
2300
|
Awaited<ReturnType<${dataType}>>,
|
|
2201
2301
|
TError,
|
|
@@ -2203,7 +2303,7 @@ var generateMutatorReturnType = ({
|
|
|
2203
2303
|
TContext
|
|
2204
2304
|
>`;
|
|
2205
2305
|
}
|
|
2206
|
-
if (outputClient ===
|
|
2306
|
+
if (outputClient === import_core3.OutputClient.VUE_QUERY) {
|
|
2207
2307
|
return `: UseMutationReturnType<
|
|
2208
2308
|
Awaited<ReturnType<${dataType}>>,
|
|
2209
2309
|
TError,
|
|
@@ -2213,46 +2313,6 @@ var generateMutatorReturnType = ({
|
|
|
2213
2313
|
}
|
|
2214
2314
|
return "";
|
|
2215
2315
|
};
|
|
2216
|
-
var getQueryOptions = ({
|
|
2217
|
-
isRequestOptions,
|
|
2218
|
-
mutator,
|
|
2219
|
-
isExactOptionalPropertyTypes,
|
|
2220
|
-
hasSignal
|
|
2221
|
-
}) => {
|
|
2222
|
-
if (!mutator && isRequestOptions) {
|
|
2223
|
-
if (!hasSignal) {
|
|
2224
|
-
return "axiosOptions";
|
|
2225
|
-
}
|
|
2226
|
-
return `{ ${isExactOptionalPropertyTypes ? "...(signal ? { signal } : {})" : "signal"}, ...axiosOptions }`;
|
|
2227
|
-
}
|
|
2228
|
-
if ((mutator == null ? void 0 : mutator.hasSecondArg) && isRequestOptions) {
|
|
2229
|
-
if (!hasSignal) {
|
|
2230
|
-
return "requestOptions";
|
|
2231
|
-
}
|
|
2232
|
-
return "requestOptions, signal";
|
|
2233
|
-
}
|
|
2234
|
-
if (hasSignal) {
|
|
2235
|
-
return "signal";
|
|
2236
|
-
}
|
|
2237
|
-
return "";
|
|
2238
|
-
};
|
|
2239
|
-
var getHookOptions = ({
|
|
2240
|
-
isRequestOptions,
|
|
2241
|
-
mutator
|
|
2242
|
-
}) => {
|
|
2243
|
-
if (!isRequestOptions) {
|
|
2244
|
-
return "";
|
|
2245
|
-
}
|
|
2246
|
-
let value = "const {query: queryOptions";
|
|
2247
|
-
if (!mutator) {
|
|
2248
|
-
value += ", axios: axiosOptions";
|
|
2249
|
-
}
|
|
2250
|
-
if (mutator == null ? void 0 : mutator.hasSecondArg) {
|
|
2251
|
-
value += ", request: requestOptions";
|
|
2252
|
-
}
|
|
2253
|
-
value += "} = options ?? {};";
|
|
2254
|
-
return value;
|
|
2255
|
-
};
|
|
2256
2316
|
var getQueryFnArguments = ({
|
|
2257
2317
|
hasQueryParam,
|
|
2258
2318
|
hasSignal
|
|
@@ -2283,6 +2343,7 @@ var generateQueryImplementation = ({
|
|
|
2283
2343
|
isRequestOptions,
|
|
2284
2344
|
response,
|
|
2285
2345
|
outputClient,
|
|
2346
|
+
httpClient,
|
|
2286
2347
|
isExactOptionalPropertyTypes,
|
|
2287
2348
|
hasSignal,
|
|
2288
2349
|
route,
|
|
@@ -2292,13 +2353,44 @@ var generateQueryImplementation = ({
|
|
|
2292
2353
|
doc,
|
|
2293
2354
|
usePrefetch
|
|
2294
2355
|
}) => {
|
|
2295
|
-
const
|
|
2356
|
+
const queryPropDefinitions = (0, import_core3.toObjectString)(props, "definition");
|
|
2357
|
+
const definedInitialDataQueryPropsDefinitions = (0, import_core3.toObjectString)(
|
|
2358
|
+
props.map((prop) => {
|
|
2359
|
+
const regex = new RegExp(`^${prop.name}\\s*\\?:`);
|
|
2360
|
+
if (!regex.test(prop.definition)) {
|
|
2361
|
+
return prop;
|
|
2362
|
+
}
|
|
2363
|
+
const definitionWithUndefined = prop.definition.replace(
|
|
2364
|
+
regex,
|
|
2365
|
+
`${prop.name}: undefined | `
|
|
2366
|
+
);
|
|
2367
|
+
return {
|
|
2368
|
+
...prop,
|
|
2369
|
+
definition: definitionWithUndefined
|
|
2370
|
+
};
|
|
2371
|
+
}),
|
|
2372
|
+
"definition"
|
|
2373
|
+
);
|
|
2374
|
+
const queryProps = (0, import_core3.toObjectString)(props, "implementation");
|
|
2296
2375
|
const hasInfiniteQueryParam = queryParam && (queryParams == null ? void 0 : queryParams.schema.name);
|
|
2297
2376
|
const httpFunctionProps = queryParam ? props.map((param) => {
|
|
2298
|
-
if (param.type ===
|
|
2377
|
+
if (param.type === import_core3.GetterPropType.NAMED_PATH_PARAMS && !isVue(outputClient))
|
|
2299
2378
|
return param.destructured;
|
|
2300
2379
|
return param.name === "params" ? `{...${isVue(outputClient) ? `unref(params)` : "params"}, ${queryParam}: pageParam || ${isVue(outputClient) ? `unref(params)?.['${queryParam}']` : `params?.['${queryParam}']`}}` : param.name;
|
|
2301
|
-
}).join(",") :
|
|
2380
|
+
}).join(",") : getHttpFunctionQueryProps(
|
|
2381
|
+
isVue(outputClient),
|
|
2382
|
+
httpClient,
|
|
2383
|
+
queryProperties
|
|
2384
|
+
);
|
|
2385
|
+
const definedInitialDataReturnType = generateQueryReturnType({
|
|
2386
|
+
outputClient,
|
|
2387
|
+
type,
|
|
2388
|
+
isMutatorHook: mutator == null ? void 0 : mutator.isHook,
|
|
2389
|
+
operationName,
|
|
2390
|
+
hasVueQueryV4,
|
|
2391
|
+
hasSvelteQueryV4,
|
|
2392
|
+
isInitialDataDefined: true
|
|
2393
|
+
});
|
|
2302
2394
|
const returnType = generateQueryReturnType({
|
|
2303
2395
|
outputClient,
|
|
2304
2396
|
type,
|
|
@@ -2307,11 +2399,39 @@ var generateQueryImplementation = ({
|
|
|
2307
2399
|
hasVueQueryV4,
|
|
2308
2400
|
hasSvelteQueryV4
|
|
2309
2401
|
});
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2402
|
+
const errorType = getQueryErrorType(
|
|
2403
|
+
operationName,
|
|
2404
|
+
response,
|
|
2405
|
+
httpClient,
|
|
2406
|
+
mutator
|
|
2407
|
+
);
|
|
2408
|
+
const dataType = (mutator == null ? void 0 : mutator.isHook) ? `ReturnType<typeof use${(0, import_core3.pascal)(operationName)}Hook>` : `typeof ${operationName}`;
|
|
2409
|
+
const definedInitialDataQueryArguments = generateQueryArguments({
|
|
2410
|
+
operationName,
|
|
2411
|
+
definitions: "",
|
|
2412
|
+
mutator,
|
|
2413
|
+
isRequestOptions,
|
|
2414
|
+
type,
|
|
2415
|
+
hasSvelteQueryV4,
|
|
2416
|
+
hasQueryV5,
|
|
2417
|
+
queryParams,
|
|
2418
|
+
queryParam,
|
|
2419
|
+
initialData: "defined",
|
|
2420
|
+
httpClient
|
|
2421
|
+
});
|
|
2422
|
+
const undefinedInitialDataQueryArguments = generateQueryArguments({
|
|
2423
|
+
operationName,
|
|
2424
|
+
definitions: "",
|
|
2425
|
+
mutator,
|
|
2426
|
+
isRequestOptions,
|
|
2427
|
+
type,
|
|
2428
|
+
hasSvelteQueryV4,
|
|
2429
|
+
hasQueryV5,
|
|
2430
|
+
queryParams,
|
|
2431
|
+
queryParam,
|
|
2432
|
+
initialData: "undefined",
|
|
2433
|
+
httpClient
|
|
2434
|
+
});
|
|
2315
2435
|
const queryArguments = generateQueryArguments({
|
|
2316
2436
|
operationName,
|
|
2317
2437
|
definitions: "",
|
|
@@ -2321,16 +2441,19 @@ var generateQueryImplementation = ({
|
|
|
2321
2441
|
hasSvelteQueryV4,
|
|
2322
2442
|
hasQueryV5,
|
|
2323
2443
|
queryParams,
|
|
2324
|
-
queryParam
|
|
2444
|
+
queryParam,
|
|
2445
|
+
httpClient
|
|
2325
2446
|
});
|
|
2326
2447
|
const queryOptions = getQueryOptions({
|
|
2327
2448
|
isRequestOptions,
|
|
2328
2449
|
isExactOptionalPropertyTypes,
|
|
2329
2450
|
mutator,
|
|
2330
|
-
hasSignal
|
|
2451
|
+
hasSignal,
|
|
2452
|
+
httpClient
|
|
2331
2453
|
});
|
|
2332
2454
|
const hookOptions = getHookOptions({
|
|
2333
2455
|
isRequestOptions,
|
|
2456
|
+
httpClient,
|
|
2334
2457
|
mutator
|
|
2335
2458
|
});
|
|
2336
2459
|
const queryFnArguments = getQueryFnArguments({
|
|
@@ -2354,7 +2477,7 @@ var generateQueryImplementation = ({
|
|
|
2354
2477
|
type,
|
|
2355
2478
|
outputClient
|
|
2356
2479
|
});
|
|
2357
|
-
const queryOptionsFnName = (0,
|
|
2480
|
+
const queryOptionsFnName = (0, import_core3.camel)(
|
|
2358
2481
|
queryKeyMutator || queryOptionsMutator || (mutator == null ? void 0 : mutator.isHook) ? `use-${name}-queryOptions` : `get-${name}-queryOptions`
|
|
2359
2482
|
);
|
|
2360
2483
|
const queryOptionsVarName = isRequestOptions ? "queryOptions" : "options";
|
|
@@ -2370,13 +2493,13 @@ ${hookOptions}
|
|
|
2370
2493
|
|
|
2371
2494
|
const queryKey = ${!queryKeyMutator ? `${!hasVueQueryV4 ? "queryOptions?.queryKey ?? " : ""}${queryKeyFnName}(${queryKeyProperties});` : `${queryKeyMutator.name}({ ${queryProperties} }${queryKeyMutator.hasSecondArg ? `, { url: \`${route}\`, queryOptions }` : ""});`}
|
|
2372
2495
|
|
|
2373
|
-
${(mutator == null ? void 0 : mutator.isHook) ? `const ${operationName} = use${(0,
|
|
2496
|
+
${(mutator == null ? void 0 : mutator.isHook) ? `const ${operationName} = use${(0, import_core3.pascal)(operationName)}Hook();` : ""}
|
|
2374
2497
|
|
|
2375
|
-
const queryFn: QueryFunction<Awaited<ReturnType<${(mutator == null ? void 0 : mutator.isHook) ? `ReturnType<typeof use${(0,
|
|
2498
|
+
const queryFn: QueryFunction<Awaited<ReturnType<${(mutator == null ? void 0 : mutator.isHook) ? `ReturnType<typeof use${(0, import_core3.pascal)(operationName)}Hook>` : `typeof ${operationName}`}>>${hasQueryV5 && hasInfiniteQueryParam ? `, QueryKey, ${queryParams == null ? void 0 : queryParams.schema.name}['${queryParam}']` : ""}> = (${queryFnArguments}) => ${operationName}(${httpFunctionProps}${httpFunctionProps ? ", " : ""}${queryOptions});
|
|
2376
2499
|
|
|
2377
2500
|
${isVue(outputClient) ? vueUnRefParams(
|
|
2378
2501
|
props.filter(
|
|
2379
|
-
(prop) => prop.type ===
|
|
2502
|
+
(prop) => prop.type === import_core3.GetterPropType.NAMED_PATH_PARAMS
|
|
2380
2503
|
)
|
|
2381
2504
|
) : ""}
|
|
2382
2505
|
|
|
@@ -2385,23 +2508,34 @@ ${hookOptions}
|
|
|
2385
2508
|
return ${!queryOptionsMutator ? `{ queryKey, queryFn, ${queryOptionsImp}}` : "customOptions"} as ${queryOptionFnReturnType} ${isVue(outputClient) ? "" : "& { queryKey: QueryKey }"}
|
|
2386
2509
|
}`;
|
|
2387
2510
|
const operationPrefix = hasSvelteQueryV4 ? "create" : "use";
|
|
2511
|
+
const queryHookName = (0, import_core3.camel)(`${operationPrefix}-${name}`);
|
|
2512
|
+
const overrideTypes = `
|
|
2513
|
+
export function ${queryHookName}<TData = ${TData}, TError = ${errorType}>(
|
|
2514
|
+
${definedInitialDataQueryPropsDefinitions} ${definedInitialDataQueryArguments}
|
|
2515
|
+
): ${definedInitialDataReturnType}
|
|
2516
|
+
export function ${queryHookName}<TData = ${TData}, TError = ${errorType}>(
|
|
2517
|
+
${queryPropDefinitions} ${undefinedInitialDataQueryArguments}
|
|
2518
|
+
): ${returnType}
|
|
2519
|
+
export function ${queryHookName}<TData = ${TData}, TError = ${errorType}>(
|
|
2520
|
+
${queryPropDefinitions} ${queryArguments}
|
|
2521
|
+
): ${returnType}`;
|
|
2388
2522
|
return `
|
|
2389
2523
|
${queryOptionsFn}
|
|
2390
2524
|
|
|
2391
|
-
export type ${(0,
|
|
2525
|
+
export type ${(0, import_core3.pascal)(
|
|
2392
2526
|
name
|
|
2393
2527
|
)}QueryResult = NonNullable<Awaited<ReturnType<${dataType}>>>
|
|
2394
|
-
export type ${(0,
|
|
2528
|
+
export type ${(0, import_core3.pascal)(name)}QueryError = ${errorType}
|
|
2395
2529
|
|
|
2396
|
-
${
|
|
2397
|
-
|
|
2398
|
-
|
|
2530
|
+
${hasQueryV5 && import_core3.OutputClient.REACT_QUERY === outputClient ? overrideTypes : ""}
|
|
2531
|
+
${doc}
|
|
2532
|
+
export function ${queryHookName}<TData = ${TData}, TError = ${errorType}>(
|
|
2399
2533
|
${queryProps} ${queryArguments}
|
|
2400
|
-
): ${returnType}
|
|
2534
|
+
): ${returnType} {
|
|
2401
2535
|
|
|
2402
2536
|
const ${queryOptionsVarName} = ${queryOptionsFnName}(${queryProperties}${queryProperties ? "," : ""}${isRequestOptions ? "options" : "queryOptions"})
|
|
2403
2537
|
|
|
2404
|
-
const ${queryResultVarName} = ${(0,
|
|
2538
|
+
const ${queryResultVarName} = ${(0, import_core3.camel)(
|
|
2405
2539
|
`${operationPrefix}-${type}`
|
|
2406
2540
|
)}(${queryOptionsVarName}) as ${returnType};
|
|
2407
2541
|
|
|
@@ -2410,7 +2544,7 @@ ${doc}export const ${(0, import_core2.camel)(
|
|
|
2410
2544
|
return ${queryResultVarName};
|
|
2411
2545
|
}
|
|
2412
2546
|
|
|
2413
|
-
${usePrefetch && (type === QueryType.QUERY || type === QueryType.INFINITE) ? `${doc}export const ${(0,
|
|
2547
|
+
${usePrefetch && (type === QueryType.QUERY || type === QueryType.INFINITE) ? `${doc}export const ${(0, import_core3.camel)(
|
|
2414
2548
|
`prefetch-${name}`
|
|
2415
2549
|
)} = async <TData = Awaited<ReturnType<${dataType}>>, TError = ${errorType}>(
|
|
2416
2550
|
queryClient: QueryClient, ${queryProps} ${queryArguments}
|
|
@@ -2418,7 +2552,7 @@ ${usePrefetch && (type === QueryType.QUERY || type === QueryType.INFINITE) ? `${
|
|
|
2418
2552
|
|
|
2419
2553
|
const ${queryOptionsVarName} = ${queryOptionsFnName}(${queryProperties}${queryProperties ? "," : ""}${isRequestOptions ? "options" : "queryOptions"})
|
|
2420
2554
|
|
|
2421
|
-
await queryClient.${(0,
|
|
2555
|
+
await queryClient.${(0, import_core3.camel)(`prefetch-${type}`)}(${queryOptionsVarName});
|
|
2422
2556
|
|
|
2423
2557
|
return queryClient;
|
|
2424
2558
|
}
|
|
@@ -2448,16 +2582,17 @@ var generateQueryHook = async ({
|
|
|
2448
2582
|
const isRequestOptions = (override == null ? void 0 : override.requestOptions) !== false;
|
|
2449
2583
|
const operationQueryOptions = (_a = operations[operationId]) == null ? void 0 : _a.query;
|
|
2450
2584
|
const isExactOptionalPropertyTypes = !!((_c = (_b = context.output.tsconfig) == null ? void 0 : _b.compilerOptions) == null ? void 0 : _c.exactOptionalPropertyTypes);
|
|
2451
|
-
const hasVueQueryV4 =
|
|
2452
|
-
const hasSvelteQueryV4 =
|
|
2585
|
+
const hasVueQueryV4 = import_core3.OutputClient.VUE_QUERY === outputClient && (!isVueQueryV3(context.output.packageJson) || query.version === 4);
|
|
2586
|
+
const hasSvelteQueryV4 = import_core3.OutputClient.SVELTE_QUERY === outputClient && (!isSvelteQueryV3(context.output.packageJson) || query.version === 4);
|
|
2453
2587
|
const hasQueryV5 = query.version === 5 || isQueryV5(
|
|
2454
2588
|
context.output.packageJson,
|
|
2455
2589
|
outputClient
|
|
2456
2590
|
);
|
|
2457
|
-
const
|
|
2591
|
+
const httpClient = context.output.httpClient;
|
|
2592
|
+
const doc = (0, import_core3.jsDoc)({ summary, deprecated });
|
|
2458
2593
|
let implementation = "";
|
|
2459
2594
|
let mutators = void 0;
|
|
2460
|
-
let isQuery =
|
|
2595
|
+
let isQuery = import_core3.Verbs.GET === verb && (override.query.useQuery || override.query.useSuspenseQuery || override.query.useInfinite || override.query.useSuspenseInfiniteQuery);
|
|
2461
2596
|
if ((operationQueryOptions == null ? void 0 : operationQueryOptions.useInfinite) !== void 0) {
|
|
2462
2597
|
isQuery = operationQueryOptions.useInfinite;
|
|
2463
2598
|
}
|
|
@@ -2471,14 +2606,14 @@ var generateQueryHook = async ({
|
|
|
2471
2606
|
isQuery = operationQueryOptions.useSuspenseQuery;
|
|
2472
2607
|
}
|
|
2473
2608
|
if (isQuery) {
|
|
2474
|
-
const queryKeyMutator = query.queryKey ? await (0,
|
|
2609
|
+
const queryKeyMutator = query.queryKey ? await (0, import_core3.generateMutator)({
|
|
2475
2610
|
output,
|
|
2476
2611
|
mutator: query.queryKey,
|
|
2477
2612
|
name: `${operationName}QueryKey`,
|
|
2478
2613
|
workspace: context.workspace,
|
|
2479
2614
|
tsconfig: context.output.tsconfig
|
|
2480
2615
|
}) : void 0;
|
|
2481
|
-
const queryOptionsMutator = query.queryOptions ? await (0,
|
|
2616
|
+
const queryOptionsMutator = query.queryOptions ? await (0, import_core3.generateMutator)({
|
|
2482
2617
|
output,
|
|
2483
2618
|
mutator: query.queryOptions,
|
|
2484
2619
|
name: `${operationName}QueryOptions`,
|
|
@@ -2486,19 +2621,19 @@ var generateQueryHook = async ({
|
|
|
2486
2621
|
tsconfig: context.output.tsconfig
|
|
2487
2622
|
}) : void 0;
|
|
2488
2623
|
const queryProperties = props.map((param) => {
|
|
2489
|
-
if (param.type ===
|
|
2624
|
+
if (param.type === import_core3.GetterPropType.NAMED_PATH_PARAMS && !isVue(outputClient))
|
|
2490
2625
|
return param.destructured;
|
|
2491
|
-
return param.type ===
|
|
2626
|
+
return param.type === import_core3.GetterPropType.BODY ? body.implementation : param.name;
|
|
2492
2627
|
}).join(",");
|
|
2493
|
-
const queryKeyProperties = props.filter((prop) => prop.type !==
|
|
2494
|
-
if (param.type ===
|
|
2628
|
+
const queryKeyProperties = props.filter((prop) => prop.type !== import_core3.GetterPropType.HEADER).map((param) => {
|
|
2629
|
+
if (param.type === import_core3.GetterPropType.NAMED_PATH_PARAMS && !isVue(outputClient))
|
|
2495
2630
|
return param.destructured;
|
|
2496
|
-
return param.type ===
|
|
2631
|
+
return param.type === import_core3.GetterPropType.BODY ? body.implementation : param.name;
|
|
2497
2632
|
}).join(",");
|
|
2498
2633
|
const queries = [
|
|
2499
2634
|
...(query == null ? void 0 : query.useInfinite) || (operationQueryOptions == null ? void 0 : operationQueryOptions.useInfinite) ? [
|
|
2500
2635
|
{
|
|
2501
|
-
name: (0,
|
|
2636
|
+
name: (0, import_core3.camel)(`${operationName}-infinite`),
|
|
2502
2637
|
options: query == null ? void 0 : query.options,
|
|
2503
2638
|
type: QueryType.INFINITE,
|
|
2504
2639
|
queryParam: query == null ? void 0 : query.useInfiniteQueryParam
|
|
@@ -2513,26 +2648,26 @@ var generateQueryHook = async ({
|
|
|
2513
2648
|
] : [],
|
|
2514
2649
|
...(query == null ? void 0 : query.useSuspenseQuery) || (operationQueryOptions == null ? void 0 : operationQueryOptions.useSuspenseQuery) ? [
|
|
2515
2650
|
{
|
|
2516
|
-
name: (0,
|
|
2651
|
+
name: (0, import_core3.camel)(`${operationName}-suspense`),
|
|
2517
2652
|
options: query == null ? void 0 : query.options,
|
|
2518
2653
|
type: QueryType.SUSPENSE_QUERY
|
|
2519
2654
|
}
|
|
2520
2655
|
] : [],
|
|
2521
2656
|
...(query == null ? void 0 : query.useSuspenseInfiniteQuery) || (operationQueryOptions == null ? void 0 : operationQueryOptions.useSuspenseInfiniteQuery) ? [
|
|
2522
2657
|
{
|
|
2523
|
-
name: (0,
|
|
2658
|
+
name: (0, import_core3.camel)(`${operationName}-suspense-infinite`),
|
|
2524
2659
|
options: query == null ? void 0 : query.options,
|
|
2525
2660
|
type: QueryType.SUSPENSE_INFINITE,
|
|
2526
2661
|
queryParam: query == null ? void 0 : query.useInfiniteQueryParam
|
|
2527
2662
|
}
|
|
2528
2663
|
] : []
|
|
2529
2664
|
];
|
|
2530
|
-
const queryKeyFnName = (0,
|
|
2531
|
-
let queryKeyProps = (0,
|
|
2532
|
-
props.filter((prop) => prop.type !==
|
|
2665
|
+
const queryKeyFnName = (0, import_core3.camel)(`get-${operationName}-queryKey`);
|
|
2666
|
+
let queryKeyProps = (0, import_core3.toObjectString)(
|
|
2667
|
+
props.filter((prop) => prop.type !== import_core3.GetterPropType.HEADER),
|
|
2533
2668
|
"implementation"
|
|
2534
2669
|
);
|
|
2535
|
-
const routeString = isVue(outputClient) ? (0,
|
|
2670
|
+
const routeString = isVue(outputClient) ? (0, import_core3.getRouteAsArray)(route) : `\`${route}\``;
|
|
2536
2671
|
const queryKeyFn = `${override.query.shouldExportQueryKey ? "export " : ""}const ${queryKeyFnName} = (${queryKeyProps}) => {
|
|
2537
2672
|
return [${routeString}${queryParams ? ", ...(params ? [params]: [])" : ""}${body.implementation ? `, ${body.implementation}` : ""}] as const;
|
|
2538
2673
|
}`;
|
|
@@ -2552,6 +2687,7 @@ var generateQueryHook = async ({
|
|
|
2552
2687
|
queryParams,
|
|
2553
2688
|
response,
|
|
2554
2689
|
outputClient,
|
|
2690
|
+
httpClient,
|
|
2555
2691
|
isExactOptionalPropertyTypes,
|
|
2556
2692
|
hasSignal: !!query.signal,
|
|
2557
2693
|
queryOptionsMutator,
|
|
@@ -2571,12 +2707,12 @@ var generateQueryHook = async ({
|
|
|
2571
2707
|
...queryKeyMutator ? [queryKeyMutator] : []
|
|
2572
2708
|
] : void 0;
|
|
2573
2709
|
}
|
|
2574
|
-
let isMutation = verb !==
|
|
2710
|
+
let isMutation = verb !== import_core3.Verbs.GET && override.query.useMutation;
|
|
2575
2711
|
if ((operationQueryOptions == null ? void 0 : operationQueryOptions.useMutation) !== void 0) {
|
|
2576
2712
|
isMutation = operationQueryOptions.useMutation;
|
|
2577
2713
|
}
|
|
2578
2714
|
if (isMutation) {
|
|
2579
|
-
const mutationOptionsMutator = query.mutationOptions ? await (0,
|
|
2715
|
+
const mutationOptionsMutator = query.mutationOptions ? await (0, import_core3.generateMutator)({
|
|
2580
2716
|
output,
|
|
2581
2717
|
mutator: query.mutationOptions,
|
|
2582
2718
|
name: `${operationName}MutationOptions`,
|
|
@@ -2584,14 +2720,16 @@ var generateQueryHook = async ({
|
|
|
2584
2720
|
tsconfig: context.output.tsconfig
|
|
2585
2721
|
}) : void 0;
|
|
2586
2722
|
const definitions = props.map(
|
|
2587
|
-
({ definition, type }) => type ===
|
|
2723
|
+
({ definition, type }) => type === import_core3.GetterPropType.BODY ? (mutator == null ? void 0 : mutator.bodyTypeName) ? `data: ${mutator.bodyTypeName}<${body.definition}>` : `data: ${body.definition}` : definition
|
|
2588
2724
|
).join(";");
|
|
2589
|
-
const properties = props.map(({ name, type }) => type ===
|
|
2590
|
-
let errorType =
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2725
|
+
const properties = props.map(({ name, type }) => type === import_core3.GetterPropType.BODY ? "data" : name).join(",");
|
|
2726
|
+
let errorType = getQueryErrorType(
|
|
2727
|
+
operationName,
|
|
2728
|
+
response,
|
|
2729
|
+
httpClient,
|
|
2730
|
+
mutator
|
|
2731
|
+
);
|
|
2732
|
+
const dataType = (mutator == null ? void 0 : mutator.isHook) ? `ReturnType<typeof use${(0, import_core3.pascal)(operationName)}Hook>` : `typeof ${operationName}`;
|
|
2595
2733
|
const mutationOptionFnReturnType = getQueryOptionsDefinition({
|
|
2596
2734
|
operationName,
|
|
2597
2735
|
definitions,
|
|
@@ -2606,23 +2744,33 @@ var generateQueryHook = async ({
|
|
|
2606
2744
|
mutator,
|
|
2607
2745
|
isRequestOptions,
|
|
2608
2746
|
hasSvelteQueryV4,
|
|
2609
|
-
hasQueryV5
|
|
2747
|
+
hasQueryV5,
|
|
2748
|
+
httpClient
|
|
2610
2749
|
});
|
|
2611
|
-
const mutationOptionsFnName = (0,
|
|
2750
|
+
const mutationOptionsFnName = (0, import_core3.camel)(
|
|
2612
2751
|
mutationOptionsMutator || (mutator == null ? void 0 : mutator.isHook) ? `use-${operationName}-mutationOptions` : `get-${operationName}-mutationOptions`
|
|
2613
2752
|
);
|
|
2614
2753
|
const mutationOptionsVarName = isRequestOptions ? "mutationOptions" : "options";
|
|
2754
|
+
const hooksOptionImplementation = getHooksOptionImplementation(
|
|
2755
|
+
isRequestOptions,
|
|
2756
|
+
httpClient,
|
|
2757
|
+
mutator
|
|
2758
|
+
);
|
|
2615
2759
|
const mutationOptionsFn = `export const ${mutationOptionsFnName} = <TError = ${errorType},
|
|
2616
2760
|
TContext = unknown>(${mutationArguments}): ${mutationOptionFnReturnType} => {
|
|
2617
|
-
${
|
|
2761
|
+
${hooksOptionImplementation}
|
|
2618
2762
|
|
|
2619
|
-
${(mutator == null ? void 0 : mutator.isHook) ? `const ${operationName} = use${(0,
|
|
2763
|
+
${(mutator == null ? void 0 : mutator.isHook) ? `const ${operationName} = use${(0, import_core3.pascal)(operationName)}Hook()` : ""}
|
|
2620
2764
|
|
|
2621
2765
|
|
|
2622
2766
|
const mutationFn: MutationFunction<Awaited<ReturnType<${dataType}>>, ${definitions ? `{${definitions}}` : "void"}> = (${properties ? "props" : ""}) => {
|
|
2623
2767
|
${properties ? `const {${properties}} = props ?? {};` : ""}
|
|
2624
2768
|
|
|
2625
|
-
return ${operationName}(${properties}${properties ? "," : ""}${
|
|
2769
|
+
return ${operationName}(${properties}${properties ? "," : ""}${getMutationRequestArgs(
|
|
2770
|
+
isRequestOptions,
|
|
2771
|
+
httpClient,
|
|
2772
|
+
mutator
|
|
2773
|
+
)})
|
|
2626
2774
|
}
|
|
2627
2775
|
|
|
2628
2776
|
${mutationOptionsMutator ? `const customOptions = ${mutationOptionsMutator.name}({...mutationOptions, mutationFn}${mutationOptionsMutator.hasThirdArg ? `, { url: \`${route}\` }` : ""});` : ""}
|
|
@@ -2633,13 +2781,13 @@ ${isRequestOptions ? `const {mutation: mutationOptions${!mutator ? `, axios: axi
|
|
|
2633
2781
|
implementation += `
|
|
2634
2782
|
${mutationOptionsFn}
|
|
2635
2783
|
|
|
2636
|
-
export type ${(0,
|
|
2784
|
+
export type ${(0, import_core3.pascal)(
|
|
2637
2785
|
operationName
|
|
2638
2786
|
)}MutationResult = NonNullable<Awaited<ReturnType<${dataType}>>>
|
|
2639
|
-
${body.definition ? `export type ${(0,
|
|
2640
|
-
export type ${(0,
|
|
2787
|
+
${body.definition ? `export type ${(0, import_core3.pascal)(operationName)}MutationBody = ${(mutator == null ? void 0 : mutator.bodyTypeName) ? `${mutator.bodyTypeName}<${body.definition}>` : body.definition}` : ""}
|
|
2788
|
+
export type ${(0, import_core3.pascal)(operationName)}MutationError = ${errorType}
|
|
2641
2789
|
|
|
2642
|
-
${doc}export const ${(0,
|
|
2790
|
+
${doc}export const ${(0, import_core3.camel)(
|
|
2643
2791
|
`${operationPrefix}-${operationName}`
|
|
2644
2792
|
)} = <TError = ${errorType},
|
|
2645
2793
|
TContext = unknown>(${mutationArguments})${generateMutatorReturnType({
|
|
@@ -2675,13 +2823,12 @@ ${isRequestOptions && isMutator ? `type SecondParameter<T extends (...args: any)
|
|
|
2675
2823
|
` : ""}
|
|
2676
2824
|
`;
|
|
2677
2825
|
};
|
|
2678
|
-
var generateQuery = async (verbOptions, options, outputClient
|
|
2679
|
-
const imports = (0,
|
|
2826
|
+
var generateQuery = async (verbOptions, options, outputClient) => {
|
|
2827
|
+
const imports = (0, import_core3.generateVerbImports)(verbOptions);
|
|
2680
2828
|
const functionImplementation = generateQueryRequestFunction(
|
|
2681
2829
|
verbOptions,
|
|
2682
2830
|
options,
|
|
2683
|
-
outputClient
|
|
2684
|
-
output
|
|
2831
|
+
isVue(outputClient)
|
|
2685
2832
|
);
|
|
2686
2833
|
const { implementation: hookImplementation, mutators } = await generateQueryHook(verbOptions, options, outputClient);
|
|
2687
2834
|
return {
|
|
@@ -2705,7 +2852,7 @@ var builder = ({
|
|
|
2705
2852
|
const client = (verbOptions, options, outputClient) => {
|
|
2706
2853
|
if (options.override.useNamedParameters && (type === "vue-query" || outputClient === "vue-query")) {
|
|
2707
2854
|
throw new Error(
|
|
2708
|
-
`vue-query client does not support named parameters, and had broken reactivity previously, please set useNamedParameters to false; See for context: https://github.com/
|
|
2855
|
+
`vue-query client does not support named parameters, and had broken reactivity previously, please set useNamedParameters to false; See for context: https://github.com/orval-labs/orval/pull/931#issuecomment-1752355686`
|
|
2709
2856
|
);
|
|
2710
2857
|
}
|
|
2711
2858
|
if (queryOptions) {
|
|
@@ -2713,11 +2860,11 @@ var builder = ({
|
|
|
2713
2860
|
queryOptions,
|
|
2714
2861
|
options.context.workspace
|
|
2715
2862
|
);
|
|
2716
|
-
verbOptions.override.query = (0,
|
|
2863
|
+
verbOptions.override.query = (0, import_core3.mergeDeep)(
|
|
2717
2864
|
normalizedQueryOptions,
|
|
2718
2865
|
verbOptions.override.query
|
|
2719
2866
|
);
|
|
2720
|
-
options.override.query = (0,
|
|
2867
|
+
options.override.query = (0, import_core3.mergeDeep)(
|
|
2721
2868
|
normalizedQueryOptions,
|
|
2722
2869
|
verbOptions.override.query
|
|
2723
2870
|
);
|